package net.minecraft.world.item;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.InteractionResult;

public class FlintAndSteelItem extends Item {
    public FlintAndSteelItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext blv) {
        final Player bec2 = blv.getPlayer();
        final LevelAccessor bqc4 = blv.getLevel();
        final BlockPos fu5 = blv.getClickedPos();
        final BlockState cfj6 = bqc4.getBlockState(fu5);
        if (CampfireBlock.canLight(cfj6)) {
            bqc4.playSound(bec2, fu5, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0f, FlintAndSteelItem.random.nextFloat() * 0.4f + 0.8f);
            bqc4.setBlock(fu5, ((StateHolder<O, BlockState>)cfj6).<Comparable, Boolean>setValue((Property<Comparable>)BlockStateProperties.LIT, true), 11);
            if (bec2 != null) {
                blv.getItemInHand().<Player>hurtAndBreak(1, bec2, bec -> bec.broadcastBreakEvent(blv.getHand()));
            }
            return InteractionResult.sidedSuccess(bqc4.isClientSide());
        }
        final BlockPos fu6 = fu5.relative(blv.getClickedFace());
        if (BaseFireBlock.canBePlacedAt(bqc4, fu6)) {
            bqc4.playSound(bec2, fu6, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0f, FlintAndSteelItem.random.nextFloat() * 0.4f + 0.8f);
            final BlockState cfj7 = BaseFireBlock.getState(bqc4, fu6);
            bqc4.setBlock(fu6, cfj7, 11);
            final ItemStack bki9 = blv.getItemInHand();
            if (bec2 instanceof ServerPlayer) {
                CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer)bec2, fu6, bki9);
                bki9.<Player>hurtAndBreak(1, bec2, bec -> bec.broadcastBreakEvent(blv.getHand()));
            }
            return InteractionResult.sidedSuccess(bqc4.isClientSide());
        }
        return InteractionResult.FAIL;
    }
}
