package common.block;

import common.entity.npc.EntityNPC;
import common.item.CheatTab;
import common.material.Material;
import common.model.BlockLayer;
import common.model.Model;
import common.model.ModelProvider;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityBeacon;
import common.util.BlockPos;
import common.util.Facing;
import common.world.State;
import common.world.World;

public class BlockBeacon extends BlockContainer
{
	private static final Model beacon = ModelProvider.getModelProvider().getModel("glass").noOcclude()
			.add(0, 0, 0, 16, 16, 16)
				.d().uv(0, 0, 16, 16).noCull()
				.u().uv(0, 0, 16, 16).noCull()
				.n().uv(0, 0, 16, 16).noCull()
				.s().uv(0, 0, 16, 16).noCull()
				.w().uv(0, 0, 16, 16).noCull()
				.e().uv(0, 0, 16, 16).noCull()
			.add(2, 0.1f, 2, 14, 3, 14)
				.d("obsidian").uv(2, 2, 14, 14).noCull()
				.u("obsidian").uv(2, 2, 14, 14).noCull()
				.n("obsidian").uv(2, 13, 14, 16).noCull()
				.s("obsidian").uv(2, 13, 14, 16).noCull()
				.w("obsidian").uv(2, 13, 14, 16).noCull()
				.e("obsidian").uv(2, 13, 14, 16).noCull()
			.add(3, 3, 3, 13, 14, 13)
				.d("beacon").uv(3, 3, 13, 13).noCull()
				.u("beacon").uv(3, 3, 13, 13).noCull()
				.n("beacon").uv(3, 2, 13, 13).noCull()
				.s("beacon").uv(3, 2, 13, 13).noCull()
				.w("beacon").uv(3, 2, 13, 13).noCull()
				.e("beacon").uv(3, 2, 13, 13).noCull()
	;
	
    public BlockBeacon()
    {
        super(Material.glass);
        this.setHardness(3.0F);
        this.setTab(CheatTab.tabTech);
    }

    /**
     * Returns a new instance of a block's tile entity class. Called on placing the block.
     */
    public TileEntity createNewTileEntity(World worldIn, int meta)
    {
        return new TileEntityBeacon();
    }

    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
        {
//            TileEntity tileentity = worldIn.getTileEntity(pos);
//
//            if (tileentity instanceof TileEntityBeacon)
//            {
//                playerIn.displayGUIChest((TileEntityBeacon)tileentity);
////                playerIn.triggerAchievement(StatRegistry.beaconStat);
//            }

            return true;
        }
    }

    /**
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
     */
    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean isFullCube()
    {
        return false;
    }

    /**
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
     */
    public int getRenderType()
    {
        return 3;
    }

    /**
     * Called by ItemBlocks after a block is set in the world, to allow post-place logic
     */
//    public void onBlockPlacedBy(World worldIn, BlockPos pos, State state, EntityLiving placer, ItemStack stack)
//    {
//        super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
//
//        if (stack.hasDisplayName())
//        {
//            TileEntity tileentity = worldIn.getTileEntity(pos);
//
//            if (tileentity instanceof TileEntityBeacon)
//            {
//                ((TileEntityBeacon)tileentity).setName(stack.getDisplayName());
//            }
//        }
//    }

    /**
     * Called when a neighboring block changes.
     */
    public void onNeighborBlockChange(World worldIn, BlockPos pos, State state, Block neighborBlock)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof TileEntityBeacon)
        {
            ((TileEntityBeacon)tileentity).updateBeacon();
//            worldIn.addBlockEvent(pos, this, 1, 0);
        }
    }

    public BlockLayer getBlockLayer()
    {
        return BlockLayer.CUTOUT;
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return beacon;
    }
}
