package info.jbcs.minecraft.chisel;

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 ContainerChisel extends Container {
	final InventoryChiselSelection inventory;

	public ContainerChisel(InventoryPlayer inventoryplayer, InventoryChiselSelection inv) {
		inventory = inv;

		int[] leftOffsets = { 8, 26, 134, 152 };
		int[] topOffsets = { 8, 26, 44, 62 };

		int index = 0;
		for (int i = 0; i < 2; i++) {
			for (int y = 0; y < 4; y++) {
				for (int x = 0; x < 2; x++) {
					addSlotToContainer(new SlotChiselSelection(inventory, inventory, x + i * 8 + y * 2, leftOffsets[x+i*2], topOffsets[y]));
				}
			}
		}

		addSlotToContainer(new SlotChiselInput(inventory, 16, 80, 35));

		for (int k = 0; k < 3; k++) {
			for (int j1 = 0; j1 < 9; j1++) {
				addSlotToContainer(new Slot(inventoryplayer, j1 + k * 9 + 9, 8 + j1 * 18, 102 + k * 18 - 18));
			}
		}

		for (int l = 0; l < 9; l++) {
			addSlotToContainer(new Slot(inventoryplayer, l, 8 + l * 18, 160 - 18));
		}
	}

	@Override
	public void onCraftGuiClosed(EntityPlayer entityplayer) {
		if (inventory.getStackInSlot(16) != null) {
			entityplayer.dropPlayerItem(inventory.getStackInSlot(16));
		}
		inventory.clearItems();
		super.onCraftGuiClosed(entityplayer);
	}

	@Override
	public boolean canInteractWith(EntityPlayer entityplayer) {
		return inventory.isUseableByPlayer(entityplayer);
	}

	@Override
	public ItemStack transferStackInSlot(EntityPlayer entity, int i) {
		return null;
	}
}
