diff options
author | durron597 <martin.jared@gmail.com> | 2011-01-06 06:20:12 -0500 |
---|---|---|
committer | durron597 <martin.jared@gmail.com> | 2011-01-06 06:26:12 -0500 |
commit | 687ae0533c74ce990006be2ed9134426cb0d107f (patch) | |
tree | 051211bfbc03d6f7e3e9519abdc570dfad463e5d /src | |
parent | 95c53f09fc0d14b93525dcedc66e84811b25a03e (diff) | |
download | craftbukkit-687ae0533c74ce990006be2ed9134426cb0d107f.tar craftbukkit-687ae0533c74ce990006be2ed9134426cb0d107f.tar.gz craftbukkit-687ae0533c74ce990006be2ed9134426cb0d107f.tar.lz craftbukkit-687ae0533c74ce990006be2ed9134426cb0d107f.tar.xz craftbukkit-687ae0533c74ce990006be2ed9134426cb0d107f.zip |
Create a concept of a null item stack
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftItemStack.java | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java index ed800910..3527721b 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftItemStack.java @@ -7,7 +7,7 @@ public class CraftItemStack extends ItemStack { protected net.minecraft.server.ItemStack item; public CraftItemStack(net.minecraft.server.ItemStack item) { - super(item.c, item.a); + super(item != null ? item.c : 0, item != null ? item.a : 0); this.item = item; } @@ -18,44 +18,68 @@ public class CraftItemStack extends ItemStack { @Override public Material getType() { - super.setTypeID(item.c); // sync, needed? + super.setTypeID(item != null ? item.c : 0); // sync, needed? return super.getType(); } @Override public int getTypeID() { - super.setTypeID(item.c); // sync, needed? - return item.c; + super.setTypeID(item != null ? item.c : 0); // sync, needed? + return item != null ? item.c : 0; } @Override public void setTypeID(int type) { - super.setTypeID(item.c); - item.c = type; + if (type == 0) { + super.setTypeID(0); + super.setAmount(0); + item = null; + } else { + if (item == null) { + item = new net.minecraft.server.ItemStack(type); + super.setAmount(1); + } else { + item.c = type; + super.setTypeID(item.c); + } + } } @Override public int getAmount() { - super.setAmount(item.a); // sync, needed? + super.setAmount(item != null ? item.a : 0); // sync, needed? return item.a; } @Override public void setAmount(int amount) { - super.setAmount(amount); - item.a = amount; + if (amount == 0) { + super.setTypeID(0); + super.setAmount(0); + item = null; + } else { + super.setAmount(amount); + item.a = amount; + } } @Override public void setDamage(final byte damage) { - super.setDamage(damage); - item.d = damage; + // Ignore damage if item is null + if (item != null) { + super.setDamage(damage); + item.d = damage; + } } @Override public byte getDamage() { - super.setDamage((byte) item.d); // sync, needed? - return (byte) item.d; + if (item != null) { + super.setDamage((byte) item.d); // sync, needed? + return (byte) item.d; + } else { + return 0; + } } } |