Fixed right clicking more cells than max

This commit is contained in:
Calclavia 2013-08-07 21:27:50 -04:00
parent d84e3c812a
commit c083670b55
2 changed files with 18 additions and 4 deletions

View file

@ -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();
}
}
/**

View file

@ -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();