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.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.Block;
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;

public class SwordItem extends TieredItem {
    private final float attackDamage;
    private final float attackSpeed;
    
    public SwordItem(final Tier bfs, final int integer, final float float3, final Properties a) {
        super(bfs, a);
        this.attackSpeed = float3;
        this.attackDamage = integer + bfs.getAttackDamageBonus();
    }
    
    public float getDamage() {
        return this.attackDamage;
    }
    
    @Override
    public boolean canAttackBlock(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj) {
        return !ayj.isCreative();
    }
    
    @Override
    public float getDestroySpeed(final ItemStack ben, final BlockState byj) {
        final Block bph4 = byj.getBlock();
        if (bph4 == Blocks.COBWEB) {
            return 15.0f;
        }
        final Material coo5 = byj.getMaterial();
        if (coo5 == Material.PLANT || coo5 == Material.REPLACEABLE_PLANT || coo5 == Material.CORAL || byj.is(BlockTags.LEAVES) || coo5 == Material.VEGETABLE) {
            return 1.5f;
        }
        return 1.0f;
    }
    
    @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 boolean mineBlock(final ItemStack ben, final Level bjw, final BlockState byj, final BlockPos fk, final LivingEntity akz) {
        if (byj.getDestroySpeed(bjw, fk) != 0.0f) {
            ben.<LivingEntity>hurtAndBreak(2, akz, akz -> akz.broadcastBreakEvent(EquipmentSlot.MAINHAND));
        }
        return true;
    }
    
    @Override
    public boolean canDestroySpecial(final BlockState byj) {
        return byj.getBlock() == Blocks.COBWEB;
    }
    
    @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(SwordItem.BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", this.attackDamage, AttributeModifier.Operation.ADDITION));
            multimap3.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(SwordItem.BASE_ATTACK_SPEED_UUID, "Weapon modifier", this.attackSpeed, AttributeModifier.Operation.ADDITION));
        }
        return multimap3;
    }
}
