package common.block;

import common.init.Items;
import common.item.Item;
import common.material.Material;
import common.rng.Random;
import common.tileentity.TileEntity;
import common.tileentity.TileEntitySign;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.world.IBlockAccess;
import common.world.State;
import common.world.World;

public class BlockSign extends BlockContainer
{
	public BlockSign()
    {
        super(Material.wood);
        float f = 0.25F;
        float f1 = 1.0F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
    }

    public BoundingBox getCollisionBoundingBox(World worldIn, BlockPos pos, State state)
    {
        return null;
    }

    public BoundingBox getSelectedBoundingBox(World worldIn, BlockPos pos)
    {
        this.setBlockBoundsBasedOnState(worldIn, pos);
        return super.getSelectedBoundingBox(worldIn, pos);
    }

    public boolean isFullCube()
    {
        return false;
    }

    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
    {
        return true;
    }

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

    /**
     * Return true if an entity can be spawned inside the block (used to get the player's bed spawn location)
     */
    public boolean canSpawnInBlock()
    {
        return true;
    }

    /**
     * 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 TileEntitySign();
    }

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(State state, Random rand, int fortune)
    {
        return Items.sign;
    }

    public Item getItem(World worldIn, BlockPos pos)
    {
        return Items.sign;
    }

//    public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
//    {
//        if (worldIn.client)
//        {
//        	TileEntity tileentity = worldIn.getTileEntity(pos);
//            if(tileentity instanceof TileEntitySign) {
//            	String command = ((TileEntitySign)tileentity).command;
//            	if(command != null)
//            		playerIn.sendSignCommand(command);
//            }
//        }
//        return true;
//    }

//    public void onBlockRemoved(IWorldServer worldIn, BlockPos pos, State state)
//    {
//    	if(!worldIn.client) {
//	        TileEntity tileentity = worldIn.getTileEntity(pos);
//	        if(tileentity instanceof TileEntitySign)
//	            Server.getServer().getSigns().removeEntry(new WorldPos(tileentity).toString()); //TODO: nosave??
//    	}
//    	super.onBlockRemoved(worldIn, pos, state);
//    }

    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return !this.hasInvalidNeighbor(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos);
    }
    
    public boolean isXrayVisible()
    {
        return true;
    }
}
