This commit is contained in:
61352151511 2015-01-29 12:58:38 -04:00
parent b6e2f384ae
commit c1912bc475
2 changed files with 59 additions and 45 deletions

View File

@ -34,44 +34,55 @@ public class ItemChestChanger extends Item
} }
@Override @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; if (world.isRemote)
TileEntity te = world.getTileEntity(pos); return false;
TileEntityIronChest newchest = new TileEntityIronChest(); TileEntity te = world.getTileEntity(pos);
ItemStack[] chestContents = new ItemStack[27]; TileEntityIronChest newchest = new TileEntityIronChest();
if (te != null) { ItemStack[] chestContents = new ItemStack[27];
if (te instanceof TileEntityIronChest) { if (te != null)
chestContents = ((TileEntityIronChest) te).chestContents; {
newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal())); if (te instanceof TileEntityIronChest)
if (newchest == null) return false; {
} else if (te instanceof TileEntityChest) { chestContents = ((TileEntityIronChest) te).chestContents;
if (((TileEntityChest) te).numPlayersUsing > 0) return false; newchest = IronChestType.makeEntity(this.getTargetChestOrdinal(this.type.ordinal()));
if (!getType().canUpgrade(IronChestType.WOOD)) return false; if (newchest == null)
chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()]; return false;
for (int i = 0; i < chestContents.length; i ++) chestContents[i] = ((TileEntityChest) te).getStackInSlot(i); }
newchest = IronChestType.makeEntity(IronChestType.IRON.ordinal()); else if (te instanceof TileEntityChest)
} {
} if (((TileEntityChest) te).numPlayersUsing > 0)
return false;
te.updateContainingBlockInfo(); if (!getType().canUpgrade(IronChestType.WOOD))
if (te instanceof TileEntityChest) ((TileEntityChest) te).checkForAdjacentChests(); return false;
chestContents = new ItemStack[((TileEntityChest) te).getSizeInventory()];
world.removeTileEntity(pos); for (int i = 0; i < chestContents.length; i++)
world.setBlockToAir(pos); chestContents[i] = ((TileEntityChest) te).getStackInSlot(i);
newchest = IronChestType.makeEntity(IronChestType.IRON.ordinal());
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; te.updateContainingBlockInfo();
return true; 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) public int getTargetChestOrdinal(int sourceOrdinal)

View File

@ -60,15 +60,18 @@ public class TileEntityIronChest extends TileEntityLockable implements IUpdatePl
return chestContents; return chestContents;
} }
public void setContents(ItemStack[] contents) { public void setContents (ItemStack[] contents)
chestContents = new ItemStack[getSizeInventory()]; {
for (int i = 0; i < contents.length; i ++) { chestContents = new ItemStack[getSizeInventory()];
if (i < chestContents.length) { for (int i = 0; i < contents.length; i++)
chestContents[i] = contents[i]; {
} if (i < chestContents.length)
} {
inventoryTouched = true; chestContents[i] = contents[i];
} }
}
inventoryTouched = true;
}
@Override @Override
public int getSizeInventory() public int getSizeInventory()