From 34f96dc68781553c240aa16a244a896049dfbeca Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 28 Nov 2025 13:32:35 -0800 Subject: [PATCH] add Spears interactions to CombatUtils --- .../com/gmail/nossr50/util/ItemUtils.java | 54 ++++++++++++++----- .../gmail/nossr50/util/MaterialMapStore.java | 30 +++++++++-- .../nossr50/util/skills/CombatUtils.java | 45 ++++++++++++++++ 3 files changed, 111 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/ItemUtils.java b/src/main/java/com/gmail/nossr50/util/ItemUtils.java index 50138ea68..c118ad960 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ItemUtils.java @@ -166,20 +166,6 @@ public final class ItemUtils { } } - // TODO: Unit tests - public static boolean isCrossbow(@NotNull ItemStack item) { - return mcMMO.getMaterialMapStore().isCrossbow(item.getType().getKey().getKey()); - } - - // TODO: Unit tests - public static boolean isTrident(@NotNull ItemStack item) { - return mcMMO.getMaterialMapStore().isTrident(item.getType().getKey().getKey()); - } - - public static boolean isMace(@NotNull ItemStack item) { - return mcMMO.getMaterialMapStore().isMace(item.getType().getKey().getKey()); - } - public static boolean hasItemInEitherHand(@NotNull Player player, Material material) { return player.getInventory().getItemInMainHand().getType() == material || player.getInventory().getItemInOffHand().getType() == material; @@ -276,6 +262,46 @@ public final class ItemUtils { return null; } + /** + * Checks if the item is a crossbow. + * + * @param item Item to check + * @return true if the item is a crossbow, false otherwise + */ + public static boolean isCrossbow(@NotNull ItemStack item) { + return mcMMO.getMaterialMapStore().isCrossbow(item.getType().getKey().getKey()); + } + + /** + * Checks if the item is a trident. + * + * @param item Item to check + * @return true if the item is a trident, false otherwise + */ + public static boolean isTrident(@NotNull ItemStack item) { + return mcMMO.getMaterialMapStore().isTrident(item.getType().getKey().getKey()); + } + + /** + * Checks if the item is a mace. + * + * @param item Item to check + * @return true if the item is a mace, false otherwise + */ + public static boolean isMace(@NotNull ItemStack item) { + return mcMMO.getMaterialMapStore().isMace(item.getType().getKey().getKey()); + } + + /** + * Checks if the item is a spear. + * @param item Item to check + * + * @return true if the item is a spear, false otherwise + */ + public static boolean isSpear(@NotNull ItemStack item) { + return mcMMO.getMaterialMapStore().isSpear(item.getType().getKey().getKey()); + } + /** * Checks if the item is a sword. * diff --git a/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java b/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java index e28380a63..55905dd5f 100644 --- a/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java +++ b/src/main/java/com/gmail/nossr50/util/MaterialMapStore.java @@ -51,9 +51,10 @@ public class MaterialMapStore { private final @NotNull HashSet tridents; private final @NotNull HashSet bows; private final @NotNull HashSet crossbows; - private final @NotNull HashSet tools; - private final @NotNull HashSet enchantables; private final @NotNull HashSet maces; + private final @NotNull HashSet spears; + private final @NotNull HashSet enchantables; + private final @NotNull HashSet tools; private final @NotNull HashSet ores; private final @NotNull HashSet intendedToolPickAxe; @@ -95,15 +96,15 @@ public class MaterialMapStore { crossbows = new HashSet<>(); stringTools = new HashSet<>(); prismarineTools = new HashSet<>(); - tools = new HashSet<>(); - swords = new HashSet<>(); axes = new HashSet<>(); pickAxes = new HashSet<>(); shovels = new HashSet<>(); hoes = new HashSet<>(); tridents = new HashSet<>(); + spears = new HashSet<>(); maces = new HashSet<>(); + tools = new HashSet<>(); enchantables = new HashSet<>(); @@ -459,6 +460,7 @@ public class MaterialMapStore { enchantables.addAll(bows); enchantables.addAll(crossbows); enchantables.addAll(maces); + enchantables.addAll(spears); enchantables.add("shears"); enchantables.add("fishing_rod"); @@ -484,6 +486,7 @@ public class MaterialMapStore { fillShovels(); fillTridents(); fillMaces(); + fillSpears(); fillStringTools(); fillPrismarineTools(); fillBows(); @@ -502,6 +505,7 @@ public class MaterialMapStore { tools.addAll(bows); tools.addAll(crossbows); tools.addAll(maces); + tools.addAll(spears); } private void fillBows() { @@ -527,6 +531,16 @@ public class MaterialMapStore { maces.add("mace"); } + private void fillSpears() { + spears.add("wooden_spear"); + spears.add("stone_spear"); + spears.add("copper_spear"); + spears.add("iron_spear"); + spears.add("golden_spear"); + spears.add("diamond_spear"); + spears.add("netherite_spear"); + } + private void fillTridents() { tridents.add("trident"); } @@ -874,6 +888,14 @@ public class MaterialMapStore { return maces.contains(id); } + public boolean isSpear(@NotNull Material material) { + return isSpear(material.getKey().getKey()); + } + + public boolean isSpear(@NotNull String id) { + return spears.contains(id); + } + public boolean isLeatherArmor(@NotNull Material material) { return isLeatherArmor(material.getKey().getKey()); } diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 0f3591f19..ee04e02fc 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -19,6 +19,7 @@ import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.axes.AxesManager; import com.gmail.nossr50.skills.maces.MacesManager; +import com.gmail.nossr50.skills.spears.SpearsManager; import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.tridents.TridentsManager; @@ -331,6 +332,41 @@ public final class CombatUtils { printFinalDamageDebug(player, event, mmoPlayer); } + private static void processSpearsCombat(@NotNull LivingEntity target, + @NotNull Player player, + @NotNull EntityDamageByEntityEvent event) { + if (event.getCause() == DamageCause.THORNS) { + return; + } + + double boostedDamage = event.getDamage(); + + final McMMOPlayer mmoPlayer = UserManager.getPlayer(player); + + //Make sure the profiles been loaded + if (mmoPlayer == null) { + return; + } + + final SpearsManager spearsManager = mmoPlayer.getSpearsManager(); + + // Apply Limit Break DMG + if (canUseLimitBreak(player, target, SubSkillType.SPEARS_SPEARS_LIMIT_BREAK)) { + boostedDamage += (getLimitBreakDamage( + player, target, SubSkillType.SPEARS_SPEARS_LIMIT_BREAK) + * mmoPlayer.getAttackStrength()); + } + + // TODO: Apply any other damage boosts for spears here + + event.setDamage(boostedDamage); + + // TODO: Apply any non-damage effects here + + processCombatXP(mmoPlayer, target, PrimarySkillType.SPEARS); + printFinalDamageDebug(player, event, mmoPlayer); + } + private static void processAxeCombat(@NotNull LivingEntity target, @NotNull Player player, @NotNull EntityDamageByEntityEvent event) { if (event.getCause() == DamageCause.THORNS) { @@ -642,6 +678,15 @@ public final class CombatUtils { .doesPlayerHaveSkillPermission(player, PrimarySkillType.MACES)) { processMacesCombat(target, player, event); } + } else if (ItemUtils.isSpear(heldItem)) { + if (!mcMMO.p.getSkillTools() + .canCombatSkillsTrigger(PrimarySkillType.SPEARS, target)) { + return; + } + if (mcMMO.p.getSkillTools() + .doesPlayerHaveSkillPermission(player, PrimarySkillType.SPEARS)) { + processSpearsCombat(target, player, event); + } } } else if (entityType == EntityType.WOLF) { Wolf wolf = (Wolf) painSource;