package common.item;

import common.block.Block;
import common.entity.Entity;
import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.util.BlockPos;
import common.util.Facing;
import common.world.World;

public class ItemRedstone extends Item
{
    public ItemRedstone()
    {
        this.setTab(CheatTab.tabTech);
    }

    public Block getBlock()
    {
        return Blocks.redstone;
    }

    /**
     * Called when a Block is right-clicked with this Item
     */
    public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
    {
        boolean flag = worldIn.getState(pos).getBlock().isReplaceable(worldIn, pos);
        BlockPos blockpos = flag ? pos : pos.offset(side);

        if (!playerIn.canPlayerEdit(blockpos, side, stack))
        {
            return false;
        }
        else
        {
            Block block = worldIn.getState(blockpos).getBlock();

            if (!worldIn.canBlockBePlaced(block, blockpos, false, side, (Entity)null, stack))
            {
                return false;
            }
            else if (Blocks.redstone.canPlaceBlockAt(worldIn, blockpos))
            {
                --stack.stackSize;
                worldIn.setState(blockpos, Blocks.redstone.getState());
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    
    public boolean isMagnetic() {
    	return true;
    }
}
