diff --git a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java index f8a34c3..84ab992 100755 --- a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java +++ b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java @@ -34,44 +34,55 @@ public class ItemChestChanger extends Item } @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) + public boolean onItemUseFirst (ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { - if (world.isRemote) return false; - TileEntity te = world.getTileEntity(pos); - TileEntityIronChest newchest = new TileEntityIronChest(); - ItemStack[] chestContents = new ItemStack[27]; - if (te != null) { - if (te instanceof TileEntityIronChest) { - chestContents = ((TileEntityIronChest) te).chestContents; - newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); - if (newchest == null) return false; - } else if (te instanceof TileEntityChest) { - if (((TileEntityChest) te).numPlayersUsing > 0) return false; - if (!getType().canUpgrade(IronChestType.WOOD)) return false; - chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; - for (int i = 0; i < chestContents.length; i ++) chestContents[i] = ((TileEntityChest) te).getStackInSlot(i); - newchest = IronChestType.makeEntity(IronChestType.IRON.ordinal()); - } - } - - te.updateContainingBlockInfo(); - if (te instanceof TileEntityChest) ((TileEntityChest) te).checkForAdjacentChests(); - - world.removeTileEntity(pos); - world.setBlockToAir(pos); - - world.setTileEntity(pos, newchest); - world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3); - - world.markBlockForUpdate(pos); - - TileEntity te2 = world.getTileEntity(pos); - if (te2 instanceof TileEntityIronChest) { - ((TileEntityIronChest) te2).setContents(chestContents); - } + if (world.isRemote) + return false; + TileEntity te = world.getTileEntity(pos); + TileEntityIronChest newchest = new TileEntityIronChest(); + ItemStack[] chestContents = new ItemStack[27]; + if (te != null) + { + if (te instanceof TileEntityIronChest) + { + chestContents = ((TileEntityIronChest) te).chestContents; + newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); + if (newchest == null) + return false; + } + else if (te instanceof TileEntityChest) + { + if (((TileEntityChest) te).numPlayersUsing > 0) + return false; + if (!getType().canUpgrade(IronChestType.WOOD)) + return false; + chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; + for (int i = 0; i < chestContents.length; i++) + chestContents[i] = ((TileEntityChest) te).getStackInSlot(i); + newchest = IronChestType.makeEntity(IronChestType.IRON.ordinal()); + } + } - stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1; - return true; + te.updateContainingBlockInfo(); + if (te instanceof TileEntityChest) + ((TileEntityChest) te).checkForAdjacentChests(); + + world.removeTileEntity(pos); + world.setBlockToAir(pos); + + world.setTileEntity(pos, newchest); + world.setBlockState(pos, IronChest.ironChestBlock.getStateFromMeta(newchest.getType().ordinal()), 3); + + world.markBlockForUpdate(pos); + + TileEntity te2 = world.getTileEntity(pos); + if (te2 instanceof TileEntityIronChest) + { + ((TileEntityIronChest) te2).setContents(chestContents); + } + + stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1; + return true; } public int getTargetChestOrdinal(int sourceOrdinal) diff --git a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java index 064a7a0..217eceb 100755 --- a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java @@ -60,15 +60,18 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl return chestContents; } - public void setContents(ItemStack[] contents) { - chestContents = new ItemStack[getSizeInventory()]; - for (int i = 0; i < contents.length; i ++) { - if (i < chestContents.length) { - chestContents[i] = contents[i]; - } - } - inventoryTouched = true; - } + public void setContents (ItemStack[] contents) + { + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < contents.length; i++) + { + if (i < chestContents.length) + { + chestContents[i] = contents[i]; + } + } + inventoryTouched = true; + } @Override public int getSizeInventory()