From 25d519aaf2b0fcb13bbbd269980cb2e05be55ed3 Mon Sep 17 00:00:00 2001 From: Erik Broes Date: Wed, 5 Jan 2011 01:00:57 +0100 Subject: [PATCH] Initial implementation of inventory stuff, (read-)only for StorageMinecart sofar --- .../net/minecraft/server/EntityMinecart.java | 6 ++ .../bukkit/craftbukkit/CraftItemStack.java | 61 +++++++++++++++++++ .../craftbukkit/CraftStorageMinecart.java | 32 +++++++++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/CraftItemStack.java diff --git a/src/main/java/net/minecraft/server/EntityMinecart.java b/src/main/java/net/minecraft/server/EntityMinecart.java index b8a3ed1d4e..4e11ab718a 100644 --- a/src/main/java/net/minecraft/server/EntityMinecart.java +++ b/src/main/java/net/minecraft/server/EntityMinecart.java @@ -113,6 +113,12 @@ public class EntityMinecart extends Entity // CraftBukkit end } + // CraftBukkit start + public ItemStack[] getContents() { + return this.ak; + } + // CraftBukkit end + public AxisAlignedBB d(Entity entity) { return entity.z; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java new file mode 100644 index 0000000000..ed80091064 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java @@ -0,0 +1,61 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.ItemStack; +import org.bukkit.Material; + +public class CraftItemStack extends ItemStack { + protected net.minecraft.server.ItemStack item; + + public CraftItemStack(net.minecraft.server.ItemStack item) { + super(item.c, item.a); + this.item = item; + } + + /* + * Unsure if we have to syn before each of these calls the values in 'item' + * are all public. + */ + + @Override + public Material getType() { + super.setTypeID(item.c); // sync, needed? + return super.getType(); + } + + @Override + public int getTypeID() { + super.setTypeID(item.c); // sync, needed? + return item.c; + } + + @Override + public void setTypeID(int type) { + super.setTypeID(item.c); + item.c = type; + } + + @Override + public int getAmount() { + super.setAmount(item.a); // sync, needed? + return item.a; + } + + @Override + public void setAmount(int amount) { + super.setAmount(amount); + item.a = amount; + } + + @Override + public void setDamage(final byte damage) { + super.setDamage(damage); + item.d = damage; + } + + @Override + public byte getDamage() { + super.setDamage((byte) item.d); // sync, needed? + return (byte) item.d; + } + +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java index 0adf0a180e..7567529e31 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java @@ -1,6 +1,11 @@ package org.bukkit.craftbukkit; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.server.EntityMinecart; + +import org.bukkit.ItemStack; import org.bukkit.StorageMinecart; /** @@ -8,10 +13,33 @@ import org.bukkit.StorageMinecart; * * @author sk89q */ -public class CraftStorageMinecart extends CraftMinecart - implements StorageMinecart { +public class CraftStorageMinecart extends CraftMinecart implements StorageMinecart { public CraftStorageMinecart(CraftServer server, EntityMinecart entity) { super(server, entity); } + public int getSize() { + return minecart.c(); + } + + public String getName() { + return minecart.b(); + } + + public ItemStack getItem(int index) { + return new CraftItemStack(minecart.a(index)); + } + + public List getContents() { + ArrayList items = new ArrayList(); + for (net.minecraft.server.ItemStack item: minecart.getContents()) { + ItemStack i = null; + if (item != null) { + i = new CraftItemStack( item ); + } + items.add(i); + } + + return items; + } }