package net.minecraft.world.item;

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.level.BlockGetter;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Block;
import java.util.Set;

public class DiggerItem extends TieredItem {
    private final Set<Block> blocks;
    protected final float speed;
    protected final float attackDamage;
    protected final float attackSpeed;
    
    protected DiggerItem(final float float1, final float float2, final Tier bfs, final Set<Block> set, final Properties a) {
        super(bfs, a);
        this.blocks = set;
        this.speed = bfs.getSpeed();
        this.attackDamage = float1 + bfs.getAttackDamageBonus();
        this.attackSpeed = float2;
    }
    
    @Override
    public float getDestroySpeed(final ItemStack ben, final BlockState byj) {
        return this.blocks.contains(byj.getBlock()) ? this.speed : 1.0f;
    }
    
    @Override
    public boolean hurtEnemy(final ItemStack ben, final LivingEntity akz2, final LivingEntity akz3) {
        ben.<LivingEntity>hurtAndBreak(2, akz3, akz -> akz.broadcastBreakEvent(EquipmentSlot.MAINHAND));
        return true;
    }
    
    @Override
    public boolean mineBlock(final ItemStack ben, final Level bjw, final BlockState byj, final BlockPos fk, final LivingEntity akz) {
        if (!bjw.isClientSide && byj.getDestroySpeed(bjw, fk) != 0.0f) {
            ben.<LivingEntity>hurtAndBreak(1, akz, 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(DiggerItem.BASE_ATTACK_DAMAGE_UUID, "Tool modifier", this.attackDamage, AttributeModifier.Operation.ADDITION));
            multimap3.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(DiggerItem.BASE_ATTACK_SPEED_UUID, "Tool modifier", this.attackSpeed, AttributeModifier.Operation.ADDITION));
        }
        return multimap3;
    }
}
