package net.minecraft.world.item;

import net.minecraft.world.level.block.state.AbstractStateHolder;
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.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 bfs, final float float2, final float float3, final Properties a) {
        super(float2, float3, bfs, ShovelItem.DIGGABLES, a);
    }
    
    @Override
    public boolean canDestroySpecial(final BlockState byj) {
        final Block bph3 = byj.getBlock();
        return bph3 == Blocks.SNOW || bph3 == Blocks.SNOW_BLOCK;
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext bfz) {
        final Level bjw3 = bfz.getLevel();
        final BlockPos fk4 = bfz.getClickedPos();
        final BlockState byj5 = bjw3.getBlockState(fk4);
        if (bfz.getClickedFace() == Direction.DOWN) {
            return InteractionResult.PASS;
        }
        final Player ayj2 = bfz.getPlayer();
        final BlockState byj6 = ShovelItem.FLATTENABLES.get(byj5.getBlock());
        BlockState byj7 = null;
        if (byj6 != null && bjw3.getBlockState(fk4.above()).isAir()) {
            bjw3.playSound(ayj2, fk4, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0f, 1.0f);
            byj7 = byj6;
        }
        else if (byj5.getBlock() instanceof CampfireBlock && byj5.<Boolean>getValue((Property<Boolean>)CampfireBlock.LIT)) {
            bjw3.levelEvent(null, 1009, fk4, 0);
            byj7 = ((AbstractStateHolder<O, BlockState>)byj5).<Comparable, Boolean>setValue((Property<Comparable>)CampfireBlock.LIT, false);
        }
        if (byj7 != null) {
            if (!bjw3.isClientSide) {
                bjw3.setBlock(fk4, byj7, 11);
                if (ayj2 != null) {
                    bfz.getItemInHand().<Player>hurtAndBreak(1, ayj2, ayj -> ayj.broadcastBreakEvent(bfz.getHand()));
                }
            }
            return InteractionResult.SUCCESS;
        }
        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);
        FLATTENABLES = Maps.newHashMap(ImmutableMap.<Block, BlockState>of(Blocks.GRASS_BLOCK, Blocks.GRASS_PATH.defaultBlockState()));
    }
}
