package common.item;

import common.block.Block;
import common.block.BlockDirectional;
import common.block.BlockLiquid;
import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.util.BlockPos;
import common.util.HitPosition;
import common.world.State;
import common.world.World;

public class ItemLilyPad extends ItemColored
{
    public ItemLilyPad(Block block)
    {
        super(block, false, "");
    }
    
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
    {
        HitPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);

        if (movingobjectposition == null)
        {
            return itemStackIn;
        }
        else
        {
            if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
            {
                BlockPos blockpos = movingobjectposition.block;

                if (!World.isValidXZ(blockpos))
                {
                    return itemStackIn;
                }

                if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.side), movingobjectposition.side, itemStackIn))
                {
                    return itemStackIn;
                }

                BlockPos blockpos1 = blockpos.up();
                State iblockstate = worldIn.getState(blockpos);

                if (iblockstate.getBlock().getMaterial().isColdLiquid() && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
                {
                    worldIn.setState(blockpos1, Blocks.waterlily.getState().withProperty(BlockDirectional.FACING, playerIn.getHorizontalFacing().getOpposite()));

//                    if (!playerIn.creative)
//                    {
                    --itemStackIn.stackSize;
//                    }

//                    playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
                }
            }

            return itemStackIn;
        }
    }

    public int getColorFromItemStack(ItemStack stack, int renderPass)
    {
        return Blocks.waterlily.getRenderColor(Blocks.waterlily.getStateFromMeta(stack.getMetadata()));
    }
}
