package net.minecraft.world.item;

import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.Block;
import net.minecraft.tags.Tag;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.entity.player.Player;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
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;

public class SwordItem extends TieredItem implements Vanishable {
    private final float attackDamage;
    private final Multimap<Attribute, AttributeModifier> defaultModifiers;
    
    public SwordItem(final Tier blo, final int integer, final float float3, final Properties a) {
        super(blo, a);
        this.attackDamage = integer + blo.getAttackDamageBonus();
        final ImmutableMultimap.Builder<Attribute, AttributeModifier> builder6 = ImmutableMultimap.<Attribute, AttributeModifier>builder();
        builder6.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(SwordItem.BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", this.attackDamage, AttributeModifier.Operation.ADDITION));
        builder6.put(Attributes.ATTACK_SPEED, new AttributeModifier(SwordItem.BASE_ATTACK_SPEED_UUID, "Weapon modifier", float3, AttributeModifier.Operation.ADDITION));
        this.defaultModifiers = builder6.build();
    }
    
    public float getDamage() {
        return this.attackDamage;
    }
    
    @Override
    public boolean canAttackBlock(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec) {
        return !bec.isCreative();
    }
    
    @Override
    public float getDestroySpeed(final ItemStack bki, final BlockState cfj) {
        if (cfj.is(Blocks.COBWEB)) {
            return 15.0f;
        }
        final Material cxd4 = cfj.getMaterial();
        if (cxd4 == Material.PLANT || cxd4 == Material.REPLACEABLE_PLANT || cxd4 == Material.CORAL || cfj.is(BlockTags.LEAVES) || cxd4 == Material.VEGETABLE) {
            return 1.5f;
        }
        return 1.0f;
    }
    
    @Override
    public boolean hurtEnemy(final ItemStack bki, final LivingEntity aoy2, final LivingEntity aoy3) {
        bki.<LivingEntity>hurtAndBreak(1, 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 (cfj.getDestroySpeed(bqb, fu) != 0.0f) {
            bki.<LivingEntity>hurtAndBreak(2, aoy, aoy -> aoy.broadcastBreakEvent(EquipmentSlot.MAINHAND));
        }
        return true;
    }
    
    @Override
    public boolean isCorrectToolForDrops(final BlockState cfj) {
        return cfj.is(Blocks.COBWEB);
    }
    
    @Override
    public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(final EquipmentSlot aor) {
        if (aor == EquipmentSlot.MAINHAND) {
            return this.defaultModifiers;
        }
        return super.getDefaultAttributeModifiers(aor);
    }
}
