package common.block;

import common.entity.npc.EntityNPC;
import common.inventory.Container;
import common.inventory.ContainerWorkbench;
import common.inventory.InventoryPlayer;
import common.item.CheatTab;
import common.material.Material;
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
{
	public BlockWorkbench()
    {
        super(Material.wood);
        this.setTab(CheatTab.tabTech);
    }

    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));
//            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;

        public InterfaceCraftingTable(World worldIn, BlockPos pos)
        {
            this.world = worldIn;
            this.position = pos;
        }

        public String getName()
        {
            return null;
        }

        public boolean hasCustomName()
        {
            return false;
        }

        public String getCommandName()
        {
            return "Werkbank";
        }

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

        public String getGuiID()
        {
            return "crafting_table";
        }
    }
}
