Remove all Legacy Ability Content, cleanup API.

- Add Script Tab to Abilities
- Add Custom Ability
- Add Icon Support for Abilities / Default Icon Support
- Remove Icon Tab and throw it into Effects with allowed Override
- Removed Deprecated API Sources
This commit is contained in:
Kam committed 2026-02-27 16:43:35 -05:00
1 parent 936dc7f0cc
commit 675c4ef4f9
50 files changed
+1488 -938

No files matched your search

@@ -17,6 +17,7 @@ import kamkeel.npcs.controllers.data.ability.enums.UserType;
import kamkeel.npcs.controllers.data.ability.extender.IAbilityExtender;
import kamkeel.npcs.controllers.data.ability.gui.IAbilityFieldProvider;
import kamkeel.npcs.controllers.data.ability.gui.IChainedAbilityFieldProvider;
import kamkeel.npcs.controllers.data.ability.CustomAbility;
import kamkeel.npcs.controllers.data.ability.type.AbilityCharge;
import kamkeel.npcs.controllers.data.ability.type.AbilityCutter;
import kamkeel.npcs.controllers.data.ability.type.AbilityDash;
@@ -37,11 +38,15 @@ import kamkeel.npcs.controllers.data.ability.type.energy.AbilityOrb;
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityShield;
import kamkeel.npcs.controllers.data.ability.type.energy.AbilitySweeper;
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityWall;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.controllers.data.AbilityScript;
import noppes.npcs.controllers.data.ChainedAbilityScript;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.ability.IChainedAbility;
import noppes.npcs.api.handler.IAbilityHandler;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.PlayerData;
@@ -52,7 +57,6 @@ import java.io.File;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.regex.Pattern;
public class AbilityController implements IAbilityHandler {
@@ -64,6 +68,10 @@ public class AbilityController implements IAbilityHandler {
private final Map<String, Ability> customAbilities = new LinkedHashMap<>(); // name → Ability
private final Map<String, Ability> customAbilitiesById = new LinkedHashMap<>(); // UUID → Ability
// ── Script Handlers ────────────────────────────────────────────────────
public final HashMap<String, AbilityScript> abilityScriptHandlers = new HashMap<>();
public final HashMap<String, ChainedAbilityScript> chainedAbilityScriptHandlers = new HashMap<>();
// ── Extension Points ─────────────────────────────────────────────────────
private final Map<String, List<AbilityVariant>> externalVariants = new LinkedHashMap<>();
private final List<IAbilityFieldProvider> fieldProviders = new ArrayList<>();
@@ -72,11 +80,6 @@ public class AbilityController implements IAbilityHandler {
private final Map<String, Supplier<AbilityCondition>> conditionTypes = new HashMap<>();
private final List<Predicate<EntityPlayer>> flightCheckers = new ArrayList<>();
// ── Legacy Migration ─────────────────────────────────────────────────────
private static final Pattern UUID_PATTERN =
Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
Pattern.CASE_INSENSITIVE);
// ── Chained Abilities ──────────────────────────────────────────────────
private final Map<String, ChainedAbility> chainedAbilities = new LinkedHashMap<>(); // name → ChainedAbility
private final Map<String, ChainedAbility> chainedAbilitiesById = new LinkedHashMap<>(); // UUID → ChainedAbility
@@ -97,7 +100,7 @@ public class AbilityController implements IAbilityHandler {
// TYPE REGISTRATION
// ═══════════════════════════════════════════════════════════════════════════
public void registerType(String factoryKey, Supplier<Ability> factory) {
public void registerType(Supplier<Ability> factory) {
Ability temp = factory.get();
String typeId = temp.getTypeId();
if (abilityTypes.containsKey(typeId)) {
@@ -132,36 +135,35 @@ public class AbilityController implements IAbilityHandler {
}
private void registerBuiltinTypes() {
registerType("cnpc:slam", AbilitySlam::new);
registerType("cnpc:charge", AbilityCharge::new);
registerType(CustomAbility::new);
registerType("cnpc:heavy_hit", AbilityHeavyHit::new);
registerType("cnpc:cutter", AbilityCutter::new);
registerType(AbilitySlam::new);
registerType(AbilityCharge::new);
// registerType("cnpc:projectile", AbilityProjectile::new);
registerType(AbilityHeavyHit::new);
registerType(AbilityCutter::new);
registerType("cnpc:sweeper", AbilitySweeper::new);
registerType("cnpc:orb", AbilityOrb::new);
registerType("cnpc:disc", AbilityDisc::new);
registerType("cnpc:laser_shot", AbilityLaser::new);
registerType("cnpc:beam", AbilityBeam::new);
// registerType("cnpc:slicer", AbilitySlicer::new);
registerType(AbilitySweeper::new);
registerType(AbilityOrb::new);
registerType(AbilityDisc::new);
registerType(AbilityLaser::new);
registerType(AbilityBeam::new);
registerType("cnpc:dash", AbilityDash::new);
registerType("cnpc:teleport", AbilityTeleport::new);
registerType(AbilityDash::new);
registerType(AbilityTeleport::new);
registerType("cnpc:vortex", AbilityVortex::new);
registerType("cnpc:shockwave", AbilityShockwave::new);
registerType(AbilityVortex::new);
registerType(AbilityShockwave::new);
registerType("cnpc:guard", AbilityGuard::new);
registerType("cnpc:effect", AbilityEffect::new);
registerType(AbilityGuard::new);
registerType(AbilityEffect::new);
registerType("cnpc:hazard", AbilityHazard::new);
registerType("cnpc:trap", AbilityTrap::new);
registerType(AbilityHazard::new);
registerType(AbilityTrap::new);
registerType("cnpc:dome", AbilityDome::new);
registerType("cnpc:wall", AbilityWall::new);
registerType("cnpc:shield", AbilityShield::new);
registerType(AbilityDome::new);
registerType(AbilityWall::new);
registerType(AbilityShield::new);
}
private void registerBuiltinConditionTypes() {
@@ -193,7 +195,7 @@ public class AbilityController implements IAbilityHandler {
public Ability getAbilityByDisplayName(String displayName) {
for (Ability ability : builtAbilities.values()) {
if (ability.getName().equals(displayName)) {
if (ability.getDisplayName().equals(displayName)) {
return ability;
}
}
@@ -214,8 +216,6 @@ public class AbilityController implements IAbilityHandler {
public void load() {
customAbilities.clear();
customAbilitiesById.clear();
int migrated = 0;
Map<String, String> migratedAbilityNames = new HashMap<String, String>();
File dir = getDir();
File[] files = dir.exists() ? dir.listFiles() : null;
@@ -230,59 +230,29 @@ public class AbilityController implements IAbilityHandler {
Ability ability = fromNBT(nbt);
if (ability == null) continue;
// Skip built-in abilities that were erroneously saved as custom files
if (ability.isBuiltIn()) {
file.delete();
LogWriter.info("Removed stale built-in ability file: " + filename);
continue;
}
String storedName = ability.getName();
String preferredName;
if (UUID_PATTERN.matcher(fileKey).matches()) {
preferredName = (storedName != null && !storedName.isEmpty()) ? storedName : fileKey;
} else {
preferredName = fileKey;
}
String name = FileNameHelper.sanitizeName(preferredName, "Ability");
String name = FileNameHelper.sanitizeName(fileKey, "Ability");
name = makeUniqueNameForLoad(customAbilities, dir, file, name, fileKey);
boolean dirty = false;
if (!name.equals(fileKey)) {
File renamedFile = new File(dir, name + ".json");
if (file.renameTo(renamedFile)) {
LogWriter.info("Migrated ability file: " + fileKey + ".json -> " + name + ".json");
file = renamedFile;
migrated++;
dirty = true;
} else {
LogWriter.error("Failed to rename ability file: " + fileKey + ".json -> " + name + ".json");
}
}
ability.setName(name);
if (storedName != null && !storedName.equals(name)) {
dirty = true;
if (!storedName.isEmpty()) {
migratedAbilityNames.put(storedName, name);
}
}
if (!fileKey.equals(name)) {
migratedAbilityNames.put(fileKey, name);
}
// Ensure ability has a UUID; generate one for legacy abilities
String uuid = ability.getId();
if (uuid == null || uuid.isEmpty() || uuid.equals(fileKey) || uuid.equals(name)) {
// Legacy: id was the name or empty — generate a real UUID
if (uuid == null || uuid.isEmpty()) {
uuid = UUID.randomUUID().toString();
ability.setId(uuid);
migrated++;
dirty = true;
}
if (dirty) {
NBTJsonUtil.SaveFile(file, ability.writeNBT());
NBTJsonUtil.SaveFile(file, ability.writeNBT(true));
}
customAbilities.put(name, ability);
@@ -294,12 +264,9 @@ public class AbilityController implements IAbilityHandler {
}
customAbilityRevision++;
if (migrated > 0) {
LogWriter.info("Migrated " + migrated + " abilities (filename normalization / UUID repair)");
}
LogWriter.info("Loaded " + customAbilities.size() + " custom abilities");
loadChainedAbilities(migratedAbilityNames);
loadChainedAbilities();
}
private boolean nameFileExists(File dir, String name, File ignoredFile) {
@@ -325,32 +292,6 @@ public class AbilityController implements IAbilityHandler {
return candidate;
}
private boolean remapChainEntryReferences(ChainedAbility chain, Map<String, String> migratedAbilityNames) {
if (chain == null || migratedAbilityNames == null || migratedAbilityNames.isEmpty()) return false;
boolean changed = false;
for (ChainedAbilityEntry entry : chain.getEntries()) {
if (entry == null || !entry.isReference()) continue;
String ref = entry.getAbilityReference();
if (ref == null || ref.isEmpty()) continue;
String mapped = migratedAbilityNames.get(ref);
if (mapped == null) {
for (Map.Entry<String, String> e : migratedAbilityNames.entrySet()) {
if (e.getKey().equalsIgnoreCase(ref)) {
mapped = e.getValue();
break;
}
}
}
if (mapped != null && !mapped.equals(ref)) {
entry.setAbilityReference(mapped);
changed = true;
}
}
return changed;
}
public boolean saveCustomAbility(Ability ability) {
if (ability == null) return false;
if (ability.isBuiltIn()) return false;
@@ -396,7 +337,8 @@ public class AbilityController implements IAbilityHandler {
File fileCurrent = new File(dir, name + ".json");
try {
NBTTagCompound nbt = ability.writeNBT();
NBTTagCompound nbt = ability.writeNBT(true);
NBTJsonUtil.SaveFile(fileNew, nbt);
if (fileCurrent.exists()) {
@@ -434,10 +376,11 @@ public class AbilityController implements IAbilityHandler {
}
if (removed == null) return false;
// Also remove from UUID index
// Also remove from UUID index and script handler
String uuid = removed.getId();
if (uuid != null && !uuid.isEmpty()) {
customAbilitiesById.remove(uuid);
abilityScriptHandlers.remove(uuid);
}
File dir = getDir();
@@ -459,6 +402,9 @@ public class AbilityController implements IAbilityHandler {
pData.abilityData.lockAbility(name);
changed = true;
}
if (changed) {
pData.save();
}
}
}
}
@@ -516,10 +462,9 @@ public class AbilityController implements IAbilityHandler {
// CHAINED ABILITIES
// ═══════════════════════════════════════════════════════════════════════════
private void loadChainedAbilities(Map<String, String> migratedAbilityNames) {
private void loadChainedAbilities() {
chainedAbilities.clear();
chainedAbilitiesById.clear();
int migrated = 0;
File dir = getChainedDir();
File[] files = dir.exists() ? dir.listFiles() : null;
@@ -534,7 +479,6 @@ public class AbilityController implements IAbilityHandler {
ChainedAbility chain = new ChainedAbility();
chain.readNBT(nbt);
String storedName = chain.getName();
String name = FileNameHelper.sanitizeName(fileKey, "Chain");
name = makeUniqueNameForLoad(chainedAbilities, dir, file, name, fileKey);
@@ -542,33 +486,22 @@ public class AbilityController implements IAbilityHandler {
if (!name.equals(fileKey)) {
File renamedFile = new File(dir, name + ".json");
if (file.renameTo(renamedFile)) {
LogWriter.info("Migrated chained ability file: " + fileKey + ".json -> " + name + ".json");
file = renamedFile;
dirty = true;
} else {
LogWriter.error("Failed to rename chained ability file: " + fileKey + ".json -> " + name + ".json");
}
}
chain.setName(name);
if (storedName != null && !storedName.equals(name)) {
dirty = true;
}
if (remapChainEntryReferences(chain, migratedAbilityNames)) {
dirty = true;
}
String uuid = chain.getId();
if (uuid == null || uuid.isEmpty() || uuid.equals(fileKey) || uuid.equals(name)) {
if (uuid == null || uuid.isEmpty()) {
uuid = UUID.randomUUID().toString();
chain.setId(uuid);
dirty = true;
}
if (dirty) {
NBTJsonUtil.SaveFile(file, chain.writeNBT());
migrated++;
NBTJsonUtil.SaveFile(file, chain.writeNBT(true));
}
chainedAbilities.put(name, chain);
@@ -580,9 +513,6 @@ public class AbilityController implements IAbilityHandler {
}
chainedAbilityRevision++;
if (migrated > 0) {
LogWriter.info("Migrated " + migrated + " chained abilities");
}
LogWriter.info("Loaded " + chainedAbilities.size() + " chained abilities");
}
@@ -626,7 +556,8 @@ public class AbilityController implements IAbilityHandler {
File fileCurrent = new File(dir, name + ".json");
try {
NBTTagCompound nbt = chain.writeNBT();
NBTTagCompound nbt = chain.writeNBT(true);
NBTJsonUtil.SaveFile(fileNew, nbt);
if (fileCurrent.exists()) {
@@ -667,6 +598,7 @@ public class AbilityController implements IAbilityHandler {
String uuid = removed.getId();
if (uuid != null && !uuid.isEmpty()) {
chainedAbilitiesById.remove(uuid);
chainedAbilityScriptHandlers.remove(uuid);
}
File dir = getChainedDir();
@@ -775,7 +707,7 @@ public class AbilityController implements IAbilityHandler {
}
@Override
public boolean saveChainedAbility(noppes.npcs.api.ability.IChainedAbility chain) {
public boolean saveChainedAbility(IChainedAbility chain) {
if (chain instanceof ChainedAbility) {
return saveChainedAbility((ChainedAbility) chain);
}
@@ -818,48 +750,36 @@ public class AbilityController implements IAbilityHandler {
Ability byUuid = customAbilitiesById.get(key);
if (byUuid != null) return byUuid.deepCopy();
// Built-in: exact name
// Built-in: exact key
Ability builtIn = builtAbilities.get(key);
if (builtIn != null) return builtIn.deepCopy();
// Built-in: case-insensitive map key
// Built-in: case-insensitive key
String lowerKey = key.toLowerCase();
for (Map.Entry<String, Ability> entry : builtAbilities.entrySet()) {
if (entry.getKey().equalsIgnoreCase(key)) {
if (entry.getKey().equalsIgnoreCase(lowerKey)) {
return entry.getValue().deepCopy();
}
}
// Built-in: by ability name (name may differ from map key, e.g. "Ki Fist" vs "ki_fist")
// Built-in: by ID (case-insensitive)
for (Ability ability : builtAbilities.values()) {
if (ability.getName() != null && ability.getName().equalsIgnoreCase(key)) {
if (key.equalsIgnoreCase(ability.getId())) {
return ability.deepCopy();
}
}
// Built-in: registry key / ID
for (Ability ability : builtAbilities.values()) {
if (ability.getId() != null && ability.getId().equalsIgnoreCase(key)) {
return ability.deepCopy();
}
}
// Custom: exact name (fallback for legacy references)
// Custom: exact name
Ability custom = customAbilities.get(key);
if (custom != null) return custom.deepCopy();
// Custom: case-insensitive name
for (Ability ability : customAbilities.values()) {
if (ability.getName() != null && ability.getName().equalsIgnoreCase(key)) {
return ability.deepCopy();
for (Map.Entry<String, Ability> entry : customAbilities.entrySet()) {
if (entry.getKey().equalsIgnoreCase(key)) {
return entry.getValue().deepCopy();
}
}
String sanitizedKey = FileNameHelper.sanitizeTextInput(key);
if (!sanitizedKey.equals(key)) {
Ability sanitized = customAbilities.get(sanitizedKey);
if (sanitized != null) return sanitized.deepCopy();
}
return null;
}
@@ -904,14 +824,8 @@ public class AbilityController implements IAbilityHandler {
}
public boolean hasAbility(String key) {
if (builtAbilities.containsKey(key) || customAbilities.containsKey(key)
|| customAbilitiesById.containsKey(key)) {
return true;
}
String sanitized = FileNameHelper.sanitizeTextInput(key);
return !sanitized.equals(key)
&& (builtAbilities.containsKey(sanitized) || customAbilities.containsKey(sanitized)
|| customAbilitiesById.containsKey(sanitized));
return builtAbilities.containsKey(key) || customAbilities.containsKey(key)
|| customAbilitiesById.containsKey(key);
}
public Ability getCustomAbilityByUUID(String uuid) {
@@ -919,12 +833,30 @@ public class AbilityController implements IAbilityHandler {
}
public Ability getCustomAbilityByName(String name) {
Ability ability = customAbilities.get(name);
if (ability != null) return ability;
String sanitized = FileNameHelper.sanitizeTextInput(name);
if (!sanitized.equals(name)) {
return customAbilities.get(sanitized);
return customAbilities.get(name);
}
/**
* Resolve an ability by key and return the live (non-copied) reference.
* For validation/permission checks only — do NOT expose or modify the returned ability.
* Uses the same lookup chain as {@link #resolveAbility(String)}.
*/
public Ability peekAbility(String key) {
if (key == null || key.isEmpty()) return null;
Ability byUuid = customAbilitiesById.get(key);
if (byUuid != null) return byUuid;
Ability builtIn = builtAbilities.get(key);
if (builtIn != null) return builtIn;
for (Ability ability : builtAbilities.values()) {
if (key.equals(ability.getId())) return ability;
}
Ability custom = customAbilities.get(key);
if (custom != null) return custom;
return null;
}
@@ -935,33 +867,20 @@ public class AbilityController implements IAbilityHandler {
public boolean canResolveAbility(String key) {
if (key == null || key.isEmpty()) return false;
// Custom: UUID lookup (most common for persistent references)
// Custom: UUID lookup
if (customAbilitiesById.containsKey(key)) return true;
// Built-in: exact name
// Built-in: exact key
if (builtAbilities.containsKey(key)) return true;
// Built-in: case-insensitive name
for (String name : builtAbilities.keySet()) {
if (name.equalsIgnoreCase(key)) return true;
}
// Built-in: registry key / ID
// Built-in: by ID
for (Ability ability : builtAbilities.values()) {
if (ability.getId() != null && ability.getId().equalsIgnoreCase(key)) return true;
if (key.equals(ability.getId())) return true;
}
// Custom: exact name (fallback for legacy references)
// Custom: exact name
if (customAbilities.containsKey(key)) return true;
// Custom: case-insensitive name
for (Ability ability : customAbilities.values()) {
if (ability.getName() != null && ability.getName().equalsIgnoreCase(key)) return true;
}
String sanitizedKey = FileNameHelper.sanitizeTextInput(key);
if (!sanitizedKey.equals(key) && customAbilities.containsKey(sanitizedKey)) return true;
return false;
}
@@ -337,7 +337,7 @@ public class SyncController {
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for (Map.Entry<String, Ability> entry : AbilityController.Instance.getCustomAbilities().entrySet()) {
NBTTagCompound abilityNBT = entry.getValue().writeNBT();
NBTTagCompound abilityNBT = entry.getValue().writeNBT(false);
abilityNBT.setString("CustomAbilityId", entry.getKey());
list.appendTag(abilityNBT);
}
@@ -358,7 +358,7 @@ public class SyncController {
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for (Map.Entry<String, ChainedAbility> entry : AbilityController.Instance.getChainedAbilities().entrySet()) {
NBTTagCompound chainNBT = entry.getValue().writeNBT();
NBTTagCompound chainNBT = entry.getValue().writeNBT(false);
chainNBT.setString("ChainedAbilityId", entry.getKey());
list.appendTag(chainNBT);
}
@@ -36,23 +36,20 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import noppes.npcs.DataAbilities;
import noppes.npcs.NpcDamageSource;
import noppes.npcs.api.INbt;
import noppes.npcs.api.ability.IAbility;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
import noppes.npcs.client.gui.builder.FieldDef;
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
import noppes.npcs.controllers.AnimationController;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.PlayerDataScript;
import noppes.npcs.controllers.data.AbilityScript;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.EventHooks;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.AbilityEvent;
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
import java.util.ArrayList;
import java.util.Collections;
@@ -139,6 +136,13 @@ public abstract class Ability implements IAbility, IAbilityAction {
protected transient boolean builtIn = false;
protected transient String registryKey;
// Default icon (set in subclass constructors, NOT persisted)
protected transient String defaultIconTexture = "";
protected transient java.util.function.IntSupplier defaultIconColorSource = null;
protected transient int defaultIconWidth = 48;
protected transient int defaultIconHeight = 48;
protected transient String[] defaultIconStateTextures = null;
// ═══════════════════════════════════════════════════════════════════
// TOGGLE CONFIGURATION (saved to NBT for custom abilities)
// ═══════════════════════════════════════════════════════════════════
@@ -295,28 +299,14 @@ public abstract class Ability implements IAbility, IAbilityAction {
// ═══════════════════════════════════════════════════════════════════
/**
* Called when this toggle ability is first activated (state goes from 0 to any active state).
* Override to apply effects (e.g., set a DBC flag, apply a buff).
*/
public void onToggleOn(EntityLivingBase caster) {
}
/**
* Called when this toggle ability is fully deactivated (state goes to 0).
* Override to remove effects (e.g., clear a DBC flag, remove a buff).
*/
public void onToggleOff(EntityLivingBase caster) {
}
/**
* Called whenever the toggle state changes (including on/off transitions and mid-cycling).
* For multi-state toggles, this fires on every state transition.
* Called whenever the toggle state changes (activation, deactivation, or mid-cycling).
* Override to apply/remove effects based on state transitions.
*
* @param caster The entity
* @param oldState Previous state (0 = was off)
* @param newState New state (0 = now off, 1+ = active state)
*/
public void onToggleStateChanged(EntityLivingBase caster, int oldState, int newState) {
public void onToggle(EntityLivingBase caster, int oldState, int newState) {
}
/**
@@ -432,39 +422,15 @@ public abstract class Ability implements IAbility, IAbilityAction {
private boolean applyAbilityDamageInternal(EntityLivingBase caster, EntityLivingBase hitEntity,
float damage, float knockback, float knockbackUp,
double knockbackDirX, double knockbackDirZ) {
// Fire hit event for NPC casters (NPC event system)
if (caster instanceof EntityNPCInterface) {
EntityNPCInterface npc = (EntityNPCInterface) caster;
DataAbilities dataAbilities = npc.abilities;
AbilityEvent.HitEvent event = dataAbilities.fireHitEvent(
this, currentTarget, hitEntity, damage, knockback, knockbackUp);
if (event == null) {
return false; // Cancelled
}
damage = event.getDamage();
knockback = event.getKnockback();
knockbackUp = event.getKnockbackUp();
}
// Fire hit event for Player casters (Player event system)
else if (caster instanceof EntityPlayer && ScriptController.Instance != null) {
EntityPlayer player = (EntityPlayer) caster;
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
if (handler != null) {
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
PlayerAbilityEvent.HitEvent event = new PlayerAbilityEvent.HitEvent(
iPlayer, this, currentTarget, hitEntity, damage, knockback, knockbackUp);
if (noppes.npcs.EventHooks.onPlayerAbilityHit(handler, event)) {
return false; // Cancelled
}
damage = event.getDamage();
knockback = event.getKnockback();
knockbackUp = event.getKnockbackUp();
}
// Fire hit event (unified — works for both NPC and Player casters)
AbilityEvent.HitEvent hitEvent = new AbilityEvent.HitEvent(
caster, this, currentTarget, hitEntity, damage, knockback, knockbackUp);
if (EventHooks.onAbilityHit(this, hitEvent)) {
return false; // Cancelled
}
damage = hitEvent.getDamage();
knockback = hitEvent.getKnockback();
knockbackUp = hitEvent.getKnockbackUp();
// Save velocity before damage to cancel vanilla knockback when ability knockback is zero
double prevMotionX = hitEntity.motionX;
@@ -809,23 +775,30 @@ public abstract class Ability implements IAbility, IAbilityAction {
}
}
// ── Icon tab (native) ─────────────────────────────────────
// ── Icon section (Effects tab) ───────────────────────────
if (!isNpcInlineEdit()) {
AbilityIconData icon = AbilityIconData.fromAbility(this);
defs.add(FieldDef.section("ability.section.icon").tab("Effects"));
defs.add(FieldDef.boolField("ability.hasIcon", icon::isEnabled, icon::setEnabled)
.tab("Effects"));
defs.add(FieldDef.stringField("gui.texture", icon::getTexture, icon::setTexture)
.tab("Icon"));
defs.add(FieldDef.section("ability.icon.section.uv").tab("Icon"));
.tab("Effects").visibleWhen(icon::isEnabled));
defs.add(FieldDef.section("ability.icon.section.uv").tab("Effects")
.visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("ability.icon.x", icon::getIconX, icon::setIconX)
.tab("Icon").range(0, 4096));
.tab("Effects").range(0, 4096).visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("ability.icon.y", icon::getIconY, icon::setIconY)
.tab("Icon").range(0, 4096));
defs.add(FieldDef.section("gui.size").tab("Icon"));
.tab("Effects").range(0, 4096).visibleWhen(icon::isEnabled));
defs.add(FieldDef.section("gui.size").tab("Effects")
.visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("gui.width", icon::getWidth, icon::setWidth)
.tab("Icon").range(1, 256));
.tab("Effects").range(1, 256).visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("gui.height", icon::getHeight, icon::setHeight)
.tab("Icon").range(1, 256));
.tab("Effects").range(1, 256).visibleWhen(icon::isEnabled));
defs.add(FieldDef.floatField("gui.scale", icon::getScale, icon::setScale)
.tab("Icon").range(0.1f, 10.0f));
.tab("Effects").range(0.1f, 10.0f).visibleWhen(icon::isEnabled));
defs.add(FieldDef.colorSubGui("ability.icon.tint", icon::getTintColor, icon::setTintColor)
.tab("Effects").visibleWhen(icon::isEnabled));
}
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
@@ -1378,7 +1351,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
// NBT (config only, execution state is transient)
// ═══════════════════════════════════════════════════════════════════
public NBTTagCompound writeNBT() {
public NBTTagCompound writeNBT(boolean saveScripts) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("id", id);
nbt.setString("name", name);
@@ -1452,6 +1425,16 @@ public abstract class Ability implements IAbility, IAbilityAction {
writeTypeNBT(typeNBT);
nbt.setTag("typeData", typeNBT);
// Script handler data (matching CustomEffect.writeToNBT pattern)
if (saveScripts) {
AbilityScript handler = getScriptHandler();
if (handler != null) {
NBTTagCompound scriptData = new NBTTagCompound();
handler.writeToNBT(scriptData);
nbt.setTag("ScriptData", scriptData);
}
}
return nbt;
}
@@ -1548,6 +1531,13 @@ public abstract class Ability implements IAbility, IAbilityAction {
if (nbt.hasKey("typeData")) {
readTypeNBT(nbt.getCompoundTag("typeData"));
}
// Script handler data (matching CustomEffect.readFromNBT pattern)
if (nbt.hasKey("ScriptData", 10)) {
AbilityScript handler = new AbilityScript(this.id);
handler.readFromNBT(nbt.getCompoundTag("ScriptData"));
setScriptHandler(handler);
}
}
// ═══════════════════════════════════════════════════════════════════
@@ -1627,8 +1617,48 @@ public abstract class Ability implements IAbility, IAbilityAction {
this.typeId = "ability." + registryKey.replace(':', '.');
}
// ═══════════════════════════════════════════════════════════════════
// DEFAULT ICON
// ═══════════════════════════════════════════════════════════════════
public String getDefaultIconTexture() {
return defaultIconTexture;
}
/**
* Returns the default icon texture for a specific toggle state.
* Falls back to the base defaultIconTexture if no state-specific texture exists.
* @param state 1-indexed toggle state (0 = off/default)
*/
public String getDefaultIconTextureForState(int state) {
if (state > 0 && defaultIconStateTextures != null && state - 1 < defaultIconStateTextures.length) {
return defaultIconStateTextures[state - 1];
}
return defaultIconTexture;
}
public int getDefaultIconColor() {
return defaultIconColorSource != null ? defaultIconColorSource.getAsInt() : 0xFFFFFF;
}
public int getDefaultIconWidth() {
return defaultIconWidth;
}
public int getDefaultIconHeight() {
return defaultIconHeight;
}
public String[] getDefaultIconStateTextures() {
return defaultIconStateTextures;
}
public boolean hasDefaultIcon() {
return defaultIconTexture != null && !defaultIconTexture.isEmpty();
}
public Ability deepCopy() {
return AbilityController.Instance.fromNBT(this.writeNBT());
return AbilityController.Instance.fromNBT(this.writeNBT(true));
}
@Override
@@ -2497,11 +2527,35 @@ public abstract class Ability implements IAbility, IAbilityAction {
@Override
public INbt getNbt() {
return NpcAPI.Instance().getINbt(writeNBT());
return NpcAPI.Instance().getINbt(writeNBT(false));
}
@Override
public void setNbt(INbt nbt) {
readNBT(nbt.getMCNBT());
}
// ═══════════════════════════════════════════════════════════════════
// SCRIPT HANDLER
// ═══════════════════════════════════════════════════════════════════
public AbilityScript getScriptHandler() {
if (this.id == null || this.id.isEmpty()) return null;
return AbilityController.Instance.abilityScriptHandlers.get(this.id);
}
public void setScriptHandler(AbilityScript handler) {
if (this.id == null || this.id.isEmpty()) return;
AbilityController.Instance.abilityScriptHandlers.put(this.id, handler);
}
public AbilityScript getOrCreateScriptHandler() {
if (this.id == null || this.id.isEmpty()) return null;
AbilityScript handler = getScriptHandler();
if (handler == null) {
handler = new AbilityScript(this.id);
AbilityController.Instance.abilityScriptHandlers.put(this.id, handler);
}
return handler;
}
}
@@ -218,7 +218,7 @@ public class AbilityAction {
Ability resolved = getAbility();
if (resolved == null) return false;
inlineAbility = AbilityController.Instance.fromNBT(resolved.writeNBT());
inlineAbility = AbilityController.Instance.fromNBT(resolved.writeNBT(true));
slotType = SlotType.INLINE_ABILITY;
referenceId = null;
cachedAction = null;
@@ -245,12 +245,12 @@ public class AbilityAction {
// NBT
// ═══════════════════════════════════════════════════════════════════
public NBTTagCompound writeNBT() {
public NBTTagCompound writeNBT(boolean saveScripts) {
switch (slotType) {
case INLINE_CHAIN: {
NBTTagCompound nbt = new NBTTagCompound();
if (inlineChain != null) {
nbt.setTag("InlineChain", inlineChain.writeNBT());
nbt.setTag("InlineChain", inlineChain.writeNBT(saveScripts));
}
return nbt;
}
@@ -275,7 +275,7 @@ public class AbilityAction {
case INLINE_ABILITY:
default:
return inlineAbility != null ? inlineAbility.writeNBT() : new NBTTagCompound();
return inlineAbility != null ? inlineAbility.writeNBT(saveScripts) : new NBTTagCompound();
}
}
@@ -0,0 +1,165 @@
package kamkeel.npcs.controllers.data.ability;
import kamkeel.npcs.controllers.data.ability.enums.LockMode;
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
import kamkeel.npcs.controllers.data.ability.enums.UserType;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.ability.ICustomAbility;
import noppes.npcs.client.gui.builder.FieldDef;
import java.util.List;
/**
* A blank-slate ability that does nothing by itself.
* All behavior is driven by script event hooks (abilityStart, abilityTick, abilityComplete,
* abilityToggle, abilityToggleTick).
* <p>
* Supports two modes based on toggle configuration:
* <ul>
* <li><b>Instant mode</b> (toggleStates = 0): Uses standard execution lifecycle with
* configurable duration. Script hooks: abilityStart, abilityTick, abilityComplete.</li>
* <li><b>Toggle mode</b> (toggleStates >= 1): Uses toggle lifecycle.
* Script hooks: abilityToggle, abilityToggleTick.</li>
* </ul>
*/
public class CustomAbility extends Ability implements ICustomAbility {
private int durationTicks = 20;
public CustomAbility() {
this.typeId = "ability.cnpc.custom";
this.name = "Custom";
this.targetingMode = TargetingMode.SELF;
this.lockMovement = LockMode.NO;
this.cooldownTicks = 0;
this.windUpTicks = 0;
this.telegraphType = TelegraphType.NONE;
this.showTelegraph = false;
}
// ==================== EXECUTION ====================
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target) {
if (durationTicks <= 0) {
signalCompletion();
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, int tick) {
if (durationTicks > 0 && tick >= durationTicks) {
signalCompletion();
}
}
// ==================== PROPERTIES ====================
@Override
public boolean hasDamage() {
return false;
}
@Override
public boolean isConcurrentCapable() {
return true;
}
@Override
public boolean isTargetingModeLocked() {
return false;
}
@Override
public boolean allowFreeOnCast() {
return true;
}
// ==================== FIELDS ====================
@Override
public int getDurationTicks() {
return durationTicks;
}
@Override
public void setDurationTicks(int ticks) {
this.durationTicks = Math.max(0, ticks);
}
// ==================== ICustomAbility ====================
@Override
public int getTelegraphShapeType() {
return getTelegraphType().ordinal();
}
@Override
public void setTelegraphShapeType(int type) {
TelegraphType[] values = TelegraphType.values();
if (type >= 0 && type < values.length) {
setTelegraphType(values[type]);
}
}
@Override
public int getTargetingModeType() {
return getTargetingMode().ordinal();
}
@Override
public void setTargetingModeType(int type) {
TargetingMode[] values = TargetingMode.values();
if (type >= 0 && type < values.length) {
setTargetingMode(values[type]);
}
}
// ==================== NBT ====================
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setInteger("durationTicks", durationTicks);
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
this.durationTicks = nbt.getInteger("durationTicks");
}
// ==================== GUI ====================
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
// User Type (NPC / Player / Both)
defs.add(FieldDef.enumField("ability.allowedBy", UserType.class,
this::getAllowedBy, this::setAllowedBy));
// Targeting Mode
defs.add(FieldDef.enumField("ability.targetingMode", TargetingMode.class,
this::getTargetingMode, this::setTargetingMode));
// Telegraph Shape
defs.add(FieldDef.enumField("ability.telegraphShape", TelegraphType.class,
this::getTelegraphType, this::setTelegraphType));
// Toggle section
defs.add(FieldDef.section("ability.section.toggle"));
defs.add(FieldDef.boolField("ability.toggleEnabled",
this::isToggleable, enabled -> setToggleStates(enabled ? Math.max(1, getToggleStates()) : 0)));
defs.add(FieldDef.intField("ability.toggleStates", this::getToggleStates, this::setToggleStates)
.range(1, 10)
.visibleWhen(this::isToggleable));
defs.add(FieldDef.boolField("ability.hasActiveToggle", this::hasActiveToggle, this::setHasActiveToggle)
.visibleWhen(this::isToggleable));
// Duration (instant mode only)
defs.add(FieldDef.section("ability.section.execution")
.visibleWhen(() -> !this.isToggleable()));
defs.add(FieldDef.intField("ability.duration", this::getDurationTicks, this::setDurationTicks)
.range(0, 6000)
.visibleWhen(() -> !this.isToggleable()));
}
}
@@ -21,6 +21,12 @@ public class AbilityIconData {
public int height = 32;
public float scale = 1.0f;
/** Whether a custom icon override is active. Default false = use type's default icon. */
private boolean enabled = false;
/** Manual tint color for the custom icon (0xRRGGBB). Default white = no tint. */
private int tintColor = 0xFFFFFF;
/** Per-state icon UV overrides (0-indexed, maps to toggle states 1, 2, ...). */
private int[][] stateIcons = null;
@@ -64,12 +70,14 @@ public class AbilityIconData {
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setBoolean("Enabled", enabled);
nbt.setString("Texture", texture);
nbt.setInteger("IconX", iconX);
nbt.setInteger("IconY", iconY);
nbt.setInteger("Width", width);
nbt.setInteger("Height", height);
nbt.setFloat("Scale", scale);
nbt.setInteger("TintColor", tintColor);
if (stateIcons != null && stateIcons.length > 0) {
NBTTagList list = new NBTTagList();
for (int[] pair : stateIcons) {
@@ -83,7 +91,9 @@ public class AbilityIconData {
}
public void readFromNBT(NBTTagCompound nbt) {
enabled = nbt.getBoolean("Enabled");
texture = nbt.getString("Texture");
tintColor = nbt.hasKey("TintColor") ? nbt.getInteger("TintColor") : 0xFFFFFF;
iconX = nbt.getInteger("IconX");
iconY = nbt.getInteger("IconY");
width = nbt.getInteger("Width");
@@ -114,6 +124,24 @@ public class AbilityIconData {
// GETTERS AND SETTERS (with auto-save)
// ═══════════════════════════════════════════════════════════════════
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
save();
}
public int getTintColor() {
return tintColor;
}
public void setTintColor(int tintColor) {
this.tintColor = tintColor & 0xFFFFFF;
save();
}
public String getTexture() {
return texture;
}
@@ -2,6 +2,7 @@ package kamkeel.npcs.controllers.data.ability.data;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import noppes.npcs.controllers.data.ChainedAbilityScript;
import kamkeel.npcs.controllers.data.ability.data.entry.ChainedAbilityEntry;
import kamkeel.npcs.controllers.data.ability.enums.UserType;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
@@ -358,7 +359,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
*/
public ChainedAbility deepCopy() {
ChainedAbility copy = new ChainedAbility();
copy.readNBT(this.writeNBT());
copy.readNBT(this.writeNBT(true));
return copy;
}
@@ -376,7 +377,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
// NBT SERIALIZATION
// ═══════════════════════════════════════════════════════════════════
public NBTTagCompound writeNBT() {
public NBTTagCompound writeNBT(boolean saveScripts) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("Id", id);
nbt.setString("Name", name);
@@ -398,13 +399,23 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
// Entries
NBTTagList entryList = new NBTTagList();
for (ChainedAbilityEntry entry : entries) {
entryList.appendTag(entry.writeNBT());
entryList.appendTag(entry.writeNBT(saveScripts));
}
nbt.setTag("Entries", entryList);
// Custom data (for external mods)
nbt.setTag("customData", (NBTTagCompound) customData.copy());
// Script handler data (matching CustomEffect.writeToNBT pattern)
if (saveScripts) {
ChainedAbilityScript handler = getScriptHandler();
if (handler != null) {
NBTTagCompound scriptData = new NBTTagCompound();
handler.writeToNBT(scriptData);
nbt.setTag("ScriptData", scriptData);
}
}
return nbt;
}
@@ -418,7 +429,7 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
cooldownTicks = nbt.hasKey("CooldownTicks") ? nbt.getInteger("CooldownTicks") : 100;
minRange = nbt.getFloat("MinRange");
maxRange = nbt.hasKey("MaxRange") ? nbt.getFloat("MaxRange") : 20;
// AllowedBy is computed from child abilities — old NBT data silently ignored
// AllowedBy is computed from child abilities
// Conditions
conditions.clear();
@@ -442,5 +453,33 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
// Custom data (for external mods)
customData = (NBTTagCompound) nbt.getCompoundTag("customData").copy();
// Script handler data (matching CustomEffect.readFromNBT pattern)
if (nbt.hasKey("ScriptData", 10)) {
ChainedAbilityScript handler = new ChainedAbilityScript(this.id);
handler.readFromNBT(nbt.getCompoundTag("ScriptData"));
setScriptHandler(handler);
}
}
// ═══════════════════════════════════════════════════════════════════
// SCRIPT HANDLER
// ═══════════════════════════════════════════════════════════════════
public ChainedAbilityScript getScriptHandler() {
return AbilityController.Instance.chainedAbilityScriptHandlers.get(this.id);
}
public void setScriptHandler(ChainedAbilityScript handler) {
AbilityController.Instance.chainedAbilityScriptHandlers.put(this.id, handler);
}
public ChainedAbilityScript getOrCreateScriptHandler() {
ChainedAbilityScript handler = getScriptHandler();
if (handler == null) {
handler = new ChainedAbilityScript(this.id);
AbilityController.Instance.chainedAbilityScriptHandlers.put(this.id, handler);
}
return handler;
}
}
@@ -50,5 +50,5 @@ public interface IAbilityAction {
*/
IAbilityAction deepCopyAction();
NBTTagCompound writeNBT();
NBTTagCompound writeNBT(boolean saveScripts);
}
@@ -16,10 +16,6 @@ public class EnergyDisplayData implements IEnergyDisplayData {
public float innerAlpha = 1.0f;
public float rotationSpeed = 4.0f;
// TODO: Skybox Feature
// public boolean skyboxEnabled = false;
// public String skyboxTexture = "";
public EnergyDisplayData() {
}
@@ -122,9 +118,6 @@ public class EnergyDisplayData implements IEnergyDisplayData {
nbt.setFloat("outerColorAlpha", outerColorAlpha);
nbt.setFloat("innerAlpha", innerAlpha);
nbt.setFloat("rotationSpeed", rotationSpeed);
// TODO: Skybox Feature
// nbt.setBoolean("skyboxEnabled", skyboxEnabled);
// nbt.setString("skyboxTexture", skyboxTexture);
}
public void readNBT(NBTTagCompound nbt) {
@@ -135,16 +128,10 @@ public class EnergyDisplayData implements IEnergyDisplayData {
outerColorAlpha = nbt.hasKey("outerColorAlpha") ? nbt.getFloat("outerColorAlpha") : 0.5f;
innerAlpha = nbt.hasKey("innerAlpha") ? nbt.getFloat("innerAlpha") : 1.0f;
rotationSpeed = nbt.hasKey("rotationSpeed") ? nbt.getFloat("rotationSpeed") : 4.0f;
// TODO: Skybox Feature
// skyboxEnabled = nbt.hasKey("skyboxEnabled") && nbt.getBoolean("skyboxEnabled");
// skyboxTexture = nbt.hasKey("skyboxTexture") ? nbt.getString("skyboxTexture") : "";
}
public EnergyDisplayData copy() {
EnergyDisplayData copy = new EnergyDisplayData(innerColor, outerColor, outerColorEnabled, outerColorWidth, outerColorAlpha, innerAlpha, rotationSpeed);
// TODO: Skybox Feature
// copy.skyboxEnabled = skyboxEnabled;
// copy.skyboxTexture = skyboxTexture;
return copy;
}
}
@@ -155,7 +155,7 @@ public class ChainedAbilityEntry {
Ability resolved = ctrl.resolveAbility(abilityReference);
if (resolved == null) return false;
inlineAbility = ctrl.fromNBT(resolved.writeNBT());
inlineAbility = ctrl.fromNBT(resolved.writeNBT(true));
entryType = EntryType.INLINE;
abilityReference = "";
return true;
@@ -175,22 +175,22 @@ public class ChainedAbilityEntry {
copy.delayTicks = this.delayTicks;
copy.concurrentEnabled = this.concurrentEnabled;
if (this.inlineAbility != null) {
copy.inlineAbility = AbilityController.Instance.fromNBT(this.inlineAbility.writeNBT());
copy.inlineAbility = AbilityController.Instance.fromNBT(this.inlineAbility.writeNBT(true));
}
return copy;
}
// ═══════════════════════════════════════════════════════════════════
// NBT (backwards compatible)
// NBT
// ═══════════════════════════════════════════════════════════════════
public NBTTagCompound writeNBT() {
public NBTTagCompound writeNBT(boolean saveScripts) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("Delay", delayTicks);
nbt.setBoolean("Concurrent", concurrentEnabled);
if (entryType == EntryType.INLINE && inlineAbility != null) {
nbt.setTag("InlineAbility", inlineAbility.writeNBT());
nbt.setTag("InlineAbility", inlineAbility.writeNBT(saveScripts));
} else {
nbt.setString("Reference", abilityReference);
}
@@ -204,14 +204,12 @@ public class ChainedAbilityEntry {
entry.delayTicks = Math.max(0, nbt.getInteger("Delay"));
entry.concurrentEnabled = nbt.hasKey("Concurrent") ? nbt.getBoolean("Concurrent") : true;
// Inline entry (new format)
if (nbt.hasKey("InlineAbility")) {
NBTTagCompound abilityNBT = nbt.getCompoundTag("InlineAbility");
entry.entryType = EntryType.INLINE;
entry.inlineAbility = AbilityController.Instance != null
? AbilityController.Instance.fromNBT(abilityNBT) : null;
} else {
// Reference entry (old + new format)
entry.entryType = EntryType.REFERENCE;
entry.abilityReference = nbt.getString("Reference");
}
@@ -137,7 +137,7 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
for (ChainedAbilityEntry entry : chain.getEntries()) {
Ability resolved = entry.resolve();
if (resolved != null && AbilityController.Instance != null) {
Ability copy = AbilityController.Instance.fromNBT(resolved.writeNBT());
Ability copy = AbilityController.Instance.fromNBT(resolved.writeNBT(true));
if (copy != null) {
chainAbilities.add(copy);
chainDelays.add(entry.getDelayTicks());
@@ -55,6 +55,9 @@ public class AbilityBeam extends AbilityEnergyProjectile<EntityAbilityBeam> impl
this.showTelegraph = true;
this.windUpAnimationName = "Ability_Beam_Windup";
this.activeAnimationName = "Ability_Beam_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/beam.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -55,6 +55,9 @@ public class AbilityDisc extends AbilityEnergyProjectile<EntityAbilityDisc> impl
this.showTelegraph = true;
this.windUpAnimationName = "Ability_Disc_Windup";
this.activeAnimationName = "Ability_Disc_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/disc.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -192,20 +192,6 @@ public abstract class AbilityEnergyProjectile<E extends EntityEnergyProjectile>
this.fireDelay = Math.max(0, delay);
}
/**
* @deprecated Use {@link #getFireDelay()}
*/
public int getDualFireDelay() {
return fireDelay;
}
/**
* @deprecated Use {@link #setFireDelay(int)}
*/
public void setDualFireDelay(int delay) {
setFireDelay(delay);
}
protected int clampIndex(int index) {
return Math.max(0, Math.min(index, projectileCount - 1));
}
@@ -53,6 +53,9 @@ public class AbilityLaser extends AbilityEnergyProjectile<EntityAbilityLaser> im
this.showTelegraph = true;
this.windUpAnimationName = "Ability_Laser_Windup";
this.activeAnimationName = "Ability_Laser_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/laser.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
}
// ==================== OVERRIDES ====================
@@ -49,6 +49,9 @@ public class AbilityOrb extends AbilityEnergyProjectile<EntityAbilityOrb> implem
this.showTelegraph = true;
this.windUpAnimationName = "Ability_Orb_Windup";
this.activeAnimationName = "Ability_Orb_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/orb.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -226,6 +226,8 @@ import kamkeel.npcs.network.packets.request.role.RoleCompanionUpdatePacket;
import kamkeel.npcs.network.packets.request.role.RoleGetPacket;
import kamkeel.npcs.network.packets.request.role.RoleSavePacket;
import kamkeel.npcs.network.packets.request.script.BlockScriptPacket;
import kamkeel.npcs.network.packets.request.script.AbilityScriptPacket;
import kamkeel.npcs.network.packets.request.script.ChainedAbilityScriptPacket;
import kamkeel.npcs.network.packets.request.script.EffectScriptPacket;
import kamkeel.npcs.network.packets.request.script.EventScriptPacket;
import kamkeel.npcs.network.packets.request.script.ForgeScriptPacket;
@@ -316,6 +318,8 @@ public class PacketHandler {
REQUEST_PACKET.registerPacket(new ScriptInfoPacket());
REQUEST_PACKET.registerPacket(new ScriptFilesPacket());
REQUEST_PACKET.registerPacket(new EffectScriptPacket());
REQUEST_PACKET.registerPacket(new AbilityScriptPacket());
REQUEST_PACKET.registerPacket(new ChainedAbilityScriptPacket());
// Cloner Packets
REQUEST_PACKET.registerPacket(new CloneListPacket());
@@ -214,4 +214,6 @@ public enum EnumRequestPacket {
RecipeScript,
ManageAuctionAction,
AbilityScript,
ChainedAbilityScript,
}
@@ -62,7 +62,7 @@ public final class BuiltInAbilityGetPacket extends AbstractPacket {
String name = ByteBufUtils.readString(in);
Ability ability = AbilityController.Instance.getAbilityByDisplayName(name);
if (ability != null) {
NBTTagCompound compound = ability.writeNBT();
NBTTagCompound compound = ability.writeNBT(false);
compound.setBoolean("BuiltIn", true);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
@@ -61,7 +61,7 @@ public final class ChainedAbilityGetPacket extends AbstractPacket {
String chainName = ByteBufUtils.readString(in);
ChainedAbility chain = AbilityController.Instance.getChainedAbility(chainName);
if (chain != null) {
NBTTagCompound compound = chain.writeNBT();
NBTTagCompound compound = chain.writeNBT(false);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
}
@@ -73,7 +73,7 @@ public final class ChainedAbilitySavePacket extends AbstractPacket {
if (chain.getName() != null && !chain.getName().isEmpty()) {
AbilityController.Instance.saveChainedAbility(chain);
NoppesUtilServer.sendChainedAbilitiesData((EntityPlayerMP) player);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, chain.writeNBT());
GuiDataPacket.sendGuiData((EntityPlayerMP) player, chain.writeNBT(false));
}
}
}
@@ -61,7 +61,7 @@ public final class CustomAbilityGetPacket extends AbstractPacket {
String abilityName = ByteBufUtils.readString(in);
Ability ability = AbilityController.Instance.getCustomAbility(abilityName);
if (ability != null) {
NBTTagCompound compound = ability.writeNBT();
NBTTagCompound compound = ability.writeNBT(false);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
}
@@ -70,7 +70,7 @@ public final class CustomAbilitySavePacket extends AbstractPacket {
if (ability != null) {
AbilityController.Instance.saveCustomAbility(ability);
NoppesUtilServer.sendCustomAbilitiesData((EntityPlayerMP) player);
NBTTagCompound responseNbt = ability.writeNBT();
NBTTagCompound responseNbt = ability.writeNBT(false);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, responseNbt);
}
}
@@ -0,0 +1,117 @@
package kamkeel.npcs.network.packets.request.script;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.LogWriter;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.controllers.data.AbilityScript;
import noppes.npcs.controllers.data.IScriptHandler;
import java.io.IOException;
public final class AbilityScriptPacket extends AbstractPacket {
public static String packetName = "Request|AbilityScript";
private Action type;
private String abilityId;
private int page;
private int maxSize;
private NBTTagCompound compound;
public AbilityScriptPacket() {
}
public AbilityScriptPacket(Action type, String abilityId, int page, int maxSize, NBTTagCompound compound) {
this.type = type;
this.abilityId = abilityId;
this.page = page;
this.maxSize = maxSize;
this.compound = compound;
}
@Override
public Enum getType() {
return EnumRequestPacket.AbilityScript;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.SCRIPT_PLAYER;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
ByteBufUtils.writeUTF8String(out, abilityId);
if (type == Action.SAVE) {
out.writeInt(this.page);
out.writeInt(this.maxSize);
ByteBufUtils.writeNBT(out, this.compound);
}
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT))
return;
Action requestedAction = Action.values()[in.readInt()];
String id = ByteBufUtils.readUTF8String(in);
Ability ability = AbilityController.Instance.resolveAbility(id);
if (ability == null)
return;
AbilityScript data = ability.getOrCreateScriptHandler();
if (requestedAction == Action.GET) {
PacketUtil.getScripts((IScriptHandler) data, (EntityPlayerMP) player);
} else {
data.saveScript(in);
// Persist to disk
AbilityController.Instance.saveCustomAbility(ability);
if (ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
LogWriter.script(String.format("[%s] (Player) %s SAVED ABILITY SCRIPT %s [%s]",
"ABILITY SCRIPTS", player.getCommandSenderName(), ability.getName(), ability.getId()));
}
}
}
public static void Save(String abilityId, int id, int maxSize, NBTTagCompound compound) {
PacketClient.sendClient(new AbilityScriptPacket(Action.SAVE, abilityId, id, maxSize, compound));
}
public static void Get(String abilityId) {
PacketClient.sendClient(new AbilityScriptPacket(Action.GET, abilityId, -1, -1, new NBTTagCompound()));
}
private enum Action {
GET,
SAVE
}
}
@@ -0,0 +1,117 @@
package kamkeel.npcs.network.packets.request.script;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.LogWriter;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigScript;
import noppes.npcs.controllers.data.ChainedAbilityScript;
import noppes.npcs.controllers.data.IScriptHandler;
import java.io.IOException;
public final class ChainedAbilityScriptPacket extends AbstractPacket {
public static String packetName = "Request|ChainedAbilityScript";
private Action type;
private String chainId;
private int page;
private int maxSize;
private NBTTagCompound compound;
public ChainedAbilityScriptPacket() {
}
public ChainedAbilityScriptPacket(Action type, String chainId, int page, int maxSize, NBTTagCompound compound) {
this.type = type;
this.chainId = chainId;
this.page = page;
this.maxSize = maxSize;
this.compound = compound;
}
@Override
public Enum getType() {
return EnumRequestPacket.ChainedAbilityScript;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.SCRIPT_PLAYER;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(type.ordinal());
ByteBufUtils.writeUTF8String(out, chainId);
if (type == Action.SAVE) {
out.writeInt(this.page);
out.writeInt(this.maxSize);
ByteBufUtils.writeNBT(out, this.compound);
}
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT))
return;
Action requestedAction = Action.values()[in.readInt()];
String id = ByteBufUtils.readUTF8String(in);
ChainedAbility chain = AbilityController.Instance.resolveChainedAbility(id);
if (chain == null)
return;
ChainedAbilityScript data = chain.getOrCreateScriptHandler();
if (requestedAction == Action.GET) {
PacketUtil.getScripts((IScriptHandler) data, (EntityPlayerMP) player);
} else {
data.saveScript(in);
// Persist to disk
AbilityController.Instance.saveChainedAbility(chain);
if (ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
LogWriter.script(String.format("[%s] (Player) %s SAVED CHAIN SCRIPT %s [%s]",
"CHAIN SCRIPTS", player.getCommandSenderName(), chain.getName(), chain.getId()));
}
}
}
public static void Save(String chainId, int id, int maxSize, NBTTagCompound compound) {
PacketClient.sendClient(new ChainedAbilityScriptPacket(Action.SAVE, chainId, id, maxSize, compound));
}
public static void Get(String chainId) {
PacketClient.sendClient(new ChainedAbilityScriptPacket(Action.GET, chainId, -1, -1, new NBTTagCompound()));
}
private enum Action {
GET,
SAVE
}
}
@@ -93,7 +93,7 @@ public class Register<T> {
public void register() {
for (Map.Entry<String, Supplier<Ability>> entry : entries.entrySet()) {
AbilityController.Instance.registerType(entry.getKey(), entry.getValue());
AbilityController.Instance.registerType(entry.getValue());
if (!typeOnly.contains(entry.getKey())) {
AbilityController.Instance.registerAbility(uniqueNames.get(entry.getKey()), entry.getValue().get());
}