Added condition checking to extenders

Extended HP condition to read DBC HP instead
This commit is contained in:
Vidal committed 2026-02-24 00:00:51 -03:00
1 parent 670b811e03
commit aa160ba8fc
3 files changed
+45 -1

No files matched your search

@@ -1176,6 +1176,27 @@ public class AbilityController implements IAbilityHandler {
return false;
}
public Boolean fireCheckConditions(AbilityCondition condition, EntityLivingBase caster, EntityLivingBase target) {
for (IAbilityExtender ext : extenders) {
Boolean result = ext.onCheckCondition(condition, caster, target);
if (result != null) {
return result;
}
}
return false;
}
public Boolean fireCheckConditionsForPlayer(AbilityCondition condition, EntityLivingBase player) {
for (IAbilityExtender ext : extenders) {
Boolean result = ext.onCheckConditionForPlayer(condition, player);
if (result != null) {
return result;
}
}
return null;
}
// ═══════════════════════════════════════════════════════════════════════════
// IAbilityHandler
// ═══════════════════════════════════════════════════════════════════════════
@@ -632,7 +632,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
defs.add(FieldDef.stringField("gui.displayName", this::getRawDisplayName, this::setDisplayName)
.tab("General"));
defs.add(FieldDef.labelField("ability.validFor", () ->
"\u00A7e" + StatCollector.translateToLocal("ability.userType." + getAllowedBy().name()))
"\u00A7e" + StatCollector.translateToLocal("ability.userType." + getAllowedBy().name()))
.tab("General"));
defs.add(FieldDef.row(
FieldDef.intField("ability.weight", this::getWeight, this::setWeight).range(1, 1000),
@@ -1324,6 +1324,13 @@ public abstract class Ability implements IAbility, IAbilityAction {
public boolean checkConditions(EntityLivingBase caster, EntityLivingBase target) {
for (AbilityCondition c : conditions) {
if (!c.getUserType().allowsNpc()) continue;
Boolean extendedCondition = AbilityController.Instance.fireCheckConditions(c, caster, target);
if (extendedCondition != null) {
if (!extendedCondition) return false;
continue;
}
if (!c.check(caster, target)) return false;
}
return true;
@@ -1336,6 +1343,13 @@ public abstract class Ability implements IAbility, IAbilityAction {
for (AbilityCondition c : conditions) {
if (!c.getUserType().allowsPlayer()) continue;
if (c.requiresTarget()) continue;
Boolean extendedCondition = AbilityController.Instance.fireCheckConditionsForPlayer(c, caster);
if (extendedCondition != null) {
if (!extendedCondition) return false;
continue;
}
if (!c.check(caster, null)) return false;
}
return true;
@@ -1,5 +1,6 @@
package kamkeel.npcs.controllers.data.ability.extender;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
import kamkeel.npcs.controllers.data.ability.Ability;
import net.minecraft.entity.EntityLivingBase;
@@ -117,4 +118,12 @@ public interface IAbilityExtender {
default boolean onAbilityHeal(Ability ability, EntityLivingBase caster, EntityLivingBase target, float healAmount) {
return false;
}
default Boolean onCheckCondition(AbilityCondition condition, EntityLivingBase caster, EntityLivingBase target) {
return false;
}
default Boolean onCheckConditionForPlayer(AbilityCondition condition, EntityLivingBase player) {
return false;
}
}