equivalent-exchange-3/src/main/java/com/pahimar/ee3/inventory/ContainerGlassBell.java

92 lines
2.7 KiB
Java
Raw Normal View History

2013-08-23 16:59:50 +02:00
package com.pahimar.ee3.inventory;
import com.pahimar.ee3.tileentity.TileGlassBell;
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
* <p/>
2013-08-23 16:59:50 +02:00
* ContainerGlassBell
*
2013-08-23 16:59:50 +02:00
* @author pahimar
*/
public class ContainerGlassBell extends Container
{
2013-08-23 16:59:50 +02:00
private final int PLAYER_INVENTORY_ROWS = 3;
private final int PLAYER_INVENTORY_COLUMNS = 9;
public ContainerGlassBell(InventoryPlayer inventoryPlayer, TileGlassBell tileGlassBell)
{
2013-08-23 16:59:50 +02:00
this.addSlotToContainer(new Slot(tileGlassBell, TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, 80, 22));
// Add the player's inventory slots to the container
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, 8 + inventoryColumnIndex * 18, 58 + inventoryRowIndex * 18));
}
}
// Add the player's action bar slots to the container
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex)
{
2013-08-23 16:59:50 +02:00
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 116));
}
}
@Override
public boolean canInteractWith(EntityPlayer var1)
{
2013-08-23 16:59:50 +02:00
return true;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
{
2013-08-23 16:59:50 +02:00
ItemStack itemStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack())
{
2013-08-23 16:59:50 +02:00
ItemStack slotItemStack = slot.getStack();
itemStack = slotItemStack.copy();
if (slotIndex < TileGlassBell.INVENTORY_SIZE)
{
2013-08-23 16:59:50 +02:00
if (!this.mergeItemStack(slotItemStack, 1, inventorySlots.size(), true))
{
2013-08-23 16:59:50 +02:00
return null;
}
}
else
{
if (!this.mergeItemStack(slotItemStack, 0, TileGlassBell.INVENTORY_SIZE, false))
{
2013-08-23 16:59:50 +02:00
return null;
}
}
if (slotItemStack.stackSize == 0)
{
2013-08-23 16:59:50 +02:00
slot.putStack((ItemStack) null);
}
else
{
2013-08-23 16:59:50 +02:00
slot.onSlotChanged();
}
}
return itemStack;
}
}