public class ContainerSpoilMachine extends Container
{
private IInventory tileMachine;
private int workTime;
private int currentSpoilTime;
private int spoilTime;
private int totalSpoilTime;
public ContainerSpoilMachine(InventoryPlayer playerInventory, IInventory machineInventory)
{
this.tileMachine = machineInventory;
this.addSlotToContainer(new Slot(machineInventory, 0, 56, 53));
this.addSlotToContainer(new Slot(machineInventory, 1, 56, 17));
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}
@Override
public void addListener(IContainerListener listener)
{
super.addListener(listener);
listener.sendAllWindowProperties(this, this.tileMachine);
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); ++i)
{
IContainerListener icontainerlistener = this.listeners.get(i);
if (this.spoilTime != this.tileMachine.getField(2))
{
icontainerlistener.sendWindowProperty(this, 2, this.tileMachine.getField(2));
}
if (this.workTime != this.tileMachine.getField(0))
{
icontainerlistener.sendWindowProperty(this, 0, this.tileMachine.getField(0));
}
if (this.currentSpoilTime != this.tileMachine.getField(1))
{
icontainerlistener.sendWindowProperty(this, 1, this.tileMachine.getField(1));
}
if (this.totalSpoilTime != this.tileMachine.getField(3))
{
icontainerlistener.sendWindowProperty(this, 3, this.tileMachine.getField(3));
}
}
this.spoilTime = this.tileMachine.getField(2);
this.workTime = this.tileMachine.getField(0);
this.currentSpoilTime = this.tileMachine.getField(1);
this.totalSpoilTime = this.tileMachine.getField(3);
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
this.tileMachine.setField(id, data);
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileMachine.isUsableByPlayer(playerIn);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 1)
{
if (!this.mergeItemStack(itemstack1, 2, 38, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index != 0)
{
if (TileEntitySpoilMachine.isItemCanSpoiled(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 2 && index <= 28)
{
if (!this.mergeItemStack(itemstack1, 29, 38, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 29 && index <= 37 && !this.mergeItemStack(itemstack1, 2, 29, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 2, 38, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
}