mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 00:19:05 +00:00
Added a filter to browse through abilities from different mods
This commit is contained in:
1 parent
ad4033ed62
commit
2c3ca1b5ed
3 files changed
+150
-18
No files matched your search
@@ -5,45 +5,92 @@ import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.BuiltInAnimation;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Register<T> {
|
||||
public static final Map<String, List<String>> REGISTERED_NAMESPACES = new LinkedHashMap<>();
|
||||
private final String registryKey;
|
||||
protected final String namespace;
|
||||
protected final Map<String, Supplier<T>> entries = new LinkedHashMap<>();
|
||||
|
||||
public Register(String registryKey, String namespace) {
|
||||
private Register(String registryKey, String namespace) {
|
||||
this.registryKey = registryKey;
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public T register(String factoryName, Supplier<T> factory) {
|
||||
entries.put(registryKey + "." + namespace + ":" + factoryName, factory);
|
||||
entries.put(registryKey + "." + namespace + "." + factoryName, factory);
|
||||
return factory.get();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String registryKey) {
|
||||
if (REGISTERED_NAMESPACES.isEmpty()) return true;
|
||||
|
||||
if (REGISTERED_NAMESPACES.get(registryKey).isEmpty()) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<T> catalogue() {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (String regKey : REGISTERED_NAMESPACES.keySet()) {
|
||||
List<String> nameSp = REGISTERED_NAMESPACES.get(regKey);
|
||||
for (String name : nameSp) {
|
||||
List<T> nameSpContent = catalogue(regKey, name);
|
||||
list.addAll(nameSpContent);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<T> catalogue(String namespace) {
|
||||
return catalogue(registryKey, namespace);
|
||||
}
|
||||
|
||||
public List<T> catalogue(String registryKey, String namespace) {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (Map.Entry<String, Supplier<T>> entry : entries.entrySet()) {
|
||||
if (entry.getKey().startsWith(registryKey + "." + namespace + ":"))
|
||||
list.add(entry.getValue().get());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class Abilities extends Register<Ability> {
|
||||
public Abilities(String namespace) {
|
||||
private Abilities(String namespace) {
|
||||
super("ability", namespace);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
for (Map.Entry<String, Supplier<Ability>> entry : entries.entrySet()) {
|
||||
AbilityController.Instance.registerType(entry.getKey(), entry.getValue());
|
||||
AbilityController.Instance.registerType(entry.getValue().get().getTypeId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Register.Abilities create(String namespace) {
|
||||
if (!REGISTERED_NAMESPACES.containsKey("ability"))
|
||||
REGISTERED_NAMESPACES.put("ability", new ArrayList<>());
|
||||
|
||||
if (REGISTERED_NAMESPACES.get("ability").contains(namespace)) {
|
||||
LogWriter.error("REGISTER ABILITIES: Namespace " + namespace + " already registered!");
|
||||
}
|
||||
|
||||
REGISTERED_NAMESPACES.get("ability").add(namespace);
|
||||
|
||||
return new Register.Abilities(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Animations extends Register<Animation> {
|
||||
private final Class<?> modClass;
|
||||
private final String animationsPath;
|
||||
|
||||
public Animations(Class<?> modClass, String animationsPath, String namespace) {
|
||||
super("ability", namespace);
|
||||
private Animations(Class<?> modClass, String animationsPath, String namespace) {
|
||||
super("animation", namespace);
|
||||
this.animationsPath = animationsPath;
|
||||
this.modClass = modClass;
|
||||
}
|
||||
@@ -57,12 +104,25 @@ public class Register<T> {
|
||||
try {
|
||||
String path = "/assets/" + namespace + "/" + animationsPath;
|
||||
for (Map.Entry<String, Supplier<Animation>> entry : entries.entrySet()) {
|
||||
String name = entry.getKey().substring(entry.getKey().indexOf(":") + 1);
|
||||
String name = entry.getKey().substring(entry.getKey().indexOf(namespace + ".") + 1);
|
||||
AnimationController.Instance.loadBuiltInAnimation(modClass, path, name);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogWriter.error("Error scanning built-in animations folder", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Register.Animations create(Class<?> modClass, String animationsPath, String namespace) {
|
||||
if (!REGISTERED_NAMESPACES.containsKey("animation"))
|
||||
REGISTERED_NAMESPACES.put("animation", new ArrayList<>());
|
||||
|
||||
if (REGISTERED_NAMESPACES.get("animation").contains(namespace)) {
|
||||
LogWriter.error("REGISTER ANIMATIONS: Namespace " + namespace + " already registered!");
|
||||
}
|
||||
|
||||
REGISTERED_NAMESPACES.get("animation").add(namespace);
|
||||
|
||||
return new Register.Animations(modClass, animationsPath, namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user