feat: add built-in ability handling and UI updates for ability management

This commit is contained in:
Kam committed 2026-02-12 20:30:12 -05:00
1 parent 9dae4bae55
commit 2c00ecae9e
12 files changed
+201 -47

No files matched your search

@@ -1278,6 +1278,10 @@ public abstract class Ability implements IAbility {
return typeId;
}
public boolean isBuiltIn() {
return false;
}
public int getWeight() {
return weight;
}
@@ -48,6 +48,9 @@ public class AbilityController implements IAbilityHandler {
/** External variant definitions registered by addons, keyed by typeId. */
private final Map<String, List<AbilityVariant>> externalVariants = new LinkedHashMap<>();
/** TypeIds that produce BuiltInAbility instances (non-editable in GUI). */
private final Set<String> builtInTypeIds = new HashSet<>();
public AbilityController() {
registerBuiltinTypes();
}
@@ -173,7 +176,9 @@ public class AbilityController implements IAbilityHandler {
if (abilities.containsKey(name)) {
LogWriter.info("AbilityController: Overwriting built-in ability: " + name);
}
ability.setName(name);
if (!ability.isBuiltIn()) {
ability.setName(name);
}
abilities.put(name, ability);
LogWriter.info("Registered ability: " + name);
}
@@ -281,12 +286,22 @@ public class AbilityController implements IAbilityHandler {
// ACCESSORS
// ═══════════════════════════════════════════════════════════════════════════
/** Get a built-in ability by name. Returns the stored instance (not a copy). */
/** Get a built-in ability by map key. Returns the stored instance (not a copy). */
public Ability getAbility(String name) {
return abilities.get(name);
}
/** Get all built-in ability names. */
/** Get a built-in ability by its display name (ability.getName()). */
public Ability getAbilityByDisplayName(String displayName) {
for (Ability ability : abilities.values()) {
if (ability.getName().equals(displayName)) {
return ability;
}
}
return null;
}
/** Get all built-in ability map keys. */
public Set<String> getAbilityNames() {
return new LinkedHashSet<>(abilities.keySet());
}
@@ -338,6 +353,10 @@ public class AbilityController implements IAbilityHandler {
return typeFactories.keySet().toArray(new String[0]);
}
public boolean isBuiltInType(String typeId) {
return builtInTypeIds.contains(typeId);
}
@Override
public boolean hasType(String typeId) {
return typeFactories.containsKey(typeId);
@@ -386,6 +405,9 @@ public class AbilityController implements IAbilityHandler {
LogWriter.info("AbilityController: Overwriting type: " + typeId);
}
typeFactories.put(typeId, factory);
if (temp.isBuiltIn()) {
builtInTypeIds.add(typeId);
}
}
/**
@@ -21,7 +21,13 @@ public abstract class BuiltInAbility extends Ability {
this.registryKey = registryKey;
this.id = registryKey;
this.name = registryKey;
this.typeId = registryKey;
// Convert "namespace:name" to "ability.namespace.name" for GUI filter compatibility
this.typeId = "ability." + registryKey.replace(':', '.');
}
@Override
public boolean isBuiltIn() {
return true;
}
/**
@@ -96,6 +96,7 @@ import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcSavePacket;
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket;
import kamkeel.npcs.network.packets.request.ability.CustomAbilityRemovePacket;
import kamkeel.npcs.network.packets.request.ability.BuiltInAbilityGetPacket;
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
import kamkeel.npcs.network.packets.request.animation.AnimationGetPacket;
import kamkeel.npcs.network.packets.request.animation.AnimationRemovePacket;
@@ -516,6 +517,7 @@ public class PacketHandler {
REQUEST_PACKET.registerPacket(new CustomAbilityGetPacket());
REQUEST_PACKET.registerPacket(new CustomAbilityRemovePacket());
REQUEST_PACKET.registerPacket(new CustomAbilitySavePacket());
REQUEST_PACKET.registerPacket(new BuiltInAbilityGetPacket());
// Other Packets
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
@@ -205,6 +205,7 @@ public enum EnumRequestPacket {
CustomAbilityGet,
CustomAbilityRemove,
CustomAbilitySave,
BuiltInAbilityGet,
Hammer,
RecipeScript,
@@ -47,5 +47,6 @@ public final class CustomAbilitiesGetPacket extends AbstractPacket {
return;
NoppesUtilServer.sendCustomAbilitiesData((EntityPlayerMP) player);
NoppesUtilServer.sendBuiltInAbilitiesData((EntityPlayerMP) player);
}
}
+18 -1
View File
@@ -37,6 +37,7 @@ public class Register<T> {
public static class Abilities extends Register<Ability> {
protected final Map<String, String> uniqueNames = new LinkedHashMap<>();
protected final Set<String> typeOnly = new HashSet<>();
private Abilities(String namespace) {
super("ability", namespace);
@@ -50,9 +51,25 @@ public class Register<T> {
return factory.get();
}
/**
* Register a type only (shell template, no built-in preset).
* The type will appear in the ability type picker but won't be
* available as a pre-configured ability by name.
*/
public Ability registerType(String factoryName, Supplier<Ability> factory) {
String name = registryKey + "." + namespace + "." + factoryName.trim().toLowerCase().replaceAll(" ", "_");
entries.put(name, factory);
uniqueNames.put(name, factoryName);
typeOnly.add(name);
return factory.get();
}
public void register() {
for (Map.Entry<String, Supplier<Ability>> entry : entries.entrySet()) {
AbilityController.Instance.registerAbility(uniqueNames.get(entry.getKey()), entry.getValue().get());
AbilityController.Instance.registerType(entry.getKey(), entry.getValue());
if (!typeOnly.contains(entry.getKey())) {
AbilityController.Instance.registerAbility(uniqueNames.get(entry.getKey()), entry.getValue().get());
}
}
}