Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package greatblitz.testmod.common.container;
- import greatblitz.testmod.tileentity.TileEntityTestBlock;
- 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;
- import net.minecraftforge.items.CapabilityItemHandler;
- import net.minecraftforge.items.IItemHandler;
- import net.minecraftforge.items.SlotItemHandler;
- public class ContainerTileEntityTestBlock extends Container{
- private TileEntityTestBlock te;
- public ContainerTileEntityTestBlock(InventoryPlayer inv, TileEntityTestBlock te) {
- this.te = te;
- IItemHandler ish = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
- this.addSlotToContainer(new SlotItemHandler(ish, 0, 29, 15));
- this.addSlotToContainer(new SlotItemHandler(ish, 1, 29, 52));
- this.addSlotToContainer(new SlotItemHandler(ish, 2, 129, 37));
- bindPlayerInventory(inv);
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- // TODO Auto-generated method stub
- return true;
- }
- protected void bindPlayerInventory(InventoryPlayer playerInventory) {
- 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 ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
- ItemStack previous = null;
- Slot slot = (Slot) this.inventorySlots.get(fromSlot);
- if (slot != null && slot.getHasStack()) {
- ItemStack current = slot.getStack();
- previous = current.copy();
- if (fromSlot < 3) {
- // From TE Inventory to Player Inventory
- if (!this.mergeItemStack(current, 3, 45, true))
- return null;
- } else {
- // From Player Inventory to TE Inventory
- if (!this.mergeItemStack(current, 0, 3, false))
- return null;
- }
- if (current.stackSize == 0)
- slot.putStack((ItemStack) null);
- else
- slot.onSlotChanged();
- if (current.stackSize == previous.stackSize)
- return null;
- slot.onPickupFromSlot(playerIn, current);
- }
- return previous;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment