From c083670b5539bff6a658107b1dcbe0afe0e74935 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Wed, 7 Aug 2013 21:27:50 -0400 Subject: [PATCH] Fixed right clicking more cells than max --- src/resonantinduction/battery/BlockBattery.java | 10 ++++++---- .../battery/SynchronizedBatteryData.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/resonantinduction/battery/BlockBattery.java b/src/resonantinduction/battery/BlockBattery.java index e8fe76ce..b8896a0b 100644 --- a/src/resonantinduction/battery/BlockBattery.java +++ b/src/resonantinduction/battery/BlockBattery.java @@ -70,10 +70,12 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider if (!world.isRemote) { TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z); - tileEntity.structure.inventory.add(entityPlayer.getCurrentEquippedItem()); - tileEntity.structure.sortInventory(); - entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null); - tileEntity.updateAllClients(); + + if (tileEntity.structure.addCell(entityPlayer.getCurrentEquippedItem())) + { + entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null); + tileEntity.updateAllClients(); + } } /** diff --git a/src/resonantinduction/battery/SynchronizedBatteryData.java b/src/resonantinduction/battery/SynchronizedBatteryData.java index 78209196..d7adbc69 100644 --- a/src/resonantinduction/battery/SynchronizedBatteryData.java +++ b/src/resonantinduction/battery/SynchronizedBatteryData.java @@ -45,6 +45,18 @@ public class SynchronizedBatteryData return getVolume() * BatteryManager.CELLS_PER_BATTERY; } + public boolean addCell(ItemStack cell) + { + if (this.inventory.size() < this.getMaxCells()) + { + this.inventory.add(cell); + this.sortInventory(); + return true; + } + + return false; + } + public void sortInventory() { Object[] array = ListUtil.copy(inventory).toArray();