package net.minecraft.world.item;

import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.block.Block;

public class WaterLilyBlockItem extends BlockItem {
    public WaterLilyBlockItem(final Block bph, final Properties a) {
        super(bph, a);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext bfz) {
        return InteractionResult.PASS;
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bjw, final Player ayj, final InteractionHand ajk) {
        final ItemStack ben5 = ayj.getItemInHand(ajk);
        final HitResult cvi6 = Item.getPlayerPOVHitResult(bjw, ayj, ClipContext.Fluid.SOURCE_ONLY);
        if (cvi6.getType() == HitResult.Type.MISS) {
            return InteractionResultHolder.<ItemStack>pass(ben5);
        }
        if (cvi6.getType() == HitResult.Type.BLOCK) {
            final BlockHitResult cvg7 = (BlockHitResult)cvi6;
            final BlockPos fk8 = cvg7.getBlockPos();
            final Direction fp9 = cvg7.getDirection();
            if (!bjw.mayInteract(ayj, fk8) || !ayj.mayUseItemAt(fk8.relative(fp9), fp9, ben5)) {
                return InteractionResultHolder.<ItemStack>fail(ben5);
            }
            final BlockPos fk9 = fk8.above();
            final BlockState byj11 = bjw.getBlockState(fk8);
            final Material coo12 = byj11.getMaterial();
            final FluidState coj13 = bjw.getFluidState(fk8);
            if ((coj13.getType() == Fluids.WATER || coo12 == Material.ICE) && bjw.isEmptyBlock(fk9)) {
                bjw.setBlock(fk9, Blocks.LILY_PAD.defaultBlockState(), 11);
                if (ayj instanceof ServerPlayer) {
                    CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer)ayj, fk9, ben5);
                }
                if (!ayj.abilities.instabuild) {
                    ben5.shrink(1);
                }
                ayj.awardStat(Stats.ITEM_USED.get(this));
                bjw.playSound(ayj, fk8, SoundEvents.LILY_PAD_PLACE, SoundSource.BLOCKS, 1.0f, 1.0f);
                return InteractionResultHolder.<ItemStack>success(ben5);
            }
        }
        return InteractionResultHolder.<ItemStack>fail(ben5);
    }
}
