package net.minecraft.src;

/**
 * The Crafting Tool device container
 * 
 * @author MightyPork
 * @copy (c) 2012
 */
public class PCco_ContainerCraftingTool extends Container {

	private IInventory playerInventory;
	private int numRows;

	public static ItemStack[] stacklist = new ItemStack[91];

	/**
	 * Fill it with all useful blocks and items
	 */
	static {
		int i = 0;

		for (i = 0; i < PClo_GateType.TOTAL_GATE_COUNT; i++) {
			stacklist[i] = new ItemStack(mod_PClogic.gateOn, 1, i);
		}

		stacklist[i] = new ItemStack(mod_PClogic.pulsar, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCwireless.radioTx, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCwireless.radioRx, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCwireless.portableTx, 1, 0);

		stacklist[++i] = new ItemStack(mod_PCwireless.sensor, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCwireless.sensor, 1, 1);
		stacklist[++i] = new ItemStack(mod_PCwireless.sensor, 1, 2);

		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.RED.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.ORANGE.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.YELLOW.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.LIME.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.CYAN.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.BLUE.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.LIGHTBLUE.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.MAGENTA.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.PURPLE.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.PINK.meta);
		stacklist[++i] = new ItemStack(mod_PClogic.lightOn, 1, PC_Color.dye.WHITE.meta);

		stacklist[++i] = new ItemStack(mod_PCtransport.conveyorBelt, 16, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.ejectionBelt, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.detectionBelt, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.separationBelt, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.brakeBelt, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.redirectionBelt, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.speedyBelt, 16, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.itemElevator, 6, 0);
		stacklist[++i] = new ItemStack(mod_PCtransport.itemElevator, 6, 1);
		stacklist[++i] = new ItemStack(mod_PCtransport.teleporter, 1, 0);

		stacklist[++i] = new ItemStack(mod_PCtransport.automaticWorkbench, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmachines.harvester, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmachines.builder, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmachines.xpbank, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmachines.roaster, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmachines.laser, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmachines.mirrorPlacer, 2, 0);
		stacklist[++i] = new ItemStack(mod_PCmachines.prismPlacer, 1, 0);

		stacklist[++i] = new ItemStack(mod_PCmobile.activator, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmobile.oreSniffer, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerDust, 24, 0);

		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 1);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 0);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 7);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 2);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 6);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 3);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 4);
		stacklist[++i] = new ItemStack(mod_PCmobile.powerCrystal, 1, 5);

		stacklist[++i] = new ItemStack(mod_PCtransport.ironFrame, 16, 0);
		stacklist[++i] = new ItemStack(Item.redstoneRepeater, 1, 0);
		stacklist[++i] = new ItemStack(Block.torchRedstoneActive, 1, 0);
		stacklist[++i] = new ItemStack(Block.lever, 1, 0);
		stacklist[++i] = new ItemStack(Block.button, 1, 0);
		stacklist[++i] = new ItemStack(Block.pressurePlateStone, 1, 0);
		stacklist[++i] = new ItemStack(Block.pressurePlatePlanks, 1, 0);
		stacklist[++i] = new ItemStack(Block.pistonBase, 1, 0);
		stacklist[++i] = new ItemStack(Block.pistonStickyBase, 1, 0);
		stacklist[++i] = new ItemStack(Block.tnt, 1, 0);
		stacklist[++i] = new ItemStack(Block.redstoneLampIdle, 1, 0);
		stacklist[++i] = new ItemStack(Block.chest, 1, 0);
		stacklist[++i] = new ItemStack(Block.stoneOvenIdle, 1, 0);
		stacklist[++i] = new ItemStack(Block.music, 1, 0);
		stacklist[++i] = new ItemStack(Block.dispenser, 1, 0);
		stacklist[++i] = new ItemStack(Block.trapdoor, 2, 0);
		stacklist[++i] = new ItemStack(Item.doorSteel, 1, 0);
		stacklist[++i] = new ItemStack(Item.doorWood, 1, 0);
		stacklist[++i] = new ItemStack(Item.redstone, 1, 0);

	}

	private ItemStack getItemInSlot(int num) {
		if (num < stacklist.length) { return stacklist[num]; }
		return null;
	}

	public PCco_ContainerCraftingTool(EntityPlayer player) {
		playerInventory = player.inventory;
		numRows = 7;

		// crafting slots
		int i = (numRows - 4) * 18;
		for (int j = 0; j < numRows; j++) {
			for (int i1 = 0; i1 < 13; i1++) {
				addSlot(new PCco_SlotDirectCrafting(player, getItemInSlot(i1 + j * 13), i1 + j * 13, 8 + i1 * 18, 18 + j * 18));
			}

		}

		for (int k = 0; k < 3; k++) {
			for (int j1 = 0; j1 < 9; j1++) {
				addSlot(new Slot(playerInventory, j1 + k * 9 + 9, 2 * 18 + 8 + j1 * 18, 103 + k * 18 + i));
			}

		}

		for (int l = 0; l < 9; l++) {
			addSlot(new Slot(playerInventory, l, 2 * 18 + 8 + l * 18, 161 + i));
		}

	}

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

	@Override
	protected void retrySlotClick(int i, int j, boolean flag, EntityPlayer entityplayer) {
		// no SHIFT!
	}

	@Override
	public void onCraftGuiClosed(EntityPlayer entityplayer) {
		super.onCraftGuiClosed(entityplayer);
		playerInventory.closeChest();
	}

}
