package info.jbcs.minecraft.chisel;

import info.jbcs.minecraft.chisel.utilities.InventoryStatic;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class InventoryChiselSelection extends InventoryStatic {
	ItemStack chisel = null;

	public InventoryChiselSelection(ItemStack c) {
		super(17);

		chisel = c;
	}

	@Override
	public String getInvName() {
		return "Carve blocks";
	}

	@Override
	public boolean isUseableByPlayer(EntityPlayer entityplayer) {
		return true;
	}

	@Override
	public void onInventoryChanged() {
	}

	public void clearItems() {
		for (int i = 0; i < 16; i++) {
			items[i] = null;
		}
	}

	public void updateItems() {
		ItemStack chiseledItem = items[16];

		clearItems();

		if (chiseledItem == null)
			return;
		if(chiseledItem.itemID>=Block.blocksList.length)
			return;

		Block block = Block.blocksList[chiseledItem.itemID];

		if (block == null || !(block instanceof Carvable))
			return;

		Carvable carvable = (Carvable) block;

		int count = carvable.variations();
		if (count > 16)
			count = 16;

		for (int j = 0; j < count; j++) {
			items[j] = new ItemStack(block.blockID, 1, carvable.metadata(j));
		}
	}

	@Override
	public ItemStack getStackInSlotOnClosing(int i) {
		return null;
	}

	@Override
	public boolean isInvNameLocalized() {
		return true;
	}

	@Override
	public void openChest() {
	}

	@Override
	public void closeChest() {
	}

	@Override
	public boolean isStackValidForSlot(int i, ItemStack itemstack) {
		return i==16;
	}
}
