package net.minecraft.world.item;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.FireBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.InteractionResult;

public class FireChargeItem extends Item {
    public FireChargeItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext bfz) {
        final Level bjw3 = bfz.getLevel();
        BlockPos fk4 = bfz.getClickedPos();
        final BlockState byj5 = bjw3.getBlockState(fk4);
        boolean boolean6 = false;
        if (byj5.getBlock() == Blocks.CAMPFIRE) {
            if (!byj5.<Boolean>getValue((Property<Boolean>)CampfireBlock.LIT) && !byj5.<Boolean>getValue((Property<Boolean>)CampfireBlock.WATERLOGGED)) {
                this.playSound(bjw3, fk4);
                bjw3.setBlockAndUpdate(fk4, ((AbstractStateHolder<O, BlockState>)byj5).<Comparable, Boolean>setValue((Property<Comparable>)CampfireBlock.LIT, true));
                boolean6 = true;
            }
        }
        else {
            fk4 = fk4.relative(bfz.getClickedFace());
            if (bjw3.getBlockState(fk4).isAir()) {
                this.playSound(bjw3, fk4);
                bjw3.setBlockAndUpdate(fk4, ((FireBlock)Blocks.FIRE).getStateForPlacement(bjw3, fk4));
                boolean6 = true;
            }
        }
        if (boolean6) {
            bfz.getItemInHand().shrink(1);
            return InteractionResult.SUCCESS;
        }
        return InteractionResult.FAIL;
    }
    
    private void playSound(final Level bjw, final BlockPos fk) {
        bjw.playSound(null, fk, SoundEvents.FIRECHARGE_USE, SoundSource.BLOCKS, 1.0f, (FireChargeItem.random.nextFloat() - FireChargeItem.random.nextFloat()) * 0.2f + 1.0f);
    }
}
