Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.robert.aoemod.blocks.towncentergui;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.ClickType;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.EnumFacing;
- import net.minecraftforge.items.CapabilityItemHandler;
- import net.minecraftforge.items.IItemHandler;
- import net.minecraftforge.items.SlotItemHandler;
- public class ContainerTowncenter extends Container {
- public ContainerTowncenter(IInventory playerInv, TileEntityTowncenter te) {
- super();
- IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH);
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 9; j++) {
- addSlotToContainer(new SlotItemHandler(inventory, j + i * 9, 8 + j * 18, 18 + i * 18));
- }
- }
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 9; j++) {
- addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
- }
- }
- for(int i=0;i<9;i++) {
- addSlotToContainer(new Slot(playerInv, i, 8+(18*i), 198));
- }
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int index) {
- ItemStack itemstack = ItemStack.EMPTY;
- Slot slot = inventorySlots.get(index);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- int containerSlots = inventorySlots.size() - player.inventory.mainInventory.size();
- if (index < containerSlots) {
- if (!this.mergeItemStack(itemstack1, containerSlots, inventorySlots.size(), true)) {
- return ItemStack.EMPTY;
- }
- } else if (!this.mergeItemStack(itemstack1, 0, containerSlots, false)) {
- return ItemStack.EMPTY;
- }
- if (itemstack1.getCount() == 0) {
- slot.putStack(ItemStack.EMPTY);
- } else {
- slot.onSlotChanged();
- }
- if (itemstack1.getCount() == itemstack.getCount()) {
- return ItemStack.EMPTY;
- }
- slot.onTake(player, itemstack1);
- }
- return itemstack;
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement