mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 16:13:07 +00:00
Condition Registry [1/2]
This commit is contained in:
1 parent
8648e019a9
commit
606bc093df
4 files changed
+232
-48
No files matched your search
@@ -903,6 +903,28 @@ public class AbilityController implements IAbilityHandler {
|
||||
return conditionTypes.keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
public List<String> getConditionNamespaces() {
|
||||
LinkedHashSet<String> seen = new LinkedHashSet<>();
|
||||
for (String typeId : conditionTypes.keySet()) {
|
||||
String[] parts = typeId.split("\\.", 3);
|
||||
if (parts.length >= 2) {
|
||||
seen.add(parts[1]);
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(seen);
|
||||
}
|
||||
|
||||
public String[] getConditionTypesByNamespace(String namespace) {
|
||||
String prefix = "condition." + namespace + ".";
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String typeId : conditionTypes.keySet()) {
|
||||
if (typeId.startsWith(prefix)) {
|
||||
result.add(typeId);
|
||||
}
|
||||
}
|
||||
return result.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public void registerFlightChecker(Predicate<EntityPlayer> checker) {
|
||||
flightCheckers.add(checker);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,12 @@ public class ConditionHitCount extends AbilityCondition {
|
||||
this.userType = UserType.NPC_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkEntity(EntityLivingBase entity) {
|
||||
// Not used — this condition overrides check() directly
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (caster instanceof EntityNPCInterface) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.controllers.data.ability.IEffectAction;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
@@ -207,4 +208,36 @@ public class Register<T> {
|
||||
return new Register.EffectActions(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Conditions extends Register<AbilityCondition> {
|
||||
|
||||
private Conditions(String namespace) {
|
||||
super("condition", namespace);
|
||||
}
|
||||
|
||||
public AbilityCondition register(String name, Supplier<AbilityCondition> factory) {
|
||||
entries.put(registryKey + "." + namespace + "." + name, factory);
|
||||
return factory.get();
|
||||
}
|
||||
|
||||
public void register() {
|
||||
for (Map.Entry<String, Supplier<AbilityCondition>> entry : entries.entrySet()) {
|
||||
AbilityController.Instance.registerCondition(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Register.Conditions create(String namespace, String displayName) {
|
||||
if (!REGISTERED_NAMESPACES.containsKey("condition"))
|
||||
REGISTERED_NAMESPACES.put("condition", new ArrayList<>());
|
||||
|
||||
if (REGISTERED_NAMESPACES.get("condition").contains(namespace)) {
|
||||
LogWriter.error("REGISTER CONDITIONS: Namespace " + namespace + " already registered!");
|
||||
}
|
||||
|
||||
REGISTERED_NAMESPACES.get("condition").add(namespace);
|
||||
NAMESPACE_DISPLAY_NAMES.put(namespace, displayName);
|
||||
|
||||
return new Register.Conditions(namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user