Condition overhaul completed

This commit is contained in:
Vidal committed 2026-02-20 21:36:08 -03:00
1 parent a2e0bb50b9
commit 89e87b7656
9 files changed
+290 -292

No files matched your search

@@ -1233,6 +1233,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
public boolean checkConditions(EntityLivingBase caster, EntityLivingBase target) {
for (AbilityCondition c : conditions) {
if (!c.getUserType().allowsNpc()) continue;
if (!c.check(caster, target)) return false;
}
return true;
@@ -1243,6 +1244,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
*/
public boolean checkConditionsForPlayer(EntityLivingBase caster) {
for (AbilityCondition c : conditions) {
if (!c.getUserType().allowsPlayer()) continue;
if (c.requiresTarget()) continue;
if (!c.check(caster, null)) return false;
}
@@ -9,6 +9,7 @@ import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.LogWriter;
import noppes.npcs.client.gui.builder.FieldDef;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
@@ -16,6 +17,7 @@ public abstract class AbilityCondition {
protected String typeId = "";
protected String name = "";
protected UserType userType = UserType.BOTH;
protected ConditionFilter conditionFilter = ConditionFilter.CASTER;
/**
* Check if this condition is met.
@@ -34,10 +36,6 @@ public abstract class AbilityCondition {
return userType;
}
public void setUserType(UserType userType) {
this.userType = userType;
}
public String getTypeId() {
return typeId;
}
@@ -46,14 +44,32 @@ public abstract class AbilityCondition {
return name;
}
public ConditionFilter getFilter() {
return conditionFilter;
}
public void setFilter(ConditionFilter filter) {
this.conditionFilter = filter;
}
@SideOnly(Side.CLIENT)
public abstract List<FieldDef> getAbilityDefinitions(List<FieldDef> defs);
public abstract void getConditionDefinitions(List<FieldDef> defs);
@SideOnly(Side.CLIENT)
public final List<FieldDef> getAllDefinitions() {
List<FieldDef> defs = new ArrayList<>();
defs.add(FieldDef.enumField("condition.filter", ConditionFilter.class, this::getFilter, this::setFilter));
getConditionDefinitions(defs);
return defs;
}
public final NBTTagCompound writeNBT() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("userType", getUserType().ordinal());
nbt.setString("type", getTypeId());
nbt.setString("typeId", getTypeId());
nbt.setString("name", getName());
nbt.setInteger("userType", getUserType().ordinal());
nbt.setInteger("filter", getUserType().ordinal());
writeTypeNBT(nbt);
return nbt;
}
@@ -63,14 +79,15 @@ public abstract class AbilityCondition {
public abstract void readTypeNBT(NBTTagCompound nbt);
public final void readNBT(NBTTagCompound nbt) {
typeId = nbt.getString("type");
typeId = nbt.getString("typeId");
name = nbt.getString("name");
userType = UserType.fromOrdinal(nbt.getInteger("userType"));
conditionFilter = ConditionFilter.fromOrdinal(nbt.getInteger("filter"));
readTypeNBT(nbt);
}
public static AbilityCondition fromNBT(NBTTagCompound nbt) {
String typeId = nbt.getString("type");
String typeId = nbt.getString("typeId");
Supplier<AbilityCondition> factory = AbilityController.Instance.getConditionType(typeId);
if (factory == null) {
LogWriter.info("AbilityController: Unknown condition type: " + typeId);
@@ -0,0 +1,39 @@
package kamkeel.npcs.controllers.data.ability.conditions;
import kamkeel.npcs.controllers.data.ability.UserType;
public enum ConditionFilter {
CASTER,
TARGET,
BOTH;
public boolean checksCaster() {
return this == CASTER || this == BOTH;
}
public boolean checksTarget() {
return this == TARGET || this == BOTH;
}
public static ConditionFilter fromOrdinal(int ordinal) {
ConditionFilter[] values = values();
if (ordinal >= 0 && ordinal < values.length) {
return values[ordinal];
}
return BOTH;
}
@Override
public String toString() {
switch (this) {
case BOTH:
return "condition.filter.both";
case CASTER:
return "condition.filter.caster";
case TARGET:
return "condition.filter.target";
default:
return name();
}
}
}
@@ -1,11 +1,9 @@
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{
@@ -16,13 +14,13 @@ public class ConditionHPThreshold extends AbilityCondition{
ABOVE {
@Override
public boolean test(float value, float threshold) {
return value > threshold;
return value >= threshold;
}
},
BELOW {
@Override
public boolean test(float value, float threshold) {
return value < threshold;
return value <= threshold;
}
};
@@ -35,12 +33,23 @@ public class ConditionHPThreshold extends AbilityCondition{
}
return ABOVE;
}
@Override
public String toString() {
switch (this) {
case ABOVE:
return "condition.hp_above";
case BELOW:
return "condition.hp_below";
default:
return name();
}
}
}
public ConditionHPThreshold() {
this.typeId = "condition.cnpc.hp_threshold";
this.name = "Health Threshold";
this.userType = UserType.NPC_ONLY;
this.name = "condition.hp_threshold";
}
@Override
@@ -56,10 +65,10 @@ public class ConditionHPThreshold extends AbilityCondition{
boolean casterCheck = thresholdType.test(casterHp, threshold);
boolean targetCheck = thresholdType.test(targetHp, threshold);
switch (getUserType()) {
switch (getFilter()) {
case BOTH:
return casterCheck && targetCheck;
case PLAYER_ONLY:
case CASTER:
return casterCheck;
default:
return targetCheck;
@@ -83,8 +92,10 @@ public class ConditionHPThreshold extends AbilityCondition{
}
@Override
public List<FieldDef> getAbilityDefinitions(List<FieldDef> defs) {
return Collections.emptyList();
public void getConditionDefinitions(List<FieldDef> defs) {
defs.add(FieldDef.floatField("condition.threshold", this::getThreshold, this::setThreshold).min(0));
defs.add(FieldDef.enumField("condition.threshold_type", ThresholdType.class,
this::getThresholdType, this::setThresholdType));
}
@Override
@@ -6,16 +6,15 @@ 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{
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.name = "condition.hit_count";
this.userType = UserType.NPC_ONLY;
}
@@ -49,8 +48,9 @@ public class ConditionHitCount extends AbilityCondition{
}
@Override
public List<FieldDef> getAbilityDefinitions(List<FieldDef> defs) {
return Collections.emptyList();
public void getConditionDefinitions(List<FieldDef> defs) {
defs.add(FieldDef.intField("condition.required_hits", this::getRequiredHits, this::setRequiredHits).min(1));
defs.add(FieldDef.intField("condition.within_ticks", this::getWithinTicks, this::setWithinTicks).min(0));
}
@Override