mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-13 08:54:12 +00:00
84 lines
2.4 KiB
Java
84 lines
2.4 KiB
Java
package tconstruct.inventory;
|
|||
|
|
|
||
|
|
import tconstruct.util.player.KnapsackInventory;
|
||
|
|
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;
|
||
|
|
|
||
|
|
public class KnapsackContainer extends Container
|
||
|
|
{
|
||
|
|
public KnapsackInventory backpack;
|
||
|
|
public int progress = 0;
|
||
|
|
public int fuel = 0;
|
||
|
|
public int fuelGague = 0;
|
||
|
|
|
||
|
|
public KnapsackContainer(InventoryPlayer inventoryplayer, KnapsackInventory knapsack)
|
||
|
|
{
|
||
|
|
backpack = knapsack;
|
||
|
|
for (int column = 0; column < 3; column++)
|
||
|
|
{
|
||
|
|
for (int row = 0; row < 9; row++)
|
||
|
|
{
|
||
|
|
this.addSlotToContainer(new Slot(knapsack, row + column * 9, 8 + row * 18, 17 + column * 18));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Player inventory */
|
||
|
|
for (int column = 0; column < 3; column++)
|
||
|
|
{
|
||
|
|
for (int row = 0; row < 9; row++)
|
||
|
|
{
|
||
|
|
this.addSlotToContainer(new Slot(inventoryplayer, row + column * 9 + 9, 8 + row * 18, 84 + column * 18));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
for (int column = 0; column < 9; column++)
|
||
|
|
{
|
||
|
|
this.addSlotToContainer(new Slot(inventoryplayer, column, 8 + column * 18, 142));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public boolean canInteractWith (EntityPlayer entityplayer)
|
||
|
|
{
|
||
|
|
return backpack.isUseableByPlayer(entityplayer);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public ItemStack transferStackInSlot (EntityPlayer player, int slotID)
|
||
|
|
{
|
||
|
|
ItemStack stack = null;
|
||
|
|
Slot slot = (Slot) this.inventorySlots.get(slotID);
|
||
|
|
|
||
|
|
if (slot != null && slot.getHasStack())
|
||
|
|
{
|
||
|
|
ItemStack slotStack = slot.getStack();
|
||
|
|
stack = slotStack.copy();
|
||
|
|
|
||
|
|
if (slotID < backpack.getSizeInventory())
|
||
|
|
{
|
||
|
|
if (!this.mergeItemStack(slotStack, backpack.getSizeInventory(), this.inventorySlots.size(), true))
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (!this.mergeItemStack(slotStack, 0, backpack.getSizeInventory(), false))
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (slotStack.stackSize == 0)
|
||
|
|
{
|
||
|
|
slot.putStack((ItemStack) null);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
slot.onSlotChanged();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return stack;
|
||
|
|
}
|
||
|
|
}
|