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

@ -36,26 +36,36 @@ 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)
{
if (world.isRemote) return false;
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) {
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;
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);
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();
if (te instanceof TileEntityChest)
((TileEntityChest) te).checkForAdjacentChests();
world.removeTileEntity(pos);
world.setBlockToAir(pos);
@ -66,7 +76,8 @@ public class ItemChestChanger extends Item
world.markBlockForUpdate(pos);
TileEntity te2 = world.getTileEntity(pos);
if (te2 instanceof TileEntityIronChest) {
if (te2 instanceof TileEntityIronChest)
{
((TileEntityIronChest) te2).setContents(chestContents);
}

View File

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