mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 11:32:20 +00:00
Add Chained Abilities
This commit is contained in:
1 parent
0311dc5806
commit
0512588a7a
51 files changed
+2955
-800
No files matched your search
@@ -1,26 +1,74 @@
|
||||
package kamkeel.npcs.controllers.data.ability;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* A single entry in a {@link ChainedAbility}, representing one ability
|
||||
* to execute in sequence along with its delay configuration.
|
||||
* <p>
|
||||
* Entries can be either a <b>reference</b> to a registered ability (by name/key)
|
||||
* or an <b>inline</b> ability that is owned directly by this entry.
|
||||
*/
|
||||
public class ChainedAbilityEntry {
|
||||
|
||||
/** Reference key (built-in name or custom ability name). */
|
||||
public enum EntryType { REFERENCE, INLINE }
|
||||
|
||||
private EntryType entryType = EntryType.REFERENCE;
|
||||
|
||||
/** Reference key (built-in name or custom ability name). Used when entryType == REFERENCE. */
|
||||
private String abilityReference = "";
|
||||
|
||||
/** Inline ability data. Used when entryType == INLINE. */
|
||||
private Ability inlineAbility = null;
|
||||
|
||||
/** Delay in ticks BEFORE this ability starts (after previous entry completes). */
|
||||
private int delayTicks = 0;
|
||||
|
||||
public ChainedAbilityEntry() {}
|
||||
|
||||
public ChainedAbilityEntry(String abilityReference, int delayTicks) {
|
||||
this.entryType = EntryType.REFERENCE;
|
||||
this.abilityReference = abilityReference != null ? abilityReference : "";
|
||||
this.delayTicks = Math.max(0, delayTicks);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// FACTORY METHODS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public static ChainedAbilityEntry reference(String ref, int delay) {
|
||||
ChainedAbilityEntry entry = new ChainedAbilityEntry();
|
||||
entry.entryType = EntryType.REFERENCE;
|
||||
entry.abilityReference = ref != null ? ref : "";
|
||||
entry.delayTicks = Math.max(0, delay);
|
||||
return entry;
|
||||
}
|
||||
|
||||
public static ChainedAbilityEntry inline(Ability ability, int delay) {
|
||||
ChainedAbilityEntry entry = new ChainedAbilityEntry();
|
||||
entry.entryType = EntryType.INLINE;
|
||||
entry.inlineAbility = ability;
|
||||
entry.delayTicks = Math.max(0, delay);
|
||||
return entry;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// TYPE QUERIES
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public EntryType getEntryType() {
|
||||
return entryType;
|
||||
}
|
||||
|
||||
public boolean isInline() {
|
||||
return entryType == EntryType.INLINE;
|
||||
}
|
||||
|
||||
public boolean isReference() {
|
||||
return entryType == EntryType.REFERENCE;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// GETTERS / SETTERS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -33,6 +81,14 @@ public class ChainedAbilityEntry {
|
||||
this.abilityReference = abilityReference != null ? abilityReference : "";
|
||||
}
|
||||
|
||||
public Ability getInlineAbility() {
|
||||
return inlineAbility;
|
||||
}
|
||||
|
||||
public void setInlineAbility(Ability ability) {
|
||||
this.inlineAbility = ability;
|
||||
}
|
||||
|
||||
public int getDelayTicks() {
|
||||
return delayTicks;
|
||||
}
|
||||
@@ -42,13 +98,77 @@ public class ChainedAbilityEntry {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT
|
||||
// RESOLUTION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Resolve this entry to an Ability instance.
|
||||
* Inline entries return their ability directly.
|
||||
* Reference entries resolve via AbilityController.
|
||||
*/
|
||||
public Ability resolve() {
|
||||
if (entryType == EntryType.INLINE) {
|
||||
return inlineAbility;
|
||||
}
|
||||
AbilityController ctrl = AbilityController.Instance;
|
||||
if (ctrl == null) return null;
|
||||
return ctrl.resolveAbility(abilityReference);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONVERSION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Convert a reference entry to inline by cloning the resolved ability.
|
||||
* Returns false if already inline or the reference cannot be resolved.
|
||||
*/
|
||||
public boolean convertToInline() {
|
||||
if (entryType != EntryType.REFERENCE) return false;
|
||||
|
||||
AbilityController ctrl = AbilityController.Instance;
|
||||
if (ctrl == null) return false;
|
||||
|
||||
Ability resolved = ctrl.resolveAbility(abilityReference);
|
||||
if (resolved == null) return false;
|
||||
|
||||
inlineAbility = ctrl.fromNBT(resolved.writeNBT());
|
||||
entryType = EntryType.INLINE;
|
||||
abilityReference = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// DEEP COPY
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Create a deep copy of this entry. Inline abilities are copied via NBT round-trip.
|
||||
*/
|
||||
public ChainedAbilityEntry deepCopy() {
|
||||
ChainedAbilityEntry copy = new ChainedAbilityEntry();
|
||||
copy.entryType = this.entryType;
|
||||
copy.abilityReference = this.abilityReference;
|
||||
copy.delayTicks = this.delayTicks;
|
||||
if (this.inlineAbility != null) {
|
||||
copy.inlineAbility = AbilityController.Instance.fromNBT(this.inlineAbility.writeNBT());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT (backwards compatible)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public NBTTagCompound writeNBT() {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("Reference", abilityReference);
|
||||
nbt.setInteger("Delay", delayTicks);
|
||||
|
||||
if (entryType == EntryType.INLINE && inlineAbility != null) {
|
||||
nbt.setTag("InlineAbility", inlineAbility.writeNBT());
|
||||
} else {
|
||||
nbt.setString("Reference", abilityReference);
|
||||
}
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@@ -56,8 +176,20 @@ public class ChainedAbilityEntry {
|
||||
if (nbt == null) return null;
|
||||
|
||||
ChainedAbilityEntry entry = new ChainedAbilityEntry();
|
||||
entry.abilityReference = nbt.getString("Reference");
|
||||
entry.delayTicks = Math.max(0, nbt.getInteger("Delay"));
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user