add Spears interactions to CombatUtils

This commit is contained in:
nossr50
2025-11-28 13:32:35 -08:00
parent 461d2d4570
commit 34f96dc687
3 changed files with 111 additions and 18 deletions

View File

@@ -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.
*

View File

@@ -51,9 +51,10 @@ public class MaterialMapStore {
private final @NotNull HashSet<String> tridents;
private final @NotNull HashSet<String> bows;
private final @NotNull HashSet<String> crossbows;
private final @NotNull HashSet<String> tools;
private final @NotNull HashSet<String> enchantables;
private final @NotNull HashSet<String> maces;
private final @NotNull HashSet<String> spears;
private final @NotNull HashSet<String> enchantables;
private final @NotNull HashSet<String> tools;
private final @NotNull HashSet<String> ores;
private final @NotNull HashSet<String> 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());
}

View File

@@ -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;