package net.minecraft.world.item;

import net.minecraft.world.level.block.state.StateHolder;
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.LevelAccessor;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.InteractionResult;

public class FireChargeItem extends Item {
    public FireChargeItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext blv) {
        final Level bqb3 = blv.getLevel();
        BlockPos fu4 = blv.getClickedPos();
        final BlockState cfj5 = bqb3.getBlockState(fu4);
        boolean boolean6 = false;
        if (CampfireBlock.canLight(cfj5)) {
            this.playSound(bqb3, fu4);
            bqb3.setBlockAndUpdate(fu4, ((StateHolder<O, BlockState>)cfj5).<Comparable, Boolean>setValue((Property<Comparable>)CampfireBlock.LIT, true));
            boolean6 = true;
        }
        else {
            fu4 = fu4.relative(blv.getClickedFace());
            if (BaseFireBlock.canBePlacedAt(bqb3, fu4)) {
                this.playSound(bqb3, fu4);
                bqb3.setBlockAndUpdate(fu4, BaseFireBlock.getState(bqb3, fu4));
                boolean6 = true;
            }
        }
        if (boolean6) {
            blv.getItemInHand().shrink(1);
            return InteractionResult.sidedSuccess(bqb3.isClientSide);
        }
        return InteractionResult.FAIL;
    }
    
    private void playSound(final Level bqb, final BlockPos fu) {
        bqb.playSound(null, fu, SoundEvents.FIRECHARGE_USE, SoundSource.BLOCKS, 1.0f, (FireChargeItem.random.nextFloat() - FireChargeItem.random.nextFloat()) * 0.2f + 1.0f);
    }
}
