2016-01-07 23:05:23 +00:00
|
|
|
package WayofTime.bloodmagic.tile.container;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import WayofTime.bloodmagic.api.soul.ISoul;
|
|
|
|
import WayofTime.bloodmagic.api.soul.ISoulGem;
|
|
|
|
import WayofTime.bloodmagic.item.ItemTelepositionFocus;
|
|
|
|
|
|
|
|
public class ContainerSoulForge extends Container
|
|
|
|
{
|
|
|
|
private final IInventory tileForge;
|
|
|
|
|
|
|
|
public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileForge)
|
|
|
|
{
|
|
|
|
this.tileForge = tileForge;
|
|
|
|
this.addSlotToContainer(new SlotSoul(tileForge, 0, 152, 51));
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 9; j++)
|
|
|
|
{
|
2016-01-08 03:40:04 +00:00
|
|
|
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 123 + i * 18));
|
2016-01-07 23:05:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
{
|
2016-01-08 03:40:04 +00:00
|
|
|
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 181));
|
2016-01-07 23:05:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
|
|
|
|
{
|
|
|
|
ItemStack stack = null;
|
|
|
|
Slot slotObject = inventorySlots.get(slot);
|
|
|
|
int slots = inventorySlots.size();
|
|
|
|
|
|
|
|
if (slotObject != null && slotObject.getHasStack())
|
|
|
|
{
|
|
|
|
ItemStack stackInSlot = slotObject.getStack();
|
|
|
|
stack = stackInSlot.copy();
|
|
|
|
|
|
|
|
if (stack.getItem() instanceof ItemTelepositionFocus)
|
|
|
|
{
|
|
|
|
if (slot <= slots)
|
|
|
|
{
|
|
|
|
if (!this.mergeItemStack(stackInSlot, 0, slots, false))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else if (!this.mergeItemStack(stackInSlot, slots, 36 + slots, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInteractWith(EntityPlayer playerIn)
|
|
|
|
{
|
|
|
|
return this.tileForge.isUseableByPlayer(playerIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class SlotSoul extends Slot
|
|
|
|
{
|
|
|
|
public SlotSoul(IInventory inventory, int slotIndex, int x, int y)
|
|
|
|
{
|
|
|
|
super(inventory, slotIndex, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValid(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
return itemStack.getItem() instanceof ISoulGem || itemStack.getItem() instanceof ISoul;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|