13
0
geforkt von Mirrors/Paper

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.
Dieser Commit ist enthalten in:
Andrew Ardill 2011-12-13 01:40:35 +11:00
Ursprung d34e289434
Commit 82965eb10f
5 geänderte Dateien mit 11 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -102,7 +102,7 @@ public class BlockDispenser extends BlockContainer {
itemstack = tileentitydispenser.getContents()[dispenseSlot]; itemstack = tileentitydispenser.getContents()[dispenseSlot];
// Copy item stack, because we want it to have 1 item // 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 // CraftBukkit end
@ -139,7 +139,7 @@ public class BlockDispenser extends BlockContainer {
motY = event.getVelocity().getY(); motY = event.getVelocity().getY();
motZ = event.getVelocity().getZ(); motZ = event.getVelocity().getZ();
itemstack = new ItemStack(event.getItem().getTypeId(), event.getItem().getAmount(), event.getItem().getDurability()); itemstack = CraftItemStack.createNMSItemStack(event.getItem());
// CraftBukkit end // CraftBukkit end
if (itemstack.id == Item.ARROW.id) { if (itemstack.id == Item.ARROW.id) {
@ -244,7 +244,7 @@ public class BlockDispenser extends BlockContainer {
} }
itemstack.count -= i1; 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; float f3 = 0.05F;
entityitem.motX = (double) ((float) this.a.nextGaussian() * f3); entityitem.motX = (double) ((float) this.a.nextGaussian() * f3);

Datei anzeigen

@ -80,11 +80,7 @@ public class EntityCow extends EntityAnimal {
return false; return false;
} }
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, CraftItemStack.createNMSItemStack(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);
// CraftBukkit end // CraftBukkit end
return true; return true;

Datei anzeigen

@ -54,13 +54,10 @@ public class ItemBucket extends Item {
if (entityhuman.abilities.canInstantlyBuild) { if (entityhuman.abilities.canInstantlyBuild) {
return itemstack; return itemstack;
} }
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
// CraftBukkit end // CraftBukkit end
world.setTypeId(i, j, k, 0); 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) { 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) { if (entityhuman.abilities.canInstantlyBuild) {
return itemstack; return itemstack;
} }
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
// CraftBukkit end // CraftBukkit end
world.setTypeId(i, j, k, 0); world.setTypeId(i, j, k, 0);
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit return CraftItemStack.createNMSItemStack(event.getItemStack()); // CraftBukkit
} }
} else { } else {
if (this.a < 0) { if (this.a < 0) {
@ -91,9 +85,7 @@ public class ItemBucket extends Item {
return itemstack; return itemstack;
} }
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); return CraftItemStack.createNMSItemStack(event.getItemStack());
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data);
} }
int clickedX = i, clickedY = j, clickedZ = k; int clickedX = i, clickedY = j, clickedZ = k;
@ -151,10 +143,7 @@ public class ItemBucket extends Item {
} }
// CraftBukkit start // CraftBukkit start
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); return CraftItemStack.createNMSItemStack(event.getItemStack());
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data);
// CraftBukkit end // CraftBukkit end
} }
} }
@ -167,9 +156,7 @@ public class ItemBucket extends Item {
return itemstack; return itemstack;
} }
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack(); return CraftItemStack.createNMSItemStack(event.getItemStack());
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data);
// CraftBukkit end // CraftBukkit end
} }

Datei anzeigen

@ -211,9 +211,7 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
return; return;
} }
org.bukkit.inventory.ItemStack oldResult = furnaceSmeltEvent.getResult(); itemstack = CraftItemStack.createNMSItemStack(furnaceSmeltEvent.getResult());
ItemStack newResult = new ItemStack(oldResult.getTypeId(), oldResult.getAmount(), oldResult.getDurability());
itemstack = newResult;
if (this.items[2] == null) { if (this.items[2] == null) {
this.items[2] = itemstack.cloneItemStack(); this.items[2] = itemstack.cloneItemStack();

Datei anzeigen

@ -19,7 +19,7 @@ public class CraftItem extends CraftEntity implements Item {
} }
public void setItemStack(ItemStack stack) { 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() { public int getPickupDelay() {