if(type == MachineType.ELECTRIC_CHEST)
{
if(world != null && !world.isRemote)
{
InventoryElectricChest inv = new InventoryElectricChest(itemstack);
if(inv.getStackInSlot(54) != null && getEnergy(itemstack) < getMaxEnergy(itemstack))
{
if(inv.getStackInSlot(54).getItem() instanceof IEnergizedItem)
{
setEnergy(itemstack, getEnergy(itemstack) + EnergizedItemManager.discharge(inv.getStackInSlot(54), getMaxEnergy(itemstack) - getEnergy(itemstack)));
}
else if(MekanismUtils.useIC2() && inv.getStackInSlot(54).getItem() instanceof IElectricItem)
{
IElectricItem item = (IElectricItem)inv.getStackInSlot(54).getItem();
if(item.canProvideEnergy(inv.getStackInSlot(54)))
{
double gain = ElectricItem.manager.discharge(inv.getStackInSlot(54), (int)((getMaxEnergy(itemstack) - getEnergy(itemstack))*Mekanism.TO_IC2), 3, false, true, false)*Mekanism.FROM_IC2;
setEnergy(itemstack, getEnergy(itemstack) + gain);
}
}
else if(MekanismUtils.useRF() && inv.getStackInSlot(54).getItem() instanceof IEnergyContainerItem)
{
ItemStack itemStack = inv.getStackInSlot(54);
IEnergyContainerItem item = (IEnergyContainerItem)inv.getStackInSlot(54).getItem();
int itemEnergy = (int)Math.round(Math.min(Math.sqrt(item.getMaxEnergyStored(itemStack)), item.getEnergyStored(itemStack)));
int toTransfer = (int)Math.round(Math.min(itemEnergy, ((getMaxEnergy(itemstack) - getEnergy(itemstack))*Mekanism.TO_TE)));
setEnergy(itemstack, getEnergy(itemstack) + (item.extractEnergy(itemStack, toTransfer, false)*Mekanism.FROM_TE));
}
else if(inv.getStackInSlot(54).getItem() == Items.redstone && getEnergy(itemstack)+Mekanism.ENERGY_PER_REDSTONE <= getMaxEnergy(itemstack))
{
setEnergy(itemstack, getEnergy(itemstack) + Mekanism.ENERGY_PER_REDSTONE);
inv.getStackInSlot(54).stackSize--;
if(inv.getStackInSlot(54).stackSize <= 0)
{
inv.setInventorySlotContents(54, null);
}
}
inv.write();
}
}
}
else if(type == MachineType.PORTABLE_TANK)
{