Skip to content

Commit

Permalink
Fix Swords not performing damage to mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonymendez committed Aug 13, 2024
1 parent d9d1c60 commit 7a0686f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions common/src/main/java/com/anthonymendez/items/SimpleSwordItem.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.anthonymendez.items;

import com.mojang.datafixers.util.Pair;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.text.Text;

import java.util.List;

public class SimpleSwordItem extends SwordItem implements ISimpleTool {
public static final float BASE_ATTACK_DAMAGE = 4.0F;
public static final float BASE_ATTACK_SPEED = 1.6F;

private final float attackDamage;
private final float attackSpeed;

Expand All @@ -20,7 +24,8 @@ public class SimpleSwordItem extends SwordItem implements ISimpleTool {
public SimpleSwordItem(ToolMaterial material) {
super(material, new Settings());
Pair<Float, Float> attackDamageAndSpeed =
SimpleToolUtils.getAttackDamageAndSpeedFromSwordItem(this, 4.0F, 1.6F);
SimpleToolUtils.getAttackDamageAndSpeedFromSwordItem(
this, BASE_ATTACK_DAMAGE, BASE_ATTACK_SPEED);
this.attackDamage = attackDamageAndSpeed.getFirst();
this.attackSpeed = attackDamageAndSpeed.getSecond();
}
Expand All @@ -44,4 +49,10 @@ public void appendTooltip(
super.appendTooltip(stack, context, tooltip, type);
SimpleToolUtils.AppendDefaultMinecraftMiningItemTooltip(tooltip, attackDamage, attackSpeed);
}

@Override
public float getBonusAttackDamage(
Entity target, float baseAttackDamage, DamageSource damageSource) {
return attackDamage;
}
}

0 comments on commit 7a0686f

Please sign in to comment.