package net.minecraft.world.item;

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.entity.ai.attributes.Attributes;
import com.google.common.collect.ImmutableMultimap;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attribute;
import com.google.common.collect.Multimap;
import net.minecraft.world.level.block.Block;
import java.util.Set;

public class DiggerItem extends TieredItem implements Vanishable {
    private final Set<Block> blocks;
    protected final float speed;
    private final float attackDamageBaseline;
    private final Multimap<Attribute, AttributeModifier> defaultModifiers;
    
    protected DiggerItem(final float float1, final float float2, final Tier blo, final Set<Block> set, final Properties a) {
        super(blo, a);
        this.blocks = set;
        this.speed = blo.getSpeed();
        this.attackDamageBaseline = float1 + blo.getAttackDamageBonus();
        final ImmutableMultimap.Builder<Attribute, AttributeModifier> builder7 = ImmutableMultimap.<Attribute, AttributeModifier>builder();
        builder7.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(DiggerItem.BASE_ATTACK_DAMAGE_UUID, "Tool modifier", this.attackDamageBaseline, AttributeModifier.Operation.ADDITION));
        builder7.put(Attributes.ATTACK_SPEED, new AttributeModifier(DiggerItem.BASE_ATTACK_SPEED_UUID, "Tool modifier", float2, AttributeModifier.Operation.ADDITION));
        this.defaultModifiers = builder7.build();
    }
    
    @Override
    public float getDestroySpeed(final ItemStack bki, final BlockState cfj) {
        return this.blocks.contains(cfj.getBlock()) ? this.speed : 1.0f;
    }
    
    @Override
    public boolean hurtEnemy(final ItemStack bki, final LivingEntity aoy2, final LivingEntity aoy3) {
        bki.<LivingEntity>hurtAndBreak(2, aoy3, aoy -> aoy.broadcastBreakEvent(EquipmentSlot.MAINHAND));
        return true;
    }
    
    @Override
    public boolean mineBlock(final ItemStack bki, final Level bqb, final BlockState cfj, final BlockPos fu, final LivingEntity aoy) {
        if (!bqb.isClientSide && cfj.getDestroySpeed(bqb, fu) != 0.0f) {
            bki.<LivingEntity>hurtAndBreak(1, aoy, aoy -> aoy.broadcastBreakEvent(EquipmentSlot.MAINHAND));
        }
        return true;
    }
    
    @Override
    public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(final EquipmentSlot aor) {
        if (aor == EquipmentSlot.MAINHAND) {
            return this.defaultModifiers;
        }
        return super.getDefaultAttributeModifiers(aor);
    }
    
    public float getAttackDamage() {
        return this.attackDamageBaseline;
    }
}
