diff options
author | Andrew Ardill <andrew.ardill@gmail.com> | 2011-12-13 01:40:35 +1100 |
---|---|---|
committer | Andrew Ardill <andrew.ardill@gmail.com> | 2011-12-13 01:46:55 +1100 |
commit | 82965eb10f66b84273f61e29b7548c215ebd4fc6 (patch) | |
tree | 098d994a875c754275f60e17fe3f22c47378ff78 /src | |
parent | d34e2894347f780ed6f27f745a88688000dc3615 (diff) | |
download | craftbukkit-82965eb10f66b84273f61e29b7548c215ebd4fc6.tar craftbukkit-82965eb10f66b84273f61e29b7548c215ebd4fc6.tar.gz craftbukkit-82965eb10f66b84273f61e29b7548c215ebd4fc6.tar.lz craftbukkit-82965eb10f66b84273f61e29b7548c215ebd4fc6.tar.xz craftbukkit-82965eb10f66b84273f61e29b7548c215ebd4fc6.zip |
Stop converting ItemStack to nms ItemStack by hand
This should fix many issues with enchantments being lost, as the method used takes care of enchantments.
Additionally, use the new nms ItemStack constructor in places where appropriate.
Fixes (at least part of) BUKKIT-7. Need to identify any further places to fix.
Diffstat (limited to 'src')
5 files changed, 11 insertions, 30 deletions
diff --git a/src/main/java/net/minecraft/server/BlockDispenser.java b/src/main/java/net/minecraft/server/BlockDispenser.java index 4b7f8a3e..39833823 100644 --- a/src/main/java/net/minecraft/server/BlockDispenser.java +++ b/src/main/java/net/minecraft/server/BlockDispenser.java @@ -102,7 +102,7 @@ public class BlockDispenser extends BlockContainer { itemstack = tileentitydispenser.getContents()[dispenseSlot]; // Copy item stack, because we want it to have 1 item - itemstack = new ItemStack(itemstack.id, 1, itemstack.getData()); + itemstack = new ItemStack(itemstack.id, 1, itemstack.getData(), itemstack.getEnchantments()); } // CraftBukkit end @@ -139,7 +139,7 @@ public class BlockDispenser extends BlockContainer { motY = event.getVelocity().getY(); motZ = event.getVelocity().getZ(); - itemstack = new ItemStack(event.getItem().getTypeId(), event.getItem().getAmount(), event.getItem().getDurability()); + itemstack = CraftItemStack.createNMSItemStack(event.getItem()); // CraftBukkit end if (itemstack.id == Item.ARROW.id) { @@ -244,7 +244,7 @@ public class BlockDispenser extends BlockContainer { } itemstack.count -= i1; - EntityItem entityitem = new EntityItem(world, (double) ((float) i + f), (double) ((float) j + f1), (double) ((float) k + f2), new ItemStack(itemstack.id, i1, itemstack.getData())); + EntityItem entityitem = new EntityItem(world, (double) ((float) i + f), (double) ((float) j + f1), (double) ((float) k + f2), new ItemStack(itemstack.id, i1, itemstack.getData(), itemstack.getEnchantments())); // CraftBukkit - make sure enchantments are copied over float f3 = 0.05F; entityitem.motX = (double) ((float) this.a.nextGaussian() * f3); diff --git a/src/main/java/net/minecraft/server/EntityCow.java b/src/main/java/net/minecraft/server/EntityCow.java index ecbf4fd5..9700fe86 100644 --- a/src/main/java/net/minecraft/server/EntityCow.java +++ b/src/main/java/net/minecraft/server/EntityCow.java @@ -80,11 +80,7 @@ public class EntityCow extends EntityAnimal { return false; } - CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); - byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); - itemstack = new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); - - entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, itemstack); + entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, CraftItemStack.createNMSItemStack(event.getItemStack())); // CraftBukkit end return true; diff --git a/src/main/java/net/minecraft/server/ItemBucket.java b/src/main/java/net/minecraft/server/ItemBucket.java index 2eb6104d..4b6a2422 100644 --- a/src/main/java/net/minecraft/server/ItemBucket.java +++ b/src/main/java/net/minecraft/server/ItemBucket.java @@ -54,13 +54,10 @@ public class ItemBucket extends Item { if (entityhuman.abilities.canInstantlyBuild) { return itemstack; } - - CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); - byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); // CraftBukkit end world.setTypeId(i, j, k, 0); - return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit + return CraftItemStack.createNMSItemStack(event.getItemStack()); // CraftBukkit } if (world.getMaterial(i, j, k) == Material.LAVA && world.getData(i, j, k) == 0) { @@ -74,13 +71,10 @@ public class ItemBucket extends Item { if (entityhuman.abilities.canInstantlyBuild) { return itemstack; } - - CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); - byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); // CraftBukkit end world.setTypeId(i, j, k, 0); - return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit + return CraftItemStack.createNMSItemStack(event.getItemStack()); // CraftBukkit } } else { if (this.a < 0) { @@ -91,9 +85,7 @@ public class ItemBucket extends Item { return itemstack; } - CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); - byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); - return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); + return CraftItemStack.createNMSItemStack(event.getItemStack()); } int clickedX = i, clickedY = j, clickedZ = k; @@ -151,10 +143,7 @@ public class ItemBucket extends Item { } // CraftBukkit start - CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); - byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); - - return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); + return CraftItemStack.createNMSItemStack(event.getItemStack()); // CraftBukkit end } } @@ -167,9 +156,7 @@ public class ItemBucket extends Item { return itemstack; } - CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); - byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData(); - return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); + return CraftItemStack.createNMSItemStack(event.getItemStack()); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java index f8a7c6fb..1de57c59 100644 --- a/src/main/java/net/minecraft/server/TileEntityFurnace.java +++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java @@ -211,9 +211,7 @@ public class TileEntityFurnace extends TileEntity implements IInventory { return; } - org.bukkit.inventory.ItemStack oldResult = furnaceSmeltEvent.getResult(); - ItemStack newResult = new ItemStack(oldResult.getTypeId(), oldResult.getAmount(), oldResult.getDurability()); - itemstack = newResult; + itemstack = CraftItemStack.createNMSItemStack(furnaceSmeltEvent.getResult()); if (this.items[2] == null) { this.items[2] = itemstack.cloneItemStack(); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java index a01976cf..a92598be 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java @@ -19,7 +19,7 @@ public class CraftItem extends CraftEntity implements Item { } public void setItemStack(ItemStack stack) { - item.itemStack = new net.minecraft.server.ItemStack(stack.getTypeId(), stack.getAmount(), stack.getDurability()); + item.itemStack = CraftItemStack.createNMSItemStack(stack); } public int getPickupDelay() { |