package net.minecraft.world.item;

import net.minecraft.world.level.block.state.StateHolder;
import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import java.util.Map;
import net.minecraft.world.level.block.Block;
import java.util.Set;

public class ShovelItem extends DiggerItem {
    private static final Set<Block> DIGGABLES;
    protected static final Map<Block, BlockState> FLATTENABLES;
    
    public ShovelItem(final Tier blo, final float float2, final float float3, final Properties a) {
        super(float2, float3, blo, ShovelItem.DIGGABLES, a);
    }
    
    @Override
    public boolean isCorrectToolForDrops(final BlockState cfj) {
        return cfj.is(Blocks.SNOW) || cfj.is(Blocks.SNOW_BLOCK);
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext blv) {
        final Level bqb3 = blv.getLevel();
        final BlockPos fu4 = blv.getClickedPos();
        final BlockState cfj5 = bqb3.getBlockState(fu4);
        if (blv.getClickedFace() == Direction.DOWN) {
            return InteractionResult.PASS;
        }
        final Player bec2 = blv.getPlayer();
        final BlockState cfj6 = ShovelItem.FLATTENABLES.get(cfj5.getBlock());
        BlockState cfj7 = null;
        if (cfj6 != null && bqb3.getBlockState(fu4.above()).isAir()) {
            bqb3.playSound(bec2, fu4, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0f, 1.0f);
            cfj7 = cfj6;
        }
        else if (cfj5.getBlock() instanceof CampfireBlock && cfj5.<Boolean>getValue((Property<Boolean>)CampfireBlock.LIT)) {
            if (!bqb3.isClientSide()) {
                bqb3.levelEvent(null, 1009, fu4, 0);
            }
            CampfireBlock.dowse(bqb3, fu4, cfj5);
            cfj7 = ((StateHolder<O, BlockState>)cfj5).<Comparable, Boolean>setValue((Property<Comparable>)CampfireBlock.LIT, false);
        }
        if (cfj7 != null) {
            if (!bqb3.isClientSide) {
                bqb3.setBlock(fu4, cfj7, 11);
                if (bec2 != null) {
                    blv.getItemInHand().<Player>hurtAndBreak(1, bec2, bec -> bec.broadcastBreakEvent(blv.getHand()));
                }
            }
            return InteractionResult.sidedSuccess(bqb3.isClientSide);
        }
        return InteractionResult.PASS;
    }
    
    static {
        DIGGABLES = Sets.<Block>newHashSet(Blocks.CLAY, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL, Blocks.FARMLAND, Blocks.GRASS_BLOCK, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.RED_SAND, Blocks.SNOW_BLOCK, Blocks.SNOW, Blocks.SOUL_SAND, Blocks.GRASS_PATH, Blocks.WHITE_CONCRETE_POWDER, Blocks.ORANGE_CONCRETE_POWDER, Blocks.MAGENTA_CONCRETE_POWDER, Blocks.LIGHT_BLUE_CONCRETE_POWDER, Blocks.YELLOW_CONCRETE_POWDER, Blocks.LIME_CONCRETE_POWDER, Blocks.PINK_CONCRETE_POWDER, Blocks.GRAY_CONCRETE_POWDER, Blocks.LIGHT_GRAY_CONCRETE_POWDER, Blocks.CYAN_CONCRETE_POWDER, Blocks.PURPLE_CONCRETE_POWDER, Blocks.BLUE_CONCRETE_POWDER, Blocks.BROWN_CONCRETE_POWDER, Blocks.GREEN_CONCRETE_POWDER, Blocks.RED_CONCRETE_POWDER, Blocks.BLACK_CONCRETE_POWDER, Blocks.SOUL_SOIL);
        FLATTENABLES = Maps.newHashMap(ImmutableMap.<Block, BlockState>of(Blocks.GRASS_BLOCK, Blocks.GRASS_PATH.defaultBlockState()));
    }
}
