mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 02:29:41 +00:00
Built In Animation System + Fixes to Defaults for Energy Projectile Abilities
This commit is contained in:
1 parent
7d2bba7b95
commit
e73054a529
20 files changed
+622
-238
No files matched your search
@@ -64,8 +64,12 @@ public abstract class Ability implements IAbility {
|
||||
protected String activeSound = ""; // Sound to play when active phase starts
|
||||
|
||||
// Animations (global animation IDs, -1 = none)
|
||||
protected int windUpAnimationId = -1; // Animation to play during wind up
|
||||
protected int activeAnimationId = -1; // Animation to play during active phase
|
||||
protected int windUpAnimationId = -1; // Animation to play during wind up (user animations)
|
||||
protected int activeAnimationId = -1; // Animation to play during active phase (user animations)
|
||||
|
||||
// Built-in animation names (empty = none, takes priority over IDs if set)
|
||||
protected String windUpAnimationName = ""; // Built-in animation name for wind up
|
||||
protected String activeAnimationName = ""; // Built-in animation name for active phase
|
||||
|
||||
// Telegraph configuration
|
||||
protected boolean showTelegraph = true;
|
||||
@@ -669,6 +673,8 @@ public abstract class Ability implements IAbility {
|
||||
nbt.setString("activeSound", activeSound);
|
||||
nbt.setInteger("windUpAnimationId", windUpAnimationId);
|
||||
nbt.setInteger("activeAnimationId", activeAnimationId);
|
||||
nbt.setString("windUpAnimationName", windUpAnimationName);
|
||||
nbt.setString("activeAnimationName", activeAnimationName);
|
||||
nbt.setBoolean("showTelegraph", showTelegraph);
|
||||
nbt.setString("telegraphType", telegraphType.name());
|
||||
nbt.setFloat("telegraphHeightOffset", telegraphHeightOffset);
|
||||
@@ -738,6 +744,8 @@ public abstract class Ability implements IAbility {
|
||||
windUpAnimationId = -1;
|
||||
}
|
||||
activeAnimationId = nbt.hasKey("activeAnimationId") ? nbt.getInteger("activeAnimationId") : -1;
|
||||
windUpAnimationName = nbt.hasKey("windUpAnimationName") ? nbt.getString("windUpAnimationName") : "";
|
||||
activeAnimationName = nbt.hasKey("activeAnimationName") ? nbt.getString("activeAnimationName") : "";
|
||||
showTelegraph = !nbt.hasKey("showTelegraph") || nbt.getBoolean("showTelegraph");
|
||||
if (nbt.hasKey("telegraphType")) {
|
||||
try {
|
||||
@@ -959,23 +967,63 @@ public abstract class Ability implements IAbility {
|
||||
public Animation getWindUpAnimation() {
|
||||
if (AnimationController.Instance == null) return null;
|
||||
|
||||
return (Animation) AnimationController.Instance.get(windUpAnimationId);
|
||||
// Built-in animation by name takes priority
|
||||
if (windUpAnimationName != null && !windUpAnimationName.isEmpty()) {
|
||||
return (Animation) AnimationController.Instance.get(windUpAnimationName);
|
||||
}
|
||||
// Fall back to user animation by ID
|
||||
if (windUpAnimationId >= 0) {
|
||||
return (Animation) AnimationController.Instance.get(windUpAnimationId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getWindUpAnimationId() {
|
||||
return windUpAnimationId;
|
||||
}
|
||||
|
||||
public void setWindUpAnimationId(int windUpAnimationId) {
|
||||
this.windUpAnimationId = windUpAnimationId;
|
||||
}
|
||||
|
||||
public String getWindUpAnimationName() {
|
||||
return windUpAnimationName;
|
||||
}
|
||||
|
||||
public void setWindUpAnimationName(String windUpAnimationName) {
|
||||
this.windUpAnimationName = windUpAnimationName != null ? windUpAnimationName : "";
|
||||
}
|
||||
|
||||
public Animation getActiveAnimation() {
|
||||
if (AnimationController.Instance == null) return null;
|
||||
|
||||
return (Animation) AnimationController.Instance.get(activeAnimationId);
|
||||
// Built-in animation by name takes priority
|
||||
if (activeAnimationName != null && !activeAnimationName.isEmpty()) {
|
||||
return (Animation) AnimationController.Instance.get(activeAnimationName);
|
||||
}
|
||||
// Fall back to user animation by ID
|
||||
if (activeAnimationId >= 0) {
|
||||
return (Animation) AnimationController.Instance.get(activeAnimationId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getActiveAnimationId() {
|
||||
return activeAnimationId;
|
||||
}
|
||||
|
||||
public void setActiveAnimationId(int activeAnimationId) {
|
||||
this.activeAnimationId = activeAnimationId;
|
||||
}
|
||||
|
||||
public String getActiveAnimationName() {
|
||||
return activeAnimationName;
|
||||
}
|
||||
|
||||
public void setActiveAnimationName(String activeAnimationName) {
|
||||
this.activeAnimationName = activeAnimationName != null ? activeAnimationName : "";
|
||||
}
|
||||
|
||||
public boolean isShowTelegraph() {
|
||||
return showTelegraph;
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
package kamkeel.npcs.controllers.data.ability;
|
||||
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static kamkeel.npcs.controllers.data.ability.AbilityPhase.*;
|
||||
|
||||
public enum AbilityAnimation {
|
||||
ABILITYORB("Ability_Orb_Windup", WINDUP),
|
||||
ABILITYBEAM("Ability_Beam_Windup", "Ability_Beam_Active");
|
||||
private final HashMap<AbilityPhase, String> animationNames = new HashMap<>();
|
||||
|
||||
AbilityAnimation(String idle, String windUp, String active, String recovery) {
|
||||
animationNames.put(IDLE, idle);
|
||||
animationNames.put(WINDUP, windUp);
|
||||
animationNames.put(ACTIVE, active);
|
||||
animationNames.put(DAZED, recovery);
|
||||
}
|
||||
|
||||
AbilityAnimation(String idle, String windUp, String active) {
|
||||
animationNames.put(IDLE, idle);
|
||||
animationNames.put(WINDUP, windUp);
|
||||
animationNames.put(ACTIVE, active);
|
||||
}
|
||||
|
||||
AbilityAnimation(String windUp, String active) {
|
||||
animationNames.put(WINDUP, windUp);
|
||||
animationNames.put(ACTIVE, active);
|
||||
}
|
||||
|
||||
AbilityAnimation(String anim, AbilityPhase phase) {
|
||||
animationNames.put(phase, anim);
|
||||
}
|
||||
|
||||
public String fileName(AbilityPhase phase) {
|
||||
return animationNames.get(phase);
|
||||
}
|
||||
|
||||
public File getFile(AbilityPhase phase) {
|
||||
if (animationNames.get(phase).isEmpty() || animationNames.get(phase).equals("N/A"))
|
||||
return null;
|
||||
|
||||
return getFileFromName(animationNames.get(phase));
|
||||
}
|
||||
|
||||
public Animation getAnimation(AbilityPhase phase) {
|
||||
try {
|
||||
File file = getFile(phase);
|
||||
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Animation animation = new Animation();
|
||||
animation.readFromNBT(NBTJsonUtil.LoadFile(file));
|
||||
|
||||
return animation;
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Animation idle() {
|
||||
return getAnimation(IDLE);
|
||||
}
|
||||
|
||||
public Animation windUp() {
|
||||
return getAnimation(WINDUP);
|
||||
}
|
||||
|
||||
public Animation active() {
|
||||
return getAnimation(ACTIVE);
|
||||
}
|
||||
|
||||
public Animation dazed() {
|
||||
return getAnimation(DAZED);
|
||||
}
|
||||
|
||||
private File getFileFromName(String fileName) {
|
||||
try (InputStream stream = CustomNpcs.class.getResourceAsStream("/internal/animations/" + name() + "/" + fileName + ".json")) {
|
||||
|
||||
File file = new File("temp");
|
||||
|
||||
FileUtils.copyInputStreamToFile(stream, file);
|
||||
|
||||
return file;
|
||||
} catch (Exception i) {
|
||||
LogWriter.except(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -121,10 +121,13 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
|
||||
if (discEntity != null && !discEntity.isDead) {
|
||||
discEntity.startMoving(target);
|
||||
}
|
||||
discEntity = null;
|
||||
|
||||
// Disc entity manages itself - ability is done
|
||||
signalCompletion();
|
||||
// If movement is locked during active phase, keep ability active until entity dies
|
||||
// Otherwise signal completion immediately
|
||||
if (!lockMovement.locksActive()) {
|
||||
discEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,6 +157,11 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) {
|
||||
// If we're tracking the entity for movement lock, check if it's dead
|
||||
if (discEntity != null && discEntity.isDead) {
|
||||
discEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ 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.AbilityAnimation;
|
||||
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
|
||||
import kamkeel.npcs.controllers.data.ability.LockMovementType;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
@@ -13,13 +12,12 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
|
||||
import noppes.npcs.client.gui.advanced.ability.SubGuiAbilityEnergyBeam;
|
||||
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
|
||||
import noppes.npcs.api.ability.type.IAbilityEnergyBeam;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
/**
|
||||
@@ -71,9 +69,7 @@ public class AbilityEnergyBeam extends Ability implements IAbilityEnergyBeam {
|
||||
private float lightningRadius = 0.5f;
|
||||
|
||||
// Anchor point for charging position
|
||||
private AnchorPoint anchorPoint = AnchorPoint.FRONT;
|
||||
|
||||
private final AbilityAnimation animation = AbilityAnimation.ABILITYBEAM;
|
||||
private AnchorPoint anchorPoint = AnchorPoint.RIGHT_HAND;
|
||||
|
||||
// Transient state for beam entity (used during windup charging)
|
||||
private transient EntityAbilityBeam beamEntity = null;
|
||||
@@ -89,6 +85,9 @@ public class AbilityEnergyBeam extends Ability implements IAbilityEnergyBeam {
|
||||
this.lockMovement = 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";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,10 +122,13 @@ public class AbilityEnergyBeam extends Ability implements IAbilityEnergyBeam {
|
||||
if (beamEntity != null && !beamEntity.isDead) {
|
||||
beamEntity.startFiring(target);
|
||||
}
|
||||
beamEntity = null;
|
||||
|
||||
// Beam entity manages itself - ability is done
|
||||
signalCompletion();
|
||||
// If movement is locked during active phase, keep ability active until entity dies
|
||||
// Otherwise signal completion immediately
|
||||
if (!lockMovement.locksActive()) {
|
||||
beamEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,6 +161,11 @@ public class AbilityEnergyBeam extends Ability implements IAbilityEnergyBeam {
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) {
|
||||
// If we're tracking the entity for movement lock, check if it's dead
|
||||
if (beamEntity != null && beamEntity.isDead) {
|
||||
beamEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -313,23 +320,6 @@ public class AbilityEnergyBeam extends Ability implements IAbilityEnergyBeam {
|
||||
public float getLightningRadius() { return lightningRadius; }
|
||||
public void setLightningRadius(float lightningRadius) { this.lightningRadius = lightningRadius; }
|
||||
|
||||
|
||||
@Override
|
||||
public Animation getWindUpAnimation() {
|
||||
if (windUpAnimationId == -1)
|
||||
return animation.windUp();
|
||||
|
||||
return super.getWindUpAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Animation getActiveAnimation() {
|
||||
if (activeAnimationId == -1)
|
||||
return animation.active();
|
||||
|
||||
return super.getActiveAnimation();
|
||||
}
|
||||
|
||||
public AnchorPoint getAnchorPointEnum() { return anchorPoint; }
|
||||
public void setAnchorPointEnum(AnchorPoint anchorPoint) { this.anchorPoint = anchorPoint; }
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
|
||||
private float lightningDensity = 0.15f;
|
||||
private float lightningRadius = 0.5f;
|
||||
|
||||
// Transient state for laser entity (used for movement locking)
|
||||
private transient EntityAbilityLaser laserEntity = null;
|
||||
|
||||
public AbilityLaserShot() {
|
||||
this.typeId = "ability.cnpc.laser_shot";
|
||||
this.name = "Laser Shot";
|
||||
@@ -111,7 +114,7 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
|
||||
double spawnY = npc.posY + npc.getEyeHeight() * 0.8;
|
||||
double spawnZ = npc.posZ;
|
||||
|
||||
EntityAbilityLaser laser = new EntityAbilityLaser(
|
||||
laserEntity = new EntityAbilityLaser(
|
||||
world, npc, target,
|
||||
spawnX, spawnY, spawnZ,
|
||||
laserWidth, innerColor, outerColor, outerColorEnabled, outerColorWidth,
|
||||
@@ -123,15 +126,23 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
|
||||
lightningEffect, lightningDensity, lightningRadius
|
||||
);
|
||||
|
||||
world.spawnEntityInWorld(laser);
|
||||
world.spawnEntityInWorld(laserEntity);
|
||||
|
||||
// Laser entity manages itself - ability is done
|
||||
signalCompletion();
|
||||
// If movement is locked during active phase, keep ability active until entity dies
|
||||
// Otherwise signal completion immediately
|
||||
if (!lockMovement.locksActive()) {
|
||||
laserEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) {
|
||||
// Laser entity manages itself
|
||||
// If we're tracking the entity for movement lock, check if it's dead
|
||||
if (laserEntity != null && laserEntity.isDead) {
|
||||
laserEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,6 +153,15 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
|
||||
public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// Despawn laser entity if still alive
|
||||
if (laserEntity != null && !laserEntity.isDead) {
|
||||
laserEntity.setDead();
|
||||
}
|
||||
laserEntity = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTypeNBT(NBTTagCompound nbt) {
|
||||
nbt.setFloat("laserWidth", laserWidth);
|
||||
|
||||
@@ -3,7 +3,6 @@ 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.AbilityAnimation;
|
||||
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
|
||||
import kamkeel.npcs.controllers.data.ability.LockMovementType;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
@@ -19,7 +18,6 @@ import net.minecraft.world.World;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
|
||||
import noppes.npcs.client.gui.advanced.ability.SubGuiAbilityOrb;
|
||||
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.api.ability.type.IAbilityOrb;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
@@ -70,13 +68,11 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
|
||||
private int lightningFadeTime = 6; // Ticks before lightning fades out
|
||||
|
||||
// Anchor point for charging position
|
||||
private AnchorPoint anchorPoint = AnchorPoint.FRONT;
|
||||
private AnchorPoint anchorPoint = AnchorPoint.RIGHT_HAND;
|
||||
|
||||
// Transient state for orb entity (used during windup charging)
|
||||
private transient EntityAbilityOrb orbEntity = null;
|
||||
|
||||
private final AbilityAnimation animation = AbilityAnimation.ABILITYORB;
|
||||
|
||||
public AbilityOrb() {
|
||||
this.typeId = "ability.cnpc.orb";
|
||||
this.name = "Orb";
|
||||
@@ -88,6 +84,8 @@ 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";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,10 +120,13 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
|
||||
if (orbEntity != null && !orbEntity.isDead) {
|
||||
orbEntity.startMoving(target);
|
||||
}
|
||||
orbEntity = null;
|
||||
|
||||
// Orb entity manages itself - ability is done
|
||||
signalCompletion();
|
||||
// If movement is locked during active phase, keep ability active until entity dies
|
||||
// Otherwise signal completion immediately
|
||||
if (!lockMovement.locksActive()) {
|
||||
orbEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,7 +155,11 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) {
|
||||
// Nothing to do - entity manages itself
|
||||
// If we're tracking the entity for movement lock, check if it's dead
|
||||
if (orbEntity != null && orbEntity.isDead) {
|
||||
orbEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -467,14 +472,6 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
|
||||
this.anchorPoint = anchorPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Animation getWindUpAnimation() {
|
||||
if (windUpAnimationId != -1)
|
||||
return super.getWindUpAnimation();
|
||||
|
||||
return animation.windUp();
|
||||
}
|
||||
|
||||
public int getAnchorPoint() {
|
||||
return anchorPoint.getId();
|
||||
}
|
||||
|
||||
@@ -91,8 +91,6 @@ public class AbilitySweeper extends Ability implements IAbilitySweeper {
|
||||
return;
|
||||
}
|
||||
|
||||
LogWriter.info("[Sweeper] onExecute called at NPC pos " + npc.posX + ", " + npc.posY + ", " + npc.posZ);
|
||||
|
||||
// Spawn the entity that handles BOTH visuals AND damage
|
||||
activeEntity = new EntityAbilitySweeper(world, npc, target,
|
||||
beamLength, beamWidth, beamHeight,
|
||||
@@ -102,14 +100,19 @@ public class AbilitySweeper extends Ability implements IAbilitySweeper {
|
||||
lockOnTarget);
|
||||
world.spawnEntityInWorld(activeEntity);
|
||||
|
||||
LogWriter.info("[Sweeper] Spawned sweeper entity");
|
||||
// Entity manages itself - completion signaled from onActiveTick when entity dies
|
||||
// If movement is locked during active phase, keep ability active until entity dies
|
||||
// Otherwise signal completion immediately
|
||||
if (!lockMovement.locksActive()) {
|
||||
activeEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) {
|
||||
// Entity handles everything - check if entity finished its rotations
|
||||
if (activeEntity == null || activeEntity.isDead) {
|
||||
// If we're tracking the entity for movement lock, check if it's dead
|
||||
if (activeEntity != null && activeEntity.isDead) {
|
||||
activeEntity = null;
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,5 +44,6 @@ public final class AnimationsGetPacket extends AbstractPacket {
|
||||
return;
|
||||
|
||||
NoppesUtilServer.sendAnimationDataAll((EntityPlayerMP) player);
|
||||
NoppesUtilServer.sendBuiltInAnimationData((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user