Add Custom Particle Handling and Preset Handling to Trap and Hazards

This commit is contained in:
Kam committed 2026-02-12 18:15:41 -05:00
1 parent bf3391a1a8
commit 6f9cafa141
13 files changed
+318 -79

No files matched your search

@@ -252,13 +252,30 @@ public class RenderAbilityZone extends Render {
// 6. Particles
if (c.particles && c.newTick && c.particleDensity > 0) {
if (c.particleDir != null && !c.particleDir.isEmpty()) {
spawnCustomFXParticle(c);
if (c.particleDir.startsWith("mc:")) {
spawnVanillaParticle(c);
} else {
spawnCustomFXParticle(c);
}
} else {
spawnDefaultParticles(c);
}
}
}
/** Spawn vanilla Minecraft particles using mc: prefix (e.g. "mc:flame"). */
private void spawnVanillaParticle(Ctx c) {
String particleName = c.particleDir.substring(3);
int count = Math.round(3 * c.particleDensity);
for (int i = 0; i < count; i++) {
double[] pos = randomPosInZone(c);
double[] motion = getMotionForStyle(c.particleMotion);
c.zone.worldObj.spawnParticle(particleName,
c.zone.posX + pos[0], c.zone.posY + pos[1], c.zone.posZ + pos[2],
motion[0], motion[1], motion[2]);
}
}
/** Spawn CustomFX particles using a texture directory. */
private void spawnCustomFXParticle(Ctx c) {
int count = Math.round(3 * c.particleDensity);
@@ -267,18 +284,26 @@ public class RenderAbilityZone extends Render {
double[] motion = getMotionForStyle(c.particleMotion);
CustomFX fx = new CustomFX(c.zone.worldObj, null, c.particleDir,
c.zone.posX + pos[0], c.zone.posY + pos[1], c.zone.posZ + pos[2],
motion[0], motion[1], motion[2]);
0, 0, 0);
fx.motionX = motion[0];
fx.motionY = motion[1];
fx.motionZ = motion[2];
fx.setMaxAge(20 + RANDOM.nextInt(20));
fx.width = -1;
fx.height = -1;
fx.scaleX1 = c.particleScale * 10.0f;
fx.scaleY1 = c.particleScale * 10.0f;
fx.width = c.particleSize;
fx.height = c.particleSize;
fx.scaleX2 = fx.scaleX1;
fx.scaleY2 = fx.scaleY1;
fx.scaleXRate = 0;
fx.scaleYRate = 0;
fx.HEXColor = c.zone.getInnerColor();
fx.facePlayer = true;
fx.glows = c.particleGlow;
fx.noClip = true;
fx.alpha1 = 0.8f;
fx.alpha2 = 0.0f;
fx.alphaRate = 0.04f;
fx.alphaRate = -0.04f;
Minecraft.getMinecraft().effectRenderer.addEffect(fx);
}
}
@@ -404,6 +404,16 @@ public abstract class Ability implements IAbility {
return caster instanceof EntityPlayer;
}
/**
* Whether the telegraph should remain visible during the ACTIVE phase.
* Default: false (telegraph removed at WINDUP→ACTIVE transition).
* Override for abilities where the active phase IS the attack (e.g., sweeping/spinning attacks)
* so the telegraph stays visible while damage is being dealt.
*/
public boolean keepTelegraphDuringActive() {
return false;
}
/**
* Returns true if this ability controls NPC movement during ACTIVE phase.
* When true, AI pathfinding will be blocked during ability execution.
@@ -20,7 +20,8 @@ public class AbilityEffect {
BLINDNESS("potion.blindness", Potion.blindness.id),
NAUSEA("potion.confusion", Potion.confusion.id),
HUNGER("potion.hunger", Potion.hunger.id),
MINING_FATIGUE("potion.digSlowDown", Potion.digSlowdown.id);
MINING_FATIGUE("potion.digSlowDown", Potion.digSlowdown.id),
BURN("ability.effect.burn", -1);
private final String langKey;
private final int potionId;
@@ -83,6 +84,11 @@ public class AbilityEffect {
return;
}
if (type == EffectType.BURN) {
entity.setFire(Math.max(1, durationTicks / 20));
return;
}
int potionId = type.getPotionId();
if (potionId >= 0) {
entity.addPotionEffect(new PotionEffect(potionId, durationTicks, amplifier));
@@ -38,9 +38,11 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
// Runtime state (transient)
private transient double startX, startY, startZ;
private transient double prevTickX, prevTickZ;
private transient Vec3 chargeDirection;
private transient Set<Integer> hitEntities = new HashSet<>();
private transient float lockedYaw;
private transient int maxActiveTicks;
public AbilityCharge() {
this.typeId = "ability.cnpc.charge";
@@ -119,8 +121,13 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
startX = caster.posX;
startY = caster.posY;
startZ = caster.posZ;
prevTickX = caster.posX;
prevTickZ = caster.posZ;
hitEntities.clear();
// Safety timeout: expected ticks + buffer to prevent infinite charge
maxActiveTicks = chargeSpeed > 0 ? (int)(maxRange / chargeSpeed) + 10 : 10;
// If direction wasn't set during windup (shouldn't happen), set it now
if (chargeDirection == null) {
lockChargeDirection(caster, target);
@@ -140,13 +147,36 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
@Override
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
if (chargeDirection == null) return;
// Safety timeout or missing state: force-complete to prevent stuck NPC
if (!isPreview() && (chargeDirection == null || tick > maxActiveTicks)) {
stopMomentum(caster);
signalCompletion();
return;
}
if (chargeDirection == null) {
signalCompletion();
return;
}
// Enforce rotation every tick
if (!isPreview()) {
enforceLockedRotation(caster);
}
// Stall detection: if entity hasn't moved since last tick, it's stuck against a wall
if (!isPreview() && tick > 1) {
double dx = caster.posX - prevTickX;
double dz = caster.posZ - prevTickZ;
if (dx * dx + dz * dz < 0.0001) {
stopMomentum(caster);
signalCompletion();
return;
}
}
prevTickX = caster.posX;
prevTickZ = caster.posZ;
// Calculate distance traveled
double distanceTraveled = Math.sqrt(
Math.pow(caster.posX - startX, 2) +
@@ -155,11 +185,7 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
// Check if reached max distance
if (distanceTraveled >= maxRange) {
caster.motionX = 0;
caster.motionZ = 0;
if (!isPreview()) {
caster.velocityChanged = true;
}
stopMomentum(caster);
signalCompletion();
return;
}
@@ -240,6 +266,7 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
super.reset();
chargeDirection = null;
hitEntities.clear();
maxActiveTicks = 0;
}
@Override
@@ -3,6 +3,8 @@ 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.telegraph.Telegraph;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
@@ -60,6 +62,8 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
// Runtime state
private transient Set<Integer> hitEntities = new HashSet<>();
private transient float currentRotation = 0.0f;
private transient boolean activeSoundPlayed = false;
private transient float sweepBaseYaw = 0.0f;
public AbilityCutter() {
this.typeId = "ability.cnpc.cutter";
@@ -86,6 +90,54 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
return new TargetingMode[]{TargetingMode.AOE_SELF};
}
/**
* Calculate how many ticks the active sweep phase takes.
* SWIPE: arcAngle / sweepSpeed ticks
* SPIN: spinDurationTicks
*/
private int getActiveDurationTicks() {
if (sweepMode == SweepMode.SPIN) {
return spinDurationTicks;
}
return sweepSpeed > 0 ? (int) Math.ceil(arcAngle / sweepSpeed) : 1;
}
@Override
public boolean keepTelegraphDuringActive() {
return true;
}
/**
* Creates a CONE telegraph that lasts through both windup and active sweep phases.
* Warning color transitions when the sweep actually begins (at windUpTicks).
*/
@Override
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
if (!isShowTelegraph() || getTelegraphType() == TelegraphType.NONE) {
return null;
}
Telegraph telegraph = Telegraph.cone(getTelegraphLength(), getTelegraphAngle());
int totalDuration = windUpTicks + getActiveDurationTicks();
telegraph.setDurationTicks(totalDuration);
telegraph.setColor(windUpColor);
telegraph.setWarningColor(activeColor);
// Warning transition starts when the sweep begins (active phase)
telegraph.setWarningStartTick(windUpTicks);
telegraph.setHeightOffset(telegraphHeightOffset);
double groundY = findGroundLevel(caster.worldObj, caster.posX, caster.posY, caster.posZ);
TelegraphInstance instance = new TelegraphInstance(telegraph, caster.posX, groundY, caster.posZ, caster.rotationYaw);
instance.setCasterEntityId(caster.getEntityId());
instance.setEntityIdToFollow(caster.getEntityId());
if (target != null && !isRotationLockedDuringWindup()) {
instance.setTargetEntityId(target.getEntityId());
}
return instance;
}
@Override
public float getTelegraphRadius() {
return range;
@@ -105,6 +157,21 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
hitEntities.clear();
currentRotation = -arcAngle / 2.0f;
activeSoundPlayed = false;
// Lock sweep direction toward target at execute time to prevent
// AI look-at jitter from misdirecting the sweep at close range
if (target != null) {
double dx = target.posX - caster.posX;
double dz = target.posZ - caster.posZ;
if (dx * dx + dz * dz > 0.0001) {
sweepBaseYaw = (float) Math.toDegrees(Math.atan2(-dx, dz));
} else {
sweepBaseYaw = caster.rotationYaw;
}
} else {
sweepBaseYaw = caster.rotationYaw;
}
}
@Override
@@ -115,6 +182,12 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
case SWIPE:
float prevRotation = currentRotation;
currentRotation += sweepSpeed;
// Play active sound when sweep reaches center (where target typically stands)
if (!activeSoundPlayed && currentRotation >= 0) {
playActiveSound(caster, world);
}
if (currentRotation > arcAngle / 2.0f) {
if (!isPreview()) {
performSweepDamageRange(caster, world, innerRadius, range, prevRotation, arcAngle / 2.0f);
@@ -128,6 +201,11 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
break;
case SPIN:
// Play active sound at spin start
if (!activeSoundPlayed) {
playActiveSound(caster, world);
}
if (tick >= spinDurationTicks) {
signalCompletion();
return;
@@ -142,6 +220,13 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
}
}
private void playActiveSound(EntityLivingBase caster, World world) {
activeSoundPlayed = true;
if (activeSound != null && !activeSound.isEmpty()) {
world.playSoundAtEntity(caster, activeSound, 1.0f, 1.0f);
}
}
/**
* Check for entities between two sweep angles, ensuring no gaps between ticks.
* For SWIPE mode, this covers the continuous arc from startAngle to endAngle.
@@ -171,7 +256,7 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
double dist = Math.sqrt(dx * dx + dz * dz);
if (dist < minDist || dist > maxDist) continue;
if (!isInSweepRange(dx, dz, caster.rotationYaw, minAngle, maxAngle)) continue;
if (!isInSweepRange(dx, dz, sweepBaseYaw, minAngle, maxAngle)) continue;
hitEntities.add(entity.getEntityId());
@@ -214,12 +299,16 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
hitEntities.clear();
currentRotation = 0.0f;
activeSoundPlayed = false;
sweepBaseYaw = 0.0f;
}
@Override
public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {
hitEntities.clear();
currentRotation = 0.0f;
activeSoundPlayed = false;
sweepBaseYaw = 0.0f;
}
@Override
@@ -148,6 +148,8 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
addPresetFieldDef(defs);
defs.addAll(Arrays.asList(
FieldDef.row(
FieldDef.intField("ability.duration", this::getDurationTicks, this::setDurationTicks).range(1, 2000),
@@ -35,7 +35,7 @@ public class AbilityShockwave extends Ability implements IAbilityShockwave {
this.typeId = "ability.cnpc.shockwave";
this.name = "Shockwave";
this.targetingMode = TargetingMode.AOE_SELF;
this.maxRange = 15.0f;
this.maxRange = 8.0f;
this.lockMovement = LockMovementType.WINDUP_AND_ACTIVE;
this.cooldownTicks = 0;
this.windUpTicks = 25;
@@ -157,6 +157,8 @@ public class AbilityTrap extends AbilityZone implements IAbilityTrap {
@SideOnly(Side.CLIENT)
@Override
public void getAbilityDefinitions(List<FieldDef> defs) {
addPresetFieldDef(defs);
defs.addAll(Arrays.asList(
FieldDef.row(
FieldDef.intField("ability.duration", this::getDurationTicks, this::setDurationTicks).range(1, 2000),
@@ -1,6 +1,7 @@
package kamkeel.npcs.controllers.data.ability.type;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityEffect;
import kamkeel.npcs.controllers.data.ability.LockMovementType;
import kamkeel.npcs.controllers.data.ability.TargetingMode;
import kamkeel.npcs.controllers.data.ability.UserType;
@@ -17,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import noppes.npcs.client.gui.SubGuiZonePresetSelector;
import noppes.npcs.client.gui.builder.FieldDef;
import cpw.mods.fml.relauncher.Side;
@@ -243,36 +245,61 @@ public abstract class AbilityZone extends Ability {
* Apply preset defaults by style name.
*/
private void applyPresetDefaults(String styleName) {
effects.clear();
particleDir = "";
switch (styleName) {
case "TOXIC":
groundFill = true; groundAlpha = 0.30f; rings = true; ringCount = 3;
border = false; borderSpeed = 1.0f; accents = true; accentStyle = 1;
lightning = false; particles = true; particleMotion = 0; particleGlow = true;
lightning = false; particles = true; particleDensity = 1.5f; particleScale = 0.8f;
particleMotion = 1; particleGlow = true; particleDir = "mc:mobSpell";
colorData.innerColor = 0x44DD44; colorData.outerColor = 0x116611;
windUpColor = 0x6044DD44; activeColor = 0xC044FF44;
effects.add(new AbilityEffect(AbilityEffect.EffectType.POISON, 100, 0));
break;
case "INFERNO":
groundFill = true; groundAlpha = 0.35f; rings = true; ringCount = 3;
border = true; borderSpeed = 2.0f; accents = true; accentStyle = 2;
lightning = false; particles = true; particleMotion = 0; particleGlow = true;
lightning = false; particles = true; particleDensity = 2.0f; particleScale = 1.2f;
particleMotion = 0; particleGlow = true; particleDir = "mc:flame";
colorData.innerColor = 0xFF6611; colorData.outerColor = 0xCC2200;
windUpColor = 0x60FF6611; activeColor = 0xC0FF4400;
effects.add(new AbilityEffect(AbilityEffect.EffectType.BURN, 60, 0));
break;
case "ARCANE":
groundFill = true; groundAlpha = 0.20f; rings = true; ringCount = 1;
border = true; borderSpeed = 0.8f; accents = true; accentStyle = 0;
lightning = false; particles = true; particleMotion = 1; particleGlow = true;
lightning = false; particles = true; particleDensity = 1.0f; particleScale = 1.0f;
particleMotion = 1; particleGlow = true; particleDir = "mc:portal";
colorData.innerColor = 0xAA44FF; colorData.outerColor = 0x6622BB;
windUpColor = 0x60AA44FF; activeColor = 0xC0CC66FF;
effects.add(new AbilityEffect(AbilityEffect.EffectType.WEAKNESS, 100, 0));
break;
case "ELECTRIC":
groundFill = true; groundAlpha = 0.15f; rings = false; ringCount = 1;
border = false; borderSpeed = 1.0f; accents = false; accentStyle = 0;
lightning = true; particles = true; particleMotion = 2; particleGlow = true;
lightning = true; particles = true; particleDensity = 0.8f; particleScale = 0.6f;
particleMotion = 2; particleGlow = true; particleDir = "mc:enchantmenttable";
colorData.innerColor = 0x4488FF; colorData.outerColor = 0x2244BB;
windUpColor = 0x604488FF; activeColor = 0xC066AAFF;
effects.add(new AbilityEffect(AbilityEffect.EffectType.MINING_FATIGUE, 80, 1));
break;
case "FROST":
groundFill = true; groundAlpha = 0.25f; rings = true; ringCount = 3;
border = true; borderSpeed = 0.3f; accents = true; accentStyle = 0;
lightning = false; particles = true; particleMotion = 1; particleGlow = true;
lightning = false; particles = true; particleDensity = 1.5f; particleScale = 1.0f;
particleMotion = 1; particleGlow = true; particleDir = "mc:snowshovel";
colorData.innerColor = 0x88CCFF; colorData.outerColor = 0x4488CC;
windUpColor = 0x6088CCFF; activeColor = 0xC0AADDFF;
effects.add(new AbilityEffect(AbilityEffect.EffectType.SLOWNESS, 100, 1));
break;
case "DEFAULT":
groundFill = true; groundAlpha = 0.25f; rings = true; ringCount = 3;
border = true; borderSpeed = 1.0f; accents = true; accentStyle = 0;
lightning = false; particles = false; particleMotion = 0; particleGlow = true;
lightning = false; particles = false; particleDensity = 1.0f; particleScale = 1.0f;
particleMotion = 0; particleGlow = true;
colorData.innerColor = 0xCCCCCC; colorData.outerColor = 0x666666;
windUpColor = 0x60CCCCCC; activeColor = 0xC0FFFFFF;
break;
default:
break;
@@ -285,7 +312,7 @@ public abstract class AbilityZone extends Ability {
*/
@SideOnly(Side.CLIENT)
public enum ZonePreset {
CUSTOM, DEFAULT, TOXIC, INFERNO, ARCANE, ELECTRIC, FROST;
DEFAULT, TOXIC, INFERNO, ARCANE, ELECTRIC, FROST;
@Override
public String toString() {
@@ -293,44 +320,6 @@ public abstract class AbilityZone extends Ability {
}
}
/**
* Check current field values against each preset, return matching preset or CUSTOM.
*/
@SideOnly(Side.CLIENT)
public ZonePreset getCurrentPreset() {
if (matchesPreset(true, 0.25f, true, 3, true, 1.0f, true, 0, false, false, 0, true))
return ZonePreset.DEFAULT;
if (matchesPreset(true, 0.30f, true, 3, false, 1.0f, true, 1, false, true, 0, true))
return ZonePreset.TOXIC;
if (matchesPreset(true, 0.35f, true, 3, true, 2.0f, true, 2, false, true, 0, true))
return ZonePreset.INFERNO;
if (matchesPreset(true, 0.20f, true, 1, true, 0.8f, true, 0, false, true, 1, true))
return ZonePreset.ARCANE;
if (matchesPreset(true, 0.15f, false, 1, false, 1.0f, false, 0, true, true, 2, true))
return ZonePreset.ELECTRIC;
if (matchesPreset(true, 0.25f, true, 3, true, 0.3f, true, 0, false, true, 1, true))
return ZonePreset.FROST;
return ZonePreset.CUSTOM;
}
@SideOnly(Side.CLIENT)
private boolean matchesPreset(boolean gf, float ga, boolean r, int rc, boolean b, float bs,
boolean a, int as, boolean l, boolean p, int pm, boolean pg) {
return groundFill == gf && Math.abs(groundAlpha - ga) < 0.001f
&& rings == r && ringCount == rc && border == b && Math.abs(borderSpeed - bs) < 0.001f
&& accents == a && accentStyle == as && lightning == l
&& particles == p && particleMotion == pm && particleGlow == pg;
}
/**
* Apply a preset's field values. CUSTOM does nothing (user configures manually).
*/
@SideOnly(Side.CLIENT)
public void applyPreset(ZonePreset preset) {
if (preset == ZonePreset.CUSTOM) return;
applyPresetDefaults(preset.name());
}
// ═════════════════════════════════════════════════════════════════
// SHARED NBT
// ═════════════════════════════════════════════════════════════════
@@ -476,13 +465,21 @@ public abstract class AbilityZone extends Ability {
// SHARED FIELD DEFINITIONS (client-only)
// ═════════════════════════════════════════════════════════════════
@SideOnly(Side.CLIENT)
protected void addPresetFieldDef(List<FieldDef> defs) {
defs.add(FieldDef.subGuiField("gui.applyPreset",
SubGuiZonePresetSelector::new,
gui -> {
SubGuiZonePresetSelector selector = (SubGuiZonePresetSelector) gui;
if (selector.selectedPreset != null) {
applyPresetDefaults(selector.selectedPreset);
}
}));
}
@SideOnly(Side.CLIENT)
protected void addVisualFieldDefs(List<FieldDef> defs) {
defs.addAll(Arrays.asList(
// Preset dropdown
FieldDef.enumField("gui.preset", ZonePreset.class, this::getCurrentPreset, this::applyPreset)
.tab("ability.tab.visual"),
// Ground Fill
FieldDef.section("ability.section.ground").tab("ability.tab.visual"),
FieldDef.row(
@@ -520,20 +517,18 @@ public abstract class AbilityZone extends Ability {
// Particles
FieldDef.section("ability.section.particles").tab("ability.tab.visual"),
FieldDef.row(
FieldDef.boolField("gui.enabled", this::isParticles, this::setParticles),
FieldDef.floatField("gui.density", this::getParticleDensity, this::setParticleDensity)
).tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.scale", this::getParticleScale, this::setParticleScale),
FieldDef.enumField("gui.motion", ParticleMotion.class, this::getParticleMotionEnum, this::setParticleMotionEnum)
).tab("ability.tab.visual"),
FieldDef.boolField("gui.glow", this::isParticleGlow, this::setParticleGlow)
FieldDef.boolField("gui.enabled", this::isParticles, this::setParticles)
.tab("ability.tab.visual"),
FieldDef.row(
FieldDef.floatField("gui.density", this::getParticleDensity, this::setParticleDensity),
FieldDef.floatField("gui.scale", this::getParticleScale, this::setParticleScale)
).tab("ability.tab.visual").visibleWhen(this::isParticles),
FieldDef.row(
FieldDef.enumField("gui.motion", ParticleMotion.class, this::getParticleMotionEnum, this::setParticleMotionEnum),
FieldDef.boolField("gui.glow", this::isParticleGlow, this::setParticleGlow)
).tab("ability.tab.visual").visibleWhen(this::isParticles),
FieldDef.stringField("gui.texture", this::getParticleDir, this::setParticleDir)
.tab("ability.tab.visual").visibleWhen(this::isParticles),
FieldDef.intField("gui.size", this::getParticleSize, this::setParticleSize).range(1, 256)
.tab("ability.tab.visual").visibleWhen(this::isParticles),
// Animation
FieldDef.section("ability.section.animation").tab("ability.tab.visual"),
+12 -3
View File
@@ -197,8 +197,11 @@ public class DataAbilities {
telegraph.lockPosition();
}
// Remove telegraph - it has served its purpose
removeTelegraph(currentAbility);
// Remove telegraph unless the ability keeps it during active phase
// (e.g., sweeping attacks where the telegraph shows the ongoing danger zone)
if (!currentAbility.keepTelegraphDuringActive()) {
removeTelegraph(currentAbility);
}
// Handle rotation control transition from WINDUP to ACTIVE
if (currentAbility.isRotationLockedDuringActive()) {
@@ -224,7 +227,10 @@ public class DataAbilities {
}
// Play active sound and animation
playAbilitySound(currentAbility.getActiveSound());
// Abilities that keep telegraph during active manage their own sound timing
if (!currentAbility.keepTelegraphDuringActive()) {
playAbilitySound(currentAbility.getActiveSound());
}
playAbilityAnimation(currentAbility.getActiveAnimation());
// Snap NPC to face target before execute so startMoving() reads correct rotation
@@ -338,6 +344,9 @@ public class DataAbilities {
private void handleAbilityCompletion(EntityLivingBase target) {
if (currentAbility == null) return;
// Remove any remaining telegraphs (for abilities that keep telegraph during active)
removeTelegraph(currentAbility);
// Call onComplete callback
currentAbility.onComplete(npc, target);
@@ -0,0 +1,72 @@
package noppes.npcs.client.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.SubGuiInterface;
@SideOnly(Side.CLIENT)
public class SubGuiZonePresetSelector extends SubGuiInterface {
public String selectedPreset = null;
private static final String[] PRESET_NAMES = {"DEFAULT", "TOXIC", "INFERNO", "ARCANE", "ELECTRIC", "FROST"};
private static final String[] PRESET_LABELS = {
"ability.preset.default", "ability.preset.toxic", "ability.preset.inferno",
"ability.preset.arcane", "ability.preset.electric", "ability.preset.frost"
};
private static final int[] PRESET_COLORS = {0xCCCCCC, 0x44DD44, 0xFF6611, 0xAA44FF, 0x4488FF, 0x88CCFF};
public SubGuiZonePresetSelector() {
xSize = 170;
ySize = 135;
setBackground("menubg.png");
}
@Override
public void initGui() {
super.initGui();
int btnW = 72;
int btnH = 20;
int gapY = 4;
int col1 = guiLeft + 7;
int col2 = col1 + btnW + 6;
int startY = guiTop + 22;
for (int i = 0; i < 6; i++) {
int x = (i % 2 == 0) ? col1 : col2;
int y = startY + (i / 2) * (btnH + gapY);
addButton(new GuiNpcButton(i, x, y, btnW, btnH, PRESET_LABELS[i]));
}
int cancelY = startY + 3 * (btnH + gapY) + 4;
addButton(new GuiNpcButton(10, guiLeft + xSize / 2 - 36, cancelY, 72, btnH, "gui.cancel"));
}
@Override
protected void actionPerformed(GuiButton btn) {
super.actionPerformed(btn);
if (btn.id >= 0 && btn.id < 6) {
selectedPreset = PRESET_NAMES[btn.id];
close();
} else if (btn.id == 10) {
close();
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
super.drawScreen(mouseX, mouseY, f);
drawCenteredString(fontRendererObj, StatCollector.translateToLocal("gui.applyPreset"), guiLeft + xSize / 2, guiTop + 8, 0xFFFFFF);
for (int i = 0; i < 6; i++) {
GuiNpcButton btn = getButton(i);
if (btn != null && btn.visible) {
int x = btn.xPosition + 4;
int y = btn.yPosition + 5;
drawRect(x, y, x + 10, y + 10, 0xFF000000 | PRESET_COLORS[i]);
}
}
}
}
@@ -154,8 +154,8 @@ public class FieldDef {
public static FieldDef colorSubGui(String label, Supplier<Integer> getter, Consumer<Integer> setter) {
return subGuiField(label,
() -> new SubGuiColorSelector(getter.get()),
gui -> setter.accept(((SubGuiColorSelector) gui).color & 0x00FFFFFF))
() -> new SubGuiColorSelector(getter.get() & 0xFFFFFF),
gui -> setter.accept((((SubGuiColorSelector) gui).color & 0x00FFFFFF) | (getter.get() & 0xFF000000)))
.buttonLabel(() -> String.format("%06X", getter.get() & 0xFFFFFF))
.buttonTextColor(() -> getter.get() & 0xFFFFFF);
}