package common.block.tech;

import common.block.Block;
import common.block.Material;
import common.entity.npc.EntityNPC;
import common.init.BlockRegistry;
import common.inventory.Container;
import common.inventory.ContainerWorkbench;
import common.inventory.InventoryPlayer;
import common.item.CheatTab;
import common.model.Model;
import common.model.ModelProvider;
import common.tileentity.IInteractionObject;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import common.world.World;

public class BlockWorkbench extends Block
{
	private final int size;
	
	public BlockWorkbench(int size)
    {
        super(Material.WOOD);
        this.setTab(CheatTab.TECHNOLOGY);
        this.size = size;
    }
	
	public int getSize() {
		return this.size;
	}

    public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
    {
        if (worldIn.client)
        {
            return true;
        }
        else
        {
            playerIn.displayGui(new BlockWorkbench.InterfaceCraftingTable(worldIn, pos, this));
//            playerIn.triggerAchievement(StatRegistry.craftingTableStat);
            return true;
        }
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return provider.getModel("crafting_table_front").add().d("oak_planks").u("crafting_table_top").n().s("crafting_table_side")
    			.w().e("crafting_table_side");
    }

    public static class InterfaceCraftingTable implements IInteractionObject
    {
        private final World world;
        private final BlockPos position;
        private final BlockWorkbench block;

        public InterfaceCraftingTable(World worldIn, BlockPos pos, BlockWorkbench block)
        {
            this.world = worldIn;
            this.position = pos;
            this.block = block;
        }
        
        public String getCommandName()
        {
            return this.block.getDisplay();
        }

        public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
        {
            return new ContainerWorkbench(playerInventory, this.world, this.position, this.block);
        }

        public String getGuiID()
        {
            return BlockRegistry.getNameFromBlock(this.block);
        }
    }
}
