package net.minecraft.world.item;

import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.entity.monster.SharedMonsterAttributes;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import com.google.common.collect.Multimap;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.player.Player;
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.state.BlockState;
import net.minecraft.world.level.block.Block;
import java.util.Map;

public class HoeItem extends TieredItem {
    private final float attackSpeed;
    protected static final Map<Block, BlockState> TILLABLES;
    
    public HoeItem(final Tier bfs, final float float2, final Properties a) {
        super(bfs, a);
        this.attackSpeed = float2;
    }
    
    @Override
    public InteractionResult useOn(final UseOnContext bfz) {
        final Level bjw3 = bfz.getLevel();
        final BlockPos fk4 = bfz.getClickedPos();
        if (bfz.getClickedFace() != Direction.DOWN && bjw3.getBlockState(fk4.above()).isAir()) {
            final BlockState byj5 = HoeItem.TILLABLES.get(bjw3.getBlockState(fk4).getBlock());
            if (byj5 != null) {
                final Player ayj2 = bfz.getPlayer();
                bjw3.playSound(ayj2, fk4, SoundEvents.HOE_TILL, SoundSource.BLOCKS, 1.0f, 1.0f);
                if (!bjw3.isClientSide) {
                    bjw3.setBlock(fk4, byj5, 11);
                    if (ayj2 != null) {
                        bfz.getItemInHand().<Player>hurtAndBreak(1, ayj2, ayj -> ayj.broadcastBreakEvent(bfz.getHand()));
                    }
                }
                return InteractionResult.SUCCESS;
            }
        }
        return InteractionResult.PASS;
    }
    
    @Override
    public boolean hurtEnemy(final ItemStack ben, final LivingEntity akz2, final LivingEntity akz3) {
        ben.<LivingEntity>hurtAndBreak(1, akz3, akz -> akz.broadcastBreakEvent(EquipmentSlot.MAINHAND));
        return true;
    }
    
    @Override
    public Multimap<String, AttributeModifier> getDefaultAttributeModifiers(final EquipmentSlot akv) {
        final Multimap<String, AttributeModifier> multimap3 = super.getDefaultAttributeModifiers(akv);
        if (akv == EquipmentSlot.MAINHAND) {
            multimap3.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(HoeItem.BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", 0.0, AttributeModifier.Operation.ADDITION));
            multimap3.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(HoeItem.BASE_ATTACK_SPEED_UUID, "Weapon modifier", this.attackSpeed, AttributeModifier.Operation.ADDITION));
        }
        return multimap3;
    }
    
    static {
        TILLABLES = Maps.newHashMap(ImmutableMap.<Block, BlockState>of(Blocks.GRASS_BLOCK, Blocks.FARMLAND.defaultBlockState(), Blocks.GRASS_PATH, Blocks.FARMLAND.defaultBlockState(), Blocks.DIRT, Blocks.FARMLAND.defaultBlockState(), Blocks.COARSE_DIRT, Blocks.DIRT.defaultBlockState()));
    }
}
