package powercrystals.minefactoryreloaded.gui.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import powercrystals.minefactoryreloaded.gui.slot.SlotRemoveOnly;
import powercrystals.minefactoryreloaded.tile.machine.TileEntityBioReactor;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ContainerBioReactor extends ContainerFactoryInventory
{
public ContainerBioReactor(TileEntityBioReactor tileentity, InventoryPlayer inv)
{
super(tileentity, inv);
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for(int i = 0; i < crafters.size(); i++)
{
((ICrafting)crafters.get(i)).sendProgressBarUpdate(this, 100, ((TileEntityBioReactor)_te).getBurnTime());
}
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int var, int value)
{
super.updateProgressBar(var, value);
if(var == 100) ((TileEntityBioReactor)_te).setBurnTime(value);
}
@Override
protected void addSlots()
{
super.addSlots();
for(int i = 0; i < 9; i++)
{
addSlotToContainer(new SlotRemoveOnly(_te, 9 + i, 8 + 18 * i, 83));
}
}
@Override
protected int getPlayerInventoryVerticalOffset()
{
return 113;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
int machInvSize = _te.getSizeInventory();
if(slotObject != null && slotObject.getHasStack())
{
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if(slot < machInvSize)
{
if(!mergeItemStack(stackInSlot, machInvSize, inventorySlots.size(), true))
{
return null;
}
}
else if(!mergeItemStack(stackInSlot, 0, 9, false))
{
return null;
}
if(stackInSlot.stackSize == 0)
{
slotObject.putStack(null);
}
else
{
slotObject.onSlotChanged();
}
if(stackInSlot.stackSize == stack.stackSize)
{
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
}