Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
somehussar committed 2026-02-21 00:04:33 +01:00
commit 15486a1ea8
11 files changed
+385 -414

No files matched your search

@@ -1,6 +1,9 @@
package kamkeel.npcs.controllers;
import kamkeel.npcs.controllers.data.ability.*;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import kamkeel.npcs.controllers.data.ability.conditions.ConditionHPThreshold;
import kamkeel.npcs.controllers.data.ability.conditions.ConditionHitCount;
import kamkeel.npcs.controllers.data.ability.type.AbilityCharge;
import kamkeel.npcs.controllers.data.ability.type.AbilityCutter;
import kamkeel.npcs.controllers.data.ability.type.AbilityDash;
@@ -54,7 +57,7 @@ public class AbilityController implements IAbilityHandler {
private final List<IAbilityFieldProvider> fieldProviders = new ArrayList<>();
private final List<IChainedAbilityFieldProvider> chainedFieldProviders = new ArrayList<>();
private final List<IAbilityExtender> extenders = new ArrayList<>();
private final Map<String, Supplier<IAbilityCondition>> conditionTypes = new HashMap<>();
private final Map<String, Supplier<AbilityCondition>> conditionTypes = new HashMap<>();
private final List<Predicate<EntityPlayer>> flightCheckers = new ArrayList<>();
// ── Legacy Migration ─────────────────────────────────────────────────────
@@ -147,7 +150,8 @@ public class AbilityController implements IAbilityHandler {
}
private void registerBuiltinConditionTypes() {
registerCondition(IAbilityCondition.ConditionHPAbove::new);
registerCondition(ConditionHPThreshold::new);
registerCondition(ConditionHitCount::new);
}
// ═══════════════════════════════════════════════════════════════════════════
@@ -880,8 +884,8 @@ public class AbilityController implements IAbilityHandler {
return extenders;
}
public void registerCondition(Supplier<IAbilityCondition> conditionFactory) {
IAbilityCondition temp = conditionFactory.get();
public void registerCondition(Supplier<AbilityCondition> conditionFactory) {
AbilityCondition temp = conditionFactory.get();
String typeId = temp.getTypeId();
if (conditionTypes.containsKey(typeId)) {
LogWriter.info("AbilityController: Overwriting Condition type: " + typeId);
@@ -889,7 +893,7 @@ public class AbilityController implements IAbilityHandler {
conditionTypes.put(typeId, conditionFactory);
}
public Supplier<IAbilityCondition> getConditionType(String key) {
public Supplier<AbilityCondition> getConditionType(String key) {
return conditionTypes.get(key);
}
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
@@ -58,7 +59,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
// Selection
protected int weight = 10;
protected boolean enabled = true;
protected List<Condition> conditions = new ArrayList<>();
protected List<AbilityCondition> conditions = new ArrayList<>();
// Targeting
protected TargetingMode targetingMode = TargetingMode.AGGRO_TARGET;
@@ -1231,7 +1232,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
// ═══════════════════════════════════════════════════════════════════
public boolean checkConditions(EntityLivingBase caster, EntityLivingBase target) {
for (Condition c : conditions) {
for (AbilityCondition c : conditions) {
if (!c.check(caster, target)) return false;
}
return true;
@@ -1241,7 +1242,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
* Check conditions for a player caster, skipping target-requiring conditions.
*/
public boolean checkConditionsForPlayer(EntityLivingBase caster) {
for (Condition c : conditions) {
for (AbilityCondition c : conditions) {
if (c.requiresTarget()) continue;
if (!c.check(caster, null)) return false;
}
@@ -1310,7 +1311,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
// Conditions
NBTTagList condList = new NBTTagList();
for (Condition c : conditions) condList.appendTag(c.writeNBT());
for (AbilityCondition c : conditions) condList.appendTag(c.writeNBT());
nbt.setTag("conditions", condList);
// Effects
@@ -1397,7 +1398,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
conditions.clear();
NBTTagList condList = nbt.getTagList("conditions", 10);
for (int i = 0; i < condList.tagCount(); i++) {
Condition c = Condition.fromNBT(condList.getCompoundTagAt(i));
AbilityCondition c = AbilityCondition.fromNBT(condList.getCompoundTagAt(i));
if (c != null) conditions.add(c);
}
@@ -1935,11 +1936,11 @@ public abstract class Ability implements IAbility, IAbilityAction {
return customData;
}
public List<Condition> getConditions() {
public List<AbilityCondition> getConditions() {
return conditions;
}
public void addCondition(Condition c) {
public void addCondition(AbilityCondition c) {
conditions.add(c);
}
@@ -1,6 +1,7 @@
package kamkeel.npcs.controllers.data.ability;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -57,7 +58,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
/**
* Chain-level conditions (individual ability conditions are ignored).
*/
private List<Condition> conditions = new ArrayList<>();
private List<AbilityCondition> conditions = new ArrayList<>();
/**
* Ordered list of ability entries to execute.
@@ -185,11 +186,11 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
return UserType.NPC_ONLY;
}
public List<Condition> getConditions() {
public List<AbilityCondition> getConditions() {
return conditions;
}
public void setConditions(List<Condition> conditions) {
public void setConditions(List<AbilityCondition> conditions) {
this.conditions = conditions != null ? conditions : new ArrayList<>();
}
@@ -279,7 +280,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
* Check all chain-level conditions against the caster and target.
*/
public boolean checkConditions(EntityLivingBase caster, EntityLivingBase target) {
for (Condition c : conditions) {
for (AbilityCondition c : conditions) {
if (!c.check(caster, target)) {
return false;
}
@@ -291,7 +292,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
* Check conditions for player use (skip target-requiring conditions).
*/
public boolean checkConditionsForPlayer(EntityLivingBase caster) {
for (Condition c : conditions) {
for (AbilityCondition c : conditions) {
if (c.requiresTarget()) continue;
if (!c.check(caster, null)) {
return false;
@@ -382,7 +383,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
// Conditions
NBTTagList condList = new NBTTagList();
for (Condition c : conditions) {
for (AbilityCondition c : conditions) {
condList.appendTag(c.writeNBT());
}
nbt.setTag("Conditions", condList);
@@ -416,7 +417,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
conditions.clear();
NBTTagList condList = nbt.getTagList("Conditions", 10);
for (int i = 0; i < condList.tagCount(); i++) {
Condition c = Condition.fromNBT(condList.getCompoundTagAt(i));
AbilityCondition c = AbilityCondition.fromNBT(condList.getCompoundTagAt(i));
if (c != null) {
conditions.add(c);
}
@@ -1,197 +0,0 @@
package kamkeel.npcs.controllers.data.ability;
import net.minecraft.nbt.NBTTagCompound;
public abstract class ConditionField<T> {
protected final String key;
protected final String label;
protected final Class<T> type; // Float.class, Integer.class, etc
protected T value;
public ConditionField(String key, String label, Class<T> type, T defaultValue) {
this.key = key;
this.label = label;
this.type = type;
this.value = defaultValue;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public String getKey() {
return key;
}
public String getLabel() {
return label;
}
public Class<T> getType() {
return type;
}
public abstract void writeNBT(NBTTagCompound nbt);
public abstract void readNBT(NBTTagCompound nbt);
public static ConditionField<Integer> intField(String key, String label, int defaultValue) {
return intField(key, label, defaultValue, 0, Integer.MAX_VALUE);
}
public static ConditionField<Integer> intField(String key, String label, int defaultValue, int min, int max) {
return new NumberField<>(key, label, Integer.class, defaultValue, min, max);
}
public static ConditionField<Double> doubleField(String key, String label, double defaultValue) {
return doubleField(key, label, defaultValue, 0, Double.MAX_VALUE);
}
public static ConditionField<Double> doubleField(String key, String label, double defaultValue, double min, double max) {
return new NumberField<>(key, label, Double.class, defaultValue, min, max);
}
public static ConditionField<Float> floatField(String key, String label, float defaultValue) {
return floatField(key, label, defaultValue, 0, Float.MAX_VALUE);
}
public static ConditionField<Float> floatField(String key, String label, float defaultValue, float min, float max) {
return new NumberField<>(key, label, Float.class, defaultValue, min, max);
}
public static ConditionField<String> stringField(String key, String label) {
return new StringField(key, label, "");
}
public static ConditionField<String> stringField(String key, String label, String defaultValue) {
return new StringField(key, label, defaultValue);
}
public static ConditionField<Boolean> booleanField(String key, String label, boolean defaultValue) {
return new BoolField(key, label, defaultValue);
}
public static <E extends Enum<E>> ConditionField<E> enumField(String key, String label, E defaultValue, Class<E> enumClass) {
return new EnumField<>(key, label, defaultValue, enumClass);
}
public static <E extends Enum<E>> ConditionField<E> enumField(String key, String label, E defaultValue) {
return new EnumField<>(key, label, defaultValue, defaultValue.getDeclaringClass());
}
private static class NumberField<T extends Number & Comparable<T>> extends ConditionField<T> {
private T min;
private T max;
public NumberField(String key, String label, Class<T> type, T defaultValue, T min, T max) {
super(key, label, type, defaultValue);
this.min = min;
this.max = max;
}
@Override
public void setValue(T value) {
if (value.compareTo(min) < 0) {
this.value = min;
} else if (value.compareTo(max) > 0) {
this.value = max;
} else {
this.value = value;
}
}
public NumberField<T> min(T value) {
this.min = value;
return this;
}
public NumberField<T> max(T value) {
this.max = value;
return this;
}
@Override
public void writeNBT(NBTTagCompound nbt) {
if (value instanceof Integer) nbt.setInteger(key, (Integer) value);
else if (value instanceof Float) nbt.setFloat(key, (Float) value);
else if (value instanceof Double) nbt.setDouble(key, (Double) value);
else if (value instanceof Long) nbt.setLong(key, (Long) value);
}
@Override
@SuppressWarnings("unchecked")
public void readNBT(NBTTagCompound nbt) {
if (!nbt.hasKey(key)) return;
T v;
Class<?> t = type;
if (t == Integer.class) v = (T) (Integer) nbt.getInteger(key);
else if (t == Float.class) v = (T) (Float) nbt.getFloat(key);
else if (t == Double.class) v = (T) (Double) nbt.getDouble(key);
else if (t == Long.class) v = (T) (Long) nbt.getLong(key);
else return;
setValue(v);
}
}
private static class StringField extends ConditionField<String> {
public StringField(String key, String label, String defaultValue) {
super(key, label, String.class, defaultValue);
}
@Override
public void writeNBT(NBTTagCompound nbt) {
nbt.setString(key, value);
}
@Override
public void readNBT(NBTTagCompound nbt) {
setValue(nbt.getString(key));
}
}
private static class BoolField extends ConditionField<Boolean> {
public BoolField(String key, String label, boolean defaultValue) {
super(key, label, Boolean.class, defaultValue);
}
@Override
public void writeNBT(NBTTagCompound nbt) {
nbt.setBoolean(key, value);
}
@Override
public void readNBT(NBTTagCompound nbt) {
setValue(nbt.getBoolean(key));
}
}
private static class EnumField<E extends Enum<E>> extends ConditionField<E> {
private final E[] options;
public EnumField(String key, String label, E defaultValue, Class<E> enumClass) {
super(key, label, enumClass, defaultValue);
this.options = enumClass.getEnumConstants();
}
public E[] getOptions() {
return options;
}
@Override
public void writeNBT(NBTTagCompound nbt) {
nbt.setString(key, value.name());
}
@Override
public void readNBT(NBTTagCompound nbt) {
if (!nbt.hasKey(key)) return;
try {
setValue(Enum.valueOf(type, nbt.getString(key)));
} catch (IllegalArgumentException ignored) {}
}
}
}
@@ -1,5 +1,6 @@
package kamkeel.npcs.controllers.data.ability;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
@@ -30,7 +31,7 @@ public interface IAbilityAction {
UserType getAllowedBy();
List<Condition> getConditions();
List<AbilityCondition> getConditions();
boolean checkConditions(EntityLivingBase caster, EntityLivingBase target);
@@ -1,94 +0,0 @@
package kamkeel.npcs.controllers.data.ability;
import kamkeel.npcs.controllers.AbilityController;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.LogWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
public interface IAbilityCondition {
/**
* Check if this condition is met.
*
* @param caster The entity that would use the ability (NPC or Player)
* @param target The current target (may be null for self-targeting abilities or players)
* @return true if the condition is satisfied
*/
boolean check(EntityLivingBase caster, EntityLivingBase target);
UserType getUserType();
String getTypeId();
List<ConditionField<?>> getFields();
default NBTTagCompound writeNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("userType", getUserType().ordinal());
nbt.setString("type", getTypeId());
for (ConditionField<?> field : getFields()) {
field.writeNBT(nbt);
}
return nbt;
}
default void readNBT(NBTTagCompound nbt) {
for (ConditionField<?> field : getFields()) {
field.readNBT(nbt);
}
}
static IAbilityCondition fromNBT(NBTTagCompound nbt) {
String typeId = nbt.getString("type");
Supplier<IAbilityCondition> factory = AbilityController.Instance.getConditionType(typeId);
if (factory == null) {
LogWriter.info("AbilityController: Unknown condition type: " + typeId);
return null;
}
IAbilityCondition condition = factory.get();
condition.readNBT(nbt);
return condition;
}
class ConditionHPAbove implements IAbilityCondition {
ConditionField<Float> threshold = ConditionField.floatField("threshold", "threshold", 0.5f);
public ConditionHPAbove() {
}
@Override
public boolean check(EntityLivingBase caster, EntityLivingBase target) {
return caster.getHealth() / caster.getMaxHealth() > threshold.getValue();
}
@Override
public UserType getUserType() {
return UserType.BOTH;
}
@Override
public String getTypeId() {
return "hp_above";
}
public float getThreshold() {
return threshold.getValue();
}
public void setThreshold(float threshold) {
this.threshold.setValue(threshold);
}
@Override
public List<ConditionField<?>> getFields() {
return Arrays.asList(
threshold
);
}
}
}
@@ -0,0 +1,84 @@
package kamkeel.npcs.controllers.data.ability.conditions;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.UserType;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.LogWriter;
import noppes.npcs.client.gui.builder.FieldDef;
import java.util.List;
import java.util.function.Supplier;
public abstract class AbilityCondition {
protected String typeId = "";
protected String name = "";
protected UserType userType = UserType.BOTH;
/**
* Check if this condition is met.
*
* @param caster The entity that would use the ability (NPC or Player)
* @param target The current target (may be null for self-targeting abilities or players)
* @return true if the condition is satisfied
*/
public abstract boolean check(EntityLivingBase caster, EntityLivingBase target);
public boolean requiresTarget() {
return false;
}
public UserType getUserType() {
return userType;
}
public void setUserType(UserType userType) {
this.userType = userType;
}
public String getTypeId() {
return typeId;
}
public String getName() {
return name;
}
@SideOnly(Side.CLIENT)
public abstract List<FieldDef> getAbilityDefinitions(List<FieldDef> defs);
public final NBTTagCompound writeNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("userType", getUserType().ordinal());
nbt.setString("type", getTypeId());
nbt.setString("name", getName());
writeTypeNBT(nbt);
return nbt;
}
public abstract void writeTypeNBT(NBTTagCompound nbt);
public abstract void readTypeNBT(NBTTagCompound nbt);
public final void readNBT(NBTTagCompound nbt) {
typeId = nbt.getString("type");
name = nbt.getString("name");
userType = UserType.fromOrdinal(nbt.getInteger("userType"));
readTypeNBT(nbt);
}
public static AbilityCondition fromNBT(NBTTagCompound nbt) {
String typeId = nbt.getString("type");
Supplier<AbilityCondition> factory = AbilityController.Instance.getConditionType(typeId);
if (factory == null) {
LogWriter.info("AbilityController: Unknown condition type: " + typeId);
return null;
}
AbilityCondition condition = factory.get();
condition.readNBT(nbt);
return condition;
}
}
@@ -0,0 +1,99 @@
package kamkeel.npcs.controllers.data.ability.conditions;
import kamkeel.npcs.controllers.data.ability.UserType;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.gui.builder.FieldDef;
import java.util.Collections;
import java.util.List;
public class ConditionHPThreshold extends AbilityCondition{
private float threshold = 0.5f; // 50%
private ThresholdType thresholdType = ThresholdType.ABOVE;
public enum ThresholdType {
ABOVE {
@Override
public boolean test(float value, float threshold) {
return value > threshold;
}
},
BELOW {
@Override
public boolean test(float value, float threshold) {
return value < threshold;
}
};
public abstract boolean test(float value, float threshold);
public static ThresholdType fromOrdinal(int ordinal) {
ThresholdType[] values = values();
if (ordinal >= 0 && ordinal < values.length) {
return values[ordinal];
}
return ABOVE;
}
}
public ConditionHPThreshold() {
this.typeId = "condition.cnpc.hp_threshold";
this.name = "Health Threshold";
this.userType = UserType.NPC_ONLY;
}
@Override
public boolean check(EntityLivingBase caster, EntityLivingBase target) {
float casterHP = caster.getHealth() / caster.getMaxHealth();
float targetHP = target.getHealth() / target.getMaxHealth();
return compare(casterHP, targetHP);
}
public boolean compare(float casterHp, float targetHp) {
boolean casterCheck = thresholdType.test(casterHp, threshold);
boolean targetCheck = thresholdType.test(targetHp, threshold);
switch (getUserType()) {
case BOTH:
return casterCheck && targetCheck;
case PLAYER_ONLY:
return casterCheck;
default:
return targetCheck;
}
}
public float getThreshold() {
return threshold;
}
public void setThreshold(float threshold) {
this.threshold = Math.max(0, threshold);
}
public ThresholdType getThresholdType() {
return thresholdType;
}
public void setThresholdType(ThresholdType thresholdType) {
this.thresholdType = thresholdType;
}
@Override
public List<FieldDef> getAbilityDefinitions(List<FieldDef> defs) {
return Collections.emptyList();
}
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("threshold", threshold);
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
threshold = nbt.getFloat("threshold");
}
}
@@ -0,0 +1,67 @@
package kamkeel.npcs.controllers.data.ability.conditions;
import kamkeel.npcs.controllers.data.ability.UserType;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.gui.builder.FieldDef;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.Collections;
import java.util.List;
public class ConditionHitCount extends AbilityCondition{
private int requiredHits = 3;
private int withinTicks = 60;
public ConditionHitCount() {
this.typeId = "condition.cnpc.hit_count";
this.name = "Hit Count";
this.userType = UserType.NPC_ONLY;
}
@Override
public boolean check(EntityLivingBase caster, EntityLivingBase target) {
if (caster instanceof EntityNPCInterface) {
EntityNPCInterface npc = (EntityNPCInterface) caster;
if (npc.abilities != null) {
return npc.abilities.getRecentHitCount(withinTicks) >= requiredHits;
}
}
// For players, hit count tracking is not yet supported
return false;
}
public int getRequiredHits() {
return requiredHits;
}
public void setRequiredHits(int requiredHits) {
this.requiredHits = Math.max(0, requiredHits);
}
public int getWithinTicks() {
return withinTicks;
}
public void setWithinTicks(int withinTicks) {
this.withinTicks = Math.max(0, withinTicks);
}
@Override
public List<FieldDef> getAbilityDefinitions(List<FieldDef> defs) {
return Collections.emptyList();
}
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setInteger("requiredHits", requiredHits);
nbt.setInteger("withinTicks", withinTicks);
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
requiredHits = nbt.getInteger("requiredHits");
withinTicks = nbt.getInteger("withinTicks");
}
}