package hmggirlfront.gui;
 

import gvclib.item.ItemGunBase;
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;
 
public class GFContainerInventoryItemSquad extends Container
{
    private GFInventoryItemSquad inventory;
 
    private IInventory holderInventory;
    
    public GFContainerInventoryItemSquad(InventoryPlayer inventoryPlayer, ItemStack itemstack)
    {
    	inventory = new GFInventoryItemSquad(inventoryPlayer, itemstack);
        inventory.openInventory();
        {
            {
                //this.addSlotToContainer(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18));
            	this.addSlotToContainer(new Slot(inventory, 1, 62, 18));
            	this.addSlotToContainer(new Slot(inventory, 2, 80, 18));
            	
            	this.addSlotToContainer(new Slot(inventory, 3, 62, 36));
            	this.addSlotToContainer(new Slot(inventory, 4, 80, 36));
            	this.addSlotToContainer(new Slot(inventory, 5, 98, 36));
            	this.addSlotToContainer(new Slot(inventory, 6, 116, 36));
            	
            	this.addSlotToContainer(new Slot(inventory, 7, 62, 54));
            	/*this.addSlotToContainer(new Slot(inventory, 1, 8 + 5 * 18, 18 + 1 * 18));
            	this.addSlotToContainer(new Slot(inventory, 2, 8 + 2 * 18, 18 + 1 * 18));
            	this.addSlotToContainer(new Slot(inventory, 3, 8 + 0 * 18, 18 + 4 * 18));
            	this.addSlotToContainer(new Slot(inventory, 4, 8 + 2 * 18, 18 + 5 * 18));
            	
            	this.addSlotToContainer(new Slot(inventory, 5, 8 + 7 * 18, 18 + 5 * 18));*/
            }
        }
 
       /* int i = 2 * 18 + 1;
        for (int j = 0; j < 3; ++j)
        {
            for (int k = 0; k < 9; ++k)
            {
                this.addSlotToContainer(new GVCSlotInventoryItemSquad(inventoryPlayer, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
            }
        }
 
        for (int j = 0; j < 9; ++j)
        {
            this.addSlotToContainer(new GVCSlotInventoryItemSquad(inventoryPlayer, j, 8 + j * 18, 161 + i));
        }*/
        for (int i1 = 0; i1 < 3; ++i1)
        {
            for (int k1 = 0; k1 < 9; ++k1)
            {
                this.addSlotToContainer(new GFSlotInventoryItemSquad(inventoryPlayer, k1 + i1 * 9 + 9, 8 + k1 * 18, 102 + i1 * 18 + -18));
            }
        }

        for (int j1 = 0; j1 < 9; ++j1)
        {
            this.addSlotToContainer(new GFSlotInventoryItemSquad(inventoryPlayer, j1, 8 + j1 * 18, 142));
        }

        //System.out.println(String.format("open"));
    }
 

    /**
     * Determines whether supplied player can use this container
     */
    public boolean canInteractWith(EntityPlayer playerIn)
    {
        return this.inventory.isUsableByPlayer(playerIn);
    }
 
    @Override
    public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
    {
    	 ItemStack itemstack = ItemStack.EMPTY;
        Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);
 
        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();
 
            if (p_82846_2_ < this.inventory.getSizeInventory())
            {
                if (!this.mergeItemStack(itemstack1, this.inventory.getSizeInventory(), this.inventorySlots.size(), true))
                {
                	return ItemStack.EMPTY;
                }
            }
            //シフトクリック時に、このアイテムだったら動かさない。
            else if(slot.getStack() != ItemStack.EMPTY && slot.getStack().getItem()instanceof ItemGunBase)
            {
            	return ItemStack.EMPTY;
            }
            else if (!this.mergeItemStack(itemstack1, 0, this.inventory.getSizeInventory(), false))
            {
            	return ItemStack.EMPTY;
            }
            if (itemstack1.getCount() == 0)
            {
                slot.putStack(ItemStack.EMPTY);
            }
            else
            {
                slot.onSlotChanged();
            }
        }
 
        return itemstack;
    }
 
    /*
        Containerを閉じるときに呼ばれる
     */
    @Override
    public void onContainerClosed(EntityPlayer p_75134_1_)
    {
        super.onContainerClosed(p_75134_1_);
        this.inventory.closeInventory(p_75134_1_);
    }
    
    /**
     * Return this chest container's lower chest inventory.
     */
    public IInventory getLowerChestInventory()
    {
        return this.inventory;
    }
}