package common.item.block;

import common.block.foliage.BlockLilyPad;
import common.block.liquid.BlockLiquid;
import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.item.ItemStack;
import common.util.BlockPos;
import common.util.HitPosition;
import common.world.State;
import common.world.World;

public class ItemLilyPad extends ItemColored
{
    public ItemLilyPad(BlockLilyPad block)
    {
        super(block, "");
    }
    
    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(BlockLilyPad.FACING, playerIn.getHorizontalFacing().getOpposite()));

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

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

            return itemStackIn;
        }
    }
}
