2013-08-23 16:59:50 +02:00
|
|
|
package com.pahimar.ee3.inventory;
|
|
|
|
|
2013-12-16 02:26:42 +01:00
|
|
|
import com.pahimar.ee3.tileentity.TileAlchemicalChest;
|
2013-08-23 16:59:50 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Equivalent-Exchange-3
|
2013-12-16 02:26:42 +01:00
|
|
|
* <p/>
|
2013-08-23 16:59:50 +02:00
|
|
|
* ContainerAlchemicalChest
|
2013-12-16 02:26:42 +01:00
|
|
|
*
|
2013-08-23 16:59:50 +02:00
|
|
|
* @author pahimar
|
|
|
|
*/
|
2013-12-16 02:26:42 +01:00
|
|
|
public class ContainerAlchemicalChest extends Container
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
private TileAlchemicalChest tileAlchemicalChest;
|
|
|
|
|
|
|
|
private final int CHEST_INVENTORY_ROWS = 4;
|
|
|
|
private final int CHEST_INVENTORY_COLUMNS = 13;
|
|
|
|
|
|
|
|
private final int PLAYER_INVENTORY_ROWS = 3;
|
|
|
|
private final int PLAYER_INVENTORY_COLUMNS = 9;
|
|
|
|
|
2013-12-16 02:26:42 +01:00
|
|
|
public ContainerAlchemicalChest(InventoryPlayer inventoryPlayer, TileAlchemicalChest tileAlchemicalChest)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
this.tileAlchemicalChest = tileAlchemicalChest;
|
|
|
|
|
|
|
|
tileAlchemicalChest.openChest();
|
|
|
|
|
|
|
|
// Add the Alchemical Chest slots to the container
|
2013-12-16 02:26:42 +01:00
|
|
|
for (int chestRowIndex = 0; chestRowIndex < CHEST_INVENTORY_ROWS; ++chestRowIndex)
|
|
|
|
{
|
|
|
|
for (int chestColumnIndex = 0; chestColumnIndex < CHEST_INVENTORY_COLUMNS; ++chestColumnIndex)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
this.addSlotToContainer(new Slot(tileAlchemicalChest, chestColumnIndex + chestRowIndex * 13, 8 + chestColumnIndex * 18, 18 + chestRowIndex * 18));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the player's inventory slots to the container
|
2013-12-16 02:26:42 +01:00
|
|
|
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex)
|
|
|
|
{
|
|
|
|
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 44 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the player's action bar slots to the container
|
2013-12-16 02:26:42 +01:00
|
|
|
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 162));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-16 02:26:42 +01:00
|
|
|
public boolean canInteractWith(EntityPlayer var1)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when the crafting gui is closed.
|
|
|
|
*/
|
|
|
|
@Override
|
2013-12-16 02:26:42 +01:00
|
|
|
public void onContainerClosed(EntityPlayer entityPlayer)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
super.onContainerClosed(entityPlayer);
|
|
|
|
tileAlchemicalChest.closeChest();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-12-16 02:26:42 +01:00
|
|
|
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
ItemStack newItemStack = null;
|
|
|
|
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
|
|
|
|
2013-12-16 02:26:42 +01:00
|
|
|
if (slot != null && slot.getHasStack())
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
ItemStack itemStack = slot.getStack();
|
|
|
|
newItemStack = itemStack.copy();
|
|
|
|
|
2013-12-16 02:26:42 +01:00
|
|
|
if (slotIndex < CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
if (!this.mergeItemStack(itemStack, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, inventorySlots.size(), false))
|
2013-12-16 02:26:42 +01:00
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
return null;
|
2013-12-16 02:26:42 +01:00
|
|
|
}
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
else if (!this.mergeItemStack(itemStack, 0, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, false))
|
2013-12-16 02:26:42 +01:00
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
return null;
|
2013-12-16 02:26:42 +01:00
|
|
|
}
|
2013-08-23 16:59:50 +02:00
|
|
|
|
2013-12-16 02:26:42 +01:00
|
|
|
if (itemStack.stackSize == 0)
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
slot.putStack((ItemStack) null);
|
|
|
|
}
|
2013-12-16 02:26:42 +01:00
|
|
|
else
|
|
|
|
{
|
2013-08-23 16:59:50 +02:00
|
|
|
slot.onSlotChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newItemStack;
|
|
|
|
}
|
|
|
|
}
|