Advertisement
Guest User

Untitled

a guest
Aug 26th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. package com.robert.aoemod.blocks.towncentergui;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.inventory.ClickType;
  5. import net.minecraft.inventory.Container;
  6. import net.minecraft.inventory.IInventory;
  7. import net.minecraft.inventory.Slot;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.util.EnumFacing;
  10. import net.minecraftforge.items.CapabilityItemHandler;
  11. import net.minecraftforge.items.IItemHandler;
  12. import net.minecraftforge.items.SlotItemHandler;
  13.  
  14. public class ContainerTowncenter extends Container {
  15.  
  16.     public ContainerTowncenter(IInventory playerInv, TileEntityTowncenter te) {
  17.         super();
  18.  
  19.         IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH);
  20.  
  21.         for (int i = 0; i < 6; i++) {
  22.             for (int j = 0; j < 9; j++) {
  23.                 addSlotToContainer(new SlotItemHandler(inventory, j + i * 9, 8 + j * 18, 18 + i * 18));
  24.             }
  25.         }
  26.  
  27.         for (int i = 0; i < 3; i++) {
  28.             for (int j = 0; j < 9; j++) {
  29.                 addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
  30.             }
  31.         }
  32.  
  33.         for(int i=0;i<9;i++) {
  34.             addSlotToContainer(new Slot(playerInv, i, 8+(18*i), 198));
  35.         }
  36.     }
  37.  
  38.     @Override
  39.     public ItemStack transferStackInSlot(EntityPlayer player, int index) {
  40.         ItemStack itemstack = ItemStack.EMPTY;
  41.         Slot slot = inventorySlots.get(index);
  42.  
  43.         if (slot != null && slot.getHasStack()) {
  44.             ItemStack itemstack1 = slot.getStack();
  45.             itemstack = itemstack1.copy();
  46.  
  47.             int containerSlots = inventorySlots.size() - player.inventory.mainInventory.size();
  48.  
  49.             if (index < containerSlots) {
  50.                 if (!this.mergeItemStack(itemstack1, containerSlots, inventorySlots.size(), true)) {
  51.                     return ItemStack.EMPTY;
  52.                 }
  53.             } else if (!this.mergeItemStack(itemstack1, 0, containerSlots, false)) {
  54.                 return ItemStack.EMPTY;
  55.             }
  56.  
  57.             if (itemstack1.getCount() == 0) {
  58.                 slot.putStack(ItemStack.EMPTY);
  59.             } else {
  60.                 slot.onSlotChanged();
  61.             }
  62.  
  63.             if (itemstack1.getCount() == itemstack.getCount()) {
  64.                 return ItemStack.EMPTY;
  65.             }
  66.  
  67.             slot.onTake(player, itemstack1);
  68.         }
  69.  
  70.         return itemstack;
  71.     }
  72.  
  73.     @Override
  74.     public boolean canInteractWith(EntityPlayer playerIn) {
  75.         return true;
  76.     }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement