Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vidal committed 2026-02-12 10:22:52 -03:00
commit 4d19e90c0d
60 files changed
+3904 -3901

No files matched your search

+1 -1
Submodule src/api updated: f383fc3037...fd4c77d015.
@@ -43,7 +43,16 @@ public class RenderAbilityDisc extends RenderAbilityProjectile {
GL11.glPushMatrix();
GL11.glScalef(scale, scale, scale);
// Apply ONLY Y-axis rotation for flat spin
if (disc.isVertical()) {
// Vertical mode: thin edge faces direction of travel (like a saw blade)
// 1. Spin in local space (Y-axis)
// 2. Tilt 90° to stand up (X-axis)
// 3. Orient to face travel direction (Y-axis world yaw)
GL11.glRotatef(disc.getTravelYaw(), 0.0f, 1.0f, 0.0f);
GL11.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
}
// Apply Y-axis rotation for spin
GL11.glRotatef(disc.getInterpolatedRotationY(partialTicks), 0.0f, 1.0f, 0.0f);
// Inner scale defines the core size
@@ -31,7 +31,7 @@ public abstract class RenderAbilityProjectile extends Render {
*/
protected void setupRenderState() {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_ALPHA_TEST);
@@ -88,17 +88,14 @@ public class AttachedLightningRenderer {
/**
* Render all active arcs in local space.
* Call this after glTranslated to entity position.
* Note: Expects the caller to have already set up GL state (disabled textures,
* disabled lighting, disabled culling, enabled blending). This avoids nesting
* glPushAttrib calls which can overflow the GL attrib stack (depth 16) when
* other mods also push attribs during entity rendering.
*/
public void render() {
if (arcs.isEmpty()) return;
// Setup GL state
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDepthMask(false);
Tessellator tess = Tessellator.instance;
@@ -114,7 +111,6 @@ public class AttachedLightningRenderer {
}
GL11.glDepthMask(true);
GL11.glPopAttrib();
}
public int getArcCount() {
@@ -239,6 +235,8 @@ public class AttachedLightningRenderer {
/**
* Render a single instant lightning arc (no fading, drawn this frame only).
* Expects the caller to have already set up GL state (disabled textures,
* disabled lighting, disabled culling, enabled blending).
*/
public static void renderInstantArc(float radius, int outerColor, int innerColor) {
double theta = rand.nextDouble() * Math.PI * 2;
@@ -254,12 +252,6 @@ public class AttachedLightningRenderer {
List<double[]> points = generateLightningPath(0, 0, 0, endX, endY, endZ, segments, displacement);
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDepthMask(false);
Tessellator tess = Tessellator.instance;
@@ -267,7 +259,6 @@ public class AttachedLightningRenderer {
renderBoltPath(tess, points, innerColor, 0.012f, 0.7f);
GL11.glDepthMask(true);
GL11.glPopAttrib();
}
/**
@@ -2,7 +2,12 @@ package kamkeel.npcs.command;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.controllers.data.ability.UserType;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.PlayerData;
import java.util.ArrayList;
import java.util.Collections;
@@ -122,5 +127,192 @@ public class AbilityCommand extends CommandKamkeelBase {
}
sendResult(sender, " Range: \u00A7e" + ability.getMinRange() + " - " + ability.getMaxRange());
sendResult(sender, " Telegraph: \u00A7e" + (ability.isShowTelegraph() ? "Yes" : "No"));
sendResult(sender, " Allowed By: \u00A7e" + ability.getAllowedBy().name());
}
@SubCommand(
desc = "List all built-in abilities available for players"
)
public void prebuilts(ICommandSender sender, String[] args) {
Set<String> names = AbilityController.Instance.getAbilityNames();
if (names.isEmpty()) {
sendResult(sender, "No built-in abilities found.");
return;
}
List<String> playerAbilities = new ArrayList<>();
for (String name : names) {
Ability ability = AbilityController.Instance.getAbility(name);
if (ability != null && ability.getAllowedBy().allowsPlayer()) {
playerAbilities.add(name);
}
}
if (playerAbilities.isEmpty()) {
sendResult(sender, "No player-usable built-in abilities found.");
return;
}
Collections.sort(playerAbilities);
sendResult(sender, "Built-in Player Abilities (" + playerAbilities.size() + "):");
for (String name : playerAbilities) {
Ability ability = AbilityController.Instance.getAbility(name);
String userType = ability.getAllowedBy() == UserType.PLAYER_ONLY ? "\u00A7d[PLAYER]" : "\u00A7a[BOTH]";
sendResult(sender, " - \u00A7b" + name + " " + userType);
}
}
@SubCommand(
desc = "Unlock an ability for a player",
usage = "<player> <ability>"
)
public void unlock(ICommandSender sender, String[] args) {
if (args.length < 2) {
sendError(sender, "Usage: /kam ability unlock <player> <ability>");
return;
}
String playerName = args[0];
String abilityKey = joinArgs(args, 1);
// Find player
EntityPlayerMP player = (EntityPlayerMP) NoppesUtilServer.getPlayerByName(playerName);
if (player == null) {
sendError(sender, "Player not found: " + playerName);
return;
}
// Resolve ability
Ability ability = AbilityController.Instance.resolveAbility(abilityKey);
if (ability == null) {
sendError(sender, "Ability not found: " + abilityKey);
return;
}
// Use the ability's canonical ID for storage (registry key for built-in, UUID for custom)
String canonicalKey = ability.getId();
if (canonicalKey == null || canonicalKey.isEmpty()) {
canonicalKey = abilityKey; // Fallback to user-provided key
}
String displayName = ability.getName() != null ? ability.getName() : canonicalKey;
// Check if ability allows players
if (!ability.getAllowedBy().allowsPlayer()) {
sendError(sender, "Ability '\u00A7b" + displayName + "\u00A7c' is NPC-only and cannot be given to players.");
return;
}
// Get player data and unlock
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
if (data.abilityData.hasUnlockedAbility(canonicalKey)) {
sendError(sender, "Player already has ability: " + displayName);
return;
}
data.abilityData.unlockAbility(canonicalKey);
sendResult(sender, "Unlocked ability '\u00A7b" + displayName + "\u00A77' for player \u00A7a" + playerName);
}
@SubCommand(
desc = "Lock (revoke) an ability from a player",
usage = "<player> <ability>"
)
public void lock(ICommandSender sender, String[] args) {
if (args.length < 2) {
sendError(sender, "Usage: /kam ability lock <player> <ability>");
return;
}
String playerName = args[0];
String abilityKey = joinArgs(args, 1);
// Find player
EntityPlayerMP player = (EntityPlayerMP) NoppesUtilServer.getPlayerByName(playerName);
if (player == null) {
sendError(sender, "Player not found: " + playerName);
return;
}
// Resolve ability to get canonical key
Ability ability = AbilityController.Instance.resolveAbility(abilityKey);
String canonicalKey = abilityKey;
String displayName = abilityKey;
if (ability != null) {
canonicalKey = ability.getId() != null ? ability.getId() : abilityKey;
displayName = ability.getName() != null ? ability.getName() : canonicalKey;
}
// Get player data and lock
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
if (!data.abilityData.hasUnlockedAbility(canonicalKey)) {
sendError(sender, "Player doesn't have ability: " + displayName);
return;
}
data.abilityData.lockAbility(canonicalKey);
sendResult(sender, "Locked ability '\u00A7b" + displayName + "\u00A77' from player \u00A7a" + playerName);
}
@SubCommand(
desc = "List abilities unlocked for a player",
usage = "<player>"
)
public void player(ICommandSender sender, String[] args) {
if (args.length < 1) {
sendError(sender, "Usage: /kam ability player <player>");
return;
}
String playerName = args[0];
// Find player
EntityPlayerMP player = (EntityPlayerMP) NoppesUtilServer.getPlayerByName(playerName);
if (player == null) {
sendError(sender, "Player not found: " + playerName);
return;
}
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
String[] abilityKeys = data.abilityData.getUnlockedAbilities();
if (abilityKeys.length == 0) {
sendResult(sender, "Player \u00A7a" + playerName + "\u00A77 has no unlocked abilities.");
return;
}
sendResult(sender, "Abilities for \u00A7a" + playerName + "\u00A77 (" + abilityKeys.length + "):");
int selected = data.abilityData.getSelectedIndex();
for (int i = 0; i < abilityKeys.length; i++) {
String key = abilityKeys[i];
Ability ability = AbilityController.Instance.resolveAbility(key);
String displayName = ability != null && ability.getName() != null ? ability.getName() : key;
String prefix = (i == selected) ? "\u00A7e> " : " ";
// Show display name and key if different
if (!displayName.equals(key)) {
sendResult(sender, prefix + "\u00A7b" + displayName + " \u00A78[" + key + "]");
} else {
sendResult(sender, prefix + "\u00A7b" + displayName);
}
}
}
private String joinArgs(String[] args, int startIndex) {
StringBuilder sb = new StringBuilder();
for (int i = startIndex; i < args.length; i++) {
if (i > startIndex) sb.append(" ");
sb.append(args[i]);
}
return sb.toString();
}
/**
* Get list of player-usable ability keys (for tab completion).
* Uses registry keys for built-in abilities (no spaces) and UUIDs for custom.
* Used by CommandKamkeel for <ability> usage token.
*/
public static List<String> getPlayerAbilityNames() {
List<String> keys = new ArrayList<>(AbilityController.Instance.getPlayerAbilityKeys());
Collections.sort(keys);
return keys;
}
}
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static kamkeel.npcs.command.AbilityCommand.getPlayerAbilityNames;
import static kamkeel.npcs.command.EffectCommand.getSortedEffectNames;
public class CommandKamkeel extends CommandBase {
@@ -135,6 +136,9 @@ public class CommandKamkeel extends CommandBase {
} else if (usage.equals("<effectName>")) {
List<String> keys = getSortedEffectNames();
return CommandBase.getListOfStringsMatchingLastWord(args, keys.toArray(new String[keys.size()]));
} else if (usage.equals("<ability>")) {
List<String> keys = getPlayerAbilityNames();
return CommandBase.getListOfStringsMatchingLastWord(args, keys.toArray(new String[keys.size()]));
}
}
}
@@ -32,6 +32,7 @@ import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
import noppes.npcs.client.gui.builder.FieldDef;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.entity.Entity;
@@ -67,7 +68,8 @@ public abstract class Ability implements IAbility {
// Feedback
protected LockMovementType lockMovement = LockMovementType.WINDUP;
protected LockType lockType = LockType.BOTH;
protected RotationMode rotationMode = RotationMode.FREE;
protected LockMovementType rotationPhase = LockMovementType.WINDUP_AND_ACTIVE;
protected int windUpColor = 0x80FF4400; // Telegraph color during wind up
protected int activeColor = 0xC0FF0000; // Telegraph warning/active color
@@ -100,6 +102,13 @@ public abstract class Ability implements IAbility {
// Configurable potion effects
protected List<AbilityEffect> effects = new ArrayList<>();
// Burst
protected boolean burstEnabled = false;
protected int burstAmount = 0; // number of EXTRA repetitions
protected int burstDelay = 0; // ticks between bursts
protected boolean burstReplayAnimations = true;
protected boolean burstOverlap = false; // if true, don't wait for entity death between bursts
// ═══════════════════════════════════════════════════════════════════
// EXECUTION STATE (not saved, reset each combat)
// ═══════════════════════════════════════════════════════════════════
@@ -110,6 +119,17 @@ public abstract class Ability implements IAbility {
protected transient long executionStartTime;
protected transient TelegraphInstance telegraphInstance;
// Burst execution state
protected transient int burstIndex = 0;
protected transient List<Entity> burstEntities = new ArrayList<>();
// ═══════════════════════════════════════════════════════════════════
// PREVIEW STATE (client-side only, not saved)
// ═══════════════════════════════════════════════════════════════════
protected transient boolean previewMode = false;
protected transient PreviewEntityHandler previewEntityHandler;
// ═══════════════════════════════════════════════════════════════════
// ABSTRACT METHODS
// ═══════════════════════════════════════════════════════════════════
@@ -148,6 +168,50 @@ public abstract class Ability implements IAbility {
return true;
}
/**
* Override to provide variant templates for this ability type.
* When a user creates this ability type, they will be shown a selection dialog
* with the returned variants. If empty or single-entry, the dialog is skipped.
*/
public List<AbilityVariant> getVariants() {
return Collections.emptyList();
}
/**
* Whether this ability type supports the burst system.
* Override to return false for abilities that shouldn't repeat (Guard, Heal, Sweeper, etc.).
*/
public boolean allowBurst() {
return true;
}
/**
* Whether this ability supports overlap mode for burst (entities from previous bursts keep flying).
* Override to return true for entity-spawning projectile abilities (Orb, Beam, Disc, LaserShot).
*/
public boolean allowOverlap() {
return false;
}
/**
* Whether this ability is ready for auto-completion during burst overlap mode.
* Override to delay auto-completion until all staggered projectiles have been fired.
* @param activeTick the current tick within the ACTIVE phase
*/
public boolean isReadyForBurstCompletion(int activeTick) {
return true;
}
/**
* Called when burst re-fires without replay animations (burstReplayAnimations=false).
* Entity-spawning abilities should override to spawn and fire entities in one step,
* since onWindUpTick was not called (windup was skipped).
* Default: does nothing (ability goes directly to onExecute with existing state).
*/
public void onBurstRefire(EntityLivingBase caster, EntityLivingBase target, World world) {
// Override in entity-spawning abilities (Orb, Beam, Disc, LaserShot)
}
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
}
@@ -328,6 +392,18 @@ public abstract class Ability implements IAbility {
return 45.0f;
}
/**
* Returns true if the caster is a player (not an NPC).
* Use this instead of checking {@code target != null} to make NPC/Player
* code paths explicit and readable.
* <p>
* NPCs always have an aggro target passed to ability methods.
* Players never do — they use look direction for aiming instead.
*/
protected final boolean isPlayerCaster(EntityLivingBase caster) {
return caster instanceof EntityPlayer;
}
/**
* Returns true if this ability controls NPC movement during ACTIVE phase.
* When true, AI pathfinding will be blocked during ability execution.
@@ -411,26 +487,33 @@ public abstract class Ability implements IAbility {
defs.add(FieldDef.intField("ability.cooldownTicks", this::getCooldownTicks, this::setCooldownTicks)
.tab("General").range(0, 10000));
defs.add(FieldDef.section("ability.section.movement").tab("General"));
defs.add(FieldDef.row(
FieldDef.stringEnumField("ability.lockPosition", LockMovementType.getDisplayKeys(),
defs.add(FieldDef.stringEnumField("ability.lockMovement", LockMovementType.getDisplayKeys(),
() -> this.getLockMovement().getDisplayKey(),
v -> {
String[] keys = LockMovementType.getDisplayKeys();
for (int i = 0; i < keys.length; i++) {
if (keys[i].equals(v)) { this.setLockMovement(LockMovementType.fromOrdinal(i)); break; }
for (LockMovementType t : LockMovementType.values()) {
if (t.getDisplayKey().equals(v)) { this.setLockMovement(t); break; }
}
})
.hover("ability.hover.lockPosition"),
FieldDef.stringEnumField("ability.lockType", LockType.getDisplayKeys(),
() -> this.getLockType().getDisplayKey(),
.hover("ability.hover.lockMovement")
.tab("General"));
defs.add(FieldDef.row(
FieldDef.stringEnumField("ability.rotationMode", RotationMode.getDisplayKeys(),
() -> this.getRotationMode().getDisplayKey(),
v -> {
String[] keys = LockType.getDisplayKeys();
for (int i = 0; i < keys.length; i++) {
if (keys[i].equals(v)) { this.setLockType(LockType.fromOrdinal(i)); break; }
for (RotationMode m : RotationMode.values()) {
if (m.getDisplayKey().equals(v)) { this.setRotationMode(m); break; }
}
})
.hover("ability.hover.lockType")
.visibleWhen(() -> this.lockMovement != LockMovementType.NO)
.hover("ability.hover.rotationMode"),
FieldDef.stringEnumField("ability.rotationPhase", getRotationPhaseKeys(),
() -> this.getRotationPhase().getDisplayKey(),
v -> {
for (LockMovementType t : LockMovementType.values()) {
if (t.getDisplayKey().equals(v)) { this.setRotationPhase(t); break; }
}
})
.hover("ability.hover.rotationPhase")
.visibleWhen(() -> this.rotationMode != RotationMode.FREE)
).tab("General"));
defs.add(FieldDef.row(
FieldDef.boolField("ability.interruptible", this::isInterruptible, this::setInterruptible)
@@ -439,6 +522,25 @@ public abstract class Ability implements IAbility {
.range(0, 1000).visibleWhen(this::isInterruptible)
).tab("General"));
// ── Burst section ────────────────────────────────────────────
if (allowBurst()) {
defs.add(FieldDef.section("ability.section.burst").tab("General"));
defs.add(FieldDef.boolField("ability.burstEnabled", this::isBurstEnabled, this::setBurstEnabled)
.tab("General"));
defs.add(FieldDef.row(
FieldDef.intField("ability.burstAmount", this::getBurstAmount, this::setBurstAmount).range(1, 100),
FieldDef.intField("ability.burstDelay", this::getBurstDelay, this::setBurstDelay).range(0, 1000)
).tab("General").visibleWhen(this::isBurstEnabled));
defs.add(FieldDef.boolField("ability.burstReplayAnimations", this::isBurstReplayAnimations, this::setBurstReplayAnimations)
.tab("General").visibleWhen(this::isBurstEnabled)
.hover("ability.hover.burstReplay"));
if (allowOverlap()) {
defs.add(FieldDef.boolField("ability.burstOverlap", this::isBurstOverlap, this::setBurstOverlap)
.tab("General").visibleWhen(this::isBurstEnabled)
.hover("ability.hover.burstOverlap"));
}
}
// ── Target tab ───────────────────────────────────────────────
defs.add(FieldDef.row(
FieldDef.intField("ability.minRange", () -> (int) getMinRange(), v -> setMinRange(v)).range(0, 100),
@@ -599,12 +701,12 @@ public abstract class Ability implements IAbility {
instance.setEntityIdToFollow(caster.getEntityId());
// For LINE/CONE telegraphs: track target direction during windup
// Only track if movement is NOT locked during windup (locked = NPC can't rotate)
// Only track if rotation is NOT locked during windup (NPC can still turn)
if ((telegraphType == TelegraphType.LINE || telegraphType == TelegraphType.CONE) && target != null) {
if (!lockMovement.locksWindup()) {
if (!isRotationLockedDuringWindup()) {
instance.setTargetEntityId(target.getEntityId());
}
// If windup is locked, yaw stays fixed at creation time
// If rotation is locked, yaw stays fixed at creation time
}
} else if (target != null) {
// AOE_TARGET abilities: telegraph follows target during windup
@@ -707,6 +809,8 @@ public abstract class Ability implements IAbility {
this.currentTick = 0;
this.currentTarget = target;
this.executionStartTime = System.currentTimeMillis();
this.burstIndex = 0;
this.burstEntities.clear();
if (windUpTicks <= 0) {
this.phase = AbilityPhase.ACTIVE;
@@ -749,6 +853,19 @@ public abstract class Ability implements IAbility {
return true;
}
break;
case BURST_DELAY:
// Waiting between burst repetitions - free movement/rotation
if (currentTick >= burstDelay) {
if (burstReplayAnimations && getWindUpTicks() > 0) {
phase = AbilityPhase.WINDUP;
} else {
phase = AbilityPhase.ACTIVE;
}
currentTick = 0;
return true;
}
break;
}
return false;
}
@@ -762,6 +879,19 @@ public abstract class Ability implements IAbility {
*/
public boolean signalCompletion() {
if (phase == AbilityPhase.ACTIVE) {
// Check if more burst iterations remain
if (burstEnabled && burstAmount > 0 && burstIndex < burstAmount) {
if (!burstOverlap) {
cleanup();
}
burstIndex++;
phase = AbilityPhase.BURST_DELAY;
currentTick = 0;
return true;
}
// Final completion - let burst entities die naturally (don't force-kill)
burstEntities.clear();
cleanup();
phase = AbilityPhase.IDLE;
currentTick = 0;
@@ -775,9 +905,10 @@ public abstract class Ability implements IAbility {
* Called when NPC takes direct damage during WINDUP.
*/
public void interrupt() {
cleanupBurstEntities();
cleanup();
if (interruptible && phase == AbilityPhase.WINDUP) {
// Interrupted during windup - go to dazed state
if (interruptible && (phase == AbilityPhase.WINDUP || phase == AbilityPhase.BURST_DELAY)) {
// Interrupted during windup or burst delay - go to dazed state
phase = AbilityPhase.DAZED;
currentTick = 0;
} else {
@@ -785,6 +916,7 @@ public abstract class Ability implements IAbility {
phase = AbilityPhase.IDLE;
currentTick = 0;
}
burstIndex = 0;
currentTarget = null;
telegraphInstance = null;
}
@@ -805,7 +937,7 @@ public abstract class Ability implements IAbility {
* @return true if the ability should be interrupted
*/
public boolean canInterrupt(DamageSource source) {
if (!interruptible || phase != AbilityPhase.WINDUP) {
if (!interruptible || (phase != AbilityPhase.WINDUP && phase != AbilityPhase.BURST_DELAY)) {
return false;
}
@@ -832,11 +964,15 @@ public abstract class Ability implements IAbility {
* Reset all execution state (called on combat end, NPC death, target lost, etc.)
*/
public void reset() {
cleanupBurstEntities();
cleanup();
phase = AbilityPhase.IDLE;
currentTick = 0;
burstIndex = 0;
currentTarget = null;
telegraphInstance = null;
previewMode = false;
previewEntityHandler = null;
}
/**
@@ -848,91 +984,73 @@ public abstract class Ability implements IAbility {
// Override in subclasses to clean up spawned entities, etc.
}
/**
* Kill all entities tracked during burst overlap and clear the list.
*/
protected void cleanupBurstEntities() {
for (Entity e : burstEntities) {
if (e != null && !e.isDead) {
killAbilityEntity(e);
}
}
burstEntities.clear();
}
// ═══════════════════════════════════════════════════════════════════
// CLIENT-SIDE PREVIEW METHODS
// PREVIEW MODE SUPPORT
// ═══════════════════════════════════════════════════════════════════
/**
* Get total active phase duration for preview (in ticks).
* Override in subclasses to provide accurate preview duration.
*
* @return Duration of active phase in ticks (default: 40 = 2 seconds)
* Whether this ability is running in preview mode (GUI preview).
* When true, abilities should skip damage, effects, sounds, and particles
* but still run their core logic (entity spawning, movement, timing).
*/
public int getPreviewActiveDuration() {
return 40;
public boolean isPreview() {
return previewMode;
}
public void setPreviewMode(boolean preview) {
this.previewMode = preview;
}
public void setPreviewEntityHandler(PreviewEntityHandler handler) {
this.previewEntityHandler = handler;
}
/**
* Called during preview windup tick (client-side only).
* Override for visual updates during windup preview.
* Do NOT apply damage or world effects here.
*
* @param npc The preview NPC
* @param tick Current tick within windup phase
* Spawn an entity during ability execution.
* In preview mode, routes to PreviewEntityHandler instead of world.spawnEntityInWorld().
*/
@SideOnly(Side.CLIENT)
public void onPreviewWindUpTick(EntityNPCInterface npc, int tick) {
// Default: no-op. Override in subclasses for visual effects.
protected void spawnAbilityEntity(World world, Entity entity) {
if (previewMode && previewEntityHandler != null) {
previewEntityHandler.onEntitySpawned(entity);
} else {
world.spawnEntityInWorld(entity);
}
if (burstEnabled && burstOverlap) {
burstEntities.add(entity);
}
}
/**
* Called during preview active tick (client-side only).
* Override for visual updates during active preview.
* Do NOT apply damage or world effects here.
*
* @param npc The preview NPC
* @param tick Current tick within active phase
* Kill an entity spawned by this ability.
* In preview mode, notifies PreviewEntityHandler of removal.
*/
@SideOnly(Side.CLIENT)
public void onPreviewActiveTick(EntityNPCInterface npc, int tick) {
// Default: no-op. Override in subclasses for visual effects.
protected void killAbilityEntity(Entity entity) {
if (entity == null) return;
entity.setDead();
if (previewMode && previewEntityHandler != null) {
previewEntityHandler.onEntityRemoved(entity);
}
}
/**
* Create a preview entity for GUI display (client-side only).
* The entity should be in preview mode and not apply damage.
* Override in abilities that spawn entities (Beam, Orb, Disc, etc.)
*
* @param npc The preview NPC
* @return Preview entity, or null if ability doesn't spawn entities
* Maximum duration (in ticks) for preview before auto-stopping.
* Override in movement abilities that have variable duration.
* Default: 200 ticks (10 seconds).
*/
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
return null; // Override in entity-spawning abilities
}
/**
* Whether to spawn preview entity during WINDUP phase (true) or ACTIVE phase (false).
* Most abilities (Orb, Beam, Disc) spawn during windup for charging effect.
* Laser spawns at active phase since it has no charging state.
*/
public boolean spawnPreviewDuringWindup() {
return true; // Default: spawn during windup for charging
}
// ── Preview target (set by executor for abilities that need targeting) ──
protected transient EntityLivingBase previewTarget;
/**
* Set the fake target entity for preview mode.
* Called by AbilityPreviewExecutor before starting preview.
*/
public void setPreviewTarget(EntityLivingBase target) {
this.previewTarget = target;
}
public EntityLivingBase getPreviewTarget() {
return previewTarget;
}
/**
* Called once when transitioning from WINDUP to ACTIVE in preview mode.
* Override in movement-based abilities to initiate movement.
*/
@SideOnly(Side.CLIENT)
public void onPreviewExecute(EntityNPCInterface npc) {
// Default: no-op. Override in movement abilities.
public int getMaxPreviewDuration() {
return 200;
}
// ═══════════════════════════════════════════════════════════════════
@@ -978,7 +1096,8 @@ public abstract class Ability implements IAbility {
nbt.setInteger("recovery", dazedTicks);
nbt.setBoolean("interruptible", interruptible);
nbt.setInteger("lockMovement", lockMovement.ordinal());
nbt.setInteger("lockType", lockType.ordinal());
nbt.setInteger("rotationMode", rotationMode.ordinal());
nbt.setInteger("rotationPhase", rotationPhase.ordinal());
nbt.setInteger("windUpColor", windUpColor);
nbt.setInteger("activeColor", activeColor);
nbt.setString("windUpSound", windUpSound);
@@ -994,6 +1113,13 @@ public abstract class Ability implements IAbility {
nbt.setInteger("allowedBy", allowedBy.ordinal());
nbt.setBoolean("ignoreCooldown", ignoreCooldown);
// Burst
nbt.setBoolean("burstEnabled", burstEnabled);
nbt.setInteger("burstAmount", burstAmount);
nbt.setInteger("burstDelay", burstDelay);
nbt.setBoolean("burstReplayAnimations", burstReplayAnimations);
nbt.setBoolean("burstOverlap", burstOverlap);
// Conditions
NBTTagList condList = new NBTTagList();
for (Condition c : conditions) condList.appendTag(c.writeNBT());
@@ -1029,7 +1155,30 @@ public abstract class Ability implements IAbility {
dazedTicks = nbt.getInteger("recovery");
interruptible = nbt.getBoolean("interruptible");
lockMovement = LockMovementType.fromOrdinal(nbt.getInteger("lockMovement"));
lockType = nbt.hasKey("lockType") ? LockType.fromOrdinal(nbt.getInteger("lockType")) : LockType.BOTH;
if (nbt.hasKey("rotationMode")) {
// Current format
rotationMode = RotationMode.fromOrdinal(nbt.getInteger("rotationMode"));
rotationPhase = LockMovementType.fromOrdinal(nbt.getInteger("rotationPhase"));
} else if (nbt.hasKey("lockType")) {
// Legacy format migration: lockType was LockType enum (0=MOVEMENT, 1=ROTATION, 2=BOTH)
int oldLockType = nbt.getInteger("lockType");
if (oldLockType == 0) {
// MOVEMENT only: movement locked, rotation was free
rotationMode = RotationMode.FREE;
} else if (oldLockType == 1) {
// ROTATION only: rotation locked same timing as old lockMovement, movement was free
rotationMode = RotationMode.LOCKED;
rotationPhase = lockMovement;
lockMovement = LockMovementType.NO;
} else {
// BOTH: both locked same timing
rotationMode = RotationMode.LOCKED;
rotationPhase = lockMovement;
}
} else {
rotationMode = RotationMode.FREE;
rotationPhase = LockMovementType.WINDUP_AND_ACTIVE;
}
windUpColor = nbt.getInteger("windUpColor");
activeColor = nbt.getInteger("activeColor");
windUpSound = nbt.getString("windUpSound");
@@ -1051,6 +1200,13 @@ public abstract class Ability implements IAbility {
allowedBy = nbt.hasKey("allowedBy") ? UserType.fromOrdinal(nbt.getInteger("allowedBy")) : UserType.BOTH;
ignoreCooldown = nbt.hasKey("ignoreCooldown") && nbt.getBoolean("ignoreCooldown");
// Burst
burstEnabled = nbt.hasKey("burstEnabled") && nbt.getBoolean("burstEnabled");
burstAmount = nbt.hasKey("burstAmount") ? nbt.getInteger("burstAmount") : 0;
burstDelay = nbt.hasKey("burstDelay") ? nbt.getInteger("burstDelay") : 0;
burstReplayAnimations = !nbt.hasKey("burstReplayAnimations") || nbt.getBoolean("burstReplayAnimations");
burstOverlap = nbt.hasKey("burstOverlap") && nbt.getBoolean("burstOverlap");
// Conditions
conditions.clear();
NBTTagList condList = nbt.getTagList("conditions", 10);
@@ -1194,12 +1350,20 @@ public abstract class Ability implements IAbility {
this.lockMovement = lockMovement;
}
public LockType getLockType() {
return lockType;
public RotationMode getRotationMode() {
return rotationMode;
}
public void setLockType(LockType lockType) {
this.lockType = lockType;
public void setRotationMode(RotationMode rotationMode) {
this.rotationMode = rotationMode;
}
public LockMovementType getRotationPhase() {
return rotationPhase;
}
public void setRotationPhase(LockMovementType rotationPhase) {
this.rotationPhase = rotationPhase;
}
/**
@@ -1221,21 +1385,39 @@ public abstract class Ability implements IAbility {
}
/**
* API method: Get lock type as integer.
* @return 0=MOVEMENT, 1=ROTATION, 2=BOTH
* API method: Get rotation mode as integer.
* @return 0=FREE, 1=LOCKED, 2=TRACK
*/
@Override
public int getLockTypeOrdinal() {
return lockType.ordinal();
public int getRotationModeType() {
return rotationMode.ordinal();
}
/**
* API method: Set lock type from integer.
* @param type 0=MOVEMENT, 1=ROTATION, 2=BOTH
* API method: Set rotation mode from integer.
* @param type 0=FREE, 1=LOCKED, 2=TRACK
*/
@Override
public void setLockTypeOrdinal(int type) {
this.lockType = LockType.fromOrdinal(type);
public void setRotationModeType(int type) {
this.rotationMode = RotationMode.fromOrdinal(type);
}
/**
* API method: Get rotation phase as integer.
* @return 0=NO, 1=WINDUP, 2=ACTIVE, 3=WINDUP_AND_ACTIVE
*/
@Override
public int getRotationPhaseType() {
return rotationPhase.ordinal();
}
/**
* API method: Set rotation phase from integer.
* @param type 0=NO, 1=WINDUP, 2=ACTIVE, 3=WINDUP_AND_ACTIVE
*/
@Override
public void setRotationPhaseType(int type) {
this.rotationPhase = LockMovementType.fromOrdinal(type);
}
/**
@@ -1243,7 +1425,7 @@ public abstract class Ability implements IAbility {
*/
@Override
public boolean isMovementLockedDuringWindup() {
return lockMovement.locksWindup() && lockType.locksMovement();
return lockMovement.locksWindup();
}
/**
@@ -1251,7 +1433,7 @@ public abstract class Ability implements IAbility {
*/
@Override
public boolean isMovementLockedDuringActive() {
return lockMovement.locksActive() && lockType.locksMovement();
return lockMovement.locksActive();
}
/**
@@ -1259,7 +1441,7 @@ public abstract class Ability implements IAbility {
*/
@Override
public boolean isRotationLockedDuringWindup() {
return lockMovement.locksWindup() && lockType.locksRotation();
return rotationMode == RotationMode.LOCKED && rotationPhase.locksWindup();
}
/**
@@ -1267,7 +1449,7 @@ public abstract class Ability implements IAbility {
*/
@Override
public boolean isRotationLockedDuringActive() {
return lockMovement.locksActive() && lockType.locksRotation();
return rotationMode == RotationMode.LOCKED && rotationPhase.locksActive();
}
/**
@@ -1279,6 +1461,8 @@ public abstract class Ability implements IAbility {
return isMovementLockedDuringWindup();
case ACTIVE:
return isMovementLockedDuringActive();
case BURST_DELAY:
return false; // Free movement during burst delay
default:
return false;
}
@@ -1293,6 +1477,25 @@ public abstract class Ability implements IAbility {
return isRotationLockedDuringWindup();
case ACTIVE:
return isRotationLockedDuringActive();
case BURST_DELAY:
return false; // Free rotation during burst delay
default:
return false;
}
}
/**
* Check if hit scan (force face target) is active during the current phase.
*/
public boolean isHitScanForCurrentPhase() {
if (rotationMode != RotationMode.TRACK) return false;
switch (phase) {
case WINDUP:
return rotationPhase.locksWindup();
case ACTIVE:
return rotationPhase.locksActive();
case BURST_DELAY:
return false; // Free rotation during burst delay
default:
return false;
}
@@ -1481,6 +1684,63 @@ public abstract class Ability implements IAbility {
effects.clear();
}
// Burst getters/setters
public boolean isBurstEnabled() {
return burstEnabled;
}
public void setBurstEnabled(boolean burstEnabled) {
this.burstEnabled = burstEnabled;
}
public int getBurstAmount() {
return burstAmount;
}
public void setBurstAmount(int burstAmount) {
this.burstAmount = Math.max(0, burstAmount);
}
public int getBurstDelay() {
return burstDelay;
}
public void setBurstDelay(int burstDelay) {
this.burstDelay = Math.max(0, burstDelay);
}
public boolean isBurstReplayAnimations() {
return burstReplayAnimations;
}
public void setBurstReplayAnimations(boolean burstReplayAnimations) {
this.burstReplayAnimations = burstReplayAnimations;
}
public boolean isBurstOverlap() {
return burstOverlap;
}
public void setBurstOverlap(boolean burstOverlap) {
this.burstOverlap = burstOverlap;
}
public int getBurstIndex() {
return burstIndex;
}
/**
* Get display keys for rotation phase dropdown (excludes "None" since mode=FREE handles that).
*/
private static String[] getRotationPhaseKeys() {
return new String[]{
"ability.lockMove.windup",
"ability.lockMove.active",
"ability.lockMove.both"
};
}
// ═══════════════════════════════════════════════════════════════════
// SHIT FROM THE ASS
// ═══════════════════════════════════════════════════════════════════
@@ -45,6 +45,9 @@ public class AbilityController implements IAbilityHandler {
/** External field providers for ability GUI (e.g., DBC Addon). Client-side only. */
private final List<IAbilityFieldProvider> fieldProviders = new ArrayList<>();
/** External variant definitions registered by addons, keyed by typeId. */
private final Map<String, List<AbilityVariant>> externalVariants = new LinkedHashMap<>();
public AbilityController() {
registerBuiltinTypes();
}
@@ -180,30 +183,93 @@ public class AbilityController implements IAbilityHandler {
// ═══════════════════════════════════════════════════════════════════════════
/**
* Resolve an ability by key. Checks built-in abilities first (by name),
* then custom abilities (by UUID). Returns a copy safe to modify.
* Resolve an ability by key. Checks built-in abilities first (by name or registry key),
* then custom abilities (by UUID or name). Returns a copy safe to modify for
* custom abilities, or the singleton instance for built-in abilities.
*
* @param key The ability name (built-in) or UUID (custom)
* @return A copy of the resolved ability, or null if not found
* @param key The ability name, registry key (built-in) or UUID (custom)
* @return The resolved ability, or null if not found
*/
public Ability resolveAbility(String key) {
if (key == null || key.isEmpty()) return null;
// Check built-in abilities first
// Check built-in abilities first (exact match by name)
Ability builtIn = abilities.get(key);
if (builtIn != null) {
return fromNBT(builtIn.writeNBT());
return builtIn;
}
// Check custom abilities
// Check built-in abilities by name (case-insensitive)
for (Map.Entry<String, Ability> entry : abilities.entrySet()) {
if (entry.getKey().equalsIgnoreCase(key)) {
return entry.getValue();
}
}
// Check built-in abilities by registry key / ID
for (Ability ability : abilities.values()) {
if (ability.getId() != null && ability.getId().equalsIgnoreCase(key)) {
return ability;
}
}
// Check custom abilities (exact UUID match)
Ability custom = customAbilities.get(key);
if (custom != null) {
return fromNBT(custom.writeNBT());
}
// Check custom abilities by name (case-insensitive)
for (Ability ability : customAbilities.values()) {
if (ability.getName() != null && ability.getName().equalsIgnoreCase(key)) {
return fromNBT(ability.writeNBT());
}
}
return null;
}
/**
* Get all keys that can be used to look up abilities (for tab completion).
* Returns registry keys for built-in abilities (no spaces) and UUIDs for custom.
*/
public Set<String> getAbilityKeys() {
Set<String> keys = new LinkedHashSet<>();
// Built-in abilities - use the ID (registry key for BuiltInAbility)
for (Ability ability : abilities.values()) {
String id = ability.getId();
if (id != null && !id.isEmpty()) {
keys.add(id);
}
}
// Custom abilities - use UUID
keys.addAll(customAbilities.keySet());
return keys;
}
/**
* Get keys for player-usable abilities only (for tab completion).
*/
public Set<String> getPlayerAbilityKeys() {
Set<String> keys = new LinkedHashSet<>();
// Built-in abilities - use the ID (registry key for BuiltInAbility)
for (Ability ability : abilities.values()) {
if (ability.getAllowedBy().allowsPlayer()) {
String id = ability.getId();
if (id != null && !id.isEmpty()) {
keys.add(id);
}
}
}
// Custom abilities - use UUID (if player-usable)
for (Map.Entry<String, Ability> entry : customAbilities.entrySet()) {
if (entry.getValue().getAllowedBy().allowsPlayer()) {
keys.add(entry.getKey());
}
}
return keys;
}
/**
* Check if an ability key exists (either built-in or custom).
*/
@@ -369,13 +435,9 @@ public class AbilityController implements IAbilityHandler {
registerType("cnpc:sweeper", AbilitySweeper::new);
registerType("cnpc:projectile", AbilityProjectile::new);
registerType("cnpc:orb", AbilityOrb::new);
registerType("cnpc:dual_orb", AbilityOrbDual::new);
registerType("cnpc:orb_barrage", AbilityOrbBarrage::new);
registerType("cnpc:dual_disc", AbilityDisc::new);
registerType("cnpc:dual_disc", AbilityDiscDual::new);
registerType("cnpc:disc", AbilityDisc::new);
registerType("cnpc:laser_shot", AbilityLaserShot::new);
registerType("cnpc:beam", AbilityBeam::new);
registerType("cnpc:dual_beam", AbilityBeamDual::new);
// Movement abilities
registerType("cnpc:charge", AbilityCharge::new);
@@ -427,4 +489,41 @@ public class AbilityController implements IAbilityHandler {
public List<IAbilityFieldProvider> getFieldProviders() {
return fieldProviders;
}
// ═══════════════════════════════════════════════════════════════════════════
// EXTERNAL VARIANT REGISTRY
// ═══════════════════════════════════════════════════════════════════════════
/**
* Register an external variant for an ability type.
* External mods can call this to add variant presets that appear
* alongside built-in variants in the variant selection SubGui.
*
* @param typeId The ability typeId (e.g., "ability.cnpc.beam")
* @param variant The variant to register
*/
public void registerVariant(String typeId, AbilityVariant variant) {
externalVariants.computeIfAbsent(typeId, k -> new ArrayList<>()).add(variant);
}
/**
* Get all variants for a given ability type (built-in + external).
* Returns the combined list of variants from the ability's getVariants()
* and any externally registered variants.
*
* @param typeId The ability typeId
* @return Combined list of variants, empty if none
*/
public List<AbilityVariant> getVariantsForType(String typeId) {
List<AbilityVariant> result = new ArrayList<>();
Ability temp = create(typeId);
if (temp != null) {
result.addAll(temp.getVariants());
}
List<AbilityVariant> ext = externalVariants.get(typeId);
if (ext != null) {
result.addAll(ext);
}
return result;
}
}
@@ -4,5 +4,6 @@ public enum AbilityPhase {
IDLE, // Not executing
WINDUP, // Charging up (telegraph visible)
ACTIVE, // Executing (damage happens)
DAZED // Stunned after interrupt during WINDUP (cannot attack)
DAZED, // Stunned after interrupt during WINDUP (cannot attack)
BURST_DELAY // Waiting between burst repetitions (free movement/rotation)
}
@@ -0,0 +1,54 @@
package kamkeel.npcs.controllers.data.ability;
import java.util.function.Consumer;
/**
* Represents a variant/template for an ability type.
* When a user creates an ability that has registered variants,
* they are presented with a selection dialog before the ability is created.
*
* Each variant has a display name (lang key) and a configurator that
* applies preset values to the newly created ability.
*/
public class AbilityVariant {
private final String displayKey;
private final String group;
private final Consumer<Ability> configurator;
/**
* @param displayKey Lang key for the variant display name (e.g., "ability.variant.dual")
* @param configurator Lambda that configures the ability with preset values
*/
public AbilityVariant(String displayKey, Consumer<Ability> configurator) {
this(displayKey, null, configurator);
}
/**
* @param displayKey Lang key for the variant display name
* @param group Optional group header shown in the variant selection GUI (e.g., "DBC Addon")
* @param configurator Lambda that configures the ability with preset values
*/
public AbilityVariant(String displayKey, String group, Consumer<Ability> configurator) {
this.displayKey = displayKey;
this.group = group;
this.configurator = configurator;
}
public String getDisplayKey() {
return displayKey;
}
public String getGroup() {
return group;
}
/**
* Apply this variant's preset configuration to the given ability.
*/
public void apply(Ability ability) {
if (configurator != null) {
configurator.accept(ability);
}
}
}
@@ -0,0 +1,13 @@
package kamkeel.npcs.controllers.data.ability;
import net.minecraft.entity.Entity;
/**
* Interface for routing entity spawn/kill calls during preview mode.
* In preview mode, entities are not added to the world but instead
* tracked by the GUI for rendering in the 3D viewport.
*/
public interface PreviewEntityHandler {
void onEntitySpawned(Entity entity);
void onEntityRemoved(Entity entity);
}
@@ -0,0 +1,53 @@
package kamkeel.npcs.controllers.data.ability;
/**
* Defines what happens to NPC rotation during ability phases.
* Used with a LockMovementType to control WHEN it applies.
*/
public enum RotationMode {
/**
* NPC rotates normally via AI look helper.
*/
FREE,
/**
* Freeze rotation at the moment the phase starts.
* NPC stays facing the direction it was looking when the phase began.
*/
LOCKED,
/**
* Force NPC to continuously face its target (hit scan).
* Overrides AI look helper every tick for precise aiming.
*/
TRACK;
public String getDisplayKey() {
switch (this) {
case FREE:
return "ability.rotation.free";
case LOCKED:
return "ability.rotation.locked";
case TRACK:
return "ability.rotation.track";
default:
return "ability.rotation.free";
}
}
public static String[] getDisplayKeys() {
return new String[]{
"ability.rotation.free",
"ability.rotation.locked",
"ability.rotation.track"
};
}
public static RotationMode fromOrdinal(int ordinal) {
RotationMode[] values = values();
if (ordinal >= 0 && ordinal < values.length) {
return values[ordinal];
}
return FREE;
}
}
@@ -0,0 +1,60 @@
package kamkeel.npcs.controllers.data.ability.data;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import net.minecraft.nbt.NBTTagCompound;
/**
* Per-projectile data: anchor point + optional color override.
* All projectiles share the primary EnergyDisplayData; this class
* allows individual projectiles to override just the inner/outer colors.
*/
public class ProjectileData {
public EnergyAnchorData anchor;
public boolean colorOverride = false;
public int innerColor = 0xFFFFFF;
public int outerColor = 0x8888FF;
public ProjectileData(AnchorPoint defaultAnchor) {
this.anchor = new EnergyAnchorData(defaultAnchor);
}
/**
* Returns the display data to use for this projectile.
* If colorOverride is false, returns the primary display data directly.
* If colorOverride is true, returns a copy with overridden inner/outer colors.
*/
public EnergyDisplayData resolveDisplay(EnergyDisplayData primary) {
if (!colorOverride) return primary;
EnergyDisplayData resolved = primary.copy();
resolved.innerColor = this.innerColor;
resolved.outerColor = this.outerColor;
return resolved;
}
public void writeNBT(NBTTagCompound nbt) {
anchor.writeNBT(nbt);
nbt.setBoolean("colorOverride", colorOverride);
if (colorOverride) {
nbt.setInteger("overrideInnerColor", innerColor);
nbt.setInteger("overrideOuterColor", outerColor);
}
}
public void readNBT(NBTTagCompound nbt) {
anchor.readNBT(nbt);
colorOverride = nbt.getBoolean("colorOverride");
if (colorOverride) {
innerColor = nbt.hasKey("overrideInnerColor") ? nbt.getInteger("overrideInnerColor") : 0xFFFFFF;
outerColor = nbt.hasKey("overrideOuterColor") ? nbt.getInteger("overrideOuterColor") : 0x8888FF;
}
}
public ProjectileData copy() {
ProjectileData copy = new ProjectileData(anchor.anchorPoint);
copy.anchor = anchor.copy();
copy.colorOverride = colorOverride;
copy.innerColor = innerColor;
copy.outerColor = outerColor;
return copy;
}
}
@@ -23,4 +23,5 @@ public class AbilityFieldDefs {
() -> getter.get(),
v -> setter.accept((List<AbilityEffect>) v));
}
}
@@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.RotationMode;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.data.*;
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
@@ -12,7 +13,6 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityBeam;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
@@ -23,30 +23,39 @@ import noppes.npcs.api.ability.type.IAbilityEnergyBeam;
import java.util.Arrays;
import java.util.List;
import noppes.npcs.entity.EntityNPCInterface;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
/**
* Energy Beam ability: A homing head with a trailing path.
* The beam stays attached to the origin and curves as it homes in on target.
* Cannot cross over itself (self-intersection prevention).
* Supports 1-8 projectiles with shared visuals and per-projectile anchor points.
*/
public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
// Shape properties (standalone)
private static final int MAX_PROJECTILES = 8;
// Beam shape properties (shared)
private float beamWidth = 0.4f;
private float headSize = 0.6f;
// Data classes
private final EnergyDisplayData colorData = new EnergyDisplayData(0xFFFFFF, 0x00AAFF, true, 0.4f, 0.5f, 6.0f);
// Projectile count and fire stagger
private int projectileCount = 1;
private int fireDelay = 0;
// Shared visual data (all projectiles use these)
private EnergyDisplayData displayData = new EnergyDisplayData(0xFFFFFF, 0x00AAFF, true, 0.4f, 0.5f, 6.0f);
private EnergyLightningData lightningData = new EnergyLightningData();
private EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Shared combat/movement data
private final EnergyCombatData combatData = new EnergyCombatData(10.0f, 1.5f, 0.2f, false, 4.0f, 0.5f);
private final EnergyHomingData homingData = new EnergyHomingData(0.4f, true, 0.1f, 15.0f);
private final EnergyLightningData lightningData = new EnergyLightningData();
private final EnergyLifespanData lifespanData = new EnergyLifespanData(25.0f, 200);
private final EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.RIGHT_HAND);
private final EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Transient state for beam entity (used during windup charging)
private transient EntityAbilityBeam beamEntity = null;
// Per-projectile data (anchor + optional color override)
private ProjectileData[] projectiles;
// Transient entity state
private transient EntityAbilityBeam[] beamEntities;
public AbilityBeam() {
this.typeId = "ability.cnpc.beam";
@@ -57,11 +66,92 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
this.cooldownTicks = 0;
this.windUpTicks = 40;
this.lockMovement = LockMovementType.WINDUP_AND_ACTIVE;
this.rotationMode = RotationMode.TRACK;
this.rotationPhase = LockMovementType.WINDUP_AND_ACTIVE;
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
// Default built-in animations
this.windUpAnimationName = "Ability_Beam_Windup";
this.activeAnimationName = "Ability_Beam_Active";
initProjectiles(1);
}
private void initProjectiles(int count) {
this.projectileCount = Math.max(1, Math.min(count, MAX_PROJECTILES));
this.projectiles = new ProjectileData[projectileCount];
for (int i = 0; i < projectileCount; i++) {
projectiles[i] = new ProjectileData(getDefaultAnchor(i));
}
}
private AnchorPoint getDefaultAnchor(int index) {
switch (index) {
case 0: return AnchorPoint.RIGHT_HAND;
case 1: return AnchorPoint.LEFT_HAND;
default: return AnchorPoint.FRONT;
}
}
public void setProjectileCount(int count) {
int newCount = Math.max(1, Math.min(count, MAX_PROJECTILES));
if (newCount == projectileCount) return;
ProjectileData[] oldProjectiles = projectiles;
initProjectiles(newCount);
if (oldProjectiles != null) {
int copyCount = Math.min(oldProjectiles.length, newCount);
for (int i = 0; i < copyCount; i++) {
if (oldProjectiles[i] != null) projectiles[i] = oldProjectiles[i];
}
}
}
public int getProjectileCount() {
return projectileCount;
}
public int getFireDelay() {
return fireDelay;
}
public void setFireDelay(int delay) {
this.fireDelay = Math.max(0, delay);
}
// Legacy compat
public int getDualFireDelay() { return fireDelay; }
public void setDualFireDelay(int delay) { setFireDelay(delay); }
@Override
public List<AbilityVariant> getVariants() {
return Arrays.asList(
new AbilityVariant("ability.variant.single", a -> {
a.setName("Beam");
}),
new AbilityVariant("ability.variant.dual", a -> {
AbilityBeam beam = (AbilityBeam) a;
a.setName("Dual Beam");
beam.setProjectileCount(2);
beam.setFireDelay(0);
// Set color override for second beam
beam.projectiles[1].colorOverride = true;
beam.projectiles[1].innerColor = 0xFFFFFF;
beam.projectiles[1].outerColor = 0xFF0000;
a.setWindUpTicks(80);
a.setWindUpAnimationName("Ability_BeamDual_Windup");
a.setActiveAnimationName("Ability_BeamDual_Active");
})
);
}
@Override
public boolean allowOverlap() {
return true;
}
@Override
public boolean isReadyForBurstCompletion(int activeTick) {
return fireDelay <= 0 || activeTick >= fireDelay * (projectileCount - 1);
}
@Override
@@ -74,51 +164,113 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
signalCompletion();
return;
/**
* Create beam entities.
* NPC: target is the aggro target — beams will home toward it.
* Player: target is null — beams fire in caster's look direction.
*/
private EntityAbilityBeam[] createBeamEntities(EntityLivingBase caster, EntityLivingBase target, World world) {
EntityAbilityBeam[] entities = new EntityAbilityBeam[projectileCount];
float offsetDist = 1.0f;
for (int i = 0; i < projectileCount; i++) {
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, projectiles[i].anchor, offsetDist);
EnergyDisplayData resolved = projectiles[i].resolveDisplay(displayData);
entities[i] = new EntityAbilityBeam(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord,
beamWidth, headSize,
resolved, combatData, homingData, lightningData, lifespanData, trajectoryData,
lockMovement.locksActive());
entities[i].setEffects(this.effects);
entities[i].setSourceAbility(this);
}
// Start firing the beam that was spawned during windup
if (beamEntity != null && !beamEntity.isDead) {
beamEntity.startFiring(target);
if (projectileCount == 2 && entities[0] != null && entities[1] != null) {
entities[0].setSiblingEntityId(entities[1].getEntityId());
entities[1].setSiblingEntityId(entities[0].getEntityId());
}
return entities;
}
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
private void fireBeamEntity(EntityAbilityBeam beam, EntityLivingBase target) {
if (beam == null || beam.isDead) return;
if (isPreview()) {
beam.startPreviewFiring();
} else {
beam.startFiring(target);
}
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
// Spawn beam in charging mode on first tick of windup
if (tick == 1) {
beamEntities = createBeamEntities(caster, target, world);
float offsetDist = 1.0f;
for (int i = 0; i < projectileCount; i++) {
EnergyDisplayData resolved = projectiles[i].resolveDisplay(displayData);
if (isPreview()) {
beamEntities[i].setupPreview(caster, beamWidth, headSize, resolved, lightningData, projectiles[i].anchor, windUpTicks, offsetDist);
} else {
beamEntities[i].setupCharging(projectiles[i].anchor, windUpTicks, offsetDist);
}
spawnAbilityEntity(world, beamEntities[i]);
}
}
}
// Create beam in charging mode - follows caster based on anchor point during windup
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchorData, offsetDist);
beamEntity = new EntityAbilityBeam(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord,
beamWidth, headSize,
colorData, combatData, homingData, lightningData, lifespanData, trajectoryData,
lockMovement.locksActive());
beamEntity.setupCharging(anchorData, windUpTicks, offsetDist);
@Override
public void onBurstRefire(EntityLivingBase caster, EntityLivingBase target, World world) {
beamEntities = createBeamEntities(caster, target, world);
for (EntityAbilityBeam beam : beamEntities) {
spawnAbilityEntity(world, beam);
}
for (EntityAbilityBeam beam : beamEntities) {
fireBeamEntity(beam, target);
}
}
beamEntity.setEffects(this.effects);
beamEntity.setSourceAbility(this);
world.spawnEntityInWorld(beamEntity);
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote && !isPreview()) {
signalCompletion();
return;
}
if (beamEntities == null) return;
fireBeamEntity(beamEntities[0], target);
if (fireDelay <= 0) {
for (int i = 1; i < projectileCount; i++) {
fireBeamEntity(beamEntities[i], target);
}
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Signal completion when entity dies
if (beamEntity == null || beamEntity.isDead) {
beamEntity = null;
if (beamEntities == null) {
signalCompletion();
return;
}
if (fireDelay > 0) {
for (int i = 1; i < projectileCount; i++) {
if (tick == fireDelay * i) {
fireBeamEntity(beamEntities[i], target);
}
}
}
boolean allDead = true;
for (EntityAbilityBeam beam : beamEntities) {
if (beam != null && !beam.isDead) {
allDead = false;
break;
}
}
if (allDead) {
signalCompletion();
}
}
@@ -134,20 +286,25 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
@Override
public void cleanup() {
// Despawn beam entity if still alive
if (beamEntity != null && !beamEntity.isDead) {
beamEntity.setDead();
if (beamEntities != null) {
for (int i = 0; i < beamEntities.length; i++) {
if (beamEntities[i] != null && !beamEntities[i].isDead) {
beamEntities[i].setDead();
}
beamEntities[i] = null;
}
}
beamEntity = null;
beamEntities = null;
}
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
// NPC: telegraph on aggro target position
// Player: no telegraph (beam fires in look direction, no fixed position to mark)
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster) || target == null) {
return null;
}
// Create circle telegraph at target position
Telegraph telegraph = Telegraph.circle(headSize * 2.0f);
telegraph.setDurationTicks(windUpTicks);
telegraph.setColor(windUpColor);
@@ -155,7 +312,6 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
telegraph.setHeightOffset(telegraphHeightOffset);
// Position at target and follow target during windup
TelegraphInstance instance = new TelegraphInstance(telegraph, target.posX, target.posY, target.posZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
instance.setEntityIdToFollow(target.getEntityId());
@@ -172,176 +328,310 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("beamWidth", beamWidth);
nbt.setFloat("headSize", headSize);
anchorData.writeNBT(nbt);
colorData.writeNBT(nbt);
nbt.setInteger("projectileCount", projectileCount);
nbt.setInteger("fireDelay", fireDelay);
// Shared visual data
displayData.writeNBT(nbt);
lightningData.writeNBT(nbt);
// Shared combat/movement data
combatData.writeNBT(nbt);
homingData.writeNBT(nbt);
lightningData.writeNBT(nbt);
lifespanData.writeNBT(nbt);
// Per-projectile data
for (int i = 0; i < projectileCount; i++) {
NBTTagCompound projNbt = new NBTTagCompound();
projectiles[i].writeNBT(projNbt);
nbt.setTag("Projectile_" + i, projNbt);
}
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
this.beamWidth = nbt.hasKey("beamWidth") ? nbt.getFloat("beamWidth") : 0.4f;
this.headSize = nbt.hasKey("headSize") ? nbt.getFloat("headSize") : 0.6f;
anchorData.readNBT(nbt);
colorData.readNBT(nbt);
int count = nbt.hasKey("projectileCount") ? nbt.getInteger("projectileCount") : 1;
initProjectiles(count);
if (nbt.hasKey("fireDelay")) {
this.fireDelay = nbt.getInteger("fireDelay");
} else if (nbt.hasKey("dualFireDelay")) {
this.fireDelay = nbt.getInteger("dualFireDelay");
} else {
this.fireDelay = 0;
}
combatData.readNBT(nbt);
homingData.readNBT(nbt);
lightningData.readNBT(nbt);
lifespanData.readNBT(nbt);
if (nbt.hasKey("Projectile_0")) {
NBTTagCompound proj0 = nbt.getCompoundTag("Projectile_0");
if (proj0.hasKey("colorOverride")) {
// NEW format
displayData.readNBT(nbt);
lightningData.readNBT(nbt);
for (int i = 0; i < projectileCount; i++) {
if (nbt.hasKey("Projectile_" + i)) {
projectiles[i].readNBT(nbt.getCompoundTag("Projectile_" + i));
}
}
} else {
// OLD per-projectile format
displayData.readNBT(proj0);
lightningData.readNBT(proj0);
projectiles[0].anchor.readNBT(proj0);
for (int i = 1; i < projectileCount; i++) {
if (nbt.hasKey("Projectile_" + i)) {
NBTTagCompound projNbt = nbt.getCompoundTag("Projectile_" + i);
projectiles[i].anchor.readNBT(projNbt);
EnergyDisplayData tempDisplay = new EnergyDisplayData();
tempDisplay.readNBT(projNbt);
if (tempDisplay.innerColor != displayData.innerColor || tempDisplay.outerColor != displayData.outerColor) {
projectiles[i].colorOverride = true;
projectiles[i].innerColor = tempDisplay.innerColor;
projectiles[i].outerColor = tempDisplay.outerColor;
}
}
}
}
} else {
// LEGACY flat format
displayData.readNBT(nbt);
lightningData.readNBT(nbt);
projectiles[0].anchor.readNBT(nbt);
}
}
// Getters & Setters - Standalone fields
// ═══════════════════════════════════════════════════════════════════
// API GETTERS & SETTERS
// ═══════════════════════════════════════════════════════════════════
public float getBeamWidth() { return beamWidth; }
public void setBeamWidth(float beamWidth) { this.beamWidth = beamWidth; }
public float getHeadSize() { return headSize; }
public void setHeadSize(float headSize) { this.headSize = headSize; }
// Getters & Setters - Color data
public int getInnerColor() { return colorData.innerColor; }
public void setInnerColor(int innerColor) { this.colorData.innerColor = innerColor; }
public int getOuterColor() { return colorData.outerColor; }
public void setOuterColor(int outerColor) { this.colorData.outerColor = outerColor; }
public boolean isOuterColorEnabled() { return colorData.outerColorEnabled; }
public void setOuterColorEnabled(boolean outerColorEnabled) { this.colorData.outerColorEnabled = outerColorEnabled; }
public float getOuterColorWidth() { return colorData.outerColorWidth; }
public void setOuterColorWidth(float outerColorWidth) { this.colorData.outerColorWidth = outerColorWidth; }
public float getOuterColorAlpha() { return colorData.outerColorAlpha; }
public void setOuterColorAlpha(float outerColorAlpha) { this.colorData.outerColorAlpha = outerColorAlpha; }
public float getRotationSpeed() { return colorData.rotationSpeed; }
public void setRotationSpeed(float rotationSpeed) { this.colorData.rotationSpeed = rotationSpeed; }
// Getters & Setters - Combat data
public float getDamage() { return combatData.damage; }
public void setDamage(float damage) { this.combatData.damage = damage; }
public float getKnockback() { return combatData.knockback; }
public void setKnockback(float knockback) { this.combatData.knockback = knockback; }
public float getKnockbackUp() { return combatData.knockbackUp; }
public void setKnockbackUp(float knockbackUp) { this.combatData.knockbackUp = knockbackUp; }
public boolean isExplosive() { return combatData.explosive; }
public void setExplosive(boolean explosive) { this.combatData.explosive = explosive; }
public float getExplosionRadius() { return combatData.explosionRadius; }
public void setExplosionRadius(float explosionRadius) { this.combatData.explosionRadius = explosionRadius; }
public float getExplosionDamageFalloff() { return combatData.explosionDamageFalloff; }
public void setExplosionDamageFalloff(float explosionDamageFalloff) { this.combatData.explosionDamageFalloff = explosionDamageFalloff; }
// Getters & Setters - Homing data
public float getSpeed() { return homingData.speed; }
public void setSpeed(float speed) { this.homingData.speed = speed; }
public boolean isHoming() { return homingData.homing; }
public void setHoming(boolean homing) { this.homingData.homing = homing; }
public float getHomingStrength() { return homingData.homingStrength; }
public void setHomingStrength(float homingStrength) { this.homingData.homingStrength = homingStrength; }
public float getHomingRange() { return homingData.homingRange; }
public void setHomingRange(float homingRange) { this.homingData.homingRange = homingRange; }
// Getters & Setters - Lightning data
public boolean hasLightningEffect() { return lightningData.lightningEffect; }
public void setLightningEffect(boolean lightningEffect) { this.lightningData.lightningEffect = lightningEffect; }
public float getLightningDensity() { return lightningData.lightningDensity; }
public void setLightningDensity(float lightningDensity) { this.lightningData.lightningDensity = lightningDensity; }
public float getLightningRadius() { return lightningData.lightningRadius; }
public void setLightningRadius(float lightningRadius) { this.lightningData.lightningRadius = lightningRadius; }
// Getters & Setters - Lifespan data
public float getMaxDistance() { return lifespanData.maxDistance; }
public void setMaxDistance(float maxDistance) { this.lifespanData.maxDistance = maxDistance; }
public int getMaxLifetime() { return lifespanData.maxLifetime; }
public void setMaxLifetime(int maxLifetime) { this.lifespanData.maxLifetime = maxLifetime; }
// Getters & Setters - Anchor point
public AnchorPoint getAnchorPointEnum() { return anchorData.anchorPoint; }
public float getAnchorOffsetX() { return anchorData.anchorOffsetX; }
public float getAnchorOffsetY() { return anchorData.anchorOffsetY; }
public float getAnchorOffsetZ() { return anchorData.anchorOffsetZ; }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { this.anchorData.anchorPoint = anchorPoint; }
public void setAnchorOffsetX(float x) { this.anchorData.anchorOffsetX = x; }
public void setAnchorOffsetY(float y) { this.anchorData.anchorOffsetY = y; }
public void setAnchorOffsetZ(float z) { this.anchorData.anchorOffsetZ = z; }
public float getDamage() { return combatData.damage; }
public void setDamage(float damage) { this.combatData.damage = damage; }
public float getKnockback() { return combatData.knockback; }
public void setKnockback(float knockback) { this.combatData.knockback = knockback; }
public float getKnockbackUp() { return combatData.knockbackUp; }
public void setKnockbackUp(float knockbackUp) { this.combatData.knockbackUp = knockbackUp; }
public boolean isHoming() { return homingData.homing; }
public void setHoming(boolean homing) { this.homingData.homing = homing; }
public float getHomingStrength() { return homingData.homingStrength; }
public void setHomingStrength(float homingStrength) { this.homingData.homingStrength = homingStrength; }
public float getHomingRange() { return homingData.homingRange; }
public void setHomingRange(float homingRange) { this.homingData.homingRange = homingRange; }
public boolean isExplosive() { return combatData.explosive; }
public void setExplosive(boolean explosive) { this.combatData.explosive = explosive; }
public float getExplosionRadius() { return combatData.explosionRadius; }
public void setExplosionRadius(float explosionRadius) { this.combatData.explosionRadius = explosionRadius; }
public float getExplosionDamageFalloff() { return combatData.explosionDamageFalloff; }
public void setExplosionDamageFalloff(float explosionDamageFalloff) { this.combatData.explosionDamageFalloff = explosionDamageFalloff; }
// Shared display data (primary colors)
public int getInnerColor() { return displayData.innerColor; }
public void setInnerColor(int innerColor) { displayData.innerColor = innerColor; }
public int getOuterColor() { return displayData.outerColor; }
public void setOuterColor(int outerColor) { displayData.outerColor = outerColor; }
public boolean isOuterColorEnabled() { return displayData.outerColorEnabled; }
public void setOuterColorEnabled(boolean outerColorEnabled) { displayData.outerColorEnabled = outerColorEnabled; }
public float getOuterColorWidth() { return displayData.outerColorWidth; }
public void setOuterColorWidth(float outerColorWidth) { displayData.outerColorWidth = outerColorWidth; }
public float getOuterColorAlpha() { return displayData.outerColorAlpha; }
public void setOuterColorAlpha(float outerColorAlpha) { displayData.outerColorAlpha = outerColorAlpha; }
public float getRotationSpeed() { return displayData.rotationSpeed; }
public void setRotationSpeed(float rotationSpeed) { displayData.rotationSpeed = rotationSpeed; }
// Shared lightning data
public boolean hasLightningEffect() { return lightningData.lightningEffect; }
public void setLightningEffect(boolean lightningEffect) { lightningData.lightningEffect = lightningEffect; }
public float getLightningDensity() { return lightningData.lightningDensity; }
public void setLightningDensity(float lightningDensity) { lightningData.lightningDensity = lightningDensity; }
public float getLightningRadius() { return lightningData.lightningRadius; }
public void setLightningRadius(float lightningRadius) { lightningData.lightningRadius = lightningRadius; }
public int getLightningFadeTime() { return lightningData.lightningFadeTime; }
public void setLightningFadeTime(int lightningFadeTime) { lightningData.lightningFadeTime = lightningFadeTime; }
// Anchor - default to projectile 0
public AnchorPoint getAnchorPointEnum() { return projectiles[0].anchor.anchorPoint; }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { projectiles[0].anchor.anchorPoint = anchorPoint; }
public float getAnchorOffsetX() { return projectiles[0].anchor.anchorOffsetX; }
public void setAnchorOffsetX(float x) { projectiles[0].anchor.anchorOffsetX = x; }
public float getAnchorOffsetY() { return projectiles[0].anchor.anchorOffsetY; }
public void setAnchorOffsetY(float y) { projectiles[0].anchor.anchorOffsetY = y; }
public float getAnchorOffsetZ() { return projectiles[0].anchor.anchorOffsetZ; }
public void setAnchorOffsetZ(float z) { projectiles[0].anchor.anchorOffsetZ = z; }
@Override
public int getAnchorPoint() { return anchorData.anchorPoint.ordinal(); }
public int getAnchorPoint() { return projectiles[0].anchor.anchorPoint.ordinal(); }
@Override
public void setAnchorPoint(int point) { this.anchorData.anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorPoint(int point) { projectiles[0].anchor.anchorPoint = AnchorPoint.fromOrdinal(point); }
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
// Indexed API methods
public int getInnerColor(int index) {
ProjectileData p = projectiles[clampIndex(index)];
return p.colorOverride ? p.innerColor : displayData.innerColor;
}
public void setInnerColor(int index, int color) {
ProjectileData p = projectiles[clampIndex(index)];
p.colorOverride = true;
p.innerColor = color;
}
EntityAbilityBeam beam = new EntityAbilityBeam(npc.worldObj);
beam.setupPreview(npc, beamWidth, headSize, colorData, lightningData, anchorData, windUpTicks, 1.0f);
return beam;
public int getOuterColor(int index) {
ProjectileData p = projectiles[clampIndex(index)];
return p.colorOverride ? p.outerColor : displayData.outerColor;
}
public void setOuterColor(int index, int color) {
ProjectileData p = projectiles[clampIndex(index)];
p.colorOverride = true;
p.outerColor = color;
}
public int getAnchorPoint(int index) { return projectiles[clampIndex(index)].anchor.anchorPoint.ordinal(); }
public void setAnchorPoint(int index, int point) { projectiles[clampIndex(index)].anchor.anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorOffsetX(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetX = offset; }
public void setAnchorOffsetY(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetY = offset; }
public void setAnchorOffsetZ(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetZ = offset; }
private int clampIndex(int index) {
return Math.max(0, Math.min(index, projectileCount - 1));
}
@Override
public int getPreviewActiveDuration() {
public int getMaxPreviewDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 100) : 100;
}
// ═══════════════════════════════════════════════════════════════════
// GUI FIELD DEFINITIONS
// ═══════════════════════════════════════════════════════════════════
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Type tab
FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getSpeed, this::setSpeed)
),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback),
FieldDef.section("ability.section.beam"),
FieldDef.row(
FieldDef.floatField("ability.beamWidth", this::getBeamWidth, this::setBeamWidth),
FieldDef.floatField("ability.headSize", this::getHeadSize, this::setHeadSize)
),
FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
),
FieldDef.section("ability.section.homing"),
FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming)
.hover("ability.hover.homing"),
FieldDef.row(
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength)
.visibleWhen(this::isHoming),
FieldDef.floatField("gui.range", this::getHomingRange, this::setHomingRange)
.visibleWhen(this::isHoming)
),
FieldDef.section("ability.section.explosive"),
FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive)
.hover("ability.hover.explosive"),
FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius)
.visibleWhen(this::isExplosive),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects),
// Visual tab
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class, this::getAnchorPointEnum, this::setAnchorPointEnum)
.tab("ability.tab.visual"),
FieldDef.section("ability.section.colors").tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor)
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled)
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor", this::getOuterColor, this::setOuterColor)
.tab("ability.tab.visual").visibleWhen(this::isOuterColorEnabled),
FieldDef.row(
FieldDef.floatField("ability.outerWidth", this::getOuterColorWidth, this::setOuterColorWidth)
.visibleWhen(this::isOuterColorEnabled),
FieldDef.floatField("ability.outerAlpha", this::getOuterColorAlpha, this::setOuterColorAlpha)
.range(0, 1).visibleWhen(this::isOuterColorEnabled)
).tab("ability.tab.visual"),
FieldDef.section("ability.section.effects").tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed)
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning", this::hasLightningEffect, this::setLightningEffect)
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density", this::getLightningDensity, this::setLightningDensity)
.range(0.01f, 100f).visibleWhen(this::hasLightningEffect),
FieldDef.floatField("gui.radius", this::getLightningRadius, this::setLightningRadius)
.range(0.1f, 100f).visibleWhen(this::hasLightningEffect)
).tab("ability.tab.visual")
defs.add(FieldDef.row(
FieldDef.intField("ability.projectileCount", this::getProjectileCount, this::setProjectileCount).range(1, MAX_PROJECTILES),
FieldDef.intField("ability.fireDelay", this::getFireDelay, this::setFireDelay)
.range(0, 200).visibleWhen(() -> projectileCount > 1)
));
defs.add(FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getSpeed, this::setSpeed)
));
defs.add(FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback));
defs.add(FieldDef.section("ability.section.beam"));
defs.add(FieldDef.row(
FieldDef.floatField("ability.beamWidth", this::getBeamWidth, this::setBeamWidth),
FieldDef.floatField("ability.headSize", this::getHeadSize, this::setHeadSize)
));
defs.add(FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
));
defs.add(FieldDef.section("ability.section.homing"));
defs.add(FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming).hover("ability.hover.homing"));
defs.add(FieldDef.row(
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength).visibleWhen(this::isHoming),
FieldDef.floatField("gui.range", this::getHomingRange, this::setHomingRange).visibleWhen(this::isHoming)
));
defs.add(FieldDef.section("ability.section.explosive"));
defs.add(FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive).hover("ability.hover.explosive"));
defs.add(FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius).visibleWhen(this::isExplosive));
defs.add(AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects));
// Visual tab - shared primary colors
defs.add(FieldDef.section("ability.section.colors").tab("ability.tab.visual"));
defs.add(FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor)
.tab("ability.tab.visual"));
defs.add(FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled)
.tab("ability.tab.visual"));
defs.add(FieldDef.colorSubGui("ability.outerColor", this::getOuterColor, this::setOuterColor)
.tab("ability.tab.visual").visibleWhen(this::isOuterColorEnabled));
defs.add(FieldDef.row(
FieldDef.floatField("ability.outerWidth", this::getOuterColorWidth, this::setOuterColorWidth)
.visibleWhen(this::isOuterColorEnabled),
FieldDef.floatField("ability.outerAlpha", this::getOuterColorAlpha, this::setOuterColorAlpha)
.range(0, 1).visibleWhen(this::isOuterColorEnabled)
).tab("ability.tab.visual"));
// Visual tab - shared effects
defs.add(FieldDef.section("ability.section.effects").tab("ability.tab.visual"));
defs.add(FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed)
.tab("ability.tab.visual"));
defs.add(FieldDef.boolField("ability.lightning", this::hasLightningEffect, this::setLightningEffect)
.tab("ability.tab.visual"));
defs.add(FieldDef.row(
FieldDef.floatField("gui.density", this::getLightningDensity, this::setLightningDensity)
.visibleWhen(this::hasLightningEffect).range(0.01f, 100f),
FieldDef.floatField("gui.radius", this::getLightningRadius, this::setLightningRadius)
.range(0.1f, 100f).visibleWhen(this::hasLightningEffect)
).tab("ability.tab.visual"));
// Visual tab - per-projectile sections
for (int i = 0; i < MAX_PROJECTILES; i++) {
final int idx = i;
String sectionKey = "ability.section.projectile" + (i + 1);
defs.add(FieldDef.section(sectionKey).tab("ability.tab.visual")
.visibleWhen(() -> idx < projectileCount));
defs.add(FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> projectiles[idx].anchor.anchorPoint, v -> projectiles[idx].anchor.anchorPoint = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
defs.add(FieldDef.row(
FieldDef.floatField("ability.anchor.offsetX", () -> projectiles[idx].anchor.anchorOffsetX, v -> projectiles[idx].anchor.anchorOffsetX = v),
FieldDef.floatField("ability.anchor.offsetY", () -> projectiles[idx].anchor.anchorOffsetY, v -> projectiles[idx].anchor.anchorOffsetY = v)
).tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
defs.add(FieldDef.floatField("ability.anchor.offsetZ", () -> projectiles[idx].anchor.anchorOffsetZ, v -> projectiles[idx].anchor.anchorOffsetZ = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
// Color override (only when multiple projectiles)
defs.add(FieldDef.boolField("ability.colorOverride", () -> projectiles[idx].colorOverride, v -> projectiles[idx].colorOverride = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1));
defs.add(FieldDef.colorSubGui("ability.innerColor", () -> projectiles[idx].innerColor, v -> projectiles[idx].innerColor = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1 && projectiles[idx].colorOverride));
defs.add(FieldDef.colorSubGui("ability.outerColor", () -> projectiles[idx].outerColor, v -> projectiles[idx].outerColor = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1 && projectiles[idx].colorOverride));
}
}
}
@@ -1,517 +0,0 @@
package kamkeel.npcs.controllers.data.ability.type;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.data.*;
import noppes.npcs.client.gui.builder.FieldDef;
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityBeam;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.ValueUtil;
import java.util.Arrays;
import java.util.List;
public class AbilityBeamDual extends Ability {
private float beamWidth = 0.4f;
private float headSize = 0.6f;
private boolean dualFire= true;
private int dualFireDelay = 0;
// Data classes
private final EnergyDisplayData[] displayData = new EnergyDisplayData[]{
new EnergyDisplayData(0xFFFFFF, 0x00AAFF, true, 0.4f, 0.5f, 6.0f),
new EnergyDisplayData(0xFFFFFF, 0xFF0000, true, 0.4f, 0.5f, 6.0f),
};
private final EnergyCombatData combatData = new EnergyCombatData(10.0f, 1.5f, 0.2f, false, 4.0f, 0.5f);
private final EnergyHomingData homingData = new EnergyHomingData(0.4f, true, 0.1f, 15.0f);
private final EnergyLightningData[] lightningData = new EnergyLightningData[]{
new EnergyLightningData(), new EnergyLightningData()
};
private final EnergyLifespanData lifespanData = new EnergyLifespanData(25.0f, 200);
private final EnergyAnchorData[] anchorData = new EnergyAnchorData[]{
new EnergyAnchorData(AnchorPoint.RIGHT_HAND), new EnergyAnchorData(AnchorPoint.LEFT_HAND)
};
private final EnergyTrajectoryData[] trajectoryData = new EnergyTrajectoryData[]{
new EnergyTrajectoryData(), new EnergyTrajectoryData()
};
// Transient state for beam entity (used during windup charging)
private transient EntityAbilityBeam beamEntity = null;
private transient EntityAbilityBeam beamEntity2 = null;
public AbilityBeamDual() {
this.typeId = "ability.cnpc.beam_dual";
this.name = "Beam Dual";
this.targetingMode = TargetingMode.AGGRO_TARGET;
this.maxRange = 20.0f;
this.minRange = 5.0f;
this.cooldownTicks = 0;
this.windUpTicks = 80;
this.lockMovement = LockMovementType.WINDUP_AND_ACTIVE;
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
// Default built-in animations
this.windUpAnimationName = "Ability_BeamDual_Windup";
this.activeAnimationName = "Ability_BeamDual_Active";
}
@Override
public boolean isTargetingModeLocked() {
return true;
}
@Override
public TargetingMode[] getAllowedTargetingModes() {
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
signalCompletion();
return;
}
// Start firing the beam that was spawned during windup
if (beamEntity != null && !beamEntity.isDead) {
beamEntity.startFiring(target);
}
if (dualFire) {
if (beamEntity2 != null && !beamEntity2.isDead && dualFireDelay <= 0) {
beamEntity2.startFiring(target);
}
} else if (beamEntity2 != null) {
beamEntity2.setDead();
}
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
// Spawn beam in charging mode on first tick of windup
if (tick == 1) {
float offsetDist = 1.0f;
// Create beam in charging mode - follows caster based on anchor point during windup
Vec3 spawnPos1 = AnchorPointHelper.calculateAnchorPosition(caster, anchorData[0], offsetDist);
beamEntity = new EntityAbilityBeam(
world, caster, target,
spawnPos1.xCoord, spawnPos1.yCoord, spawnPos1.zCoord,
beamWidth, headSize,
displayData[0], combatData, homingData, lightningData[0], lifespanData, trajectoryData[0],
lockMovement.locksActive());
Vec3 spawnPos2 = AnchorPointHelper.calculateAnchorPosition(caster, anchorData[1], offsetDist);
beamEntity2 = new EntityAbilityBeam(
world, caster, target,
spawnPos2.xCoord, spawnPos2.yCoord, spawnPos2.zCoord,
beamWidth, headSize,
displayData[1], combatData, homingData, lightningData[1], lifespanData, trajectoryData[1],
lockMovement.locksActive());
beamEntity.setSiblingEntityId(beamEntity2.getEntityId());
beamEntity2.setSiblingEntityId(beamEntity.getEntityId());
beamEntity.setupCharging(anchorData[0], windUpTicks, offsetDist);
beamEntity2.setupCharging(anchorData[1], windUpTicks, offsetDist);
beamEntity.setEffects(this.effects);
if (dualFire) beamEntity2.setEffects(this.effects);
beamEntity.setSourceAbility(this);
beamEntity2.setSourceAbility(this);
world.spawnEntityInWorld(beamEntity);
world.spawnEntityInWorld(beamEntity2);
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Signal completion when entity dies
if (dualFire) {
if ((beamEntity == null || beamEntity.isDead) && (beamEntity2 == null || beamEntity2.isDead)) {
beamEntity = null;
beamEntity2 = null;
signalCompletion();
}
if (tick == dualFireDelay && beamEntity2 != null && !beamEntity2.isDead) {
beamEntity2.startFiring(target);
}
} else {
if (beamEntity == null || beamEntity.isDead) {
beamEntity = null;
signalCompletion();
}
}
}
@Override
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
}
@Override
public void onInterrupt(EntityLivingBase caster, net.minecraft.util.DamageSource source, float damage) {
cleanup();
}
@Override
public void cleanup() {
// Despawn beam entity if still alive
if (beamEntity != null && !beamEntity.isDead) {
beamEntity.setDead();
}
if (beamEntity2 != null && !beamEntity2.isDead) {
beamEntity2.setDead();
}
beamEntity = null;
beamEntity2 = null;
}
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
return null;
}
// Create circle telegraph at target position
Telegraph telegraph = Telegraph.circle(headSize * 2.0f);
telegraph.setDurationTicks(windUpTicks);
telegraph.setColor(windUpColor);
telegraph.setWarningColor(activeColor);
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
telegraph.setHeightOffset(telegraphHeightOffset);
// Position at target and follow target during windup
TelegraphInstance instance = new TelegraphInstance(telegraph, target.posX, target.posY, target.posZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
instance.setEntityIdToFollow(target.getEntityId());
return instance;
}
@Override
public float getTelegraphRadius() {
return headSize * 2.0f;
}
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("beamWidth", beamWidth);
nbt.setFloat("headSize", headSize);
nbt.setBoolean("dualFire", dualFire);
nbt.setInteger("dualFireDelay", dualFireDelay);
combatData.writeNBT(nbt);
homingData.writeNBT(nbt);
lifespanData.writeNBT(nbt);
NBTTagCompound beam1 = new NBTTagCompound();
NBTTagCompound beam2 = new NBTTagCompound();
for (int i = 0; i < 2; i++) {
NBTTagCompound beam = i == 0 ? beam1 : beam2;
anchorData[i].writeNBT(beam);
displayData[i].writeNBT(beam);
lightningData[i].writeNBT(beam);
trajectoryData[i].writeNBT(beam);
}
nbt.setTag("Beam_1", beam1);
nbt.setTag("Beam_2", beam2);
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
NBTTagCompound beam1 = nbt.hasKey("Beam_1") ? nbt.getCompoundTag("Beam_1") : new NBTTagCompound();
NBTTagCompound beam2 = nbt.hasKey("Beam_2") ? nbt.getCompoundTag("Beam_2") : new NBTTagCompound();
this.beamWidth = nbt.hasKey("beamWidth") ? nbt.getFloat("beamWidth") : 0.4f;
this.headSize = nbt.hasKey("headSize") ? nbt.getFloat("headSize") : 0.6f;
this.dualFire = !nbt.hasKey("dualFire") || nbt.getBoolean("dualFire");
this.dualFireDelay = nbt.hasKey("dualFireDelay") ? nbt.getInteger("dualFireDelay") : 0;
combatData.readNBT(nbt);
homingData.readNBT(nbt);
lifespanData.readNBT(nbt);
for (int i = 0; i < 2; i++) {
NBTTagCompound beam = i == 0 ? beam1 : beam2;
anchorData[i].readNBT(beam);
displayData[i].readNBT(beam);
lightningData[i].readNBT(beam);
trajectoryData[i].readNBT(beam);
}
}
// Getters & Setters - Standalone fields
public float getBeamWidth() { return beamWidth; }
public void setBeamWidth(float beamWidth) { this.beamWidth = beamWidth; }
public float getHeadSize() { return headSize; }
public void setHeadSize(float headSize) { this.headSize = headSize; }
public boolean isDualFire() { return dualFire; }
public void setDualFire(boolean dualFire) { this.dualFire = dualFire; }
public int getDualFireDelay() { return dualFireDelay; }
public void setDualFireDelay(int dualFireDelay) { this.dualFireDelay = dualFireDelay; }
private EnergyDisplayData getColorData(int beam) {
beam = ValueUtil.clamp(beam, 0, 1);
return displayData[beam];
}
private EnergyLightningData getLightningData(int beam) {
beam = ValueUtil.clamp(beam, 0, 1);
return lightningData[beam];
}
private EnergyAnchorData getAnchorData(int beam) {
beam = ValueUtil.clamp(beam, 0, 1);
return anchorData[beam];
}
// Getters & Setters - Color data
public int getInnerColor(int beam) { return getColorData(beam).innerColor; }
public void setInnerColor(int beam, int innerColor) { getColorData(beam).innerColor = innerColor; }
public int getOuterColor(int beam) { return getColorData(beam).outerColor; }
public void setOuterColor(int beam, int outerColor) { getColorData(beam).outerColor = outerColor; }
public boolean isOuterColorEnabled(int beam) { return getColorData(beam).outerColorEnabled; }
public void setOuterColorEnabled(int beam, boolean enabled) { getColorData(beam).outerColorEnabled = enabled; }
public float getOuterColorWidth(int beam) { return getColorData(beam).outerColorWidth; }
public void setOuterColorWidth(int beam, float width) { getColorData(beam).outerColorWidth = width; }
public float getOuterColorAlpha(int beam) { return getColorData(beam).outerColorAlpha; }
public void setOuterColorAlpha(int beam, float alpha) { getColorData(beam).outerColorAlpha = alpha; }
public float getRotationSpeed(int beam) { return getColorData(beam).rotationSpeed; }
public void setRotationSpeed(int beam, float speed) { getColorData(beam).rotationSpeed = speed; }
public int getInnerColor() { return getInnerColor(0); }
public void setInnerColor(int innerColor) { setInnerColor(0, innerColor); }
public int getOuterColor() { return getOuterColor(0); }
public void setOuterColor(int outerColor) { setOuterColor(0, outerColor); }
public boolean isOuterColorEnabled() { return isOuterColorEnabled(0); }
public void setOuterColorEnabled(boolean enabled) { setOuterColorEnabled(0, enabled); }
public float getOuterColorWidth() { return getOuterColorWidth(0); }
public void setOuterColorWidth(float width) { setOuterColorWidth(0, width); }
public float getOuterColorAlpha() { return getOuterColorAlpha(0); }
public void setOuterColorAlpha(float alpha) { setOuterColorAlpha(0, alpha); }
public float getRotationSpeed() { return getRotationSpeed(0); }
public void setRotationSpeed(float speed) { setRotationSpeed(0, speed); }
// Getters & Setters - Combat data
public float getDamage() { return combatData.damage; }
public void setDamage(float damage) { this.combatData.damage = damage; }
public float getKnockback() { return combatData.knockback; }
public void setKnockback(float knockback) { this.combatData.knockback = knockback; }
public float getKnockbackUp() { return combatData.knockbackUp; }
public void setKnockbackUp(float knockbackUp) { this.combatData.knockbackUp = knockbackUp; }
public boolean isExplosive() { return combatData.explosive; }
public void setExplosive(boolean explosive) { this.combatData.explosive = explosive; }
public float getExplosionRadius() { return combatData.explosionRadius; }
public void setExplosionRadius(float explosionRadius) { this.combatData.explosionRadius = explosionRadius; }
public float getExplosionDamageFalloff() { return combatData.explosionDamageFalloff; }
public void setExplosionDamageFalloff(float explosionDamageFalloff) { this.combatData.explosionDamageFalloff = explosionDamageFalloff; }
// Getters & Setters - Homing data
public float getSpeed() { return homingData.speed; }
public void setSpeed(float speed) { this.homingData.speed = speed; }
public boolean isHoming() { return homingData.homing; }
public void setHoming(boolean homing) { this.homingData.homing = homing; }
public float getHomingStrength() { return homingData.homingStrength; }
public void setHomingStrength(float homingStrength) { this.homingData.homingStrength = homingStrength; }
public float getHomingRange() { return homingData.homingRange; }
public void setHomingRange(float homingRange) { this.homingData.homingRange = homingRange; }
// Getters & Setters - Lightning data
public boolean hasLightningEffect(int beam) { return getLightningData(beam).lightningEffect; }
public void setLightningEffect(int beam, boolean lightningEffect) { getLightningData(beam).lightningEffect = lightningEffect; }
public float getLightningDensity(int beam) { return getLightningData(beam).lightningDensity; }
public void setLightningDensity(int beam, float lightningDensity) { getLightningData(beam).lightningDensity = lightningDensity; }
public float getLightningRadius(int beam) { return getLightningData(beam).lightningRadius; }
public void setLightningRadius(int beam, float lightningRadius) { getLightningData(beam).lightningRadius = lightningRadius; }
public boolean hasLightningEffect() { return hasLightningEffect(0); }
public void setLightningEffect(boolean lightningEffect) { setLightningEffect(0, lightningEffect); }
public float getLightningDensity() { return getLightningDensity(0); }
public void setLightningDensity(float lightningDensity) { setLightningDensity(0, lightningDensity); }
public float getLightningRadius() { return getLightningRadius(0); }
public void setLightningRadius(float lightningRadius) { setLightningRadius(0, lightningRadius); }
// Getters & Setters - Lifespan data
public float getMaxDistance() { return lifespanData.maxDistance; }
public void setMaxDistance(float maxDistance) { this.lifespanData.maxDistance = maxDistance; }
public int getMaxLifetime() { return lifespanData.maxLifetime; }
public void setMaxLifetime(int maxLifetime) { this.lifespanData.maxLifetime = maxLifetime; }
// Getters & Setters - Anchor point
public AnchorPoint getAnchorPointEnum(int beam) { return getAnchorData(beam).anchorPoint; }
public void setAnchorPointEnum(int beam, AnchorPoint anchorPoint) { getAnchorData(beam).anchorPoint = anchorPoint; }
public float getAnchorOffsetX(int beam) { return getAnchorData(beam).anchorOffsetX; }
public void setAnchorOffsetX(int beam, float x) { getAnchorData(beam).anchorOffsetX = x; }
public float getAnchorOffsetY(int beam) { return getAnchorData(beam).anchorOffsetY; }
public void setAnchorOffsetY(int beam, float y) { getAnchorData(beam).anchorOffsetY = y; }
public float getAnchorOffsetZ(int beam) { return getAnchorData(beam).anchorOffsetZ; }
public void setAnchorOffsetZ(int beam, float z) { getAnchorData(beam).anchorOffsetZ = z; }
public AnchorPoint getAnchorPointEnum() { return getAnchorPointEnum(0); }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { setAnchorPointEnum(0, anchorPoint); }
public float getAnchorOffsetX() { return getAnchorOffsetX(0); }
public void setAnchorOffsetX(float x) { setAnchorOffsetX(0, x); }
public float getAnchorOffsetY() { return getAnchorOffsetY(0); }
public void setAnchorOffsetY(float y) { setAnchorOffsetY(0, y); }
public float getAnchorOffsetZ() { return getAnchorOffsetZ(0); }
public void setAnchorOffsetZ(float z) { setAnchorOffsetZ(0, z); }
//@Override
public int getAnchorPoint(int beam) { return getAnchorData(beam).anchorPoint.ordinal(); }
public int getAnchorPoint() { return getAnchorData(0).anchorPoint.ordinal(); }
//@Override
public void setAnchorPoint(int beam, int point) { getAnchorData(beam).anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorPoint(int point) { getAnchorData(0).anchorPoint = AnchorPoint.fromOrdinal(point); }
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Type tab
FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getSpeed, this::setSpeed)
),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback),
FieldDef.section("ability.section.beam"),
FieldDef.row(
FieldDef.floatField("ability.beamWidth", this::getBeamWidth, this::setBeamWidth),
FieldDef.floatField("ability.headSize", this::getHeadSize, this::setHeadSize)
),
FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
),
FieldDef.section("ability.section.dual"),
FieldDef.boolField("ability.dualFire", this::isDualFire, this::setDualFire),
FieldDef.intField("ability.dualFireDelay", this::getDualFireDelay, this::setDualFireDelay)
.visibleWhen(this::isDualFire),
FieldDef.section("ability.section.homing"),
FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming)
.hover("ability.hover.homing"),
FieldDef.row(
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength)
.visibleWhen(this::isHoming),
FieldDef.floatField("gui.range", this::getHomingRange, this::setHomingRange)
.visibleWhen(this::isHoming)
),
FieldDef.section("ability.section.explosive"),
FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive)
.hover("ability.hover.explosive"),
FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius)
.visibleWhen(this::isExplosive),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects),
// Visual tab - Beam 1
FieldDef.section("ability.section.beam1").tab("ability.tab.visual"),
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> getAnchorPointEnum(0), v -> setAnchorPointEnum(0, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor",
() -> getInnerColor(0), v -> setInnerColor(0, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled",
() -> isOuterColorEnabled(0), v -> setOuterColorEnabled(0, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor",
() -> getOuterColor(0), v -> setOuterColor(0, v))
.tab("ability.tab.visual").visibleWhen(() -> isOuterColorEnabled(0)),
FieldDef.row(
FieldDef.floatField("ability.outerWidth",
() -> getOuterColorWidth(0), v -> setOuterColorWidth(0, v))
.visibleWhen(() -> isOuterColorEnabled(0)),
FieldDef.floatField("ability.outerAlpha",
() -> getOuterColorAlpha(0), v -> setOuterColorAlpha(0, v))
.range(0, 1).visibleWhen(() -> isOuterColorEnabled(0))
).tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed",
() -> getRotationSpeed(0), v -> setRotationSpeed(0, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning",
() -> hasLightningEffect(0), v -> setLightningEffect(0, v))
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density",
() -> getLightningDensity(0), v -> setLightningDensity(0, v))
.range(0.01f, 100f).visibleWhen(() -> hasLightningEffect(0)),
FieldDef.floatField("gui.radius",
() -> getLightningRadius(0), v -> setLightningRadius(0, v))
.range(0.1f, 100f).visibleWhen(() -> hasLightningEffect(0))
).tab("ability.tab.visual"),
// Visual tab - Beam 2
FieldDef.section("ability.section.beam2").tab("ability.tab.visual"),
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> getAnchorPointEnum(1), v -> setAnchorPointEnum(1, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor",
() -> getInnerColor(1), v -> setInnerColor(1, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled",
() -> isOuterColorEnabled(1), v -> setOuterColorEnabled(1, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor",
() -> getOuterColor(1), v -> setOuterColor(1, v))
.tab("ability.tab.visual").visibleWhen(() -> isOuterColorEnabled(1)),
FieldDef.row(
FieldDef.floatField("ability.outerWidth",
() -> getOuterColorWidth(1), v -> setOuterColorWidth(1, v))
.visibleWhen(() -> isOuterColorEnabled(1)),
FieldDef.floatField("ability.outerAlpha",
() -> getOuterColorAlpha(1), v -> setOuterColorAlpha(1, v))
.range(0, 1).visibleWhen(() -> isOuterColorEnabled(1))
).tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed",
() -> getRotationSpeed(1), v -> setRotationSpeed(1, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning",
() -> hasLightningEffect(1), v -> setLightningEffect(1, v))
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density",
() -> getLightningDensity(1), v -> setLightningDensity(1, v))
.range(0.01f, 100f).visibleWhen(() -> hasLightningEffect(1)),
FieldDef.floatField("gui.radius",
() -> getLightningRadius(1), v -> setLightningRadius(1, v))
.range(0.1f, 100f).visibleWhen(() -> hasLightningEffect(1))
).tab("ability.tab.visual")
));
}
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
EntityAbilityBeam beam = new EntityAbilityBeam(npc.worldObj);
beam.setupPreview(npc, beamWidth, headSize, displayData[0], lightningData[0], anchorData[0], windUpTicks, 1.0f);
return beam;
}
@Override
public int getPreviewActiveDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 100) : 100;
}
}
@@ -87,11 +87,13 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
}
/**
* Locks the charge direction based on current target position.
* Called once at windup start - direction won't change even if target moves.
* Locks the charge direction. Called once at windup start — direction won't change even if target moves.
* NPC: charges toward aggro target.
* Player: charges in look direction.
*/
private void lockChargeDirection(EntityLivingBase caster, EntityLivingBase target) {
if (target != null) {
if (!isPlayerCaster(caster) && target != null) {
// NPC: charge toward aggro target
double dx = target.posX - caster.posX;
double dz = target.posZ - caster.posZ;
double len = Math.sqrt(dx * dx + dz * dz);
@@ -102,6 +104,7 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
chargeDirection = Vec3.createVectorHelper(-Math.sin(yaw), 0, Math.cos(yaw));
}
} else {
// Player: charge in look direction
float yaw = (float) Math.toRadians(caster.rotationYaw);
chargeDirection = Vec3.createVectorHelper(-Math.sin(yaw), 0, Math.cos(yaw));
}
@@ -138,7 +141,9 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
if (chargeDirection == null) return;
// Enforce rotation every tick
enforceLockedRotation(caster);
if (!isPreview()) {
enforceLockedRotation(caster);
}
// Calculate distance traveled
double distanceTraveled = Math.sqrt(
@@ -150,12 +155,15 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
if (distanceTraveled >= maxRange) {
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
if (!isPreview()) {
caster.velocityChanged = true;
}
signalCompletion();
return;
}
if (isChargeBlocked(caster)) {
// Block detection (skip in preview - no real world collision)
if (!isPreview() && isChargeBlocked(caster)) {
stopMomentum(caster);
signalCompletion();
return;
@@ -165,10 +173,12 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
caster.motionX = chargeDirection.xCoord * chargeSpeed;
caster.motionY = 0;
caster.motionZ = chargeDirection.zCoord * chargeSpeed;
caster.velocityChanged = true;
if (!isPreview()) {
caster.velocityChanged = true;
}
// Server-side collision damage
if (!world.isRemote) {
// Server-side collision damage (skip in preview)
if (!world.isRemote && !isPreview()) {
AxisAlignedBB hitBox = caster.boundingBox.expand(hitWidth, hitWidth * 0.5, hitWidth);
@SuppressWarnings("unchecked")
@@ -211,7 +221,9 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
private void stopMomentum(EntityLivingBase caster) {
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
if (!isPreview()) {
caster.velocityChanged = true;
}
}
private boolean isChargeBlocked(EntityLivingBase caster) {
@@ -249,9 +261,10 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
return null;
}
// Calculate direction to target at this moment (locked)
// NPC: telegraph points toward aggro target
// Player: telegraph points in look direction
float yaw;
if (target != null) {
if (!isPlayerCaster(caster) && target != null) {
double dx = target.posX - caster.posX;
double dz = target.posZ - caster.posZ;
yaw = (float) Math.toDegrees(Math.atan2(-dx, dz));
@@ -277,66 +290,8 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
return instance;
}
// ==================== PREVIEW MODE ====================
private transient double previewDirX, previewDirZ;
private transient double previewStartX, previewStartZ;
private transient boolean previewCharging = false;
@Override
@SideOnly(Side.CLIENT)
public void onPreviewExecute(EntityNPCInterface npc) {
previewStartX = npc.posX;
previewStartZ = npc.posZ;
previewCharging = false;
// Calculate direction toward fake target
if (previewTarget != null) {
double dx = previewTarget.posX - npc.posX;
double dz = previewTarget.posZ - npc.posZ;
double len = Math.sqrt(dx * dx + dz * dz);
if (len > 0) {
previewDirX = dx / len;
previewDirZ = dz / len;
} else {
float yaw = (float) Math.toRadians(npc.rotationYaw);
previewDirX = -Math.sin(yaw);
previewDirZ = Math.cos(yaw);
}
} else {
float yaw = (float) Math.toRadians(npc.rotationYaw);
previewDirX = -Math.sin(yaw);
previewDirZ = Math.cos(yaw);
}
previewCharging = true;
}
@Override
@SideOnly(Side.CLIENT)
public void onPreviewActiveTick(EntityNPCInterface npc, int tick) {
if (!previewCharging) return;
// Check distance traveled
double distTraveled = Math.sqrt(
Math.pow(npc.posX - previewStartX, 2) +
Math.pow(npc.posZ - previewStartZ, 2)
);
if (distTraveled >= maxRange) {
previewCharging = false;
return;
}
npc.prevPosX = npc.posX;
npc.prevPosY = npc.posY;
npc.prevPosZ = npc.posZ;
npc.posX += previewDirX * chargeSpeed;
npc.posZ += previewDirZ * chargeSpeed;
}
@Override
public int getPreviewActiveDuration() {
public int getMaxPreviewDuration() {
return (int) Math.ceil(maxRange / chargeSpeed) + 5;
}
@@ -109,31 +109,35 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
switch (sweepMode) {
case SWIPE:
float prevRotation = currentRotation;
currentRotation += sweepSpeed;
if (currentRotation > arcAngle / 2.0f) {
// Final sweep — check from prevRotation to end of arc
performSweepDamageRange(caster, world, innerRadius, range, prevRotation, arcAngle / 2.0f);
if (!isPreview()) {
performSweepDamageRange(caster, world, innerRadius, range, prevRotation, arcAngle / 2.0f);
}
signalCompletion();
return;
}
// Check entities between previous and current sweep position
performSweepDamageRange(caster, world, innerRadius, range, prevRotation, currentRotation);
if (!isPreview()) {
performSweepDamageRange(caster, world, innerRadius, range, prevRotation, currentRotation);
}
break;
case SPIN:
if (tick >= spinDurationTicks) {
signalCompletion(); // Spin duration complete
signalCompletion();
return;
}
float prevSpin = currentRotation;
currentRotation = (currentRotation + sweepSpeed) % 360.0f;
hitEntities.clear();
performSweepDamageRange(caster, world, innerRadius, range, prevSpin, currentRotation);
if (!isPreview()) {
hitEntities.clear();
performSweepDamageRange(caster, world, innerRadius, range, prevSpin, currentRotation);
}
break;
}
}
@@ -87,13 +87,14 @@ public class AbilityDash extends Ability implements IAbilityDash {
// Type-specific parameters
private DashMode dashMode = DashMode.DEFENSIVE;
private float dashDistance = 4.0f;
private float dashSpeed = 1.5f;
private float dashSpeed = 0.5f;
// Runtime state
private transient Vec3 dashDirection;
private transient double startX, startY, startZ;
private transient double prevTickX, prevTickZ;
private transient DashDirection chosenDirection;
private transient int maxActiveTicks;
public AbilityDash() {
this.typeId = "ability.cnpc.dash";
@@ -139,15 +140,19 @@ public class AbilityDash extends Ability implements IAbilityDash {
prevTickX = caster.posX;
prevTickZ = caster.posZ;
// Safety timeout: expected ticks + generous buffer to prevent infinite dash
maxActiveTicks = dashSpeed > 0 ? (int)(dashDistance / dashSpeed) + 10 : 10;
// Choose random direction based on mode
DashDirection[] directions = dashMode == DashMode.AGGRESSIVE
? AGGRESSIVE_DIRECTIONS
: DEFENSIVE_DIRECTIONS;
chosenDirection = directions[RANDOM.nextInt(directions.length)];
// Calculate dash direction relative to target
// NPC: dash direction is relative to aggro target facing
// Player: dash direction is relative to look direction
float baseYaw;
if (target != null) {
if (!isPlayerCaster(caster) && target != null) {
double dx = target.posX - caster.posX;
double dz = target.posZ - caster.posZ;
baseYaw = (float) Math.toDegrees(Math.atan2(-dx, dz));
@@ -165,21 +170,30 @@ public class AbilityDash extends Ability implements IAbilityDash {
Math.cos(yawRad)
);
// Small upward impulse for a skip/hop arc (gravity handles the descent)
caster.motionY = 0.2;
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (dashDirection == null) return;
// Safety timeout or missing state: force-complete to prevent stuck NPC
if (!isPreview() && (dashDirection == null || tick > maxActiveTicks)) {
stopDash(caster);
signalCompletion();
return;
}
if (dashDirection == null) {
signalCompletion();
return;
}
// Stall detection: if entity hasn't moved since last tick, it's stuck against a wall
if (tick > 1) {
double movedThisTick = Math.sqrt(
Math.pow(caster.posX - prevTickX, 2) +
Math.pow(caster.posZ - prevTickZ, 2));
if (movedThisTick < 0.01) {
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
if (!isPreview() && tick > 1) {
double dx = caster.posX - prevTickX;
double dz = caster.posZ - prevTickZ;
if (dx * dx + dz * dz < 0.0001) {
stopDash(caster);
signalCompletion();
return;
}
@@ -187,57 +201,56 @@ public class AbilityDash extends Ability implements IAbilityDash {
prevTickX = caster.posX;
prevTickZ = caster.posZ;
// Calculate distance traveled
double distanceTraveled = Math.sqrt(
Math.pow(caster.posX - startX, 2) +
Math.pow(caster.posZ - startZ, 2)
);
// Check if reached max distance
if (distanceTraveled >= dashDistance) {
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
double travelDx = caster.posX - startX;
double travelDz = caster.posZ - startZ;
if (travelDx * travelDx + travelDz * travelDz >= (double) dashDistance * dashDistance) {
stopDash(caster);
signalCompletion();
return;
}
if (isDashBlocked(caster)) {
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
// Block detection (skip in preview - no real world collision)
if (!isPreview() && isDashBlocked(caster)) {
stopDash(caster);
signalCompletion();
return;
}
// Move caster
// Move caster (motionY left to gravity for skip arc)
caster.motionX = dashDirection.xCoord * dashSpeed;
caster.motionY = 0;
caster.motionZ = dashDirection.zCoord * dashSpeed;
caster.velocityChanged = true;
if (!isPreview()) {
caster.velocityChanged = true;
// Trail particles
world.spawnParticle("smoke", caster.posX, caster.posY + 0.5, caster.posZ, 0, 0, 0);
// Trail particles
world.spawnParticle("smoke", caster.posX, caster.posY + 0.5, caster.posZ, 0, 0, 0);
}
}
private void stopDash(EntityLivingBase caster) {
caster.motionX = 0;
caster.motionZ = 0;
if (!isPreview()) {
caster.velocityChanged = true;
}
}
@Override
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
stopDash(caster);
}
@Override
public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
stopDash(caster);
}
@Override
public void cleanup() {
dashDirection = null;
chosenDirection = null;
maxActiveTicks = 0;
}
private boolean isDashBlocked(EntityLivingBase caster) {
@@ -247,66 +260,8 @@ public class AbilityDash extends Ability implements IAbilityDash {
return !caster.worldObj.getCollidingBoundingBoxes(caster, caster.boundingBox.copy().offset(nextX, 0, nextZ)).isEmpty();
}
// ==================== PREVIEW MODE ====================
private transient double previewDirX, previewDirZ;
private transient double previewStartX, previewStartZ;
private transient boolean previewDashing = false;
@Override
@SideOnly(Side.CLIENT)
public void onPreviewExecute(EntityNPCInterface npc) {
previewStartX = npc.posX;
previewStartZ = npc.posZ;
previewDashing = false;
// Pick a random direction based on mode
DashDirection[] directions = dashMode == DashMode.AGGRESSIVE
? AGGRESSIVE_DIRECTIONS
: DEFENSIVE_DIRECTIONS;
DashDirection dir = directions[RANDOM.nextInt(directions.length)];
float baseYaw;
if (previewTarget != null) {
double dx = previewTarget.posX - npc.posX;
double dz = previewTarget.posZ - npc.posZ;
baseYaw = (float) Math.toDegrees(Math.atan2(-dx, dz));
} else {
baseYaw = npc.rotationYaw;
}
float dashYaw = baseYaw + dir.getAngleOffset();
float yawRad = (float) Math.toRadians(dashYaw);
previewDirX = -Math.sin(yawRad);
previewDirZ = Math.cos(yawRad);
previewDashing = true;
}
@Override
@SideOnly(Side.CLIENT)
public void onPreviewActiveTick(EntityNPCInterface npc, int tick) {
if (!previewDashing) return;
double distTraveled = Math.sqrt(
Math.pow(npc.posX - previewStartX, 2) +
Math.pow(npc.posZ - previewStartZ, 2)
);
if (distTraveled >= dashDistance) {
previewDashing = false;
return;
}
npc.prevPosX = npc.posX;
npc.prevPosY = npc.posY;
npc.prevPosZ = npc.posZ;
npc.posX += previewDirX * dashSpeed;
npc.posZ += previewDirZ * dashSpeed;
}
@Override
public int getPreviewActiveDuration() {
public int getMaxPreviewDuration() {
return (int) Math.ceil(dashDistance / dashSpeed) + 5;
}
@@ -330,7 +285,7 @@ public class AbilityDash extends Ability implements IAbilityDash {
this.dashMode = DashMode.DEFENSIVE;
}
this.dashDistance = nbt.hasKey("dashDistance") ? nbt.getFloat("dashDistance") : 4.0f;
this.dashSpeed = nbt.hasKey("dashSpeed") ? nbt.getFloat("dashSpeed") : 1.5f;
this.dashSpeed = nbt.hasKey("dashSpeed") ? nbt.getFloat("dashSpeed") : 0.5f;
}
// Getters & Setters
@@ -12,7 +12,6 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityDisc;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
@@ -23,33 +22,45 @@ import noppes.npcs.api.ability.type.IAbilityDisc;
import java.util.Arrays;
import java.util.List;
import noppes.npcs.entity.EntityNPCInterface;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
/**
* Disc ability: Spawns a flat spinning disc projectile.
* Supports 1-8 projectiles with shared visuals and per-projectile anchor points.
* Has optional boomerang behavior to return to owner.
*/
public class AbilityDisc extends Ability implements IAbilityDisc {
// Disc geometry
private static final int MAX_PROJECTILES = 8;
// Disc geometry (shared)
private float discRadius = 1.0f;
private float discThickness = 0.2f;
private boolean vertical = false; // false = horizontal (flat), true = vertical (thin edge forward)
// Boomerang properties
// Boomerang properties (shared)
private boolean boomerang = false;
private int boomerangDelay = 40;
// Energy data classes
private final EnergyDisplayData colorData = new EnergyDisplayData(0xFFFFFF, 0xFF8800, true, 0.4f, 0.5f, 5.0f);
// Projectile count and fire stagger
private int projectileCount = 1;
private int fireDelay = 0;
// Shared visual data (all projectiles use these)
private EnergyDisplayData displayData = new EnergyDisplayData(0xFFFFFF, 0xFF8800, true, 0.4f, 0.5f, 5.0f);
private EnergyLightningData lightningData = new EnergyLightningData();
private EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Shared combat/movement data
private final EnergyCombatData combatData = new EnergyCombatData(8.0f, 1.2f, 0.15f, false, 3.0f, 0.5f);
private final EnergyHomingData homingData = new EnergyHomingData(0.6f, true, 0.12f, 18.0f);
private final EnergyLightningData lightningData = new EnergyLightningData();
private final EnergyLifespanData lifespanData = new EnergyLifespanData(35.0f, 200);
private final EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.RIGHT_HAND);
private final EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Transient state for disc entity (used during windup charging)
private transient EntityAbilityDisc discEntity = null;
// Per-projectile data (anchor + optional color override)
private ProjectileData[] projectiles;
// Transient entity state
private transient EntityAbilityDisc[] discEntities;
public AbilityDisc() {
this.typeId = "ability.cnpc.disc";
@@ -62,9 +73,90 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
this.lockMovement = LockMovementType.WINDUP;
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
// Default built-in animations
this.windUpAnimationName = "Ability_Disc_Windup";
this.activeAnimationName = "Ability_Disc_Active";
initProjectiles(1);
}
private void initProjectiles(int count) {
this.projectileCount = Math.max(1, Math.min(count, MAX_PROJECTILES));
this.projectiles = new ProjectileData[projectileCount];
for (int i = 0; i < projectileCount; i++) {
projectiles[i] = new ProjectileData(getDefaultAnchor(i));
}
}
/**
* Disc anchor order is REVERSED from Orb/Beam: [0]=LEFT_HAND, [1]=RIGHT_HAND
*/
private AnchorPoint getDefaultAnchor(int index) {
switch (index) {
case 0: return AnchorPoint.RIGHT_HAND;
case 1: return AnchorPoint.LEFT_HAND;
default: return AnchorPoint.FRONT;
}
}
public void setProjectileCount(int count) {
int newCount = Math.max(1, Math.min(count, MAX_PROJECTILES));
if (newCount == projectileCount) return;
ProjectileData[] oldProjectiles = projectiles;
initProjectiles(newCount);
if (oldProjectiles != null) {
int copyCount = Math.min(oldProjectiles.length, newCount);
for (int i = 0; i < copyCount; i++) {
if (oldProjectiles[i] != null) projectiles[i] = oldProjectiles[i];
}
}
}
public int getProjectileCount() {
return projectileCount;
}
public int getFireDelay() {
return fireDelay;
}
public void setFireDelay(int delay) {
this.fireDelay = Math.max(0, delay);
}
// Legacy compat
public int getDualFireDelay() { return fireDelay; }
public void setDualFireDelay(int delay) { setFireDelay(delay); }
@Override
public List<AbilityVariant> getVariants() {
return Arrays.asList(
new AbilityVariant("ability.variant.single", a -> {
a.setName("Disc");
}),
new AbilityVariant("ability.variant.dual", a -> {
AbilityDisc disc = (AbilityDisc) a;
a.setName("Dual Disc");
disc.setProjectileCount(2);
disc.setFireDelay(10);
// Set color override for second disc
disc.projectiles[1].colorOverride = true;
disc.projectiles[1].innerColor = 0xFFFFFF;
disc.projectiles[1].outerColor = 0x8800FF;
a.setWindUpAnimationName("Ability_DiscDual_Windup");
a.setActiveAnimationName("Ability_DiscDual_Active");
})
);
}
@Override
public boolean allowOverlap() {
return true;
}
@Override
public boolean isReadyForBurstCompletion(int activeTick) {
return fireDelay <= 0 || activeTick >= fireDelay * (projectileCount - 1);
}
@Override
@@ -77,49 +169,115 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
signalCompletion();
return;
/**
* Create disc entities.
* NPC: target is the aggro target — discs will home toward it.
* Player: target is null — discs fire in caster's look direction.
*/
private EntityAbilityDisc[] createDiscEntities(EntityLivingBase caster, EntityLivingBase target, World world) {
EntityAbilityDisc[] entities = new EntityAbilityDisc[projectileCount];
for (int i = 0; i < projectileCount; i++) {
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, projectiles[i].anchor);
EnergyDisplayData resolved = projectiles[i].resolveDisplay(displayData);
entities[i] = new EntityAbilityDisc(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord,
discRadius, discThickness,
resolved, combatData, homingData, lightningData, lifespanData, trajectoryData,
boomerang, boomerangDelay);
entities[i].setEffects(this.effects);
entities[i].setSourceAbility(this);
}
// Start moving the disc that was spawned during windup
if (discEntity != null && !discEntity.isDead) {
discEntity.startMoving(target);
if (projectileCount == 2 && entities[0] != null && entities[1] != null) {
entities[0].setSiblingEntityId(entities[1].getEntityId());
entities[1].setSiblingEntityId(entities[0].getEntityId());
}
return entities;
}
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
private void fireDiscEntity(EntityAbilityDisc disc, EntityLivingBase target) {
if (disc == null || disc.isDead) return;
if (isPreview()) {
disc.startPreviewFiring();
} else {
disc.startMoving(target);
}
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
// Spawn disc in charging mode on first tick of windup
if (tick == 1) {
// Create disc in charging mode - follows caster based on anchor point during windup
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchorData);
discEntity = new EntityAbilityDisc(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord,
discRadius, discThickness,
colorData, combatData, homingData, lightningData, lifespanData, trajectoryData,
boomerang, boomerangDelay);
discEntity.setupCharging(anchorData, windUpTicks);
discEntities = createDiscEntities(caster, target, world);
for (int i = 0; i < projectileCount; i++) {
EnergyDisplayData resolved = projectiles[i].resolveDisplay(displayData);
if (isPreview()) {
discEntities[i].setupPreview(caster, discRadius, discThickness, resolved, lightningData, projectiles[i].anchor, windUpTicks, vertical);
} else {
discEntities[i].setupCharging(projectiles[i].anchor, windUpTicks, vertical);
}
spawnAbilityEntity(world, discEntities[i]);
}
}
}
discEntity.setEffects(this.effects);
discEntity.setSourceAbility(this);
world.spawnEntityInWorld(discEntity);
@Override
public void onBurstRefire(EntityLivingBase caster, EntityLivingBase target, World world) {
discEntities = createDiscEntities(caster, target, world);
for (EntityAbilityDisc disc : discEntities) {
spawnAbilityEntity(world, disc);
}
for (EntityAbilityDisc disc : discEntities) {
fireDiscEntity(disc, target);
}
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote && !isPreview()) {
signalCompletion();
return;
}
if (discEntities == null) return;
// Fire first projectile immediately
fireDiscEntity(discEntities[0], target);
// Fire remaining projectiles if no delay
if (fireDelay <= 0) {
for (int i = 1; i < projectileCount; i++) {
fireDiscEntity(discEntities[i], target);
}
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Signal completion when entity dies
if (discEntity == null || discEntity.isDead) {
discEntity = null;
if (discEntities == null) {
signalCompletion();
return;
}
// Fire staggered projectiles
if (fireDelay > 0) {
for (int i = 1; i < projectileCount; i++) {
if (tick == fireDelay * i) {
fireDiscEntity(discEntities[i], target);
}
}
}
// Check if all entities are dead
boolean allDead = true;
for (EntityAbilityDisc disc : discEntities) {
if (disc != null && !disc.isDead) {
allDead = false;
break;
}
}
if (allDead) {
signalCompletion();
}
}
@@ -135,16 +293,22 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
@Override
public void cleanup() {
// Despawn disc entity if still alive
if (discEntity != null && !discEntity.isDead) {
discEntity.setDead();
if (discEntities != null) {
for (int i = 0; i < discEntities.length; i++) {
if (discEntities[i] != null && !discEntities[i].isDead) {
discEntities[i].setDead();
}
discEntities[i] = null;
}
}
discEntity = null;
discEntities = null;
}
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
// NPC: telegraph on aggro target position
// Player: no telegraph (discs fire in look direction, no fixed position to mark)
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster) || target == null) {
return null;
}
@@ -173,173 +337,336 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("discRadius", discRadius);
nbt.setFloat("discThickness", discThickness);
nbt.setBoolean("vertical", vertical);
nbt.setBoolean("boomerang", boomerang);
nbt.setInteger("boomerangDelay", boomerangDelay);
anchorData.writeNBT(nbt);
colorData.writeNBT(nbt);
nbt.setInteger("projectileCount", projectileCount);
nbt.setInteger("fireDelay", fireDelay);
// Shared visual data
displayData.writeNBT(nbt);
lightningData.writeNBT(nbt);
// Shared combat/movement data
combatData.writeNBT(nbt);
homingData.writeNBT(nbt);
lightningData.writeNBT(nbt);
lifespanData.writeNBT(nbt);
// Per-projectile data
for (int i = 0; i < projectileCount; i++) {
NBTTagCompound projNbt = new NBTTagCompound();
projectiles[i].writeNBT(projNbt);
nbt.setTag("Projectile_" + i, projNbt);
}
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
this.discRadius = nbt.hasKey("discRadius") ? nbt.getFloat("discRadius") : 1.0f;
this.discThickness = nbt.hasKey("discThickness") ? nbt.getFloat("discThickness") : 0.2f;
this.vertical = nbt.hasKey("vertical") && nbt.getBoolean("vertical");
this.boomerang = nbt.hasKey("boomerang") && nbt.getBoolean("boomerang");
this.boomerangDelay = nbt.hasKey("boomerangDelay") ? nbt.getInteger("boomerangDelay") : 40;
anchorData.readNBT(nbt);
colorData.readNBT(nbt);
int count = nbt.hasKey("projectileCount") ? nbt.getInteger("projectileCount") : 1;
initProjectiles(count);
// Read fireDelay with fallback to old dualFireDelay key
if (nbt.hasKey("fireDelay")) {
this.fireDelay = nbt.getInteger("fireDelay");
} else if (nbt.hasKey("dualFireDelay")) {
this.fireDelay = nbt.getInteger("dualFireDelay");
} else {
this.fireDelay = 0;
}
// Shared combat/movement data
combatData.readNBT(nbt);
homingData.readNBT(nbt);
lightningData.readNBT(nbt);
lifespanData.readNBT(nbt);
// Determine format and read accordingly
if (nbt.hasKey("Projectile_0")) {
NBTTagCompound proj0 = nbt.getCompoundTag("Projectile_0");
if (proj0.hasKey("colorOverride")) {
// NEW format: shared visuals at root + ProjectileData per projectile
displayData.readNBT(nbt);
lightningData.readNBT(nbt);
for (int i = 0; i < projectileCount; i++) {
if (nbt.hasKey("Projectile_" + i)) {
projectiles[i].readNBT(nbt.getCompoundTag("Projectile_" + i));
}
}
} else {
// OLD format: full per-projectile arrays (displayData, lightningData, etc. in each Projectile_i)
// Read primary visuals from Projectile_0
displayData.readNBT(proj0);
lightningData.readNBT(proj0);
projectiles[0].anchor.readNBT(proj0);
// Read remaining projectiles, set color override if colors differ
for (int i = 1; i < projectileCount; i++) {
if (nbt.hasKey("Projectile_" + i)) {
NBTTagCompound projNbt = nbt.getCompoundTag("Projectile_" + i);
projectiles[i].anchor.readNBT(projNbt);
// Check if this projectile had different colors
EnergyDisplayData tempDisplay = new EnergyDisplayData();
tempDisplay.readNBT(projNbt);
if (tempDisplay.innerColor != displayData.innerColor || tempDisplay.outerColor != displayData.outerColor) {
projectiles[i].colorOverride = true;
projectiles[i].innerColor = tempDisplay.innerColor;
projectiles[i].outerColor = tempDisplay.outerColor;
}
}
}
}
} else {
// LEGACY flat format: all data at root level
displayData.readNBT(nbt);
lightningData.readNBT(nbt);
projectiles[0].anchor.readNBT(nbt);
}
}
// Getters & Setters
// ═══════════════════════════════════════════════════════════════════
// API GETTERS & SETTERS
// ═══════════════════════════════════════════════════════════════════
public float getSpeed() { return homingData.speed; }
public void setSpeed(float speed) { homingData.speed = speed; }
public float getDiscRadius() { return discRadius; }
public void setDiscRadius(float discRadius) { this.discRadius = discRadius; }
public float getDiscThickness() { return discThickness; }
public void setDiscThickness(float discThickness) { this.discThickness = discThickness; }
public float getMaxDistance() { return lifespanData.maxDistance; }
public void setMaxDistance(float maxDistance) { lifespanData.maxDistance = maxDistance; }
public int getMaxLifetime() { return lifespanData.maxLifetime; }
public void setMaxLifetime(int maxLifetime) { lifespanData.maxLifetime = maxLifetime; }
public float getDamage() { return combatData.damage; }
public void setDamage(float damage) { combatData.damage = damage; }
public float getKnockback() { return combatData.knockback; }
public void setKnockback(float knockback) { combatData.knockback = knockback; }
public float getKnockbackUp() { return combatData.knockbackUp; }
public void setKnockbackUp(float knockbackUp) { combatData.knockbackUp = knockbackUp; }
public boolean isHoming() { return homingData.homing; }
public void setHoming(boolean homing) { homingData.homing = homing; }
public float getHomingStrength() { return homingData.homingStrength; }
public void setHomingStrength(float homingStrength) { homingData.homingStrength = homingStrength; }
public float getHomingRange() { return homingData.homingRange; }
public void setHomingRange(float homingRange) { homingData.homingRange = homingRange; }
public boolean isVertical() { return vertical; }
public void setVertical(boolean vertical) { this.vertical = vertical; }
public boolean isBoomerang() { return boomerang; }
public void setBoomerang(boolean boomerang) { this.boomerang = boomerang; }
public int getBoomerangDelay() { return boomerangDelay; }
public void setBoomerangDelay(int boomerangDelay) { this.boomerangDelay = boomerangDelay; }
public float getMaxDistance() { return lifespanData.maxDistance; }
public void setMaxDistance(float d) { lifespanData.maxDistance = d; }
public int getMaxLifetime() { return lifespanData.maxLifetime; }
public void setMaxLifetime(int t) { lifespanData.maxLifetime = t; }
public float getDamage() { return combatData.damage; }
public void setDamage(float d) { combatData.damage = d; }
public float getKnockback() { return combatData.knockback; }
public void setKnockback(float k) { combatData.knockback = k; }
public float getKnockbackUp() { return combatData.knockbackUp; }
public void setKnockbackUp(float k) { combatData.knockbackUp = k; }
public boolean isHoming() { return homingData.homing; }
public void setHoming(boolean h) { homingData.homing = h; }
public float getHomingStrength() { return homingData.homingStrength; }
public void setHomingStrength(float s) { homingData.homingStrength = s; }
public float getHomingRange() { return homingData.homingRange; }
public void setHomingRange(float r) { homingData.homingRange = r; }
public boolean isExplosive() { return combatData.explosive; }
public void setExplosive(boolean explosive) { combatData.explosive = explosive; }
public void setExplosive(boolean e) { combatData.explosive = e; }
public float getExplosionRadius() { return combatData.explosionRadius; }
public void setExplosionRadius(float explosionRadius) { combatData.explosionRadius = explosionRadius; }
public void setExplosionRadius(float r) { combatData.explosionRadius = r; }
public float getExplosionDamageFalloff() { return combatData.explosionDamageFalloff; }
public void setExplosionDamageFalloff(float explosionDamageFalloff) { combatData.explosionDamageFalloff = explosionDamageFalloff; }
public int getInnerColor() { return colorData.innerColor; }
public void setInnerColor(int innerColor) { colorData.innerColor = innerColor; }
public int getOuterColor() { return colorData.outerColor; }
public void setOuterColor(int outerColor) { colorData.outerColor = outerColor; }
public float getOuterColorWidth() { return colorData.outerColorWidth; }
public void setOuterColorWidth(float outerColorWidth) { colorData.outerColorWidth = outerColorWidth; }
public float getOuterColorAlpha() { return colorData.outerColorAlpha; }
public void setOuterColorAlpha(float outerColorAlpha) { colorData.outerColorAlpha = outerColorAlpha; }
public boolean isOuterColorEnabled() { return colorData.outerColorEnabled; }
public void setOuterColorEnabled(boolean outerColorEnabled) { colorData.outerColorEnabled = outerColorEnabled; }
public float getRotationSpeed() { return colorData.rotationSpeed; }
public void setRotationSpeed(float rotationSpeed) { colorData.rotationSpeed = rotationSpeed; }
public void setExplosionDamageFalloff(float f) { combatData.explosionDamageFalloff = f; }
// Shared display data (primary colors)
public int getInnerColor() { return displayData.innerColor; }
public void setInnerColor(int c) { displayData.innerColor = c; }
public int getOuterColor() { return displayData.outerColor; }
public void setOuterColor(int c) { displayData.outerColor = c; }
public float getOuterColorWidth() { return displayData.outerColorWidth; }
public void setOuterColorWidth(float w) { displayData.outerColorWidth = w; }
public float getOuterColorAlpha() { return displayData.outerColorAlpha; }
public void setOuterColorAlpha(float a) { displayData.outerColorAlpha = a; }
public boolean isOuterColorEnabled() { return displayData.outerColorEnabled; }
public void setOuterColorEnabled(boolean e) { displayData.outerColorEnabled = e; }
public float getRotationSpeed() { return displayData.rotationSpeed; }
public void setRotationSpeed(float s) { displayData.rotationSpeed = s; }
// Shared lightning data
public boolean hasLightningEffect() { return lightningData.lightningEffect; }
public void setLightningEffect(boolean lightningEffect) { lightningData.lightningEffect = lightningEffect; }
public void setLightningEffect(boolean e) { lightningData.lightningEffect = e; }
public float getLightningDensity() { return lightningData.lightningDensity; }
public void setLightningDensity(float lightningDensity) { lightningData.lightningDensity = lightningDensity; }
public void setLightningDensity(float d) { lightningData.lightningDensity = d; }
public float getLightningRadius() { return lightningData.lightningRadius; }
public void setLightningRadius(float lightningRadius) { lightningData.lightningRadius = lightningRadius; }
public AnchorPoint getAnchorPointEnum() { return anchorData.anchorPoint; }
public float getAnchorOffsetX() { return anchorData.anchorOffsetX; }
public float getAnchorOffsetY() { return anchorData.anchorOffsetY; }
public float getAnchorOffsetZ() { return anchorData.anchorOffsetZ; }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { this.anchorData.anchorPoint = anchorPoint; }
public void setAnchorOffsetX(float x) { this.anchorData.anchorOffsetX = x; }
public void setAnchorOffsetY(float y) { this.anchorData.anchorOffsetY = y; }
public void setAnchorOffsetZ(float z) { this.anchorData.anchorOffsetZ = z; }
public void setLightningRadius(float r) { lightningData.lightningRadius = r; }
public int getLightningFadeTime() { return lightningData.lightningFadeTime; }
public void setLightningFadeTime(int t) { lightningData.lightningFadeTime = t; }
// Anchor - default to projectile 0
public AnchorPoint getAnchorPointEnum() { return projectiles[0].anchor.anchorPoint; }
public void setAnchorPointEnum(AnchorPoint p) { projectiles[0].anchor.anchorPoint = p; }
public float getAnchorOffsetX() { return projectiles[0].anchor.anchorOffsetX; }
public void setAnchorOffsetX(float x) { projectiles[0].anchor.anchorOffsetX = x; }
public float getAnchorOffsetY() { return projectiles[0].anchor.anchorOffsetY; }
public void setAnchorOffsetY(float y) { projectiles[0].anchor.anchorOffsetY = y; }
public float getAnchorOffsetZ() { return projectiles[0].anchor.anchorOffsetZ; }
public void setAnchorOffsetZ(float z) { projectiles[0].anchor.anchorOffsetZ = z; }
@Override
public int getAnchorPoint() { return anchorData.anchorPoint.ordinal(); }
public int getAnchorPoint() { return projectiles[0].anchor.anchorPoint.ordinal(); }
@Override
public void setAnchorPoint(int point) { this.anchorData.anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorPoint(int point) { projectiles[0].anchor.anchorPoint = AnchorPoint.fromOrdinal(point); }
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
// Indexed API methods
public int getInnerColor(int index) {
ProjectileData p = projectiles[clampIndex(index)];
return p.colorOverride ? p.innerColor : displayData.innerColor;
}
public void setInnerColor(int index, int color) {
ProjectileData p = projectiles[clampIndex(index)];
p.colorOverride = true;
p.innerColor = color;
}
EntityAbilityDisc disc = new EntityAbilityDisc(npc.worldObj);
disc.setupPreview(npc, discRadius, discThickness, colorData, lightningData, anchorData, windUpTicks);
return disc;
public int getOuterColor(int index) {
ProjectileData p = projectiles[clampIndex(index)];
return p.colorOverride ? p.outerColor : displayData.outerColor;
}
public void setOuterColor(int index, int color) {
ProjectileData p = projectiles[clampIndex(index)];
p.colorOverride = true;
p.outerColor = color;
}
public int getAnchorPoint(int index) { return projectiles[clampIndex(index)].anchor.anchorPoint.ordinal(); }
public void setAnchorPoint(int index, int point) { projectiles[clampIndex(index)].anchor.anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorOffsetX(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetX = offset; }
public void setAnchorOffsetY(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetY = offset; }
public void setAnchorOffsetZ(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetZ = offset; }
private int clampIndex(int index) {
return Math.max(0, Math.min(index, projectileCount - 1));
}
@Override
public int getPreviewActiveDuration() {
public int getMaxPreviewDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 100) : 100;
}
// ═══════════════════════════════════════════════════════════════════
// GUI FIELD DEFINITIONS
// ═══════════════════════════════════════════════════════════════════
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Type tab
FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getSpeed, this::setSpeed)
),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback),
FieldDef.section("ability.section.disc"),
FieldDef.row(
FieldDef.floatField("gui.radius", this::getDiscRadius, this::setDiscRadius),
FieldDef.floatField("gui.thickness", this::getDiscThickness, this::setDiscThickness)
),
FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
),
FieldDef.section("ability.section.homing"),
FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming)
.hover("ability.hover.homing"),
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength)
.visibleWhen(this::isHoming),
FieldDef.section("ability.section.boomerang"),
FieldDef.boolField("gui.enabled", this::isBoomerang, this::setBoomerang)
.hover("ability.hover.boomerang"),
FieldDef.intField("gui.delay", this::getBoomerangDelay, this::setBoomerangDelay)
.visibleWhen(this::isBoomerang),
FieldDef.section("ability.section.explosive"),
FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive)
.hover("ability.hover.explosive"),
FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius)
.visibleWhen(this::isExplosive),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects),
// Visual tab
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class, this::getAnchorPointEnum, this::setAnchorPointEnum)
.tab("ability.tab.visual"),
FieldDef.section("ability.section.colors").tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor)
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled)
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor", this::getOuterColor, this::setOuterColor)
.tab("ability.tab.visual").visibleWhen(this::isOuterColorEnabled),
FieldDef.row(
FieldDef.floatField("ability.outerWidth", this::getOuterColorWidth, this::setOuterColorWidth)
.visibleWhen(this::isOuterColorEnabled),
FieldDef.floatField("ability.outerAlpha", this::getOuterColorAlpha, this::setOuterColorAlpha)
.range(0, 1).visibleWhen(this::isOuterColorEnabled)
).tab("ability.tab.visual"),
FieldDef.section("ability.section.effects").tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed)
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning", this::hasLightningEffect, this::setLightningEffect)
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density", this::getLightningDensity, this::setLightningDensity)
.range(0.01f, 100f).visibleWhen(this::hasLightningEffect),
FieldDef.floatField("gui.radius", this::getLightningRadius, this::setLightningRadius)
.range(0.1f, 100f).visibleWhen(this::hasLightningEffect)
).tab("ability.tab.visual")
// Type tab - projectile count and fire delay
defs.add(FieldDef.row(
FieldDef.intField("ability.projectileCount", this::getProjectileCount, this::setProjectileCount).range(1, MAX_PROJECTILES),
FieldDef.intField("ability.fireDelay", this::getFireDelay, this::setFireDelay)
.range(0, 200).visibleWhen(() -> projectileCount > 1)
));
// Type tab - disc properties
defs.add(FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getSpeed, this::setSpeed)
));
defs.add(FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback));
defs.add(FieldDef.section("ability.section.disc"));
defs.add(FieldDef.row(
FieldDef.floatField("gui.radius", this::getDiscRadius, this::setDiscRadius),
FieldDef.floatField("gui.thickness", this::getDiscThickness, this::setDiscThickness)
));
defs.add(FieldDef.boolField("ability.vertical", this::isVertical, this::setVertical)
.hover("ability.hover.vertical"));
defs.add(FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
));
defs.add(FieldDef.section("ability.section.homing"));
defs.add(FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming).hover("ability.hover.homing"));
defs.add(FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength).visibleWhen(this::isHoming));
defs.add(FieldDef.section("ability.section.boomerang"));
defs.add(FieldDef.boolField("gui.enabled", this::isBoomerang, this::setBoomerang).hover("ability.hover.boomerang"));
defs.add(FieldDef.intField("gui.delay", this::getBoomerangDelay, this::setBoomerangDelay).visibleWhen(this::isBoomerang));
defs.add(FieldDef.section("ability.section.explosive"));
defs.add(FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive).hover("ability.hover.explosive"));
defs.add(FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius).visibleWhen(this::isExplosive));
defs.add(AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects));
// Visual tab - shared primary colors
defs.add(FieldDef.section("ability.section.colors").tab("ability.tab.visual"));
defs.add(FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor)
.tab("ability.tab.visual"));
defs.add(FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled)
.tab("ability.tab.visual"));
defs.add(FieldDef.colorSubGui("ability.outerColor", this::getOuterColor, this::setOuterColor)
.tab("ability.tab.visual").visibleWhen(this::isOuterColorEnabled));
defs.add(FieldDef.row(
FieldDef.floatField("ability.outerWidth", this::getOuterColorWidth, this::setOuterColorWidth)
.visibleWhen(this::isOuterColorEnabled),
FieldDef.floatField("ability.outerAlpha", this::getOuterColorAlpha, this::setOuterColorAlpha)
.range(0, 1).visibleWhen(this::isOuterColorEnabled)
).tab("ability.tab.visual"));
// Visual tab - shared effects
defs.add(FieldDef.section("ability.section.effects").tab("ability.tab.visual"));
defs.add(FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed)
.tab("ability.tab.visual"));
defs.add(FieldDef.boolField("ability.lightning", this::hasLightningEffect, this::setLightningEffect)
.tab("ability.tab.visual"));
defs.add(FieldDef.row(
FieldDef.floatField("gui.density", this::getLightningDensity, this::setLightningDensity)
.visibleWhen(this::hasLightningEffect).range(0.01f, 100f),
FieldDef.floatField("gui.radius", this::getLightningRadius, this::setLightningRadius)
.range(0.1f, 100f).visibleWhen(this::hasLightningEffect)
).tab("ability.tab.visual"));
// Visual tab - per-projectile sections
for (int i = 0; i < MAX_PROJECTILES; i++) {
final int idx = i;
String sectionKey = "ability.section.projectile" + (i + 1);
defs.add(FieldDef.section(sectionKey).tab("ability.tab.visual")
.visibleWhen(() -> idx < projectileCount));
// Anchor point
defs.add(FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> projectiles[idx].anchor.anchorPoint, v -> projectiles[idx].anchor.anchorPoint = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
defs.add(FieldDef.row(
FieldDef.floatField("ability.anchor.offsetX", () -> projectiles[idx].anchor.anchorOffsetX, v -> projectiles[idx].anchor.anchorOffsetX = v),
FieldDef.floatField("ability.anchor.offsetY", () -> projectiles[idx].anchor.anchorOffsetY, v -> projectiles[idx].anchor.anchorOffsetY = v)
).tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
defs.add(FieldDef.floatField("ability.anchor.offsetZ", () -> projectiles[idx].anchor.anchorOffsetZ, v -> projectiles[idx].anchor.anchorOffsetZ = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
// Color override (only when multiple projectiles)
defs.add(FieldDef.boolField("ability.colorOverride", () -> projectiles[idx].colorOverride, v -> projectiles[idx].colorOverride = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1));
defs.add(FieldDef.colorSubGui("ability.innerColor", () -> projectiles[idx].innerColor, v -> projectiles[idx].innerColor = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1 && projectiles[idx].colorOverride));
defs.add(FieldDef.colorSubGui("ability.outerColor", () -> projectiles[idx].outerColor, v -> projectiles[idx].outerColor = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1 && projectiles[idx].colorOverride));
}
}
}
@@ -1,527 +0,0 @@
package kamkeel.npcs.controllers.data.ability.type;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.data.*;
import noppes.npcs.client.gui.builder.FieldDef;
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityDisc;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.ValueUtil;
import java.util.Arrays;
import java.util.List;
public class AbilityDiscDual extends Ability {
// Disc geometry
private float discRadius = 1.0f;
private float discThickness = 0.2f;
// Boomerang properties
private boolean boomerang = false;
private int boomerangDelay = 40;
// Dual properties
private boolean dualFire = true;
private int dualFireDelay = 10;
// Energy data classes
private final EnergyDisplayData[] displayData = new EnergyDisplayData[]{
new EnergyDisplayData(0xFFFFFF, 0xFF8800, true, 0.4f, 0.5f, 5.0f),
new EnergyDisplayData(0xFFFFFF, 0x8800FF, true, 0.4f, 0.5f, 5.0f)
};
private final EnergyCombatData combatData = new EnergyCombatData(8.0f, 1.2f, 0.15f, false, 3.0f, 0.5f);
private final EnergyHomingData homingData = new EnergyHomingData(0.6f, true, 0.12f, 18.0f);
private final EnergyLightningData[] lightningData = new EnergyLightningData[]{
new EnergyLightningData(), new EnergyLightningData()
};
private final EnergyLifespanData lifespanData = new EnergyLifespanData(35.0f, 200);
private final EnergyAnchorData[] anchorData = new EnergyAnchorData[]{
new EnergyAnchorData(AnchorPoint.LEFT_HAND), new EnergyAnchorData(AnchorPoint.RIGHT_HAND)
};
private final EnergyTrajectoryData[] trajectoryData = new EnergyTrajectoryData[]{
new EnergyTrajectoryData(), new EnergyTrajectoryData()
};
// Transient state for disc entity (used during windup charging)
private transient EntityAbilityDisc discEntity = null;
private transient EntityAbilityDisc discEntity2 = null;
public AbilityDiscDual() {
this.typeId = "ability.cnpc.disc_dual";
this.name = "Disc Dual";
this.targetingMode = TargetingMode.AGGRO_TARGET;
this.maxRange = 30.0f;
this.minRange = 5.0f;
this.cooldownTicks = 0;
this.windUpTicks = 60;
this.lockMovement = LockMovementType.WINDUP;
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
// Default built-in animations
this.windUpAnimationName = "Ability_DiscDual_Windup";
this.activeAnimationName = "Ability_DiscDual_Active";
}
@Override
public boolean isTargetingModeLocked() {
return true;
}
@Override
public TargetingMode[] getAllowedTargetingModes() {
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
signalCompletion();
return;
}
// Start moving the orb that was spawned during windup
if (discEntity != null && !discEntity.isDead) {
discEntity.startMoving(target);
}
if (dualFire) {
if (discEntity2 != null && !discEntity2.isDead && dualFireDelay <= 0) {
discEntity2.startMoving(target);
}
} else if (discEntity2 != null) {
discEntity2.setDead();
}
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
// Spawn disc in charging mode on first tick of windup
if (tick == 1) {
// Create disc in charging mode - follows caster based on anchor point during windup
Vec3 spawnPos1 = AnchorPointHelper.calculateAnchorPosition(caster, anchorData[0]);
discEntity = new EntityAbilityDisc(
world, caster, target,
spawnPos1.xCoord, spawnPos1.yCoord, spawnPos1.zCoord,
discRadius, discThickness,
displayData[0], combatData, homingData, lightningData[0], lifespanData, trajectoryData[0],
boomerang, boomerangDelay);
Vec3 spawnPos2 = AnchorPointHelper.calculateAnchorPosition(caster, anchorData[1]);
discEntity2 = new EntityAbilityDisc(
world, caster, target,
spawnPos2.xCoord, spawnPos2.yCoord, spawnPos2.zCoord,
discRadius, discThickness,
displayData[1], combatData, homingData, lightningData[1], lifespanData, trajectoryData[1],
boomerang, boomerangDelay);
discEntity.setSiblingEntityId(discEntity2.getEntityId());
discEntity2.setSiblingEntityId(discEntity.getEntityId());
discEntity.setupCharging(anchorData[0], windUpTicks);
discEntity2.setupCharging(anchorData[1], windUpTicks);
discEntity.setEffects(this.effects);
if (dualFire) {
discEntity2.setEffects(this.effects);
}
discEntity.setSourceAbility(this);
discEntity2.setSourceAbility(this);
world.spawnEntityInWorld(discEntity);
world.spawnEntityInWorld(discEntity2);
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Signal completion when entity dies
if (dualFire) {
if ((discEntity == null || discEntity.isDead) && (discEntity2 == null || discEntity2.isDead)) {
discEntity = null;
discEntity2 = null;
signalCompletion();
}
if (tick == dualFireDelay && discEntity2 != null && !discEntity2.isDead) {
discEntity2.startMoving(target);
}
} else {
if (discEntity == null || discEntity.isDead) {
discEntity = null;
signalCompletion();
}
}
}
@Override
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
}
@Override
public void onInterrupt(EntityLivingBase caster, net.minecraft.util.DamageSource source, float damage) {
cleanup();
}
@Override
public void cleanup() {
// Despawn disc entity if still alive
if (discEntity != null && !discEntity.isDead) {
discEntity.setDead();
}
if (discEntity2 != null && !discEntity2.isDead) {
discEntity2.setDead();
}
discEntity = null;
discEntity2 = null;
}
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
return null;
}
// Create circle telegraph at target position
Telegraph telegraph = Telegraph.circle(discRadius * 1.5f);
telegraph.setDurationTicks(windUpTicks);
telegraph.setColor(windUpColor);
telegraph.setWarningColor(activeColor);
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
telegraph.setHeightOffset(telegraphHeightOffset);
// Position at target and follow target during windup
TelegraphInstance instance = new TelegraphInstance(telegraph, target.posX, target.posY, target.posZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
instance.setEntityIdToFollow(target.getEntityId());
return instance;
}
@Override
public float getTelegraphRadius() {
return discRadius * 1.5f;
}
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("discRadius", discRadius);
nbt.setFloat("discThickness", discThickness);
nbt.setBoolean("boomerang", boomerang);
nbt.setInteger("boomerangDelay", boomerangDelay);
nbt.setBoolean("dualFire", dualFire);
nbt.setInteger("dualFireDelay", dualFireDelay);
combatData.writeNBT(nbt);
homingData.writeNBT(nbt);
lifespanData.writeNBT(nbt);
NBTTagCompound disc1 = new NBTTagCompound();
NBTTagCompound disc2 = new NBTTagCompound();
for (int i = 0; i < 2; i++) {
NBTTagCompound disc = i == 0 ? disc1 : disc2;
anchorData[i].writeNBT(disc);
displayData[i].writeNBT(disc);
lightningData[i].writeNBT(disc);
trajectoryData[i].writeNBT(disc);
}
nbt.setTag("Disc_1", disc1);
nbt.setTag("Disc_2", disc2);
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
NBTTagCompound disc1 = nbt.hasKey("Disc_1") ? nbt.getCompoundTag("Disc_1") : new NBTTagCompound();
NBTTagCompound disc2 = nbt.hasKey("Disc_2") ? nbt.getCompoundTag("Disc_2") : new NBTTagCompound();
this.discRadius = nbt.hasKey("discRadius") ? nbt.getFloat("discRadius") : 1.0f;
this.discThickness = nbt.hasKey("discThickness") ? nbt.getFloat("discThickness") : 0.2f;
this.boomerang = nbt.hasKey("boomerang") && nbt.getBoolean("boomerang");
this.boomerangDelay = nbt.hasKey("boomerangDelay") ? nbt.getInteger("boomerangDelay") : 40;
this.dualFire = !nbt.hasKey("dualFire") || nbt.getBoolean("dualFire");
this.dualFireDelay = nbt.hasKey("dualFireDelay") ? nbt.getInteger("dualFireDelay") : 0;
combatData.readNBT(nbt);
homingData.readNBT(nbt);
lifespanData.readNBT(nbt);
for (int i = 0; i < 2; i++) {
NBTTagCompound disc = i == 0 ? disc1 : disc2;
anchorData[i].readNBT(disc);
displayData[i].readNBT(disc);
lightningData[i].readNBT(disc);
trajectoryData[i].readNBT(disc);
}
}
// Getters & Setters
private EnergyDisplayData getColorData(int orb) {
orb = ValueUtil.clamp(orb, 0, 1);
return displayData[orb];
}
private EnergyLightningData getLightningData(int orb) {
orb = ValueUtil.clamp(orb, 0, 1);
return lightningData[orb];
}
private EnergyAnchorData getAnchorData(int orb) {
orb = ValueUtil.clamp(orb, 0, 1);
return anchorData[orb];
}
public boolean isDualFire() { return dualFire; }
public void setDualFire(boolean dualFire) { this.dualFire = dualFire; }
public int getDualFireDelay() { return dualFireDelay; }
public void setDualFireDelay(int dualFireDelay) { this.dualFireDelay = dualFireDelay; }
public float getSpeed() { return homingData.speed; }
public void setSpeed(float speed) { homingData.speed = speed; }
public float getDiscRadius() { return discRadius; }
public void setDiscRadius(float discRadius) { this.discRadius = discRadius; }
public float getDiscThickness() { return discThickness; }
public void setDiscThickness(float discThickness) { this.discThickness = discThickness; }
public float getMaxDistance() { return lifespanData.maxDistance; }
public void setMaxDistance(float maxDistance) { lifespanData.maxDistance = maxDistance; }
public int getMaxLifetime() { return lifespanData.maxLifetime; }
public void setMaxLifetime(int maxLifetime) { lifespanData.maxLifetime = maxLifetime; }
public float getDamage() { return combatData.damage; }
public void setDamage(float damage) { combatData.damage = damage; }
public float getKnockback() { return combatData.knockback; }
public void setKnockback(float knockback) { combatData.knockback = knockback; }
public float getKnockbackUp() { return combatData.knockbackUp; }
public void setKnockbackUp(float knockbackUp) { combatData.knockbackUp = knockbackUp; }
public boolean isHoming() { return homingData.homing; }
public void setHoming(boolean homing) { homingData.homing = homing; }
public float getHomingStrength() { return homingData.homingStrength; }
public void setHomingStrength(float homingStrength) { homingData.homingStrength = homingStrength; }
public float getHomingRange() { return homingData.homingRange; }
public void setHomingRange(float homingRange) { homingData.homingRange = homingRange; }
public boolean isBoomerang() { return boomerang; }
public void setBoomerang(boolean boomerang) { this.boomerang = boomerang; }
public int getBoomerangDelay() { return boomerangDelay; }
public void setBoomerangDelay(int boomerangDelay) { this.boomerangDelay = boomerangDelay; }
public boolean isExplosive() { return combatData.explosive; }
public void setExplosive(boolean explosive) { combatData.explosive = explosive; }
public float getExplosionRadius() { return combatData.explosionRadius; }
public void setExplosionRadius(float explosionRadius) { combatData.explosionRadius = explosionRadius; }
public float getExplosionDamageFalloff() { return combatData.explosionDamageFalloff; }
public void setExplosionDamageFalloff(float explosionDamageFalloff) { combatData.explosionDamageFalloff = explosionDamageFalloff; }
public int getInnerColor(int orb) { return getColorData(orb).innerColor; }
public void setInnerColor(int orb, int innerColor) { getColorData(orb).innerColor = innerColor; }
public int getOuterColor(int orb) { return getColorData(orb).outerColor; }
public void setOuterColor(int orb, int outerColor) { getColorData(orb).outerColor = outerColor; }
public boolean isOuterColorEnabled(int orb) { return getColorData(orb).outerColorEnabled; }
public void setOuterColorEnabled(int orb, boolean enabled) { getColorData(orb).outerColorEnabled = enabled; }
public float getOuterColorWidth(int orb) { return getColorData(orb).outerColorWidth; }
public void setOuterColorWidth(int orb, float width) { getColorData(orb).outerColorWidth = width; }
public float getOuterColorAlpha(int orb) { return getColorData(orb).outerColorAlpha; }
public void setOuterColorAlpha(int orb, float alpha) { getColorData(orb).outerColorAlpha = alpha; }
public float getRotationSpeed(int orb) { return getColorData(orb).rotationSpeed; }
public void setRotationSpeed(int orb, float speed) { getColorData(orb).rotationSpeed = speed; }
public int getInnerColor() { return getInnerColor(0); }
public void setInnerColor(int innerColor) { setInnerColor(0, innerColor); }
public int getOuterColor() { return getOuterColor(0); }
public void setOuterColor(int outerColor) { setOuterColor(0, outerColor); }
public boolean isOuterColorEnabled() { return isOuterColorEnabled(0); }
public void setOuterColorEnabled(boolean enabled) { setOuterColorEnabled(0, enabled); }
public float getOuterColorWidth() { return getOuterColorWidth(0); }
public void setOuterColorWidth(float width) { setOuterColorWidth(0, width); }
public float getOuterColorAlpha() { return getOuterColorAlpha(0); }
public void setOuterColorAlpha(float alpha) { setOuterColorAlpha(0, alpha); }
public float getRotationSpeed() { return getRotationSpeed(0); }
public void setRotationSpeed(float speed) { setRotationSpeed(0, speed); }
public boolean hasLightningEffect(int orb) { return getLightningData(orb).lightningEffect; }
public void setLightningEffect(int orb, boolean lightningEffect) { getLightningData(orb).lightningEffect = lightningEffect; }
public float getLightningDensity(int orb) { return getLightningData(orb).lightningDensity; }
public void setLightningDensity(int orb, float lightningDensity) { getLightningData(orb).lightningDensity = lightningDensity; }
public float getLightningRadius(int orb) { return getLightningData(orb).lightningRadius; }
public void setLightningRadius(int orb, float lightningRadius) { getLightningData(orb).lightningRadius = lightningRadius; }
public boolean hasLightningEffect() { return hasLightningEffect(0); }
public void setLightningEffect(boolean lightningEffect) { setLightningEffect(0, lightningEffect); }
public float getLightningDensity() { return getLightningDensity(0); }
public void setLightningDensity(float lightningDensity) { setLightningDensity(0, lightningDensity); }
public float getLightningRadius() { return getLightningRadius(0); }
public void setLightningRadius(float lightningRadius) { setLightningRadius(0, lightningRadius); }
public AnchorPoint getAnchorPointEnum(int orb) { return getAnchorData(orb).anchorPoint; }
public void setAnchorPointEnum(int orb, AnchorPoint anchorPoint) { getAnchorData(orb).anchorPoint = anchorPoint; }
public float getAnchorOffsetX(int orb) { return getAnchorData(orb).anchorOffsetX; }
public void setAnchorOffsetX(int orb, float x) { getAnchorData(orb).anchorOffsetX = x; }
public float getAnchorOffsetY(int orb) { return getAnchorData(orb).anchorOffsetY; }
public void setAnchorOffsetY(int orb, float y) { getAnchorData(orb).anchorOffsetY = y; }
public float getAnchorOffsetZ(int orb) { return getAnchorData(orb).anchorOffsetZ; }
public void setAnchorOffsetZ(int orb, float z) { getAnchorData(orb).anchorOffsetZ = z; }
public AnchorPoint getAnchorPointEnum() { return getAnchorPointEnum(0); }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { setAnchorPointEnum(0, anchorPoint); }
public float getAnchorOffsetX() { return getAnchorOffsetX(0); }
public void setAnchorOffsetX(float x) { setAnchorOffsetX(0, x); }
public float getAnchorOffsetY() { return getAnchorOffsetY(0); }
public void setAnchorOffsetY(float y) { setAnchorOffsetY(0, y); }
public float getAnchorOffsetZ() { return getAnchorOffsetZ(0); }
public void setAnchorOffsetZ(float z) { setAnchorOffsetZ(0, z); }
//@Override
public int getAnchorPoint(int orb) { return getAnchorData(orb).anchorPoint.ordinal(); }
public int getAnchorPoint() { return getAnchorData(0).anchorPoint.ordinal(); }
//@Override
public void setAnchorPoint(int orb, int point) { getAnchorData(orb).anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorPoint(int point) { getAnchorData(0).anchorPoint = AnchorPoint.fromOrdinal(point); }
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Type tab
FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getSpeed, this::setSpeed)
),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback),
FieldDef.section("ability.section.disc"),
FieldDef.row(
FieldDef.floatField("gui.radius", this::getDiscRadius, this::setDiscRadius),
FieldDef.floatField("gui.thickness", this::getDiscThickness, this::setDiscThickness)
),
FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
),
FieldDef.section("ability.section.dual"),
FieldDef.boolField("ability.dualFire", this::isDualFire, this::setDualFire),
FieldDef.intField("ability.dualFireDelay", this::getDualFireDelay, this::setDualFireDelay)
.visibleWhen(this::isDualFire),
FieldDef.section("ability.section.homing"),
FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming)
.hover("ability.hover.homing"),
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength)
.visibleWhen(this::isHoming),
FieldDef.section("ability.section.boomerang"),
FieldDef.boolField("gui.enabled", this::isBoomerang, this::setBoomerang)
.hover("ability.hover.boomerang"),
FieldDef.intField("gui.delay", this::getBoomerangDelay, this::setBoomerangDelay)
.visibleWhen(this::isBoomerang),
FieldDef.section("ability.section.explosive"),
FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive)
.hover("ability.hover.explosive"),
FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius)
.visibleWhen(this::isExplosive),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects),
// Visual tab - Disc 1
FieldDef.section("ability.section.disc1").tab("ability.tab.visual"),
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> getAnchorPointEnum(0), v -> setAnchorPointEnum(0, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor",
() -> getInnerColor(0), v -> setInnerColor(0, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled",
() -> isOuterColorEnabled(0), v -> setOuterColorEnabled(0, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor",
() -> getOuterColor(0), v -> setOuterColor(0, v))
.tab("ability.tab.visual").visibleWhen(() -> isOuterColorEnabled(0)),
FieldDef.row(
FieldDef.floatField("ability.outerWidth",
() -> getOuterColorWidth(0), v -> setOuterColorWidth(0, v))
.visibleWhen(() -> isOuterColorEnabled(0)),
FieldDef.floatField("ability.outerAlpha",
() -> getOuterColorAlpha(0), v -> setOuterColorAlpha(0, v))
.range(0, 1).visibleWhen(() -> isOuterColorEnabled(0))
).tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed",
() -> getRotationSpeed(0), v -> setRotationSpeed(0, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning",
() -> hasLightningEffect(0), v -> setLightningEffect(0, v))
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density",
() -> getLightningDensity(0), v -> setLightningDensity(0, v))
.range(0.01f, 5.0f).visibleWhen(() -> hasLightningEffect(0)),
FieldDef.floatField("gui.radius",
() -> getLightningRadius(0), v -> setLightningRadius(0, v))
.range(0.1f, 10.0f).visibleWhen(() -> hasLightningEffect(0))
).tab("ability.tab.visual"),
// Visual tab - Disc 2
FieldDef.section("ability.section.disc2").tab("ability.tab.visual"),
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> getAnchorPointEnum(1), v -> setAnchorPointEnum(1, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor",
() -> getInnerColor(1), v -> setInnerColor(1, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled",
() -> isOuterColorEnabled(1), v -> setOuterColorEnabled(1, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor",
() -> getOuterColor(1), v -> setOuterColor(1, v))
.tab("ability.tab.visual").visibleWhen(() -> isOuterColorEnabled(1)),
FieldDef.row(
FieldDef.floatField("ability.outerWidth",
() -> getOuterColorWidth(1), v -> setOuterColorWidth(1, v))
.visibleWhen(() -> isOuterColorEnabled(1)),
FieldDef.floatField("ability.outerAlpha",
() -> getOuterColorAlpha(1), v -> setOuterColorAlpha(1, v))
.range(0, 1).visibleWhen(() -> isOuterColorEnabled(1))
).tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed",
() -> getRotationSpeed(1), v -> setRotationSpeed(1, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning",
() -> hasLightningEffect(1), v -> setLightningEffect(1, v))
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density",
() -> getLightningDensity(1), v -> setLightningDensity(1, v))
.range(0.01f, 100f).visibleWhen(() -> hasLightningEffect(1)),
FieldDef.floatField("gui.radius",
() -> getLightningRadius(1), v -> setLightningRadius(1, v))
.range(0.1f, 100f).visibleWhen(() -> hasLightningEffect(1))
).tab("ability.tab.visual")
));
}
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
EntityAbilityDisc disc = new EntityAbilityDisc(npc.worldObj);
disc.setupPreview(npc, discRadius, discThickness, displayData[0], lightningData[0], anchorData[0], windUpTicks);
return disc;
}
@Override
public int getPreviewActiveDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 100) : 100;
}
}
@@ -70,6 +70,11 @@ public class AbilityGuard extends Ability implements IAbilityGuard {
return false;
}
@Override
public boolean allowBurst() {
return false;
}
public enum CounterType {
FLAT,
PERCENT;
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.type;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.UserType;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import net.minecraft.entity.EntityLivingBase;
@@ -111,6 +112,12 @@ public class AbilityHazard extends Ability implements IAbilityHazard {
this.cooldownTicks = 0;
this.windUpTicks = 30;
this.telegraphType = TelegraphType.CIRCLE;
this.allowedBy = UserType.NPC_ONLY;
}
@Override
public boolean allowBurst() {
return false;
}
@Override
@@ -197,14 +204,12 @@ public class AbilityHazard extends Ability implements IAbilityHazard {
}
break;
case AT_TARGET:
// Use telegraph position if available, apply offset
if (telegraph != null) {
double[] pos = Ability.calculateOffsetPosition(telegraph.getX(), telegraph.getY(), telegraph.getZ(),
minOffset, maxOffset, randomOffset, RANDOM);
zoneX = pos[0];
zoneY = pos[1];
zoneZ = pos[2];
// Update telegraph to show actual hazard position
telegraph.setX(zoneX);
telegraph.setY(zoneY);
telegraph.setZ(zoneZ);
@@ -243,7 +248,7 @@ public class AbilityHazard extends Ability implements IAbilityHazard {
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
// Check if hazard duration has ended
if (tick >= durationTicks) {
@@ -251,53 +256,55 @@ public class AbilityHazard extends Ability implements IAbilityHazard {
return;
}
damagedThisTick.clear();
ticksSinceDamage++;
if (!isPreview()) {
damagedThisTick.clear();
ticksSinceDamage++;
switch (placement) {
case FOLLOW_CASTER:
zoneX = caster.posX;
zoneY = caster.posY;
zoneZ = caster.posZ;
break;
case FOLLOW_TARGET:
if (target != null) {
zoneX = target.posX;
zoneY = target.posY;
zoneZ = target.posZ;
}
break;
default:
break;
}
if (ticksSinceDamage >= damageInterval) {
ticksSinceDamage = 0;
AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox(
zoneX - radius, zoneY - heightBelow, zoneZ - radius,
zoneX + radius, zoneY + heightAbove, zoneZ + radius
);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, searchBox);
for (EntityLivingBase entity : entities) {
if (entity == caster && !affectsCaster) continue;
if (damagedThisTick.contains(entity.getEntityId())) continue;
if (!isInZone(entity, caster)) continue;
if (damagePerSecond > 0) {
if (ignoreInvulnFrames) {
entity.hurtResistantTime = 0;
switch (placement) {
case FOLLOW_CASTER:
zoneX = caster.posX;
zoneY = caster.posY;
zoneZ = caster.posZ;
break;
case FOLLOW_TARGET:
if (target != null) {
zoneX = target.posX;
zoneY = target.posY;
zoneZ = target.posZ;
}
// Apply damage with scripted event support (no knockback for hazard)
boolean wasHit = applyAbilityDamage(caster, entity, damagePerSecond, 0);
if (!wasHit) continue; // Skip debuffs if hit was cancelled
}
break;
default:
break;
}
applyDebuffs(entity);
damagedThisTick.add(entity.getEntityId());
if (ticksSinceDamage >= damageInterval) {
ticksSinceDamage = 0;
AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox(
zoneX - radius, zoneY - heightBelow, zoneZ - radius,
zoneX + radius, zoneY + heightAbove, zoneZ + radius
);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, searchBox);
for (EntityLivingBase entity : entities) {
if (entity == caster && !affectsCaster) continue;
if (damagedThisTick.contains(entity.getEntityId())) continue;
if (!isInZone(entity, caster)) continue;
if (damagePerSecond > 0) {
if (ignoreInvulnFrames) {
entity.hurtResistantTime = 0;
}
// Apply damage with scripted event support (no knockback for hazard)
boolean wasHit = applyAbilityDamage(caster, entity, damagePerSecond, 0);
if (!wasHit) continue; // Skip debuffs if hit was cancelled
}
applyDebuffs(entity);
damagedThisTick.add(entity.getEntityId());
}
}
}
}
@@ -63,6 +63,11 @@ public class AbilityHeal extends Ability implements IAbilityHeal {
return false;
}
@Override
public boolean allowBurst() {
return false;
}
@Override
public boolean isTargetingModeLocked() {
return true;
@@ -75,27 +80,31 @@ public class AbilityHeal extends Ability implements IAbilityHeal {
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
getHealedAllies().clear();
if (!isPreview()) {
getHealedAllies().clear();
// Always find allies if we're healing them (needed for both instant and HoT)
if (healAllies && healRadius > 0) {
findAlliesInRadius(caster, world);
// Always find allies if we're healing them (needed for both instant and HoT)
if (healAllies && healRadius > 0) {
findAlliesInRadius(caster, world);
}
if (instantHeal) {
// Instant heal - apply all healing now
if (healSelf) {
healEntity(caster);
spawnHealParticles(world, caster);
}
for (EntityLivingBase ally : getHealedAllies()) {
healEntity(ally);
spawnHealParticles(world, ally);
}
}
}
if (instantHeal) {
// Instant heal - apply all healing now
if (healSelf) {
healEntity(caster);
spawnHealParticles(world, caster);
}
for (EntityLivingBase ally : getHealedAllies()) {
healEntity(ally);
spawnHealParticles(world, ally);
}
// Instant heal completes immediately
signalCompletion();
}
@@ -104,7 +113,7 @@ public class AbilityHeal extends Ability implements IAbilityHeal {
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote || instantHeal) return;
if ((world.isRemote && !isPreview()) || instantHeal) return;
// Heal over time - distribute heal across duration ticks
if (tick % 10 == 0) {
@@ -68,51 +68,53 @@ public class AbilityHeavyHit extends Ability implements IAbilityHeavyHit {
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
if (world.isRemote && !isPreview()) {
signalCompletion();
return;
}
// Calculate forward and right vectors from caster yaw
float yawRad = (float) Math.toRadians(caster.rotationYaw);
double forwardX = -Math.sin(yawRad);
double forwardZ = Math.cos(yawRad);
double rightX = forwardZ; // perpendicular right
double rightZ = -forwardX;
if (!isPreview()) {
// Calculate forward and right vectors from caster yaw
float yawRad = (float) Math.toRadians(caster.rotationYaw);
double forwardX = -Math.sin(yawRad);
double forwardZ = Math.cos(yawRad);
double rightX = forwardZ; // perpendicular right
double rightZ = -forwardX;
// Search area: AABB that encompasses the rectangle
float searchDist = Math.max(hitLength, hitWidth) + 1.0f;
@SuppressWarnings("unchecked")
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(
caster, caster.boundingBox.expand(searchDist, 2, searchDist));
// Search area: AABB that encompasses the rectangle
float searchDist = Math.max(hitLength, hitWidth) + 1.0f;
@SuppressWarnings("unchecked")
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(
caster, caster.boundingBox.expand(searchDist, 2, searchDist));
boolean anyHit = false;
for (Entity entity : entities) {
if (!(entity instanceof EntityLivingBase) || entity == caster) continue;
EntityLivingBase livingTarget = (EntityLivingBase) entity;
boolean anyHit = false;
for (Entity entity : entities) {
if (!(entity instanceof EntityLivingBase) || entity == caster) continue;
EntityLivingBase livingTarget = (EntityLivingBase) entity;
double dx = livingTarget.posX - caster.posX;
double dz = livingTarget.posZ - caster.posZ;
double dx = livingTarget.posX - caster.posX;
double dz = livingTarget.posZ - caster.posZ;
// Project onto forward direction (must be in front, within hitLength)
double forwardDist = dx * forwardX + dz * forwardZ;
if (forwardDist < 0 || forwardDist > hitLength) continue;
// Project onto forward direction (must be in front, within hitLength)
double forwardDist = dx * forwardX + dz * forwardZ;
if (forwardDist < 0 || forwardDist > hitLength) continue;
// Project onto right direction (must be within hitWidth to each side)
double sideDist = dx * rightX + dz * rightZ;
if (Math.abs(sideDist) > hitWidth) continue;
// Project onto right direction (must be within hitWidth to each side)
double sideDist = dx * rightX + dz * rightZ;
if (Math.abs(sideDist) > hitWidth) continue;
// Entity is within the rectangle - apply damage
boolean wasHit = applyAbilityDamage(caster, livingTarget, damage, knockback);
if (wasHit) {
applyEffects(livingTarget);
anyHit = true;
// Entity is within the rectangle - apply damage
boolean wasHit = applyAbilityDamage(caster, livingTarget, damage, knockback);
if (wasHit) {
applyEffects(livingTarget);
anyHit = true;
}
}
}
// Play hit sound even if nothing was hit (the attack still happens)
if (!anyHit) {
world.playSoundAtEntity(caster, "random.anvil_land", 0.5f, 1.2f);
// Play hit sound even if nothing was hit (the attack still happens)
if (!anyHit) {
world.playSoundAtEntity(caster, "random.anvil_land", 0.5f, 1.2f);
}
}
}
@@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.RotationMode;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.data.*;
import noppes.npcs.client.gui.builder.FieldDef;
@@ -12,7 +13,6 @@ import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityLaser;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
@@ -22,7 +22,6 @@ import noppes.npcs.api.ability.type.IAbilityLaserShot;
import java.util.Arrays;
import java.util.List;
import noppes.npcs.entity.EntityNPCInterface;
/**
* Laser Shot ability: Fast expanding thin line that pierces through targets.
@@ -40,7 +39,7 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
private final EnergyCombatData combatData = new EnergyCombatData(6.0f, 0.5f, 0.05f, false, 2.0f, 0.5f);
private final EnergyLightningData lightningData = new EnergyLightningData();
private final EnergyLifespanData lifespanData = new EnergyLifespanData(40.0f, 100);
private final EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.RIGHT_HAND);
private final EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.FRONT);
private final EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Transient state for laser entity (used for movement locking)
@@ -55,6 +54,8 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
this.cooldownTicks = 0;
this.windUpTicks = 15;
this.lockMovement = LockMovementType.WINDUP_AND_ACTIVE;
this.rotationMode = RotationMode.TRACK;
this.rotationPhase = LockMovementType.WINDUP;
this.telegraphType = TelegraphType.LINE;
this.showTelegraph = true;
// Default built-in animations
@@ -62,6 +63,11 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
this.activeAnimationName = "Ability_Laser_Active";
}
@Override
public boolean allowOverlap() {
return true;
}
@Override
public boolean isTargetingModeLocked() {
return false;
@@ -82,31 +88,55 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
return laserWidth * 2.0f; // Make telegraph slightly wider for visibility
}
/**
* Spawn laser entity.
* NPC: target is the aggro target — laser expands toward it.
* Player: target is null — laser expands in caster's look direction.
*/
private EntityAbilityLaser spawnLaserEntity(EntityLivingBase caster, EntityLivingBase target, World world) {
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchorData);
EntityAbilityLaser entity = new EntityAbilityLaser(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord,
laserWidth,
colorData, combatData, lightningData, lifespanData, trajectoryData,
expansionSpeed, lingerTicks
);
entity.setEffects(this.effects);
entity.setSourceAbility(this);
spawnAbilityEntity(world, entity);
return entity;
}
private void fireLaserEntity(EntityAbilityLaser laser, EntityLivingBase target) {
if (laser == null || laser.isDead) return;
laser.setLockVerticalDirection(true);
laser.startMoving(target);
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
if (tick == 1) {
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchorData);
laserEntity = new EntityAbilityLaser(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord,
laserWidth,
colorData, combatData, lightningData, lifespanData, trajectoryData,
expansionSpeed, lingerTicks
);
laserEntity.setupCharging(anchorData, windUpTicks);
laserEntity.setEffects(this.effects);
laserEntity.setSourceAbility(this);
world.spawnEntityInWorld(laserEntity);
laserEntity = spawnLaserEntity(caster, target, world);
if (isPreview()) {
laserEntity.setupPreview(caster, laserWidth, colorData, lightningData, expansionSpeed, lifespanData.maxDistance);
} else {
laserEntity.setupCharging(anchorData, windUpTicks);
}
}
}
@Override
public void onBurstRefire(EntityLivingBase caster, EntityLivingBase target, World world) {
laserEntity = spawnLaserEntity(caster, target, world);
fireLaserEntity(laserEntity, target);
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
if (world.isRemote && !isPreview()) {
signalCompletion();
return;
}
@@ -116,10 +146,7 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
return;
}
laserEntity.startMoving(target);
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
fireLaserEntity(laserEntity, target);
}
@Override
@@ -235,25 +262,10 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
public void setAnchorPoint(int point) { this.anchorData.anchorPoint = AnchorPoint.fromOrdinal(point); }
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
EntityAbilityLaser laser = new EntityAbilityLaser(npc.worldObj);
laser.setupPreview(npc, laserWidth, colorData, lightningData, expansionSpeed, lifespanData.maxDistance);
return laser;
}
@Override
public int getPreviewActiveDuration() {
public int getMaxPreviewDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 60) : 60;
}
@Override
public boolean spawnPreviewDuringWindup() {
return false; // Laser has no charging, spawns at active phase
}
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
@@ -282,6 +294,12 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
// Visual tab
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class, this::getAnchorPointEnum, this::setAnchorPointEnum)
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("ability.anchor.offsetX", this::getAnchorOffsetX, this::setAnchorOffsetX),
FieldDef.floatField("ability.anchor.offsetY", this::getAnchorOffsetY, this::setAnchorOffsetY)
).tab("ability.tab.visual"),
FieldDef.floatField("ability.anchor.offsetZ", this::getAnchorOffsetZ, this::setAnchorOffsetZ)
.tab("ability.tab.visual"),
FieldDef.section("ability.section.colors").tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor).tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled).tab("ability.tab.visual"),
@@ -12,7 +12,6 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityOrb;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
@@ -23,29 +22,38 @@ import noppes.npcs.api.ability.type.IAbilityOrb;
import java.util.Arrays;
import java.util.List;
import noppes.npcs.entity.EntityNPCInterface;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
/**
* Orb ability: Spawns a homing projectile sphere that tracks target.
* The EntityAbilityOrb handles all movement, collision, and damage logic.
* This ability just configures and spawns the orb entity.
* Orb ability: Spawns homing projectile sphere(s) that track target.
* Supports 1-8 projectiles with shared visuals and per-projectile anchor points.
*/
public class AbilityOrb extends Ability implements IAbilityOrb {
// Ability-specific properties
private static final int MAX_PROJECTILES = 8;
// Orb properties
private float orbSize = 1.0f;
// Data classes for energy properties
private final EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.RIGHT_HAND);
private final EnergyCombatData combatData = new EnergyCombatData();
private final EnergyDisplayData displayData = new EnergyDisplayData();
private final EnergyHomingData homingData = new EnergyHomingData();
private final EnergyLightningData lightningData = new EnergyLightningData();
private final EnergyLifespanData lifespanData = new EnergyLifespanData();
private final EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Projectile count and fire stagger
private int projectileCount = 1;
private int fireDelay = 0;
// Transient state for orb entity (used during windup charging)
private transient EntityAbilityOrb orbEntity = null;
// Shared visual data (all projectiles use these)
private EnergyDisplayData displayData = new EnergyDisplayData(0xFFFFFF, 0xFF0000, true, 0.4f, 0.5f, 0.0f);
private EnergyLightningData lightningData = new EnergyLightningData();
private EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Shared combat/movement data
private final EnergyCombatData combatData = new EnergyCombatData();
private final EnergyHomingData homingData = new EnergyHomingData();
private final EnergyLifespanData lifespanData = new EnergyLifespanData();
// Per-projectile data (anchor + optional color override)
private ProjectileData[] projectiles;
// Transient entity state
private transient EntityAbilityOrb[] orbEntities;
public AbilityOrb() {
this.typeId = "ability.cnpc.orb";
@@ -58,9 +66,100 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
this.lockMovement = LockMovementType.WINDUP;
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
// Default built-in animation
this.windUpAnimationName = "Ability_Orb_Windup";
this.activeAnimationName = "Ability_Orb_Active";
initProjectiles(1);
}
private void initProjectiles(int count) {
this.projectileCount = Math.max(1, Math.min(count, MAX_PROJECTILES));
this.projectiles = new ProjectileData[projectileCount];
for (int i = 0; i < projectileCount; i++) {
projectiles[i] = new ProjectileData(getDefaultAnchor(i));
}
}
private AnchorPoint getDefaultAnchor(int index) {
switch (index) {
case 0: return AnchorPoint.RIGHT_HAND;
case 1: return AnchorPoint.LEFT_HAND;
default: return AnchorPoint.FRONT;
}
}
public void setProjectileCount(int count) {
int newCount = Math.max(1, Math.min(count, MAX_PROJECTILES));
if (newCount == projectileCount) return;
ProjectileData[] oldProjectiles = projectiles;
initProjectiles(newCount);
// Preserve existing projectile data
if (oldProjectiles != null) {
int copyCount = Math.min(oldProjectiles.length, newCount);
for (int i = 0; i < copyCount; i++) {
if (oldProjectiles[i] != null) projectiles[i] = oldProjectiles[i];
}
}
}
public int getProjectileCount() {
return projectileCount;
}
public int getFireDelay() {
return fireDelay;
}
public void setFireDelay(int delay) {
this.fireDelay = Math.max(0, delay);
}
// Legacy compat
public int getDualFireDelay() { return fireDelay; }
public void setDualFireDelay(int delay) { setFireDelay(delay); }
@Override
public List<AbilityVariant> getVariants() {
return Arrays.asList(
new AbilityVariant("ability.variant.single", a -> {
a.setName("Orb");
}),
new AbilityVariant("ability.variant.dual", a -> {
AbilityOrb orb = (AbilityOrb) a;
a.setName("Dual Orb");
orb.setProjectileCount(2);
orb.setFireDelay(5);
a.setWindUpAnimationName("Ability_OrbDual_Windup");
a.setActiveAnimationName("Ability_OrbDual_Active");
}),
new AbilityVariant("ability.variant.barrage", a -> {
AbilityOrb orb = (AbilityOrb) a;
a.setName("Orb Barrage");
orb.setOrbSize(0.5f);
orb.setDamage(4.0f);
orb.setKnockback(0.0f);
orb.setKnockbackUp(0.0f);
a.setMaxRange(75.0f);
a.setBurstEnabled(true);
a.setBurstAmount(15);
a.setBurstDelay(10);
a.setBurstReplayAnimations(false);
a.setBurstOverlap(true);
a.setWindUpAnimationName("Ability_BeamDual_Windup");
a.setActiveAnimationName("Ability_BeamDual_Active");
})
);
}
@Override
public boolean allowOverlap() {
return true;
}
@Override
public boolean isReadyForBurstCompletion(int activeTick) {
return fireDelay <= 0 || activeTick >= fireDelay * (projectileCount - 1);
}
@Override
@@ -73,54 +172,119 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
signalCompletion();
return;
/**
* Create orb entities.
* NPC: target is the aggro target — orbs will home toward it.
* Player: target is null — orbs fire in caster's look direction.
*/
private EntityAbilityOrb[] createOrbEntities(EntityLivingBase caster, EntityLivingBase target, World world) {
EntityAbilityOrb[] entities = new EntityAbilityOrb[projectileCount];
for (int i = 0; i < projectileCount; i++) {
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, projectiles[i].anchor);
EnergyDisplayData resolved = projectiles[i].resolveDisplay(displayData);
entities[i] = new EntityAbilityOrb(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord, orbSize,
resolved, combatData, homingData, lightningData, lifespanData, trajectoryData);
entities[i].setEffects(this.effects);
entities[i].setSourceAbility(this);
}
// Start moving the orb that was spawned during windup
if (orbEntity != null && !orbEntity.isDead) {
orbEntity.startMoving(target);
if (projectileCount == 2 && entities[0] != null && entities[1] != null) {
entities[0].setSiblingEntityId(entities[1].getEntityId());
entities[1].setSiblingEntityId(entities[0].getEntityId());
}
return entities;
}
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
private void fireOrbEntity(EntityAbilityOrb orb, EntityLivingBase target) {
if (orb == null || orb.isDead) return;
if (isPreview()) {
orb.startPreviewFiring();
} else {
orb.startMoving(target);
}
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
// Spawn orb in charging mode on first tick of windup
if (tick == 1) {
// Create orb in charging mode - follows caster based on anchor point during windup
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchorData);
orbEntity = new EntityAbilityOrb(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord, orbSize,
displayData, combatData, homingData, lightningData, lifespanData, trajectoryData);
orbEntity.setupCharging(anchorData, windUpTicks);
orbEntities = createOrbEntities(caster, target, world);
for (int i = 0; i < projectileCount; i++) {
EnergyDisplayData resolved = projectiles[i].resolveDisplay(displayData);
if (isPreview()) {
orbEntities[i].setupPreview(caster, orbSize, resolved, lightningData, projectiles[i].anchor, windUpTicks);
} else {
orbEntities[i].setupCharging(projectiles[i].anchor, windUpTicks);
}
spawnAbilityEntity(world, orbEntities[i]);
}
}
}
orbEntity.setEffects(this.effects);
orbEntity.setSourceAbility(this);
world.spawnEntityInWorld(orbEntity);
@Override
public void onBurstRefire(EntityLivingBase caster, EntityLivingBase target, World world) {
orbEntities = createOrbEntities(caster, target, world);
for (EntityAbilityOrb orb : orbEntities) {
spawnAbilityEntity(world, orb);
}
for (EntityAbilityOrb orb : orbEntities) {
fireOrbEntity(orb, target);
}
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote && !isPreview()) {
signalCompletion();
return;
}
if (orbEntities == null) return;
// Fire first projectile immediately
fireOrbEntity(orbEntities[0], target);
// Fire remaining projectiles if no delay
if (fireDelay <= 0) {
for (int i = 1; i < projectileCount; i++) {
fireOrbEntity(orbEntities[i], target);
}
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Signal completion when entity dies
if (orbEntity == null || orbEntity.isDead) {
orbEntity = null;
if (orbEntities == null) {
signalCompletion();
return;
}
// Fire staggered projectiles
if (fireDelay > 0) {
for (int i = 1; i < projectileCount; i++) {
if (tick == fireDelay * i) {
fireOrbEntity(orbEntities[i], target);
}
}
}
// Check if all entities are dead
boolean allDead = true;
for (EntityAbilityOrb orb : orbEntities) {
if (orb != null && !orb.isDead) {
allDead = false;
break;
}
}
if (allDead) {
signalCompletion();
}
}
@Override
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
// Nothing to clean up - entity manages itself
}
@Override
@@ -130,20 +294,25 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
@Override
public void cleanup() {
// Despawn orb entity if still alive
if (orbEntity != null && !orbEntity.isDead) {
orbEntity.setDead();
if (orbEntities != null) {
for (int i = 0; i < orbEntities.length; i++) {
if (orbEntities[i] != null && !orbEntities[i].isDead) {
orbEntities[i].setDead();
}
orbEntities[i] = null;
}
}
orbEntity = null;
orbEntities = null;
}
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
// NPC: telegraph on aggro target position
// Player: no telegraph (orbs fire in look direction, no fixed position to mark)
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster) || target == null) {
return null;
}
// Create small circle telegraph at target position
Telegraph telegraph = Telegraph.circle(orbSize * 1.5f);
telegraph.setDurationTicks(windUpTicks);
telegraph.setColor(windUpColor);
@@ -151,7 +320,6 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
telegraph.setHeightOffset(telegraphHeightOffset);
// Position at target and follow target during windup
TelegraphInstance instance = new TelegraphInstance(telegraph, target.posX, target.posY, target.posZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
instance.setEntityIdToFollow(target.getEntityId());
@@ -167,307 +335,316 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("orbSize", orbSize);
anchorData.writeNBT(nbt);
combatData.writeNBT(nbt);
nbt.setInteger("projectileCount", projectileCount);
nbt.setInteger("fireDelay", fireDelay);
// Shared visual data
displayData.writeNBT(nbt);
homingData.writeNBT(nbt);
lightningData.writeNBT(nbt);
// Shared combat/movement data
combatData.writeNBT(nbt);
homingData.writeNBT(nbt);
lifespanData.writeNBT(nbt);
trajectoryData.writeNBT(nbt);
// Backward compat: old key was "orbSpeed"
// Per-projectile data
for (int i = 0; i < projectileCount; i++) {
NBTTagCompound projNbt = new NBTTagCompound();
projectiles[i].writeNBT(projNbt);
nbt.setTag("Projectile_" + i, projNbt);
}
// Backward compat write
nbt.setFloat("orbSpeed", homingData.speed);
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
this.orbSize = nbt.hasKey("orbSize") ? nbt.getFloat("orbSize") : 1.0f;
anchorData.readNBT(nbt);
int count = nbt.hasKey("projectileCount") ? nbt.getInteger("projectileCount") : 1;
initProjectiles(count);
// Read fireDelay with fallback to old dualFireDelay key
if (nbt.hasKey("fireDelay")) {
this.fireDelay = nbt.getInteger("fireDelay");
} else if (nbt.hasKey("dualFireDelay")) {
this.fireDelay = nbt.getInteger("dualFireDelay");
} else {
this.fireDelay = 0;
}
// Shared combat/movement data
combatData.readNBT(nbt);
displayData.readNBT(nbt);
homingData.readNBT(nbt);
lightningData.readNBT(nbt);
lifespanData.readNBT(nbt);
trajectoryData.readNBT(nbt);
// Backward compat: old key was "orbSpeed"
// Determine format and read accordingly
if (nbt.hasKey("Projectile_0")) {
NBTTagCompound proj0 = nbt.getCompoundTag("Projectile_0");
if (proj0.hasKey("colorOverride")) {
// NEW format: shared visuals at root + ProjectileData per projectile
displayData.readNBT(nbt);
lightningData.readNBT(nbt);
for (int i = 0; i < projectileCount; i++) {
if (nbt.hasKey("Projectile_" + i)) {
projectiles[i].readNBT(nbt.getCompoundTag("Projectile_" + i));
}
}
} else {
// OLD format: full per-projectile arrays (displayData, lightningData, etc. in each Projectile_i)
// Read primary visuals from Projectile_0
displayData.readNBT(proj0);
lightningData.readNBT(proj0);
projectiles[0].anchor.readNBT(proj0);
// Read remaining projectiles, set color override if colors differ
for (int i = 1; i < projectileCount; i++) {
if (nbt.hasKey("Projectile_" + i)) {
NBTTagCompound projNbt = nbt.getCompoundTag("Projectile_" + i);
projectiles[i].anchor.readNBT(projNbt);
// Check if this projectile had different colors
EnergyDisplayData tempDisplay = new EnergyDisplayData();
tempDisplay.readNBT(projNbt);
if (tempDisplay.innerColor != displayData.innerColor || tempDisplay.outerColor != displayData.outerColor) {
projectiles[i].colorOverride = true;
projectiles[i].innerColor = tempDisplay.innerColor;
projectiles[i].outerColor = tempDisplay.outerColor;
}
}
}
}
} else {
// LEGACY flat format: all data at root level
displayData.readNBT(nbt);
lightningData.readNBT(nbt);
projectiles[0].anchor.readNBT(nbt);
}
// Backward compat
if (nbt.hasKey("orbSpeed")) {
homingData.speed = nbt.getFloat("orbSpeed");
}
}
// Getters & Setters
public float getOrbSpeed() {
return homingData.speed;
// ═══════════════════════════════════════════════════════════════════
// API GETTERS & SETTERS
// ═══════════════════════════════════════════════════════════════════
public float getOrbSpeed() { return homingData.speed; }
public void setOrbSpeed(float speed) { homingData.speed = speed; }
public float getOrbSize() { return orbSize; }
public void setOrbSize(float size) { this.orbSize = size; }
public float getMaxDistance() { return lifespanData.maxDistance; }
public void setMaxDistance(float d) { lifespanData.maxDistance = d; }
public int getMaxLifetime() { return lifespanData.maxLifetime; }
public void setMaxLifetime(int t) { lifespanData.maxLifetime = t; }
public float getDamage() { return combatData.damage; }
public void setDamage(float d) { combatData.damage = d; }
public float getKnockback() { return combatData.knockback; }
public void setKnockback(float k) { combatData.knockback = k; }
public float getKnockbackUp() { return combatData.knockbackUp; }
public void setKnockbackUp(float k) { combatData.knockbackUp = k; }
public boolean isHoming() { return homingData.homing; }
public void setHoming(boolean h) { homingData.homing = h; }
public float getHomingStrength() { return homingData.homingStrength; }
public void setHomingStrength(float s) { homingData.homingStrength = s; }
public float getHomingRange() { return homingData.homingRange; }
public void setHomingRange(float r) { homingData.homingRange = r; }
public boolean isExplosive() { return combatData.explosive; }
public void setExplosive(boolean e) { combatData.explosive = e; }
public float getExplosionRadius() { return combatData.explosionRadius; }
public void setExplosionRadius(float r) { combatData.explosionRadius = r; }
public float getExplosionDamageFalloff() { return combatData.explosionDamageFalloff; }
public void setExplosionDamageFalloff(float f) { combatData.explosionDamageFalloff = f; }
// Shared display data (primary colors)
public int getInnerColor() { return displayData.innerColor; }
public void setInnerColor(int c) { displayData.innerColor = c; }
public int getOuterColor() { return displayData.outerColor; }
public void setOuterColor(int c) { displayData.outerColor = c; }
public float getOuterColorWidth() { return displayData.outerColorWidth; }
public void setOuterColorWidth(float w) { displayData.outerColorWidth = w; }
public float getOuterColorAlpha() { return displayData.outerColorAlpha; }
public void setOuterColorAlpha(float a) { displayData.outerColorAlpha = a; }
public boolean isOuterColorEnabled() { return displayData.outerColorEnabled; }
public void setOuterColorEnabled(boolean e) { displayData.outerColorEnabled = e; }
public float getRotationSpeed() { return displayData.rotationSpeed; }
public void setRotationSpeed(float s) { displayData.rotationSpeed = s; }
// Shared lightning data
public boolean hasLightningEffect() { return lightningData.lightningEffect; }
public void setLightningEffect(boolean e) { lightningData.lightningEffect = e; }
public float getLightningDensity() { return lightningData.lightningDensity; }
public void setLightningDensity(float d) { lightningData.lightningDensity = d; }
public float getLightningRadius() { return lightningData.lightningRadius; }
public void setLightningRadius(float r) { lightningData.lightningRadius = r; }
public int getLightningFadeTime() { return lightningData.lightningFadeTime; }
public void setLightningFadeTime(int t) { lightningData.lightningFadeTime = t; }
// Anchor - default to projectile 0
public AnchorPoint getAnchorPointEnum() { return projectiles[0].anchor.anchorPoint; }
public void setAnchorPointEnum(AnchorPoint p) { projectiles[0].anchor.anchorPoint = p; }
public float getAnchorOffsetX() { return projectiles[0].anchor.anchorOffsetX; }
public void setAnchorOffsetX(float x) { projectiles[0].anchor.anchorOffsetX = x; }
public float getAnchorOffsetY() { return projectiles[0].anchor.anchorOffsetY; }
public void setAnchorOffsetY(float y) { projectiles[0].anchor.anchorOffsetY = y; }
public float getAnchorOffsetZ() { return projectiles[0].anchor.anchorOffsetZ; }
public void setAnchorOffsetZ(float z) { projectiles[0].anchor.anchorOffsetZ = z; }
public int getAnchorPoint() { return projectiles[0].anchor.anchorPoint.ordinal(); }
@Override
public void setAnchorPoint(int point) { projectiles[0].anchor.anchorPoint = AnchorPoint.fromOrdinal(point); }
// Indexed API methods
public int getInnerColor(int index) {
ProjectileData p = projectiles[clampIndex(index)];
return p.colorOverride ? p.innerColor : displayData.innerColor;
}
public void setInnerColor(int index, int color) {
ProjectileData p = projectiles[clampIndex(index)];
p.colorOverride = true;
p.innerColor = color;
}
public void setOrbSpeed(float orbSpeed) {
homingData.speed = orbSpeed;
public int getOuterColor(int index) {
ProjectileData p = projectiles[clampIndex(index)];
return p.colorOverride ? p.outerColor : displayData.outerColor;
}
public void setOuterColor(int index, int color) {
ProjectileData p = projectiles[clampIndex(index)];
p.colorOverride = true;
p.outerColor = color;
}
public float getOrbSize() {
return orbSize;
}
public int getAnchorPoint(int index) { return projectiles[clampIndex(index)].anchor.anchorPoint.ordinal(); }
public void setAnchorPoint(int index, int point) { projectiles[clampIndex(index)].anchor.anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorOffsetX(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetX = offset; }
public void setAnchorOffsetY(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetY = offset; }
public void setAnchorOffsetZ(int index, float offset) { projectiles[clampIndex(index)].anchor.anchorOffsetZ = offset; }
public void setOrbSize(float orbSize) {
this.orbSize = orbSize;
}
public float getMaxDistance() {
return lifespanData.maxDistance;
}
public void setMaxDistance(float maxDistance) {
lifespanData.maxDistance = maxDistance;
}
public int getMaxLifetime() {
return lifespanData.maxLifetime;
}
public void setMaxLifetime(int maxLifetime) {
lifespanData.maxLifetime = maxLifetime;
}
public float getDamage() {
return combatData.damage;
}
public void setDamage(float damage) {
combatData.damage = damage;
}
public float getKnockback() {
return combatData.knockback;
}
public void setKnockback(float knockback) {
combatData.knockback = knockback;
}
public float getKnockbackUp() {
return combatData.knockbackUp;
}
public void setKnockbackUp(float knockbackUp) {
combatData.knockbackUp = knockbackUp;
}
public boolean isHoming() {
return homingData.homing;
}
public void setHoming(boolean homing) {
homingData.homing = homing;
}
public float getHomingStrength() {
return homingData.homingStrength;
}
public void setHomingStrength(float homingStrength) {
homingData.homingStrength = homingStrength;
}
public float getHomingRange() {
return homingData.homingRange;
}
public void setHomingRange(float homingRange) {
homingData.homingRange = homingRange;
}
public boolean isExplosive() {
return combatData.explosive;
}
public void setExplosive(boolean explosive) {
combatData.explosive = explosive;
}
public float getExplosionRadius() {
return combatData.explosionRadius;
}
public void setExplosionRadius(float explosionRadius) {
combatData.explosionRadius = explosionRadius;
}
public float getExplosionDamageFalloff() {
return combatData.explosionDamageFalloff;
}
public void setExplosionDamageFalloff(float explosionDamageFalloff) {
combatData.explosionDamageFalloff = explosionDamageFalloff;
}
public int getInnerColor() {
return displayData.innerColor;
}
public void setInnerColor(int innerColor) {
displayData.innerColor = innerColor;
}
public int getOuterColor() {
return displayData.outerColor;
}
public void setOuterColor(int outerColor) {
displayData.outerColor = outerColor;
}
public float getOuterColorWidth() {
return displayData.outerColorWidth;
}
public void setOuterColorWidth(float outerColorWidth) {
displayData.outerColorWidth = outerColorWidth;
}
public float getOuterColorAlpha() {
return displayData.outerColorAlpha;
}
public void setOuterColorAlpha(float outerColorAlpha) {
displayData.outerColorAlpha = outerColorAlpha;
}
public boolean isOuterColorEnabled() {
return displayData.outerColorEnabled;
}
public void setOuterColorEnabled(boolean outerColorEnabled) {
displayData.outerColorEnabled = outerColorEnabled;
}
public float getRotationSpeed() {
return displayData.rotationSpeed;
}
public void setRotationSpeed(float rotationSpeed) {
displayData.rotationSpeed = rotationSpeed;
}
public boolean hasLightningEffect() {
return lightningData.lightningEffect;
}
public void setLightningEffect(boolean lightningEffect) {
lightningData.lightningEffect = lightningEffect;
}
public float getLightningDensity() {
return lightningData.lightningDensity;
}
public void setLightningDensity(float lightningDensity) {
lightningData.lightningDensity = lightningDensity;
}
public float getLightningRadius() {
return lightningData.lightningRadius;
}
public void setLightningRadius(float lightningRadius) {
lightningData.lightningRadius = lightningRadius;
}
public int getLightningFadeTime() {
return lightningData.lightningFadeTime;
}
public void setLightningFadeTime(int lightningFadeTime) {
lightningData.lightningFadeTime = lightningFadeTime;
}
public AnchorPoint getAnchorPointEnum() { return anchorData.anchorPoint; }
public float getAnchorOffsetX() { return anchorData.anchorOffsetX; }
public float getAnchorOffsetY() { return anchorData.anchorOffsetY; }
public float getAnchorOffsetZ() { return anchorData.anchorOffsetZ; }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { this.anchorData.anchorPoint = anchorPoint; }
public void setAnchorOffsetX(float x) { this.anchorData.anchorOffsetX = x; }
public void setAnchorOffsetY(float y) { this.anchorData.anchorOffsetY = y; }
public void setAnchorOffsetZ(float z) { this.anchorData.anchorOffsetZ = z; }
public int getAnchorPoint() {
return anchorData.anchorPoint.ordinal();
private int clampIndex(int index) {
return Math.max(0, Math.min(index, projectileCount - 1));
}
@Override
public void setAnchorPoint(int point) {
this.anchorData.anchorPoint = AnchorPoint.fromOrdinal(point);
}
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
EntityAbilityOrb orb = new EntityAbilityOrb(npc.worldObj);
orb.setupPreview(npc, orbSize, displayData, lightningData, anchorData, windUpTicks);
return orb;
}
@Override
public int getPreviewActiveDuration() {
public int getMaxPreviewDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 100) : 100;
}
// ═══════════════════════════════════════════════════════════════════
// GUI FIELD DEFINITIONS
// ═══════════════════════════════════════════════════════════════════
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Type tab
FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getOrbSpeed, this::setOrbSpeed)
),
FieldDef.row(
FieldDef.floatField("stats.size", this::getOrbSize, this::setOrbSize),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback)
),
FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
),
FieldDef.section("ability.section.homing"),
FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming).hover("ability.hover.homing"),
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength).visibleWhen(this::isHoming),
FieldDef.section("ability.section.explosive"),
FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive).hover("ability.hover.explosive"),
FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius).visibleWhen(this::isExplosive),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects),
// Visual tab
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class, this::getAnchorPointEnum, this::setAnchorPointEnum)
.tab("ability.tab.visual"),
FieldDef.section("ability.section.colors").tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor).tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled).tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor", this::getOuterColor, this::setOuterColor)
.tab("ability.tab.visual").visibleWhen(this::isOuterColorEnabled),
FieldDef.row(
FieldDef.floatField("ability.outerWidth", this::getOuterColorWidth, this::setOuterColorWidth)
.visibleWhen(this::isOuterColorEnabled),
FieldDef.floatField("ability.outerAlpha", this::getOuterColorAlpha, this::setOuterColorAlpha)
.range(0, 1).visibleWhen(this::isOuterColorEnabled)
).tab("ability.tab.visual"),
FieldDef.section("ability.section.effects").tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed).tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning", this::hasLightningEffect, this::setLightningEffect).tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density", this::getLightningDensity, this::setLightningDensity)
.visibleWhen(this::hasLightningEffect).range(0.01f, 100f),
FieldDef.floatField("gui.radius", this::getLightningRadius, this::setLightningRadius)
.range(0.1f, 100f).visibleWhen(this::hasLightningEffect)
).tab("ability.tab.visual")
// Type tab - projectile count and fire delay
defs.add(FieldDef.row(
FieldDef.intField("ability.projectileCount", this::getProjectileCount, this::setProjectileCount).range(1, MAX_PROJECTILES),
FieldDef.intField("ability.fireDelay", this::getFireDelay, this::setFireDelay)
.range(0, 200).visibleWhen(() -> projectileCount > 1)
));
// Type tab - orb properties
defs.add(FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getOrbSpeed, this::setOrbSpeed)
));
defs.add(FieldDef.row(
FieldDef.floatField("stats.size", this::getOrbSize, this::setOrbSize),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback)
));
defs.add(FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
));
defs.add(FieldDef.section("ability.section.homing"));
defs.add(FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming).hover("ability.hover.homing"));
defs.add(FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength).visibleWhen(this::isHoming));
defs.add(FieldDef.section("ability.section.explosive"));
defs.add(FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive).hover("ability.hover.explosive"));
defs.add(FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius).visibleWhen(this::isExplosive));
defs.add(AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects));
// Visual tab - shared primary colors
defs.add(FieldDef.section("ability.section.colors").tab("ability.tab.visual"));
defs.add(FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor)
.tab("ability.tab.visual"));
defs.add(FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled)
.tab("ability.tab.visual"));
defs.add(FieldDef.colorSubGui("ability.outerColor", this::getOuterColor, this::setOuterColor)
.tab("ability.tab.visual").visibleWhen(this::isOuterColorEnabled));
defs.add(FieldDef.row(
FieldDef.floatField("ability.outerWidth", this::getOuterColorWidth, this::setOuterColorWidth)
.visibleWhen(this::isOuterColorEnabled),
FieldDef.floatField("ability.outerAlpha", this::getOuterColorAlpha, this::setOuterColorAlpha)
.range(0, 1).visibleWhen(this::isOuterColorEnabled)
).tab("ability.tab.visual"));
// Visual tab - shared effects
defs.add(FieldDef.section("ability.section.effects").tab("ability.tab.visual"));
defs.add(FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed)
.tab("ability.tab.visual"));
defs.add(FieldDef.boolField("ability.lightning", this::hasLightningEffect, this::setLightningEffect)
.tab("ability.tab.visual"));
defs.add(FieldDef.row(
FieldDef.floatField("gui.density", this::getLightningDensity, this::setLightningDensity)
.visibleWhen(this::hasLightningEffect).range(0.01f, 100f),
FieldDef.floatField("gui.radius", this::getLightningRadius, this::setLightningRadius)
.range(0.1f, 100f).visibleWhen(this::hasLightningEffect)
).tab("ability.tab.visual"));
// Visual tab - per-projectile sections
for (int i = 0; i < MAX_PROJECTILES; i++) {
final int idx = i;
String sectionKey = "ability.section.projectile" + (i + 1);
defs.add(FieldDef.section(sectionKey).tab("ability.tab.visual")
.visibleWhen(() -> idx < projectileCount));
// Anchor point
defs.add(FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> projectiles[idx].anchor.anchorPoint, v -> projectiles[idx].anchor.anchorPoint = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
defs.add(FieldDef.row(
FieldDef.floatField("ability.anchor.offsetX", () -> projectiles[idx].anchor.anchorOffsetX, v -> projectiles[idx].anchor.anchorOffsetX = v),
FieldDef.floatField("ability.anchor.offsetY", () -> projectiles[idx].anchor.anchorOffsetY, v -> projectiles[idx].anchor.anchorOffsetY = v)
).tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
defs.add(FieldDef.floatField("ability.anchor.offsetZ", () -> projectiles[idx].anchor.anchorOffsetZ, v -> projectiles[idx].anchor.anchorOffsetZ = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount));
// Color override (only when multiple projectiles)
defs.add(FieldDef.boolField("ability.colorOverride", () -> projectiles[idx].colorOverride, v -> projectiles[idx].colorOverride = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1));
defs.add(FieldDef.colorSubGui("ability.innerColor", () -> projectiles[idx].innerColor, v -> projectiles[idx].innerColor = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1 && projectiles[idx].colorOverride));
defs.add(FieldDef.colorSubGui("ability.outerColor", () -> projectiles[idx].outerColor, v -> projectiles[idx].outerColor = v)
.tab("ability.tab.visual").visibleWhen(() -> idx < projectileCount && projectileCount > 1 && projectiles[idx].colorOverride));
}
}
}
@@ -1,614 +0,0 @@
package kamkeel.npcs.controllers.data.ability.type;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.data.*;
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityOrb;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.client.gui.builder.FieldDef;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.ValueUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class AbilityOrbBarrage extends Ability {
// Ability-specific properties
private float orbSize = 0.5f;
private int orbAmount = 16;
private int firingSpeed = 2;
private boolean dualCharging = true;
// Data classes for energy properties
private final EnergyDisplayData colorData = new EnergyDisplayData();
private final EnergyCombatData combatData = new EnergyCombatData(4.0f, 0.0f, 0.0f, false, 1.5f, 0.5f);
private final EnergyHomingData homingData = new EnergyHomingData();
private final EnergyLightningData lightningData = new EnergyLightningData();
private final EnergyLifespanData lifespanData = new EnergyLifespanData();
private final EnergyAnchorData[] anchorData = new EnergyAnchorData[]{
new EnergyAnchorData(AnchorPoint.RIGHT_HAND), new EnergyAnchorData(AnchorPoint.LEFT_HAND)
};
private final EnergyTrajectoryData trajectoryData = new EnergyTrajectoryData();
// Array to store entities
private transient List<EntityAbilityOrb> orbEntities = new ArrayList<>();
private transient EntityAbilityOrb[] chargingEntities = null;
// Field to keep track of the currently firing orb
private int currentOrb = 0;
public AbilityOrbBarrage() {
this.typeId = "ability.cnpc.orb_barrage";
this.name = "Orb Barrage";
this.targetingMode = TargetingMode.AGGRO_TARGET;
this.maxRange = 75.0f;
this.minRange = 5.0f;
this.cooldownTicks = 0;
this.windUpTicks = 30;
this.lockMovement = LockMovementType.WINDUP;
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
// Default built-in animation
this.windUpAnimationName = "Ability_BeamDual_Windup";
this.activeAnimationName = "Ability_BeamDual_Active";
}
// @Override
// @SideOnly(Side.CLIENT)
// public SubGuiAbilityConfig createConfigGui(IAbilityConfigCallback callback) {
// return new SubGuiAbilityOrbBarrage(this, callback);
// }
@Override
public boolean isTargetingModeLocked() {
return true;
}
@Override
public TargetingMode[] getAllowedTargetingModes() {
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
signalCompletion();
return;
}
for (int i = 0; i < chargingEntities.length; i++) {
EntityAbilityOrb orbEntity = chargingEntities[i];
if (orbEntity != null && !orbEntity.isDead) {
orbEntity.setDead();
}
chargingEntities[i] = null;
}
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
// Spawn orb in charging mode on first tick of windup
if (tick == 1) {
// Create orb in charging mode - follows caster based on anchor point during windup
if (dualCharging) {
chargingEntities = new EntityAbilityOrb[2];
} else {
chargingEntities = new EntityAbilityOrb[1];
}
for (int i = 0; i < chargingEntities.length; i++) {
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchorData[i]);
EntityAbilityOrb orbEntity = new EntityAbilityOrb(
world, caster, target,
spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord, orbSize,
colorData, combatData, homingData, lightningData, lifespanData, trajectoryData
);
orbEntity.setupCharging(anchorData[i], windUpTicks);
orbEntity.setSourceAbility(this);
chargingEntities[i] = orbEntity;
world.spawnEntityInWorld(orbEntity);
}
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (!orbEntities.isEmpty()) {
boolean allDead = true;
for (EntityAbilityOrb orbEntity : orbEntities) {
if (orbEntity != null && !orbEntity.isDead) {
allDead = false;
break;
}
}
if (allDead && currentOrb >= orbAmount) {
signalCompletion();
return;
}
}
if (currentOrb >= orbAmount) {
return;
}
int ticksPerOrb = Math.max(1, 20 / firingSpeed);
if (tick % ticksPerOrb != 0) {
return;
}
EnergyAnchorData anchor;
if (dualCharging) {
anchor = anchorData[currentOrb % 2];
} else {
anchor = anchorData[0];
}
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchor);
EntityAbilityOrb orb = new EntityAbilityOrb(
world, caster, target, spawnPos.xCoord, spawnPos.yCoord, spawnPos.zCoord,
orbSize, colorData, combatData, homingData, lightningData, lifespanData, trajectoryData
);
orb.setSourceAbility(this);
world.spawnEntityInWorld(orb);
orbEntities.add(orb);
currentOrb++;
}
@Override
public boolean canInterrupt(DamageSource source) {
// Can be interrupted if the caster is hit when the beam is moving
if (!interruptible) {
return false;
}
// Only direct physical hits can interrupt, not magic, fire, or other indirect damage
if (source == null) {
return false;
}
// Reject indirect damage types
if (source.isMagicDamage() || source.isFireDamage() || source.isExplosion()) {
return false;
}
// Reject damage without a direct attacker entity
if (source.getEntity() == null) {
return false;
}
// Direct hit from an entity - can interrupt
return true;
}
@Override
public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {
cleanup();
}
@Override
public void cleanup() {
currentOrb = 0;
if (chargingEntities != null) {
for (int i = 0; i < chargingEntities.length; i++) {
if (chargingEntities[i] != null && !chargingEntities[i].isDead) {
chargingEntities[i].setDead();
}
chargingEntities[i] = null;
}
chargingEntities = null;
}
if (orbEntities != null && !orbEntities.isEmpty()) {
for (EntityAbilityOrb orbEntity : orbEntities) {
if (orbEntity != null && !orbEntity.isDead) {
orbEntity.setDead();
}
}
orbEntities.clear();
}
}
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
return null;
}
// Create small circle telegraph at target position
Telegraph telegraph = Telegraph.circle(orbSize * 1.5f);
telegraph.setDurationTicks(windUpTicks);
telegraph.setColor(windUpColor);
telegraph.setWarningColor(activeColor);
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
telegraph.setHeightOffset(telegraphHeightOffset);
// Position at target and follow target during windup
TelegraphInstance instance = new TelegraphInstance(telegraph, target.posX, target.posY, target.posZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
instance.setEntityIdToFollow(target.getEntityId());
return instance;
}
@Override
public float getTelegraphRadius() {
return orbSize * 1.5f;
}
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("orbSize", orbSize);
nbt.setInteger("orbAmount", orbAmount);
nbt.setInteger("firingSpeed", firingSpeed);
nbt.setBoolean("dualCharging", dualCharging);
colorData.writeNBT(nbt);
combatData.writeNBT(nbt);
homingData.writeNBT(nbt);
lightningData.writeNBT(nbt);
lifespanData.writeNBT(nbt);
trajectoryData.writeNBT(nbt);
for (int i = 0; i < anchorData.length; i++) {
NBTTagCompound comp = new NBTTagCompound();
anchorData[i].writeNBT(comp);
nbt.setTag("Anchor_" + i, comp);
}
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
this.orbSize = nbt.hasKey("orbSize") ? nbt.getFloat("orbSize") : 1.0f;
this.orbAmount = nbt.hasKey("orbAmount") ? nbt.getInteger("orbAmount") : 16;
this.firingSpeed = nbt.hasKey("firingSpeed") ? nbt.getInteger("firingSpeed") : 2;
this.dualCharging = !nbt.hasKey("dualCharging") || nbt.getBoolean("dualCharging");
colorData.readNBT(nbt);
combatData.readNBT(nbt);
homingData.readNBT(nbt);
lightningData.readNBT(nbt);
lifespanData.readNBT(nbt);
trajectoryData.readNBT(nbt);
for (int i = 0; i < anchorData.length; i++) {
if (nbt.hasKey("Anchor_" + i, Constants.NBT.TAG_COMPOUND)) {
anchorData[i].readNBT(nbt.getCompoundTag("Anchor_" + i));
} else {
anchorData[i] = new EnergyAnchorData(i == 0 ? AnchorPoint.RIGHT_HAND : AnchorPoint.LEFT_HAND);
}
}
}
// Getters & Setters
public float getOrbSpeed() {
return homingData.speed;
}
public void setOrbSpeed(float orbSpeed) {
homingData.speed = orbSpeed;
}
public float getOrbSize() {
return orbSize;
}
public void setOrbSize(float orbSize) {
this.orbSize = orbSize;
}
public int getOrbAmount() { return orbAmount; }
public void setOrbAmount(int orbAmount) { this.orbAmount = orbAmount; }
public int getFiringSpeed() { return firingSpeed; }
public void setFiringSpeed(int firingSpeed) { this.firingSpeed = firingSpeed; }
public boolean isDualCharging() { return dualCharging; }
public void setDualCharging(boolean dualCharging) { this.dualCharging = dualCharging; }
public float getMaxDistance() {
return lifespanData.maxDistance;
}
public void setMaxDistance(float maxDistance) {
lifespanData.maxDistance = maxDistance;
}
public int getMaxLifetime() {
return lifespanData.maxLifetime;
}
public void setMaxLifetime(int maxLifetime) {
lifespanData.maxLifetime = maxLifetime;
}
public float getDamage() {
return combatData.damage;
}
public void setDamage(float damage) {
combatData.damage = damage;
}
public float getKnockback() {
return combatData.knockback;
}
public void setKnockback(float knockback) {
combatData.knockback = knockback;
}
public float getKnockbackUp() {
return combatData.knockbackUp;
}
public void setKnockbackUp(float knockbackUp) {
combatData.knockbackUp = knockbackUp;
}
public boolean isHoming() {
return homingData.homing;
}
public void setHoming(boolean homing) {
homingData.homing = homing;
}
public float getHomingStrength() {
return homingData.homingStrength;
}
public void setHomingStrength(float homingStrength) {
homingData.homingStrength = homingStrength;
}
public float getHomingRange() {
return homingData.homingRange;
}
public void setHomingRange(float homingRange) {
homingData.homingRange = homingRange;
}
public boolean isExplosive() {
return combatData.explosive;
}
public void setExplosive(boolean explosive) {
combatData.explosive = explosive;
}
public float getExplosionRadius() {
return combatData.explosionRadius;
}
public void setExplosionRadius(float explosionRadius) {
combatData.explosionRadius = explosionRadius;
}
public float getExplosionDamageFalloff() {
return combatData.explosionDamageFalloff;
}
public void setExplosionDamageFalloff(float explosionDamageFalloff) {
combatData.explosionDamageFalloff = explosionDamageFalloff;
}
public int getInnerColor() {
return colorData.innerColor;
}
public void setInnerColor(int innerColor) {
colorData.innerColor = innerColor;
}
public int getOuterColor() {
return colorData.outerColor;
}
public void setOuterColor(int outerColor) {
colorData.outerColor = outerColor;
}
public float getOuterColorWidth() {
return colorData.outerColorWidth;
}
public void setOuterColorWidth(float outerColorWidth) {
colorData.outerColorWidth = outerColorWidth;
}
public float getOuterColorAlpha() {
return colorData.outerColorAlpha;
}
public void setOuterColorAlpha(float outerColorAlpha) {
colorData.outerColorAlpha = outerColorAlpha;
}
public boolean isOuterColorEnabled() {
return colorData.outerColorEnabled;
}
public void setOuterColorEnabled(boolean outerColorEnabled) {
colorData.outerColorEnabled = outerColorEnabled;
}
public float getRotationSpeed() {
return colorData.rotationSpeed;
}
public void setRotationSpeed(float rotationSpeed) {
colorData.rotationSpeed = rotationSpeed;
}
public boolean hasLightningEffect() {
return lightningData.lightningEffect;
}
public void setLightningEffect(boolean lightningEffect) {
lightningData.lightningEffect = lightningEffect;
}
public float getLightningDensity() {
return lightningData.lightningDensity;
}
public void setLightningDensity(float lightningDensity) {
lightningData.lightningDensity = lightningDensity;
}
public float getLightningRadius() {
return lightningData.lightningRadius;
}
public void setLightningRadius(float lightningRadius) {
lightningData.lightningRadius = lightningRadius;
}
public int getLightningFadeTime() {
return lightningData.lightningFadeTime;
}
public void setLightningFadeTime(int lightningFadeTime) {
lightningData.lightningFadeTime = lightningFadeTime;
}
private EnergyAnchorData getAnchorData(int orb) {
orb = ValueUtil.clamp(orb, 0, 1);
return anchorData[orb];
}
public AnchorPoint getAnchorPointEnum(int orb) { return getAnchorData(orb).anchorPoint; }
public void setAnchorPointEnum(int orb, AnchorPoint anchorPoint) { getAnchorData(orb).anchorPoint = anchorPoint; }
public float getAnchorOffsetX(int orb) { return getAnchorData(orb).anchorOffsetX; }
public void setAnchorOffsetX(int orb, float x) { getAnchorData(orb).anchorOffsetX = x; }
public float getAnchorOffsetY(int orb) { return getAnchorData(orb).anchorOffsetY; }
public void setAnchorOffsetY(int orb, float y) { getAnchorData(orb).anchorOffsetY = y; }
public float getAnchorOffsetZ(int orb) { return getAnchorData(orb).anchorOffsetZ; }
public void setAnchorOffsetZ(int orb, float z) { getAnchorData(orb).anchorOffsetZ = z; }
public AnchorPoint getAnchorPointEnum() { return getAnchorPointEnum(0); }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { setAnchorPointEnum(0, anchorPoint); }
public float getAnchorOffsetX() { return getAnchorOffsetX(0); }
public void setAnchorOffsetX(float x) { setAnchorOffsetX(0, x); }
public float getAnchorOffsetY() { return getAnchorOffsetY(0); }
public void setAnchorOffsetY(float y) { setAnchorOffsetY(0, y); }
public float getAnchorOffsetZ() { return getAnchorOffsetZ(0); }
public void setAnchorOffsetZ(float z) { setAnchorOffsetZ(0, z); }
//@Override
public int getAnchorPoint(int orb) { return getAnchorData(orb).anchorPoint.ordinal(); }
public int getAnchorPoint() { return getAnchorData(0).anchorPoint.ordinal(); }
//@Override
public void setAnchorPoint(int orb, int point) { getAnchorData(orb).anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorPoint(int point) { getAnchorData(0).anchorPoint = AnchorPoint.fromOrdinal(point); }
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
EntityAbilityOrb orb = new EntityAbilityOrb(npc.worldObj);
orb.setupPreview(npc, orbSize, colorData, lightningData, anchorData[0], windUpTicks);
return orb;
}
@Override
public int getPreviewActiveDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 100) : 100;
}
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Type tab
FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getOrbSpeed, this::setOrbSpeed)
),
FieldDef.row(
FieldDef.floatField("stats.size", this::getOrbSize, this::setOrbSize),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback)
),
FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
),
FieldDef.section("ability.section.barrage"),
FieldDef.row(
FieldDef.intField("ability.amount", this::getOrbAmount, this::setOrbAmount),
FieldDef.intField("ability.firingSpeed", this::getFiringSpeed, this::setFiringSpeed)
),
FieldDef.boolField("ability.dualCharge", this::isDualCharging, this::setDualCharging),
FieldDef.section("ability.section.homing"),
FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming).hover("ability.hover.homing"),
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength).visibleWhen(this::isHoming),
FieldDef.section("ability.section.explosive"),
FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive).hover("ability.hover.explosive"),
FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius).visibleWhen(this::isExplosive),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects),
// Visual tab
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class, this::getAnchorPointEnum, this::setAnchorPointEnum)
.tab("ability.tab.visual"),
FieldDef.section("ability.section.colors").tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor", this::getInnerColor, this::setInnerColor).tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled", this::isOuterColorEnabled, this::setOuterColorEnabled).tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor", this::getOuterColor, this::setOuterColor)
.tab("ability.tab.visual").visibleWhen(this::isOuterColorEnabled),
FieldDef.row(
FieldDef.floatField("ability.outerWidth", this::getOuterColorWidth, this::setOuterColorWidth)
.visibleWhen(this::isOuterColorEnabled),
FieldDef.floatField("ability.outerAlpha", this::getOuterColorAlpha, this::setOuterColorAlpha)
.range(0, 1).visibleWhen(this::isOuterColorEnabled)
).tab("ability.tab.visual"),
FieldDef.section("ability.section.effects").tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed).tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning", this::hasLightningEffect, this::setLightningEffect).tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density", this::getLightningDensity, this::setLightningDensity)
.range(0.01f, 100f).visibleWhen(this::hasLightningEffect),
FieldDef.floatField("gui.radius", this::getLightningRadius, this::setLightningRadius)
.range(0.1f, 100f).visibleWhen(this::hasLightningEffect)
).tab("ability.tab.visual")
));
}
}
@@ -1,586 +0,0 @@
package kamkeel.npcs.controllers.data.ability.type;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.data.*;
import noppes.npcs.client.gui.builder.FieldDef;
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import kamkeel.npcs.entity.EntityAbilityOrb;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.ValueUtil;
import java.util.Arrays;
import java.util.List;
public class AbilityOrbDual extends Ability {
// Ability-specific properties
private float orbSize = 1.0f;
private boolean dualFire= true;
private int dualFireDelay = 5;
// Data classes for energy properties
public final EnergyDisplayData[] displayData = new EnergyDisplayData[]{
new EnergyDisplayData(), new EnergyDisplayData()
};
public final EnergyCombatData combatData = new EnergyCombatData();
public final EnergyHomingData homingData = new EnergyHomingData();
public final EnergyLightningData[] lightningData = new EnergyLightningData[]{
new EnergyLightningData(), new EnergyLightningData()
};
public final EnergyLifespanData lifespanData = new EnergyLifespanData();
private final EnergyAnchorData[] anchorData = new EnergyAnchorData[]{
new EnergyAnchorData(AnchorPoint.RIGHT_HAND), new EnergyAnchorData(AnchorPoint.LEFT_HAND)
};
private EnergyTrajectoryData[] trajectoryData = new EnergyTrajectoryData[]{
new EnergyTrajectoryData(), new EnergyTrajectoryData()
};
// Transient state for orb entity (used during windup charging)
private transient EntityAbilityOrb orbEntity = null;
private transient EntityAbilityOrb orbEntity2 = null;
public AbilityOrbDual() {
this.typeId = "ability.cnpc.orb_dual";
this.name = "Orb Dual";
this.targetingMode = TargetingMode.AGGRO_TARGET;
this.maxRange = 25.0f;
this.minRange = 5.0f;
this.cooldownTicks = 0;
this.windUpTicks = 30;
this.lockMovement = LockMovementType.WINDUP;
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
// Default built-in animation
this.windUpAnimationName = "Ability_OrbDual_Windup";
this.activeAnimationName = "Ability_OrbDual_Active";
}
@Override
public boolean isTargetingModeLocked() {
return true;
}
@Override
public TargetingMode[] getAllowedTargetingModes() {
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
signalCompletion();
return;
}
// Start moving the orb that was spawned during windup
if (orbEntity != null && !orbEntity.isDead) {
orbEntity.startMoving(target);
}
if (dualFire) {
if (orbEntity2 != null && !orbEntity2.isDead && dualFireDelay <= 0) {
orbEntity2.startMoving(target);
}
} else if (orbEntity2 != null) {
orbEntity2.setDead();
}
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
}
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (world.isRemote) return;
// Spawn orb in charging mode on first tick of windup
if (tick == 1) {
// Create orb in charging mode - follows caster based on anchor point during windup
Vec3 spawnPos1 = AnchorPointHelper.calculateAnchorPosition(caster, anchorData[0]);
orbEntity = new EntityAbilityOrb(
world, caster, target,
spawnPos1.xCoord, spawnPos1.yCoord, spawnPos1.zCoord, orbSize,
displayData[0], combatData, homingData, lightningData[0], lifespanData, trajectoryData[0]);
Vec3 spawnPos2 = AnchorPointHelper.calculateAnchorPosition(caster, anchorData[1]);
orbEntity2 = new EntityAbilityOrb(
world, caster, target,
spawnPos2.xCoord, spawnPos2.yCoord, spawnPos2.zCoord, orbSize,
displayData[1], combatData, homingData, lightningData[1], lifespanData, trajectoryData[1]);
orbEntity.setSiblingEntityId(orbEntity2.getEntityId());
orbEntity2.setSiblingEntityId(orbEntity.getEntityId());
orbEntity.setupCharging(anchorData[0], windUpTicks);
orbEntity2.setupCharging(anchorData[1], windUpTicks);
orbEntity.setEffects(this.effects);
if (dualFire) {
orbEntity2.setEffects(this.effects);
}
orbEntity.setSourceAbility(this);
orbEntity2.setSourceAbility(this);
world.spawnEntityInWorld(orbEntity);
world.spawnEntityInWorld(orbEntity2);
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Signal completion when entity dies
if (dualFire) {
if ((orbEntity == null || orbEntity.isDead) && (orbEntity2 == null || orbEntity2.isDead)) {
orbEntity = null;
orbEntity2 = null;
signalCompletion();
}
if (tick == dualFireDelay && orbEntity2 != null && !orbEntity2.isDead) {
orbEntity2.startMoving(target);
}
} else {
if (orbEntity == null || orbEntity.isDead) {
orbEntity = null;
signalCompletion();
}
}
}
@Override
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
}
@Override
public void onInterrupt(EntityLivingBase caster, net.minecraft.util.DamageSource source, float damage) {
cleanup();
}
@Override
public void cleanup() {
// Despawn orb entity if still alive
if (orbEntity != null && !orbEntity.isDead) {
orbEntity.setDead();
}
if (orbEntity2 != null && !orbEntity2.isDead) {
orbEntity2.setDead();
}
orbEntity = null;
orbEntity2 = null;
}
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
return null;
}
// Create small circle telegraph at target position
Telegraph telegraph = Telegraph.circle(orbSize * 1.5f);
telegraph.setDurationTicks(windUpTicks);
telegraph.setColor(windUpColor);
telegraph.setWarningColor(activeColor);
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
telegraph.setHeightOffset(telegraphHeightOffset);
// Position at target and follow target during windup
TelegraphInstance instance = new TelegraphInstance(telegraph, target.posX, target.posY, target.posZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
instance.setEntityIdToFollow(target.getEntityId());
return instance;
}
@Override
public float getTelegraphRadius() {
return orbSize * 1.5f;
}
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setFloat("orbSize", orbSize);
nbt.setBoolean("dualFire", dualFire);
nbt.setInteger("dualFireDelay", dualFireDelay);
combatData.writeNBT(nbt);
homingData.writeNBT(nbt);
lifespanData.writeNBT(nbt);
// Backward compat: old key was "orbSpeed"
nbt.setFloat("orbSpeed", homingData.speed);
NBTTagCompound orb1 = new NBTTagCompound();
NBTTagCompound orb2 = new NBTTagCompound();
for (int i = 0; i < 2; i++) {
NBTTagCompound orb = i == 0 ? orb1 : orb2;
anchorData[i].writeNBT(orb);
displayData[i].writeNBT(orb);
lightningData[i].writeNBT(orb);
trajectoryData[i].writeNBT(orb);
}
nbt.setTag("Orb_1", orb1);
nbt.setTag("Orb_2", orb2);
}
@Override
public void readTypeNBT(NBTTagCompound nbt) {
NBTTagCompound orb1 = nbt.hasKey("Orb_1") ? nbt.getCompoundTag("Orb_1") : new NBTTagCompound();
NBTTagCompound orb2 = nbt.hasKey("Orb_2") ? nbt.getCompoundTag("Orb_2") : new NBTTagCompound();
this.orbSize = nbt.hasKey("orbSize") ? nbt.getFloat("orbSize") : 1.0f;
this.dualFire = !nbt.hasKey("dualFire") || nbt.getBoolean("dualFire");
this.dualFireDelay = nbt.hasKey("dualFireDelay") ? nbt.getInteger("dualFireDelay") : 0;
combatData.readNBT(nbt);
homingData.readNBT(nbt);
lifespanData.readNBT(nbt);
// Backward compat: old key was "orbSpeed"
if (nbt.hasKey("orbSpeed")) {
homingData.speed = nbt.getFloat("orbSpeed");
}
for (int i = 0; i < 2; i++) {
NBTTagCompound orb = i == 0 ? orb1 : orb2;
anchorData[i].readNBT(orb);
displayData[i].readNBT(orb);
lightningData[i].readNBT(orb);
trajectoryData[i].readNBT(orb);
}
}
// Getters & Setters
private EnergyDisplayData getColorData(int orb) {
orb = ValueUtil.clamp(orb, 0, 1);
return displayData[orb];
}
private EnergyLightningData getLightningData(int orb) {
orb = ValueUtil.clamp(orb, 0, 1);
return lightningData[orb];
}
private EnergyAnchorData getAnchorData(int orb) {
orb = ValueUtil.clamp(orb, 0, 1);
return anchorData[orb];
}
public float getOrbSpeed() {
return homingData.speed;
}
public void setOrbSpeed(float orbSpeed) {
homingData.speed = orbSpeed;
}
public float getOrbSize() {
return orbSize;
}
public void setOrbSize(float orbSize) {
this.orbSize = orbSize;
}
public boolean isDualFire() {
return dualFire;
}
public void setDualFire(boolean dualFire) {
this.dualFire = dualFire;
}
public int getDualFireDelay() {
return dualFireDelay;
}
public void setDualFireDelay(int dualFireDelay) {
this.dualFireDelay = dualFireDelay;
}
public float getMaxDistance() {
return lifespanData.maxDistance;
}
public void setMaxDistance(float maxDistance) {
lifespanData.maxDistance = maxDistance;
}
public int getMaxLifetime() {
return lifespanData.maxLifetime;
}
public void setMaxLifetime(int maxLifetime) {
lifespanData.maxLifetime = maxLifetime;
}
public float getDamage() {
return combatData.damage;
}
public void setDamage(float damage) {
combatData.damage = damage;
}
public float getKnockback() {
return combatData.knockback;
}
public void setKnockback(float knockback) {
combatData.knockback = knockback;
}
public float getKnockbackUp() {
return combatData.knockbackUp;
}
public void setKnockbackUp(float knockbackUp) {
combatData.knockbackUp = knockbackUp;
}
public boolean isHoming() {
return homingData.homing;
}
public void setHoming(boolean homing) {
homingData.homing = homing;
}
public float getHomingStrength() {
return homingData.homingStrength;
}
public void setHomingStrength(float homingStrength) {
homingData.homingStrength = homingStrength;
}
public float getHomingRange() {
return homingData.homingRange;
}
public void setHomingRange(float homingRange) {
homingData.homingRange = homingRange;
}
public boolean isExplosive() {
return combatData.explosive;
}
public void setExplosive(boolean explosive) {
combatData.explosive = explosive;
}
public float getExplosionRadius() {
return combatData.explosionRadius;
}
public void setExplosionRadius(float explosionRadius) {
combatData.explosionRadius = explosionRadius;
}
public float getExplosionDamageFalloff() {
return combatData.explosionDamageFalloff;
}
public void setExplosionDamageFalloff(float explosionDamageFalloff) {
combatData.explosionDamageFalloff = explosionDamageFalloff;
}
public int getInnerColor(int orb) { return getColorData(orb).innerColor; }
public void setInnerColor(int orb, int innerColor) { getColorData(orb).innerColor = innerColor; }
public int getOuterColor(int orb) { return getColorData(orb).outerColor; }
public void setOuterColor(int orb, int outerColor) { getColorData(orb).outerColor = outerColor; }
public boolean isOuterColorEnabled(int orb) { return getColorData(orb).outerColorEnabled; }
public void setOuterColorEnabled(int orb, boolean enabled) { getColorData(orb).outerColorEnabled = enabled; }
public float getOuterColorWidth(int orb) { return getColorData(orb).outerColorWidth; }
public void setOuterColorWidth(int orb, float width) { getColorData(orb).outerColorWidth = width; }
public float getOuterColorAlpha(int orb) { return getColorData(orb).outerColorAlpha; }
public void setOuterColorAlpha(int orb, float alpha) { getColorData(orb).outerColorAlpha = alpha; }
public float getRotationSpeed(int orb) { return getColorData(orb).rotationSpeed; }
public void setRotationSpeed(int orb, float speed) { getColorData(orb).rotationSpeed = speed; }
public int getInnerColor() { return getInnerColor(0); }
public void setInnerColor(int innerColor) { setInnerColor(0, innerColor); }
public int getOuterColor() { return getOuterColor(0); }
public void setOuterColor(int outerColor) { setOuterColor(0, outerColor); }
public boolean isOuterColorEnabled() { return isOuterColorEnabled(0); }
public void setOuterColorEnabled(boolean enabled) { setOuterColorEnabled(0, enabled); }
public float getOuterColorWidth() { return getOuterColorWidth(0); }
public void setOuterColorWidth(float width) { setOuterColorWidth(0, width); }
public float getOuterColorAlpha() { return getOuterColorAlpha(0); }
public void setOuterColorAlpha(float alpha) { setOuterColorAlpha(0, alpha); }
public float getRotationSpeed() { return getRotationSpeed(0); }
public void setRotationSpeed(float speed) { setRotationSpeed(0, speed); }
public boolean hasLightningEffect(int orb) { return getLightningData(orb).lightningEffect; }
public void setLightningEffect(int orb, boolean lightningEffect) { getLightningData(orb).lightningEffect = lightningEffect; }
public float getLightningDensity(int orb) { return getLightningData(orb).lightningDensity; }
public void setLightningDensity(int orb, float lightningDensity) { getLightningData(orb).lightningDensity = lightningDensity; }
public float getLightningRadius(int orb) { return getLightningData(orb).lightningRadius; }
public void setLightningRadius(int orb, float lightningRadius) { getLightningData(orb).lightningRadius = lightningRadius; }
public boolean hasLightningEffect() { return hasLightningEffect(0); }
public void setLightningEffect(boolean lightningEffect) { setLightningEffect(0, lightningEffect); }
public float getLightningDensity() { return getLightningDensity(0); }
public void setLightningDensity(float lightningDensity) { setLightningDensity(0, lightningDensity); }
public float getLightningRadius() { return getLightningRadius(0); }
public void setLightningRadius(float lightningRadius) { setLightningRadius(0, lightningRadius); }
public AnchorPoint getAnchorPointEnum(int orb) { return getAnchorData(orb).anchorPoint; }
public void setAnchorPointEnum(int orb, AnchorPoint anchorPoint) { getAnchorData(orb).anchorPoint = anchorPoint; }
public float getAnchorOffsetX(int orb) { return getAnchorData(orb).anchorOffsetX; }
public void setAnchorOffsetX(int orb, float x) { getAnchorData(orb).anchorOffsetX = x; }
public float getAnchorOffsetY(int orb) { return getAnchorData(orb).anchorOffsetY; }
public void setAnchorOffsetY(int orb, float y) { getAnchorData(orb).anchorOffsetY = y; }
public float getAnchorOffsetZ(int orb) { return getAnchorData(orb).anchorOffsetZ; }
public void setAnchorOffsetZ(int orb, float z) { getAnchorData(orb).anchorOffsetZ = z; }
public AnchorPoint getAnchorPointEnum() { return getAnchorPointEnum(0); }
public void setAnchorPointEnum(AnchorPoint anchorPoint) { setAnchorPointEnum(0, anchorPoint); }
public float getAnchorOffsetX() { return getAnchorOffsetX(0); }
public void setAnchorOffsetX(float x) { setAnchorOffsetX(0, x); }
public float getAnchorOffsetY() { return getAnchorOffsetY(0); }
public void setAnchorOffsetY(float y) { setAnchorOffsetY(0, y); }
public float getAnchorOffsetZ() { return getAnchorOffsetZ(0); }
public void setAnchorOffsetZ(float z) { setAnchorOffsetZ(0, z); }
//@Override
public int getAnchorPoint(int orb) { return getAnchorData(orb).anchorPoint.ordinal(); }
public int getAnchorPoint() { return getAnchorData(0).anchorPoint.ordinal(); }
//@Override
public void setAnchorPoint(int orb, int point) { getAnchorData(orb).anchorPoint = AnchorPoint.fromOrdinal(point); }
public void setAnchorPoint(int point) { getAnchorData(0).anchorPoint = AnchorPoint.fromOrdinal(point); }
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Type tab
FieldDef.row(
FieldDef.floatField("enchantment.damage", this::getDamage, this::setDamage),
FieldDef.floatField("stats.speed", this::getOrbSpeed, this::setOrbSpeed)
),
FieldDef.row(
FieldDef.floatField("stats.size", this::getOrbSize, this::setOrbSize),
FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback)
),
FieldDef.row(
FieldDef.floatField("ability.maxDistance", this::getMaxDistance, this::setMaxDistance),
FieldDef.intField("ability.lifetime", this::getMaxLifetime, this::setMaxLifetime)
),
FieldDef.section("ability.section.dual"),
FieldDef.boolField("ability.dualFire", this::isDualFire, this::setDualFire),
FieldDef.intField("ability.dualFireDelay", this::getDualFireDelay, this::setDualFireDelay)
.visibleWhen(this::isDualFire),
FieldDef.section("ability.section.homing"),
FieldDef.boolField("gui.enabled", this::isHoming, this::setHoming).hover("ability.hover.homing"),
FieldDef.floatField("gui.strength", this::getHomingStrength, this::setHomingStrength).visibleWhen(this::isHoming),
FieldDef.section("ability.section.explosive"),
FieldDef.boolField("gui.enabled", this::isExplosive, this::setExplosive).hover("ability.hover.explosive"),
FieldDef.floatField("gui.radius", this::getExplosionRadius, this::setExplosionRadius).visibleWhen(this::isExplosive),
AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects),
// Visual tab - Orb 1
FieldDef.section("ability.section.orb1").tab("ability.tab.visual"),
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> getAnchorPointEnum(0), v -> setAnchorPointEnum(0, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor",
() -> getInnerColor(0), v -> setInnerColor(0, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled",
() -> isOuterColorEnabled(0), v -> setOuterColorEnabled(0, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor",
() -> getOuterColor(0), v -> setOuterColor(0, v))
.tab("ability.tab.visual").visibleWhen(() -> isOuterColorEnabled(0)),
FieldDef.row(
FieldDef.floatField("ability.outerWidth",
() -> getOuterColorWidth(0), v -> setOuterColorWidth(0, v))
.visibleWhen(() -> isOuterColorEnabled(0)),
FieldDef.floatField("ability.outerAlpha",
() -> getOuterColorAlpha(0), v -> setOuterColorAlpha(0, v))
.range(0, 1).visibleWhen(() -> isOuterColorEnabled(0))
).tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed",
() -> getRotationSpeed(0), v -> setRotationSpeed(0, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning",
() -> hasLightningEffect(0), v -> setLightningEffect(0, v))
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density",
() -> getLightningDensity(0), v -> setLightningDensity(0, v))
.range(0.01f, 5.0f).visibleWhen(() -> hasLightningEffect(0)),
FieldDef.floatField("gui.radius",
() -> getLightningRadius(0), v -> setLightningRadius(0, v))
.range(0.1f, 10.0f).visibleWhen(() -> hasLightningEffect(0))
).tab("ability.tab.visual"),
// Visual tab - Orb 2
FieldDef.section("ability.section.orb2").tab("ability.tab.visual"),
FieldDef.enumField("ability.anchorPoint", AnchorPoint.class,
() -> getAnchorPointEnum(1), v -> setAnchorPointEnum(1, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.innerColor",
() -> getInnerColor(1), v -> setInnerColor(1, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.outerEnabled",
() -> isOuterColorEnabled(1), v -> setOuterColorEnabled(1, v))
.tab("ability.tab.visual"),
FieldDef.colorSubGui("ability.outerColor",
() -> getOuterColor(1), v -> setOuterColor(1, v))
.tab("ability.tab.visual").visibleWhen(() -> isOuterColorEnabled(1)),
FieldDef.row(
FieldDef.floatField("ability.outerWidth",
() -> getOuterColorWidth(1), v -> setOuterColorWidth(1, v))
.visibleWhen(() -> isOuterColorEnabled(1)),
FieldDef.floatField("ability.outerAlpha",
() -> getOuterColorAlpha(1), v -> setOuterColorAlpha(1, v))
.range(0, 1).visibleWhen(() -> isOuterColorEnabled(1))
).tab("ability.tab.visual"),
FieldDef.floatField("ability.rotationSpeed",
() -> getRotationSpeed(1), v -> setRotationSpeed(1, v))
.tab("ability.tab.visual"),
FieldDef.boolField("ability.lightning",
() -> hasLightningEffect(1), v -> setLightningEffect(1, v))
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density",
() -> getLightningDensity(1), v -> setLightningDensity(1, v))
.range(0.01f, 100f).visibleWhen(() -> hasLightningEffect(1)),
FieldDef.floatField("gui.radius",
() -> getLightningRadius(1), v -> setLightningRadius(1, v))
.range(0.1f, 100f).visibleWhen(() -> hasLightningEffect(1))
).tab("ability.tab.visual")
));
}
@Override
@SideOnly(Side.CLIENT)
public Entity createPreviewEntity(EntityNPCInterface npc) {
if (npc == null || npc.worldObj == null) return null;
EntityAbilityOrb orb = new EntityAbilityOrb(npc.worldObj);
orb.setupPreview(npc, orbSize, displayData[0], lightningData[0], anchorData[0], windUpTicks);
return orb;
}
@Override
public int getPreviewActiveDuration() {
return lifespanData.maxLifetime > 0 ? Math.min(lifespanData.maxLifetime, 100) : 100;
}
}
@@ -9,6 +9,7 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import noppes.npcs.entity.EntityNPCInterface;
@@ -50,6 +51,11 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile {
this.showTelegraph = false;
}
@Override
public boolean allowBurst() {
return false;
}
@Override
public boolean isTargetingModeLocked() {
return true;
@@ -62,61 +68,129 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile {
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote || target == null) return;
if (world.isRemote && !isPreview()) {
signalCompletion();
return;
}
if (isPlayerCaster(caster)) {
// Player: instant hit-scan in look direction
executePlayerProjectile(caster, world);
} else if (target != null) {
// NPC: instant hit-scan on aggro target
executeNpcProjectile(caster, target, world);
}
signalCompletion();
}
/**
* NPC projectile: instant hit-scan damage on the aggro target.
*/
private void executeNpcProjectile(EntityLivingBase caster, EntityLivingBase target, World world) {
if (isPreview()) return;
// Calculate direction to target
double dx = target.posX - caster.posX;
double dy = (target.posY + target.height / 2) - (caster.posY + caster.getEyeHeight());
double dz = target.posZ - caster.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) { dx /= len; dy /= len; dz /= len; }
if (len > 0) {
dx /= len;
dy /= len;
dz /= len;
}
// Deal instant damage with scripted event support
// TODO: Use custom EntityAbilityProjectile for actual tracking
applyAbilityDamageWithDirection(caster, target, damage, knockback, dx, dz);
// Play sound
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
// Handle splash damage for explosive projectiles
if (explosive && explosionRadius > 0) {
@SuppressWarnings("unchecked")
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(target,
target.boundingBox.expand(explosionRadius, explosionRadius, explosionRadius));
applyExplosionDamage(caster, target, world, target.posX, target.posY, target.posZ);
}
for (Entity entity : entities) {
if (entity instanceof EntityLivingBase && entity != caster) {
EntityLivingBase living = (EntityLivingBase) entity;
float dist = target.getDistanceToEntity(living);
if (dist < explosionRadius) {
float falloff = 1.0f - (dist / explosionRadius);
// Apply splash damage with scripted event support (no knockback)
applyAbilityDamage(caster, living, damage * falloff * 0.5f, 0);
}
}
}
spawnProjectileParticles(world, caster, target);
}
// Explosion particles
world.playSoundAtEntity(target, "random.explode", 0.5f, 1.0f);
for (int i = 0; i < 10; i++) {
world.spawnParticle("explode",
target.posX + (world.rand.nextDouble() - 0.5) * explosionRadius,
target.posY + world.rand.nextDouble() * target.height,
target.posZ + (world.rand.nextDouble() - 0.5) * explosionRadius,
0, 0.1, 0);
/**
* Player projectile: fires instant hit-scan in look direction.
* Raycasts for the first entity in range and applies damage.
*/
private void executePlayerProjectile(EntityLivingBase caster, World world) {
if (isPreview()) return;
Vec3 look = caster.getLookVec();
double eyeX = caster.posX;
double eyeY = caster.posY + caster.getEyeHeight();
double eyeZ = caster.posZ;
// Raycast: find the closest entity along look direction
EntityLivingBase hitTarget = null;
double closestDist = maxRange;
@SuppressWarnings("unchecked")
List<Entity> candidates = world.getEntitiesWithinAABBExcludingEntity(caster,
caster.boundingBox.expand(maxRange, maxRange, maxRange));
for (Entity entity : candidates) {
if (!(entity instanceof EntityLivingBase)) continue;
if (entity.isDead) continue;
// Check if entity is roughly along look direction
double dx = entity.posX - eyeX;
double dy = (entity.posY + entity.height / 2) - eyeY;
double dz = entity.posZ - eyeZ;
double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (dist > maxRange || dist < 0.5) continue;
// Dot product to check alignment with look vector
double dot = (dx * look.xCoord + dy * look.yCoord + dz * look.zCoord) / dist;
if (dot < 0.95) continue; // Must be within ~18 degree cone
if (dist < closestDist) {
closestDist = dist;
hitTarget = (EntityLivingBase) entity;
}
}
// Spawn projectile particles (visual trail)
spawnProjectileParticles(world, caster, target);
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
// Projectile is instant
signalCompletion();
if (hitTarget != null) {
applyAbilityDamageWithDirection(caster, hitTarget, damage, knockback, look.xCoord, look.zCoord);
if (explosive && explosionRadius > 0) {
applyExplosionDamage(caster, hitTarget, world, hitTarget.posX, hitTarget.posY, hitTarget.posZ);
}
spawnProjectileParticles(world, caster, hitTarget);
} else {
// No hit — spawn particles along look direction anyway
spawnProjectileParticlesInDirection(world, caster, look);
}
}
/**
* Apply explosion splash damage around a point.
*/
private void applyExplosionDamage(EntityLivingBase caster, EntityLivingBase primaryTarget, World world,
double x, double y, double z) {
@SuppressWarnings("unchecked")
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(primaryTarget,
primaryTarget.boundingBox.expand(explosionRadius, explosionRadius, explosionRadius));
for (Entity entity : entities) {
if (entity instanceof EntityLivingBase && entity != caster) {
EntityLivingBase living = (EntityLivingBase) entity;
float dist = primaryTarget.getDistanceToEntity(living);
if (dist < explosionRadius) {
float falloff = 1.0f - (dist / explosionRadius);
applyAbilityDamage(caster, living, damage * falloff * 0.5f, 0);
}
}
}
world.playSoundAtEntity(primaryTarget, "random.explode", 0.5f, 1.0f);
for (int i = 0; i < 10; i++) {
world.spawnParticle("explode",
x + (world.rand.nextDouble() - 0.5) * explosionRadius,
y + world.rand.nextDouble() * 2,
z + (world.rand.nextDouble() - 0.5) * explosionRadius,
0, 0.1, 0);
}
}
private void spawnProjectileParticles(World world, EntityLivingBase caster, EntityLivingBase target) {
@@ -150,6 +224,31 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile {
}
}
/**
* Spawn projectile particles along a direction (player miss — no entity hit).
*/
private void spawnProjectileParticlesInDirection(World world, EntityLivingBase caster, Vec3 look) {
double startX = caster.posX;
double startY = caster.posY + caster.getEyeHeight();
double startZ = caster.posZ;
String particle = "flame";
if (projectileType.equals("arrow")) {
particle = "crit";
} else if (projectileType.equals("magic")) {
particle = "witchMagic";
}
int steps = (int) Math.max(5, maxRange * 2);
for (int i = 0; i < steps; i++) {
double progress = (double) i / steps * maxRange;
double px = startX + look.xCoord * progress;
double py = startY + look.yCoord * progress;
double pz = startZ + look.zCoord * progress;
world.spawnParticle(particle, px, py, pz, 0, 0, 0);
}
}
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Projectile is instant, nothing to do per-tick
@@ -63,48 +63,50 @@ public class AbilityShockwave extends Ability implements IAbilityShockwave {
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
// Shockwave is instant - apply effect immediately after windup
if (!isPreview()) {
// Shockwave is instant - apply effect immediately after windup
// Get all entities in radius
AxisAlignedBB box = caster.boundingBox.expand(pushRadius, pushRadius / 2, pushRadius);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
// Get all entities in radius
AxisAlignedBB box = caster.boundingBox.expand(pushRadius, pushRadius / 2, pushRadius);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
int count = 0;
for (EntityLivingBase entity : entities) {
if (entity == caster) continue;
if (entity.isDead) continue;
int count = 0;
for (EntityLivingBase entity : entities) {
if (entity == caster) continue;
if (entity.isDead) continue;
double dist = caster.getDistanceToEntity(entity);
if (dist > pushRadius) continue;
double dist = caster.getDistanceToEntity(entity);
if (dist > pushRadius) continue;
count++;
if (count > maxTargets) break;
count++;
if (count > maxTargets) break;
// Calculate push direction (away from caster)
double dx = entity.posX - caster.posX;
double dz = entity.posZ - caster.posZ;
double len = Math.sqrt(dx * dx + dz * dz);
// Calculate push direction (away from caster)
double dx = entity.posX - caster.posX;
double dz = entity.posZ - caster.posZ;
double len = Math.sqrt(dx * dx + dz * dz);
if (len > 0) {
dx /= len;
dz /= len;
} else {
// Entity is directly on top of caster, push in random direction
double angle = Math.random() * Math.PI * 2;
dx = Math.cos(angle);
dz = Math.sin(angle);
}
if (len > 0) {
dx /= len;
dz /= len;
} else {
// Entity is directly on top of caster, push in random direction
double angle = Math.random() * Math.PI * 2;
dx = Math.cos(angle);
dz = Math.sin(angle);
}
// Scale knockback by distance (closer = stronger)
float distFactor = 1.0f - (float) (dist / pushRadius) * 0.5f;
float finalPush = pushStrength * distFactor;
// Apply damage with custom knockback direction
boolean wasHit = applyAbilityDamageWithDirection(caster, entity, damage * distFactor, finalPush, dx, dz);
// Scale knockback by distance (closer = stronger)
float distFactor = 1.0f - (float) (dist / pushRadius) * 0.5f;
float finalPush = pushStrength * distFactor;
// Apply damage with custom knockback direction
boolean wasHit = applyAbilityDamageWithDirection(caster, entity, damage * distFactor, finalPush, dx, dz);
// Apply effects if hit connected
if (wasHit) {
applyEffects(entity);
// Apply effects if hit connected
if (wasHit) {
applyEffects(entity);
}
}
}
}
@@ -85,51 +85,74 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
@Override
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
// Update target position during windup
if (targetingMode == TargetingMode.AOE_SELF) {
// AOE_SELF: slam at caster's current position
if (isPlayerCaster(caster)) {
// Player: slam will launch from current position, no target tracking needed
targetX = caster.posX;
targetY = caster.posY;
targetZ = caster.posZ;
} else if (targetingMode == TargetingMode.AOE_TARGET && target != null && !target.isDead) {
// AOE_TARGET: telegraph follows target via setEntityIdToFollow
targetX = target.posX;
targetY = target.posY;
targetZ = target.posZ;
} else {
// NPC: update target position during windup for telegraph tracking
if (targetingMode == TargetingMode.AOE_SELF) {
targetX = caster.posX;
targetY = caster.posY;
targetZ = caster.posZ;
} else if (targetingMode == TargetingMode.AOE_TARGET && target != null && !target.isDead) {
targetX = target.posX;
targetY = target.posY;
targetZ = target.posZ;
}
}
}
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
// Lock in the destination at moment of launch
hasLaunched = false;
hasLanded = false;
airTicks = 0;
caster.fallDistance = 0;
if (isPlayerCaster(caster)) {
executePlayerSlam(caster);
} else {
executeNpcSlam(caster, target);
}
}
/**
* NPC slam: Lock destination based on targeting mode, then launch in a ballistic arc toward it.
*/
private void executeNpcSlam(EntityLivingBase caster, EntityLivingBase target) {
if (targetingMode == TargetingMode.AOE_SELF) {
// AOE_SELF: slam in place (just jump up)
targetX = caster.posX;
targetY = caster.posY;
targetZ = caster.posZ;
} else if (targetingMode == TargetingMode.AOE_TARGET && target != null && !target.isDead) {
// AOE_TARGET: leap to target's current position
targetX = target.posX;
targetY = target.posY;
targetZ = target.posZ;
} else {
// Fallback: slam in place
targetX = caster.posX;
targetY = caster.posY;
targetZ = caster.posZ;
}
hasLaunched = false;
hasLanded = false;
airTicks = 0;
// Reset fall distance to prevent fall damage during slam
caster.fallDistance = 0;
// Calculate and apply leap velocity
launchTowardTarget(caster);
}
/**
* Player slam: Launch straight up. Player controls horizontal movement via WASD.
* AOE damage triggers wherever the player lands.
*/
private void executePlayerSlam(EntityLivingBase caster) {
targetX = caster.posX;
targetY = caster.posY;
targetZ = caster.posZ;
double vy = calculateLaunchVelocity(Math.max(1.0, leapHeight));
caster.motionY = vy;
hasLaunched = true;
caster.velocityChanged = true;
}
/**
* Calculate the initial vertical velocity needed to reach a target height
* in Minecraft's physics (gravity=0.08, vertical drag=0.98).
@@ -187,11 +210,13 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
caster.motionZ = 0;
caster.motionY = vy;
hasLaunched = true;
if (caster instanceof EntityNPCInterface) {
if (!isPreview() && caster instanceof EntityNPCInterface) {
((EntityNPCInterface) caster).setNpcJumpingState(true);
}
caster.velocityChanged = true;
caster.worldObj.playSoundAtEntity(caster, "mob.irongolem.throw", 0.8f, 0.8f);
if (!isPreview()) {
caster.velocityChanged = true;
caster.worldObj.playSoundAtEntity(caster, "mob.irongolem.throw", 0.8f, 0.8f);
}
return;
}
@@ -233,10 +258,12 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
caster.motionY = vy;
hasLaunched = true;
if (caster instanceof EntityNPCInterface) {
if (!isPreview() && caster instanceof EntityNPCInterface) {
((EntityNPCInterface) caster).setNpcJumpingState(true);
}
caster.velocityChanged = true;
if (!isPreview()) {
caster.velocityChanged = true;
}
// Face the target
float targetYaw = (float) (Math.atan2(-dx, dz) * 180.0D / Math.PI);
@@ -252,7 +279,9 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
airTicks++;
// Continuously reset fall distance during slam to prevent fall damage
caster.fallDistance = 0;
if (!isPreview()) {
caster.fallDistance = 0;
}
// Check for landing
if (caster.onGround && airTicks > 3) {
@@ -267,12 +296,15 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
return;
}
// While in air, face toward target
double dx = targetX - caster.posX;
double dz = targetZ - caster.posZ;
float targetYaw = (float) (Math.atan2(-dx, dz) * 180.0D / Math.PI);
caster.rotationYaw = targetYaw;
caster.rotationYawHead = targetYaw;
// NPC: face toward target destination while in air
// Player: free look — player controls their own camera
if (!isPreview() && !isPlayerCaster(caster)) {
double dx = targetX - caster.posX;
double dz = targetZ - caster.posZ;
float targetYaw = (float) (Math.atan2(-dx, dz) * 180.0D / Math.PI);
caster.rotationYaw = targetYaw;
caster.rotationYawHead = targetYaw;
}
}
/**
@@ -280,22 +312,25 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
*/
private void onLanding(EntityLivingBase caster, World world) {
hasLanded = true;
if (caster instanceof EntityNPCInterface) {
if (!isPreview() && caster instanceof EntityNPCInterface) {
((EntityNPCInterface) caster).setNpcJumpingState(false);
}
// Signal that the ability has completed its active phase
signalCompletion();
// Reset fall distance to prevent fall damage on landing
caster.fallDistance = 0;
// Stop horizontal momentum
caster.motionX = 0;
caster.motionZ = 0;
caster.velocityChanged = true;
if (world.isRemote) return;
if (!isPreview()) {
// Reset fall distance to prevent fall damage on landing
caster.fallDistance = 0;
caster.velocityChanged = true;
}
if (world.isRemote && !isPreview()) return;
if (isPreview()) return;
// Play slam impact sound on landing
world.playSoundAtEntity(caster, "random.explode", 1.0f, 1.0f);
@@ -361,7 +396,7 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
@Override
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
if (caster instanceof EntityNPCInterface) {
if (!isPreview() && caster instanceof EntityNPCInterface) {
((EntityNPCInterface) caster).setNpcJumpingState(false);
}
hasLaunched = false;
@@ -371,7 +406,7 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
@Override
public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {
if (caster instanceof EntityNPCInterface) {
if (!isPreview() && caster instanceof EntityNPCInterface) {
((EntityNPCInterface) caster).setNpcJumpingState(false);
}
hasLaunched = false;
@@ -387,97 +422,8 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
airTicks = 0;
}
// ==================== PREVIEW MODE ====================
private transient double previewVelX, previewVelY, previewVelZ;
private transient boolean previewLaunched = false;
private transient double previewGroundY;
@Override
@SideOnly(Side.CLIENT)
public void onPreviewExecute(EntityNPCInterface npc) {
previewLaunched = false;
double tx, ty, tz;
if (previewTarget != null && targetingMode == TargetingMode.AOE_TARGET) {
tx = previewTarget.posX;
ty = previewTarget.posY;
tz = previewTarget.posZ;
} else {
tx = npc.posX;
ty = npc.posY;
tz = npc.posZ;
}
previewGroundY = npc.posY;
double dx = tx - npc.posX;
double dz = tz - npc.posZ;
double horizontalDist = Math.sqrt(dx * dx + dz * dz);
// Calculate vertical velocity for exact leapHeight
double arcHeight = Math.max(1.0, leapHeight);
double vy = calculateLaunchVelocity(arcHeight);
if (horizontalDist < 0.5) {
previewVelX = 0;
previewVelZ = 0;
previewVelY = vy;
} else {
if (horizontalDist > maxRange) {
double scale = maxRange / horizontalDist;
dx *= scale;
dz *= scale;
horizontalDist = maxRange;
}
double speedFactor = Math.max(0.1, leapSpeed);
int flightTicks = (int) Math.max(10, Math.min(horizontalDist * 1.5 / speedFactor, 40));
double drag = 0.91;
double dragPowN = Math.pow(drag, flightTicks);
double vHorizontal = horizontalDist * (1.0 - drag) / (1.0 - dragPowN);
double dirX = dx / horizontalDist;
double dirZ = dz / horizontalDist;
previewVelX = dirX * vHorizontal;
previewVelZ = dirZ * vHorizontal;
previewVelY = vy;
}
previewLaunched = true;
}
@Override
@SideOnly(Side.CLIENT)
public void onPreviewActiveTick(EntityNPCInterface npc, int tick) {
if (!previewLaunched) return;
// Apply velocity
npc.prevPosX = npc.posX;
npc.prevPosY = npc.posY;
npc.prevPosZ = npc.posZ;
npc.posX += previewVelX;
npc.posY += previewVelY;
npc.posZ += previewVelZ;
// Gravity and drag
previewVelY -= 0.08;
previewVelY *= 0.98;
previewVelX *= 0.91;
previewVelZ *= 0.91;
// Ground clamp - stop falling below starting Y
if (npc.posY < previewGroundY && previewVelY < 0) {
npc.posY = previewGroundY;
previewVelY = 0;
previewVelX = 0;
previewVelZ = 0;
previewLaunched = false;
}
}
@Override
public int getPreviewActiveDuration() {
public int getMaxPreviewDuration() {
return 60;
}
@@ -519,11 +465,11 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
TelegraphInstance instance = new TelegraphInstance(telegraph, targetX, groundY, targetZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
// AOE_TARGET: telegraph follows target during windup
if (targetingMode == TargetingMode.AOE_TARGET && target != null) {
// NPC AOE_TARGET: telegraph follows target during windup
// Player: telegraph stays at caster position (no target to follow)
if (!isPlayerCaster(caster) && targetingMode == TargetingMode.AOE_TARGET && target != null) {
instance.setEntityIdToFollow(target.getEntityId());
}
// AOE_SELF: telegraph stays at caster position, no follow
return instance;
}
@@ -61,6 +61,11 @@ public class AbilitySweeper extends Ability implements IAbilitySweeper {
this.showTelegraph = true;
}
@Override
public boolean allowBurst() {
return false;
}
@Override
public boolean isTargetingModeLocked() {
return true;
@@ -73,19 +78,26 @@ public class AbilitySweeper extends Ability implements IAbilitySweeper {
@Override
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) {
if (world.isRemote && !isPreview()) {
signalCompletion();
return;
}
// Spawn the entity that handles BOTH visuals AND damage
// Spawn the sweeper entity that handles BOTH visuals AND damage.
// NPC: target is the aggro target — lockOnTarget tracks it during sweep.
// Player: target is null — sweep rotates around caster's facing direction, lockOnTarget has no effect.
activeEntity = new EntityAbilitySweeper(world, caster, target,
beamLength, beamWidth, beamHeight,
colorData,
sweepSpeed, numberOfRotations,
damage, damageInterval, piercing,
lockOnTarget);
world.spawnEntityInWorld(activeEntity);
if (isPreview()) {
activeEntity.setupPreview(caster);
}
spawnAbilityEntity(world, activeEntity);
// Ability stays active until entity dies (prevents firing another while projectile is alive)
// Movement locking is handled separately by the base class
@@ -200,6 +212,11 @@ public class AbilitySweeper extends Ability implements IAbilitySweeper {
public boolean isOuterColorEnabled() { return colorData.outerColorEnabled; }
public void setOuterColorEnabled(boolean outerColorEnabled) { colorData.outerColorEnabled = outerColorEnabled; }
@Override
public int getMaxPreviewDuration() {
return (int) ((360.0f * numberOfRotations) / sweepSpeed) + 10;
}
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.type;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.UserType;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
@@ -72,6 +73,7 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
this.typeId = "ability.cnpc.teleport";
this.name = "Teleport";
this.targetingMode = TargetingMode.AGGRO_TARGET;
this.allowedBy = UserType.NPC_ONLY;
this.maxRange = 30.0f;
this.minRange = 5.0f;
this.cooldownTicks = 0;
@@ -128,7 +130,7 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
}
private void performBlink(EntityLivingBase caster, EntityLivingBase target, World world) {
if (world.isRemote) return;
if (world.isRemote && !isPreview()) return;
double oldX = caster.posX;
double oldY = caster.posY;
@@ -137,36 +139,47 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
Vec3 destination = calculateDestination(caster, target, world);
if (destination == null) return;
boolean mustHaveLOS = mode == TeleportMode.BEHIND || requireLineOfSight;
if (mustHaveLOS && !hasLineOfSight(world, oldX, oldY + caster.getEyeHeight(), oldZ,
destination.xCoord, destination.yCoord + caster.getEyeHeight(), destination.zCoord)) {
destination = findValidPositionAlongLine(world, caster, oldX, oldY, oldZ,
if (!isPreview()) {
boolean mustHaveLOS = mode == TeleportMode.BEHIND || requireLineOfSight;
if (mustHaveLOS && !hasLineOfSight(world, oldX, oldY + caster.getEyeHeight(), oldZ,
destination.xCoord, destination.yCoord + caster.getEyeHeight(), destination.zCoord)) {
destination = findValidPositionAlongLine(world, caster, oldX, oldY, oldZ,
destination.xCoord, destination.yCoord, destination.zCoord);
if (destination == null) return;
}
destination = findSafeDestination(world, oldX, oldY, oldZ,
destination.xCoord, destination.yCoord, destination.zCoord);
if (destination == null) return;
// Damage at origin
if (damageAtStart) {
dealDamageAt(caster, world, oldX, oldY, oldZ);
}
// Spawn particles at origin
spawnTeleportParticles(world, oldX, oldY, oldZ);
}
destination = findSafeDestination(world, oldX, oldY, oldZ,
destination.xCoord, destination.yCoord, destination.zCoord);
if (destination == null) return;
// Damage at origin
if (damageAtStart) {
dealDamageAt(caster, world, oldX, oldY, oldZ);
}
// Spawn particles at origin
spawnTeleportParticles(world, oldX, oldY, oldZ);
// Teleport
caster.setPositionAndUpdate(destination.xCoord, destination.yCoord, destination.zCoord);
if (isPreview()) {
caster.setPosition(destination.xCoord, destination.yCoord, destination.zCoord);
caster.prevPosX = destination.xCoord;
caster.prevPosY = destination.yCoord;
caster.prevPosZ = destination.zCoord;
} else {
caster.setPositionAndUpdate(destination.xCoord, destination.yCoord, destination.zCoord);
}
caster.fallDistance = 0;
// Spawn particles at destination
spawnTeleportParticles(world, destination.xCoord, destination.yCoord, destination.zCoord);
if (!isPreview()) {
// Spawn particles at destination
spawnTeleportParticles(world, destination.xCoord, destination.yCoord, destination.zCoord);
// Damage at destination
if (damageAtEnd) {
dealDamageAt(caster, world, destination.xCoord, destination.yCoord, destination.zCoord);
// Damage at destination
if (damageAtEnd) {
dealDamageAt(caster, world, destination.xCoord, destination.yCoord, destination.zCoord);
}
}
// Face target after teleport
@@ -217,26 +230,8 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
}
}
// No target (player use) - teleport in caster's look direction
Vec3 look = caster.getLookVec();
switch (mode) {
case BEHIND:
// Teleport forward in look direction by behindDistance
newX = caster.posX + look.xCoord * behindDistance;
newZ = caster.posZ + look.zCoord * behindDistance;
newY = caster.posY;
return Vec3.createVectorHelper(newX, newY, newZ);
case SINGLE:
case BLINK:
default:
// Teleport forward in look direction within blinkRadius
double dist = Math.min(blinkRadius, maxRange);
double offset = (RANDOM.nextDouble() * 0.5 + 0.5) * dist; // 50-100% of max distance
newX = caster.posX + look.xCoord * offset;
newZ = caster.posZ + look.zCoord * offset;
newY = caster.posY;
return Vec3.createVectorHelper(newX, newY, newZ);
}
// NPC-only ability — should not reach here
return null;
}
private Vec3 findSafeDestination(World world, double oldX, double oldY, double oldZ,
@@ -561,6 +556,12 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
this.damageRadius = damageRadius;
}
@Override
public int getMaxPreviewDuration() {
int blinkLimit = mode == TeleportMode.BLINK ? blinkCount : 1;
return blinkLimit * blinkDelayTicks + 10;
}
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.type;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.UserType;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import net.minecraft.entity.EntityLivingBase;
@@ -83,6 +84,12 @@ public class AbilityTrap extends Ability implements IAbilityTrap {
this.cooldownTicks = 0;
this.windUpTicks = 20;
this.telegraphType = TelegraphType.CIRCLE;
this.allowedBy = UserType.NPC_ONLY;
}
@Override
public boolean allowBurst() {
return false;
}
@Override
@@ -123,7 +130,6 @@ public class AbilityTrap extends Ability implements IAbilityTrap {
}
break;
case AT_TARGET:
// Telegraph follows target during windup, locks on execute
if (target != null) {
instance.setEntityIdToFollow(target.getEntityId());
}
@@ -149,14 +155,12 @@ public class AbilityTrap extends Ability implements IAbilityTrap {
trapZ = caster.posZ;
break;
case AT_TARGET:
// Use telegraph position with offset
if (telegraph != null) {
double[] pos = Ability.calculateOffsetPosition(telegraph.getX(), telegraph.getY(), telegraph.getZ(),
minOffset, maxOffset, randomOffset, RANDOM);
trapX = pos[0];
trapY = pos[1];
trapZ = pos[2];
// Update telegraph to show actual trap position
telegraph.setX(trapX);
telegraph.setY(trapY);
telegraph.setZ(trapZ);
@@ -207,26 +211,28 @@ public class AbilityTrap extends Ability implements IAbilityTrap {
return;
}
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(
trapX - triggerRadius, trapY - 1, trapZ - triggerRadius,
trapX + triggerRadius, trapY + 2, trapZ + triggerRadius
);
if (!isPreview()) {
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(
trapX - triggerRadius, trapY - 1, trapZ - triggerRadius,
trapX + triggerRadius, trapY + 2, trapZ + triggerRadius
);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
for (EntityLivingBase entity : entities) {
if (entity == caster) continue;
if (entity.isDead) continue;
if (maxTriggers == 1 && triggeredEntities.contains(entity.getUniqueID())) continue;
for (EntityLivingBase entity : entities) {
if (entity == caster) continue;
if (entity.isDead) continue;
if (maxTriggers == 1 && triggeredEntities.contains(entity.getUniqueID())) continue;
double dx = entity.posX - trapX;
double dz = entity.posZ - trapZ;
double dist = Math.sqrt(dx * dx + dz * dz);
double dx = entity.posX - trapX;
double dz = entity.posZ - trapZ;
double dist = Math.sqrt(dx * dx + dz * dz);
if (dist <= triggerRadius) {
triggerTrap(caster, entity, world);
return;
if (dist <= triggerRadius) {
triggerTrap(caster, entity, world);
return;
}
}
}
}
@@ -84,29 +84,32 @@ public class AbilityVortex extends Ability implements IAbilityVortex {
pullComplete = false;
ticksSincePullDamage = 0;
if (aoe) {
AxisAlignedBB box = caster.boundingBox.expand(pullRadius, pullRadius / 2, pullRadius);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
if (!isPreview()) {
if (aoe) {
AxisAlignedBB box = caster.boundingBox.expand(pullRadius, pullRadius / 2, pullRadius);
@SuppressWarnings("unchecked")
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, box);
int count = 0;
for (EntityLivingBase entity : entities) {
if (entity == caster) continue;
if (entity.isDead) continue;
int count = 0;
for (EntityLivingBase entity : entities) {
if (entity == caster) continue;
if (entity.isDead) continue;
double dist = caster.getDistanceToEntity(entity);
if (dist <= pullRadius) {
getPulledEntities().add(entity.getUniqueID());
count++;
if (count >= maxTargets) break;
double dist = caster.getDistanceToEntity(entity);
if (dist <= pullRadius) {
getPulledEntities().add(entity.getUniqueID());
count++;
if (count >= maxTargets) break;
}
}
}
} else {
// Single target mode - still check pullRadius
if (target != null && !target.isDead) {
double dist = caster.getDistanceToEntity(target);
if (dist <= pullRadius) {
getPulledEntities().add(target.getUniqueID());
} else {
// NPC single-target mode: pull the aggro target
// Player: single-target mode has no effect (no target to pull — use AOE mode instead)
if (!isPlayerCaster(caster) && target != null && !target.isDead) {
double dist = caster.getDistanceToEntity(target);
if (dist <= pullRadius) {
getPulledEntities().add(target.getUniqueID());
}
}
}
}
@@ -114,6 +117,12 @@ public class AbilityVortex extends Ability implements IAbilityVortex {
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (isPreview()) {
// No entities to pull in preview, just run animation for a duration
if (tick >= 60) signalCompletion();
return;
}
if (pullComplete || getPulledEntities().isEmpty()) {
signalCompletion();
return;
@@ -222,24 +222,39 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
setCharging(false);
// Update start position to current position
// Origin (tail) stays at the charged position
startX = posX;
startY = posY;
startZ = posZ;
// Reset head offset to origin
headOffsetX = 0;
headOffsetY = 0;
headOffsetZ = 0;
prevHeadOffsetX = 0;
prevHeadOffsetY = 0;
prevHeadOffsetZ = 0;
// Origin no longer follows owner after firing
attachedToOwner = false;
// Sync prev position to prevent visual jump on first frame
prevPosX = posX;
prevPosY = posY;
prevPosZ = posZ;
// Reset trail
trailPoints.clear();
trailPointAges.clear();
trailPoints.add(Vec3.createVectorHelper(0, 0, 0));
// Fire forward based on owner facing direction
Entity owner = getOwnerEntity();
if (owner != null) {
float yaw = (float) Math.toRadians(owner.rotationYaw);
float pitch = 0; // Fire horizontally
motionX = -Math.sin(yaw) * Math.cos(pitch) * getSpeed();
motionY = -Math.sin(pitch) * getSpeed();
motionZ = Math.cos(yaw) * Math.cos(pitch) * getSpeed();
motionX = -Math.sin(yaw) * getSpeed();
motionY = 0;
motionZ = Math.cos(yaw) * getSpeed();
} else {
motionX = getSpeed();
motionY = 0;
@@ -31,6 +31,7 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
// Disc shape properties
private float discRadius = 1.0f; // Width of disc
private float discThickness = 0.2f; // Height of disc
private boolean vertical = false; // false = horizontal (flat), true = vertical (thin edge forward)
// Charging state (during windup)
private boolean charging = false;
@@ -38,7 +39,6 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
private int chargeTick = 0;
private float targetDiscRadius = 1.0f; // Full radius to grow to during charging
private float targetDiscThickness = 0.2f; // Full thickness to grow to during charging
private EnergyAnchorData anchorData = new EnergyAnchorData();
// Data watcher index for charging state (synced to clients)
private static final int DW_CHARGING = 20;
@@ -123,11 +123,12 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
* The disc will grow from 0 to discRadius over chargeDuration ticks.
* Position follows the owner based on anchor point.
*/
public void setupCharging(EnergyAnchorData anchor, int chargeDuration) {
public void setupCharging(EnergyAnchorData anchor, int chargeDuration, boolean vertical) {
setCharging(true);
this.chargeDuration = chargeDuration;
this.chargeTick = 0;
this.anchorData = anchor;
this.vertical = vertical;
this.targetDiscRadius = this.discRadius;
this.targetDiscThickness = this.discThickness;
this.discRadius = 0.01f;
@@ -145,7 +146,7 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
* Follows anchor point and animations like in the real game.
* Can be fired when transitioning to active phase.
*/
public void setupPreview(EntityLivingBase owner, float discRadius, float discThickness, EnergyDisplayData display, EnergyLightningData lightning, EnergyAnchorData anchor, int chargeDuration) {
public void setupPreview(EntityLivingBase owner, float discRadius, float discThickness, EnergyDisplayData display, EnergyLightningData lightning, EnergyAnchorData anchor, int chargeDuration, boolean vertical) {
this.setPreviewMode(true);
this.setPreviewOwner(owner);
@@ -158,6 +159,7 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
this.chargeDuration = chargeDuration;
this.chargeTick = 0;
this.anchorData = anchor;
this.vertical = vertical;
// Store target size and start at 0 for grow effect
this.targetDiscRadius = discRadius;
@@ -542,6 +544,28 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
return returning;
}
public boolean isVertical() {
return vertical;
}
/**
* Get the yaw angle (degrees) from motion vector for vertical disc orientation.
* During charging, uses owner's facing direction.
*/
public float getTravelYaw() {
if (isCharging()) {
Entity owner = previewMode ? previewOwner : getOwnerEntity();
if (owner != null) {
return owner.rotationYaw;
}
}
double speed = Math.sqrt(motionX * motionX + motionZ * motionZ);
if (speed > 0.001) {
return (float) (Math.atan2(-motionX, motionZ) * 180.0 / Math.PI);
}
return 0.0f;
}
// ==================== NBT ====================
@Override
@@ -550,6 +574,7 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
this.boomerangDelay = nbt.hasKey("BoomerangDelay") ? nbt.getInteger("BoomerangDelay") : 40;
this.discRadius = nbt.hasKey("DiscRadius") ? nbt.getFloat("DiscRadius") : 1.0f;
this.discThickness = nbt.hasKey("DiscThickness") ? nbt.getFloat("DiscThickness") : 0.2f;
this.vertical = nbt.hasKey("Vertical") ? nbt.getBoolean("Vertical") : false;
this.returning = nbt.hasKey("Returning") && nbt.getBoolean("Returning");
// Charging state
boolean isCharging = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
@@ -567,6 +592,7 @@ public class EntityAbilityDisc extends EntityAbilityProjectile {
nbt.setInteger("BoomerangDelay", boomerangDelay);
nbt.setFloat("DiscRadius", discRadius);
nbt.setFloat("DiscThickness", discThickness);
nbt.setBoolean("Vertical", vertical);
nbt.setBoolean("Returning", returning);
// Charging state
nbt.setBoolean("Charging", isCharging());
@@ -1,6 +1,5 @@
package kamkeel.npcs.entity;
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
import kamkeel.npcs.controllers.data.ability.data.*;
import kamkeel.npcs.util.AnchorPointHelper;
import net.minecraft.entity.Entity;
@@ -36,6 +35,9 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
// Direction (normalized)
private double dirX, dirY, dirZ;
// Lock vertical direction after firing (only update yaw, keep pitch fixed)
private boolean lockVerticalDirection = false;
// Track hit entities to avoid double-damage
private Set<Integer> hitEntities = new HashSet<>();
@@ -46,7 +48,6 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
private boolean charging = false;
private int chargeDuration = 40;
private int chargeTick = 0;
private EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.FRONT);
private float targetSize = 1.0f; // Full size to grow to during charging
// Data watcher index for charging state (synced to clients)
@@ -167,6 +168,10 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
return;
}
// Track owner's anchor position and rotation each tick
// so the laser follows the NPC's facing direction
updateLaserOriginAndDirection();
if (!fullyExtended) {
// Expand the laser
currentLength += expansionSpeed;
@@ -189,27 +194,76 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
} else {
// Laser is fully extended, count down linger time
ticksSinceFullExtension++;
// Update end point during linger (origin/direction may still change)
endX = startX + dirX * currentLength;
endY = startY + dirY * currentLength;
endZ = startZ + dirZ * currentLength;
if (ticksSinceFullExtension >= lingerTicks) {
this.setDead();
}
}
}
/**
* Update laser origin and direction from the owner's current anchor position and rotation.
* Called each tick so the laser follows the NPC when tracking a target.
*/
private void updateLaserOriginAndDirection() {
Entity owner = getOwnerEntity();
if (owner == null || owner.isDead) return;
if (!(owner instanceof EntityLivingBase)) return;
EntityLivingBase livingOwner = (EntityLivingBase) owner;
// Update origin from anchor point
if (anchorData != null) {
Vec3 pos = AnchorPointHelper.calculateAnchorPosition(livingOwner, anchorData);
startX = pos.xCoord;
startY = pos.yCoord;
startZ = pos.zCoord;
} else {
startX = owner.posX;
startY = owner.posY + owner.height * 0.7;
startZ = owner.posZ;
}
// Update direction from owner's current rotation
float yaw = (float) Math.toRadians(owner.rotationYaw);
if (lockVerticalDirection) {
// Only update horizontal direction (yaw), keep vertical (pitch) fixed
double horizontalLen = Math.sqrt(dirX * dirX + dirZ * dirZ);
if (horizontalLen < 0.001) horizontalLen = 1.0;
dirX = -Math.sin(yaw) * horizontalLen;
dirZ = Math.cos(yaw) * horizontalLen;
} else {
float pitch = (float) Math.toRadians(owner.rotationPitch);
dirX = -Math.sin(yaw) * Math.cos(pitch);
dirY = -Math.sin(pitch);
dirZ = Math.cos(yaw) * Math.cos(pitch);
}
// Keep entity positioned at origin
prevPosX = startX;
prevPosY = startY;
prevPosZ = startZ;
setPosition(startX, startY, startZ);
}
public void startMoving(EntityLivingBase target) {
if (!isCharging()) return;
setCharging(false);
// Update start position to current position
// Initialize from current anchor position
// updateLaserOriginAndDirection() will keep these updated each tick
startX = posX;
startY = posY;
startZ = posZ;
// Always derive direction from the owner's current yaw/pitch.
// This ensures the laser fires in the direction the NPC is visually facing,
// which matches the telegraph line direction regardless of Lock Movement mode.
// Set initial direction from owner's rotation
Entity owner = getOwnerEntity();
if (owner != null) {
float yaw = (float) Math.toRadians(owner.rotationYaw);
float pitch = (float) Math.toRadians(owner.rotationPitch);
@@ -217,7 +271,6 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
this.dirY = -Math.sin(pitch);
this.dirZ = Math.cos(yaw) * Math.cos(pitch);
} else if (target != null) {
// Fallback: aim at target if owner is somehow unavailable
double dx = target.posX - startX;
double dy = (target.posY + target.getEyeHeight() - 0.4) - startY;
double dz = target.posZ - startZ;
@@ -229,12 +282,10 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
}
}
setPosition(endX, endY, endZ);
// Initialize end point
this.endX = posX;
this.endY = posY;
this.endZ = posZ;
// Initialize end point at start (will expand from here)
this.endX = startX;
this.endY = startY;
this.endZ = startZ;
}
private void checkBlockCollision() {
@@ -310,14 +361,14 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
}
private void checkEntityCollisionAlongLine() {
// Check collision along the entire laser line
// Use a slightly expanded AABB for the full line
double minX = Math.min(startX, endX) - laserWidth;
double minY = Math.min(startY, endY) - laserWidth;
double minZ = Math.min(startZ, endZ) - laserWidth;
double maxX = Math.max(startX, endX) + laserWidth;
double maxY = Math.max(startY, endY) + laserWidth;
double maxZ = Math.max(startZ, endZ) + laserWidth;
// Expand search AABB by entity sizes to ensure we find all potential targets
double expand = Math.max(laserWidth, 1.0);
double minX = Math.min(startX, endX) - expand;
double minY = Math.min(startY, endY) - expand;
double minZ = Math.min(startZ, endZ) - expand;
double maxX = Math.max(startX, endX) + expand;
double maxY = Math.max(startY, endY) + expand;
double maxZ = Math.max(startZ, endZ) + expand;
AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
@@ -328,7 +379,7 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
if (shouldIgnoreEntity(entity)) continue;
if (hitEntities.contains(entity.getEntityId())) continue;
// Check if entity is close to the laser line
// Check if entity's bounding box intersects with the laser line
if (isEntityOnLine(entity)) {
hitEntities.add(entity.getEntityId());
applyDamage(entity);
@@ -339,42 +390,64 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
}
/**
* Check if an entity intersects with the laser line.
* Check if an entity's bounding box intersects with the laser line.
* Uses separate XZ (horizontal) and Y (vertical) checks against
* the entity's full bounding box rather than just its center point.
*/
private boolean isEntityOnLine(EntityLivingBase entity) {
// Get entity center
double ex = entity.posX;
double ey = entity.posY + entity.height * 0.5;
double ez = entity.posZ;
// Vector from start to entity
// Project entity XZ position onto the laser line direction
double vx = ex - startX;
double vy = ey - startY;
double vz = ez - startZ;
// Project onto line direction
double dot = vx * dirX + vy * dirY + vz * dirZ;
// Clamp to line segment
// Project using horizontal direction components only
double dirLenXZ = Math.sqrt(dirX * dirX + dirZ * dirZ);
double dot;
if (dirLenXZ > 0.001) {
dot = (vx * dirX + vz * dirZ) / (dirLenXZ * dirLenXZ) * dirLenXZ;
// Remap to full 3D parameter
dot = (vx * dirX + vz * dirZ + (entity.posY + entity.height * 0.5 - startY) * dirY);
} else {
// Laser fires nearly straight up/down - use full 3D projection
dot = vx * dirX + (entity.posY + entity.height * 0.5 - startY) * dirY + vz * dirZ;
}
dot = Math.max(0, Math.min(dot, currentLength));
// Closest point on line
// Closest point on laser line at this parameter
double closestX = startX + dirX * dot;
double closestY = startY + dirY * dot;
double closestZ = startZ + dirZ * dot;
// Distance from entity to closest point
double distSq = (ex - closestX) * (ex - closestX) +
(ey - closestY) * (ey - closestY) +
(ez - closestZ) * (ez - closestZ);
// XZ distance check: entity center vs laser line point
// Use minimum collision width so visually thin lasers still hit reliably
double xzDistSq = (ex - closestX) * (ex - closestX) + (ez - closestZ) * (ez - closestZ);
double effectiveWidth = Math.max(laserWidth, 0.5);
double hitRadiusXZ = effectiveWidth * 0.5 + entity.width * 0.5;
if (xzDistSq > hitRadiusXZ * hitRadiusXZ) return false;
// Hit if within laser width + entity radius
double hitRadius = laserWidth * 0.5 + entity.width * 0.5;
return distSq <= hitRadius * hitRadius;
// Y overlap check: laser point vs entity's full height range
double entityMinY = entity.boundingBox.minY;
double entityMaxY = entity.boundingBox.maxY;
double laserHalfWidth = effectiveWidth * 0.5;
// Check if laser Y is within entity's height range (expanded by laser half-width)
if (closestY < entityMinY - laserHalfWidth) return false;
if (closestY > entityMaxY + laserHalfWidth) return false;
return true;
}
// ==================== GETTERS FOR RENDERER ====================
public void setLockVerticalDirection(boolean lock) {
this.lockVerticalDirection = lock;
}
public boolean isLockVerticalDirection() {
return lockVerticalDirection;
}
public float getLaserWidth() {
return laserWidth;
}
@@ -454,7 +527,6 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 40;
this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0;
this.targetSize = nbt.hasKey("TargetSize") ? nbt.getFloat("TargetSize") : this.size;
anchorData.readNBT(nbt);
}
@Override
@@ -476,7 +548,6 @@ public class EntityAbilityLaser extends EntityAbilityProjectile {
nbt.setInteger("ChargeDuration", chargeDuration);
nbt.setInteger("ChargeTick", chargeTick);
nbt.setFloat("TargetSize", targetSize);
anchorData.writeNBT(nbt);
}
/**
@@ -60,6 +60,10 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
private int maxTicks = 400;
private long deathWorldTime = -1;
// Preview mode
private boolean previewMode = false;
private EntityLivingBase previewOwner = null;
// Damage state
private transient int ticksSinceDamage = 0;
private transient Set<Integer> hitThisTick = new HashSet<>();
@@ -281,7 +285,16 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
target.velocityChanged = true;
}
/**
* Set up preview mode. Owner is stored directly since world entity lookup won't work.
*/
public void setupPreview(EntityLivingBase owner) {
this.previewMode = true;
this.previewOwner = owner;
}
private Entity getOwner() {
if (previewMode && previewOwner != null) return previewOwner;
if (ownerEntityId == -1) return null;
return worldObj.getEntityByID(ownerEntityId);
}
@@ -59,6 +59,16 @@ public final class SpecialKeyStatePacket extends AbstractPacket {
// Trigger ability activation on key press (rising edge)
if (keyDown && !wasDown) {
// Don't activate if player has a GUI open (not the default inventory)
if (player.openContainer != null && !(player.openContainer instanceof net.minecraft.inventory.ContainerPlayer)) {
return;
}
// Don't activate if player is riding an entity (mount)
if (player.ridingEntity != null) {
return;
}
data.abilityData.activateAbility(player);
}
}
@@ -100,9 +100,12 @@ public class AnchorPointHelper {
break;
}
x += anchorX * scale;
y += anchorY * scale;
z += anchorZ * scale;
// Rotate offsets relative to entity's body yaw
// +X = entity's right, +Y = up, +Z = entity's forward
Vec3 rotatedOffset = rotateOffsetByYaw(anchorX * scale, anchorY * scale, anchorZ * scale, bodyYaw);
x += rotatedOffset.xCoord;
y += rotatedOffset.yCoord;
z += rotatedOffset.zCoord;
return Vec3.createVectorHelper(x, y, z);
}
@@ -246,9 +249,11 @@ public class AnchorPointHelper {
double worldY = entity.posY + shoulderHeight - blockY;
double worldZ = entity.posZ + worldOffsetZ;
worldX += anchor.anchorOffsetX * scale;
worldY += anchor.anchorOffsetY * scale;
worldZ += anchor.anchorOffsetZ * scale;
// Rotate offsets relative to entity's body yaw
Vec3 rotatedOffset = rotateOffsetByYaw(anchor.anchorOffsetX * scale, anchor.anchorOffsetY * scale, anchor.anchorOffsetZ * scale, bodyYaw);
worldX += rotatedOffset.xCoord;
worldY += rotatedOffset.yCoord;
worldZ += rotatedOffset.zCoord;
return Vec3.createVectorHelper(worldX, worldY, worldZ);
}
@@ -317,9 +322,11 @@ public class AnchorPointHelper {
double y = entity.posY + entity.height * FALLBACK_ARM_HEIGHT + armLengthOffset;
double z = entity.posZ + lateralZ + forwardZ;
x += anchor.anchorOffsetX * scale;
y += anchor.anchorOffsetY * scale;
z += anchor.anchorOffsetZ * scale;
// Rotate offsets relative to entity's body yaw
Vec3 rotatedOffset = rotateOffsetByYaw(anchor.anchorOffsetX * scale, anchor.anchorOffsetY * scale, anchor.anchorOffsetZ * scale, bodyYaw);
x += rotatedOffset.xCoord;
y += rotatedOffset.yCoord;
z += rotatedOffset.zCoord;
return Vec3.createVectorHelper(x, y, z);
}
@@ -344,4 +351,17 @@ public class AnchorPointHelper {
return FRONT_HEIGHT;
}
}
/**
* Rotate an offset vector by the entity's body yaw so offsets are entity-relative.
* +X = entity's right, +Y = up, +Z = entity's forward.
* @param bodyYawRad body yaw in radians
*/
private static Vec3 rotateOffsetByYaw(double offsetX, double offsetY, double offsetZ, float bodyYawRad) {
double cos = Math.cos(bodyYawRad);
double sin = Math.sin(bodyYawRad);
double worldX = -offsetX * cos - offsetZ * sin;
double worldZ = -offsetX * sin + offsetZ * cos;
return Vec3.createVectorHelper(worldX, offsetY, worldZ);
}
}
@@ -29,7 +29,8 @@ public class Register<T> {
public static boolean isEmpty(String registryKey) {
if (REGISTERED_NAMESPACES.isEmpty()) return true;
if (REGISTERED_NAMESPACES.get(registryKey).isEmpty()) return true;
List<String> list = REGISTERED_NAMESPACES.get(registryKey);
if (list == null || list.isEmpty()) return true;
return false;
}
+173 -55
View File
@@ -100,6 +100,14 @@ public class DataAbilities {
private transient double lockedPosY = 0;
private transient double lockedPosZ = 0;
/**
* Hit scan state - forces NPC to face target.
* Set during tickCurrentAbility(), applied after super.onLivingUpdate()
* to override AI look helper rotation.
*/
private transient boolean hitScanActive = false;
private transient EntityLivingBase hitScanTarget = null;
// ═══════════════════════════════════════════════════════════════════
// CONSTRUCTOR
// ═══════════════════════════════════════════════════════════════════
@@ -117,10 +125,33 @@ public class DataAbilities {
* Should be called every tick from onLivingUpdate().
*/
public void tick() {
if (!enabled || npc.worldObj.isRemote || npc.isKilled()) {
if (npc.worldObj.isRemote) {
return;
}
// Force-stop any running ability when NPC is killed or abilities are disabled
if (!enabled || npc.isKilled()) {
if (currentAbility != null) {
removeTelegraph(currentAbility);
stopAbilityAnimation();
releaseRotationControl();
releaseLockedPosition();
currentAbility = null;
lastTarget = null;
} else {
// No ability but locks could be orphaned
if (rotationLocked || hitScanActive) releaseRotationControl();
if (positionLocked) releaseLockedPosition();
}
return;
}
// Safety: release orphaned locks if no ability is actively executing
if (currentAbility == null || !currentAbility.isExecuting()) {
if (rotationLocked || hitScanActive) releaseRotationControl();
if (positionLocked) releaseLockedPosition();
}
// Tick current ability if executing
if (currentAbility != null && currentAbility.isExecuting()) {
tickCurrentAbility();
@@ -143,11 +174,23 @@ public class DataAbilities {
// Handle phase-specific logic
switch (currentAbility.getPhase()) {
case WINDUP:
if (phaseChanged && oldPhase == AbilityPhase.BURST_DELAY) {
// Burst replay: re-enter windup - set up telegraph, sound, animation, locks
if (currentAbility.isRotationLockedDuringWindup()) {
captureLockedRotation();
}
if (currentAbility.isMovementLockedDuringWindup() && !currentAbility.hasAbilityMovement()) {
captureLockedPosition();
}
spawnTelegraph(currentAbility, target);
playAbilitySound(currentAbility.getWindUpSound());
playAbilityAnimation(currentAbility.getWindUpAnimation());
}
currentAbility.onWindUpTick(npc, target, npc.worldObj, currentAbility.getCurrentTick());
break;
case ACTIVE:
if (phaseChanged && oldPhase == AbilityPhase.WINDUP) {
if (phaseChanged && (oldPhase == AbilityPhase.WINDUP || oldPhase == AbilityPhase.BURST_DELAY)) {
// Just entered ACTIVE phase - lock telegraph position if it was following
// This commits the ability to its current target position
TelegraphInstance telegraph = currentAbility.getTelegraphInstance();
@@ -158,13 +201,13 @@ public class DataAbilities {
// Remove telegraph - it has served its purpose
removeTelegraph(currentAbility);
// Handle rotation lock transition from WINDUP to ACTIVE
// Handle rotation control transition from WINDUP to ACTIVE
if (currentAbility.isRotationLockedDuringActive()) {
if (!rotationLocked) {
captureLockedRotation();
}
} else if (rotationLocked) {
releaseLockedRotation();
releaseRotationControl();
}
// Handle position lock transition from WINDUP to ACTIVE
@@ -176,10 +219,20 @@ public class DataAbilities {
releaseLockedPosition();
}
// Burst re-fire without replay: let entity-spawning abilities spawn+fire in one step
if (oldPhase == AbilityPhase.BURST_DELAY && !currentAbility.isBurstReplayAnimations()) {
currentAbility.onBurstRefire(npc, target, npc.worldObj);
}
// Play active sound and animation
playAbilitySound(currentAbility.getActiveSound());
playAbilityAnimation(currentAbility.getActiveAnimation());
// Snap NPC to face target before execute so startMoving() reads correct rotation
if (currentAbility.isHitScanForCurrentPhase() && target != null) {
faceTarget(target);
}
// Fire execute event (cancelable)
AbilityEvent.ExecuteEvent executeEvent = new AbilityEvent.ExecuteEvent(
npc.wrappedNPC, currentAbility, target);
@@ -204,6 +257,31 @@ public class DataAbilities {
handleAbilityCompletion(target);
return;
}
// Auto-complete for burst overlap mode (entities fly independently)
// This allows entity-spawning abilities to immediately chain next burst
// without each type needing to check burst state in their onActiveTick()
// Wait until all staggered projectiles have been fired before auto-completing
if (currentAbility.isBurstEnabled() && currentAbility.isBurstOverlap()
&& currentAbility.getBurstIndex() < currentAbility.getBurstAmount()
&& currentAbility.getPhase() == AbilityPhase.ACTIVE
&& currentAbility.isReadyForBurstCompletion(currentAbility.getCurrentTick())) {
currentAbility.signalCompletion();
}
// Check if ability entered burst delay during onActiveTick or overlap auto-complete
if (currentAbility.getPhase() == AbilityPhase.BURST_DELAY) {
// Release all locks - free movement/rotation during delay
if (rotationLocked) releaseRotationControl();
if (positionLocked) releaseLockedPosition();
if (hitScanActive) releaseRotationControl();
}
break;
case BURST_DELAY:
// Free movement and rotation during burst delay
if (rotationLocked) releaseRotationControl();
if (positionLocked) releaseLockedPosition();
break;
case DAZED:
@@ -216,6 +294,15 @@ public class DataAbilities {
break;
}
// Update hit scan state - actual facing is deferred to applyRotationControl()
// which runs AFTER super.onLivingUpdate() to override AI look helper
if (currentAbility != null && currentAbility.isExecuting()
&& currentAbility.isHitScanForCurrentPhase() && target != null) {
enableHitScan(target);
} else if (hitScanActive) {
releaseRotationControl();
}
// Apply movement control if ability is still executing
if (currentAbility != null && currentAbility.isExecuting()) {
applyMovementControl();
@@ -261,7 +348,7 @@ public class DataAbilities {
NpcAPI.EVENT_BUS.post(completeEvent);
// Release locks before cleanup
releaseLockedRotation();
releaseRotationControl();
releaseLockedPosition();
// Clean up and roll cooldown (this sets currentAbility to null)
@@ -278,7 +365,7 @@ public class DataAbilities {
stopAbilityAnimation();
// Release locks
releaseLockedRotation();
releaseRotationControl();
releaseLockedPosition();
// Calculate cooldown: random(min, max) + ability offset
@@ -368,6 +455,11 @@ public class DataAbilities {
* Check if a specific ability is eligible for use.
*/
private boolean isAbilityEligible(Ability ability, EntityLivingBase target) {
// Check UserType allows NPCs
if (!ability.getAllowedBy().allowsNpc()) {
return false;
}
// Check enabled
if (!ability.isEnabled()) {
return false;
@@ -651,7 +743,7 @@ public class DataAbilities {
stopAbilityAnimation();
// Release locks
releaseLockedRotation();
releaseRotationControl();
releaseLockedPosition();
// Fire interrupt event
@@ -674,7 +766,7 @@ public class DataAbilities {
if (currentAbility != null) {
removeTelegraph(currentAbility);
stopAbilityAnimation();
releaseLockedRotation();
releaseRotationControl();
releaseLockedPosition();
currentAbility.interrupt();
currentAbility = null;
@@ -695,6 +787,11 @@ public class DataAbilities {
return false;
}
// Check UserType allows NPCs
if (!ability.getAllowedBy().allowsNpc()) {
return false;
}
// Stop any currently executing ability
stopCurrentAbility();
@@ -967,15 +1064,15 @@ public class DataAbilities {
}
// ═══════════════════════════════════════════════════════════════════
// ROTATION LOCKING
// ROTATION CONTROL
// ═══════════════════════════════════════════════════════════════════
/** Bit flag for rotation lock in the existing data watcher slot 15 bitfield */
private static final int ROTATION_LOCKED_FLAG = 16;
/** Bit flag for rotation control (LOCKED or TRACK) in data watcher slot 15 */
private static final int ROTATION_CONTROLLED_FLAG = 16;
/**
* Capture current rotation values to lock NPC's look direction.
* Called when entering a locked phase (WINDUP or ACTIVE depending on LockMovementType).
* Called when entering a LOCKED rotation phase.
*/
private void captureLockedRotation() {
lockedYaw = npc.rotationYaw;
@@ -983,41 +1080,79 @@ public class DataAbilities {
lockedRenderYawOffset = npc.renderYawOffset;
lockedPitch = npc.rotationPitch;
rotationLocked = true;
npc.setBoolFlag(true, ROTATION_LOCKED_FLAG);
npc.setBoolFlag(true, ROTATION_CONTROLLED_FLAG);
}
/**
* Release the rotation lock.
* Called when leaving the locked phase or ability completes.
* Release rotation control (both locked and hit scan).
*/
private void releaseLockedRotation() {
private void releaseRotationControl() {
rotationLocked = false;
npc.setBoolFlag(false, ROTATION_LOCKED_FLAG);
hitScanActive = false;
hitScanTarget = null;
npc.setBoolFlag(false, ROTATION_CONTROLLED_FLAG);
}
/**
* Apply locked rotation values to the NPC.
* Called AFTER super.onLivingUpdate() in EntityNPCInterface to override
* any rotation changes made by the look helper, AI tasks, or body smoothing.
* Runs on both client and server.
* Enable hit scan tracking for the given target.
*/
public void applyLockedRotation() {
private void enableHitScan(EntityLivingBase target) {
if (!hitScanActive) {
hitScanActive = true;
npc.setBoolFlag(true, ROTATION_CONTROLLED_FLAG);
}
hitScanTarget = target;
}
/**
* Snap the NPC to face the target instantly.
*/
private void faceTarget(EntityLivingBase target) {
double dx = target.posX - npc.posX;
double dz = target.posZ - npc.posZ;
double dy = (target.posY + target.getEyeHeight() * 0.5) - (npc.posY + npc.getEyeHeight());
double distXZ = Math.sqrt(dx * dx + dz * dz);
float yaw = (float) (Math.atan2(-dx, dz) * 180.0 / Math.PI);
float pitch = (float) (-(Math.atan2(dy, distXZ)) * 180.0 / Math.PI);
npc.rotationYaw = yaw;
npc.rotationYawHead = yaw;
npc.renderYawOffset = yaw;
npc.rotationPitch = pitch;
npc.prevRotationYaw = yaw;
npc.prevRotationYawHead = yaw;
npc.prevRenderYawOffset = yaw;
npc.prevRotationPitch = pitch;
}
/**
* Apply rotation control after super.onLivingUpdate() and super.onUpdate().
* Handles both LOCKED (freeze at captured values) and TRACK (face target) modes.
*
* Server: computes the correct rotation (locked values or target facing).
* Client: trusts the server-synced rotation values and prevents body smoothing override.
*/
public void applyRotationControl() {
if (npc.worldObj.isRemote) {
// Client-side: check bit 16 in the existing flags data watcher (slot 15)
boolean flagActive = npc.getBoolFlag(ROTATION_LOCKED_FLAG);
if (!flagActive) {
// Client: check single flag for any rotation control
if (!npc.getBoolFlag(ROTATION_CONTROLLED_FLAG)) {
rotationLocked = false;
return;
}
// First tick the flag is active: capture current rotation values
if (!rotationLocked) {
lockedYaw = npc.rotationYaw;
lockedYawHead = npc.rotationYawHead;
lockedRenderYawOffset = npc.renderYawOffset;
lockedPitch = npc.rotationPitch;
rotationLocked = true;
}
// Force all rotation values back to locked state
// Trust server rotation, prevent body smoothing from overriding
npc.prevRotationYaw = npc.rotationYaw;
npc.prevRotationYawHead = npc.rotationYawHead;
npc.renderYawOffset = npc.rotationYawHead;
npc.prevRenderYawOffset = npc.rotationYawHead;
npc.prevRotationPitch = npc.rotationPitch;
return;
}
// Server: apply the appropriate rotation
if (hitScanActive && hitScanTarget != null && !hitScanTarget.isDead) {
faceTarget(hitScanTarget);
} else if (rotationLocked) {
npc.rotationYaw = lockedYaw;
npc.rotationYawHead = lockedYawHead;
npc.renderYawOffset = lockedRenderYawOffset;
@@ -1026,39 +1161,22 @@ public class DataAbilities {
npc.prevRotationYawHead = lockedYawHead;
npc.prevRenderYawOffset = lockedRenderYawOffset;
npc.prevRotationPitch = lockedPitch;
return;
}
// Server-side: use stored locked values
if (!rotationLocked) {
return;
}
// Force rotation back to locked values
npc.rotationYaw = lockedYaw;
npc.rotationYawHead = lockedYawHead;
npc.renderYawOffset = lockedRenderYawOffset;
npc.rotationPitch = lockedPitch;
// Also set prev values to prevent interpolation jitter
npc.prevRotationYaw = lockedYaw;
npc.prevRotationYawHead = lockedYawHead;
npc.prevRenderYawOffset = lockedRenderYawOffset;
npc.prevRotationPitch = lockedPitch;
}
/**
* Check if rotation is currently locked.
* Check if rotation is currently controlled (locked or tracking target).
* Used by AI tasks to determine if they should try to change NPC look direction.
*/
public boolean isRotationLocked() {
return rotationLocked;
return rotationLocked || hitScanActive;
}
// ═══════════════════════════════════════════════════════════════════
// POSITION LOCKING
// ═══════════════════════════════════════════════════════════════════
/** Bit flag for position lock in the existing data watcher slot 15 bitfield */
/** Bit flag for position lock in data watcher slot 15 */
private static final int POSITION_LOCKED_FLAG = 32;
/**
@@ -2,6 +2,7 @@ package noppes.npcs;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.ParticlePacket;
@@ -792,6 +793,9 @@ public class NoppesUtilServer {
if (controller != null) {
int index = 0;
for (String uuid : controller.getCustomAbilityIds()) {
Ability ability = controller.getCustomAbility(uuid);
if (ability == null || !ability.getAllowedBy().allowsNpc()) continue;
String name = controller.getCustomAbilityName(uuid);
if (name == null || name.isEmpty()) name = uuid;
map.put(name + "\t" + uuid, index++);
@@ -509,6 +509,8 @@ public class ClientProxy extends CommonProxy {
} else {
abilityNpc = new EntityCustomNpc(Minecraft.getMinecraft().theWorld);
abilityNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
abilityNpc.height = 1.8f;
abilityNpc.width = 0.6f;
}
return new GuiNpcManageAbilities(abilityNpc, npc != null);
}
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.controllers.data.ability.AbilitySlot;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
@@ -61,6 +62,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
// Existing preset names for duplicate checking
private final Set<String> existingPresetNames = new HashSet<>();
// Pending variant selection
private String pendingTypeId = null;
public static int modIndex = 0;
public static ScrollType scrollType = ScrollType.CNPC;
@@ -197,8 +201,17 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
String displayName = availableTypesScroll.getSelected();
String typeId = displayNameToTypeId.get(displayName);
if (typeId != null) {
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
if (variants.size() > 1) {
pendingTypeId = typeId;
setSubGui(new SubGuiAbilityVariantSelect(variants));
return;
}
Ability newAbility = AbilityController.Instance.create(typeId);
if (newAbility != null) {
if (variants.size() == 1) {
variants.get(0).apply(newAbility);
}
newAbility.setId(UUID.randomUUID().toString());
npcSlots.add(AbilitySlot.inline(newAbility));
selectedAbilityIndex = npcSlots.size() - 1;
@@ -334,8 +347,12 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
Map<String, Integer> dummyMap = new HashMap<>(allAbilityTypes);
filteredAbilityTypes.clear();
filteredAbilityTypes.putAll(getFilteredData(dummyMap));
}
// Reset scroll position when changing category
if (availableTypesScroll != null) {
availableTypesScroll.resetScroll();
}
}
initGui();
}
@@ -629,7 +646,24 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
@Override
public void subGuiClosed(SubGuiInterface subgui) {
if (subgui instanceof SubGuiAbilityEditMode) {
if (subgui instanceof SubGuiAbilityVariantSelect) {
SubGuiAbilityVariantSelect variantGui = (SubGuiAbilityVariantSelect) subgui;
int idx = variantGui.getSelectedIndex();
if (idx >= 0 && pendingTypeId != null) {
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
if (newAbility != null) {
variantGui.getVariants().get(idx).apply(newAbility);
newAbility.setId(UUID.randomUUID().toString());
npcSlots.add(AbilitySlot.inline(newAbility));
selectedAbilityIndex = npcSlots.size() - 1;
updateNpcAbilitiesList();
selectAbilityByIndex(selectedAbilityIndex);
save();
}
}
pendingTypeId = null;
initGui();
} else if (subgui instanceof SubGuiAbilityEditMode) {
int mode = ((SubGuiAbilityEditMode) subgui).getResult();
if (mode < 0) return; // cancelled
@@ -324,7 +324,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
@Override
public void unFocused(GuiNpcTextField textField) {
if (textField.id < DECLARATIVE_ID_START) return;
builder.handleTextFieldEvent(textField.id, textField);
if (builder.handleTextFieldEvent(textField.id, textField)) {
initGui();
}
}
// ═══════════════════════════════════════════════════════════════════════════
@@ -0,0 +1,154 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import java.util.ArrayList;
import java.util.List;
/**
* SubGui for selecting a variant/template when creating a new ability.
* Uses a scroll list with group headers for external addon variants.
*/
public class SubGuiAbilityVariantSelect extends SubGuiInterface implements ICustomScrollListener {
private final List<AbilityVariant> variants;
private int selectedIndex = -1;
// Maps each scroll list index to a variant list index (-1 for non-selectable entries)
private final List<Integer> scrollToVariantIndex = new ArrayList<>();
public SubGuiAbilityVariantSelect(List<AbilityVariant> variants) {
this.variants = variants;
setBackground("menubg.png");
xSize = 200;
ySize = 216;
}
@Override
public void initGui() {
super.initGui();
addLabel(new GuiNpcLabel(0, "ability.selectVariant", guiLeft + 10, guiTop + 8));
// Build the unsorted scroll list with group headers
List<String> scrollList = new ArrayList<>();
scrollToVariantIndex.clear();
boolean hasBaseVariants = false;
boolean hasGroupedVariants = false;
for (AbilityVariant v : variants) {
if (v.getGroup() == null)
hasBaseVariants = true;
else
hasGroupedVariants = true;
}
// Add base (non-grouped) variants first
for (int i = 0; i < variants.size(); i++) {
if (variants.get(i).getGroup() == null) {
scrollList.add(variants.get(i).getDisplayKey());
scrollToVariantIndex.add(i);
}
}
// Blank separator between base and grouped variants
if (hasBaseVariants && hasGroupedVariants) {
scrollList.add("");
scrollToVariantIndex.add(-1);
}
// Add grouped variants with group headers
String lastGroup = null;
for (int i = 0; i < variants.size(); i++) {
AbilityVariant v = variants.get(i);
if (v.getGroup() == null)
continue;
if (!v.getGroup().equals(lastGroup)) {
scrollList.add(v.getGroup());
scrollToVariantIndex.add(-1);
lastGroup = v.getGroup();
}
scrollList.add(v.getDisplayKey());
scrollToVariantIndex.add(i);
}
GuiCustomScroll scroll = new GuiCustomScroll(this, 0);
scroll.guiLeft = guiLeft + 5;
scroll.guiTop = guiTop + 22;
scroll.setUnsortedList(scrollList);
scroll.setSize(190, 155);
// Mark blank separators and group headers as non-interactive colored entries
scroll.colors.put("", 0x000000);
if (lastGroup != null) {
for (int i = 0; i < variants.size(); i++) {
String group = variants.get(i).getGroup();
if (group != null)
scroll.colors.put(group, 0xFFFF00); // Yellow
}
}
// Restore selection in scroll
if (selectedIndex >= 0) {
for (int s = 0; s < scrollToVariantIndex.size(); s++) {
if (scrollToVariantIndex.get(s) == selectedIndex) {
scroll.selected = s;
break;
}
}
}
addScroll(scroll);
// Select / Cancel buttons
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.select"));
getButton(0).setEnabled(selectedIndex >= 0);
addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
if (scroll.id == 0 && scroll.selected >= 0 && scroll.selected < scrollToVariantIndex.size()) {
int variantIdx = scrollToVariantIndex.get(scroll.selected);
if (variantIdx >= 0) {
selectedIndex = variantIdx;
getButton(0).setEnabled(true);
}
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if (selectedIndex >= 0) {
close();
}
}
@Override
public void buttonEvent(GuiButton guibutton) {
int id = guibutton.id;
if (id == 0 && selectedIndex >= 0) {
close();
} else if (id == 1) {
selectedIndex = -1;
close();
}
}
public int getSelectedIndex() {
return selectedIndex;
}
public List<AbilityVariant> getVariants() {
return variants;
}
}
@@ -120,6 +120,9 @@ public class GuiFieldBuilder {
continue;
}
// Skip invisible fields
if (!def.isVisible()) continue;
// Section header
if (def.getType() == FieldType.SECTION_HEADER) {
y += 3;
@@ -391,7 +394,7 @@ public class GuiFieldBuilder {
/**
* Handles text field unfocus events for declarative fields.
* Call from parent GUI's unFocused(). Returns true if the event was handled.
* Call from parent GUI's unFocused(). Returns true if the value actually changed.
*/
public boolean handleTextFieldEvent(int textFieldId, GuiNpcTextField field) {
FieldDef def = textFieldMap.get(textFieldId);
@@ -399,14 +402,36 @@ public class GuiFieldBuilder {
switch (def.getType()) {
case FLOAT:
try { def.setValue(Float.parseFloat(field.getText())); } catch (NumberFormatException ignored) {}
return true;
try {
float newVal = Float.parseFloat(field.getText());
Object old = def.getValue();
float oldVal = old instanceof Number ? ((Number) old).floatValue() : 0f;
if (newVal != oldVal) {
def.setValue(newVal);
return true;
}
} catch (NumberFormatException ignored) {}
return false;
case INT:
try { def.setValue(Integer.parseInt(field.getText())); } catch (NumberFormatException ignored) {}
return true;
try {
int newVal = Integer.parseInt(field.getText());
Object old = def.getValue();
int oldVal = old instanceof Number ? ((Number) old).intValue() : 0;
if (newVal != oldVal) {
def.setValue(newVal);
return true;
}
} catch (NumberFormatException ignored) {}
return false;
case STRING:
def.setValue(field.getText());
return true;
String newVal = field.getText();
Object old = def.getValue();
String oldVal = old != null ? old.toString() : "";
if (!newVal.equals(oldVal)) {
def.setValue(newVal);
return true;
}
return false;
default:
return false;
}
@@ -65,16 +65,17 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
public void initGui() {
super.initGui();
// Toggle button - added FIRST to maintain stable buttonList index
// (prevents double-toggle when initGui() is called from actionPerformed)
String toggleLabel = showingBuiltIn ? "gui.builtin" : "gui.custom";
this.addButton(new GuiNpcButton(10, guiLeft + 368, guiTop + 56, 45, 20, toggleLabel));
// Add/Remove buttons - only show for custom animations
if (!showingBuiltIn) {
this.addButton(new GuiNpcButton(0, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
this.addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 32, 45, 20, "gui.remove"));
}
// Toggle button for Custom/Built-in - under Remove button
String toggleLabel = showingBuiltIn ? "gui.builtin" : "gui.custom";
this.addButton(new GuiNpcButton(10, guiLeft + 368, guiTop + 56, 45, 20, toggleLabel));
if (scrollAnimations == null) {
scrollAnimations = new GuiCustomScroll(this, 0, 0);
scrollAnimations.setSize(143, 185);
@@ -200,11 +201,15 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
// Toggle button
if (button.id == 10) {
showingBuiltIn = !showingBuiltIn;
// Clear selection when switching views
// Clear selection and search when switching views
selected = null;
search = "";
animation = new Animation();
currentIsBuiltIn = false;
playingAnimation = false;
scrollAnimations.clear();
// Re-request data to ensure both lists are populated
PacketClient.sendClient(new AnimationsGetPacket());
initGui();
return;
}
@@ -85,11 +85,13 @@ public class GuiNPCManageFactions extends GuiNPCInterface2 implements IScrollDat
addLabel(new GuiNpcLabel(3, "faction.hidden", guiLeft + 8, y + 5));
this.addButton(new GuiNpcButton(3, guiLeft + 100, y, 45, 20, new String[]{"gui.no", "gui.yes"}, faction.hideFaction ? 1 : 0));
getButton(3).setHoverText("faction.hidden.hover");
y += 23;
addLabel(new GuiNpcLabel(4, "faction.attacked", guiLeft + 8, y + 5));
this.addButton(new GuiNpcButton(4, guiLeft + 100, y, 45, 20, new String[]{"gui.no", "gui.yes"}, faction.getsAttacked ? 1 : 0));
getButton(4).setHoverText("faction.attacked.hover");
y += 23;
@@ -16,8 +16,10 @@ import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.NoppesUtil;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
import noppes.npcs.client.gui.advanced.SubGuiAbilityTypeSelect;
import noppes.npcs.client.gui.advanced.SubGuiAbilityVariantSelect;
import noppes.npcs.client.gui.advanced.SubGuiDuplicateNameConfirm;
import noppes.npcs.client.gui.util.AbilityPreviewExecutor;
import noppes.npcs.client.gui.util.GuiAbilityInterface;
@@ -68,6 +70,9 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
private Ability pendingSaveAbility = null;
private boolean pendingNewCreation = false;
// ==================== PENDING VARIANT ====================
private String pendingTypeId = null;
// ==================== PREVIEW ====================
private AbilityPreviewExecutor previewExecutor;
private long prevTick = 0;
@@ -343,11 +348,41 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
@Override
public void subGuiClosed(SubGuiInterface subgui) {
if (subgui instanceof SubGuiAbilityTypeSelect) {
if (subgui instanceof SubGuiAbilityVariantSelect) {
SubGuiAbilityVariantSelect variantGui = (SubGuiAbilityVariantSelect) subgui;
int idx = variantGui.getSelectedIndex();
if (idx >= 0 && pendingTypeId != null) {
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
if (newAbility != null) {
variantGui.getVariants().get(idx).apply(newAbility);
newAbility.setId(UUID.randomUUID().toString());
if (hasDuplicateName(newAbility)) {
pendingSaveAbility = newAbility;
pendingNewCreation = true;
pendingTypeId = null;
setSubGui(new SubGuiDuplicateNameConfirm());
return;
}
pendingTypeId = null;
saveAndOpenConfig(newAbility);
return;
}
}
pendingTypeId = null;
} else if (subgui instanceof SubGuiAbilityTypeSelect) {
String typeId = ((SubGuiAbilityTypeSelect) subgui).getSelectedTypeId();
if (typeId != null) {
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
if (variants.size() > 1) {
pendingTypeId = typeId;
setSubGui(new SubGuiAbilityVariantSelect(variants));
return;
}
Ability newAbility = AbilityController.Instance.create(typeId);
if (newAbility != null) {
if (variants.size() == 1) {
variants.get(0).apply(newAbility);
}
newAbility.setId(UUID.randomUUID().toString());
if (hasDuplicateName(newAbility)) {
pendingSaveAbility = newAbility;
@@ -4,15 +4,10 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
import kamkeel.npcs.controllers.data.ability.PreviewEntityHandler;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.entity.EntityAbilityBeam;
import kamkeel.npcs.entity.EntityAbilityDisc;
import kamkeel.npcs.entity.EntityAbilityLaser;
import kamkeel.npcs.entity.EntityAbilityOrb;
import kamkeel.npcs.entity.EntityAbilityProjectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.world.World;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.entity.EntityCustomNpc;
@@ -25,38 +20,39 @@ import java.util.List;
/**
* Client-side executor for previewing abilities in the GUI.
*
* Lifecycle:
* 1. WINDUP phase - plays windup animation, entities spawn and charge
* 2. ACTIVE phase - plays active animation, entities fire and move
* 3. EXTENDED phase - continues for +100 ticks after animations to see results
* 4. IDLE - preview complete
* Uses unified execution: calls the REAL ability methods (onWindUpTick, onExecute, onActiveTick)
* with previewMode=true. Abilities skip damage/effects/sounds when isPreview() returns true.
*
* Features:
* - Invisible fake target NPC placed in front of the preview NPC for targeting
* - NPC movement tracking for abilities that move the NPC (e.g. slam)
* Lifecycle:
* 1. WINDUP phase - real onWindUpTick() called, telegraph shown, entities may spawn
* 2. ACTIVE phase - real onExecute() then onActiveTick() called, physics simulated
* 3. EXTENDED phase - 100 extra ticks to observe results (entities continue updating)
* 4. IDLE - preview complete
*/
@SideOnly(Side.CLIENT)
public class AbilityPreviewExecutor {
public class AbilityPreviewExecutor implements PreviewEntityHandler {
// ==================== PREVIEW STATE ====================
private Ability previewAbility;
private EntityNPCInterface previewNpc;
private AbilityPhase phase = AbilityPhase.IDLE;
/** Executor's own phase tracking (separate from ability.getPhase()) */
private enum ExecutorPhase { IDLE, WINDUP, ACTIVE, EXTENDED }
private ExecutorPhase executorPhase = ExecutorPhase.IDLE;
private int currentTick = 0;
private boolean playing = false;
private boolean paused = false;
// ==================== TIMING ====================
private static final int EXTENDED_DURATION = 100;
private int activeDuration = 40;
private int maxPreviewDuration = 200;
// ==================== FAKE TARGET ====================
/** Invisible fake target NPC for ability targeting (placed 5 blocks in front of preview NPC) */
private EntityNPCInterface fakeTarget;
private static final double TARGET_DISTANCE = 5.0;
// ==================== NPC START POSITION ====================
/** Saved NPC position for restoring after movement abilities */
private double npcStartX, npcStartY, npcStartZ;
// ==================== PREVIEW CONTENT ====================
@@ -74,7 +70,8 @@ public class AbilityPreviewExecutor {
}
/**
* Start previewing an ability.
* Start previewing an ability using unified execution.
* Sets previewMode=true on the ability, then calls its real methods.
*/
public void startPreview(Ability ability, EntityNPCInterface npc) {
stop();
@@ -84,31 +81,35 @@ public class AbilityPreviewExecutor {
this.currentTick = 0;
this.playing = true;
this.paused = false;
this.activeDuration = ability.getPreviewActiveDuration();
this.maxPreviewDuration = ability.getMaxPreviewDuration();
// Save NPC start position for restoring later
this.npcStartX = npc.posX;
this.npcStartY = npc.posY;
this.npcStartZ = npc.posZ;
// Enable preview mode on the ability
ability.setPreviewMode(true);
ability.setPreviewEntityHandler(this);
// Create invisible fake target NPC for targeting
createFakeTarget(npc);
// Set preview target on the ability
ability.setPreviewTarget(fakeTarget);
// Start tracking NPC movement
if (parentGui != null) {
parentGui.startTrackingMovement();
}
// Use the ability's real start() method with the fake target
ability.start(fakeTarget);
if (ability.getWindUpTicks() <= 0) {
// No windup — go straight to active
this.phase = AbilityPhase.ACTIVE;
this.executorPhase = ExecutorPhase.ACTIVE;
transitionToActive();
} else {
// Normal windup flow
this.phase = AbilityPhase.WINDUP;
this.executorPhase = ExecutorPhase.WINDUP;
// Create telegraph for preview
previewTelegraph = ability.createTelegraph(npc, fakeTarget);
@@ -121,24 +122,17 @@ public class AbilityPreviewExecutor {
data.setAnimation(windUpAnim);
data.animation.paused = false;
}
// Spawn preview entity on first tick if ability spawns during windup
if (ability.spawnPreviewDuringWindup()) {
spawnPreviewEntity();
}
}
}
/**
* Create an invisible fake target NPC placed in front of the preview NPC.
* This entity is NOT rendered - it only exists for ability targeting logic.
*/
private void createFakeTarget(EntityNPCInterface npc) {
if (npc.worldObj == null) return;
try {
fakeTarget = new EntityCustomNpc(npc.worldObj);
// Position target in front of NPC based on its facing direction
float facingYaw = GuiAbilityInterface.NPC_FACING_YAW;
double yawRad = Math.toRadians(facingYaw);
double targetX = npc.posX - Math.sin(yawRad) * TARGET_DISTANCE;
@@ -153,15 +147,12 @@ public class AbilityPreviewExecutor {
}
}
/**
* Get the fake target entity for abilities that need a target.
*/
public EntityLivingBase getFakeTarget() {
return fakeTarget;
}
public void play() {
if (previewAbility == null || phase == AbilityPhase.IDLE) {
if (previewAbility == null || executorPhase == ExecutorPhase.IDLE) {
return;
}
playing = true;
@@ -178,6 +169,9 @@ public class AbilityPreviewExecutor {
public void pause() {
paused = true;
// Immediately sync prevPos to pos for NPC and all entities to prevent interpolation jitter
syncPrevPositions();
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
if (data.animation != null) {
@@ -186,10 +180,37 @@ public class AbilityPreviewExecutor {
}
}
/**
* Sync prevPos to pos for the NPC and all preview entities.
* Prevents rendering interpolation jitter when standing still or paused.
*/
private void syncPrevPositions() {
if (previewNpc != null) {
previewNpc.prevPosX = previewNpc.posX;
previewNpc.prevPosY = previewNpc.posY;
previewNpc.prevPosZ = previewNpc.posZ;
}
for (Entity entity : previewEntities) {
if (entity != null && !entity.isDead) {
entity.prevPosX = entity.posX;
entity.prevPosY = entity.posY;
entity.prevPosZ = entity.posZ;
}
}
}
public void stop() {
// Clean up the ability
if (previewAbility != null) {
previewAbility.cleanup();
previewAbility.setPreviewMode(false);
previewAbility.setPreviewEntityHandler(null);
previewAbility.reset();
}
playing = false;
paused = false;
phase = AbilityPhase.IDLE;
executorPhase = ExecutorPhase.IDLE;
currentTick = 0;
previewTelegraph = null;
@@ -211,9 +232,11 @@ public class AbilityPreviewExecutor {
previewNpc.prevPosX = npcStartX;
previewNpc.prevPosY = npcStartY;
previewNpc.prevPosZ = npcStartZ;
previewNpc.motionX = 0;
previewNpc.motionY = 0;
previewNpc.motionZ = 0;
}
// Remove fake target
fakeTarget = null;
if (previewNpc != null) {
@@ -224,13 +247,24 @@ public class AbilityPreviewExecutor {
}
/**
* Tick the preview forward.
* Tick the preview forward. Calls real ability methods.
*/
public void tick() {
if (!playing || paused || previewAbility == null || previewNpc == null) {
if (!playing || previewAbility == null || previewNpc == null) {
return;
}
if (paused) {
// Sync prevPos to pos for NPC and all entities to prevent interpolation jitter while paused
syncPrevPositions();
return;
}
// Sync NPC's prevPos to current pos BEFORE any updates to prevent jitter when standing still
previewNpc.prevPosX = previewNpc.posX;
previewNpc.prevPosY = previewNpc.posY;
previewNpc.prevPosZ = previewNpc.posZ;
currentTick++;
if (previewTelegraph != null) {
@@ -239,14 +273,14 @@ public class AbilityPreviewExecutor {
tickEntities();
switch (phase) {
switch (executorPhase) {
case WINDUP:
tickWindup();
break;
case ACTIVE:
tickActive();
break;
case IDLE:
case EXTENDED:
tickExtended();
break;
default:
@@ -255,7 +289,8 @@ public class AbilityPreviewExecutor {
}
private void tickWindup() {
previewAbility.onPreviewWindUpTick(previewNpc, currentTick);
// Call the REAL windup tick method
previewAbility.onWindUpTick(previewNpc, fakeTarget, previewNpc.worldObj, currentTick);
if (currentTick >= previewAbility.getWindUpTicks()) {
transitionToActive();
@@ -263,35 +298,41 @@ public class AbilityPreviewExecutor {
}
private void tickActive() {
previewAbility.onPreviewActiveTick(previewNpc, currentTick);
// Call the REAL active tick method
previewAbility.onActiveTick(previewNpc, fakeTarget, previewNpc.worldObj, currentTick);
if (currentTick == 1 && !previewAbility.spawnPreviewDuringWindup()) {
spawnPreviewEntity();
fireEntities();
// Simulate physics for movement abilities
simulatePhysics();
// Check if the ability signaled completion (phase went to IDLE)
if (previewAbility.getPhase() == AbilityPhase.IDLE) {
transitionToExtended();
return;
}
if (currentTick >= activeDuration) {
// Safety timeout
if (currentTick >= maxPreviewDuration) {
transitionToExtended();
}
}
private void tickExtended() {
// Continue ticking entities so they can finish their animations
if (currentTick >= EXTENDED_DURATION) {
playing = false;
}
}
private void transitionToActive() {
phase = AbilityPhase.ACTIVE;
executorPhase = ExecutorPhase.ACTIVE;
currentTick = 0;
previewTelegraph = null;
// Notify ability of execution (for movement abilities like Slam/Charge/Dash)
previewAbility.onPreviewExecute(previewNpc);
fireEntities();
// Call the REAL onExecute method (fires entities, initiates movement, etc.)
previewAbility.onExecute(previewNpc, fakeTarget, previewNpc.worldObj);
// Start active animation
Animation activeAnim = previewAbility.getActiveAnimation();
if (activeAnim != null && previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
@@ -301,7 +342,7 @@ public class AbilityPreviewExecutor {
}
private void transitionToExtended() {
phase = AbilityPhase.IDLE;
executorPhase = ExecutorPhase.EXTENDED;
currentTick = 0;
if (previewNpc != null) {
@@ -310,26 +351,40 @@ public class AbilityPreviewExecutor {
}
}
private void spawnPreviewEntity() {
Entity entity = previewAbility.createPreviewEntity(previewNpc);
if (entity != null) {
previewEntities.add(entity);
if (parentGui != null) {
parentGui.addPreviewEntity(entity);
}
}
}
/**
* Simulate basic physics for movement abilities (Slam, Charge, Dash).
* Applies gravity, drag, and ground clamping to NPC position.
*/
private void simulatePhysics() {
if (!previewAbility.hasAbilityMovement()) return;
if (previewNpc == null) return;
private void fireEntities() {
for (Entity entity : previewEntities) {
if (entity instanceof EntityAbilityOrb) {
((EntityAbilityOrb) entity).startPreviewFiring();
} else if (entity instanceof EntityAbilityBeam) {
((EntityAbilityBeam) entity).startPreviewFiring();
} else if (entity instanceof EntityAbilityDisc) {
((EntityAbilityDisc) entity).startPreviewFiring();
}
// Save previous position for interpolation
previewNpc.prevPosX = previewNpc.posX;
previewNpc.prevPosY = previewNpc.posY;
previewNpc.prevPosZ = previewNpc.posZ;
// Apply velocity
previewNpc.posX += previewNpc.motionX;
previewNpc.posY += previewNpc.motionY;
previewNpc.posZ += previewNpc.motionZ;
// Apply gravity
previewNpc.motionY -= 0.08;
previewNpc.motionY *= 0.98;
// Apply horizontal drag
previewNpc.motionX *= 0.91;
previewNpc.motionZ *= 0.91;
// Ground clamp: if below start position and falling, stop
if (previewNpc.posY < npcStartY && previewNpc.motionY < 0) {
previewNpc.posY = npcStartY;
previewNpc.motionY = 0;
previewNpc.onGround = true;
}
previewNpc.fallDistance = 0;
}
private void tickEntities() {
@@ -347,12 +402,38 @@ public class AbilityPreviewExecutor {
}
}
// ==================== PreviewEntityHandler ====================
@Override
public void onEntitySpawned(Entity entity) {
if (entity == null) return;
previewEntities.add(entity);
if (parentGui != null) {
parentGui.addPreviewEntity(entity);
}
}
@Override
public void onEntityRemoved(Entity entity) {
if (entity == null) return;
previewEntities.remove(entity);
if (parentGui != null) {
parentGui.removePreviewEntity(entity);
}
}
// ==================== GETTERS ====================
public boolean isPlaying() { return playing; }
public boolean isPaused() { return paused; }
public boolean isActive() { return playing || paused; }
public AbilityPhase getPhase() { return phase; }
public AbilityPhase getPhase() {
switch (executorPhase) {
case WINDUP: return AbilityPhase.WINDUP;
case ACTIVE: return AbilityPhase.ACTIVE;
default: return AbilityPhase.IDLE;
}
}
public int getCurrentTick() { return currentTick; }
public TelegraphInstance getTelegraph() { return previewTelegraph; }
public List<Entity> getPreviewEntities() { return previewEntities; }
@@ -364,11 +445,11 @@ public class AbilityPreviewExecutor {
return "Stopped";
} else if (paused) {
return "Paused";
} else if (phase == AbilityPhase.WINDUP) {
} else if (executorPhase == ExecutorPhase.WINDUP) {
return "Windup: " + currentTick + "/" + (previewAbility != null ? previewAbility.getWindUpTicks() : 0);
} else if (phase == AbilityPhase.ACTIVE) {
return "Active: " + currentTick + "/" + activeDuration;
} else if (phase == AbilityPhase.IDLE && playing) {
} else if (executorPhase == ExecutorPhase.ACTIVE) {
return "Active: " + currentTick + "/" + maxPreviewDuration;
} else if (executorPhase == ExecutorPhase.EXTENDED) {
return "Extended: " + currentTick + "/" + EXTENDED_DURATION;
}
return "";
@@ -11,10 +11,7 @@ import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.client.EntityUtil;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.data.ModelData;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -50,7 +47,6 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
private GuiNpcButton btnLeft, btnRight;
// ==================== NPC STATE ====================
public ModelData playerdata;
public EntityNPCInterface npc;
/** NPC starting position (saved when preview starts, used to track movement) */
@@ -85,7 +81,6 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
public GuiAbilityInterface(EntityNPCInterface npc, boolean hasMenuNpc) {
super(hasMenuNpc ? npc : null);
this.npc = npc;
this.playerdata = ((EntityCustomNpc) npc).modelData;
this.drawDefaultBackground = false;
CAMERA_ZOOM = 30f;
@@ -144,14 +139,8 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
GL11.glEnable(GL11.GL_SCISSOR_TEST);
setScissorClip(previewX, previewY, previewWidth, previewHeight);
// Get the entity to render (could be transformed player model)
EntityLivingBase renderEntity = playerdata.getEntity(npc);
if (renderEntity == null) {
renderEntity = this.npc;
}
// Sync NPC properties to render entity
EntityUtil.Copy(npc, renderEntity);
// Always use the standard NPC animation renderer for ability preview
EntityLivingBase renderEntity = this.npc;
// Set NPC facing direction (affects anchor points and visual facing)
npc.prevRenderYawOffset = npc.renderYawOffset = NPC_FACING_YAW;
@@ -207,11 +196,7 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
ClientEventHandler.renderingEntityInGUI = true;
// Render the NPC at its position delta (for movement like slam jumps)
try {
RenderManager.instance.renderEntityWithPosYaw(renderEntity, npcDeltaX, npcDeltaY, npcDeltaZ, 0.0F, partialTicks);
} catch (Exception e) {
playerdata.setEntityClass(null);
}
RenderManager.instance.renderEntityWithPosYaw(renderEntity, npcDeltaX, npcDeltaY, npcDeltaZ, 0.0F, partialTicks);
// Render preview entities at their positions relative to NPC start position
renderPreviewEntities(partialTicks);
@@ -200,7 +200,8 @@ public class GuiCustomScroll extends GuiScreen {
int k = (14 * i + 4) - scrollY;
if (k >= 4 && k + 12 < ySize) {
int xOffset = scrollHeight < ySize - 8 ? 0 : 10;
String displayString = StatCollector.translateToLocal(list.get(i));
String rawEntry = list.get(i);
String displayString = StatCollector.translateToLocal(rawEntry);
String text = "";
float maxWidth = (xSize + xOffset - 8) * 0.8f;
@@ -215,7 +216,13 @@ public class GuiCustomScroll extends GuiScreen {
text += "...";
} else
text = displayString;
if ((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
// Entries with a custom color are non-interactive (headers/separators)
Integer customColor = colors.get(rawEntry);
if (customColor != null) {
if (!text.isEmpty())
fontRendererObj.drawString(text, j, k, customColor);
} else if ((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
drawVerticalLine(j - 2, k - 4, k + 10, 0xffffffff);
drawVerticalLine(j + xSize - 18 + xOffset, k - 4, k + 10, 0xffffffff);
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k - 3, 0xffffffff);
@@ -239,13 +246,17 @@ public class GuiCustomScroll extends GuiScreen {
private int getMouseOver(int i, int j) {
i -= guiLeft;
j -= guiTop;
//fontRenderer.drawString(".", i , j, 0xffffff);
if (i >= 4 && i < xSize - 4 && j >= 4 && j < ySize) {
for (int j1 = 0; j1 < list.size(); j1++) {
if (!mouseInOption(i, j, j1)) {
continue;
}
// Skip non-interactive entries (colored headers/separators)
if (colors.containsKey(list.get(j1))) {
continue;
}
return j1;
}
@@ -308,6 +308,13 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
@Override
public void onUpdate() {
super.onUpdate();
// Re-apply locks after super.onUpdate() to override body rotation smoothing
// in EntityLivingBase.onUpdate() (func_110146_f) which runs AFTER onLivingUpdate()
// and overwrites renderYawOffset, causing a visible twitch each frame.
abilities.applyRotationControl();
abilities.applyLockedPosition();
if (!isRemote()) {
if (this.ticksExisted % 10 == 0) {
EventHooks.onNPCUpdate(this);
@@ -482,7 +489,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
super.onLivingUpdate();
// Apply locks after super.onLivingUpdate() to override AI/physics changes
abilities.applyLockedRotation();
abilities.applyRotationControl();
abilities.applyLockedPosition();
handleMountRiderState();
@@ -671,6 +678,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
if (entity instanceof EntityLivingBase)
attackingEntity = (EntityLivingBase) entity;
if (faction.isPassive)
return false;
if (attackingEntity != null && attackingEntity == getOwner())
return false;
else if (attackingEntity instanceof EntityNPCInterface) {
@@ -42,12 +42,25 @@ public class ScriptDataAbilities implements IDataAbilities {
@Override
public void addAbility(IAbility ability) {
if (ability instanceof Ability) {
data.addAbility((Ability) ability);
Ability a = (Ability) ability;
// Validate ability allows NPCs
if (!a.getAllowedBy().allowsNpc()) {
return; // Ability is PLAYER_ONLY
}
data.addAbility(a);
}
}
@Override
public void addAbilityReference(String key) {
// Validate ability exists and allows NPCs
Ability ability = AbilityController.Instance.resolveAbility(key);
if (ability == null) {
return; // Ability doesn't exist
}
if (!ability.getAllowedBy().allowsNpc()) {
return; // Ability is PLAYER_ONLY
}
data.addAbilityReference(key);
}
@@ -158,6 +171,14 @@ public class ScriptDataAbilities implements IDataAbilities {
@Override
public boolean executeAbility(String key, Object target) {
// Validate ability exists and allows NPCs
Ability ability = AbilityController.Instance.resolveAbility(key);
if (ability == null) {
return false; // Ability doesn't exist
}
if (!ability.getAllowedBy().allowsNpc()) {
return false; // Ability is PLAYER_ONLY
}
EntityLivingBase targetEntity = resolveTarget(target);
return data.executeAbility(key, targetEntity);
}
@@ -1,5 +1,7 @@
package noppes.npcs.scripted.wrapper;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import net.minecraft.entity.player.EntityPlayer;
import noppes.npcs.api.ability.IAbility;
import noppes.npcs.api.ability.IPlayerAbilityData;
@@ -26,7 +28,17 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
@Override
public void unlockAbility(String key) {
data.unlockAbility(key);
// Validate ability exists and allows players
Ability ability = AbilityController.Instance.resolveAbility(key);
if (ability == null) {
return; // Ability doesn't exist
}
if (!ability.getAllowedBy().allowsPlayer()) {
return; // Ability is NPC-only
}
// Use canonical key (registry key for built-in, UUID for custom)
String canonicalKey = ability.getId() != null ? ability.getId() : key;
data.unlockAbility(canonicalKey);
}
@Override
@@ -639,6 +639,7 @@ faction.friendly=Friendly
faction.points=Points
faction.ondeath=On death
faction.hidden=Hidden
faction.hidden.hover=Hides this faction from the player's faction standings UI
faction.default=Default
faction.attackHostile=Attack hostile factions
faction.defend=Defence faction members
@@ -647,8 +648,9 @@ faction.options=Faction Options
faction.increasepoints=Faction %s increased by %s points
faction.decreasepoints=Faction %s decreased by %s points
faction.attacked=Attacked by mobs
faction.attacked.hover=Whether vanilla mobs will target and attack NPCs in this faction
faction.passive=Is Passive
faction.passive.hover=Passive factions will not queue any attacking tasks [Good for Performance]
faction.passive.hover=Passive faction NPCs cannot be damaged and will not queue any attacking tasks [Good for Performance]
menu.inventory=Inventory
menu.display=Display
@@ -1605,11 +1607,8 @@ ability.cnpc.slam=Slam
ability.cnpc.heavy_hit=Heavy Hit
ability.cnpc.cutter=Cutter
ability.cnpc.beam=Beam
ability.cnpc.beam_dual=Beam Dual
ability.cnpc.projectile=Projectile
ability.cnpc.orb=Orb
ability.cnpc.orb_dual=Orb Dual
ability.cnpc.orb_barrage=Orb Barrage
ability.cnpc.charge=Charge
ability.cnpc.dash=Dash
ability.cnpc.teleport=Teleport
@@ -1620,7 +1619,6 @@ ability.cnpc.heal=Heal
ability.cnpc.hazard=Hazard
ability.cnpc.trap=Trap
ability.cnpc.disc=Disc
ability.cnpc.disc_dual=Disc Dual
ability.cnpc.laser_shot=Laser Shot
ability.cnpc.sweeper=Sweeper
@@ -1632,11 +1630,12 @@ ability.cnpc.sweeper=Sweeper
ability.weight=Weight
ability.windUpTicks=Wind Up
ability.cooldownTicks=Cooldown
ability.lockPosition=Lock Position
ability.lockType=Lock Type
ability.lockType.movement=Movement
ability.lockType.rotation=Rotation
ability.lockType.both=Both
ability.lockMovement=Lock Movement
ability.rotationMode=Rotation
ability.rotationPhase=Phase
ability.rotation.free=Free
ability.rotation.locked=Locked
ability.rotation.track=Track
ability.interruptible=Interruptible
ability.dazedTicks=Dazed Ticks
ability.targetingMode=Targeting
@@ -1673,14 +1672,16 @@ ability.section.boomerang=Boomerang
ability.section.explosive=Explosive
ability.section.colors=Colors
ability.section.effects=Effects
ability.section.dual=Dual
ability.section.beam1=Beam 1
ability.section.beam2=Beam 2
ability.section.disc1=Disc 1
ability.section.disc2=Disc 2
ability.section.orb1=Orb 1
ability.section.orb2=Orb 2
ability.section.barrage=Barrage
ability.section.burst=Burst
ability.section.visual=Visual
ability.section.projectile1=Projectile 1
ability.section.projectile2=Projectile 2
ability.section.projectile3=Projectile 3
ability.section.projectile4=Projectile 4
ability.section.projectile5=Projectile 5
ability.section.projectile6=Projectile 6
ability.section.projectile7=Projectile 7
ability.section.projectile8=Projectile 8
ability.section.counter=Counter
ability.section.area=Area
ability.section.damage=Damage
@@ -1724,6 +1725,10 @@ ability.effects=Effects
ability.mode=Mode
ability.duration=Duration
ability.anchorPoint=Anchor Point
ability.anchor.offsetX=Offset X
ability.anchor.offsetY=Offset Y
ability.anchor.offsetZ=Offset Z
ability.vertical=Vertical
ability.rotationSpeed=Rotation Speed
# Slam
@@ -1823,9 +1828,20 @@ ability.lightning=Lightning
ability.lightningDensity=Density
ability.lightningRadius=Radius
# Dual Energy Projectile Settings
ability.dualFire=Dual Fire
# Projectile Count / Settings
ability.projectileCount=Count
ability.dualFireDelay=Fire Delay
ability.fireDelay=Fire Delay
ability.colorOverride=Color Override
# Burst System
ability.burstEnabled=Burst
ability.burstAmount=Amount
ability.burstDelay=Delay
ability.burstReplayAnimations=Replay Animations
ability.burstOverlap=Overlap
ability.hover.burstOverlap=When enabled, projectiles from previous bursts keep flying while new ones fire
ability.hover.burstReplay=Replay windup and active animations for each burst iteration
# Ability Save/Load
ability.save.confirm=Save ability preset
@@ -1843,6 +1859,12 @@ ability.edit.mode=How should this ability be edited?
ability.cloneModify=Clone & Edit
ability.modifyParent=Edit Parent
# Ability Variant Selection
ability.selectVariant=Select Variant
ability.variant.single=Single
ability.variant.dual=Dual
ability.variant.barrage=Barrage
# Ability Type Selection
ability.selectType=Select Ability Type:
@@ -1864,8 +1886,9 @@ ability.noTypeSettings=No type-specific settings
# ═══════════════════════════════════════════════════════════════
ability.hover.weight=Higher weight = more likely to be chosen when multiple abilities available
ability.hover.lockPosition=Prevents NPC from moving or rotating while ability is charging or active
ability.hover.lockType=What to lock: Movement (pathfinding), Rotation (facing direction), or Both
ability.hover.lockMovement=Prevents NPC pathfinding during the selected phases (Windup, Active, or Both)
ability.hover.rotationMode=Free: normal AI rotation. Locked: freeze facing direction. Track: force face target for precise aiming.
ability.hover.rotationPhase=When the rotation mode applies (Windup, Active, or Both)
ability.hover.interruptible=If enabled, ability can be interrupted by taking damage
ability.hover.dazed=Stun duration in ticks if ability is interrupted (20 ticks = 1 second)
ability.hover.windup=Charge-up time before ability activates (20 ticks = 1 second)
@@ -1886,6 +1909,7 @@ ability.hover.piercing=Hits multiple targets instead of stopping on first hit
ability.hover.lightning=Add electrical effect to visuals
ability.hover.outerGlow=Enable outer glow layer around projectile
ability.hover.anchorPoint=Where on the NPC the ability spawns from
ability.hover.vertical=Disc flies standing up with thin edge facing target (like a saw blade)
ability.hover.dualCharge=Whether or not should create two anchor points
ability.hover.damage=Base damage dealt to targets
ability.hover.speed=Movement speed of projectile