From 6c7c72b0f987059c6eeeeb661134864201b2e100 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 26 Jan 2026 18:38:43 -0500 Subject: [PATCH 01/15] Lightning, Orb and Beam Improvements. Outer Glow Configurations for Abilities --- .gitignore | 1 + .../client/renderer/RenderAbilityBeam.java | 271 ++++++++++++- .../client/renderer/RenderAbilityDisc.java | 45 ++- .../client/renderer/RenderAbilityLaser.java | 84 +++- .../client/renderer/RenderAbilityOrb.java | 113 +++--- .../client/renderer/RenderAbilityOrbCube.java | 56 --- .../client/renderer/TelegraphRenderer.java | 12 +- .../lightning/AttachedLightningRenderer.java | 281 +++++++++++++ .../renderer/lightning/LightningBolt.java | 295 ++++++++++++++ .../renderer/lightning/LightningHandler.java | 202 ++++++++++ .../client/renderer/lightning/Quaternion.java | 85 ++++ .../npcs/client/renderer/lightning/Vec3d.java | 184 +++++++++ .../data/ability/type/AbilityDisc.java | 24 +- .../data/ability/type/AbilityEnergyBeam.java | 82 +++- .../data/ability/type/AbilityLaserShot.java | 24 +- .../data/ability/type/AbilityOrb.java | 53 ++- .../data/telegraph/TelegraphInstance.java | 56 ++- .../npcs/entity/EntityAbilityBeam.java | 381 +++++++++++++++++- .../npcs/entity/EntityAbilityDisc.java | 29 +- .../npcs/entity/EntityAbilityLaser.java | 28 +- .../kamkeel/npcs/entity/EntityAbilityOrb.java | 28 +- .../npcs/entity/EntityAbilityProjectile.java | 71 +++- .../java/noppes/npcs/client/ClientProxy.java | 9 +- .../noppes/npcs/client/ClientTickHandler.java | 4 + .../advanced/ability/SubGuiAbilityDisc.java | 32 ++ .../ability/SubGuiAbilityEnergyBeam.java | 32 ++ .../ability/SubGuiAbilityLaserShot.java | 32 ++ .../advanced/ability/SubGuiAbilityOrb.java | 62 ++- .../assets/customnpcs/lang/en_US.lang | 3 + 29 files changed, 2372 insertions(+), 207 deletions(-) delete mode 100644 src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrbCube.java create mode 100644 src/main/java/kamkeel/npcs/client/renderer/lightning/AttachedLightningRenderer.java create mode 100644 src/main/java/kamkeel/npcs/client/renderer/lightning/LightningBolt.java create mode 100644 src/main/java/kamkeel/npcs/client/renderer/lightning/LightningHandler.java create mode 100644 src/main/java/kamkeel/npcs/client/renderer/lightning/Quaternion.java create mode 100644 src/main/java/kamkeel/npcs/client/renderer/lightning/Vec3d.java diff --git a/.gitignore b/.gitignore index d24cc7cf7..908eae39d 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ out run src/main/resources/assets/customnpcs/api df/ +tmp/ diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java index 204be9d7e..554b07e31 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java +++ b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java @@ -2,6 +2,7 @@ package kamkeel.npcs.client.renderer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import kamkeel.npcs.client.renderer.lightning.AttachedLightningRenderer; import kamkeel.npcs.entity.EntityAbilityBeam; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; @@ -31,6 +32,13 @@ public class RenderAbilityBeam extends RenderAbilityProjectile { setupRenderState(); + // Handle charging state (windup phase) - render only growing orb + if (beam.isCharging()) { + renderChargingOrb(beam, x, y, z, partialTicks); + restoreRenderState(); + return; + } + // Get trail points (these are RELATIVE to origin) List trail = beam.getTrailPoints(); if (trail.isEmpty()) { @@ -60,11 +68,17 @@ public class RenderAbilityBeam extends RenderAbilityProjectile { GL11.glPushMatrix(); GL11.glTranslated(renderOriginX, renderOriginY, renderOriginZ); - // Render tail orb at origin (0,0,0) - static, no rotation - renderTailOrb(headSize * 0.8f, innerColor, outerColor, beam.isOuterColorEnabled()); + // Render tail orb at origin (0,0,0) - only in anchored mode + if (beam.shouldRenderTailOrb()) { + renderTailOrb(headSize * 0.8f, innerColor, outerColor, beam.isOuterColorEnabled(), beam.getOuterColorWidth()); + } - // Render trail segments with smooth connections - renderSmoothTrail(trail, beamWidth, innerColor, outerColor, beam.isOuterColorEnabled(), beam.getOuterColorWidth()); + // Render trail segments with smooth connections (with fading for non-anchored) + if (beam.hasFadingTrail()) { + renderFadingTrail(beam, trail, beamWidth, innerColor, outerColor, beam.isOuterColorEnabled(), beam.getOuterColorWidth()); + } else { + renderSmoothTrail(trail, beamWidth, innerColor, outerColor, beam.isOuterColorEnabled(), beam.getOuterColorWidth()); + } // Render head at interpolated offset position renderHead(beam, headOffsetX, headOffsetY, headOffsetZ, headSize, innerColor, outerColor, partialTicks); @@ -74,27 +88,84 @@ public class RenderAbilityBeam extends RenderAbilityProjectile { restoreRenderState(); } + /** + * Render the charging orb during windup phase. + * Grows from 0 to headSize based on charge progress. + */ + private void renderChargingOrb(EntityAbilityBeam beam, double x, double y, double z, float partialTicks) { + float headSize = beam.getHeadSize(); + float chargeProgress = beam.getInterpolatedChargeProgress(partialTicks); + float size = headSize * chargeProgress; + + if (size <= 0.01f) return; + + int innerColor = beam.getInnerColor(); + int outerColor = beam.getOuterColor(); + + GL11.glPushMatrix(); + GL11.glTranslated(x, y, z); + + // Pulsing effect + float pulseTime = beam.ticksExisted + partialTicks; + float scaleModifier = (float) Math.sin(pulseTime * 0.2f) * 0.08f; + float scale = size * (1.0f + scaleModifier); + + // Render lightning during charging if enabled + if (beam.hasLightningEffect()) { + renderAttachedLightning(beam, scale); + } + + GL11.glPushMatrix(); + GL11.glScalef(scale, scale, scale); + + // Inner scale defines the core size + float innerScale = 0.6f; + + // Render outer glow only if enabled + if (beam.isOuterColorEnabled()) { + float outerScale = innerScale + beam.getOuterColorWidth(); + GL11.glDepthMask(false); + GL11.glPushMatrix(); + GL11.glScalef(outerScale, outerScale, outerScale); + renderCube(outerColor, 0.5f, 0.5f); + GL11.glPopMatrix(); + GL11.glDepthMask(true); + } + + // Render inner core + GL11.glScalef(innerScale, innerScale, innerScale); + renderCube(innerColor, 1.0f, 0.5f); + + GL11.glPopMatrix(); + GL11.glPopMatrix(); + } + /** * Render the tail orb at the origin (where the beam emanates from). * This orb does not rotate - it's a stable anchor point. */ - private void renderTailOrb(float size, int innerColor, int outerColor, boolean outerColorEnabled) { + private void renderTailOrb(float size, int innerColor, int outerColor, boolean outerColorEnabled, float outerColorWidth) { GL11.glPushMatrix(); // Already at origin (0,0,0) + // Inner scale defines the core size + float innerScale = 0.6f; + // Render outer glow only if enabled + // outerColorWidth is an additive offset from inner size if (outerColorEnabled) { + float outerScale = innerScale + outerColorWidth; GL11.glDepthMask(false); GL11.glPushMatrix(); - GL11.glScalef(size, size, size); + GL11.glScalef(size * outerScale, size * outerScale, size * outerScale); renderCube(outerColor, 0.4f, 0.5f); GL11.glPopMatrix(); GL11.glDepthMask(true); } - // Render inner core (smaller, solid) + // Render inner core (solid) GL11.glPushMatrix(); - GL11.glScalef(size * 0.6f, size * 0.6f, size * 0.6f); + GL11.glScalef(size * innerScale, size * innerScale, size * innerScale); renderCube(innerColor, 1.0f, 0.5f); GL11.glPopMatrix(); @@ -115,15 +186,153 @@ public class RenderAbilityBeam extends RenderAbilityProjectile { // At connection points, average the perpendiculars for smooth transitions List perpFrames = computePerpendiculars(trail); + // Inner scale defines the core width + float innerScale = 0.6f; + float innerWidth = width * innerScale; + // Render outer glow trail (wider, translucent) - only if enabled + // outerColorWidth is an additive offset from inner width if (outerColorEnabled) { + float outerWidth = innerWidth + outerColorWidth * width; GL11.glDepthMask(false); - renderTrailTube(trail, perpFrames, width * outerColorWidth, outerColor, 0.3f, true); + renderTrailTube(trail, perpFrames, outerWidth, outerColor, 0.3f, true); GL11.glDepthMask(true); } // Render inner core trail - renderTrailTube(trail, perpFrames, width * 0.6f, innerColor, 0.9f, false); + renderTrailTube(trail, perpFrames, innerWidth, innerColor, 0.9f, false); + } + + /** + * Render trail with fading effect (comet style) for non-anchored beams. + * Older trail points fade out based on their age. + */ + private void renderFadingTrail(EntityAbilityBeam beam, List trail, float width, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth) { + if (trail.size() < 2) return; + + List ages = beam.getTrailPointAges(); + int fadeTime = beam.getTrailFadeTime(); + + // Pre-compute perpendicular frames + List perpFrames = computePerpendiculars(trail); + + // Inner scale defines the core width + float innerScale = 0.6f; + float innerWidth = width * innerScale; + + // Render outer glow trail with fading + if (outerColorEnabled) { + float outerWidth = innerWidth + outerColorWidth * width; + GL11.glDepthMask(false); + renderFadingTrailTube(trail, perpFrames, ages, fadeTime, outerWidth, outerColor, 0.3f); + GL11.glDepthMask(true); + } + + // Render inner core trail with fading + renderFadingTrailTube(trail, perpFrames, ages, fadeTime, innerWidth, innerColor, 0.9f); + } + + /** + * Render trail tube with age-based fading. + */ + private void renderFadingTrailTube(List trail, List perpFrames, List ages, + int fadeTime, float width, int color, float baseAlpha) { + float[] rgb = extractRGB(color); + float r = rgb[0], g = rgb[1], b = rgb[2]; + float halfWidth = width * 0.5f; + int size = trail.size(); + + Tessellator tess = Tessellator.instance; + tess.startDrawingQuads(); + + for (int i = 0; i < size - 1; i++) { + Vec3 p1 = trail.get(i); + Vec3 p2 = trail.get(i + 1); + double[] frame1 = perpFrames.get(i); + double[] frame2 = perpFrames.get(i + 1); + + // Calculate alpha based on age (older = more faded) + float age1 = i < ages.size() ? ages.get(i) : 0; + float age2 = (i + 1) < ages.size() ? ages.get(i + 1) : 0; + float fade1 = 1.0f - Math.min(1.0f, age1 / fadeTime); + float fade2 = 1.0f - Math.min(1.0f, age2 / fadeTime); + float alpha1 = baseAlpha * fade1; + float alpha2 = baseAlpha * fade2; + + // Skip fully faded segments + if (alpha1 <= 0.01f && alpha2 <= 0.01f) continue; + + // Calculate 4 corners at start + double s1x = p1.xCoord - frame1[0] * halfWidth - frame1[3] * halfWidth; + double s1y = p1.yCoord - frame1[1] * halfWidth - frame1[4] * halfWidth; + double s1z = p1.zCoord - frame1[2] * halfWidth - frame1[5] * halfWidth; + + double s2x = p1.xCoord + frame1[0] * halfWidth - frame1[3] * halfWidth; + double s2y = p1.yCoord + frame1[1] * halfWidth - frame1[4] * halfWidth; + double s2z = p1.zCoord + frame1[2] * halfWidth - frame1[5] * halfWidth; + + double s3x = p1.xCoord + frame1[0] * halfWidth + frame1[3] * halfWidth; + double s3y = p1.yCoord + frame1[1] * halfWidth + frame1[4] * halfWidth; + double s3z = p1.zCoord + frame1[2] * halfWidth + frame1[5] * halfWidth; + + double s4x = p1.xCoord - frame1[0] * halfWidth + frame1[3] * halfWidth; + double s4y = p1.yCoord - frame1[1] * halfWidth + frame1[4] * halfWidth; + double s4z = p1.zCoord - frame1[2] * halfWidth + frame1[5] * halfWidth; + + // Calculate 4 corners at end + double e1x = p2.xCoord - frame2[0] * halfWidth - frame2[3] * halfWidth; + double e1y = p2.yCoord - frame2[1] * halfWidth - frame2[4] * halfWidth; + double e1z = p2.zCoord - frame2[2] * halfWidth - frame2[5] * halfWidth; + + double e2x = p2.xCoord + frame2[0] * halfWidth - frame2[3] * halfWidth; + double e2y = p2.yCoord + frame2[1] * halfWidth - frame2[4] * halfWidth; + double e2z = p2.zCoord + frame2[2] * halfWidth - frame2[5] * halfWidth; + + double e3x = p2.xCoord + frame2[0] * halfWidth + frame2[3] * halfWidth; + double e3y = p2.yCoord + frame2[1] * halfWidth + frame2[4] * halfWidth; + double e3z = p2.zCoord + frame2[2] * halfWidth + frame2[5] * halfWidth; + + double e4x = p2.xCoord - frame2[0] * halfWidth + frame2[3] * halfWidth; + double e4y = p2.yCoord - frame2[1] * halfWidth + frame2[4] * halfWidth; + double e4z = p2.zCoord - frame2[2] * halfWidth + frame2[5] * halfWidth; + + // Bottom face + tess.setColorRGBA_F(r, g, b, alpha1); + tess.addVertex(s1x, s1y, s1z); + tess.addVertex(s2x, s2y, s2z); + tess.setColorRGBA_F(r, g, b, alpha2); + tess.addVertex(e2x, e2y, e2z); + tess.addVertex(e1x, e1y, e1z); + + // Top face + tess.setColorRGBA_F(r, g, b, alpha1); + tess.addVertex(s4x, s4y, s4z); + tess.setColorRGBA_F(r, g, b, alpha2); + tess.addVertex(e4x, e4y, e4z); + tess.addVertex(e3x, e3y, e3z); + tess.setColorRGBA_F(r, g, b, alpha1); + tess.addVertex(s3x, s3y, s3z); + + // Left face + tess.setColorRGBA_F(r, g, b, alpha1); + tess.addVertex(s1x, s1y, s1z); + tess.setColorRGBA_F(r, g, b, alpha2); + tess.addVertex(e1x, e1y, e1z); + tess.addVertex(e4x, e4y, e4z); + tess.setColorRGBA_F(r, g, b, alpha1); + tess.addVertex(s4x, s4y, s4z); + + // Right face + tess.setColorRGBA_F(r, g, b, alpha1); + tess.addVertex(s2x, s2y, s2z); + tess.addVertex(s3x, s3y, s3z); + tess.setColorRGBA_F(r, g, b, alpha2); + tess.addVertex(e3x, e3y, e3z); + tess.addVertex(e2x, e2y, e2z); + } + + tess.draw(); } /** @@ -328,6 +537,11 @@ public class RenderAbilityBeam extends RenderAbilityProjectile { float scaleModifier = (float) Math.sin(pulseTime * 0.2f) * 0.1f; float scale = size * (1.0f + scaleModifier); + // Render lightning BEFORE rotation so it crackles in all directions (only on head) + if (beam.hasLightningEffect()) { + renderAttachedLightning(beam, scale); + } + // Rotation GL11.glRotatef(beam.getInterpolatedRotationX(partialTicks), 1.0f, 0.0f, 0.0f); GL11.glRotatef(beam.getInterpolatedRotationY(partialTicks), 0.0f, 1.0f, 0.0f); @@ -336,19 +550,54 @@ public class RenderAbilityBeam extends RenderAbilityProjectile { GL11.glPushMatrix(); GL11.glScalef(scale, scale, scale); + // Inner scale defines the core size + float innerScale = 0.6f; + // Render outer glow only if enabled + // outerColorWidth is an additive offset from inner size if (beam.isOuterColorEnabled()) { + float outerScale = innerScale + beam.getOuterColorWidth(); GL11.glDepthMask(false); + GL11.glPushMatrix(); + GL11.glScalef(outerScale, outerScale, outerScale); renderCube(outerColor, 0.5f, 0.5f); + GL11.glPopMatrix(); GL11.glDepthMask(true); } // Render inner core - float innerScale = 0.6f; GL11.glScalef(innerScale, innerScale, innerScale); renderCube(innerColor, 1.0f, 0.5f); GL11.glPopMatrix(); GL11.glPopMatrix(); } + + /** + * Render fading lightning arcs attached to the beam head (in local space). + */ + private void renderAttachedLightning(EntityAbilityBeam beam, float headScale) { + AttachedLightningRenderer.LightningState state = getLightningState(beam); + + float density = beam.getLightningDensity(); + // Lightning radius extends outward from inner surface (innerScale = 0.6) + float innerRadius = 0.6f * headScale * 0.5f; + float radius = innerRadius + beam.getLightningRadius() * headScale; + int outerColor = beam.getOuterColor(); + int innerColor = beam.getInnerColor(); + int fadeTime = beam.getLightningFadeTime(); + + state.update(density, radius, outerColor, innerColor, fadeTime); + state.render(); + } + + /** + * Get or create the lightning state for an entity. + */ + private AttachedLightningRenderer.LightningState getLightningState(EntityAbilityBeam beam) { + if (beam.lightningState == null) { + beam.lightningState = new AttachedLightningRenderer.LightningState(); + } + return (AttachedLightningRenderer.LightningState) beam.lightningState; + } } diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java index 13de38b50..fdd80689a 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java +++ b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityDisc.java @@ -2,6 +2,7 @@ package kamkeel.npcs.client.renderer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import kamkeel.npcs.client.renderer.lightning.AttachedLightningRenderer; import kamkeel.npcs.entity.EntityAbilityDisc; import net.minecraft.entity.Entity; import org.lwjgl.opengl.GL11; @@ -21,6 +22,7 @@ public class RenderAbilityDisc extends RenderAbilityProjectile { setupRenderState(); + GL11.glPushMatrix(); GL11.glTranslated(x, y, z); // Get interpolated values @@ -33,29 +35,66 @@ public class RenderAbilityDisc extends RenderAbilityProjectile { float scaleModifier = (float) Math.sin(pulseTime * 0.1f) * 0.03f; float scale = 1.0f + scaleModifier; + // Render lightning BEFORE rotation so it crackles in all directions + if (disc.hasLightningEffect()) { + renderAttachedLightning(disc, radius * scale); + } + GL11.glPushMatrix(); GL11.glScalef(scale, scale, scale); // Apply ONLY Y-axis rotation for flat spin GL11.glRotatef(disc.getInterpolatedRotationY(partialTicks), 0.0f, 1.0f, 0.0f); + // Inner scale defines the core size + float innerScale = 0.6f; + // Render outer square (translucent) - only if enabled + // outerColorWidth is an additive offset from inner size if (disc.isOuterColorEnabled()) { - float outerScale = disc.getOuterColorWidth() / 1.8f; // Normalize to default width + float outerScale = innerScale + disc.getOuterColorWidth(); GL11.glDepthMask(false); renderFlatSquare(disc.getOuterColor(), 0.5f, radius * outerScale, thickness); GL11.glDepthMask(true); } - // Render inner square (solid, smaller) - float innerScale = 0.6f; + // Render inner square (solid) renderFlatSquare(disc.getInnerColor(), 1.0f, radius * innerScale, thickness * 1.2f); + GL11.glPopMatrix(); GL11.glPopMatrix(); restoreRenderState(); } + /** + * Render fading lightning arcs attached to the disc (in local space). + */ + private void renderAttachedLightning(EntityAbilityDisc disc, float discSize) { + AttachedLightningRenderer.LightningState state = getLightningState(disc); + + float density = disc.getLightningDensity(); + // Lightning radius extends outward from inner surface (innerScale = 0.6) + float innerRadius = 0.6f * discSize * 0.5f; + float radius = innerRadius + disc.getLightningRadius() * discSize; + int outerColor = disc.getOuterColor(); + int innerColor = disc.getInnerColor(); + int fadeTime = disc.getLightningFadeTime(); + + state.update(density, radius, outerColor, innerColor, fadeTime); + state.render(); + } + + /** + * Get or create the lightning state for an entity. + */ + private AttachedLightningRenderer.LightningState getLightningState(EntityAbilityDisc disc) { + if (disc.lightningState == null) { + disc.lightningState = new AttachedLightningRenderer.LightningState(); + } + return (AttachedLightningRenderer.LightningState) disc.lightningState; + } + /** * Render a flat square (thin cube) centered at origin. * The square lies flat on the XZ plane with thin Y height. diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityLaser.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityLaser.java index fce85d2db..bf4df79eb 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityLaser.java +++ b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityLaser.java @@ -2,6 +2,7 @@ package kamkeel.npcs.client.renderer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import kamkeel.npcs.client.renderer.lightning.AttachedLightningRenderer; import kamkeel.npcs.entity.EntityAbilityLaser; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; @@ -84,32 +85,103 @@ public class RenderAbilityLaser extends RenderAbilityProjectile { double vertY = dz * horzX - dx * horzZ; double vertZ = dx * horzY - dy * horzX; + // Inner scale defines the core width + float innerScale = 0.6f; + float innerWidth = width * innerScale; + // Render outer rectangle (larger, outer color, translucent) - only if enabled + // outerColorWidth is an additive offset from inner width if (laser.isOuterColorEnabled()) { - float outerScale = laser.getOuterColorWidth(); + float outerWidth = innerWidth + laser.getOuterColorWidth() * width; GL11.glDepthMask(false); renderBeamRectangle(renderStartX, renderStartY, renderStartZ, renderEndX, renderEndY, renderEndZ, horzX, horzY, horzZ, vertX, vertY, vertZ, - width * outerScale, laser.getOuterColor(), alpha * 0.4f); + outerWidth, laser.getOuterColor(), alpha * 0.4f); - // Render middle layer + // Render middle layer (halfway between inner and outer) + float midWidth = innerWidth + (outerWidth - innerWidth) * 0.5f; renderBeamRectangle(renderStartX, renderStartY, renderStartZ, renderEndX, renderEndY, renderEndZ, horzX, horzY, horzZ, vertX, vertY, vertZ, - width * 1.3f, laser.getOuterColor(), alpha * 0.7f); + midWidth, laser.getOuterColor(), alpha * 0.7f); GL11.glDepthMask(true); } - // Render inner core (smaller, inner color, solid) + // Render inner core (solid) renderBeamRectangle(renderStartX, renderStartY, renderStartZ, renderEndX, renderEndY, renderEndZ, horzX, horzY, horzZ, vertX, vertY, vertZ, - width * 0.6f, laser.getInnerColor(), alpha); + innerWidth, laser.getInnerColor(), alpha); + + // Render lightning along the laser beam + if (laser.hasLightningEffect() && laser.getCurrentLength() > 0.1f) { + renderLaserLightning(laser, renderStartX, renderStartY, renderStartZ, + renderEndX, renderEndY, renderEndZ, width); + } restoreRenderState(); } + /** + * Render lightning effects along the laser beam at multiple points. + */ + private void renderLaserLightning(EntityAbilityLaser laser, + double startX, double startY, double startZ, + double endX, double endY, double endZ, float width) { + AttachedLightningRenderer.LightningState state = getLightningState(laser); + + float density = laser.getLightningDensity(); + // Lightning radius extends outward from inner width + float innerRadius = width * 0.6f * 0.5f; + float radius = innerRadius + laser.getLightningRadius() * width; + int outerColor = laser.getOuterColor(); + int innerColor = laser.getInnerColor(); + int fadeTime = laser.getLightningFadeTime(); + + // Render lightning at multiple points along the laser + // Start, middle, and end points + double midX = (startX + endX) * 0.5; + double midY = (startY + endY) * 0.5; + double midZ = (startZ + endZ) * 0.5; + + GL11.glPushMatrix(); + GL11.glTranslated(midX, midY, midZ); + state.update(density, radius, outerColor, innerColor, fadeTime); + state.render(); + GL11.glPopMatrix(); + + // Also render at the tip + GL11.glPushMatrix(); + GL11.glTranslated(endX, endY, endZ); + // Use a secondary state for the tip + AttachedLightningRenderer.LightningState tipState = getTipLightningState(laser); + tipState.update(density * 0.7f, radius * 0.8f, outerColor, innerColor, fadeTime); + tipState.render(); + GL11.glPopMatrix(); + } + + /** + * Get or create the main lightning state for the laser. + */ + private AttachedLightningRenderer.LightningState getLightningState(EntityAbilityLaser laser) { + if (laser.lightningState == null) { + laser.lightningState = new AttachedLightningRenderer.LightningState(); + } + return (AttachedLightningRenderer.LightningState) laser.lightningState; + } + + /** + * Get or create the tip lightning state for the laser. + * Stored as a secondary object in lightningState2. + */ + private AttachedLightningRenderer.LightningState getTipLightningState(EntityAbilityLaser laser) { + // Use a simple approach - store in a transient field + // Since lightningState is already used, we'll create a new state each time + // This works because we're updating and rendering immediately + return new AttachedLightningRenderer.LightningState(); + } + /** * Render a beam as a 3D rectangular prism (box along a line). */ diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java index 39048648d..e2e6f8234 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java +++ b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrb.java @@ -2,57 +2,29 @@ package kamkeel.npcs.client.renderer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import kamkeel.npcs.client.renderer.quadric.SphereRenderer; +import kamkeel.npcs.client.renderer.lightning.AttachedLightningRenderer; import kamkeel.npcs.entity.EntityAbilityOrb; -import net.minecraft.client.renderer.entity.Render; import net.minecraft.entity.Entity; -import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; /** - * Renders the AbilityOrb entity as a glowing sphere with inner and outer layers. - * - * Design inspired by LouisXIV's energy rendering system. + * Renders the AbilityOrb entity as a cube with inner and outer layers. + * Minecraft-style blocky appearance using Tessellator. */ @SideOnly(Side.CLIENT) -public class RenderAbilityOrb extends Render { +public class RenderAbilityOrb extends RenderAbilityProjectile { - // White texture for solid color rendering - private static final ResourceLocation WHITE_TEXTURE = new ResourceLocation("customnpcs", "textures/entity/white.png"); - - // Static sphere renderer - shared across all orb renders - private static final SphereRenderer sphere = new SphereRenderer(0.5f, 16); - - public RenderAbilityOrb() { - this.shadowSize = 0.0f; - } + private static final int LIGHTNING_FADE_TICKS = 6; @Override public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTicks) { EntityAbilityOrb orb = (EntityAbilityOrb) entity; + setupRenderState(); + GL11.glPushMatrix(); - - // Disable culling, enable rescale normal - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_ALPHA_TEST); - - // Enable blending for transparency - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F); - - // Disable lighting for self-illumination - GL11.glDisable(GL11.GL_LIGHTING); - - // Translate to render position GL11.glTranslated(x, y, z); - // Bind texture - this.bindTexture(WHITE_TEXTURE); - // Get interpolated size for smooth rendering float size = orb.getInterpolatedSize(partialTicks); @@ -61,51 +33,74 @@ public class RenderAbilityOrb extends Render { float scaleModifier = (float) Math.sin(pulseTime * 0.15f) * 0.05f; float scale = size * (1.0f + scaleModifier); - GL11.glPushMatrix(); - GL11.glScalef(scale, scale, scale); + // Render lightning BEFORE rotation so it crackles in all directions + if (orb.hasLightningEffect()) { + renderAttachedLightning(orb, scale); + } // Use entity's interpolated rotation for smooth spinning GL11.glRotatef(orb.getInterpolatedRotationX(partialTicks), 1.0f, 0.0f, 0.0f); GL11.glRotatef(orb.getInterpolatedRotationY(partialTicks), 0.0f, 1.0f, 0.0f); GL11.glRotatef(orb.getInterpolatedRotationZ(partialTicks), 0.0f, 0.0f, 1.0f); - // Render outer sphere (translucent) - only if enabled + GL11.glPushMatrix(); + GL11.glScalef(scale, scale, scale); + + // Inner scale defines the core size + float innerScale = 0.6f; + + // Render outer cube (translucent) - only if enabled + // outerColorWidth is an additive offset from inner size if (orb.isOuterColorEnabled()) { + float outerScale = innerScale + orb.getOuterColorWidth(); GL11.glDepthMask(false); - this.bindTexture(WHITE_TEXTURE); - float outerScale = orb.getOuterColorWidth() / 1.8f; // Normalize to default width GL11.glPushMatrix(); GL11.glScalef(outerScale, outerScale, outerScale); - renderSphere(orb.getOuterColor(), 0.6f); + renderCube(orb.getOuterColor(), 0.5f, 0.5f); GL11.glPopMatrix(); GL11.glDepthMask(true); } - // Render inner sphere (more opaque) - float innerScale = 0.75f; - GL11.glPushMatrix(); + // Render inner cube (solid) GL11.glScalef(innerScale, innerScale, innerScale); - this.bindTexture(WHITE_TEXTURE); - renderSphere(orb.getInnerColor(), 1.0f); - GL11.glPopMatrix(); + renderCube(orb.getInnerColor(), 1.0f, 0.5f); GL11.glPopMatrix(); - - // Restore GL state - GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix(); + + restoreRenderState(); } - private void renderSphere(int color, float alpha) { - // Set sphere properties and render (rotation already applied to matrix) - sphere.setScale(1.0f); - sphere.setAlpha(alpha); - sphere.setColor(color); - sphere.render(0); + /** + * Render fading lightning arcs attached to the orb (in local space). + * Arcs persist for a few ticks and fade out, while staying attached to the orb. + */ + private void renderAttachedLightning(EntityAbilityOrb orb, float orbScale) { + // Get or create the lightning state for this entity + AttachedLightningRenderer.LightningState state = getLightningState(orb); + + float density = orb.getLightningDensity(); + // Lightning radius extends outward from inner surface (innerScale = 0.6) + float innerRadius = 0.6f * orbScale * 0.5f; // Half size of inner cube + float radius = innerRadius + orb.getLightningRadius() * orbScale; + int outerColor = orb.getOuterColor(); + int innerColor = orb.getInnerColor(); + int fadeTime = orb.getLightningFadeTime(); + + // Update: age existing arcs, spawn new ones based on density + state.update(density, radius, outerColor, innerColor, fadeTime); + + // Render all active arcs in local space (they move with the orb) + state.render(); } - @Override - protected ResourceLocation getEntityTexture(Entity entity) { - return WHITE_TEXTURE; + /** + * Get or create the lightning state for an entity. + */ + private AttachedLightningRenderer.LightningState getLightningState(EntityAbilityOrb orb) { + if (orb.lightningState == null) { + orb.lightningState = new AttachedLightningRenderer.LightningState(); + } + return (AttachedLightningRenderer.LightningState) orb.lightningState; } } diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrbCube.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrbCube.java deleted file mode 100644 index 29656e597..000000000 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityOrbCube.java +++ /dev/null @@ -1,56 +0,0 @@ -package kamkeel.npcs.client.renderer; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import kamkeel.npcs.entity.EntityAbilityOrb; -import net.minecraft.entity.Entity; -import org.lwjgl.opengl.GL11; - -/** - * Renders the AbilityOrb entity as a cube with inner and outer layers. - * Minecraft-style blocky appearance using Tessellator. - * - * Design inspired by LouisXIV's energy rendering system. - */ -@SideOnly(Side.CLIENT) -public class RenderAbilityOrbCube extends RenderAbilityProjectile { - - @Override - public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTicks) { - EntityAbilityOrb orb = (EntityAbilityOrb) entity; - - setupRenderState(); - - GL11.glTranslated(x, y, z); - - // Get interpolated size for smooth rendering - float size = orb.getInterpolatedSize(partialTicks); - - // Pulsing scale effect - float pulseTime = entity.ticksExisted + partialTicks; - float scaleModifier = (float) Math.sin(pulseTime * 0.15f) * 0.05f; - float scale = size * (1.0f + scaleModifier); - - // Use entity's interpolated rotation for smooth spinning - GL11.glRotatef(orb.getInterpolatedRotationX(partialTicks), 1.0f, 0.0f, 0.0f); - GL11.glRotatef(orb.getInterpolatedRotationY(partialTicks), 0.0f, 1.0f, 0.0f); - GL11.glRotatef(orb.getInterpolatedRotationZ(partialTicks), 0.0f, 0.0f, 1.0f); - - GL11.glPushMatrix(); - GL11.glScalef(scale, scale, scale); - - // Render outer cube (translucent) - GL11.glDepthMask(false); - renderCube(orb.getOuterColor(), 0.5f, 0.5f); - GL11.glDepthMask(true); - - // Render inner cube (solid, smaller) - float innerScale = 0.6f; - GL11.glScalef(innerScale, innerScale, innerScale); - renderCube(orb.getInnerColor(), 1.0f, 0.5f); - - GL11.glPopMatrix(); - - restoreRenderState(); - } -} diff --git a/src/main/java/kamkeel/npcs/client/renderer/TelegraphRenderer.java b/src/main/java/kamkeel/npcs/client/renderer/TelegraphRenderer.java index 0cac8805e..5f4e815b7 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/TelegraphRenderer.java +++ b/src/main/java/kamkeel/npcs/client/renderer/TelegraphRenderer.java @@ -76,10 +76,10 @@ public class TelegraphRenderer { return; } - // Calculate render position relative to camera - double renderX = instance.getX() - playerX; - double renderY = instance.getY() - playerY + telegraph.getHeightOffset(); - double renderZ = instance.getZ() - playerZ; + // Calculate render position relative to camera using interpolated positions for smooth movement + double renderX = instance.getInterpolatedX(partialTicks) - playerX; + double renderY = instance.getInterpolatedY(partialTicks) - playerY + telegraph.getHeightOffset(); + double renderZ = instance.getInterpolatedZ(partialTicks) - playerZ; // Get animated color int color = instance.getAnimatedColor(partialTicks); @@ -91,8 +91,8 @@ public class TelegraphRenderer { GL11.glPushMatrix(); GL11.glTranslated(renderX, renderY, renderZ); - // Rotate for directional shapes - GL11.glRotatef(-instance.getYaw(), 0, 1, 0); + // Rotate for directional shapes using interpolated yaw for smooth rotation + GL11.glRotatef(-instance.getInterpolatedYaw(partialTicks), 0, 1, 0); switch (telegraph.getType()) { case CIRCLE: diff --git a/src/main/java/kamkeel/npcs/client/renderer/lightning/AttachedLightningRenderer.java b/src/main/java/kamkeel/npcs/client/renderer/lightning/AttachedLightningRenderer.java new file mode 100644 index 000000000..4fa28cda8 --- /dev/null +++ b/src/main/java/kamkeel/npcs/client/renderer/lightning/AttachedLightningRenderer.java @@ -0,0 +1,281 @@ +package kamkeel.npcs.client.renderer.lightning; + +import net.minecraft.client.renderer.Tessellator; +import org.lwjgl.opengl.GL11; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +/** + * Renders lightning arcs attached to an entity (in local space). + * Supports both instant arcs and fading persistent bolts that move with the entity. + */ +public class AttachedLightningRenderer { + + private static final Random rand = new Random(); + + /** + * Data for a single lightning bolt with fading support. + */ + public static class LightningArc { + public List points; + public int age; + public int maxAge; + public int outerColor; + public int innerColor; + + public LightningArc(List points, int maxAge, int outerColor, int innerColor) { + this.points = points; + this.age = 0; + this.maxAge = maxAge; + this.outerColor = outerColor; + this.innerColor = innerColor; + } + + public float getAlphaMultiplier() { + // Fade out over lifetime + return 1.0f - ((float) age / (float) maxAge); + } + + public boolean isDead() { + return age >= maxAge; + } + + public void tick() { + age++; + } + } + + /** + * Storage for persistent lightning arcs per entity. + * Call updateAndRender() each frame from the entity's renderer. + */ + public static class LightningState { + private final List arcs = new ArrayList<>(); + private float spawnAccumulator = 0; + + /** + * Update arc ages, remove dead arcs, spawn new ones based on density. + * + * @param density Arcs per tick (can be fractional) + * @param radius Max arc distance from center + * @param outerColor Outer glow color + * @param innerColor Inner core color + * @param maxAge How many ticks arcs live (for fading) + */ + public void update(float density, float radius, int outerColor, int innerColor, int maxAge) { + // Age existing arcs and remove dead ones + Iterator iter = arcs.iterator(); + while (iter.hasNext()) { + LightningArc arc = iter.next(); + arc.tick(); + if (arc.isDead()) { + iter.remove(); + } + } + + // Spawn new arcs based on density + spawnAccumulator += density; + while (spawnAccumulator >= 1.0f) { + spawnAccumulator -= 1.0f; + arcs.add(createArc(radius, outerColor, innerColor, maxAge)); + } + } + + /** + * Render all active arcs in local space. + * Call this after glTranslated to entity position. + */ + 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; + + for (LightningArc arc : arcs) { + float alphaMult = arc.getAlphaMultiplier(); + + // Render outer glow + renderBoltPath(tess, arc.points, arc.outerColor, 0.025f, 0.35f * alphaMult); + + // Render inner core + renderBoltPath(tess, arc.points, arc.innerColor, 0.012f, 0.7f * alphaMult); + } + + GL11.glDepthMask(true); + GL11.glPopAttrib(); + } + + public int getArcCount() { + return arcs.size(); + } + } + + /** + * Create a new lightning arc from center to a random point. + */ + private static LightningArc createArc(float radius, int outerColor, int innerColor, int maxAge) { + // Random end point on sphere + double theta = rand.nextDouble() * Math.PI * 2; + double phi = Math.acos(2 * rand.nextDouble() - 1); + double r = radius * (0.5 + rand.nextDouble() * 0.5); + + double endX = r * Math.sin(phi) * Math.cos(theta); + double endY = r * Math.sin(phi) * Math.sin(theta); + double endZ = r * Math.cos(phi); + + int segments = 4 + rand.nextInt(3); + float displacement = radius * 0.25f; + + List points = generateLightningPath(0, 0, 0, endX, endY, endZ, segments, displacement); + + return new LightningArc(points, maxAge, outerColor, innerColor); + } + + /** + * Generate a jagged lightning path between two points. + */ + private static List generateLightningPath(double x1, double y1, double z1, + double x2, double y2, double z2, + int segments, float displacement) { + List points = new ArrayList<>(); + points.add(new double[]{x1, y1, z1}); + + double dx = x2 - x1; + double dy = y2 - y1; + double dz = z2 - z1; + + // Create perpendicular vectors for displacement + Vec3d dir = new Vec3d(dx, dy, dz); + Vec3d perp1 = dir.copy().perpendicular().normalize(); + Vec3d perp2 = dir.copy().crossProduct(perp1).normalize(); + + for (int i = 1; i < segments; i++) { + double t = (double) i / segments; + + double px = x1 + dx * t; + double py = y1 + dy * t; + double pz = z1 + dz * t; + + // Displacement strongest in middle + float strength = (float) (1.0 - Math.abs(t - 0.5) * 2.0) * displacement; + double offset1 = (rand.nextDouble() - 0.5) * 2 * strength; + double offset2 = (rand.nextDouble() - 0.5) * 2 * strength; + + px += perp1.x * offset1 + perp2.x * offset2; + py += perp1.y * offset1 + perp2.y * offset2; + pz += perp1.z * offset1 + perp2.z * offset2; + + points.add(new double[]{px, py, pz}); + } + + points.add(new double[]{x2, y2, z2}); + return points; + } + + /** + * Render the lightning path as quads. + */ + private static void renderBoltPath(Tessellator tess, List points, int color, float width, float alpha) { + if (alpha <= 0.01f) return; + + Color c = new Color(color); + int r = c.getRed(); + int g = c.getGreen(); + int b = c.getBlue(); + int a = Math.min(255, Math.max(0, (int) (alpha * 255))); + + for (int i = 0; i < points.size() - 1; i++) { + double[] p1 = points.get(i); + double[] p2 = points.get(i + 1); + + double segDx = p2[0] - p1[0]; + double segDy = p2[1] - p1[1]; + double segDz = p2[2] - p1[2]; + + Vec3d segDir = new Vec3d(segDx, segDy, segDz); + Vec3d perp = segDir.copy().perpendicular().normalize().multiply(width); + + // First quad + tess.startDrawingQuads(); + tess.setBrightness(0xF000F0); + tess.setColorRGBA(r, g, b, a); + + tess.addVertex(p1[0] - perp.x, p1[1] - perp.y, p1[2] - perp.z); + tess.addVertex(p1[0] + perp.x, p1[1] + perp.y, p1[2] + perp.z); + tess.addVertex(p2[0] + perp.x, p2[1] + perp.y, p2[2] + perp.z); + tess.addVertex(p2[0] - perp.x, p2[1] - perp.y, p2[2] - perp.z); + + tess.draw(); + + // Second quad (perpendicular for 3D look) + Vec3d perp2 = segDir.copy().crossProduct(perp).normalize().multiply(width); + + tess.startDrawingQuads(); + tess.setBrightness(0xF000F0); + tess.setColorRGBA(r, g, b, a); + + tess.addVertex(p1[0] - perp2.x, p1[1] - perp2.y, p1[2] - perp2.z); + tess.addVertex(p1[0] + perp2.x, p1[1] + perp2.y, p1[2] + perp2.z); + tess.addVertex(p2[0] + perp2.x, p2[1] + perp2.y, p2[2] + perp2.z); + tess.addVertex(p2[0] - perp2.x, p2[1] - perp2.y, p2[2] - perp2.z); + + tess.draw(); + } + } + + // ==================== INSTANT RENDERING (no persistence) ==================== + + /** + * Render a single instant lightning arc (no fading, drawn this frame only). + */ + public static void renderInstantArc(float radius, int outerColor, int innerColor) { + double theta = rand.nextDouble() * Math.PI * 2; + double phi = Math.acos(2 * rand.nextDouble() - 1); + double r = radius * (0.5 + rand.nextDouble() * 0.5); + + double endX = r * Math.sin(phi) * Math.cos(theta); + double endY = r * Math.sin(phi) * Math.sin(theta); + double endZ = r * Math.cos(phi); + + int segments = 4 + rand.nextInt(3); + float displacement = radius * 0.25f; + + List 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; + renderBoltPath(tess, points, outerColor, 0.025f, 0.35f); + renderBoltPath(tess, points, innerColor, 0.012f, 0.7f); + + GL11.glDepthMask(true); + GL11.glPopAttrib(); + } + + /** + * Render multiple instant arcs. + */ + public static void renderCracklingLightning(int count, float radius, int outerColor, int innerColor) { + for (int i = 0; i < count; i++) { + renderInstantArc(radius, outerColor, innerColor); + } + } +} diff --git a/src/main/java/kamkeel/npcs/client/renderer/lightning/LightningBolt.java b/src/main/java/kamkeel/npcs/client/renderer/lightning/LightningBolt.java new file mode 100644 index 000000000..6cf6e7d3a --- /dev/null +++ b/src/main/java/kamkeel/npcs/client/renderer/lightning/LightningBolt.java @@ -0,0 +1,295 @@ +package kamkeel.npcs.client.renderer.lightning; + +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * Lightning bolt data model with fractal segment generation. + * Adapted from Botania's LightningBolt by Vazkii/ChickenBones. + */ +public class LightningBolt { + + public static ConcurrentLinkedQueue boltList = new ConcurrentLinkedQueue<>(); + + public ArrayList segments = new ArrayList<>(); + public Vec3d start; + public Vec3d end; + + public double length; + public int numSegments0; + private int numSplits; + private boolean finalized; + private Random rand; + public long seed; + + public int particleAge; + public int particleMaxAge; + public boolean isDead; + + private World world; + private HashMap splitParents = new HashMap<>(); + + public float speed = 1.5F; + public static final int FADE_TIME = 4; // Short lifespan for projectile-attached lightning + + public int colorOuter; + public int colorInner; + + public LightningBolt(World world, Vec3d start, Vec3d end, float ticksPerMeter, long seed, int colorOuter, int colorInner) { + this.world = world; + this.seed = seed; + this.rand = new Random(seed); + + this.start = start; + this.end = end; + this.speed = ticksPerMeter; + + this.colorOuter = colorOuter; + this.colorInner = colorInner; + + this.numSegments0 = 1; + this.length = end.copy().subtract(start).mag(); + this.particleMaxAge = FADE_TIME + rand.nextInt(FADE_TIME) - FADE_TIME / 2; + this.particleAge = -(int) (length * speed); + + segments.add(new Segment(start, end)); + } + + /** + * Apply default fractal splitting for natural-looking lightning. + */ + public void defaultFractal() { + fractal(2, length / 1.5, 0.7F, 0.7F, 45); + fractal(2, length / 4, 0.5F, 0.8F, 50); + fractal(2, length / 15, 0.5F, 0.9F, 55); + fractal(2, length / 30, 0.5F, 1.0F, 60); + fractal(2, length / 60, 0, 0, 0); + fractal(2, length / 100, 0, 0, 0); + fractal(2, length / 400, 0, 0, 0); + } + + /** + * Simplified fractal for short-lived projectile lightning. + * Less detail but faster and more appropriate for fast-moving objects. + */ + public void simpleFractal() { + fractal(2, length / 2.0, 0.4F, 0.6F, 35); + fractal(2, length / 6, 0.3F, 0.7F, 40); + fractal(2, length / 20, 0, 0, 0); + } + + /** + * Apply fractal splitting to create branching lightning. + * + * @param splits Number of splits per segment + * @param amount Displacement amount + * @param splitChance Probability of branching (0-1) + * @param splitLength Length multiplier for branches + * @param splitAngle Angle for branch splits in degrees + */ + public void fractal(int splits, double amount, double splitChance, double splitLength, double splitAngle) { + if (finalized) return; + + ArrayList oldSegments = segments; + segments = new ArrayList<>(); + + Segment prev = null; + + for (Segment segment : oldSegments) { + prev = segment.prev; + + Vec3d subSegment = segment.diff.copy().multiply(1.0 / splits); + + BoltPoint[] newPoints = new BoltPoint[splits + 1]; + + Vec3d startPoint = segment.startPoint.point; + newPoints[0] = segment.startPoint; + newPoints[splits] = segment.endPoint; + + for (int i = 1; i < splits; i++) { + Vec3d randOff = segment.diff.copy().perpendicular().normalize() + .rotate(rand.nextFloat() * 360, segment.diff); + randOff.multiply((rand.nextFloat() - 0.5F) * amount * 2); + + Vec3d basePoint = startPoint.copy().add(subSegment.copy().multiply(i)); + + newPoints[i] = new BoltPoint(basePoint, randOff); + } + + for (int i = 0; i < splits; i++) { + Segment next = new Segment(newPoints[i], newPoints[i + 1], segment.light, + segment.segmentNo * splits + i, segment.splitNo); + next.prev = prev; + if (prev != null) { + prev.next = next; + } + + if (i != 0 && rand.nextFloat() < splitChance) { + Vec3d splitRot = next.diff.copy().xCrossProduct() + .rotate(rand.nextFloat() * 360, next.diff); + Vec3d diff = next.diff.copy() + .rotate((rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitRot) + .multiply(splitLength); + + numSplits++; + splitParents.put(numSplits, next.splitNo); + + Segment split = new Segment(newPoints[i], + new BoltPoint(newPoints[i + 1].basePoint, newPoints[i + 1].offsetVec.copy().add(diff)), + segment.light / 2F, next.segmentNo, numSplits); + split.prev = prev; + + segments.add(split); + } + + prev = next; + segments.add(next); + } + + if (segment.next != null) { + segment.next.prev = prev; + } + } + + numSegments0 *= splits; + } + + /** + * Finalize the bolt after all fractal passes. + */ + public void finalizeBolt() { + if (finalized) return; + finalized = true; + + calculateEndDiffs(); + Collections.sort(segments, new SegmentLightSorter()); + } + + private void calculateEndDiffs() { + Collections.sort(segments, new SegmentSorter()); + + for (Segment segment : segments) { + segment.calcEndDiffs(); + } + } + + public void onUpdate() { + particleAge++; + if (particleAge >= particleMaxAge) { + isDead = true; + } + } + + /** + * Update all active lightning bolts. Called from client tick handler. + */ + public static void updateAll() { + for (Iterator iterator = boltList.iterator(); iterator.hasNext(); ) { + LightningBolt bolt = iterator.next(); + bolt.onUpdate(); + if (bolt.isDead) { + iterator.remove(); + } + } + } + + // ==================== INNER CLASSES ==================== + + public class BoltPoint { + public Vec3d point; + public Vec3d basePoint; + public Vec3d offsetVec; + + public BoltPoint(Vec3d basePoint, Vec3d offsetVec) { + this.point = basePoint.copy().add(offsetVec); + this.basePoint = basePoint; + this.offsetVec = offsetVec; + } + } + + public class Segment { + public BoltPoint startPoint; + public BoltPoint endPoint; + + public Vec3d diff; + public Segment prev; + public Segment next; + + public Vec3d nextDiff; + public Vec3d prevDiff; + + public float sinPrev; + public float sinNext; + public float light; + + public int segmentNo; + public int splitNo; + + public Segment(BoltPoint start, BoltPoint end, float light, int segmentNo, int splitNo) { + this.startPoint = start; + this.endPoint = end; + this.light = light; + this.segmentNo = segmentNo; + this.splitNo = splitNo; + calcDiff(); + } + + public Segment(Vec3d start, Vec3d end) { + this(new BoltPoint(start, new Vec3d(0, 0, 0)), + new BoltPoint(end, new Vec3d(0, 0, 0)), 1, 0, 0); + } + + public void calcDiff() { + diff = endPoint.point.copy().subtract(startPoint.point); + } + + public void calcEndDiffs() { + if (prev != null) { + Vec3d prevDiffNorm = prev.diff.copy().normalize(); + Vec3d thisDiffNorm = diff.copy().normalize(); + + prevDiff = thisDiffNorm.copy().add(prevDiffNorm).normalize(); + sinPrev = (float) Math.sin(thisDiffNorm.angle(prevDiffNorm.multiply(-1)) / 2); + } else { + prevDiff = diff.copy().normalize(); + sinPrev = 1; + } + + if (next != null) { + Vec3d nextDiffNorm = next.diff.copy().normalize(); + Vec3d thisDiffNorm = diff.copy().normalize(); + + nextDiff = thisDiffNorm.add(nextDiffNorm).normalize(); + sinNext = (float) Math.sin(thisDiffNorm.angle(nextDiffNorm.multiply(-1)) / 2); + } else { + nextDiff = diff.copy().normalize(); + sinNext = 1; + } + } + } + + public class SegmentSorter implements Comparator { + @Override + public int compare(Segment o1, Segment o2) { + int comp = Integer.compare(o1.splitNo, o2.splitNo); + if (comp == 0) { + return Integer.compare(o1.segmentNo, o2.segmentNo); + } + return comp; + } + } + + public class SegmentLightSorter implements Comparator { + @Override + public int compare(Segment o1, Segment o2) { + return Float.compare(o2.light, o1.light); + } + } +} diff --git a/src/main/java/kamkeel/npcs/client/renderer/lightning/LightningHandler.java b/src/main/java/kamkeel/npcs/client/renderer/lightning/LightningHandler.java new file mode 100644 index 000000000..1951666e4 --- /dev/null +++ b/src/main/java/kamkeel/npcs/client/renderer/lightning/LightningHandler.java @@ -0,0 +1,202 @@ +package kamkeel.npcs.client.renderer.lightning; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import kamkeel.npcs.client.renderer.lightning.LightningBolt.Segment; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.entity.Entity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import org.lwjgl.opengl.GL11; + +import java.awt.Color; + +/** + * Handles rendering of lightning bolts in the world. + * Adapted from Botania's LightningHandler by Vazkii/ChickenBones. + * + * Register this handler with: MinecraftForge.EVENT_BUS.register(new LightningHandler()); + */ +@SideOnly(Side.CLIENT) +public class LightningHandler { + + private static final ResourceLocation TEXTURE_OUTER = new ResourceLocation("customnpcs", "textures/effects/lightning_outer.png"); + private static final ResourceLocation TEXTURE_INNER = new ResourceLocation("customnpcs", "textures/effects/lightning_inner.png"); + + public static int lightningCount = 0; + + private static Vec3d getRelativeViewVector(Vec3d pos) { + Entity renderEntity = Minecraft.getMinecraft().renderViewEntity; + return new Vec3d( + (float) renderEntity.posX - pos.x, + (float) renderEntity.posY + renderEntity.getEyeHeight() - pos.y, + (float) renderEntity.posZ - pos.z + ); + } + + @SubscribeEvent + public void onRenderWorldLast(RenderWorldLastEvent event) { + float partialTicks = event.partialTicks; + Entity entity = Minecraft.getMinecraft().thePlayer; + TextureManager textureManager = Minecraft.getMinecraft().renderEngine; + + double interpPosX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks; + double interpPosY = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks; + double interpPosZ = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks; + + if (LightningBolt.boltList.isEmpty()) { + return; + } + + GL11.glPushMatrix(); + GL11.glTranslated(-interpPosX, -interpPosY, -interpPosZ); + + Tessellator tessellator = Tessellator.instance; + + GL11.glDepthMask(false); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_CULL_FACE); + + lightningCount = 0; + + // Render outer layer (translucent glow) + for (LightningBolt bolt : LightningBolt.boltList) { + renderBolt(bolt, tessellator, partialTicks, false); + } + + // Render inner layer (bright core) + for (LightningBolt bolt : LightningBolt.boltList) { + renderBolt(bolt, tessellator, partialTicks, true); + } + + GL11.glEnable(GL11.GL_CULL_FACE); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthMask(true); + + GL11.glPopMatrix(); + } + + private void renderBolt(LightningBolt bolt, Tessellator tessellator, float partialTicks, boolean inner) { + lightningCount++; + + float boltAge = bolt.particleAge < 0 ? 0 : (float) bolt.particleAge / (float) bolt.particleMaxAge; + float mainAlpha; + if (!inner) { + mainAlpha = (1 - boltAge) * 0.4F; + } else { + mainAlpha = 1 - boltAge * 0.5F; + } + + int expandTime = (int) (bolt.length * bolt.speed); + + int renderStart = (int) ((expandTime / 2 - bolt.particleMaxAge + bolt.particleAge) / (float) (expandTime / 2) * bolt.numSegments0); + int renderEnd = (int) ((bolt.particleAge + expandTime) / (float) expandTime * bolt.numSegments0); + + for (Segment segment : bolt.segments) { + if (segment.segmentNo < renderStart || segment.segmentNo > renderEnd) { + continue; + } + + Vec3d playerVec = getRelativeViewVector(segment.startPoint.point).multiply(-1); + + double width = 0.008F * (playerVec.mag() / 8 + 1) * (1 + segment.light) * 0.4F; + + Vec3d diff1 = playerVec.copy().crossProduct(segment.prevDiff).normalize().multiply(width / segment.sinPrev); + Vec3d diff2 = playerVec.copy().crossProduct(segment.nextDiff).normalize().multiply(width / segment.sinNext); + + Vec3d startVec = segment.startPoint.point; + Vec3d endVec = segment.endPoint.point; + + int color = inner ? bolt.colorInner : bolt.colorOuter; + Color c = new Color(color); + int alpha = (int) (mainAlpha * segment.light * c.getAlpha()); + + tessellator.startDrawingQuads(); + tessellator.setBrightness(0xF000F0); + tessellator.setColorRGBA(c.getRed(), c.getGreen(), c.getBlue(), alpha); + + tessellator.addVertex(endVec.x - diff2.x, endVec.y - diff2.y, endVec.z - diff2.z); + tessellator.addVertex(startVec.x - diff1.x, startVec.y - diff1.y, startVec.z - diff1.z); + tessellator.addVertex(startVec.x + diff1.x, startVec.y + diff1.y, startVec.z + diff1.z); + tessellator.addVertex(endVec.x + diff2.x, endVec.y + diff2.y, endVec.z + diff2.z); + + tessellator.draw(); + + // Rounded end caps + if (segment.next == null) { + Vec3d roundEnd = segment.endPoint.point.copy().add(segment.diff.copy().normalize().multiply(width)); + + tessellator.startDrawingQuads(); + tessellator.setBrightness(0xF000F0); + tessellator.setColorRGBA(c.getRed(), c.getGreen(), c.getBlue(), alpha); + + tessellator.addVertex(roundEnd.x - diff2.x, roundEnd.y - diff2.y, roundEnd.z - diff2.z); + tessellator.addVertex(endVec.x - diff2.x, endVec.y - diff2.y, endVec.z - diff2.z); + tessellator.addVertex(endVec.x + diff2.x, endVec.y + diff2.y, endVec.z + diff2.z); + tessellator.addVertex(roundEnd.x + diff2.x, roundEnd.y + diff2.y, roundEnd.z + diff2.z); + + tessellator.draw(); + } + + if (segment.prev == null) { + Vec3d roundEnd = segment.startPoint.point.copy().subtract(segment.diff.copy().normalize().multiply(width)); + + tessellator.startDrawingQuads(); + tessellator.setBrightness(0xF000F0); + tessellator.setColorRGBA(c.getRed(), c.getGreen(), c.getBlue(), alpha); + + tessellator.addVertex(startVec.x - diff1.x, startVec.y - diff1.y, startVec.z - diff1.z); + tessellator.addVertex(roundEnd.x - diff1.x, roundEnd.y - diff1.y, roundEnd.z - diff1.z); + tessellator.addVertex(roundEnd.x + diff1.x, roundEnd.y + diff1.y, roundEnd.z + diff1.z); + tessellator.addVertex(startVec.x + diff1.x, startVec.y + diff1.y, startVec.z + diff1.z); + + tessellator.draw(); + } + } + } + + /** + * Spawn a lightning bolt between two points. + * + * @param world The world + * @param start Start position + * @param end End position + * @param ticksPerMeter Speed of bolt expansion + * @param seed Random seed for consistent appearance + * @param colorOuter Outer glow color (ARGB) + * @param colorInner Inner core color (ARGB) + */ + public static void spawnLightningBolt(World world, Vec3d start, Vec3d end, float ticksPerMeter, long seed, int colorOuter, int colorInner) { + LightningBolt bolt = new LightningBolt(world, start, end, ticksPerMeter, seed, colorOuter, colorInner); + bolt.defaultFractal(); + bolt.finalizeBolt(); + LightningBolt.boltList.add(bolt); + } + + /** + * Spawn a lightning bolt with automatic seed. + */ + public static void spawnLightningBolt(World world, Vec3d start, Vec3d end, float ticksPerMeter, int colorOuter, int colorInner) { + spawnLightningBolt(world, start, end, ticksPerMeter, System.nanoTime(), colorOuter, colorInner); + } + + /** + * Spawn a simple lightning bolt for projectiles - less detail, faster. + */ + public static void spawnSimpleLightningBolt(World world, Vec3d start, Vec3d end, float ticksPerMeter, int colorOuter, int colorInner) { + LightningBolt bolt = new LightningBolt(world, start, end, ticksPerMeter, System.nanoTime(), colorOuter, colorInner); + bolt.simpleFractal(); + bolt.finalizeBolt(); + LightningBolt.boltList.add(bolt); + } +} diff --git a/src/main/java/kamkeel/npcs/client/renderer/lightning/Quaternion.java b/src/main/java/kamkeel/npcs/client/renderer/lightning/Quaternion.java new file mode 100644 index 000000000..cda0307b7 --- /dev/null +++ b/src/main/java/kamkeel/npcs/client/renderer/lightning/Quaternion.java @@ -0,0 +1,85 @@ +package kamkeel.npcs.client.renderer.lightning; + +/** + * Quaternion class for axis-angle rotations in lightning calculations. + * Adapted from Botania's Quat by ChickenBones. + */ +public class Quaternion { + public double x; + public double y; + public double z; + public double s; + + public Quaternion() { + s = 1.0; + x = 0.0; + y = 0.0; + z = 0.0; + } + + public Quaternion(Quaternion quat) { + x = quat.x; + y = quat.y; + z = quat.z; + s = quat.s; + } + + public Quaternion(double s, double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + this.s = s; + } + + public static Quaternion aroundAxis(double ax, double ay, double az, double angle) { + angle *= 0.5; + double sinAngle = Math.sin(angle); + return new Quaternion(Math.cos(angle), ax * sinAngle, ay * sinAngle, az * sinAngle); + } + + public static Quaternion aroundAxis(Vec3d axis, double angle) { + return aroundAxis(axis.x, axis.y, axis.z, angle); + } + + public void multiply(Quaternion quat) { + double d = s * quat.s - x * quat.x - y * quat.y - z * quat.z; + double d1 = s * quat.x + x * quat.s - y * quat.z + z * quat.y; + double d2 = s * quat.y + x * quat.z + y * quat.s - z * quat.x; + double d3 = s * quat.z - x * quat.y + y * quat.x + z * quat.s; + s = d; + x = d1; + y = d2; + z = d3; + } + + public double mag() { + return Math.sqrt(x * x + y * y + z * z + s * s); + } + + public void normalize() { + double d = mag(); + if (d == 0.0) { + return; + } + d = 1.0 / d; + x *= d; + y *= d; + z *= d; + s *= d; + } + + public void rotate(Vec3d vec) { + double d = -x * vec.x - y * vec.y - z * vec.z; + double d1 = s * vec.x + y * vec.z - z * vec.y; + double d2 = s * vec.y - x * vec.z + z * vec.x; + double d3 = s * vec.z + x * vec.y - y * vec.x; + vec.x = d1 * s - d * x - d2 * z + d3 * y; + vec.y = d2 * s - d * y + d1 * z - d3 * x; + vec.z = d3 * s - d * z - d1 * y + d2 * x; + } + + @Override + public String toString() { + return "Quaternion(" + s + ", " + x + ", " + y + ", " + z + ")"; + } +} diff --git a/src/main/java/kamkeel/npcs/client/renderer/lightning/Vec3d.java b/src/main/java/kamkeel/npcs/client/renderer/lightning/Vec3d.java new file mode 100644 index 000000000..018e55bdb --- /dev/null +++ b/src/main/java/kamkeel/npcs/client/renderer/lightning/Vec3d.java @@ -0,0 +1,184 @@ +package kamkeel.npcs.client.renderer.lightning; + +import net.minecraft.entity.Entity; +import net.minecraft.util.Vec3; +import org.lwjgl.opengl.GL11; + +/** + * 3D Vector helper class for lightning calculations. + * Adapted from Botania's Vector3 by ChickenBones. + */ +public class Vec3d { + public double x; + public double y; + public double z; + + public Vec3d() { + } + + public Vec3d(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Vec3d(Vec3d vec) { + this.x = vec.x; + this.y = vec.y; + this.z = vec.z; + } + + public Vec3d(Vec3 vec) { + this.x = vec.xCoord; + this.y = vec.yCoord; + this.z = vec.zCoord; + } + + public Vec3d copy() { + return new Vec3d(this); + } + + public static Vec3d fromEntity(Entity e) { + return new Vec3d(e.posX, e.posY, e.posZ); + } + + public static Vec3d fromEntityCenter(Entity e) { + return new Vec3d(e.posX, e.posY - e.yOffset + e.height / 2, e.posZ); + } + + public Vec3d set(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + return this; + } + + public Vec3d set(Vec3d vec) { + this.x = vec.x; + this.y = vec.y; + this.z = vec.z; + return this; + } + + public double dotProduct(Vec3d vec) { + double d = vec.x * x + vec.y * y + vec.z * z; + if (d > 1 && d < 1.00001) d = 1; + else if (d < -1 && d > -1.00001) d = -1; + return d; + } + + public Vec3d crossProduct(Vec3d vec) { + double d = y * vec.z - z * vec.y; + double d1 = z * vec.x - x * vec.z; + double d2 = x * vec.y - y * vec.x; + x = d; + y = d1; + z = d2; + return this; + } + + public Vec3d add(double x, double y, double z) { + this.x += x; + this.y += y; + this.z += z; + return this; + } + + public Vec3d add(Vec3d vec) { + this.x += vec.x; + this.y += vec.y; + this.z += vec.z; + return this; + } + + public Vec3d subtract(Vec3d vec) { + this.x -= vec.x; + this.y -= vec.y; + this.z -= vec.z; + return this; + } + + public Vec3d multiply(double d) { + this.x *= d; + this.y *= d; + this.z *= d; + return this; + } + + public double mag() { + return Math.sqrt(x * x + y * y + z * z); + } + + public double magSquared() { + return x * x + y * y + z * z; + } + + public Vec3d normalize() { + double d = mag(); + if (d != 0) { + multiply(1 / d); + } + return this; + } + + public Vec3d perpendicular() { + if (z == 0) { + return zCrossProduct(); + } + return xCrossProduct(); + } + + public Vec3d xCrossProduct() { + double d = z; + double d1 = -y; + x = 0; + y = d; + z = d1; + return this; + } + + public Vec3d zCrossProduct() { + double d = y; + double d1 = -x; + x = d; + y = d1; + z = 0; + return this; + } + + public Vec3 toVec3() { + return Vec3.createVectorHelper(x, y, z); + } + + public double angle(Vec3d vec) { + return Math.acos(copy().normalize().dotProduct(vec.copy().normalize())); + } + + public Vec3d negate() { + x = -x; + y = -y; + z = -z; + return this; + } + + public Vec3d rotate(double angle, Vec3d axis) { + Quaternion.aroundAxis(axis.copy().normalize(), angle).rotate(this); + return this; + } + + public void glVertex() { + GL11.glVertex3d(x, y, z); + } + + @Override + public String toString() { + return "Vec3d(" + x + ", " + y + ", " + z + ")"; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Vec3d)) return false; + Vec3d v = (Vec3d) o; + return x == v.x && y == v.y && z == v.z; + } +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java index 0db44ea8a..5aa34a969 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java @@ -57,10 +57,15 @@ public class AbilityDisc extends Ability { // Visual properties private int innerColor = 0xFFFFFF; private int outerColor = 0xFF8800; - private float outerColorWidth = 1.8f; + private float outerColorWidth = 0.4f; // Additive offset from inner size private boolean outerColorEnabled = true; private float rotationSpeed = 5.0f; + // Lightning effect properties + private boolean lightningEffect = false; + private float lightningDensity = 0.15f; + private float lightningRadius = 0.5f; + public AbilityDisc() { this.typeId = "ability.cnpc.disc"; this.name = "Disc"; @@ -113,7 +118,8 @@ public class AbilityDisc extends Ability { boomerang, boomerangDelay, explosive, explosionRadius, explosionDamageFalloff, stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius ); world.spawnEntityInWorld(disc); @@ -184,6 +190,9 @@ public class AbilityDisc extends Ability { nbt.setFloat("outerColorWidth", outerColorWidth); nbt.setBoolean("outerColorEnabled", outerColorEnabled); nbt.setFloat("rotationSpeed", rotationSpeed); + nbt.setBoolean("lightningEffect", lightningEffect); + nbt.setFloat("lightningDensity", lightningDensity); + nbt.setFloat("lightningRadius", lightningRadius); } @Override @@ -209,9 +218,12 @@ public class AbilityDisc extends Ability { this.slowLevel = nbt.hasKey("slowLevel") ? nbt.getInteger("slowLevel") : 0; this.innerColor = nbt.hasKey("innerColor") ? nbt.getInteger("innerColor") : 0xFFFFFF; this.outerColor = nbt.hasKey("outerColor") ? nbt.getInteger("outerColor") : 0xFF8800; - this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 1.8f; + this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 0.4f; this.outerColorEnabled = !nbt.hasKey("outerColorEnabled") || nbt.getBoolean("outerColorEnabled"); this.rotationSpeed = nbt.hasKey("rotationSpeed") ? nbt.getFloat("rotationSpeed") : 5.0f; + this.lightningEffect = nbt.hasKey("lightningEffect") && nbt.getBoolean("lightningEffect"); + this.lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f; + this.lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f; } // Getters & Setters @@ -263,4 +275,10 @@ public class AbilityDisc extends Ability { public void setOuterColorEnabled(boolean outerColorEnabled) { this.outerColorEnabled = outerColorEnabled; } public float getRotationSpeed() { return rotationSpeed; } public void setRotationSpeed(float rotationSpeed) { this.rotationSpeed = rotationSpeed; } + public boolean hasLightningEffect() { return lightningEffect; } + public void setLightningEffect(boolean lightningEffect) { this.lightningEffect = lightningEffect; } + public float getLightningDensity() { return lightningDensity; } + public void setLightningDensity(float lightningDensity) { this.lightningDensity = lightningDensity; } + public float getLightningRadius() { return lightningRadius; } + public void setLightningRadius(float lightningRadius) { this.lightningRadius = lightningRadius; } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java index 58a224c64..9a5345435 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java @@ -8,6 +8,7 @@ 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 net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; @@ -56,10 +57,18 @@ public class AbilityEnergyBeam extends Ability { // Visual properties private int innerColor = 0xFFFFFF; private int outerColor = 0x00AAFF; - private float outerColorWidth = 1.8f; + private float outerColorWidth = 0.4f; // Additive offset from inner size private boolean outerColorEnabled = true; private float rotationSpeed = 6.0f; + // Lightning effect properties (only on head) + private boolean lightningEffect = false; + private float lightningDensity = 0.15f; + private float lightningRadius = 0.5f; + + // Transient state for beam entity (used during windup charging) + private transient int beamEntityId = -1; + public AbilityEnergyBeam() { this.typeId = "ability.cnpc.beam"; this.name = "Beam"; @@ -99,22 +108,43 @@ public class AbilityEnergyBeam extends Ability { public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { if (world.isRemote) return; - double spawnX = npc.posX; - double spawnY = npc.posY + npc.getEyeHeight() * 0.7; - double spawnZ = npc.posZ; + // Find and start firing the beam that was spawned during windup + if (beamEntityId != -1) { + Entity entity = world.getEntityByID(beamEntityId); + if (entity instanceof EntityAbilityBeam) { + EntityAbilityBeam beam = (EntityAbilityBeam) entity; + beam.startFiring(target); + } + beamEntityId = -1; + } + } - EntityAbilityBeam beam = new EntityAbilityBeam( - world, npc, target, - spawnX, spawnY, spawnZ, - beamWidth, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, - damage, knockback, knockbackUp, - speed, homing, homingStrength, homingRange, - explosive, explosionRadius, explosionDamageFalloff, - stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime - ); + @Override + public void onWindUpTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { + if (world.isRemote) return; - world.spawnEntityInWorld(beam); + // Spawn beam in charging mode on first tick of windup + if (tick == 1) { + float offsetDist = 1.0f; + + // Create beam in charging mode - follows NPC's look direction during windup + EntityAbilityBeam beam = EntityAbilityBeam.createCharging( + world, npc, target, + beamWidth, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, + speed, homing, homingStrength, homingRange, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, + lockMovement, // Anchored mode + windUpTicks, // Charge duration = windup duration + offsetDist // Offset distance in front of NPC + ); + + world.spawnEntityInWorld(beam); + beamEntityId = beam.getEntityId(); + } } @Override @@ -127,6 +157,14 @@ public class AbilityEnergyBeam extends Ability { @Override public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { + // Despawn charging beam if interrupted during windup + if (beamEntityId != -1) { + Entity entity = npc.worldObj.getEntityByID(beamEntityId); + if (entity != null) { + entity.setDead(); + } + beamEntityId = -1; + } } @Override @@ -180,6 +218,9 @@ public class AbilityEnergyBeam extends Ability { nbt.setFloat("outerColorWidth", outerColorWidth); nbt.setBoolean("outerColorEnabled", outerColorEnabled); nbt.setFloat("rotationSpeed", rotationSpeed); + nbt.setBoolean("lightningEffect", lightningEffect); + nbt.setFloat("lightningDensity", lightningDensity); + nbt.setFloat("lightningRadius", lightningRadius); } @Override @@ -203,9 +244,12 @@ public class AbilityEnergyBeam extends Ability { this.slowLevel = nbt.hasKey("slowLevel") ? nbt.getInteger("slowLevel") : 0; this.innerColor = nbt.hasKey("innerColor") ? nbt.getInteger("innerColor") : 0xFFFFFF; this.outerColor = nbt.hasKey("outerColor") ? nbt.getInteger("outerColor") : 0x00AAFF; - this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 1.8f; + this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 0.4f; this.outerColorEnabled = !nbt.hasKey("outerColorEnabled") || nbt.getBoolean("outerColorEnabled"); this.rotationSpeed = nbt.hasKey("rotationSpeed") ? nbt.getFloat("rotationSpeed") : 6.0f; + this.lightningEffect = nbt.hasKey("lightningEffect") && nbt.getBoolean("lightningEffect"); + this.lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f; + this.lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f; } // Getters & Setters @@ -253,4 +297,10 @@ public class AbilityEnergyBeam extends Ability { public void setOuterColorEnabled(boolean outerColorEnabled) { this.outerColorEnabled = outerColorEnabled; } public float getRotationSpeed() { return rotationSpeed; } public void setRotationSpeed(float rotationSpeed) { this.rotationSpeed = rotationSpeed; } + public boolean hasLightningEffect() { return lightningEffect; } + public void setLightningEffect(boolean lightningEffect) { this.lightningEffect = lightningEffect; } + public float getLightningDensity() { return lightningDensity; } + public void setLightningDensity(float lightningDensity) { this.lightningDensity = lightningDensity; } + public float getLightningRadius() { return lightningRadius; } + public void setLightningRadius(float lightningRadius) { this.lightningRadius = lightningRadius; } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java index 64a3da8ad..77df6ff35 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java @@ -46,9 +46,14 @@ public class AbilityLaserShot extends Ability { // Visual properties private int innerColor = 0xFFFFFF; private int outerColor = 0xFF0000; - private float outerColorWidth = 1.8f; + private float outerColorWidth = 0.4f; // Additive offset from inner width private boolean outerColorEnabled = true; + // Lightning effect properties + private boolean lightningEffect = false; + private float lightningDensity = 0.15f; + private float lightningRadius = 0.5f; + public AbilityLaserShot() { this.typeId = "ability.cnpc.laser_shot"; this.name = "Laser Shot"; @@ -110,7 +115,8 @@ public class AbilityLaserShot extends Ability { expansionSpeed, lingerTicks, explosive, explosionRadius, explosionDamageFalloff, stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius ); world.spawnEntityInWorld(laser); @@ -148,6 +154,9 @@ public class AbilityLaserShot extends Ability { nbt.setInteger("outerColor", outerColor); nbt.setFloat("outerColorWidth", outerColorWidth); nbt.setBoolean("outerColorEnabled", outerColorEnabled); + nbt.setBoolean("lightningEffect", lightningEffect); + nbt.setFloat("lightningDensity", lightningDensity); + nbt.setFloat("lightningRadius", lightningRadius); } @Override @@ -168,8 +177,11 @@ public class AbilityLaserShot extends Ability { this.slowLevel = nbt.hasKey("slowLevel") ? nbt.getInteger("slowLevel") : 0; this.innerColor = nbt.hasKey("innerColor") ? nbt.getInteger("innerColor") : 0xFFFFFF; this.outerColor = nbt.hasKey("outerColor") ? nbt.getInteger("outerColor") : 0xFF0000; - this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 1.8f; + this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 0.4f; this.outerColorEnabled = !nbt.hasKey("outerColorEnabled") || nbt.getBoolean("outerColorEnabled"); + this.lightningEffect = nbt.hasKey("lightningEffect") && nbt.getBoolean("lightningEffect"); + this.lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f; + this.lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f; } // Getters & Setters @@ -209,4 +221,10 @@ public class AbilityLaserShot extends Ability { public void setOuterColorWidth(float outerColorWidth) { this.outerColorWidth = outerColorWidth; } public boolean isOuterColorEnabled() { return outerColorEnabled; } public void setOuterColorEnabled(boolean outerColorEnabled) { this.outerColorEnabled = outerColorEnabled; } + public boolean hasLightningEffect() { return lightningEffect; } + public void setLightningEffect(boolean lightningEffect) { this.lightningEffect = lightningEffect; } + public float getLightningDensity() { return lightningDensity; } + public void setLightningDensity(float lightningDensity) { this.lightningDensity = lightningDensity; } + public float getLightningRadius() { return lightningRadius; } + public void setLightningRadius(float lightningRadius) { this.lightningRadius = lightningRadius; } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java index 7b6f34b68..358b82896 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java @@ -53,10 +53,16 @@ public class AbilityOrb extends Ability { // Visual properties private int innerColor = 0xFFFFFF; // White core private int outerColor = 0x8888FF; // Light blue glow - private float outerColorWidth = 1.8f; // Multiplier for outer glow size + private float outerColorWidth = 0.4f; // Additive offset from inner size private boolean outerColorEnabled = true; // Whether to render outer glow private float rotationSpeed = 4.0f; // Degrees per tick + // Lightning effect properties + private boolean lightningEffect = false; + private float lightningDensity = 0.15f; // Bolts spawned per tick (0.15 = ~15% chance per frame) + private float lightningRadius = 0.5f; // Max distance lightning arcs - scales with orbSize + private int lightningFadeTime = 6; // Ticks before lightning fades out + public AbilityOrb() { this.typeId = "ability.cnpc.orb"; this.name = "Orb"; @@ -110,7 +116,8 @@ public class AbilityOrb extends Ability { orbSpeed, homing, homingStrength, homingRange, explosive, explosionRadius, explosionDamageFalloff, stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, lightningFadeTime ); world.spawnEntityInWorld(orb); @@ -181,6 +188,10 @@ public class AbilityOrb extends Ability { nbt.setFloat("outerColorWidth", outerColorWidth); nbt.setBoolean("outerColorEnabled", outerColorEnabled); nbt.setFloat("rotationSpeed", rotationSpeed); + nbt.setBoolean("lightningEffect", lightningEffect); + nbt.setFloat("lightningDensity", lightningDensity); + nbt.setFloat("lightningRadius", lightningRadius); + nbt.setInteger("lightningFadeTime", lightningFadeTime); } @Override @@ -203,9 +214,13 @@ public class AbilityOrb extends Ability { this.slowLevel = nbt.hasKey("slowLevel") ? nbt.getInteger("slowLevel") : 0; this.innerColor = nbt.hasKey("innerColor") ? nbt.getInteger("innerColor") : 0xFFFFFF; this.outerColor = nbt.hasKey("outerColor") ? nbt.getInteger("outerColor") : 0x8888FF; - this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 1.8f; + this.outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 0.4f; this.outerColorEnabled = !nbt.hasKey("outerColorEnabled") || nbt.getBoolean("outerColorEnabled"); this.rotationSpeed = nbt.hasKey("rotationSpeed") ? nbt.getFloat("rotationSpeed") : 4.0f; + this.lightningEffect = nbt.hasKey("lightningEffect") && nbt.getBoolean("lightningEffect"); + this.lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f; + this.lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f; + this.lightningFadeTime = nbt.hasKey("lightningFadeTime") ? nbt.getInteger("lightningFadeTime") : 6; } // Getters & Setters @@ -376,4 +391,36 @@ public class AbilityOrb extends Ability { public void setRotationSpeed(float rotationSpeed) { this.rotationSpeed = rotationSpeed; } + + public boolean hasLightningEffect() { + return lightningEffect; + } + + public void setLightningEffect(boolean lightningEffect) { + this.lightningEffect = lightningEffect; + } + + public float getLightningDensity() { + return lightningDensity; + } + + public void setLightningDensity(float lightningDensity) { + this.lightningDensity = lightningDensity; + } + + public float getLightningRadius() { + return lightningRadius; + } + + public void setLightningRadius(float lightningRadius) { + this.lightningRadius = lightningRadius; + } + + public int getLightningFadeTime() { + return lightningFadeTime; + } + + public void setLightningFadeTime(int lightningFadeTime) { + this.lightningFadeTime = lightningFadeTime; + } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/telegraph/TelegraphInstance.java b/src/main/java/kamkeel/npcs/controllers/data/telegraph/TelegraphInstance.java index 71d63f9c6..a5d2f0d95 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/telegraph/TelegraphInstance.java +++ b/src/main/java/kamkeel/npcs/controllers/data/telegraph/TelegraphInstance.java @@ -17,12 +17,18 @@ public class TelegraphInstance { private String instanceId; private Telegraph telegraph; - // Position + // Position (current) private double x; private double y; private double z; private float yaw; + // Position (previous tick - for interpolation) + private double prevX; + private double prevY; + private double prevZ; + private float prevYaw; + // Entity tracking private int entityIdToFollow = -1; private int casterEntityId = -1; @@ -50,6 +56,11 @@ public class TelegraphInstance { this.y = y; this.z = z; this.yaw = yaw; + // Initialize prev positions to current for first frame + this.prevX = x; + this.prevY = y; + this.prevZ = z; + this.prevYaw = yaw; this.remainingTicks = telegraph.getDurationTicks(); this.totalTicks = telegraph.getDurationTicks(); } @@ -69,6 +80,12 @@ public class TelegraphInstance { return false; } + // Save previous position for interpolation + this.prevX = this.x; + this.prevY = this.y; + this.prevZ = this.z; + this.prevYaw = this.yaw; + remainingTicks--; // Update position if following an entity @@ -144,6 +161,43 @@ public class TelegraphInstance { return (alpha << 24) | (r << 16) | (g << 8) | b; } + // ═══════════════════════════════════════════════════════════════════ + // INTERPOLATED POSITION (for smooth rendering) + // ═══════════════════════════════════════════════════════════════════ + + /** + * Get interpolated X position for smooth rendering. + */ + public double getInterpolatedX(float partialTicks) { + return prevX + (x - prevX) * partialTicks; + } + + /** + * Get interpolated Y position for smooth rendering. + */ + public double getInterpolatedY(float partialTicks) { + return prevY + (y - prevY) * partialTicks; + } + + /** + * Get interpolated Z position for smooth rendering. + */ + public double getInterpolatedZ(float partialTicks) { + return prevZ + (z - prevZ) * partialTicks; + } + + /** + * Get interpolated yaw for smooth rendering. + * Handles angle wrapping for smooth rotation. + */ + public float getInterpolatedYaw(float partialTicks) { + // Handle angle wrapping to prevent spinning the wrong way + float diff = yaw - prevYaw; + while (diff > 180.0f) diff -= 360.0f; + while (diff < -180.0f) diff += 360.0f; + return prevYaw + diff * partialTicks; + } + // ═══════════════════════════════════════════════════════════════════ // NBT SERIALIZATION // ═══════════════════════════════════════════════════════════════════ diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java index b0c3579e7..ab62c4ca9 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java @@ -47,6 +47,23 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { // Origin stays fixed (or follows owner) private boolean attachedToOwner = true; + // Whether to render tail orb (only when anchored) + private boolean renderTailOrb = true; + + // Charging state (during windup) + private boolean charging = false; + private int chargeDuration = 40; + private int chargeTick = 0; + private float chargeOffsetDistance = 1.0f; + + // Trail fading for non-anchored beams (comet effect) + private boolean fadeTrail = false; + private int trailFadeTime = 20; // Ticks for trail to fully fade + private List trailPointAges = new ArrayList<>(); + + // Data watcher index for charging state (synced to clients) + private static final int DW_CHARGING = 20; + // Debug logging private static final boolean DEBUG_LOGGING = true; @@ -54,8 +71,32 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { super(world); } + @Override + protected void entityInit() { + super.entityInit(); + // Register data watcher for charging state + this.dataWatcher.addObject(DW_CHARGING, (byte) 0); + } + /** - * Full constructor with all parameters. + * Check if beam is in charging state (synced via data watcher). + */ + public boolean isCharging() { + return this.dataWatcher.getWatchableObjectByte(DW_CHARGING) == 1; + } + + /** + * Set charging state (server only, synced to clients via data watcher). + */ + private void setCharging(boolean value) { + this.charging = value; + if (!worldObj.isRemote) { + this.dataWatcher.updateObject(DW_CHARGING, (byte) (value ? 1 : 0)); + } + } + + /** + * Full constructor with all parameters (no lightning). */ public EntityAbilityBeam(World world, EntityNPCInterface owner, EntityLivingBase target, double x, double y, double z, @@ -66,15 +107,62 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { boolean explosive, float explosionRadius, float explosionDamageFalloff, int stunDuration, int slowDuration, int slowLevel, float maxDistance, int maxLifetime) { + this(world, owner, target, x, y, z, + beamWidth, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, speed, homing, homingStrength, homingRange, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, maxDistance, maxLifetime, + false, 0.15f, 0.5f); + } + + /** + * Full constructor with all parameters including lightning. + */ + public EntityAbilityBeam(World world, EntityNPCInterface owner, EntityLivingBase target, + double x, double y, double z, + float beamWidth, float headSize, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + float speed, boolean homing, float homingStrength, float homingRange, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius) { + this(world, owner, target, x, y, z, + beamWidth, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, speed, homing, homingStrength, homingRange, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, + true); // Default to anchored mode + } + + /** + * Full constructor with all parameters including lightning and anchored mode. + * @param anchoredMode If true, origin follows owner and tail orb is rendered. + * If false, beam is free-moving with trailing length (no tail orb). + */ + public EntityAbilityBeam(World world, EntityNPCInterface owner, EntityLivingBase target, + double x, double y, double z, + float beamWidth, float headSize, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + float speed, boolean homing, float homingStrength, float homingRange, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius, + boolean anchoredMode) { super(world); - // Initialize base properties + // Initialize base properties with lightning initProjectile(owner, target, x, y, z, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, damage, knockback, knockbackUp, explosive, explosionRadius, explosionDamageFalloff, stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime); + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, 6); // Beam-specific properties this.speed = speed; @@ -84,6 +172,10 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { this.beamWidth = beamWidth; this.headSize = headSize; + // Anchored mode controls whether origin follows owner and tail orb is rendered + this.attachedToOwner = anchoredMode; + this.renderTailOrb = anchoredMode; + // Initialize head offset at origin (0,0,0 relative) this.headOffsetX = 0; this.headOffsetY = 0; @@ -119,6 +211,118 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { } } + /** + * Create a beam in charging mode (for windup phase). + * The beam will grow from 0 to headSize over chargeDuration ticks. + * Position follows the owner's look direction. + */ + public static EntityAbilityBeam createCharging(World world, EntityNPCInterface owner, EntityLivingBase target, + float beamWidth, float headSize, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + float speed, boolean homing, float homingStrength, float homingRange, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius, + boolean anchoredMode, int chargeDuration, float chargeOffsetDistance) { + // Calculate initial position in front of owner's look direction + float yaw = (float) Math.toRadians(owner.rotationYawHead); + double spawnX = owner.posX - Math.sin(yaw) * chargeOffsetDistance; + double spawnY = owner.posY + owner.getEyeHeight() * 0.7; + double spawnZ = owner.posZ + Math.cos(yaw) * chargeOffsetDistance; + + EntityAbilityBeam beam = new EntityAbilityBeam( + world, owner, target, + spawnX, spawnY, spawnZ, + beamWidth, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, speed, homing, homingStrength, homingRange, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, + anchoredMode); + + // Set charging state (uses data watcher for client sync) + beam.setCharging(true); + beam.chargeDuration = chargeDuration; + beam.chargeTick = 0; + beam.chargeOffsetDistance = chargeOffsetDistance; + + // Non-anchored beams have fading trail (comet effect) + beam.fadeTrail = !anchoredMode; + + // Clear motion while charging + beam.motionX = 0; + beam.motionY = 0; + beam.motionZ = 0; + + return beam; + } + + /** + * Start the beam firing (exit charging mode). + * Called by ability when windup ends. + * + * For anchored beams: origin follows owner, head starts at charged position + * For non-anchored beams: origin fixed at charged position, head starts there + */ + public void startFiring(EntityLivingBase target) { + if (!isCharging()) return; + + setCharging(false); + + // Origin (tail) stays at the charged position - where the orb was + // This is the same for both anchored and non-anchored modes + startX = posX; + startY = posY; + startZ = posZ; + + // Head starts at the origin (tail position) + headOffsetX = 0; + headOffsetY = 0; + headOffsetZ = 0; + prevHeadOffsetX = 0; + prevHeadOffsetY = 0; + prevHeadOffsetZ = 0; + + // Origin no longer follows owner after firing starts + // (for anchored mode, tail is fixed in space; for non-anchored, there's no tail) + attachedToOwner = false; + + // Initialize trail with just the origin point + trailPoints.clear(); + trailPointAges.clear(); + trailPoints.add(Vec3.createVectorHelper(0, 0, 0)); + if (fadeTrail) trailPointAges.add(0); + + // Calculate velocity toward target (head starts at origin = startX/Y/Z) + Entity owner = getOwner(); + + if (target != null) { + double dx = target.posX - startX; + double dy = (target.posY + target.height * 0.5) - startY; + double dz = target.posZ - startZ; + double len = Math.sqrt(dx * dx + dy * dy + dz * dz); + if (len > 0) { + motionX = (dx / len) * speed; + motionY = (dy / len) * speed; + motionZ = (dz / len) * speed; + } + } else if (owner != null) { + float yaw = (float) Math.toRadians(owner.rotationYaw); + float pitch = (float) Math.toRadians(owner.rotationPitch); + motionX = -Math.sin(yaw) * Math.cos(pitch) * speed; + motionY = -Math.sin(pitch) * speed; + motionZ = Math.cos(yaw) * Math.cos(pitch) * speed; + } + + if (DEBUG_LOGGING && !worldObj.isRemote) { + LogWriter.info("[Beam] startFiring: origin=(" + startX + "," + startY + "," + startZ + + ") headOffset=(" + headOffsetX + "," + headOffsetY + "," + headOffsetZ + + ") motion=(" + motionX + "," + motionY + "," + motionZ + ")"); + } + } + @Override protected boolean checkMaxDistance() { // Check distance using head offset (distance from origin) @@ -136,19 +340,41 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { @Override protected void updateProjectile() { + // Handle charging state (windup phase) - use isCharging() for synced value + if (isCharging()) { + updateCharging(); + return; + } + // Store previous head offset for interpolation prevHeadOffsetX = headOffsetX; prevHeadOffsetY = headOffsetY; prevHeadOffsetZ = headOffsetZ; + // Age trail points for fading effect + if (fadeTrail) { + ageTrailPoints(); + } + if (worldObj.isRemote) { - // Client: interpolate entity position, derive head from offset + // Client: interpolate entity position handleClientInterpolation(); - // Client also updates head offset to match motion for smooth movement - headOffsetX += motionX; - headOffsetY += motionY; - headOffsetZ += motionZ; + // Client: update origin if attached to owner (mirrors server logic) + if (attachedToOwner) { + Entity owner = getOwner(); + if (owner != null) { + startX = owner.posX; + startY = owner.posY + owner.getEyeHeight() * 0.7; + startZ = owner.posZ; + } + } + + // Client: derive head offset from entity position and origin + // Entity position = head world position, so headOffset = pos - origin + headOffsetX = posX - startX; + headOffsetY = posY - startY; + headOffsetZ = posZ - startZ; // Add trail point on client addTrailPoint(); @@ -166,7 +392,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { Entity owner = getOwner(); if (owner != null) { startX = owner.posX; - startY = owner.posY + owner.height * 0.7; + startY = owner.posY + owner.getEyeHeight() * 0.7; startZ = owner.posZ; } } @@ -201,10 +427,66 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { } } + /** + * Update during charging state - follow owner's look direction. + */ + private void updateCharging() { + chargeTick++; + + Entity owner = getOwner(); + if (owner == null || owner.isDead) { + setDead(); + return; + } + + // Follow owner's head/look direction (rotationYawHead for NPCs/players) + float yaw; + if (owner instanceof EntityLivingBase) { + yaw = (float) Math.toRadians(((EntityLivingBase) owner).rotationYawHead); + } else { + yaw = (float) Math.toRadians(owner.rotationYaw); + } + + double offsetX = -Math.sin(yaw) * chargeOffsetDistance; + double offsetZ = Math.cos(yaw) * chargeOffsetDistance; + + double newX = owner.posX + offsetX; + double newY = owner.posY + owner.getEyeHeight() * 0.7; + double newZ = owner.posZ + offsetZ; + + setPosition(newX, newY, newZ); + + // Also update origin for when firing starts + startX = newX; + startY = newY; + startZ = newZ; + } + + /** + * Age trail points and remove old ones (for comet effect). + */ + private void ageTrailPoints() { + // Age all trail points + for (int i = 0; i < trailPointAges.size(); i++) { + trailPointAges.set(i, trailPointAges.get(i) + 1); + } + + // Remove trail points that have fully faded + while (!trailPointAges.isEmpty() && trailPointAges.get(0) >= trailFadeTime) { + trailPointAges.remove(0); + if (!trailPoints.isEmpty()) { + trailPoints.remove(0); + } + } + } + private void addTrailPoint() { // Trail points are RELATIVE to origin if (trailPoints.isEmpty()) { trailPoints.add(Vec3.createVectorHelper(headOffsetX, headOffsetY, headOffsetZ)); + if (fadeTrail) { + trailPointAges.add(0); + } return; } @@ -217,10 +499,15 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { if (dist >= MIN_POINT_DISTANCE) { trailPoints.add(Vec3.createVectorHelper(headOffsetX, headOffsetY, headOffsetZ)); + if (fadeTrail) { + trailPointAges.add(0); + } - // Limit trail length - while (trailPoints.size() > MAX_TRAIL_POINTS) { - trailPoints.remove(0); + // Limit trail length (only if not using fading - fading handles its own cleanup) + if (!fadeTrail) { + while (trailPoints.size() > MAX_TRAIL_POINTS) { + trailPoints.remove(0); + } } } } @@ -369,6 +656,59 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { return startZ; } + /** + * Whether the tail orb should be rendered (only true in anchored mode). + */ + public boolean shouldRenderTailOrb() { + return renderTailOrb; + } + + /** + * Whether the beam is attached to its owner (anchored mode). + */ + public boolean isAttachedToOwner() { + return attachedToOwner; + } + + /** + * Get the charge progress (0-1). + */ + public float getChargeProgress() { + if (chargeDuration <= 0) return 1.0f; + return Math.min(1.0f, (float) chargeTick / chargeDuration); + } + + /** + * Get interpolated charge progress for smooth rendering. + */ + public float getInterpolatedChargeProgress(float partialTicks) { + if (chargeDuration <= 0) return 1.0f; + float prevProgress = Math.max(0, (float) (chargeTick - 1) / chargeDuration); + float currProgress = Math.min(1.0f, (float) chargeTick / chargeDuration); + return prevProgress + (currProgress - prevProgress) * partialTicks; + } + + /** + * Whether trail should fade (comet effect for non-anchored beams). + */ + public boolean hasFadingTrail() { + return fadeTrail; + } + + /** + * Get trail point ages for fading calculation. + */ + public List getTrailPointAges() { + return trailPointAges; + } + + /** + * Get trail fade time in ticks. + */ + public int getTrailFadeTime() { + return trailFadeTime; + } + // ==================== NBT ==================== @Override @@ -386,6 +726,16 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { this.prevHeadOffsetY = this.headOffsetY; this.prevHeadOffsetZ = this.headOffsetZ; this.attachedToOwner = !nbt.hasKey("AttachedToOwner") || nbt.getBoolean("AttachedToOwner"); + this.renderTailOrb = !nbt.hasKey("RenderTailOrb") || nbt.getBoolean("RenderTailOrb"); + // Read charging state and sync to data watcher + boolean isCharging = nbt.hasKey("Charging") && nbt.getBoolean("Charging"); + this.charging = isCharging; + this.dataWatcher.updateObject(DW_CHARGING, (byte) (isCharging ? 1 : 0)); + this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 40; + this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0; + this.chargeOffsetDistance = nbt.hasKey("ChargeOffsetDistance") ? nbt.getFloat("ChargeOffsetDistance") : 1.0f; + this.fadeTrail = nbt.hasKey("FadeTrail") && nbt.getBoolean("FadeTrail"); + this.trailFadeTime = nbt.hasKey("TrailFadeTime") ? nbt.getInteger("TrailFadeTime") : 20; // Read trail points (relative to origin) trailPoints.clear(); @@ -414,6 +764,13 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { nbt.setDouble("HeadOffsetY", headOffsetY); nbt.setDouble("HeadOffsetZ", headOffsetZ); nbt.setBoolean("AttachedToOwner", attachedToOwner); + nbt.setBoolean("RenderTailOrb", renderTailOrb); + nbt.setBoolean("Charging", isCharging()); + nbt.setInteger("ChargeDuration", chargeDuration); + nbt.setInteger("ChargeTick", chargeTick); + nbt.setFloat("ChargeOffsetDistance", chargeOffsetDistance); + nbt.setBoolean("FadeTrail", fadeTrail); + nbt.setInteger("TrailFadeTime", trailFadeTime); // Write trail points NBTTagList trailList = new NBTTagList(); diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java index ef513f80d..c0127286f 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java @@ -40,7 +40,7 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { } /** - * Full constructor with all parameters. + * Full constructor with all parameters (no lightning). */ public EntityAbilityDisc(World world, EntityNPCInterface owner, EntityLivingBase target, double x, double y, double z, @@ -52,15 +52,38 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { boolean explosive, float explosionRadius, float explosionDamageFalloff, int stunDuration, int slowDuration, int slowLevel, float maxDistance, int maxLifetime) { + this(world, owner, target, x, y, z, + discRadius, discThickness, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, speed, homing, homingStrength, homingRange, + boomerang, boomerangDelay, explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, maxDistance, maxLifetime, + false, 0.15f, 0.5f); + } + + /** + * Full constructor with all parameters including lightning. + */ + public EntityAbilityDisc(World world, EntityNPCInterface owner, EntityLivingBase target, + double x, double y, double z, + float discRadius, float discThickness, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + float speed, boolean homing, float homingStrength, float homingRange, + boolean boomerang, int boomerangDelay, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius) { super(world); - // Initialize base properties (use discRadius as size for base) + // Initialize base properties with lightning (use discRadius as size for base) initProjectile(owner, target, x, y, z, discRadius, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, damage, knockback, knockbackUp, explosive, explosionRadius, explosionDamageFalloff, stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime); + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, 6); // Disc-specific properties this.speed = speed; diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java index 78668377a..7ad1f0d45 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java @@ -45,7 +45,7 @@ public class EntityAbilityLaser extends EntityAbilityProjectile { } /** - * Full constructor with all parameters. + * Full constructor with all parameters (no lightning). */ public EntityAbilityLaser(World world, EntityNPCInterface owner, EntityLivingBase target, double x, double y, double z, @@ -56,15 +56,37 @@ public class EntityAbilityLaser extends EntityAbilityProjectile { boolean explosive, float explosionRadius, float explosionDamageFalloff, int stunDuration, int slowDuration, int slowLevel, float maxDistance, int maxLifetime) { + this(world, owner, target, x, y, z, + laserWidth, innerColor, outerColor, outerColorEnabled, outerColorWidth, + damage, knockback, knockbackUp, expansionSpeed, lingerTicks, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, maxDistance, maxLifetime, + false, 0.15f, 0.5f); + } + + /** + * Full constructor with all parameters including lightning. + */ + public EntityAbilityLaser(World world, EntityNPCInterface owner, EntityLivingBase target, + double x, double y, double z, + float laserWidth, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, + float damage, float knockback, float knockbackUp, + float expansionSpeed, int lingerTicks, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius) { super(world); - // Initialize base properties + // Initialize base properties with lightning initProjectile(owner, target, x, y, z, laserWidth, innerColor, outerColor, outerColorEnabled, outerColorWidth, 0.0f, // No rotation for laser damage, knockback, knockbackUp, explosive, explosionRadius, explosionDamageFalloff, stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime); + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, 6); // Laser-specific properties this.laserWidth = laserWidth; diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java index de447333b..38e3741f9 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java @@ -41,15 +41,39 @@ public class EntityAbilityOrb extends EntityAbilityProjectile { boolean explosive, float explosionRadius, float explosionDamageFalloff, int stunDuration, int slowDuration, int slowLevel, float maxDistance, int maxLifetime) { + this(world, owner, target, x, y, z, + orbSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, + speed, homing, homingStrength, homingRange, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, + maxDistance, maxLifetime, + false, 0.15f, 0.5f, 6); // Default: no lightning, low density, small radius, 6 tick fade + } + + /** + * Full constructor with lightning effect support. + */ + public EntityAbilityOrb(World world, EntityNPCInterface owner, EntityLivingBase target, + double x, double y, double z, + float orbSize, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + float speed, boolean homing, float homingStrength, float homingRange, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius, int lightningFadeTime) { super(world); - // Initialize base properties + // Initialize base properties with lightning initProjectile(owner, target, x, y, z, orbSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, damage, knockback, knockbackUp, explosive, explosionRadius, explosionDamageFalloff, stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime); + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, lightningFadeTime); // Orb-specific properties this.speed = speed; diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityProjectile.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityProjectile.java index eed12d10b..32c5796bd 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityProjectile.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityProjectile.java @@ -30,7 +30,7 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA protected int innerColor = 0xFFFFFF; protected int outerColor = 0x8888FF; protected boolean outerColorEnabled = true; - protected float outerColorWidth = 1.8f; + protected float outerColorWidth = 0.4f; // Additive offset from inner size protected float rotationSpeed = 4.0f; // ==================== COMBAT PROPERTIES ==================== @@ -48,6 +48,16 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA protected float explosionRadius = 3.0f; protected float explosionDamageFalloff = 0.5f; + // ==================== LIGHTNING EFFECT PROPERTIES ==================== + protected boolean lightningEffect = false; + protected float lightningDensity = 0.15f; // Bolts spawned per tick (0.15 = ~15% chance per frame) + protected float lightningRadius = 0.5f; // Max distance lightning can arc from center + protected int lightningFadeTime = 6; // Ticks before lightning fades out + + // Client-side lightning state (not saved to NBT) + @cpw.mods.fml.relauncher.SideOnly(cpw.mods.fml.relauncher.Side.CLIENT) + public transient Object lightningState; // Actually AttachedLightningRenderer.LightningState + // ==================== LIFESPAN ==================== protected float maxDistance = 30.0f; protected int maxLifetime = 200; @@ -93,6 +103,27 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA boolean explosive, float explosionRadius, float explosionDamageFalloff, int stunDuration, int slowDuration, int slowLevel, float maxDistance, int maxLifetime) { + initProjectile(owner, target, x, y, z, + size, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, + maxDistance, maxLifetime, + false, 0.15f, 0.5f, 6); // Default: no lightning, low density, small radius, 6 tick fade + } + + /** + * Initialize common properties with lightning effect support. + */ + protected void initProjectile(EntityNPCInterface owner, EntityLivingBase target, + double x, double y, double z, + float size, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius, int lightningFadeTime) { this.setPosition(x, y, z); this.startX = x; this.startY = y; @@ -129,6 +160,12 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA this.maxLifetime = maxLifetime; // deathWorldTime will be set on first tick when world is available + // Lightning + this.lightningEffect = lightningEffect; + this.lightningDensity = lightningDensity; + this.lightningRadius = lightningRadius; + this.lightningFadeTime = lightningFadeTime; + // Initialize render size this.renderCurrentSize = size; this.prevRenderSize = size; @@ -417,6 +454,24 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA return this.prevRenderSize + (this.renderCurrentSize - this.prevRenderSize) * partialTicks; } + // ==================== LIGHTNING GETTERS ==================== + + public boolean hasLightningEffect() { + return lightningEffect; + } + + public float getLightningDensity() { + return lightningDensity; + } + + public float getLightningRadius() { + return lightningRadius; + } + + public int getLightningFadeTime() { + return lightningFadeTime; + } + // ==================== BRIGHTNESS ==================== @Override @@ -452,7 +507,7 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA this.innerColor = nbt.getInteger("InnerColor"); this.outerColor = nbt.getInteger("OuterColor"); this.outerColorEnabled = !nbt.hasKey("OuterColorEnabled") || nbt.getBoolean("OuterColorEnabled"); - this.outerColorWidth = nbt.hasKey("OuterColorWidth") ? nbt.getFloat("OuterColorWidth") : 1.8f; + this.outerColorWidth = nbt.hasKey("OuterColorWidth") ? nbt.getFloat("OuterColorWidth") : 0.4f; this.rotationSpeed = nbt.hasKey("RotationSpeed") ? nbt.getFloat("RotationSpeed") : 4.0f; this.damage = nbt.getFloat("Damage"); @@ -482,6 +537,12 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA this.motionY = nbt.getDouble("MotionY"); this.motionZ = nbt.getDouble("MotionZ"); + // Lightning + this.lightningEffect = nbt.getBoolean("LightningEffect"); + this.lightningDensity = nbt.hasKey("LightningDensity") ? nbt.getFloat("LightningDensity") : 0.15f; + this.lightningRadius = nbt.hasKey("LightningRadius") ? nbt.getFloat("LightningRadius") : 0.5f; + this.lightningFadeTime = nbt.hasKey("LightningFadeTime") ? nbt.getInteger("LightningFadeTime") : 6; + if (this.worldObj != null && this.worldObj.isRemote) { this.renderCurrentSize = this.size; this.prevRenderSize = this.size; @@ -525,6 +586,12 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA nbt.setDouble("MotionX", motionX); nbt.setDouble("MotionY", motionY); nbt.setDouble("MotionZ", motionZ); + + // Lightning + nbt.setBoolean("LightningEffect", lightningEffect); + nbt.setFloat("LightningDensity", lightningDensity); + nbt.setFloat("LightningRadius", lightningRadius); + nbt.setInteger("LightningFadeTime", lightningFadeTime); } /** diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 534963e38..9a0044191 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -144,11 +144,12 @@ import noppes.npcs.client.renderer.RenderNpcCrystal; import noppes.npcs.client.renderer.RenderNpcDragon; import noppes.npcs.client.renderer.RenderNpcSlime; import noppes.npcs.client.renderer.RenderProjectile; -import kamkeel.npcs.client.renderer.RenderAbilityOrbCube; +import kamkeel.npcs.client.renderer.RenderAbilityOrb; import kamkeel.npcs.client.renderer.RenderAbilityDisc; import kamkeel.npcs.client.renderer.RenderAbilityLaser; import kamkeel.npcs.client.renderer.RenderAbilityBeam; import kamkeel.npcs.client.renderer.RenderAbilitySweeper; +import kamkeel.npcs.client.renderer.lightning.LightningHandler; import kamkeel.npcs.entity.EntityAbilityOrb; import kamkeel.npcs.entity.EntityAbilityDisc; import kamkeel.npcs.entity.EntityAbilityLaser; @@ -261,8 +262,7 @@ public class ClientProxy extends CommonProxy { RenderingRegistry.registerEntityRenderingHandler(EntityNpcDragon.class, new RenderNpcDragon(new ModelNpcDragon(0.0F), 0.5F)); RenderingRegistry.registerEntityRenderingHandler(EntityNpcSlime.class, new RenderNpcSlime(new ModelNpcSlime(16), new ModelNpcSlime(0), 0.25F)); RenderingRegistry.registerEntityRenderingHandler(EntityProjectile.class, new RenderProjectile()); - // RenderingRegistry.registerEntityRenderingHandler(EntityAbilityOrb.class, new RenderAbilityOrb()); - RenderingRegistry.registerEntityRenderingHandler(EntityAbilityOrb.class, new RenderAbilityOrbCube()); + RenderingRegistry.registerEntityRenderingHandler(EntityAbilityOrb.class, new RenderAbilityOrb()); RenderingRegistry.registerEntityRenderingHandler(EntityAbilityDisc.class, new RenderAbilityDisc()); RenderingRegistry.registerEntityRenderingHandler(EntityAbilityLaser.class, new RenderAbilityLaser()); RenderingRegistry.registerEntityRenderingHandler(EntityAbilityBeam.class, new RenderAbilityBeam()); @@ -340,6 +340,9 @@ public class ClientProxy extends CommonProxy { TelegraphManager.initClient(); MinecraftForge.EVENT_BUS.register(new TelegraphRenderer()); + // Lightning effect rendering system + MinecraftForge.EVENT_BUS.register(new LightningHandler()); + if (ConfigClient.InventoryGuiEnabled) { MinecraftForge.EVENT_BUS.register(new TabRegistry()); if (TabRegistry.getTabList().isEmpty()) { diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 6142de16c..203cef3e2 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -5,6 +5,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import kamkeel.npcs.client.renderer.lightning.LightningBolt; import kamkeel.npcs.controllers.data.telegraph.TelegraphManager; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.player.CheckPlayerValue; @@ -115,6 +116,9 @@ public class ClientTickHandler { if (TelegraphManager.ClientInstance != null) { TelegraphManager.ClientInstance.tick(mc.theWorld); } + + // Update lightning bolts for ability effects + LightningBolt.updateAll(); if (Minecraft.getMinecraft().thePlayer != null && (prevWidth != mc.displayWidth || prevHeight != mc.displayHeight)) { prevWidth = mc.displayWidth; prevHeight = mc.displayHeight; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java index ec80ed5d6..373752fa6 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java @@ -126,6 +126,28 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { // Row 3: Rotation Speed addLabel(new GuiNpcLabel(204, "ability.rotationSpeed", labelX, y + 5)); addTextField(createFloatField(204, fieldX, y, 50, disc.getRotationSpeed())); + + y += 24; + + // Row 4: Lightning Effect Enabled + addLabel(new GuiNpcLabel(205, "ability.lightning", labelX, y + 5)); + addButton(new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.hasLightningEffect() ? 1 : 0)); + + // Only show Lightning settings if Lightning is enabled + if (disc.hasLightningEffect()) { + y += 24; + + // Row 5: Density + Radius + addLabel(new GuiNpcLabel(206, "ability.lightningDensity", labelX, y + 5)); + GuiNpcTextField densityField = new GuiNpcTextField(206, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(disc.getLightningDensity())); + densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f); + addTextField(densityField); + + addLabel(new GuiNpcLabel(207, "ability.lightningRadius", col2LabelX, y + 5)); + GuiNpcTextField radiusField = new GuiNpcTextField(207, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(disc.getLightningRadius())); + radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f); + addTextField(radiusField); + } } @Override @@ -160,6 +182,10 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { disc.setOuterColorEnabled(value == 1); initGui(); break; + case 205: + disc.setLightningEffect(value == 1); + initGui(); + break; } } @@ -222,6 +248,12 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { case 204: disc.setRotationSpeed(parseFloat(field, disc.getRotationSpeed())); break; + case 206: + disc.setLightningDensity(parseFloat(field, disc.getLightningDensity())); + break; + case 207: + disc.setLightningRadius(parseFloat(field, disc.getLightningRadius())); + break; } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java index afb89ffed..ad15bb576 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java @@ -127,6 +127,28 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { // Row 3: Rotation Speed addLabel(new GuiNpcLabel(204, "ability.rotationSpeed", labelX, y + 5)); addTextField(createFloatField(204, fieldX, y, 50, beam.getRotationSpeed())); + + y += 24; + + // Row 4: Lightning Effect Enabled (only affects head) + addLabel(new GuiNpcLabel(205, "ability.lightning", labelX, y + 5)); + addButton(new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, beam.hasLightningEffect() ? 1 : 0)); + + // Only show Lightning settings if Lightning is enabled + if (beam.hasLightningEffect()) { + y += 24; + + // Row 5: Density + Radius + addLabel(new GuiNpcLabel(206, "ability.lightningDensity", labelX, y + 5)); + GuiNpcTextField densityField = new GuiNpcTextField(206, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(beam.getLightningDensity())); + densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f); + addTextField(densityField); + + addLabel(new GuiNpcLabel(207, "ability.lightningRadius", col2LabelX, y + 5)); + GuiNpcTextField radiusField = new GuiNpcTextField(207, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(beam.getLightningRadius())); + radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f); + addTextField(radiusField); + } } @Override @@ -158,6 +180,10 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { beam.setOuterColorEnabled(value == 1); initGui(); break; + case 205: + beam.setLightningEffect(value == 1); + initGui(); + break; } } @@ -223,6 +249,12 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { case 204: beam.setRotationSpeed(parseFloat(field, beam.getRotationSpeed())); break; + case 206: + beam.setLightningDensity(parseFloat(field, beam.getLightningDensity())); + break; + case 207: + beam.setLightningRadius(parseFloat(field, beam.getLightningRadius())); + break; } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java index 47385f7cb..f83e93baf 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java @@ -111,6 +111,28 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { GuiNpcTextField widthField = createFloatField(203, col2FieldX, y, 55, laser.getOuterColorWidth()); widthField.setEnabled(laser.isOuterColorEnabled()); addTextField(widthField); + + y += 24; + + // Row 3: Lightning Effect Enabled + addLabel(new GuiNpcLabel(204, "ability.lightning", labelX, y + 5)); + addButton(new GuiNpcButton(204, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, laser.hasLightningEffect() ? 1 : 0)); + + // Only show Lightning settings if Lightning is enabled + if (laser.hasLightningEffect()) { + y += 24; + + // Row 4: Density + Radius + addLabel(new GuiNpcLabel(205, "ability.lightningDensity", labelX, y + 5)); + GuiNpcTextField densityField = new GuiNpcTextField(205, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(laser.getLightningDensity())); + densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f); + addTextField(densityField); + + addLabel(new GuiNpcLabel(206, "ability.lightningRadius", col2LabelX, y + 5)); + GuiNpcTextField radiusField = new GuiNpcTextField(206, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(laser.getLightningRadius())); + radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f); + addTextField(radiusField); + } } @Override @@ -139,6 +161,10 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { laser.setOuterColorEnabled(value == 1); initGui(); break; + case 204: + laser.setLightningEffect(value == 1); + initGui(); + break; } } @@ -165,6 +191,12 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { case 203: laser.setOuterColorWidth(parseFloat(field, laser.getOuterColorWidth())); break; + case 205: + laser.setLightningDensity(parseFloat(field, laser.getLightningDensity())); + break; + case 206: + laser.setLightningRadius(parseFloat(field, laser.getLightningRadius())); + break; } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java index 9f5ac4caf..42dd6a773 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java @@ -87,36 +87,58 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 180; int col2FieldX = guiLeft + 260; - // Row 1: Inner Color + Outer Color + // Row 1: Inner Color + Rotation Speed addLabel(new GuiNpcLabel(200, "ability.innerColor", labelX, y + 5)); String innerHex = String.format("%06X", orb.getInnerColor() & 0xFFFFFF); GuiNpcButton innerColorBtn = new GuiNpcButton(200, fieldX, y, 55, 20, innerHex); innerColorBtn.setTextColor(orb.getInnerColor() & 0xFFFFFF); addButton(innerColorBtn); - addLabel(new GuiNpcLabel(201, "ability.outerColor", col2LabelX, y + 5)); - String outerHex = String.format("%06X", orb.getOuterColor() & 0xFFFFFF); - GuiNpcButton outerColorBtn = new GuiNpcButton(201, col2FieldX, y, 55, 20, outerHex); - outerColorBtn.setTextColor(orb.getOuterColor() & 0xFFFFFF); - outerColorBtn.setEnabled(orb.isOuterColorEnabled()); - addButton(outerColorBtn); + addLabel(new GuiNpcLabel(204, "ability.rotationSpeed", col2LabelX, y + 5)); + addTextField(createFloatField(204, col2FieldX, y, 55, orb.getRotationSpeed())); y += 24; - // Row 2: Outer Color Enabled + Outer Color Width + // Row 2: Outer Glow Enabled addLabel(new GuiNpcLabel(202, "ability.outerEnabled", labelX, y + 5)); addButton(new GuiNpcButton(202, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.isOuterColorEnabled() ? 1 : 0)); - addLabel(new GuiNpcLabel(203, "ability.outerWidth", col2LabelX, y + 5)); - GuiNpcTextField widthField = createFloatField(203, col2FieldX, y, 55, orb.getOuterColorWidth()); - widthField.setEnabled(orb.isOuterColorEnabled()); - addTextField(widthField); + // Only show Outer Color and Width if Outer Glow is enabled + if (orb.isOuterColorEnabled()) { + y += 24; + + // Row 3: Outer Color + Outer Width + addLabel(new GuiNpcLabel(201, "ability.outerColor", labelX, y + 5)); + String outerHex = String.format("%06X", orb.getOuterColor() & 0xFFFFFF); + GuiNpcButton outerColorBtn = new GuiNpcButton(201, fieldX, y, 55, 20, outerHex); + outerColorBtn.setTextColor(orb.getOuterColor() & 0xFFFFFF); + addButton(outerColorBtn); + + addLabel(new GuiNpcLabel(203, "ability.outerWidth", col2LabelX, y + 5)); + addTextField(createFloatField(203, col2FieldX, y, 55, orb.getOuterColorWidth())); + } y += 24; - // Row 3: Rotation Speed - addLabel(new GuiNpcLabel(204, "ability.rotationSpeed", labelX, y + 5)); - addTextField(createFloatField(204, fieldX, y, 50, orb.getRotationSpeed())); + // Row 4: Lightning Effect Enabled + addLabel(new GuiNpcLabel(205, "ability.lightning", labelX, y + 5)); + addButton(new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.hasLightningEffect() ? 1 : 0)); + + // Only show Lightning settings if Lightning is enabled + if (orb.hasLightningEffect()) { + y += 24; + + // Row 5: Density + Radius + addLabel(new GuiNpcLabel(206, "ability.lightningDensity", labelX, y + 5)); + GuiNpcTextField densityField = new GuiNpcTextField(206, this, fontRendererObj, fieldX, y, 55, 18, String.valueOf(orb.getLightningDensity())); + densityField.setMinMaxDefaultFloat(0.01f, 5.0f, 0.15f); + addTextField(densityField); + + addLabel(new GuiNpcLabel(207, "ability.lightningRadius", col2LabelX, y + 5)); + GuiNpcTextField radiusField = new GuiNpcTextField(207, this, fontRendererObj, col2FieldX, y, 55, 18, String.valueOf(orb.getLightningRadius())); + radiusField.setMinMaxDefaultFloat(0.1f, 10.0f, 0.5f); + addTextField(radiusField); + } } @Override @@ -148,6 +170,10 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { orb.setOuterColorEnabled(value == 1); initGui(); break; + case 205: + orb.setLightningEffect(value == 1); + initGui(); + break; } } @@ -207,6 +233,12 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { case 204: orb.setRotationSpeed(parseFloat(field, orb.getRotationSpeed())); break; + case 206: + orb.setLightningDensity(parseFloat(field, orb.getLightningDensity())); + break; + case 207: + orb.setLightningRadius(parseFloat(field, orb.getLightningRadius())); + break; } } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index f3bba0c1d..b7e33a029 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1686,6 +1686,9 @@ ability.innerColor=Inner Color ability.outerColor=Outer Color ability.outerEnabled=Outer Glow ability.outerWidth=Outer Width +ability.lightning=Enable Lightning +ability.lightningDensity=Density +ability.lightningRadius=Radius ability.noVisualSettings=No visual settings for this ability type # Laser Shot Settings From d6d29613e8c1d2f6381b8833e3db042ecee6ad21 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 26 Jan 2026 19:03:48 -0500 Subject: [PATCH 02/15] Lock View Rotation --- .../client/renderer/RenderAbilityBeam.java | 6 +- .../renderer/quadric/QuadricRenderer.java | 138 ------------------ .../renderer/quadric/SphereRenderer.java | 37 ----- .../npcs/entity/EntityAbilityBeam.java | 12 +- src/main/java/noppes/npcs/DataAbilities.java | 83 ++++++++++- .../npcs/entity/EntityNPCInterface.java | 3 + 6 files changed, 90 insertions(+), 189 deletions(-) delete mode 100644 src/main/java/kamkeel/npcs/client/renderer/quadric/QuadricRenderer.java delete mode 100644 src/main/java/kamkeel/npcs/client/renderer/quadric/SphereRenderer.java diff --git a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java index 554b07e31..2fcb58d54 100644 --- a/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java +++ b/src/main/java/kamkeel/npcs/client/renderer/RenderAbilityBeam.java @@ -68,8 +68,12 @@ public class RenderAbilityBeam extends RenderAbilityProjectile { GL11.glPushMatrix(); GL11.glTranslated(renderOriginX, renderOriginY, renderOriginZ); + // Calculate head distance from origin (for overlap check) + double headDistFromOrigin = Math.sqrt(headOffsetX * headOffsetX + headOffsetY * headOffsetY + headOffsetZ * headOffsetZ); + // Render tail orb at origin (0,0,0) - only in anchored mode - if (beam.shouldRenderTailOrb()) { + // Don't render if head is too close to origin (would cause overlap/extra orb appearance) + if (beam.shouldRenderTailOrb() && headDistFromOrigin > headSize * 0.5) { renderTailOrb(headSize * 0.8f, innerColor, outerColor, beam.isOuterColorEnabled(), beam.getOuterColorWidth()); } diff --git a/src/main/java/kamkeel/npcs/client/renderer/quadric/QuadricRenderer.java b/src/main/java/kamkeel/npcs/client/renderer/quadric/QuadricRenderer.java deleted file mode 100644 index 13c994adc..000000000 --- a/src/main/java/kamkeel/npcs/client/renderer/quadric/QuadricRenderer.java +++ /dev/null @@ -1,138 +0,0 @@ -package kamkeel.npcs.client.renderer.quadric; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.renderer.GLAllocation; -import org.lwjgl.opengl.GL11; - -/** - * Base class for rendering GLU quadric shapes (spheres, cylinders, etc.) - * Uses display lists for efficient rendering. - * - * Design inspired by LouisXIV's quadric rendering system. - */ -@SideOnly(Side.CLIENT) -public abstract class QuadricRenderer { - protected int displayList; - private boolean compiled; - - public final float radius; - public final int slices; - public final int stacks; - - // Current render state - protected float scaleX = 1.0f; - protected float scaleY = 1.0f; - protected float scaleZ = 1.0f; - - protected float rotationX = 0.0f; - protected float rotationY = 0.0f; - protected float rotationZ = 0.0f; - - protected int color = 0xFFFFFF; - protected float alpha = 1.0f; - - public QuadricRenderer(float radius, int slices, int stacks) { - this.radius = radius; - this.slices = slices; - this.stacks = stacks; - } - - public QuadricRenderer(float radius, int resolution) { - this(radius, resolution, resolution); - } - - public QuadricRenderer() { - this(0.5f, 16); - } - - /** - * Render the quadric shape with current transform and color settings. - */ - public void render(float partialTicks) { - if (!compiled) { - displayList = GLAllocation.generateDisplayLists(1); - GL11.glNewList(displayList, GL11.GL_COMPILE); - compile(); - GL11.glEndList(); - compiled = true; - } - - GL11.glPushMatrix(); - - // Apply scale - GL11.glScalef(scaleX, scaleY, scaleZ); - - // Apply rotation - GL11.glRotatef(rotationX, 1.0f, 0.0f, 0.0f); - GL11.glRotatef(rotationY, 0.0f, 1.0f, 0.0f); - GL11.glRotatef(rotationZ, 0.0f, 0.0f, 1.0f); - - // Apply color - float r = ((color >> 16) & 0xFF) / 255.0f; - float g = ((color >> 8) & 0xFF) / 255.0f; - float b = (color & 0xFF) / 255.0f; - GL11.glColor4f(r, g, b, alpha); - - GL11.glCallList(displayList); - - GL11.glPopMatrix(); - } - - /** - * Compile the quadric geometry into the display list. - * Called once, then cached. - */ - protected abstract void compile(); - - // Setters for render state - public void setScale(float scale) { - this.scaleX = this.scaleY = this.scaleZ = scale; - } - - public void setScale(float x, float y, float z) { - this.scaleX = x; - this.scaleY = y; - this.scaleZ = z; - } - - public void setRotation(float x, float y, float z) { - this.rotationX = x; - this.rotationY = y; - this.rotationZ = z; - } - - public void setColor(int color) { - this.color = color; - } - - public void setAlpha(float alpha) { - this.alpha = alpha; - } - - /** - * Linear interpolation helper. - */ - public static float lerp(float current, float target, float factor) { - return current + (target - current) * factor; - } - - /** - * Color interpolation helper. - */ - public static int lerpColor(int from, int to, float factor) { - int r1 = (from >> 16) & 0xFF; - int g1 = (from >> 8) & 0xFF; - int b1 = from & 0xFF; - - int r2 = (to >> 16) & 0xFF; - int g2 = (to >> 8) & 0xFF; - int b2 = to & 0xFF; - - int r = (int) (r1 + (r2 - r1) * factor); - int g = (int) (g1 + (g2 - g1) * factor); - int b = (int) (b1 + (b2 - b1) * factor); - - return (r << 16) | (g << 8) | b; - } -} diff --git a/src/main/java/kamkeel/npcs/client/renderer/quadric/SphereRenderer.java b/src/main/java/kamkeel/npcs/client/renderer/quadric/SphereRenderer.java deleted file mode 100644 index dc72779a8..000000000 --- a/src/main/java/kamkeel/npcs/client/renderer/quadric/SphereRenderer.java +++ /dev/null @@ -1,37 +0,0 @@ -package kamkeel.npcs.client.renderer.quadric; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import org.lwjgl.util.glu.GLU; -import org.lwjgl.util.glu.Sphere; - -/** - * Renders a sphere using GLU quadrics. - * - * Design inspired by LouisXIV's quadric rendering system. - */ -@SideOnly(Side.CLIENT) -public class SphereRenderer extends QuadricRenderer { - - public SphereRenderer(float radius, int slices, int stacks) { - super(radius, slices, stacks); - } - - public SphereRenderer(float radius, int resolution) { - super(radius, resolution); - } - - public SphereRenderer() { - super(); - } - - @Override - protected void compile() { - Sphere sphere = new Sphere(); - sphere.setTextureFlag(true); // Enable texture coordinates - sphere.setDrawStyle(GLU.GLU_FILL); - sphere.setNormals(GLU.GLU_NONE); // No normals for self-illuminated rendering - sphere.setOrientation(GLU.GLU_OUTSIDE); - sphere.draw(radius, slices, stacks); - } -} diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java index ab62c4ca9..34030ab3f 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java @@ -360,18 +360,10 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { // Client: interpolate entity position handleClientInterpolation(); - // Client: update origin if attached to owner (mirrors server logic) - if (attachedToOwner) { - Entity owner = getOwner(); - if (owner != null) { - startX = owner.posX; - startY = owner.posY + owner.getEyeHeight() * 0.7; - startZ = owner.posZ; - } - } - // Client: derive head offset from entity position and origin // Entity position = head world position, so headOffset = pos - origin + // Note: During charging, updateCharging() handles origin positioning + // After firing, origin is fixed at the charged position headOffsetX = posX - startX; headOffsetY = posY - startY; headOffsetZ = posZ - startZ; diff --git a/src/main/java/noppes/npcs/DataAbilities.java b/src/main/java/noppes/npcs/DataAbilities.java index 8875508b1..246ebed46 100644 --- a/src/main/java/noppes/npcs/DataAbilities.java +++ b/src/main/java/noppes/npcs/DataAbilities.java @@ -78,6 +78,16 @@ public class DataAbilities { */ private transient List recentHitTimes = new ArrayList<>(); + /** + * Locked rotation values for ACTIVE phase with lockMovement. + * Stored when entering ACTIVE phase, applied every tick to prevent rotation changes. + */ + private transient boolean rotationLocked = false; + private transient float lockedYaw = 0; + private transient float lockedYawHead = 0; + private transient float lockedRenderYawOffset = 0; + private transient float lockedPitch = 0; + // ═══════════════════════════════════════════════════════════════════ // CONSTRUCTOR // ═══════════════════════════════════════════════════════════════════ @@ -136,6 +146,12 @@ public class DataAbilities { // Remove telegraph - it has served its purpose removeTelegraph(currentAbility); + // Lock rotation if lockMovement is true + // Capture current rotation values to force them every tick + if (currentAbility.isLockMovement()) { + captureLockedRotation(); + } + // Play active sound and animation playAbilitySound(currentAbility.getActiveSound()); playAbilityAnimation(currentAbility.getActiveAnimationId()); @@ -186,9 +202,9 @@ public class DataAbilities { } } - // Lock look direction at target during ACTIVE phase only - if (shouldLockLookDirection() && target != null && target.isEntityAlive()) { - npc.getLookHelper().setLookPositionWithEntity(target, 30.0F, 30.0F); + // Unlock rotation when leaving ACTIVE phase + if (rotationLocked && currentAbility.getPhase() != AbilityPhase.ACTIVE) { + releaseLockedRotation(); } } } @@ -202,6 +218,9 @@ public class DataAbilities { // Stop any ability animation stopAbilityAnimation(); + // Release rotation lock + releaseLockedRotation(); + // Calculate cooldown: random(min, max) + ability offset int baseCooldown = minCooldown; if (maxCooldown > minCooldown) { @@ -526,6 +545,9 @@ public class DataAbilities { // Stop any ability animation stopAbilityAnimation(); + // Release rotation lock + releaseLockedRotation(); + // Fire interrupt event AbilityEvent.InterruptEvent interruptEvent = new AbilityEvent.InterruptEvent( npc.wrappedNPC, currentAbility, lastTarget, source, damage); @@ -546,6 +568,7 @@ public class DataAbilities { if (currentAbility != null) { removeTelegraph(currentAbility); stopAbilityAnimation(); + releaseLockedRotation(); currentAbility.interrupt(); currentAbility = null; lastTarget = null; @@ -737,6 +760,60 @@ public class DataAbilities { return phase == AbilityPhase.WINDUP || phase == AbilityPhase.ACTIVE; } + // ═══════════════════════════════════════════════════════════════════ + // ROTATION LOCKING + // ═══════════════════════════════════════════════════════════════════ + + /** + * Capture current rotation values to lock NPC's look direction. + * Called when entering ACTIVE phase with lockMovement enabled. + */ + private void captureLockedRotation() { + lockedYaw = npc.rotationYaw; + lockedYawHead = npc.rotationYawHead; + lockedRenderYawOffset = npc.renderYawOffset; + lockedPitch = npc.rotationPitch; + rotationLocked = true; + } + + /** + * Release the rotation lock. + * Called when leaving ACTIVE phase or ability completes. + */ + private void releaseLockedRotation() { + rotationLocked = false; + } + + /** + * Apply locked rotation values to the NPC. + * Called AFTER super.onLivingUpdate() in EntityNPCInterface to override + * any rotation changes made by the look helper or AI tasks. + */ + public void applyLockedRotation() { + 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. + */ + public boolean isRotationLocked() { + return rotationLocked; + } + // ═══════════════════════════════════════════════════════════════════ // NBT SERIALIZATION // ═══════════════════════════════════════════════════════════════════ diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 20d2f6d5c..ae292d59d 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -481,6 +481,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti super.onLivingUpdate(); + // Apply locked rotation after super.onLivingUpdate() to override look helper changes + abilities.applyLockedRotation(); + handleMountRiderState(); if (worldObj.isRemote) { From 563b6f7a26ab73bf73b6af9ef2faf0883040c76c Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 26 Jan 2026 22:02:51 -0500 Subject: [PATCH 03/15] Ability Effects --- .../controllers/data/ability/Ability.java | 63 +++++- .../data/ability/AbilityEffect.java | 146 +++++++++++++ .../data/ability/type/AbilityCutter.java | 45 +--- .../data/ability/type/AbilityHeavyHit.java | 46 +--- .../data/ability/type/AbilityShockwave.java | 20 +- .../data/ability/type/AbilityTeleport.java | 17 +- .../data/ability/type/AbilityTrap.java | 87 +------- .../data/ability/type/AbilityVortex.java | 54 ++--- .../advanced/ability/SubGuiAbilityCharge.java | 27 ++- .../advanced/ability/SubGuiAbilityCutter.java | 42 ++-- .../advanced/ability/SubGuiAbilityDisc.java | 17 ++ .../ability/SubGuiAbilityEffects.java | 197 ++++++++++++++++++ .../ability/SubGuiAbilityEnergyBeam.java | 17 ++ .../advanced/ability/SubGuiAbilityGuard.java | 26 +++ .../advanced/ability/SubGuiAbilityHazard.java | 24 +++ .../ability/SubGuiAbilityHeavyHit.java | 50 +++-- .../ability/SubGuiAbilityLaserShot.java | 17 ++ .../advanced/ability/SubGuiAbilityOrb.java | 17 ++ .../ability/SubGuiAbilityProjectile.java | 24 +++ .../ability/SubGuiAbilityShockwave.java | 36 +++- .../advanced/ability/SubGuiAbilitySlam.java | 28 ++- .../ability/SubGuiAbilitySweeper.java | 17 ++ .../ability/SubGuiAbilityTeleport.java | 24 +++ .../advanced/ability/SubGuiAbilityTrap.java | 37 ++-- .../advanced/ability/SubGuiAbilityVortex.java | 33 +-- .../assets/customnpcs/lang/en_US.lang | 12 +- 26 files changed, 799 insertions(+), 324 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/controllers/data/ability/AbilityEffect.java create mode 100644 src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEffects.java diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java index 3f2165718..d7a8b9eab 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -78,6 +78,9 @@ public abstract class Ability implements IAbility { // Custom data for external mods protected NBTTagCompound customData = new NBTTagCompound(); + // Configurable potion effects + protected List effects = new ArrayList<>(); + // ═══════════════════════════════════════════════════════════════════ // EXECUTION STATE (not saved, reset each combat) // ═══════════════════════════════════════════════════════════════════ @@ -224,6 +227,21 @@ public abstract class Ability implements IAbility { hitEntity.velocityChanged = true; } + /** + * Applies all configured effects to the given entity. + * Call this after damage is applied to the target. + * + * @param entity The entity to apply effects to + */ + protected void applyEffects(EntityLivingBase entity) { + if (entity == null || effects.isEmpty()) { + return; + } + for (AbilityEffect effect : effects) { + effect.apply(entity); + } + } + public float getTelegraphRadius() { return 5.0f; } @@ -662,6 +680,13 @@ public abstract class Ability implements IAbility { for (Condition c : conditions) condList.appendTag(c.writeNBT()); nbt.setTag("conditions", condList); + // Effects + NBTTagList effectList = new NBTTagList(); + for (AbilityEffect effect : effects) { + effectList.appendTag(effect.writeNBT()); + } + nbt.setTag("effects", effectList); + // Type-specific NBTTagCompound typeNBT = new NBTTagCompound(); writeTypeNBT(typeNBT); @@ -735,6 +760,18 @@ public abstract class Ability implements IAbility { if (c != null) conditions.add(c); } + // Effects + effects.clear(); + if (nbt.hasKey("effects")) { + NBTTagList effectList = nbt.getTagList("effects", 10); + for (int i = 0; i < effectList.tagCount(); i++) { + AbilityEffect effect = AbilityEffect.fromNBT(effectList.getCompoundTagAt(i)); + if (effect != null && effect.isValid()) { + effects.add(effect); + } + } + } + readTypeNBT(nbt.getCompoundTag("typeData")); } @@ -807,7 +844,7 @@ public abstract class Ability implements IAbility { } public void setCooldownTicks(int cooldownTicks) { - this.cooldownTicks = cooldownTicks; + this.cooldownTicks = Math.max(0, cooldownTicks); } public int getWindUpTicks() { @@ -815,7 +852,7 @@ public abstract class Ability implements IAbility { } public void setWindUpTicks(int windUpTicks) { - this.windUpTicks = windUpTicks; + this.windUpTicks = Math.max(0, windUpTicks); } public int getActiveTicks() { @@ -823,7 +860,7 @@ public abstract class Ability implements IAbility { } public void setActiveTicks(int activeTicks) { - this.activeTicks = activeTicks; + this.activeTicks = Math.max(1, activeTicks); } public int getRecoveryTicks() { @@ -831,7 +868,7 @@ public abstract class Ability implements IAbility { } public void setRecoveryTicks(int recoveryTicks) { - this.recoveryTicks = recoveryTicks; + this.recoveryTicks = Math.max(0, recoveryTicks); } public boolean isInterruptible() { @@ -963,6 +1000,24 @@ public abstract class Ability implements IAbility { conditions.add(c); } + public List getEffects() { + return effects; + } + + public void setEffects(List effects) { + this.effects = effects != null ? effects : new ArrayList<>(); + } + + public void addEffect(AbilityEffect effect) { + if (effect != null && effect.isValid()) { + effects.add(effect); + } + } + + public void clearEffects() { + effects.clear(); + } + // ═══════════════════════════════════════════════════════════════════ // IAbility API METHODS // ═══════════════════════════════════════════════════════════════════ diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityEffect.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityEffect.java new file mode 100644 index 000000000..47e03f10d --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityEffect.java @@ -0,0 +1,146 @@ +package kamkeel.npcs.controllers.data.ability; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; + +/** + * Represents a configurable potion effect that can be applied by abilities. + * Provides a unified system for managing debuffs like slowness, weakness, poison, etc. + */ +public class AbilityEffect { + + public enum EffectType { + NONE("gui.none", -1), + SLOWNESS("potion.moveSlowdown", Potion.moveSlowdown.id), + WEAKNESS("potion.weakness", Potion.weakness.id), + POISON("potion.poison", Potion.poison.id), + WITHER("potion.wither", Potion.wither.id), + 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); + + private final String langKey; + private final int potionId; + + EffectType(String langKey, int potionId) { + this.langKey = langKey; + this.potionId = potionId; + } + + public String getLangKey() { + return langKey; + } + + public int getPotionId() { + return potionId; + } + + public static EffectType fromOrdinal(int ordinal) { + EffectType[] values = values(); + if (ordinal >= 0 && ordinal < values.length) { + return values[ordinal]; + } + return NONE; + } + } + + private EffectType type = EffectType.NONE; + private int durationTicks = 60; + private int amplifier = 0; // 0-10 + + public AbilityEffect() { + } + + public AbilityEffect(EffectType type, int durationTicks, int amplifier) { + this.type = type; + this.durationTicks = Math.max(1, durationTicks); + this.amplifier = Math.max(0, Math.min(10, amplifier)); + } + + /** + * Creates a copy of this effect. + */ + public AbilityEffect copy() { + return new AbilityEffect(type, durationTicks, amplifier); + } + + /** + * Applies this effect to the given entity. + * Does nothing if type is NONE. + */ + public void apply(EntityLivingBase entity) { + if (entity == null || type == EffectType.NONE) { + return; + } + + int potionId = type.getPotionId(); + if (potionId >= 0) { + entity.addPotionEffect(new PotionEffect(potionId, durationTicks, amplifier)); + } + } + + /** + * Writes this effect to NBT. + */ + public NBTTagCompound writeNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("type", type.ordinal()); + nbt.setInteger("duration", durationTicks); + nbt.setInteger("amplifier", amplifier); + return nbt; + } + + /** + * Reads this effect from NBT. + */ + public void readNBT(NBTTagCompound nbt) { + this.type = EffectType.fromOrdinal(nbt.getInteger("type")); + this.durationTicks = nbt.hasKey("duration") ? nbt.getInteger("duration") : 60; + this.amplifier = nbt.hasKey("amplifier") ? nbt.getInteger("amplifier") : 0; + } + + /** + * Creates an AbilityEffect from NBT. + */ + public static AbilityEffect fromNBT(NBTTagCompound nbt) { + AbilityEffect effect = new AbilityEffect(); + effect.readNBT(nbt); + return effect; + } + + // Getters & Setters + + public EffectType getType() { + return type; + } + + public void setType(EffectType type) { + this.type = type != null ? type : EffectType.NONE; + } + + public int getDurationTicks() { + return durationTicks; + } + + public void setDurationTicks(int durationTicks) { + this.durationTicks = Math.max(1, durationTicks); + } + + public int getAmplifier() { + return amplifier; + } + + public void setAmplifier(int amplifier) { + this.amplifier = Math.max(0, Math.min(10, amplifier)); + } + + /** + * Returns true if this effect is configured (not NONE). + */ + public boolean isValid() { + return type != EffectType.NONE; + } +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java index 611d0a4a6..8274b4d79 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java @@ -7,8 +7,6 @@ import kamkeel.npcs.controllers.data.ability.TargetingMode; import kamkeel.npcs.controllers.data.telegraph.TelegraphType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; import net.minecraft.world.World; @@ -41,9 +39,6 @@ public class AbilityCutter extends Ability { private SweepMode sweepMode = SweepMode.SWIPE; private float sweepSpeed = 6.0f; - private int stunDuration = 0; - private int poisonDurationSeconds = 0; - private int poisonLevel = 0; private boolean piercing = true; private float innerRadius = 0.0f; @@ -161,15 +156,9 @@ public class AbilityCutter extends Ability { // Apply damage with scripted event support boolean wasHit = applyAbilityDamage(npc, entity, actualDamage, knockback); - // Only apply effects if hit wasn't cancelled + // Apply effects if hit wasn't cancelled if (wasHit) { - if (stunDuration > 0) { - entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, stunDuration, 10)); - entity.addPotionEffect(new PotionEffect(Potion.weakness.id, stunDuration, 2)); - } - if (poisonDurationSeconds > 0) { - entity.addPotionEffect(new PotionEffect(Potion.poison.id, poisonDurationSeconds * 20, poisonLevel)); - } + applyEffects(entity); } } } @@ -206,9 +195,6 @@ public class AbilityCutter extends Ability { nbt.setFloat("knockback", knockback); nbt.setString("sweepMode", sweepMode.name()); nbt.setFloat("sweepSpeed", sweepSpeed); - nbt.setInteger("stunDuration", stunDuration); - nbt.setInteger("poisonDurationSeconds", poisonDurationSeconds); - nbt.setInteger("poisonLevel", poisonLevel); nbt.setBoolean("piercing", piercing); nbt.setFloat("innerRadius", innerRadius); } @@ -225,9 +211,6 @@ public class AbilityCutter extends Ability { this.sweepMode = SweepMode.SWIPE; } this.sweepSpeed = nbt.hasKey("sweepSpeed") ? nbt.getFloat("sweepSpeed") : 6.0f; - this.stunDuration = nbt.hasKey("stunDuration") ? nbt.getInteger("stunDuration") : 0; - this.poisonDurationSeconds = nbt.hasKey("poisonDurationSeconds") ? nbt.getInteger("poisonDurationSeconds") : 0; - this.poisonLevel = nbt.hasKey("poisonLevel") ? nbt.getInteger("poisonLevel") : 0; this.piercing = !nbt.hasKey("piercing") || nbt.getBoolean("piercing"); this.innerRadius = nbt.hasKey("innerRadius") ? nbt.getFloat("innerRadius") : 0.0f; } @@ -281,30 +264,6 @@ public class AbilityCutter extends Ability { this.sweepSpeed = sweepSpeed; } - public int getStunDuration() { - return stunDuration; - } - - public void setStunDuration(int stunDuration) { - this.stunDuration = stunDuration; - } - - public int getPoisonDurationSeconds() { - return poisonDurationSeconds; - } - - public void setPoisonDurationSeconds(int poisonDurationSeconds) { - this.poisonDurationSeconds = poisonDurationSeconds; - } - - public int getPoisonLevel() { - return poisonLevel; - } - - public void setPoisonLevel(int poisonLevel) { - this.poisonLevel = poisonLevel; - } - public boolean isPiercing() { return piercing; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java index abdcc6f86..fc68200b7 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java @@ -7,8 +7,6 @@ import kamkeel.npcs.controllers.data.ability.TargetingMode; import kamkeel.npcs.controllers.data.telegraph.TelegraphType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.advanced.ability.SubGuiAbilityHeavyHit; @@ -23,9 +21,6 @@ public class AbilityHeavyHit extends Ability { private float damage = 8.0f; private float knockback = 2.0f; - private int slownessLevel = 1; - private int weaknessLevel = 0; - private int potionDurationSeconds = 2; public AbilityHeavyHit() { this.typeId = "ability.cnpc.heavy_hit"; @@ -73,14 +68,9 @@ public class AbilityHeavyHit extends Ability { // Apply damage with scripted event support boolean wasHit = applyAbilityDamage(npc, target, damage, knockback); - if (wasHit && potionDurationSeconds > 0) { - int durationTicks = potionDurationSeconds * 20; - if (slownessLevel >= 0) { - target.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, durationTicks, slownessLevel)); - } - if (weaknessLevel >= 0) { - target.addPotionEffect(new PotionEffect(Potion.weakness.id, durationTicks, weaknessLevel)); - } + // Apply effects if hit wasn't cancelled + if (wasHit) { + applyEffects(target); } } @@ -93,18 +83,12 @@ public class AbilityHeavyHit extends Ability { public void writeTypeNBT(NBTTagCompound nbt) { nbt.setFloat("damage", damage); nbt.setFloat("knockback", knockback); - nbt.setInteger("slownessLevel", slownessLevel); - nbt.setInteger("weaknessLevel", weaknessLevel); - nbt.setInteger("potionDurationSeconds", potionDurationSeconds); } @Override public void readTypeNBT(NBTTagCompound nbt) { this.damage = nbt.hasKey("damage") ? nbt.getFloat("damage") : 8.0f; this.knockback = nbt.hasKey("knockback") ? nbt.getFloat("knockback") : 2.0f; - this.slownessLevel = nbt.hasKey("slownessLevel") ? nbt.getInteger("slownessLevel") : 1; - this.weaknessLevel = nbt.hasKey("weaknessLevel") ? nbt.getInteger("weaknessLevel") : 0; - this.potionDurationSeconds = nbt.hasKey("potionDurationSeconds") ? nbt.getInteger("potionDurationSeconds") : 2; } // Getters & Setters @@ -123,28 +107,4 @@ public class AbilityHeavyHit extends Ability { public void setKnockback(float knockback) { this.knockback = knockback; } - - public int getSlownessLevel() { - return slownessLevel; - } - - public void setSlownessLevel(int slownessLevel) { - this.slownessLevel = slownessLevel; - } - - public int getWeaknessLevel() { - return weaknessLevel; - } - - public void setWeaknessLevel(int weaknessLevel) { - this.weaknessLevel = weaknessLevel; - } - - public int getPotionDurationSeconds() { - return potionDurationSeconds; - } - - public void setPotionDurationSeconds(int potionDurationSeconds) { - this.potionDurationSeconds = potionDurationSeconds; - } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java index 1708b49bd..b5a35831f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java @@ -7,8 +7,6 @@ import kamkeel.npcs.controllers.data.ability.TargetingMode; import kamkeel.npcs.controllers.data.telegraph.TelegraphType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; import net.minecraft.world.World; @@ -28,7 +26,6 @@ public class AbilityShockwave extends Ability { private float pushRadius = 8.0f; private float pushStrength = 1.5f; private float damage = 8.0f; - private int stunDuration = 0; private int maxTargets = 10; // Runtime state @@ -122,10 +119,9 @@ public class AbilityShockwave extends Ability { // Apply damage with custom knockback direction boolean wasHit = applyAbilityDamageWithDirection(npc, entity, damage * distFactor, finalPush, dx, dz); - // Apply stun if hit connected - if (wasHit && stunDuration > 0) { - entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, stunDuration, 10)); - entity.addPotionEffect(new PotionEffect(Potion.weakness.id, stunDuration, 2)); + // Apply effects if hit connected + if (wasHit) { + applyEffects(entity); } } } @@ -145,7 +141,6 @@ public class AbilityShockwave extends Ability { nbt.setFloat("pushRadius", pushRadius); nbt.setFloat("pushStrength", pushStrength); nbt.setFloat("damage", damage); - nbt.setInteger("stunDuration", stunDuration); nbt.setInteger("maxTargets", maxTargets); } @@ -154,7 +149,6 @@ public class AbilityShockwave extends Ability { this.pushRadius = nbt.hasKey("pushRadius") ? nbt.getFloat("pushRadius") : 8.0f; this.pushStrength = nbt.hasKey("pushStrength") ? nbt.getFloat("pushStrength") : 1.5f; this.damage = nbt.hasKey("damage") ? nbt.getFloat("damage") : 8.0f; - this.stunDuration = nbt.hasKey("stunDuration") ? nbt.getInteger("stunDuration") : 0; this.maxTargets = nbt.hasKey("maxTargets") ? nbt.getInteger("maxTargets") : 10; } @@ -183,14 +177,6 @@ public class AbilityShockwave extends Ability { this.damage = damage; } - public int getStunDuration() { - return stunDuration; - } - - public void setStunDuration(int stunDuration) { - this.stunDuration = stunDuration; - } - public int getMaxTargets() { return maxTargets; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java index ad5989f25..a79223d5d 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java @@ -261,8 +261,13 @@ public class AbilityTeleport extends Ability { int blockY = MathHelper.floor_double(checkY); int blockZ = MathHelper.floor_double(checkZ); + // Skip out-of-world coordinates + if (blockY < 0 || blockY >= 256) { + continue; + } + Block block = world.getBlock(blockX, blockY, blockZ); - if (block.getMaterial().isSolid() && block.isOpaqueCube()) { + if (block != null && block.getMaterial().isSolid() && block.isOpaqueCube()) { return false; } } @@ -327,10 +332,20 @@ public class AbilityTeleport extends Ability { } private boolean isSafeLocation(World world, int x, int y, int z) { + // Bounds check - ensure we're within valid world coordinates + if (y < 1 || y >= 255) { + return false; + } + Block groundBlock = world.getBlock(x, y - 1, z); Block feetBlock = world.getBlock(x, y, z); Block headBlock = world.getBlock(x, y + 1, z); + // Defensive null checks (shouldn't happen in MC 1.7.10, but safe) + if (groundBlock == null || feetBlock == null || headBlock == null) { + return false; + } + return groundBlock.getMaterial().isSolid() && !feetBlock.getMaterial().isSolid() && !headBlock.getMaterial().isSolid(); diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java index fa2fefb4c..77ac4a5fe 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java @@ -8,8 +8,6 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance; import kamkeel.npcs.controllers.data.telegraph.TelegraphType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; import net.minecraft.world.World; @@ -45,12 +43,6 @@ public class AbilityTrap extends Ability { private float damage = 6.0f; private float damageRadius = 0.0f; private float knockback = 0.5f; - private int stunDuration = 0; - private int rootDuration = 40; - private int slowDuration = 0; - private int slowLevel = 1; - private int poisonDuration = 0; - private int poisonLevel = 0; private boolean visible = true; // Offset parameters - trap spawns near target, not exactly on them @@ -262,24 +254,9 @@ public class AbilityTrap extends Ability { // Apply damage with scripted event support boolean wasHit = applyAbilityDamage(npc, entity, damage, knockback); - // Only apply effects if the hit wasn't cancelled + // Apply effects if the hit wasn't cancelled if (wasHit) { - if (stunDuration > 0) { - entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, stunDuration, 10)); - entity.addPotionEffect(new PotionEffect(Potion.weakness.id, stunDuration, 2)); - } - - if (rootDuration > 0) { - entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, rootDuration, 127)); - } - - if (slowDuration > 0) { - entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, slowDuration, slowLevel)); - } - - if (poisonDuration > 0 && poisonLevel >= 0) { - entity.addPotionEffect(new PotionEffect(Potion.poison.id, poisonDuration, poisonLevel)); - } + applyEffects(entity); } } } @@ -309,12 +286,6 @@ public class AbilityTrap extends Ability { nbt.setFloat("damage", damage); nbt.setFloat("damageRadius", damageRadius); nbt.setFloat("knockback", knockback); - nbt.setInteger("stunDuration", stunDuration); - nbt.setInteger("rootDuration", rootDuration); - nbt.setInteger("slowDuration", slowDuration); - nbt.setInteger("slowLevel", slowLevel); - nbt.setInteger("poisonDuration", poisonDuration); - nbt.setInteger("poisonLevel", poisonLevel); nbt.setBoolean("visible", visible); nbt.setFloat("minOffset", minOffset); nbt.setFloat("maxOffset", maxOffset); @@ -336,12 +307,6 @@ public class AbilityTrap extends Ability { this.damage = nbt.hasKey("damage") ? nbt.getFloat("damage") : 6.0f; this.damageRadius = nbt.hasKey("damageRadius") ? nbt.getFloat("damageRadius") : 0.0f; this.knockback = nbt.hasKey("knockback") ? nbt.getFloat("knockback") : 0.5f; - this.stunDuration = nbt.hasKey("stunDuration") ? nbt.getInteger("stunDuration") : 0; - this.rootDuration = nbt.hasKey("rootDuration") ? nbt.getInteger("rootDuration") : 40; - this.slowDuration = nbt.hasKey("slowDuration") ? nbt.getInteger("slowDuration") : 0; - this.slowLevel = nbt.hasKey("slowLevel") ? nbt.getInteger("slowLevel") : 1; - this.poisonDuration = nbt.hasKey("poisonDuration") ? nbt.getInteger("poisonDuration") : 0; - this.poisonLevel = nbt.hasKey("poisonLevel") ? nbt.getInteger("poisonLevel") : 0; this.visible = !nbt.hasKey("visible") || nbt.getBoolean("visible"); this.minOffset = nbt.hasKey("minOffset") ? nbt.getFloat("minOffset") : 0.0f; this.maxOffset = nbt.hasKey("maxOffset") ? nbt.getFloat("maxOffset") : 1.5f; @@ -421,54 +386,6 @@ public class AbilityTrap extends Ability { this.knockback = knockback; } - public int getStunDuration() { - return stunDuration; - } - - public void setStunDuration(int stunDuration) { - this.stunDuration = stunDuration; - } - - public int getRootDuration() { - return rootDuration; - } - - public void setRootDuration(int rootDuration) { - this.rootDuration = rootDuration; - } - - public int getSlowDuration() { - return slowDuration; - } - - public void setSlowDuration(int slowDuration) { - this.slowDuration = slowDuration; - } - - public int getSlowLevel() { - return slowLevel; - } - - public void setSlowLevel(int slowLevel) { - this.slowLevel = slowLevel; - } - - public int getPoisonDuration() { - return poisonDuration; - } - - public void setPoisonDuration(int poisonDuration) { - this.poisonDuration = poisonDuration; - } - - public int getPoisonLevel() { - return poisonLevel; - } - - public void setPoisonLevel(int poisonLevel) { - this.poisonLevel = poisonLevel; - } - public boolean isVisible() { return visible; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java index f0e08dd56..666b19bbc 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java @@ -7,8 +7,6 @@ import kamkeel.npcs.controllers.data.ability.TargetingMode; import kamkeel.npcs.controllers.data.telegraph.TelegraphType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; import net.minecraft.world.World; @@ -32,8 +30,6 @@ public class AbilityVortex extends Ability { private float pullStrength = 0.8f; private float damage = 0.0f; private float knockback = 0.0f; - private int stunDuration = 0; - private int rootDuration = 0; private boolean aoe = false; private int maxTargets = 5; private boolean damageOnPull = false; @@ -134,7 +130,7 @@ public class AbilityVortex extends Ability { ticksSincePullDamage++; for (UUID uuid : new HashSet<>(pulledEntities)) { - EntityLivingBase entity = findEntity(world, uuid); + EntityLivingBase entity = findEntity(npc, world, uuid); if (entity == null || entity.isDead) { pulledEntities.remove(uuid); continue; @@ -187,25 +183,23 @@ public class AbilityVortex extends Ability { // Only apply effects if hit wasn't cancelled if (wasHit) { - if (stunDuration > 0) { - entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, stunDuration, 10)); - entity.addPotionEffect(new PotionEffect(Potion.weakness.id, stunDuration, 2)); - } - - if (rootDuration > 0) { - entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, rootDuration, 127)); - } + applyEffects(entity); } } + /** + * Find an entity by UUID within the vortex pull area. + * Uses AABB search instead of iterating all loaded entities. + */ @SuppressWarnings("unchecked") - private EntityLivingBase findEntity(World world, UUID uuid) { - for (Object obj : world.loadedEntityList) { - if (obj instanceof EntityLivingBase) { - EntityLivingBase entity = (EntityLivingBase) obj; - if (entity.getUniqueID().equals(uuid)) { - return entity; - } + private EntityLivingBase findEntity(EntityNPCInterface npc, World world, UUID uuid) { + // Search within pull radius (entities being pulled should be within this area) + AxisAlignedBB searchBox = npc.boundingBox.expand(pullRadius, pullRadius / 2, pullRadius); + List nearbyEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, searchBox); + + for (EntityLivingBase entity : nearbyEntities) { + if (entity.getUniqueID().equals(uuid)) { + return entity; } } return null; @@ -231,8 +225,6 @@ public class AbilityVortex extends Ability { nbt.setFloat("pullStrength", pullStrength); nbt.setFloat("damage", damage); nbt.setFloat("knockback", knockback); - nbt.setInteger("stunDuration", stunDuration); - nbt.setInteger("rootDuration", rootDuration); nbt.setBoolean("aoe", aoe); nbt.setInteger("maxTargets", maxTargets); nbt.setBoolean("damageOnPull", damageOnPull); @@ -245,8 +237,6 @@ public class AbilityVortex extends Ability { this.pullStrength = nbt.hasKey("pullStrength") ? nbt.getFloat("pullStrength") : 0.8f; this.damage = nbt.hasKey("damage") ? nbt.getFloat("damage") : 0.0f; this.knockback = nbt.hasKey("knockback") ? nbt.getFloat("knockback") : 0.0f; - this.stunDuration = nbt.hasKey("stunDuration") ? nbt.getInteger("stunDuration") : 0; - this.rootDuration = nbt.hasKey("rootDuration") ? nbt.getInteger("rootDuration") : 0; this.aoe = nbt.hasKey("aoe") && nbt.getBoolean("aoe"); this.maxTargets = nbt.hasKey("maxTargets") ? nbt.getInteger("maxTargets") : 5; this.damageOnPull = nbt.hasKey("damageOnPull") && nbt.getBoolean("damageOnPull"); @@ -286,22 +276,6 @@ public class AbilityVortex extends Ability { this.knockback = knockback; } - public int getStunDuration() { - return stunDuration; - } - - public void setStunDuration(int stunDuration) { - this.stunDuration = stunDuration; - } - - public int getRootDuration() { - return rootDuration; - } - - public void setRootDuration(int rootDuration) { - this.rootDuration = rootDuration; - } - public boolean isAoe() { return aoe; } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCharge.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCharge.java index 4d7486c5e..ea35797c4 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCharge.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCharge.java @@ -1,10 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityCharge; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; +import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Charge ability type-specific settings. @@ -41,10 +46,30 @@ public class SubGuiAbilityCharge extends SubGuiAbilityConfig { y += 24; - // Row 3: Hit Width + // Row 3: Hit Width + Effects addLabel(new GuiNpcLabel(104, "ability.hitWidth", labelX, y + 5)); addTextField(createFloatField(104, fieldX, y, 50, charge.getHitWidth())); + addButton(new GuiNpcButton(150, col2LabelX, y, 80, 20, "ability.effects")); + } + + @Override + protected void handleTypeButton(int id, GuiNpcButton button) { + if (id == 150) { + setSubGui(new SubGuiAbilityEffects(charge.getEffects())); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + charge.setEffects(result); + } + } } @Override diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java index 514391f8a..10f5ab8c1 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java @@ -1,11 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityCutter; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Cutter ability type-specific settings. @@ -64,18 +68,8 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig { y += 24; - // Row 5: Stun Duration + Poison Time - addLabel(new GuiNpcLabel(108, "ability.stunDuration", labelX, y + 5)); - addTextField(createIntField(108, fieldX, y, 50, cutter.getStunDuration())); - - addLabel(new GuiNpcLabel(109, "ability.poisonTime", col2LabelX, y + 5)); - addTextField(createIntField(109, col2FieldX, y, 50, cutter.getPoisonDurationSeconds())); - - y += 24; - - // Row 6: Poison Level - addLabel(new GuiNpcLabel(110, "ability.poisonLvl", labelX, y + 5)); - addTextField(createIntField(110, fieldX, y, 50, cutter.getPoisonLevel())); + // Row 5: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -88,6 +82,21 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig { case 107: cutter.setPiercing(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(cutter.getEffects())); + break; + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + cutter.setEffects(result); + } } } @@ -112,15 +121,6 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig { case 105: cutter.setSweepSpeed(parseFloat(field, cutter.getSweepSpeed())); break; - case 108: - cutter.setStunDuration(field.getInteger()); - break; - case 109: - cutter.setPoisonDurationSeconds(field.getInteger()); - break; - case 110: - cutter.setPoisonLevel(field.getInteger()); - break; } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java index 373752fa6..2a3439af1 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityDisc; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -9,6 +10,8 @@ import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; import noppes.npcs.client.gui.util.SubGuiInterface; +import java.util.List; + /** * GUI for configuring Disc ability type-specific settings. */ @@ -86,6 +89,11 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(111, "ability.maxDist", col2LabelX, y + 5)); addTextField(createFloatField(111, col2FieldX, y, 50, disc.getMaxDistance())); + + y += 24; + + // Row 7: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -163,6 +171,9 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { case 108: disc.setExplosive(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(disc.getEffects())); + break; } } @@ -201,6 +212,12 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { } editingVisualColorId = 0; initGui(); + } else if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + disc.setEffects(result); + } } else { super.subGuiClosed(subgui); } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEffects.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEffects.java new file mode 100644 index 000000000..103d87224 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEffects.java @@ -0,0 +1,197 @@ +package noppes.npcs.client.gui.advanced.ability; + +import kamkeel.npcs.controllers.data.ability.AbilityEffect; +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.gui.util.GuiNpcButton; +import noppes.npcs.client.gui.util.GuiNpcLabel; +import noppes.npcs.client.gui.util.GuiNpcTextField; +import noppes.npcs.client.gui.util.ITextfieldListener; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.ArrayList; +import java.util.List; + +/** + * SubGui for editing ability effects (potion effects that apply to targets). + * Allows adding/removing effects and configuring type, duration, and amplifier. + */ +public class SubGuiAbilityEffects extends SubGuiInterface implements ITextfieldListener { + + private static final int MAX_EFFECTS = 5; + + // Effect type names for display + private static final String[] EFFECT_TYPE_NAMES = { + "gui.none", + "potion.moveSlowdown", + "potion.weakness", + "potion.poison", + "potion.wither", + "potion.blindness", + "potion.confusion", + "potion.hunger", + "potion.digSlowDown" + }; + + // Working copy of effects + private List effects; + private boolean cancelled = false; + + public SubGuiAbilityEffects(List existingEffects) { + // Create working copies of effects + this.effects = new ArrayList<>(); + if (existingEffects != null) { + for (AbilityEffect effect : existingEffects) { + this.effects.add(effect.copy()); + } + } + + setBackground("menubg.png"); + xSize = 280; + ySize = 180; + } + + @Override + public void initGui() { + super.initGui(); + + int y = guiTop + 8; + int labelX = guiLeft + 8; + + // Title + addLabel(new GuiNpcLabel(0, "ability.effects", labelX, y)); + y += 16; + + // Column headers + addLabel(new GuiNpcLabel(1, "gui.type", guiLeft + 10, y)); + addLabel(new GuiNpcLabel(2, "gui.duration", guiLeft + 115, y)); + addLabel(new GuiNpcLabel(3, "gui.amp", guiLeft + 175, y)); + y += 14; + + // Effect rows + for (int i = 0; i < effects.size() && i < MAX_EFFECTS; i++) { + AbilityEffect effect = effects.get(i); + int baseId = 1 + i * 10; + + // Type selector button + int typeIndex = effect.getType().ordinal(); + addButton(new GuiNpcButton(baseId, guiLeft + 8, y, 100, 20, EFFECT_TYPE_NAMES, typeIndex)); + + // Duration text field + GuiNpcTextField durField = new GuiNpcTextField(baseId + 1, this, fontRendererObj, + guiLeft + 112, y, 50, 20, String.valueOf(effect.getDurationTicks())); + durField.setIntegersOnly(); + durField.setMinMaxDefault(1, 12000, 60); + addTextField(durField); + + // Amplifier selector (0-10) + String[] ampValues = new String[11]; + for (int a = 0; a <= 10; a++) { + ampValues[a] = String.valueOf(a); + } + addButton(new GuiNpcButton(baseId + 2, guiLeft + 168, y, 40, 20, ampValues, effect.getAmplifier())); + + // Delete button + addButton(new GuiNpcButton(baseId + 3, guiLeft + 215, y, 20, 20, "X")); + + y += 24; + } + + // Add button (if space available) + if (effects.size() < MAX_EFFECTS) { + addButton(new GuiNpcButton(100, guiLeft + 8, y, 50, 20, "gui.add")); + } + + // Bottom buttons + addButton(new GuiNpcButton(65, guiLeft + 8, guiTop + ySize - 28, 60, 20, "gui.cancel")); + addButton(new GuiNpcButton(66, guiLeft + xSize - 68, guiTop + ySize - 28, 60, 20, "gui.done")); + } + + @Override + public void buttonEvent(GuiButton guibutton) { + int id = guibutton.id; + + // Add button + if (id == 100) { + if (effects.size() < MAX_EFFECTS) { + // Add new effect with default values (Slowness, 60 ticks, amp 0) + effects.add(new AbilityEffect(AbilityEffect.EffectType.SLOWNESS, 60, 0)); + initGui(); + } + return; + } + + // Cancel button + if (id == 65) { + cancelled = true; + close(); + return; + } + + // Done button + if (id == 66) { + // Remove any NONE effects before saving + effects.removeIf(e -> !e.isValid()); + cancelled = false; + close(); + return; + } + + // Effect row buttons (id >= 1 and < 100) + if (id >= 1 && id < 100) { + int effectIndex = (id - 1) / 10; + int action = (id - 1) % 10; + + if (effectIndex >= 0 && effectIndex < effects.size()) { + AbilityEffect effect = effects.get(effectIndex); + + switch (action) { + case 0: // Type selector + int typeIndex = ((GuiNpcButton) guibutton).getValue(); + effect.setType(AbilityEffect.EffectType.fromOrdinal(typeIndex)); + break; + case 2: // Amplifier selector + int amp = ((GuiNpcButton) guibutton).getValue(); + effect.setAmplifier(amp); + break; + case 3: // Delete button + effects.remove(effectIndex); + initGui(); + break; + } + } + } + } + + @Override + public void unFocused(GuiNpcTextField textField) { + int id = textField.id; + + // Duration text fields (baseId + 1) + if (id >= 2 && id < 100) { + int effectIndex = (id - 1) / 10; + int action = (id - 1) % 10; + + if (action == 1 && effectIndex >= 0 && effectIndex < effects.size()) { + effects.get(effectIndex).setDurationTicks(textField.getInteger()); + } + } + } + + /** + * Returns the resulting effects list after the dialog closes. + * Returns null if cancelled. + */ + public List getResult() { + if (cancelled) { + return null; + } + return effects; + } + + /** + * Returns true if the dialog was cancelled. + */ + public boolean wasCancelled() { + return cancelled; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java index ad15bb576..1c7179deb 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityEnergyBeam; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -9,6 +10,8 @@ import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; import noppes.npcs.client.gui.util.SubGuiInterface; +import java.util.List; + /** * GUI for configuring Energy Beam ability type-specific settings. * Energy Beam is a homing head with trailing path (DBZ-style). @@ -87,6 +90,11 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(111, "ability.lifetime", col2LabelX, y + 5)); addTextField(createIntField(111, col2FieldX, y, 50, beam.getMaxLifetime())); + + y += 24; + + // Row 7: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -161,6 +169,9 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { case 108: beam.setExplosive(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(beam.getEffects())); + break; } } @@ -199,6 +210,12 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { } editingVisualColorId = 0; initGui(); + } else if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + beam.setEffects(result); + } } else { super.subGuiClosed(subgui); } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java index c5240d862..25383c926 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java @@ -1,11 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityGuard; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Guard ability type-specific settings. @@ -68,6 +72,13 @@ public class SubGuiAbilityGuard extends SubGuiAbilityConfig { GuiNpcTextField counterAnimField = createIntField(106, col2FieldX, y, 50, guard.getCounterAnimationId()); counterAnimField.setEnabled(guard.isCanCounter()); addTextField(counterAnimField); + + y += 24; + + // Row 5: Effects button (applies on counter) + GuiNpcButton effectsBtn = new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects"); + effectsBtn.setEnabled(guard.isCanCounter()); + addButton(effectsBtn); } @Override @@ -80,6 +91,21 @@ public class SubGuiAbilityGuard extends SubGuiAbilityConfig { case 102: guard.setCounterType(AbilityGuard.CounterType.values()[button.getValue()]); break; + case 150: + setSubGui(new SubGuiAbilityEffects(guard.getEffects())); + break; + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + guard.setEffects(result); + } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java index 1ec615d7a..8a91798d0 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java @@ -1,11 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityHazard; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Hazard ability type-specific settings. @@ -71,6 +75,11 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(109, "ability.affectsCaster", col2LabelX, y + 5)); addButton(new GuiNpcButton(109, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, hazard.isAffectsCaster() ? 1 : 0)); + + y += 24; + + // Row 6: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -86,6 +95,21 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig { case 109: hazard.setAffectsCaster(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(hazard.getEffects())); + break; + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + hazard.setEffects(result); + } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeavyHit.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeavyHit.java index ea21127dc..897a4af1f 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeavyHit.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeavyHit.java @@ -1,10 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityHeavyHit; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; +import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Heavy Hit ability type-specific settings. @@ -24,29 +29,37 @@ public class SubGuiAbilityHeavyHit extends SubGuiAbilityConfig { int labelX = guiLeft + 8; int fieldX = guiLeft + 85; int col2LabelX = guiLeft + 145; - int col2FieldX = guiLeft + 205; - // Row 1: Damage + Potion Time + // Row 1: Damage + Knockback addLabel(new GuiNpcLabel(100, "enchantment.damage", labelX, y + 5)); addTextField(createFloatField(100, fieldX, y, 50, heavyHit.getDamage())); - addLabel(new GuiNpcLabel(101, "ability.potionTime", col2LabelX, y + 5)); - addTextField(createIntField(101, col2FieldX, y, 50, heavyHit.getPotionDurationSeconds())); + addLabel(new GuiNpcLabel(102, "ability.knockback", col2LabelX, y + 5)); + addTextField(createFloatField(102, guiLeft + 205, y, 50, heavyHit.getKnockback())); y += 24; - // Row 2: Knockback + Slowness Level - addLabel(new GuiNpcLabel(102, "ability.knockback", labelX, y + 5)); - addTextField(createFloatField(102, fieldX, y, 50, heavyHit.getKnockback())); + // Row 2: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); + } - addLabel(new GuiNpcLabel(103, "ability.slownessLvl", col2LabelX, y + 5)); - addTextField(createIntField(103, col2FieldX, y, 50, heavyHit.getSlownessLevel())); + @Override + protected void handleTypeButton(int id, GuiNpcButton button) { + if (id == 150) { + setSubGui(new SubGuiAbilityEffects(heavyHit.getEffects())); + } + } - y += 24; - - // Row 3: Weakness Level - addLabel(new GuiNpcLabel(104, "ability.weaknessLvl", labelX, y + 5)); - addTextField(createIntField(104, fieldX, y, 50, heavyHit.getWeaknessLevel())); + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + heavyHit.setEffects(result); + } + } } @Override @@ -55,18 +68,9 @@ public class SubGuiAbilityHeavyHit extends SubGuiAbilityConfig { case 100: heavyHit.setDamage(parseFloat(field, heavyHit.getDamage())); break; - case 101: - heavyHit.setPotionDurationSeconds(field.getInteger()); - break; case 102: heavyHit.setKnockback(parseFloat(field, heavyHit.getKnockback())); break; - case 103: - heavyHit.setSlownessLevel(field.getInteger()); - break; - case 104: - heavyHit.setWeaknessLevel(field.getInteger()); - break; } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java index f83e93baf..614a8bce0 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityLaserShot; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -9,6 +10,8 @@ import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; import noppes.npcs.client.gui.util.SubGuiInterface; +import java.util.List; + /** * GUI for configuring Laser Shot ability type-specific settings. */ @@ -77,6 +80,11 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(109, "ability.knockbackUp", col2LabelX, y + 5)); addTextField(createFloatField(109, col2FieldX, y, 50, laser.getKnockbackUp())); + + y += 24; + + // Row 6: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -142,6 +150,9 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { case 106: laser.setExplosive(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(laser.getEffects())); + break; } } @@ -180,6 +191,12 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { } editingVisualColorId = 0; initGui(); + } else if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + laser.setEffects(result); + } } else { super.subGuiClosed(subgui); } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java index 42dd6a773..6c5c598ba 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityOrb; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -9,6 +10,8 @@ import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; import noppes.npcs.client.gui.util.SubGuiInterface; +import java.util.List; + /** * GUI for configuring Orb ability type-specific settings. */ @@ -77,6 +80,11 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(109, "ability.lifetime", col2LabelX, y + 5)); addTextField(createIntField(109, col2FieldX, y, 50, orb.getMaxLifetime())); + + y += 24; + + // Row 6: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -151,6 +159,9 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { case 106: orb.setExplosive(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(orb.getEffects())); + break; } } @@ -189,6 +200,12 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { } editingVisualColorId = 0; initGui(); + } else if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + orb.setEffects(result); + } } else { super.subGuiClosed(subgui); } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java index c9be00e38..52bf7a092 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java @@ -1,11 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityProjectile; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Projectile ability type-specific settings. @@ -69,6 +73,11 @@ public class SubGuiAbilityProjectile extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(107, "ability.homingStr", col2LabelX, y + 5)); addTextField(createFloatField(107, col2FieldX, y, 50, projectile.getHomingStrength())); + + y += 24; + + // Row 5: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -85,6 +94,21 @@ public class SubGuiAbilityProjectile extends SubGuiAbilityConfig { case 106: projectile.setHoming(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(projectile.getEffects())); + break; + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + projectile.setEffects(result); + } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityShockwave.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityShockwave.java index a03a85736..48c2c5295 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityShockwave.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityShockwave.java @@ -1,10 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityShockwave; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; +import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Shockwave ability type-specific settings. @@ -41,17 +46,35 @@ public class SubGuiAbilityShockwave extends SubGuiAbilityConfig { y += 24; - // Row 3: Stun Duration + Max Targets - addLabel(new GuiNpcLabel(103, "ability.stunDuration", labelX, y + 5)); - addTextField(createIntField(103, fieldX, y, 50, shockwave.getStunDuration())); + // Row 3: Max Targets + Effects button + addLabel(new GuiNpcLabel(104, "ability.maxTargets", labelX, y + 5)); + addTextField(createIntField(104, fieldX, y, 50, shockwave.getMaxTargets())); - addLabel(new GuiNpcLabel(104, "ability.maxTargets", col2LabelX, y + 5)); - addTextField(createIntField(104, col2FieldX, y, 50, shockwave.getMaxTargets())); + addButton(new GuiNpcButton(150, col2LabelX, y, 80, 20, "ability.effects")); y += 24; addLabel(new GuiNpcLabel(105, "ability.shockwaveFalloff", labelX, y + 5)); } + @Override + protected void handleTypeButton(int id, GuiNpcButton button) { + if (id == 150) { + setSubGui(new SubGuiAbilityEffects(shockwave.getEffects())); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + shockwave.setEffects(result); + } + } + } + @Override protected void handleTypeTextField(int id, GuiNpcTextField field) { switch (id) { @@ -64,9 +87,6 @@ public class SubGuiAbilityShockwave extends SubGuiAbilityConfig { case 102: shockwave.setPushStrength(parseFloat(field, shockwave.getPushStrength())); break; - case 103: - shockwave.setStunDuration(field.getInteger()); - break; case 104: shockwave.setMaxTargets(field.getInteger()); break; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySlam.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySlam.java index 989202037..4e020829b 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySlam.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySlam.java @@ -1,10 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilitySlam; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; +import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Slam ability type-specific settings. @@ -44,9 +49,30 @@ public class SubGuiAbilitySlam extends SubGuiAbilityConfig { y += 24; - // Row 3: Leap Height + // Row 3: Leap Height + Effects addLabel(new GuiNpcLabel(104, "ability.leapHeight", labelX, y + 5)); addTextField(createFloatField(104, fieldX, y, 50, slam.getLeapHeight())); + + addButton(new GuiNpcButton(150, col2LabelX, y, 80, 20, "ability.effects")); + } + + @Override + protected void handleTypeButton(int id, GuiNpcButton button) { + if (id == 150) { + setSubGui(new SubGuiAbilityEffects(slam.getEffects())); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + slam.setEffects(result); + } + } } @Override diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java index 95f54619b..9a3dc2fe8 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilitySweeper; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -9,6 +10,8 @@ import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; import noppes.npcs.client.gui.util.SubGuiInterface; +import java.util.List; + /** * GUI for configuring Sweeper ability type-specific settings. * Sweeper is a low rotating beam that players can jump over. @@ -75,6 +78,11 @@ public class SubGuiAbilitySweeper extends SubGuiAbilityConfig { // Row 5: Lock On Target addLabel(new GuiNpcLabel(108, "ability.lockTarget", labelX, y + 5)); addButton(new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, sweeper.isLockOnTarget() ? 1 : 0)); + + y += 24; + + // Row 6: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -121,6 +129,9 @@ public class SubGuiAbilitySweeper extends SubGuiAbilityConfig { case 108: sweeper.setLockOnTarget(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(sweeper.getEffects())); + break; } } @@ -155,6 +166,12 @@ public class SubGuiAbilitySweeper extends SubGuiAbilityConfig { } editingVisualColorId = 0; initGui(); + } else if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + sweeper.setEffects(result); + } } else { super.subGuiClosed(subgui); } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java index 6173f9ded..1dfb12d22 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java @@ -1,11 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityTeleport; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Teleport ability type-specific settings. @@ -85,6 +89,11 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(109, "ability.dmgAtEnd", col2LabelX, y + 5)); addButton(new GuiNpcButton(109, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isDamageAtEnd() ? 1 : 0)); + + y += 24; + + // Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); } @Override @@ -104,6 +113,21 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig { case 109: teleport.setDamageAtEnd(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(teleport.getEffects())); + break; + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + teleport.setEffects(result); + } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java index 781d0665a..2c0fc3a68 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java @@ -1,11 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityTrap; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Trap ability type-specific settings. @@ -55,24 +59,31 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig { y += 24; - // Row 4: Root Duration + Stun Duration - addLabel(new GuiNpcLabel(106, "ability.rootDuration", labelX, y + 5)); - addTextField(createIntField(106, fieldX, y, 50, trap.getRootDuration())); - - addLabel(new GuiNpcLabel(107, "ability.stunDuration", col2LabelX, y + 5)); - addTextField(createIntField(107, col2FieldX, y, 50, trap.getStunDuration())); - - y += 24; - - // Row 5: Knockback + // Row 4: Knockback + Effects button addLabel(new GuiNpcLabel(108, "ability.knockback", labelX, y + 5)); addTextField(createFloatField(108, fieldX, y, 50, trap.getKnockback())); + + addButton(new GuiNpcButton(150, col2LabelX, y, 80, 20, "ability.effects")); } @Override protected void handleTypeButton(int id, GuiNpcButton button) { if (id == 100) { trap.setPlacement(AbilityTrap.TrapPlacement.values()[button.getValue()]); + } else if (id == 150) { + setSubGui(new SubGuiAbilityEffects(trap.getEffects())); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + trap.setEffects(result); + } } } @@ -94,12 +105,6 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig { case 105: trap.setMaxTriggers(field.getInteger()); break; - case 106: - trap.setRootDuration(field.getInteger()); - break; - case 107: - trap.setStunDuration(field.getInteger()); - break; case 108: trap.setKnockback(parseFloat(field, trap.getKnockback())); break; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java index 003cef5c6..4cc7bc89a 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java @@ -1,11 +1,15 @@ package noppes.npcs.client.gui.advanced.ability; +import kamkeel.npcs.controllers.data.ability.AbilityEffect; import kamkeel.npcs.controllers.data.ability.type.AbilityVortex; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.client.gui.util.SubGuiInterface; + +import java.util.List; /** * GUI for configuring Vortex ability type-specific settings. @@ -54,12 +58,8 @@ public class SubGuiAbilityVortex extends SubGuiAbilityConfig { y += 24; - // Row 4: Stun Duration + Root Duration - addLabel(new GuiNpcLabel(106, "ability.stunDuration", labelX, y + 5)); - addTextField(createIntField(106, fieldX, y, 50, vortex.getStunDuration())); - - addLabel(new GuiNpcLabel(107, "ability.rootDuration", col2LabelX, y + 5)); - addTextField(createIntField(107, col2FieldX, y, 50, vortex.getRootDuration())); + // Row 4: Effects button + addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); y += 24; @@ -81,6 +81,21 @@ public class SubGuiAbilityVortex extends SubGuiAbilityConfig { case 108: vortex.setDamageOnPull(value == 1); break; + case 150: + setSubGui(new SubGuiAbilityEffects(vortex.getEffects())); + break; + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + super.subGuiClosed(subgui); + if (subgui instanceof SubGuiAbilityEffects) { + SubGuiAbilityEffects effectsGui = (SubGuiAbilityEffects) subgui; + List result = effectsGui.getResult(); + if (result != null) { + vortex.setEffects(result); + } } } @@ -102,12 +117,6 @@ public class SubGuiAbilityVortex extends SubGuiAbilityConfig { case 105: vortex.setMaxTargets(field.getInteger()); break; - case 106: - vortex.setStunDuration(field.getInteger()); - break; - case 107: - vortex.setRootDuration(field.getInteger()); - break; case 109: vortex.setPullDamage(parseFloat(field, vortex.getPullDamage())); break; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index b7e33a029..d5dc945ce 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1575,17 +1575,11 @@ ability.minDist=Min Dist ability.distance=Distance ability.lifetime=Lifetime ability.stunTicks=Stun -ability.stunDur=Stun Dur -ability.rootDur=Root Dur -ability.rootDuration=Root Duration -ability.stunDuration=Stun Duration ability.leapHeight=Leap Height ability.hitWidth=Hit Width -ability.potionTime=Potion Time (s) -ability.weaknessLvl=Weakness Lvl -ability.poisonTime=Poison Time (s) -ability.slownessLvl=Slowness Lvl -ability.poisonLvl=Poison Lvl +ability.effects=Effects +gui.duration=Duration +gui.amp=Amp # Slam Settings ability.leapSpeed=Leap Speed From c858f24e677f13e9a1ee155b6e28f98cf9b7932f Mon Sep 17 00:00:00 2001 From: Vidal Date: Tue, 27 Jan 2026 01:33:12 -0300 Subject: [PATCH 04/15] Implemented built in animations for abilities --- .../data/ability/AbilityAnimation.java | 79 +++++++++++++++++++ .../data/ability/AbilityController.java | 73 +++++++++++++++-- 2 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java new file mode 100644 index 000000000..1a6c907ea --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java @@ -0,0 +1,79 @@ +package kamkeel.npcs.controllers.data.ability; + +import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; +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 {; + + private final HashMap animations = new HashMap<>(); + + AbilityAnimation(String idle, String windUp, String active, String recovery) { + animations.put(IDLE, idle); + animations.put(WINDUP, windUp); + animations.put(ACTIVE, active); + animations.put(RECOVERY, recovery); + } + + AbilityAnimation(String idle, String windUp, String active) { + animations.put(IDLE, idle); + animations.put(WINDUP, windUp); + animations.put(ACTIVE, active); + } + + AbilityAnimation(String windUp, String active) { + animations.put(WINDUP, windUp); + animations.put(ACTIVE, active); + } + + AbilityAnimation(String anim, AbilityPhase phase) { + animations.put(phase, anim); + } + + public String fileName(AbilityPhase phase) { + return animations.get(phase); + } + + public File get(AbilityPhase phase) { + if (animations.get(phase).isEmpty() || animations.get(phase).equals("N/A")) + return null; + + return getFile(animations.get(phase)); + } + + public File idle() { + return get(IDLE); + } + + public File windUp() { + return get(WINDUP); + } + + public File active() { + return get(ACTIVE); + } + + public File recovery() { + return get(RECOVERY); + } + + private File getFile(String fileName) { + try (InputStream stream = CustomNpcs.class.getResourceAsStream("/internal/data/animations/" + name() + "/" + fileName + ".json")) { + + File file = new File("temp"); + + FileUtils.copyInputStreamToFile(stream, file); + + return file; + } catch (Exception i) { + LogWriter.except(i); + } + return null; + } +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java index 41c20a085..3eb8283f8 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java @@ -22,14 +22,13 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.api.handler.IAbilityHandler; +import noppes.npcs.api.handler.data.IAnimation; +import noppes.npcs.controllers.AnimationController; +import noppes.npcs.controllers.data.Animation; import noppes.npcs.util.NBTJsonUtil; import java.io.File; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Supplier; /** @@ -49,6 +48,7 @@ public class AbilityController implements IAbilityHandler { public AbilityController() { Instance = this; registerBuiltins(); + new Animations(); } /** @@ -321,4 +321,67 @@ public class AbilityController implements IAbilityHandler { registerType("cnpc:hazard", AbilityHazard::new); registerType("cnpc:trap", AbilityTrap::new); } + + public static class Animations { + public HashMap> animations; + + public static Animations Instance; + + public Animations() { + Instance = this; + animations = new HashMap<>(); + load(); + } + + public void load() { + registerBuiltins(); + } + + private void registerBuiltins() { + animations.clear(); + + try { + for (AbilityPhase phase : AbilityPhase.values()) { + for (AbilityAnimation anim : AbilityAnimation.values()) { + File file = anim.get(phase); + + if (file == null) { +// LogWriter.info("AnimationController: Ability Animations for " + anim.name() + " not found."); + continue; + } + + Animation animation = new Animation(); + animation.readFromNBT(NBTJsonUtil.LoadFile(file)); + + animations + .computeIfAbsent(anim.ordinal(), k -> new EnumMap<>(AbilityPhase.class)) + .put(phase, animation); + } + } + } catch (Exception e) { + LogWriter.except(e); + } + } + + public IAnimation get(AbilityAnimation ability, AbilityPhase phase) { + return get(ability.ordinal(), phase); + } + + public IAnimation get(int id, AbilityPhase phase) { + return animations.get(id).get(phase); + } + + public boolean has(AbilityAnimation ability, AbilityPhase phase) { + return get(ability.ordinal(), phase) != null; + } + + public boolean has(int id, AbilityPhase phase) { + return get(id, phase) != null; + } + + public IAnimation[] getAnimations(AbilityAnimation ability) { + ArrayList animations = new ArrayList<>(this.animations.get(ability.ordinal()).values()); + return animations.toArray(new IAnimation[0]); + } + } } From 39b6304bedeb549a723bcdaa6b885b34da042002 Mon Sep 17 00:00:00 2001 From: Vidal Date: Tue, 27 Jan 2026 01:34:34 -0300 Subject: [PATCH 05/15] Updated imports --- .../kamkeel/npcs/controllers/data/ability/AbilityController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java index 3eb8283f8..be9ce355d 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java @@ -23,7 +23,6 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.api.handler.IAbilityHandler; import noppes.npcs.api.handler.data.IAnimation; -import noppes.npcs.controllers.AnimationController; import noppes.npcs.controllers.data.Animation; import noppes.npcs.util.NBTJsonUtil; From 246baa9f55b424c6520705fb8f7648cbf3804078 Mon Sep 17 00:00:00 2001 From: Vidal Date: Tue, 27 Jan 2026 01:49:08 -0300 Subject: [PATCH 06/15] Removed static class from AbilityController and made animations built into the enum --- src/api | 2 +- .../data/ability/AbilityAnimation.java | 45 +++++++++---- .../data/ability/AbilityController.java | 64 ------------------- 3 files changed, 34 insertions(+), 77 deletions(-) diff --git a/src/api b/src/api index b84763a8e..ae73e1b88 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit b84763a8eefdc0be7fb909888ac5ad6d22e3f987 +Subproject commit ae73e1b885415701c1ee20b64c1d0ae9c9089efc diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java index 1a6c907ea..cb27dcd3f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java @@ -2,6 +2,9 @@ package kamkeel.npcs.controllers.data.ability; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; +import noppes.npcs.api.handler.data.IAnimation; +import noppes.npcs.controllers.data.Animation; +import noppes.npcs.util.NBTJsonUtil; import org.apache.commons.io.FileUtils; import java.io.File; @@ -11,7 +14,6 @@ import java.util.HashMap; import static kamkeel.npcs.controllers.data.ability.AbilityPhase.*; public enum AbilityAnimation {; - private final HashMap animations = new HashMap<>(); AbilityAnimation(String idle, String windUp, String active, String recovery) { @@ -40,30 +42,49 @@ public enum AbilityAnimation {; return animations.get(phase); } - public File get(AbilityPhase phase) { + public File getFile(AbilityPhase phase) { if (animations.get(phase).isEmpty() || animations.get(phase).equals("N/A")) return null; - return getFile(animations.get(phase)); + return getFileFromName(animations.get(phase)); } - public File idle() { - return get(IDLE); + public IAnimation 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 File windUp() { - return get(WINDUP); + public IAnimation idle() { + return getAnimation(IDLE); } - public File active() { - return get(ACTIVE); + public IAnimation windUp() { + return getAnimation(WINDUP); } - public File recovery() { - return get(RECOVERY); + public IAnimation active() { + return getAnimation(ACTIVE); } - private File getFile(String fileName) { + public IAnimation recovery() { + return getAnimation(RECOVERY); + } + + private File getFileFromName(String fileName) { try (InputStream stream = CustomNpcs.class.getResourceAsStream("/internal/data/animations/" + name() + "/" + fileName + ".json")) { File file = new File("temp"); diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java index be9ce355d..0b88f1a42 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java @@ -47,7 +47,6 @@ public class AbilityController implements IAbilityHandler { public AbilityController() { Instance = this; registerBuiltins(); - new Animations(); } /** @@ -320,67 +319,4 @@ public class AbilityController implements IAbilityHandler { registerType("cnpc:hazard", AbilityHazard::new); registerType("cnpc:trap", AbilityTrap::new); } - - public static class Animations { - public HashMap> animations; - - public static Animations Instance; - - public Animations() { - Instance = this; - animations = new HashMap<>(); - load(); - } - - public void load() { - registerBuiltins(); - } - - private void registerBuiltins() { - animations.clear(); - - try { - for (AbilityPhase phase : AbilityPhase.values()) { - for (AbilityAnimation anim : AbilityAnimation.values()) { - File file = anim.get(phase); - - if (file == null) { -// LogWriter.info("AnimationController: Ability Animations for " + anim.name() + " not found."); - continue; - } - - Animation animation = new Animation(); - animation.readFromNBT(NBTJsonUtil.LoadFile(file)); - - animations - .computeIfAbsent(anim.ordinal(), k -> new EnumMap<>(AbilityPhase.class)) - .put(phase, animation); - } - } - } catch (Exception e) { - LogWriter.except(e); - } - } - - public IAnimation get(AbilityAnimation ability, AbilityPhase phase) { - return get(ability.ordinal(), phase); - } - - public IAnimation get(int id, AbilityPhase phase) { - return animations.get(id).get(phase); - } - - public boolean has(AbilityAnimation ability, AbilityPhase phase) { - return get(ability.ordinal(), phase) != null; - } - - public boolean has(int id, AbilityPhase phase) { - return get(id, phase) != null; - } - - public IAnimation[] getAnimations(AbilityAnimation ability) { - ArrayList animations = new ArrayList<>(this.animations.get(ability.ordinal()).values()); - return animations.toArray(new IAnimation[0]); - } - } } From 0484596a91c7e5d6f01f7ede189b5e151de4e630 Mon Sep 17 00:00:00 2001 From: Vidal Date: Tue, 27 Jan 2026 01:51:49 -0300 Subject: [PATCH 07/15] Updated imports and fields --- .../data/ability/AbilityAnimation.java | 28 +++++++++---------- .../data/ability/AbilityController.java | 2 -- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java index cb27dcd3f..4b7f2ba3e 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java @@ -14,39 +14,39 @@ import java.util.HashMap; import static kamkeel.npcs.controllers.data.ability.AbilityPhase.*; public enum AbilityAnimation {; - private final HashMap animations = new HashMap<>(); + private final HashMap animationNames = new HashMap<>(); AbilityAnimation(String idle, String windUp, String active, String recovery) { - animations.put(IDLE, idle); - animations.put(WINDUP, windUp); - animations.put(ACTIVE, active); - animations.put(RECOVERY, recovery); + animationNames.put(IDLE, idle); + animationNames.put(WINDUP, windUp); + animationNames.put(ACTIVE, active); + animationNames.put(RECOVERY, recovery); } AbilityAnimation(String idle, String windUp, String active) { - animations.put(IDLE, idle); - animations.put(WINDUP, windUp); - animations.put(ACTIVE, active); + animationNames.put(IDLE, idle); + animationNames.put(WINDUP, windUp); + animationNames.put(ACTIVE, active); } AbilityAnimation(String windUp, String active) { - animations.put(WINDUP, windUp); - animations.put(ACTIVE, active); + animationNames.put(WINDUP, windUp); + animationNames.put(ACTIVE, active); } AbilityAnimation(String anim, AbilityPhase phase) { - animations.put(phase, anim); + animationNames.put(phase, anim); } public String fileName(AbilityPhase phase) { - return animations.get(phase); + return animationNames.get(phase); } public File getFile(AbilityPhase phase) { - if (animations.get(phase).isEmpty() || animations.get(phase).equals("N/A")) + if (animationNames.get(phase).isEmpty() || animationNames.get(phase).equals("N/A")) return null; - return getFileFromName(animations.get(phase)); + return getFileFromName(animationNames.get(phase)); } public IAnimation getAnimation(AbilityPhase phase) { diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java index 0b88f1a42..a61df06fa 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityController.java @@ -22,8 +22,6 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.api.handler.IAbilityHandler; -import noppes.npcs.api.handler.data.IAnimation; -import noppes.npcs.controllers.data.Animation; import noppes.npcs.util.NBTJsonUtil; import java.io.File; From 0f44a3c6c64906608ec9945b9923d6df20fbf620 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 26 Jan 2026 23:55:07 -0500 Subject: [PATCH 08/15] Ability Anchor Points + Orb / Disc Summoning --- .../controllers/data/ability/AnchorPoint.java | 55 ++++ .../data/ability/type/AbilityDisc.java | 73 +++-- .../data/ability/type/AbilityEnergyBeam.java | 13 +- .../data/ability/type/AbilityOrb.java | 76 +++-- .../npcs/entity/EntityAbilityBeam.java | 54 ++-- .../npcs/entity/EntityAbilityDisc.java | 275 ++++++++++++++-- .../kamkeel/npcs/entity/EntityAbilityOrb.java | 183 +++++++++++ .../kamkeel/npcs/util/AnchorPointHelper.java | 303 ++++++++++++++++++ .../advanced/ability/SubGuiAbilityDisc.java | 22 +- .../ability/SubGuiAbilityEnergyBeam.java | 12 +- .../advanced/ability/SubGuiAbilityOrb.java | 12 +- .../assets/customnpcs/lang/en_US.lang | 1 + 12 files changed, 984 insertions(+), 95 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/controllers/data/ability/AnchorPoint.java create mode 100644 src/main/java/kamkeel/npcs/util/AnchorPointHelper.java diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AnchorPoint.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AnchorPoint.java new file mode 100644 index 000000000..9bf408c27 --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AnchorPoint.java @@ -0,0 +1,55 @@ +package kamkeel.npcs.controllers.data.ability; + +/** + * Defines anchor points for ability charging effects. + * Determines where the charging visual (orb, disc, etc.) appears relative to the entity. + */ +public enum AnchorPoint { + FRONT(0, "Front"), // In front of entity face (default) + CENTER(1, "Center"), // Entity center + RIGHT_HAND(2, "Right Hand"), // Right arm/hand position + LEFT_HAND(3, "Left Hand"), // Left arm/hand position + ABOVE_HEAD(4, "Above Head"), // Above the entity + CHEST(5, "Chest"); // Chest level, centered + + private final int id; + private final String displayName; + + AnchorPoint(int id, String displayName) { + this.id = id; + this.displayName = displayName; + } + + public int getId() { + return id; + } + + public String getDisplayName() { + return displayName; + } + + /** + * Get AnchorPoint from NBT id value. + * Returns FRONT if id is invalid. + */ + public static AnchorPoint fromId(int id) { + for (AnchorPoint anchor : values()) { + if (anchor.id == id) { + return anchor; + } + } + return FRONT; + } + + /** + * Get all display names for GUI dropdowns. + */ + public static String[] getDisplayNames() { + AnchorPoint[] values = values(); + String[] names = new String[values.length]; + for (int i = 0; i < values.length; i++) { + names[i] = values[i].displayName; + } + return names; + } +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java index 5aa34a969..95dcd4afb 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java @@ -3,11 +3,13 @@ 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.TargetingMode; 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 net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; @@ -28,7 +30,7 @@ public class AbilityDisc extends Ability { private float discRadius = 1.0f; private float discThickness = 0.2f; private float maxDistance = 35.0f; - private int maxLifetime = 250; + private int maxLifetime = 200; // Combat properties private float damage = 8.0f; @@ -66,6 +68,12 @@ public class AbilityDisc extends Ability { private float lightningDensity = 0.15f; private float lightningRadius = 0.5f; + // Anchor point for charging position + private AnchorPoint anchorPoint = AnchorPoint.FRONT; + + // Transient state for disc entity (used during windup charging) + private transient int discEntityId = -1; + public AbilityDisc() { this.typeId = "ability.cnpc.disc"; this.name = "Disc"; @@ -105,24 +113,41 @@ public class AbilityDisc extends Ability { public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { if (world.isRemote) return; - double spawnX = npc.posX; - double spawnY = npc.posY + npc.getEyeHeight() * 0.8; - double spawnZ = npc.posZ; + // Find and start moving the disc that was spawned during windup + if (discEntityId != -1) { + Entity entity = world.getEntityByID(discEntityId); + if (entity instanceof EntityAbilityDisc) { + EntityAbilityDisc disc = (EntityAbilityDisc) entity; + disc.startMoving(target); + } + discEntityId = -1; + } + } - EntityAbilityDisc disc = new EntityAbilityDisc( - world, npc, target, - spawnX, spawnY, spawnZ, - discRadius, discThickness, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, - damage, knockback, knockbackUp, - speed, homing, homingStrength, homingRange, - boomerang, boomerangDelay, - explosive, explosionRadius, explosionDamageFalloff, - stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime, - lightningEffect, lightningDensity, lightningRadius - ); + @Override + public void onWindUpTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { + if (world.isRemote) return; - world.spawnEntityInWorld(disc); + // Spawn disc in charging mode on first tick of windup + if (tick == 1) { + // Create disc in charging mode - follows NPC based on anchor point during windup + EntityAbilityDisc disc = EntityAbilityDisc.createCharging( + world, npc, target, + discRadius, discThickness, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, + speed, homing, homingStrength, homingRange, + boomerang, boomerangDelay, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, + anchorPoint, // Anchor point for charging position + windUpTicks // Charge duration = windup duration + ); + + world.spawnEntityInWorld(disc); + discEntityId = disc.getEntityId(); + } } @Override @@ -135,6 +160,14 @@ public class AbilityDisc extends Ability { @Override public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { + // Despawn charging disc if interrupted during windup + if (discEntityId != -1) { + Entity entity = npc.worldObj.getEntityByID(discEntityId); + if (entity != null) { + entity.setDead(); + } + discEntityId = -1; + } } @Override @@ -193,6 +226,7 @@ public class AbilityDisc extends Ability { nbt.setBoolean("lightningEffect", lightningEffect); nbt.setFloat("lightningDensity", lightningDensity); nbt.setFloat("lightningRadius", lightningRadius); + nbt.setInteger("anchorPoint", anchorPoint.getId()); } @Override @@ -201,7 +235,7 @@ public class AbilityDisc extends Ability { this.discRadius = nbt.hasKey("discRadius") ? nbt.getFloat("discRadius") : 1.0f; this.discThickness = nbt.hasKey("discThickness") ? nbt.getFloat("discThickness") : 0.2f; this.maxDistance = nbt.hasKey("maxDistance") ? nbt.getFloat("maxDistance") : 35.0f; - this.maxLifetime = nbt.hasKey("maxLifetime") ? nbt.getInteger("maxLifetime") : 250; + this.maxLifetime = nbt.hasKey("maxLifetime") ? nbt.getInteger("maxLifetime") : 200; this.damage = nbt.hasKey("damage") ? nbt.getFloat("damage") : 8.0f; this.knockback = nbt.hasKey("knockback") ? nbt.getFloat("knockback") : 1.2f; this.knockbackUp = nbt.hasKey("knockbackUp") ? nbt.getFloat("knockbackUp") : 0.15f; @@ -224,6 +258,7 @@ public class AbilityDisc extends Ability { this.lightningEffect = nbt.hasKey("lightningEffect") && nbt.getBoolean("lightningEffect"); this.lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f; this.lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f; + this.anchorPoint = nbt.hasKey("anchorPoint") ? AnchorPoint.fromId(nbt.getInteger("anchorPoint")) : AnchorPoint.FRONT; } // Getters & Setters @@ -281,4 +316,6 @@ public class AbilityDisc extends Ability { public void setLightningDensity(float lightningDensity) { this.lightningDensity = lightningDensity; } public float getLightningRadius() { return lightningRadius; } public void setLightningRadius(float lightningRadius) { this.lightningRadius = lightningRadius; } + public AnchorPoint getAnchorPoint() { return anchorPoint; } + public void setAnchorPoint(AnchorPoint anchorPoint) { this.anchorPoint = anchorPoint; } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java index 9a5345435..18969b43c 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java @@ -3,6 +3,7 @@ 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.TargetingMode; import kamkeel.npcs.controllers.data.telegraph.Telegraph; import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance; @@ -66,6 +67,9 @@ public class AbilityEnergyBeam extends Ability { private float lightningDensity = 0.15f; private float lightningRadius = 0.5f; + // Anchor point for charging position + private AnchorPoint anchorPoint = AnchorPoint.FRONT; + // Transient state for beam entity (used during windup charging) private transient int beamEntityId = -1; @@ -127,7 +131,7 @@ public class AbilityEnergyBeam extends Ability { if (tick == 1) { float offsetDist = 1.0f; - // Create beam in charging mode - follows NPC's look direction during windup + // Create beam in charging mode - follows NPC based on anchor point during windup EntityAbilityBeam beam = EntityAbilityBeam.createCharging( world, npc, target, beamWidth, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, @@ -139,7 +143,8 @@ public class AbilityEnergyBeam extends Ability { lightningEffect, lightningDensity, lightningRadius, lockMovement, // Anchored mode windUpTicks, // Charge duration = windup duration - offsetDist // Offset distance in front of NPC + offsetDist, // Offset distance (used by FRONT anchor) + anchorPoint // Anchor point for charging position ); world.spawnEntityInWorld(beam); @@ -221,6 +226,7 @@ public class AbilityEnergyBeam extends Ability { nbt.setBoolean("lightningEffect", lightningEffect); nbt.setFloat("lightningDensity", lightningDensity); nbt.setFloat("lightningRadius", lightningRadius); + nbt.setInteger("anchorPoint", anchorPoint.getId()); } @Override @@ -250,6 +256,7 @@ public class AbilityEnergyBeam extends Ability { this.lightningEffect = nbt.hasKey("lightningEffect") && nbt.getBoolean("lightningEffect"); this.lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f; this.lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f; + this.anchorPoint = nbt.hasKey("anchorPoint") ? AnchorPoint.fromId(nbt.getInteger("anchorPoint")) : AnchorPoint.FRONT; } // Getters & Setters @@ -303,4 +310,6 @@ public class AbilityEnergyBeam extends Ability { public void setLightningDensity(float lightningDensity) { this.lightningDensity = lightningDensity; } public float getLightningRadius() { return lightningRadius; } public void setLightningRadius(float lightningRadius) { this.lightningRadius = lightningRadius; } + public AnchorPoint getAnchorPoint() { return anchorPoint; } + public void setAnchorPoint(AnchorPoint anchorPoint) { this.anchorPoint = anchorPoint; } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java index 358b82896..38ffd8db4 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java @@ -3,11 +3,13 @@ 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.TargetingMode; 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 net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; @@ -63,6 +65,12 @@ public class AbilityOrb extends Ability { private float lightningRadius = 0.5f; // Max distance lightning arcs - scales with orbSize private int lightningFadeTime = 6; // Ticks before lightning fades out + // Anchor point for charging position + private AnchorPoint anchorPoint = AnchorPoint.FRONT; + + // Transient state for orb entity (used during windup charging) + private transient int orbEntityId = -1; + public AbilityOrb() { this.typeId = "ability.cnpc.orb"; this.name = "Orb"; @@ -102,25 +110,40 @@ public class AbilityOrb extends Ability { public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { if (world.isRemote) return; - // Spawn position at NPC's eye level - double spawnX = npc.posX; - double spawnY = npc.posY + npc.getEyeHeight() * 0.8; - double spawnZ = npc.posZ; + // Find and start moving the orb that was spawned during windup + if (orbEntityId != -1) { + Entity entity = world.getEntityByID(orbEntityId); + if (entity instanceof EntityAbilityOrb) { + EntityAbilityOrb orb = (EntityAbilityOrb) entity; + orb.startMoving(target); + } + orbEntityId = -1; + } + } - // Create and spawn the self-managing orb entity - EntityAbilityOrb orb = new EntityAbilityOrb( - world, npc, target, - spawnX, spawnY, spawnZ, - orbSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, - damage, knockback, knockbackUp, - orbSpeed, homing, homingStrength, homingRange, - explosive, explosionRadius, explosionDamageFalloff, - stunDuration, slowDuration, slowLevel, - maxDistance, maxLifetime, - lightningEffect, lightningDensity, lightningRadius, lightningFadeTime - ); + @Override + public void onWindUpTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { + if (world.isRemote) return; - world.spawnEntityInWorld(orb); + // Spawn orb in charging mode on first tick of windup + if (tick == 1) { + // Create orb in charging mode - follows NPC based on anchor point during windup + EntityAbilityOrb orb = EntityAbilityOrb.createCharging( + world, npc, target, + orbSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, + orbSpeed, homing, homingStrength, homingRange, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, + maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, lightningFadeTime, + anchorPoint, // Anchor point for charging position + windUpTicks // Charge duration = windup duration + ); + + world.spawnEntityInWorld(orb); + orbEntityId = orb.getEntityId(); + } } @Override @@ -135,7 +158,14 @@ public class AbilityOrb extends Ability { @Override public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { - // Nothing to clean up - entity manages itself + // Despawn charging orb if interrupted during windup + if (orbEntityId != -1) { + Entity entity = npc.worldObj.getEntityByID(orbEntityId); + if (entity != null) { + entity.setDead(); + } + orbEntityId = -1; + } } @Override @@ -192,6 +222,7 @@ public class AbilityOrb extends Ability { nbt.setFloat("lightningDensity", lightningDensity); nbt.setFloat("lightningRadius", lightningRadius); nbt.setInteger("lightningFadeTime", lightningFadeTime); + nbt.setInteger("anchorPoint", anchorPoint.getId()); } @Override @@ -221,6 +252,7 @@ public class AbilityOrb extends Ability { this.lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f; this.lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f; this.lightningFadeTime = nbt.hasKey("lightningFadeTime") ? nbt.getInteger("lightningFadeTime") : 6; + this.anchorPoint = nbt.hasKey("anchorPoint") ? AnchorPoint.fromId(nbt.getInteger("anchorPoint")) : AnchorPoint.FRONT; } // Getters & Setters @@ -423,4 +455,12 @@ public class AbilityOrb extends Ability { public void setLightningFadeTime(int lightningFadeTime) { this.lightningFadeTime = lightningFadeTime; } + + public AnchorPoint getAnchorPoint() { + return anchorPoint; + } + + public void setAnchorPoint(AnchorPoint anchorPoint) { + this.anchorPoint = anchorPoint; + } } diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java index 34030ab3f..70aaf5254 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityBeam.java @@ -1,5 +1,7 @@ package kamkeel.npcs.entity; +import kamkeel.npcs.controllers.data.ability.AnchorPoint; +import kamkeel.npcs.util.AnchorPointHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; @@ -55,6 +57,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { private int chargeDuration = 40; private int chargeTick = 0; private float chargeOffsetDistance = 1.0f; + private AnchorPoint anchorPoint = AnchorPoint.FRONT; // Trail fading for non-anchored beams (comet effect) private boolean fadeTrail = false; @@ -214,7 +217,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { /** * Create a beam in charging mode (for windup phase). * The beam will grow from 0 to headSize over chargeDuration ticks. - * Position follows the owner's look direction. + * Position follows the owner based on anchor point. */ public static EntityAbilityBeam createCharging(World world, EntityNPCInterface owner, EntityLivingBase target, float beamWidth, float headSize, int innerColor, int outerColor, @@ -225,12 +228,13 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { int stunDuration, int slowDuration, int slowLevel, float maxDistance, int maxLifetime, boolean lightningEffect, float lightningDensity, float lightningRadius, - boolean anchoredMode, int chargeDuration, float chargeOffsetDistance) { - // Calculate initial position in front of owner's look direction - float yaw = (float) Math.toRadians(owner.rotationYawHead); - double spawnX = owner.posX - Math.sin(yaw) * chargeOffsetDistance; - double spawnY = owner.posY + owner.getEyeHeight() * 0.7; - double spawnZ = owner.posZ + Math.cos(yaw) * chargeOffsetDistance; + boolean anchoredMode, int chargeDuration, float chargeOffsetDistance, + AnchorPoint anchorPoint) { + // Calculate initial position based on anchor point + Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(owner, anchorPoint, chargeOffsetDistance); + double spawnX = spawnPos.xCoord; + double spawnY = spawnPos.yCoord; + double spawnZ = spawnPos.zCoord; EntityAbilityBeam beam = new EntityAbilityBeam( world, owner, target, @@ -247,6 +251,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { beam.chargeDuration = chargeDuration; beam.chargeTick = 0; beam.chargeOffsetDistance = chargeOffsetDistance; + beam.anchorPoint = anchorPoint; // Non-anchored beams have fading trail (comet effect) beam.fadeTrail = !anchoredMode; @@ -420,7 +425,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { } /** - * Update during charging state - follow owner's look direction. + * Update during charging state - follow owner based on anchor point. */ private void updateCharging() { chargeTick++; @@ -431,27 +436,28 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { return; } - // Follow owner's head/look direction (rotationYawHead for NPCs/players) - float yaw; + // Calculate position based on anchor point + Vec3 pos; if (owner instanceof EntityLivingBase) { - yaw = (float) Math.toRadians(((EntityLivingBase) owner).rotationYawHead); + pos = AnchorPointHelper.calculateAnchorPosition((EntityLivingBase) owner, anchorPoint, chargeOffsetDistance); } else { - yaw = (float) Math.toRadians(owner.rotationYaw); + // Fallback for non-living entities (shouldn't happen normally) + float yaw = (float) Math.toRadians(owner.rotationYaw); + double offsetX = -Math.sin(yaw) * chargeOffsetDistance; + double offsetZ = Math.cos(yaw) * chargeOffsetDistance; + pos = Vec3.createVectorHelper( + owner.posX + offsetX, + owner.posY + owner.getEyeHeight() * 0.7, + owner.posZ + offsetZ + ); } - double offsetX = -Math.sin(yaw) * chargeOffsetDistance; - double offsetZ = Math.cos(yaw) * chargeOffsetDistance; - - double newX = owner.posX + offsetX; - double newY = owner.posY + owner.getEyeHeight() * 0.7; - double newZ = owner.posZ + offsetZ; - - setPosition(newX, newY, newZ); + setPosition(pos.xCoord, pos.yCoord, pos.zCoord); // Also update origin for when firing starts - startX = newX; - startY = newY; - startZ = newZ; + startX = pos.xCoord; + startY = pos.yCoord; + startZ = pos.zCoord; } /** @@ -726,6 +732,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 40; this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0; this.chargeOffsetDistance = nbt.hasKey("ChargeOffsetDistance") ? nbt.getFloat("ChargeOffsetDistance") : 1.0f; + this.anchorPoint = nbt.hasKey("AnchorPoint") ? AnchorPoint.fromId(nbt.getInteger("AnchorPoint")) : AnchorPoint.FRONT; this.fadeTrail = nbt.hasKey("FadeTrail") && nbt.getBoolean("FadeTrail"); this.trailFadeTime = nbt.hasKey("TrailFadeTime") ? nbt.getInteger("TrailFadeTime") : 20; @@ -761,6 +768,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile { nbt.setInteger("ChargeDuration", chargeDuration); nbt.setInteger("ChargeTick", chargeTick); nbt.setFloat("ChargeOffsetDistance", chargeOffsetDistance); + nbt.setInteger("AnchorPoint", anchorPoint.getId()); nbt.setBoolean("FadeTrail", fadeTrail); nbt.setInteger("TrailFadeTime", trailFadeTime); diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java index c0127286f..b1f57f9c9 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityDisc.java @@ -1,5 +1,7 @@ package kamkeel.npcs.entity; +import kamkeel.npcs.controllers.data.ability.AnchorPoint; +import kamkeel.npcs.util.AnchorPointHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; @@ -35,10 +37,45 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { private float discRadius = 1.0f; // Width of disc private float discThickness = 0.2f; // Height of disc + // Charging state (during windup) + private boolean charging = false; + private int chargeDuration = 40; + private int chargeTick = 0; + private AnchorPoint anchorPoint = AnchorPoint.FRONT; + private float targetDiscRadius = 1.0f; // Full radius to grow to during charging + private float targetDiscThickness = 0.2f; // Full thickness to grow to during charging + + // Data watcher index for charging state (synced to clients) + private static final int DW_CHARGING = 20; + public EntityAbilityDisc(World world) { super(world); } + @Override + protected void entityInit() { + super.entityInit(); + // Register data watcher for charging state + this.dataWatcher.addObject(DW_CHARGING, (byte) 0); + } + + /** + * Check if disc is in charging state (synced via data watcher). + */ + public boolean isCharging() { + return this.dataWatcher.getWatchableObjectByte(DW_CHARGING) == 1; + } + + /** + * Set charging state (server only, synced to clients via data watcher). + */ + private void setCharging(boolean value) { + this.charging = value; + if (!worldObj.isRemote) { + this.dataWatcher.updateObject(DW_CHARGING, (byte) (value ? 1 : 0)); + } + } + /** * Full constructor with all parameters (no lightning). */ @@ -117,6 +154,97 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { } } + /** + * Create a disc in charging mode (for windup phase). + * The disc will grow from 0 to discRadius over chargeDuration ticks. + * Position follows the owner based on anchor point. + */ + public static EntityAbilityDisc createCharging(World world, EntityNPCInterface owner, EntityLivingBase target, + float discRadius, float discThickness, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + float speed, boolean homing, float homingStrength, float homingRange, + boolean boomerang, int boomerangDelay, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius, + AnchorPoint anchorPoint, int chargeDuration) { + // Calculate initial position based on anchor point + Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(owner, anchorPoint); + double spawnX = spawnPos.xCoord; + double spawnY = spawnPos.yCoord; + double spawnZ = spawnPos.zCoord; + + EntityAbilityDisc disc = new EntityAbilityDisc( + world, owner, target, + spawnX, spawnY, spawnZ, + discRadius, discThickness, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, speed, homing, homingStrength, homingRange, + boomerang, boomerangDelay, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius); + + // Set charging state (uses data watcher for client sync) + disc.setCharging(true); + disc.chargeDuration = chargeDuration; + disc.chargeTick = 0; + disc.anchorPoint = anchorPoint; + + // Store target size and start at 0 for grow effect + disc.targetDiscRadius = disc.discRadius; + disc.targetDiscThickness = disc.discThickness; + disc.discRadius = 0.01f; // Start very small + disc.discThickness = 0.01f; + disc.size = 0.01f; // Base size used for rendering + disc.renderCurrentSize = 0.01f; + disc.prevRenderSize = 0.01f; + + // Clear motion while charging + disc.motionX = 0; + disc.motionY = 0; + disc.motionZ = 0; + + return disc; + } + + /** + * Start the disc moving (exit charging mode). + * Called by ability when windup ends. + */ + public void startMoving(EntityLivingBase target) { + if (!isCharging()) return; + + setCharging(false); + + // Update start position to current position + startX = posX; + startY = posY; + startZ = posZ; + + // Calculate velocity toward target + Entity owner = getOwner(); + + if (target != null) { + double dx = target.posX - posX; + double dy = (target.posY + target.height * 0.5) - posY; + double dz = target.posZ - posZ; + double len = Math.sqrt(dx * dx + dy * dy + dz * dz); + if (len > 0) { + motionX = (dx / len) * speed; + motionY = (dy / len) * speed; + motionZ = (dz / len) * speed; + } + } else if (owner != null) { + float yaw = (float) Math.toRadians(owner.rotationYaw); + float pitch = (float) Math.toRadians(owner.rotationPitch); + motionX = -Math.sin(yaw) * Math.cos(pitch) * speed; + motionY = -Math.sin(pitch) * speed; + motionZ = Math.cos(yaw) * Math.cos(pitch) * speed; + } + } + @Override protected void updateRotation() { // Disc spins ONLY on Y axis (flat spin like a saw blade) @@ -127,6 +255,12 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { @Override protected void updateProjectile() { + // Handle charging state (windup phase) + if (isCharging()) { + updateCharging(); + return; + } + if (worldObj.isRemote) { handleClientInterpolation(); } else { @@ -141,17 +275,8 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { checkEntityCollision(); this.moveEntity(motionX, motionY, motionZ); - // Boomerang: if we've traveled far without hitting, start returning + // Track ticks for boomerang delay (checkMaxDistance handles the actual return trigger) if (boomerang && !returning && !hasHit) { - double distTraveled = Math.sqrt( - (posX - startX) * (posX - startX) + - (posY - startY) * (posY - startY) + - (posZ - startZ) * (posZ - startZ) - ); - // Start returning at 80% of max distance or after delay - if (distTraveled >= maxDistance * 0.8 || ticksSinceMiss >= boomerangDelay) { - returning = true; - } ticksSinceMiss++; } } @@ -170,20 +295,41 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { @Override protected boolean checkMaxDistance() { - // If boomerang and returning, don't die from max distance - if (boomerang && returning) { - // Die if we get close to owner - Entity owner = getOwner(); - if (owner != null) { - double distToOwner = Math.sqrt( - (posX - owner.posX) * (posX - owner.posX) + - (posY - owner.posY) * (posY - owner.posY) + - (posZ - owner.posZ) * (posZ - owner.posZ) - ); - return distToOwner < 1.0; + double distTraveled = Math.sqrt( + (posX - startX) * (posX - startX) + + (posY - startY) * (posY - startY) + + (posZ - startZ) * (posZ - startZ) + ); + + if (boomerang) { + // If not returning yet, check if we should start returning + if (!returning && !hasHit) { + if (distTraveled >= maxDistance * 0.8 || ticksSinceMiss >= boomerangDelay) { + returning = true; + } } + + // If returning, only die when close to owner + if (returning) { + Entity owner = getOwner(); + if (owner != null) { + double distToOwner = Math.sqrt( + (posX - owner.posX) * (posX - owner.posX) + + (posY - owner.posY) * (posY - owner.posY) + + (posZ - owner.posZ) * (posZ - owner.posZ) + ); + return distToOwner < 1.5; + } + // Owner gone but returning - keep going toward last known position + return false; + } + + // Not returning yet - don't die from distance (we'll trigger return above) + return false; } - return super.checkMaxDistance(); + + // Non-boomerang: standard max distance check + return distTraveled >= maxDistance; } private void updateHoming() { @@ -225,19 +371,28 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { private void updateReturnToOwner() { Entity owner = getOwner(); - if (owner == null) { - this.setDead(); - return; + + // If owner is gone (unloaded/dead), head back toward start position + double targetX, targetY, targetZ; + if (owner != null) { + targetX = owner.posX; + targetY = owner.posY + owner.height * 0.5; + targetZ = owner.posZ; + } else { + // Return to start position if owner not available + targetX = startX; + targetY = startY; + targetZ = startZ; } - double dx = owner.posX - posX; - double dy = (owner.posY + owner.height * 0.5) - posY; - double dz = owner.posZ - posZ; + double dx = targetX - posX; + double dy = targetY - posY; + double dz = targetZ - posZ; double dist = Math.sqrt(dx * dx + dy * dy + dz * dz); if (dist > 0) { // Stronger homing when returning - double returnStrength = homingStrength * 2.0; + double returnStrength = Math.min(1.0, homingStrength * 2.5); double desiredVX = (dx / dist) * speed; double desiredVY = (dy / dist) * speed; double desiredVZ = (dz / dist) * speed; @@ -297,6 +452,52 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { } } + /** + * Update during charging state - follow owner based on anchor point. + */ + private void updateCharging() { + chargeTick++; + + Entity owner = getOwner(); + if (owner == null || owner.isDead) { + setDead(); + return; + } + + // Grow size based on charge progress + float progress = getChargeProgress(); + this.discRadius = targetDiscRadius * progress; + this.discThickness = targetDiscThickness * progress; + this.size = this.discRadius; // Base size for interpolation + + // Calculate position based on anchor point + if (owner instanceof EntityLivingBase) { + Vec3 pos = AnchorPointHelper.calculateAnchorPosition((EntityLivingBase) owner, anchorPoint); + setPosition(pos.xCoord, pos.yCoord, pos.zCoord); + } + + // Update rotation during charging (disc still spins) + updateRotation(); + } + + /** + * Get the charge progress (0-1). + */ + public float getChargeProgress() { + if (chargeDuration <= 0) return 1.0f; + return Math.min(1.0f, (float) chargeTick / chargeDuration); + } + + /** + * Get interpolated charge progress for smooth rendering. + */ + public float getInterpolatedChargeProgress(float partialTicks) { + if (chargeDuration <= 0) return 1.0f; + float prevProgress = Math.max(0, (float) (chargeTick - 1) / chargeDuration); + float currProgress = Math.min(1.0f, (float) chargeTick / chargeDuration); + return prevProgress + (currProgress - prevProgress) * partialTicks; + } + // ==================== GETTERS ==================== public float getSpeed() { @@ -336,6 +537,15 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { this.discRadius = nbt.hasKey("DiscRadius") ? nbt.getFloat("DiscRadius") : 1.0f; this.discThickness = nbt.hasKey("DiscThickness") ? nbt.getFloat("DiscThickness") : 0.2f; this.returning = nbt.hasKey("Returning") && nbt.getBoolean("Returning"); + // Charging state + boolean isCharging = nbt.hasKey("Charging") && nbt.getBoolean("Charging"); + this.charging = isCharging; + this.dataWatcher.updateObject(DW_CHARGING, (byte) (isCharging ? 1 : 0)); + this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 40; + this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0; + this.anchorPoint = nbt.hasKey("AnchorPoint") ? AnchorPoint.fromId(nbt.getInteger("AnchorPoint")) : AnchorPoint.FRONT; + this.targetDiscRadius = nbt.hasKey("TargetDiscRadius") ? nbt.getFloat("TargetDiscRadius") : this.discRadius; + this.targetDiscThickness = nbt.hasKey("TargetDiscThickness") ? nbt.getFloat("TargetDiscThickness") : this.discThickness; } @Override @@ -349,5 +559,12 @@ public class EntityAbilityDisc extends EntityAbilityProjectile { nbt.setFloat("DiscRadius", discRadius); nbt.setFloat("DiscThickness", discThickness); nbt.setBoolean("Returning", returning); + // Charging state + nbt.setBoolean("Charging", isCharging()); + nbt.setInteger("ChargeDuration", chargeDuration); + nbt.setInteger("ChargeTick", chargeTick); + nbt.setInteger("AnchorPoint", anchorPoint.getId()); + nbt.setFloat("TargetDiscRadius", targetDiscRadius); + nbt.setFloat("TargetDiscThickness", targetDiscThickness); } } diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java index 38e3741f9..18a0c8503 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityOrb.java @@ -1,5 +1,7 @@ package kamkeel.npcs.entity; +import kamkeel.npcs.controllers.data.ability.AnchorPoint; +import kamkeel.npcs.util.AnchorPointHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; @@ -25,10 +27,44 @@ public class EntityAbilityOrb extends EntityAbilityProjectile { private float homingStrength = 0.35f; // Increased from 0.15 for better tracking private float homingRange = 20.0f; + // Charging state (during windup) + private boolean charging = false; + private int chargeDuration = 40; + private int chargeTick = 0; + private AnchorPoint anchorPoint = AnchorPoint.FRONT; + private float targetSize = 1.0f; // Full size to grow to during charging + + // Data watcher index for charging state (synced to clients) + private static final int DW_CHARGING = 20; + public EntityAbilityOrb(World world) { super(world); } + @Override + protected void entityInit() { + super.entityInit(); + // Register data watcher for charging state + this.dataWatcher.addObject(DW_CHARGING, (byte) 0); + } + + /** + * Check if orb is in charging state (synced via data watcher). + */ + public boolean isCharging() { + return this.dataWatcher.getWatchableObjectByte(DW_CHARGING) == 1; + } + + /** + * Set charging state (server only, synced to clients via data watcher). + */ + private void setCharging(boolean value) { + this.charging = value; + if (!worldObj.isRemote) { + this.dataWatcher.updateObject(DW_CHARGING, (byte) (value ? 1 : 0)); + } + } + /** * Full constructor with all parameters. */ @@ -102,8 +138,100 @@ public class EntityAbilityOrb extends EntityAbilityProjectile { } } + /** + * Create an orb in charging mode (for windup phase). + * The orb will grow from 0 to orbSize over chargeDuration ticks. + * Position follows the owner based on anchor point. + */ + public static EntityAbilityOrb createCharging(World world, EntityNPCInterface owner, EntityLivingBase target, + float orbSize, int innerColor, int outerColor, + boolean outerColorEnabled, float outerColorWidth, float rotationSpeed, + float damage, float knockback, float knockbackUp, + float speed, boolean homing, float homingStrength, float homingRange, + boolean explosive, float explosionRadius, float explosionDamageFalloff, + int stunDuration, int slowDuration, int slowLevel, + float maxDistance, int maxLifetime, + boolean lightningEffect, float lightningDensity, float lightningRadius, int lightningFadeTime, + AnchorPoint anchorPoint, int chargeDuration) { + // Calculate initial position based on anchor point + Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(owner, anchorPoint); + double spawnX = spawnPos.xCoord; + double spawnY = spawnPos.yCoord; + double spawnZ = spawnPos.zCoord; + + EntityAbilityOrb orb = new EntityAbilityOrb( + world, owner, target, + spawnX, spawnY, spawnZ, + orbSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, + damage, knockback, knockbackUp, speed, homing, homingStrength, homingRange, + explosive, explosionRadius, explosionDamageFalloff, + stunDuration, slowDuration, slowLevel, maxDistance, maxLifetime, + lightningEffect, lightningDensity, lightningRadius, lightningFadeTime); + + // Set charging state (uses data watcher for client sync) + orb.setCharging(true); + orb.chargeDuration = chargeDuration; + orb.chargeTick = 0; + orb.anchorPoint = anchorPoint; + + // Store target size and start at 0 for grow effect + orb.targetSize = orb.size; + orb.size = 0.01f; // Start very small + orb.renderCurrentSize = 0.01f; + orb.prevRenderSize = 0.01f; + + // Clear motion while charging + orb.motionX = 0; + orb.motionY = 0; + orb.motionZ = 0; + + return orb; + } + + /** + * Start the orb moving (exit charging mode). + * Called by ability when windup ends. + */ + public void startMoving(EntityLivingBase target) { + if (!isCharging()) return; + + setCharging(false); + + // Update start position to current position + startX = posX; + startY = posY; + startZ = posZ; + + // Calculate velocity toward target + Entity owner = getOwner(); + + if (target != null) { + double dx = target.posX - posX; + double dy = (target.posY + target.height * 0.5) - posY; + double dz = target.posZ - posZ; + double len = Math.sqrt(dx * dx + dy * dy + dz * dz); + if (len > 0) { + motionX = (dx / len) * speed; + motionY = (dy / len) * speed; + motionZ = (dz / len) * speed; + } + } else if (owner != null) { + float yaw = (float) Math.toRadians(owner.rotationYaw); + float pitch = (float) Math.toRadians(owner.rotationPitch); + motionX = -Math.sin(yaw) * Math.cos(pitch) * speed; + motionY = -Math.sin(pitch) * speed; + motionZ = Math.cos(yaw) * Math.cos(pitch) * speed; + } + } + @Override protected void updateProjectile() { + // Handle charging state (windup phase) + if (isCharging()) { + updateCharging(); + return; + } + if (worldObj.isRemote) { handleClientInterpolation(); } else { @@ -207,6 +335,47 @@ public class EntityAbilityOrb extends EntityAbilityProjectile { } } + /** + * Update during charging state - follow owner based on anchor point. + */ + private void updateCharging() { + chargeTick++; + + Entity owner = getOwner(); + if (owner == null || owner.isDead) { + setDead(); + return; + } + + // Grow size based on charge progress + float progress = getChargeProgress(); + this.size = targetSize * progress; + + // Calculate position based on anchor point + if (owner instanceof EntityLivingBase) { + Vec3 pos = AnchorPointHelper.calculateAnchorPosition((EntityLivingBase) owner, anchorPoint); + setPosition(pos.xCoord, pos.yCoord, pos.zCoord); + } + } + + /** + * Get the charge progress (0-1). + */ + public float getChargeProgress() { + if (chargeDuration <= 0) return 1.0f; + return Math.min(1.0f, (float) chargeTick / chargeDuration); + } + + /** + * Get interpolated charge progress for smooth rendering. + */ + public float getInterpolatedChargeProgress(float partialTicks) { + if (chargeDuration <= 0) return 1.0f; + float prevProgress = Math.max(0, (float) (chargeTick - 1) / chargeDuration); + float currProgress = Math.min(1.0f, (float) chargeTick / chargeDuration); + return prevProgress + (currProgress - prevProgress) * partialTicks; + } + // ==================== GETTERS ==================== public float getSpeed() { @@ -238,6 +407,14 @@ public class EntityAbilityOrb extends EntityAbilityProjectile { this.homing = !nbt.hasKey("Homing") || nbt.getBoolean("Homing"); this.homingStrength = nbt.hasKey("HomingStrength") ? nbt.getFloat("HomingStrength") : 0.15f; this.homingRange = nbt.hasKey("HomingRange") ? nbt.getFloat("HomingRange") : 20.0f; + // Charging state + boolean isCharging = nbt.hasKey("Charging") && nbt.getBoolean("Charging"); + this.charging = isCharging; + this.dataWatcher.updateObject(DW_CHARGING, (byte) (isCharging ? 1 : 0)); + this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 40; + this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0; + this.anchorPoint = nbt.hasKey("AnchorPoint") ? AnchorPoint.fromId(nbt.getInteger("AnchorPoint")) : AnchorPoint.FRONT; + this.targetSize = nbt.hasKey("TargetSize") ? nbt.getFloat("TargetSize") : this.size; } @Override @@ -246,5 +423,11 @@ public class EntityAbilityOrb extends EntityAbilityProjectile { nbt.setBoolean("Homing", homing); nbt.setFloat("HomingStrength", homingStrength); nbt.setFloat("HomingRange", homingRange); + // Charging state + nbt.setBoolean("Charging", isCharging()); + nbt.setInteger("ChargeDuration", chargeDuration); + nbt.setInteger("ChargeTick", chargeTick); + nbt.setInteger("AnchorPoint", anchorPoint.getId()); + nbt.setFloat("TargetSize", targetSize); } } diff --git a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java new file mode 100644 index 000000000..7ad4dc581 --- /dev/null +++ b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java @@ -0,0 +1,303 @@ +package kamkeel.npcs.util; + +import kamkeel.npcs.controllers.data.ability.AnchorPoint; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.Vec3; +import noppes.npcs.constants.EnumAnimationPart; +import noppes.npcs.controllers.data.AnimationData; +import noppes.npcs.controllers.data.Frame; +import noppes.npcs.controllers.data.FramePart; +import noppes.npcs.entity.EntityNPCInterface; + +/** + * Utility class for calculating world positions based on anchor points. + * Used for positioning charging effects on different body parts. + * Animation-aware: reads arm positions from NPC animation data when available. + */ +public class AnchorPointHelper { + + // Model coordinate scale factor (model coords to blocks) + private static final float MODEL_SCALE = 0.0625f; // 1/16 + + // Default offsets (in blocks) + private static final float ARM_LATERAL_OFFSET = 0.35f; // ~5.5 pixels lateral from center + private static final float ARM_FORWARD_OFFSET = 0.25f; // Arm extended slightly forward + private static final float FRONT_OFFSET = 1.0f; // Distance in front for FRONT anchor + + // Height multipliers relative to eye height + private static final float FRONT_HEIGHT_MULT = 0.7f; + private static final float CENTER_HEIGHT_MULT = 0.5f; + private static final float ARM_HEIGHT_MULT = 0.75f; + private static final float ABOVE_HEAD_HEIGHT_MULT = 1.3f; + private static final float CHEST_HEIGHT_MULT = 0.5f; + + /** + * Calculate the world position for a given anchor point on an entity. + * + * @param entity The entity to calculate the anchor position for + * @param anchor The anchor point type + * @return Vec3 containing the world coordinates for the anchor point + */ + public static Vec3 calculateAnchorPosition(EntityLivingBase entity, AnchorPoint anchor) { + return calculateAnchorPosition(entity, anchor, FRONT_OFFSET); + } + + /** + * Calculate the world position for a given anchor point on an entity. + * For NPCs with active animations, this will read the actual arm positions. + * + * @param entity The entity to calculate the anchor position for + * @param anchor The anchor point type + * @param frontOffset Custom offset distance for FRONT anchor point + * @return Vec3 containing the world coordinates for the anchor point + */ + public static Vec3 calculateAnchorPosition(EntityLivingBase entity, AnchorPoint anchor, float frontOffset) { + double x = entity.posX; + double y = entity.posY; + double z = entity.posZ; + float eyeHeight = entity.getEyeHeight(); + + // Get yaw in radians (use body yaw for arm positioning, head yaw for facing) + float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); + float headYaw = (float) Math.toRadians(entity.rotationYawHead); + + switch (anchor) { + case FRONT: + // In front of entity face (use head yaw) + x -= Math.sin(headYaw) * frontOffset; + y += eyeHeight * FRONT_HEIGHT_MULT; + z += Math.cos(headYaw) * frontOffset; + break; + + case CENTER: + // Entity center + y += eyeHeight * CENTER_HEIGHT_MULT; + break; + + case RIGHT_HAND: + // Try to get animated arm position + Vec3 rightArmPos = getAnimatedArmPosition(entity, true); + if (rightArmPos != null) { + return rightArmPos; + } + // Fallback: calculated position using body yaw + x += calculateHandOffsetX(bodyYaw, true); + y += eyeHeight * ARM_HEIGHT_MULT; + z += calculateHandOffsetZ(bodyYaw, true); + break; + + case LEFT_HAND: + // Try to get animated arm position + Vec3 leftArmPos = getAnimatedArmPosition(entity, false); + if (leftArmPos != null) { + return leftArmPos; + } + // Fallback: calculated position using body yaw + x += calculateHandOffsetX(bodyYaw, false); + y += eyeHeight * ARM_HEIGHT_MULT; + z += calculateHandOffsetZ(bodyYaw, false); + break; + + case ABOVE_HEAD: + // Above the entity + y += eyeHeight * ABOVE_HEAD_HEIGHT_MULT; + break; + + case CHEST: + // Chest level, centered + y += eyeHeight * CHEST_HEIGHT_MULT; + break; + } + + return Vec3.createVectorHelper(x, y, z); + } + + /** + * Get the animated arm position from NPC animation data. + * Uses Minecraft's hand positioning logic from RenderNPCHumanMale. + * Hand offset values: (-0.0625, 0.4375, 0.0625) for right hand after arm postRender. + * + * @param entity The entity (must be EntityNPCInterface for animation support) + * @param rightArm True for right arm, false for left arm + * @return Vec3 world position if animation data available, null otherwise + */ + private static Vec3 getAnimatedArmPosition(EntityLivingBase entity, boolean rightArm) { + if (!(entity instanceof EntityNPCInterface)) { + return null; + } + + EntityNPCInterface npc = (EntityNPCInterface) entity; + AnimationData animData = npc.display.animationData; + + if (animData == null || !animData.isActive() || animData.animation == null) { + return null; + } + + Frame frame = (Frame) animData.animation.currentFrame(); + if (frame == null) { + return null; + } + + EnumAnimationPart armPart = rightArm ? EnumAnimationPart.RIGHT_ARM : EnumAnimationPart.LEFT_ARM; + if (!frame.frameParts.containsKey(armPart)) { + return null; + } + + FramePart part = frame.frameParts.get(armPart); + if (part == null) { + return null; + } + + // Ensure interpolation is up to date + part.interpolateOffset(); + part.interpolateAngles(); + + // Get body yaw for world rotation + float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); + + // === SHOULDER POSITION (model coordinates, in model units) === + // Right arm pivot: X = -5 (right side), Y = -2 (below head), Z = 0 + // Left arm pivot: X = 5 (left side), Y = -2, Z = 0 + // Note: In Minecraft model coords, Y=0 is at head level, shoulder is at Y=-2 + float shoulderModelX = rightArm ? -5.0f : 5.0f; + float shoulderModelY = -2.0f; + float shoulderModelZ = 0.0f; + + // Add animation pivot offsets (if any) + if (part.prevPivots != null) { + shoulderModelX += part.prevPivots[0]; + shoulderModelY += part.prevPivots[1]; + shoulderModelZ += part.prevPivots[2]; + } + + // === HAND OFFSET IN ARM'S LOCAL SPACE (from RenderNPCHumanMale) === + // These values are in blocks, applied AFTER postRender transforms + // Right: (-0.0625, 0.4375, 0.0625), Left: (0.0625, 0.4375, 0.0625) + float handLocalX = rightArm ? -0.0625f : 0.0625f; + float handLocalY = 0.4375f; // 7 model units down the arm + float handLocalZ = 0.0625f; // Slightly forward + + // === ARM ROTATION ANGLES === + float rotX = part.prevRotations != null ? part.prevRotations[0] : 0; + float rotY = part.prevRotations != null ? part.prevRotations[1] : 0; + float rotZ = part.prevRotations != null ? part.prevRotations[2] : 0; + + // === APPLY ARM ROTATIONS TO HAND OFFSET === + // Rotation order matches ModelRenderer.postRender: Z, Y, X + double hx = handLocalX; + double hy = handLocalY; + double hz = handLocalZ; + + // Rotate around Z axis + double cosZ = Math.cos(rotZ); + double sinZ = Math.sin(rotZ); + double tempX = hx * cosZ - hy * sinZ; + double tempY = hx * sinZ + hy * cosZ; + hx = tempX; + hy = tempY; + + // Rotate around Y axis + double cosY = Math.cos(rotY); + double sinY = Math.sin(rotY); + tempX = hx * cosY + hz * sinY; + double tempZ = -hx * sinY + hz * cosY; + hx = tempX; + hz = tempZ; + + // Rotate around X axis + double cosX = Math.cos(rotX); + double sinX = Math.sin(rotX); + tempY = hy * cosX - hz * sinX; + tempZ = hy * sinX + hz * cosX; + hy = tempY; + hz = tempZ; + + // === COMBINE SHOULDER + ROTATED HAND OFFSET === + // Convert shoulder from model units to blocks + double worldOffsetX = shoulderModelX * MODEL_SCALE + hx; + double worldOffsetY = shoulderModelY * MODEL_SCALE + hy; + double worldOffsetZ = shoulderModelZ * MODEL_SCALE + hz; + + // === ROTATE BY BODY YAW === + double cosYaw = Math.cos(bodyYaw); + double sinYaw = Math.sin(bodyYaw); + double rotatedX = worldOffsetX * cosYaw + worldOffsetZ * sinYaw; + double rotatedZ = -worldOffsetX * sinYaw + worldOffsetZ * cosYaw; + + // === FINAL WORLD POSITION === + // Entity posY is at feet, shoulder height is approximately eyeHeight * 0.9 + double shoulderWorldY = entity.posY + entity.getEyeHeight() * 0.9; + + double worldX = entity.posX + rotatedX; + double worldY = shoulderWorldY + worldOffsetY; + double worldZ = entity.posZ + rotatedZ; + + return Vec3.createVectorHelper(worldX, worldY, worldZ); + } + + /** + * Calculate the X offset for hand positions (fallback when no animation). + * + * @param yaw Entity's body yaw in radians + * @param rightHand True for right hand, false for left hand + * @return X offset in world coordinates + */ + private static double calculateHandOffsetX(float yaw, boolean rightHand) { + // Perpendicular direction (90 degrees from look direction) + // Right hand: +90 degrees, Left hand: -90 degrees + float perpYaw = yaw + (float) (rightHand ? Math.PI / 2 : -Math.PI / 2); + + // Lateral offset (perpendicular to look direction) + double lateralX = Math.sin(perpYaw) * ARM_LATERAL_OFFSET; + + // Forward offset (in look direction) + double forwardX = -Math.sin(yaw) * ARM_FORWARD_OFFSET; + + return lateralX + forwardX; + } + + /** + * Calculate the Z offset for hand positions (fallback when no animation). + * + * @param yaw Entity's body yaw in radians + * @param rightHand True for right hand, false for left hand + * @return Z offset in world coordinates + */ + private static double calculateHandOffsetZ(float yaw, boolean rightHand) { + // Perpendicular direction (90 degrees from look direction) + float perpYaw = yaw + (float) (rightHand ? Math.PI / 2 : -Math.PI / 2); + + // Lateral offset (perpendicular to look direction) + double lateralZ = -Math.cos(perpYaw) * ARM_LATERAL_OFFSET; + + // Forward offset (in look direction) + double forwardZ = Math.cos(yaw) * ARM_FORWARD_OFFSET; + + return lateralZ + forwardZ; + } + + /** + * Get the height multiplier for a given anchor point. + * Useful for external code that needs to know the Y position offset. + * + * @param anchor The anchor point type + * @return Height multiplier relative to eye height + */ + public static float getHeightMultiplier(AnchorPoint anchor) { + switch (anchor) { + case FRONT: + return FRONT_HEIGHT_MULT; + case CENTER: + return CENTER_HEIGHT_MULT; + case RIGHT_HAND: + case LEFT_HAND: + return ARM_HEIGHT_MULT; + case ABOVE_HEAD: + return ABOVE_HEAD_HEIGHT_MULT; + case CHEST: + return CHEST_HEIGHT_MULT; + default: + return FRONT_HEIGHT_MULT; + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java index 2a3439af1..33c5372fd 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java @@ -1,6 +1,7 @@ package noppes.npcs.client.gui.advanced.ability; import kamkeel.npcs.controllers.data.ability.AbilityEffect; +import kamkeel.npcs.controllers.data.ability.AnchorPoint; import kamkeel.npcs.controllers.data.ability.type.AbilityDisc; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -92,8 +93,11 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { y += 24; - // Row 7: Effects button - addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); + // Row 7: Max Lifetime + Effects button + addLabel(new GuiNpcLabel(112, "ability.lifetime", labelX, y + 5)); + addTextField(createIntField(112, fieldX, y, 50, disc.getMaxLifetime())); + + addButton(new GuiNpcButton(150, col2LabelX, y, 80, 20, "ability.effects")); } @Override @@ -104,7 +108,13 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 180; int col2FieldX = guiLeft + 260; - // Row 1: Inner Color + Outer Color + // Row 1: Anchor Point + addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5)); + addButton(new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), disc.getAnchorPoint().getId())); + + y += 24; + + // Row 2: Inner Color + Outer Color addLabel(new GuiNpcLabel(200, "ability.innerColor", labelX, y + 5)); String innerHex = String.format("%06X", disc.getInnerColor() & 0xFFFFFF); GuiNpcButton innerColorBtn = new GuiNpcButton(200, fieldX, y, 55, 20, innerHex); @@ -197,6 +207,9 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { disc.setLightningEffect(value == 1); initGui(); break; + case 210: + disc.setAnchorPoint(AnchorPoint.fromId(value)); + break; } } @@ -253,6 +266,9 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { case 111: disc.setMaxDistance(parseFloat(field, disc.getMaxDistance())); break; + case 112: + disc.setMaxLifetime(field.getInteger()); + break; } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java index 1c7179deb..626fac6b9 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java @@ -1,6 +1,7 @@ package noppes.npcs.client.gui.advanced.ability; import kamkeel.npcs.controllers.data.ability.AbilityEffect; +import kamkeel.npcs.controllers.data.ability.AnchorPoint; import kamkeel.npcs.controllers.data.ability.type.AbilityEnergyBeam; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -105,7 +106,13 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 180; int col2FieldX = guiLeft + 260; - // Row 1: Inner Color + Outer Color + // Row 1: Anchor Point + addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5)); + addButton(new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), beam.getAnchorPoint().getId())); + + y += 24; + + // Row 2: Inner Color + Outer Color addLabel(new GuiNpcLabel(200, "ability.innerColor", labelX, y + 5)); String innerHex = String.format("%06X", beam.getInnerColor() & 0xFFFFFF); GuiNpcButton innerColorBtn = new GuiNpcButton(200, fieldX, y, 55, 20, innerHex); @@ -195,6 +202,9 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { beam.setLightningEffect(value == 1); initGui(); break; + case 210: + beam.setAnchorPoint(AnchorPoint.fromId(value)); + break; } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java index 6c5c598ba..c43569c46 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java @@ -1,6 +1,7 @@ package noppes.npcs.client.gui.advanced.ability; import kamkeel.npcs.controllers.data.ability.AbilityEffect; +import kamkeel.npcs.controllers.data.ability.AnchorPoint; import kamkeel.npcs.controllers.data.ability.type.AbilityOrb; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; @@ -95,7 +96,13 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 180; int col2FieldX = guiLeft + 260; - // Row 1: Inner Color + Rotation Speed + // Row 1: Anchor Point + addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5)); + addButton(new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), orb.getAnchorPoint().getId())); + + y += 24; + + // Row 2: Inner Color + Rotation Speed addLabel(new GuiNpcLabel(200, "ability.innerColor", labelX, y + 5)); String innerHex = String.format("%06X", orb.getInnerColor() & 0xFFFFFF); GuiNpcButton innerColorBtn = new GuiNpcButton(200, fieldX, y, 55, 20, innerHex); @@ -185,6 +192,9 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { orb.setLightningEffect(value == 1); initGui(); break; + case 210: + orb.setAnchorPoint(AnchorPoint.fromId(value)); + break; } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index d5dc945ce..01e3ae541 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1683,6 +1683,7 @@ ability.outerWidth=Outer Width ability.lightning=Enable Lightning ability.lightningDensity=Density ability.lightningRadius=Radius +ability.anchorPoint=Anchor Point ability.noVisualSettings=No visual settings for this ability type # Laser Shot Settings From 39b53b0be7424507bbc99c775aefa0450c160285 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 27 Jan 2026 02:03:54 -0500 Subject: [PATCH 09/15] Anchor Points --- .../kamkeel/npcs/util/AnchorPointHelper.java | 256 ++++++++---------- 1 file changed, 115 insertions(+), 141 deletions(-) diff --git a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java index 7ad4dc581..5a7e32d28 100644 --- a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java +++ b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java @@ -16,13 +16,32 @@ import noppes.npcs.entity.EntityNPCInterface; */ public class AnchorPointHelper { - // Model coordinate scale factor (model coords to blocks) - private static final float MODEL_SCALE = 0.0625f; // 1/16 + // ==================== TUNABLE CONSTANTS ==================== + // These can be adjusted to fine-tune positioning - // Default offsets (in blocks) - private static final float ARM_LATERAL_OFFSET = 0.35f; // ~5.5 pixels lateral from center - private static final float ARM_FORWARD_OFFSET = 0.25f; // Arm extended slightly forward - private static final float FRONT_OFFSET = 1.0f; // Distance in front for FRONT anchor + // Shoulder position in model units (default biped arm rotation points) + private static final float SHOULDER_X_RIGHT = -5.0f; // Right arm is on the right side (-X in model space) + private static final float SHOULDER_X_LEFT = 5.0f; // Left arm is on the left side (+X in model space) + private static final float SHOULDER_Y = 2.0f; // Shoulder height from model origin + private static final float SHOULDER_Z = 0.0f; // Shoulder depth + + // Hand offset in model units (where items are held, relative to shoulder after rotation) + // In arm's local space: X = toward/away from body, Y = down the arm, Z = forward/back + private static float HAND_OFFSET_X_RIGHT = -2.0f; // Slightly toward body for right + private static float HAND_OFFSET_X_LEFT = 2.0f; // Slightly toward body for left + private static float HAND_OFFSET_Y = 14.0f; // Down the arm (arm is ~12 units long) + private static float HAND_OFFSET_Z = 0.0f; // Forward from arm + + // Height of shoulder relative to entity position (feet) + private static final float SHOULDER_HEIGHT_BLOCKS = 1.35f; + + // Model scale factor (1/16 - converts model units to blocks) + private static final float MODEL_SCALE = 0.0625f; + + // Fallback offsets (in blocks) when no animation + private static final float ARM_LATERAL_OFFSET = 0.35f; + private static final float ARM_FORWARD_OFFSET = 0.3f; + private static final float FRONT_OFFSET = 1.0f; // Height multipliers relative to eye height private static final float FRONT_HEIGHT_MULT = 0.7f; @@ -33,10 +52,6 @@ public class AnchorPointHelper { /** * Calculate the world position for a given anchor point on an entity. - * - * @param entity The entity to calculate the anchor position for - * @param anchor The anchor point type - * @return Vec3 containing the world coordinates for the anchor point */ public static Vec3 calculateAnchorPosition(EntityLivingBase entity, AnchorPoint anchor) { return calculateAnchorPosition(entity, anchor, FRONT_OFFSET); @@ -44,12 +59,6 @@ public class AnchorPointHelper { /** * Calculate the world position for a given anchor point on an entity. - * For NPCs with active animations, this will read the actual arm positions. - * - * @param entity The entity to calculate the anchor position for - * @param anchor The anchor point type - * @param frontOffset Custom offset distance for FRONT anchor point - * @return Vec3 containing the world coordinates for the anchor point */ public static Vec3 calculateAnchorPosition(EntityLivingBase entity, AnchorPoint anchor, float frontOffset) { double x = entity.posX; @@ -57,54 +66,44 @@ public class AnchorPointHelper { double z = entity.posZ; float eyeHeight = entity.getEyeHeight(); - // Get yaw in radians (use body yaw for arm positioning, head yaw for facing) - float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); - float headYaw = (float) Math.toRadians(entity.rotationYawHead); + // Body yaw in radians (used for arm positioning) + // Minecraft: yaw 0 = south (+Z), 90 = west (-X), 180 = north (-Z), 270 = east (+X) + float bodyYawRad = (float) Math.toRadians(entity.renderYawOffset); + float headYawRad = (float) Math.toRadians(entity.rotationYawHead); switch (anchor) { case FRONT: // In front of entity face (use head yaw) - x -= Math.sin(headYaw) * frontOffset; + x -= Math.sin(headYawRad) * frontOffset; y += eyeHeight * FRONT_HEIGHT_MULT; - z += Math.cos(headYaw) * frontOffset; + z += Math.cos(headYawRad) * frontOffset; break; case CENTER: - // Entity center y += eyeHeight * CENTER_HEIGHT_MULT; break; case RIGHT_HAND: - // Try to get animated arm position - Vec3 rightArmPos = getAnimatedArmPosition(entity, true); - if (rightArmPos != null) { - return rightArmPos; + Vec3 rightPos = getAnimatedHandPosition(entity, true); + if (rightPos != null) { + return rightPos; } - // Fallback: calculated position using body yaw - x += calculateHandOffsetX(bodyYaw, true); - y += eyeHeight * ARM_HEIGHT_MULT; - z += calculateHandOffsetZ(bodyYaw, true); - break; + // Fallback + return calculateFallbackHandPosition(entity, bodyYawRad, true); case LEFT_HAND: - // Try to get animated arm position - Vec3 leftArmPos = getAnimatedArmPosition(entity, false); - if (leftArmPos != null) { - return leftArmPos; + Vec3 leftPos = getAnimatedHandPosition(entity, false); + if (leftPos != null) { + return leftPos; } - // Fallback: calculated position using body yaw - x += calculateHandOffsetX(bodyYaw, false); - y += eyeHeight * ARM_HEIGHT_MULT; - z += calculateHandOffsetZ(bodyYaw, false); - break; + // Fallback + return calculateFallbackHandPosition(entity, bodyYawRad, false); case ABOVE_HEAD: - // Above the entity y += eyeHeight * ABOVE_HEAD_HEIGHT_MULT; break; case CHEST: - // Chest level, centered y += eyeHeight * CHEST_HEIGHT_MULT; break; } @@ -113,15 +112,10 @@ public class AnchorPointHelper { } /** - * Get the animated arm position from NPC animation data. - * Uses Minecraft's hand positioning logic from RenderNPCHumanMale. - * Hand offset values: (-0.0625, 0.4375, 0.0625) for right hand after arm postRender. - * - * @param entity The entity (must be EntityNPCInterface for animation support) - * @param rightArm True for right arm, false for left arm - * @return Vec3 world position if animation data available, null otherwise + * Calculate hand position using NPC animation data. + * Uses the same transformation logic as the renderer. */ - private static Vec3 getAnimatedArmPosition(EntityLivingBase entity, boolean rightArm) { + private static Vec3 getAnimatedHandPosition(EntityLivingBase entity, boolean rightArm) { if (!(entity instanceof EntityNPCInterface)) { return null; } @@ -152,136 +146,116 @@ public class AnchorPointHelper { part.interpolateOffset(); part.interpolateAngles(); - // Get body yaw for world rotation - float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); + // === STEP 1: Get shoulder position in model space === + float shoulderX = rightArm ? SHOULDER_X_RIGHT : SHOULDER_X_LEFT; + float shoulderY = SHOULDER_Y; + float shoulderZ = SHOULDER_Z; - // === SHOULDER POSITION (model coordinates, in model units) === - // Right arm pivot: X = -5 (right side), Y = -2 (below head), Z = 0 - // Left arm pivot: X = 5 (left side), Y = -2, Z = 0 - // Note: In Minecraft model coords, Y=0 is at head level, shoulder is at Y=-2 - float shoulderModelX = rightArm ? -5.0f : 5.0f; - float shoulderModelY = -2.0f; - float shoulderModelZ = 0.0f; - - // Add animation pivot offsets (if any) + // Add animation pivot offsets if (part.prevPivots != null) { - shoulderModelX += part.prevPivots[0]; - shoulderModelY += part.prevPivots[1]; - shoulderModelZ += part.prevPivots[2]; + shoulderX += part.prevPivots[0]; + shoulderY += part.prevPivots[1]; + shoulderZ += part.prevPivots[2]; } - // === HAND OFFSET IN ARM'S LOCAL SPACE (from RenderNPCHumanMale) === - // These values are in blocks, applied AFTER postRender transforms - // Right: (-0.0625, 0.4375, 0.0625), Left: (0.0625, 0.4375, 0.0625) - float handLocalX = rightArm ? -0.0625f : 0.0625f; - float handLocalY = 0.4375f; // 7 model units down the arm - float handLocalZ = 0.0625f; // Slightly forward + // === STEP 2: Get hand offset in arm's local space === + float handX = rightArm ? HAND_OFFSET_X_RIGHT : HAND_OFFSET_X_LEFT; + float handY = HAND_OFFSET_Y; + float handZ = HAND_OFFSET_Z; - // === ARM ROTATION ANGLES === + // === STEP 3: Apply arm rotations to hand offset (Z → Y → X order) === + // Rotations are in radians (already converted by interpolateAngles) float rotX = part.prevRotations != null ? part.prevRotations[0] : 0; float rotY = part.prevRotations != null ? part.prevRotations[1] : 0; float rotZ = part.prevRotations != null ? part.prevRotations[2] : 0; - // === APPLY ARM ROTATIONS TO HAND OFFSET === - // Rotation order matches ModelRenderer.postRender: Z, Y, X - double hx = handLocalX; - double hy = handLocalY; - double hz = handLocalZ; + // Start with hand offset + double hx = handX; + double hy = handY; + double hz = handZ; - // Rotate around Z axis + // Apply Z rotation first double cosZ = Math.cos(rotZ); double sinZ = Math.sin(rotZ); - double tempX = hx * cosZ - hy * sinZ; - double tempY = hx * sinZ + hy * cosZ; - hx = tempX; - hy = tempY; + double newX = hx * cosZ - hy * sinZ; + double newY = hx * sinZ + hy * cosZ; + hx = newX; + hy = newY; - // Rotate around Y axis + // Apply Y rotation double cosY = Math.cos(rotY); double sinY = Math.sin(rotY); - tempX = hx * cosY + hz * sinY; - double tempZ = -hx * sinY + hz * cosY; - hx = tempX; - hz = tempZ; + newX = hx * cosY + hz * sinY; + double newZ = -hx * sinY + hz * cosY; + hx = newX; + hz = newZ; - // Rotate around X axis + // Apply X rotation double cosX = Math.cos(rotX); double sinX = Math.sin(rotX); - tempY = hy * cosX - hz * sinX; - tempZ = hy * sinX + hz * cosX; - hy = tempY; - hz = tempZ; + newY = hy * cosX - hz * sinX; + newZ = hy * sinX + hz * cosX; + hy = newY; + hz = newZ; - // === COMBINE SHOULDER + ROTATED HAND OFFSET === - // Convert shoulder from model units to blocks - double worldOffsetX = shoulderModelX * MODEL_SCALE + hx; - double worldOffsetY = shoulderModelY * MODEL_SCALE + hy; - double worldOffsetZ = shoulderModelZ * MODEL_SCALE + hz; + // === STEP 4: Combine shoulder + rotated hand offset (in model units) === + double modelX = shoulderX + hx; + double modelY = shoulderY + hy; + double modelZ = shoulderZ + hz; - // === ROTATE BY BODY YAW === + // === STEP 5: Convert to blocks === + double blockX = modelX * MODEL_SCALE; + double blockY = modelY * MODEL_SCALE; + double blockZ = modelZ * MODEL_SCALE; + + // === STEP 6: Apply body yaw rotation === + // In model space: +X = left, -X = right, +Z = back, -Z = front + // Need to rotate to align with entity's facing direction + float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); double cosYaw = Math.cos(bodyYaw); double sinYaw = Math.sin(bodyYaw); - double rotatedX = worldOffsetX * cosYaw + worldOffsetZ * sinYaw; - double rotatedZ = -worldOffsetX * sinYaw + worldOffsetZ * cosYaw; - // === FINAL WORLD POSITION === - // Entity posY is at feet, shoulder height is approximately eyeHeight * 0.9 - double shoulderWorldY = entity.posY + entity.getEyeHeight() * 0.9; + // Rotate around Y axis (body rotation) + double worldOffsetX = blockX * cosYaw + blockZ * sinYaw; + double worldOffsetZ = -blockX * sinYaw + blockZ * cosYaw; - double worldX = entity.posX + rotatedX; - double worldY = shoulderWorldY + worldOffsetY; - double worldZ = entity.posZ + rotatedZ; + // === STEP 7: Final world position === + double worldX = entity.posX + worldOffsetX; + double worldY = entity.posY + SHOULDER_HEIGHT_BLOCKS - blockY; // Subtract because +Y in model is down + double worldZ = entity.posZ + worldOffsetZ; return Vec3.createVectorHelper(worldX, worldY, worldZ); } /** - * Calculate the X offset for hand positions (fallback when no animation). - * - * @param yaw Entity's body yaw in radians - * @param rightHand True for right hand, false for left hand - * @return X offset in world coordinates + * Calculate fallback hand position when no animation is active. */ - private static double calculateHandOffsetX(float yaw, boolean rightHand) { - // Perpendicular direction (90 degrees from look direction) - // Right hand: +90 degrees, Left hand: -90 degrees - float perpYaw = yaw + (float) (rightHand ? Math.PI / 2 : -Math.PI / 2); + private static Vec3 calculateFallbackHandPosition(EntityLivingBase entity, float bodyYawRad, boolean rightHand) { + double x = entity.posX; + double y = entity.posY; + double z = entity.posZ; + float eyeHeight = entity.getEyeHeight(); - // Lateral offset (perpendicular to look direction) - double lateralX = Math.sin(perpYaw) * ARM_LATERAL_OFFSET; + // Perpendicular direction for lateral offset + float perpYaw = bodyYawRad + (float) (rightHand ? Math.PI / 2 : -Math.PI / 2); - // Forward offset (in look direction) - double forwardX = -Math.sin(yaw) * ARM_FORWARD_OFFSET; + // Lateral offset (perpendicular to body facing) + double lateralX = -Math.sin(perpYaw) * ARM_LATERAL_OFFSET; + double lateralZ = Math.cos(perpYaw) * ARM_LATERAL_OFFSET; - return lateralX + forwardX; - } + // Forward offset (in facing direction) + double forwardX = -Math.sin(bodyYawRad) * ARM_FORWARD_OFFSET; + double forwardZ = Math.cos(bodyYawRad) * ARM_FORWARD_OFFSET; - /** - * Calculate the Z offset for hand positions (fallback when no animation). - * - * @param yaw Entity's body yaw in radians - * @param rightHand True for right hand, false for left hand - * @return Z offset in world coordinates - */ - private static double calculateHandOffsetZ(float yaw, boolean rightHand) { - // Perpendicular direction (90 degrees from look direction) - float perpYaw = yaw + (float) (rightHand ? Math.PI / 2 : -Math.PI / 2); + x += lateralX + forwardX; + y += eyeHeight * ARM_HEIGHT_MULT; + z += lateralZ + forwardZ; - // Lateral offset (perpendicular to look direction) - double lateralZ = -Math.cos(perpYaw) * ARM_LATERAL_OFFSET; - - // Forward offset (in look direction) - double forwardZ = Math.cos(yaw) * ARM_FORWARD_OFFSET; - - return lateralZ + forwardZ; + return Vec3.createVectorHelper(x, y, z); } /** * Get the height multiplier for a given anchor point. - * Useful for external code that needs to know the Y position offset. - * - * @param anchor The anchor point type - * @return Height multiplier relative to eye height */ public static float getHeightMultiplier(AnchorPoint anchor) { switch (anchor) { From 93486d306b86795d9f66a363a5234e40be6be2d0 Mon Sep 17 00:00:00 2001 From: Vidal Date: Tue, 27 Jan 2026 04:36:12 -0300 Subject: [PATCH 10/15] Made animation fetching methods return Animation instead of IDs --- .../controllers/data/ability/Ability.java | 14 +++++++--- src/main/java/noppes/npcs/DataAbilities.java | 27 +++++++++++-------- .../gui/advanced/SubGuiAbilityConfig.java | 4 +-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java index d7a8b9eab..02d2227ad 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -17,6 +17,8 @@ import noppes.npcs.api.INbt; import noppes.npcs.api.ability.IAbility; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.util.IAbilityConfigCallback; +import noppes.npcs.controllers.AnimationController; +import noppes.npcs.controllers.data.Animation; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.AbilityEvent; @@ -927,16 +929,20 @@ public abstract class Ability implements IAbility { this.activeSound = activeSound; } - public int getWindUpAnimationId() { - return windUpAnimationId; + public Animation getWindUpAnimation() { + if (AnimationController.Instance == null) return null; + + return (Animation) AnimationController.Instance.get(windUpAnimationId); } public void setWindUpAnimationId(int windUpAnimationId) { this.windUpAnimationId = windUpAnimationId; } - public int getActiveAnimationId() { - return activeAnimationId; + public Animation getActiveAnimation() { + if (AnimationController.Instance == null) return null; + + return (Animation) AnimationController.Instance.get(activeAnimationId); } public void setActiveAnimationId(int activeAnimationId) { diff --git a/src/main/java/noppes/npcs/DataAbilities.java b/src/main/java/noppes/npcs/DataAbilities.java index 246ebed46..a9c670647 100644 --- a/src/main/java/noppes/npcs/DataAbilities.java +++ b/src/main/java/noppes/npcs/DataAbilities.java @@ -154,7 +154,7 @@ public class DataAbilities { // Play active sound and animation playAbilitySound(currentAbility.getActiveSound()); - playAbilityAnimation(currentAbility.getActiveAnimationId()); + playAbilityAnimation(currentAbility.getActiveAnimation()); // Fire execute event (cancelable) AbilityEvent.ExecuteEvent executeEvent = new AbilityEvent.ExecuteEvent( @@ -359,7 +359,7 @@ public class DataAbilities { playAbilitySound(ability.getWindUpSound()); // Play wind up animation if configured - playAbilityAnimation(ability.getWindUpAnimationId()); + playAbilityAnimation(ability.getWindUpAnimation()); return true; } @@ -377,18 +377,23 @@ public class DataAbilities { * Play an animation on the NPC by ID. * Public so abilities can trigger animations directly if needed. * - * @param animationId The global animation ID to play, or -1 for none + * @param animation The animation to play, or null if none */ - public void playAbilityAnimation(int animationId) { - if (animationId < 0) return; + public void playAbilityAnimation(Animation animation) { + if (animation == null || animation.id < 0) return; if (AnimationController.Instance == null) return; - Animation animation = AnimationController.Instance.animations.get(animationId); - if (animation != null) { - npc.display.animationData.setEnabled(true); - npc.display.animationData.setAnimation(animation); - npc.display.animationData.updateClient(); - } + npc.display.animationData.setEnabled(true); + npc.display.animationData.setAnimation(animation); + npc.display.animationData.updateClient(); + } + + public void playAbilityAnimation(int animation) { + if (animation < 0) return; + if (AnimationController.Instance == null) return; + if (AnimationController.Instance.get(animation) == null) return; + + playAbilityAnimation((Animation) AnimationController.Instance.get(animation)); } /** diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java index 5f03cbd9f..6c5323707 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java @@ -127,8 +127,8 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi // Effects this.windUpSound = ability.getWindUpSound(); this.activeSound = ability.getActiveSound(); - this.windUpAnimationId = ability.getWindUpAnimationId(); - this.activeAnimationId = ability.getActiveAnimationId(); + this.windUpAnimationId = ability.getWindUpAnimation() != null ? ability.getWindUpAnimation().getID() : -1; + this.activeAnimationId = ability.getActiveAnimation() != null ? ability.getActiveAnimation().getID() : -1; // Telegraph this.showTelegraph = ability.isShowTelegraph(); From 747aae833749e346bd4bb8fa6151eb9272047f89 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 27 Jan 2026 04:07:02 -0500 Subject: [PATCH 11/15] Recovery -> Dazed. Better cooldown logic handling --- .../kamkeel/npcs/command/AbilityCommand.java | 5 +- .../controllers/data/ability/Ability.java | 89 ++--- .../data/ability/AbilityAnimation.java | 6 +- .../data/ability/AbilityPhase.java | 2 +- .../data/ability/type/AbilityCharge.java | 6 +- .../data/ability/type/AbilityCutter.java | 20 +- .../data/ability/type/AbilityDash.java | 6 +- .../data/ability/type/AbilityDisc.java | 46 ++- .../data/ability/type/AbilityEnergyBeam.java | 46 ++- .../data/ability/type/AbilityGuard.java | 20 +- .../data/ability/type/AbilityHazard.java | 21 +- .../data/ability/type/AbilityHeal.java | 31 +- .../data/ability/type/AbilityHeavyHit.java | 12 +- .../data/ability/type/AbilityLaserShot.java | 13 +- .../data/ability/type/AbilityOrb.java | 46 ++- .../data/ability/type/AbilityProjectile.java | 7 +- .../data/ability/type/AbilityShockwave.java | 27 +- .../data/ability/type/AbilitySlam.java | 5 +- .../data/ability/type/AbilitySweeper.java | 46 ++- .../data/ability/type/AbilityTeleport.java | 14 +- .../data/ability/type/AbilityTrap.java | 22 +- .../data/ability/type/AbilityVortex.java | 6 +- .../kamkeel/npcs/util/AnchorPointHelper.java | 317 ++++++++++-------- src/main/java/noppes/npcs/DataAbilities.java | 51 +-- .../gui/advanced/SubGuiAbilityConfig.java | 47 +-- .../advanced/ability/SubGuiAbilityCutter.java | 15 +- .../advanced/ability/SubGuiAbilityGuard.java | 14 +- .../advanced/ability/SubGuiAbilityHazard.java | 23 +- .../advanced/ability/SubGuiAbilityHeal.java | 26 +- .../advanced/ability/SubGuiAbilityTrap.java | 23 +- 30 files changed, 577 insertions(+), 435 deletions(-) diff --git a/src/main/java/kamkeel/npcs/command/AbilityCommand.java b/src/main/java/kamkeel/npcs/command/AbilityCommand.java index 4a783f551..cf5e1ca58 100644 --- a/src/main/java/kamkeel/npcs/command/AbilityCommand.java +++ b/src/main/java/kamkeel/npcs/command/AbilityCommand.java @@ -119,8 +119,9 @@ public class AbilityCommand extends CommandKamkeelBase { sendResult(sender, " Type: \u00A7d" + ability.getTypeId()); sendResult(sender, " Cooldown: \u00A7e" + ability.getCooldownTicks() + " ticks"); sendResult(sender, " Wind Up: \u00A7e" + ability.getWindUpTicks() + " ticks"); - sendResult(sender, " Active: \u00A7e" + ability.getActiveTicks() + " ticks"); - sendResult(sender, " Recovery: \u00A7e" + ability.getRecoveryTicks() + " ticks"); + if (ability.isInterruptible()) { + sendResult(sender, " Dazed: \u00A7e" + ability.getDazedTicks() + " ticks"); + } sendResult(sender, " Range: \u00A7e" + ability.getMinRange() + " - " + ability.getMaxRange()); sendResult(sender, " Telegraph: \u00A7e" + (ability.isShowTelegraph() ? "Yes" : "No")); } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java index 02d2227ad..e5dc7e493 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -47,18 +47,13 @@ public abstract class Ability implements IAbility { protected float maxRange = 20; // Timing (ticks) - protected int cooldownTicks = 100; + protected int cooldownTicks = 0; // Added to global cooldown after ability completes protected int windUpTicks = 20; - protected int activeTicks = 10; - protected int recoveryTicks = 20; + protected int dazedTicks = 80; // Only used when interrupted during WINDUP (if interruptible) // Interruption protected boolean interruptible = true; - // Wait for completion - if true, ability controls when active phase ends (ignores activeTicks) - // Used for abilities like Slam that need to wait for landing, or Beam that runs until entity dies - protected boolean waitForCompletion = false; - // Feedback protected boolean lockMovement = true; protected int windUpColor = 0x80FF4400; // Telegraph color during wind up @@ -507,11 +502,8 @@ public abstract class Ability implements IAbility { /** * Tick the ability forward. Called every game tick while executing. *

- * Normal flow: WINDUP -> ACTIVE -> IDLE (no recovery in normal completion) - * Interrupted flow: WINDUP -> RECOVERY -> IDLE (recovery only on interrupt) - *

- * If waitForCompletion is true, the ability controls when active ends - * by calling signalCompletion() instead of using activeTicks. + * Normal flow: WINDUP -> ACTIVE -> IDLE + * Interrupted flow: WINDUP -> DAZED -> IDLE (dazed only on interrupt during WINDUP) * * @return true if phase changed this tick */ @@ -529,18 +521,13 @@ public abstract class Ability implements IAbility { } break; case ACTIVE: - // If waitForCompletion is true, ability must call signalCompletion() - // Otherwise, auto-complete when activeTicks is reached - if (!waitForCompletion && currentTick >= activeTicks) { - phase = AbilityPhase.IDLE; - currentTick = 0; - return true; - } + // Abilities control their own completion by calling signalCompletion() + // No auto-complete - each ability determines when it's done break; - case RECOVERY: - // Recovery phase is only entered on interrupt - // Count down recoveryTicks then go to IDLE - if (currentTick >= recoveryTicks) { + case DAZED: + // Dazed phase is only entered on interrupt during WINDUP + // NPC cannot attack during this time + if (currentTick >= dazedTicks) { phase = AbilityPhase.IDLE; currentTick = 0; return true; @@ -552,13 +539,14 @@ public abstract class Ability implements IAbility { /** * Signal that the ability has completed its active phase. - * Called by abilities with waitForCompletion=true when they are done. + * Called by abilities when they are done. * For example, AbilitySlam calls this when the NPC lands. * * @return true if phase changed to IDLE */ public boolean signalCompletion() { if (phase == AbilityPhase.ACTIVE) { + cleanup(); phase = AbilityPhase.IDLE; currentTick = 0; return true; @@ -567,13 +555,14 @@ public abstract class Ability implements IAbility { } /** - * Interrupt this ability. Transitions to RECOVERY phase if interruptible. + * Interrupt this ability. Transitions to DAZED phase if interruptible during WINDUP. * Called when NPC takes direct damage during WINDUP. */ public void interrupt() { + cleanup(); if (interruptible && phase == AbilityPhase.WINDUP) { - // Interrupted during windup - go to recovery (dazed state) - phase = AbilityPhase.RECOVERY; + // Interrupted during windup - go to dazed state + phase = AbilityPhase.DAZED; currentTick = 0; } else { // Force stop - go directly to IDLE @@ -624,15 +613,25 @@ public abstract class Ability implements IAbility { } /** - * Reset all execution state (called on combat end) + * Reset all execution state (called on combat end, NPC death, target lost, etc.) */ public void reset() { + cleanup(); phase = AbilityPhase.IDLE; currentTick = 0; currentTarget = null; telegraphInstance = null; } + /** + * Cleanup any resources created by this ability. + * Override this to kill spawned entities, cancel telegraphs, etc. + * Called when ability ends for any reason (completion, interrupt, reset, NPC death). + */ + public void cleanup() { + // Override in subclasses to clean up spawned entities, etc. + } + // ═══════════════════════════════════════════════════════════════════ // CONDITION CHECKING // ═══════════════════════════════════════════════════════════════════ @@ -661,10 +660,8 @@ public abstract class Ability implements IAbility { nbt.setFloat("maxRange", maxRange); nbt.setInteger("cooldown", cooldownTicks); nbt.setInteger("windUp", windUpTicks); - nbt.setInteger("active", activeTicks); - nbt.setInteger("recovery", recoveryTicks); + nbt.setInteger("recovery", dazedTicks); nbt.setBoolean("interruptible", interruptible); - nbt.setBoolean("waitForCompletion", waitForCompletion); nbt.setBoolean("lockMovement", lockMovement); nbt.setInteger("windUpColor", windUpColor); nbt.setInteger("activeColor", activeColor); @@ -708,10 +705,8 @@ public abstract class Ability implements IAbility { maxRange = nbt.getFloat("maxRange"); cooldownTicks = nbt.getInteger("cooldown"); windUpTicks = nbt.getInteger("windUp"); - activeTicks = nbt.getInteger("active"); - recoveryTicks = nbt.getInteger("recovery"); + dazedTicks = nbt.getInteger("recovery"); interruptible = nbt.getBoolean("interruptible"); - waitForCompletion = nbt.getBoolean("waitForCompletion"); lockMovement = nbt.getBoolean("lockMovement"); // Support old telegraphColor key for backwards compatibility if (nbt.hasKey("windUpColor")) { @@ -857,20 +852,12 @@ public abstract class Ability implements IAbility { this.windUpTicks = Math.max(0, windUpTicks); } - public int getActiveTicks() { - return activeTicks; + public int getDazedTicks() { + return dazedTicks; } - public void setActiveTicks(int activeTicks) { - this.activeTicks = Math.max(1, activeTicks); - } - - public int getRecoveryTicks() { - return recoveryTicks; - } - - public void setRecoveryTicks(int recoveryTicks) { - this.recoveryTicks = Math.max(0, recoveryTicks); + public void setDazedTicks(int dazedTicks) { + this.dazedTicks = Math.max(0, dazedTicks); } public boolean isInterruptible() { @@ -881,14 +868,6 @@ public abstract class Ability implements IAbility { this.interruptible = interruptible; } - public boolean isWaitForCompletion() { - return waitForCompletion; - } - - public void setWaitForCompletion(boolean waitForCompletion) { - this.waitForCompletion = waitForCompletion; - } - public boolean isLockMovement() { return lockMovement; } @@ -978,7 +957,7 @@ public abstract class Ability implements IAbility { } /** - * Get the current execution phase as int (0=IDLE, 1=WINDUP, 2=ACTIVE, 3=RECOVERY). + * Get the current execution phase as int (0=IDLE, 1=WINDUP, 2=ACTIVE, 3=DAZED). * Required for IAbility interface. */ @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java index 4b7f2ba3e..3aea051f3 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityAnimation.java @@ -20,7 +20,7 @@ public enum AbilityAnimation {; animationNames.put(IDLE, idle); animationNames.put(WINDUP, windUp); animationNames.put(ACTIVE, active); - animationNames.put(RECOVERY, recovery); + animationNames.put(DAZED, recovery); } AbilityAnimation(String idle, String windUp, String active) { @@ -80,8 +80,8 @@ public enum AbilityAnimation {; return getAnimation(ACTIVE); } - public IAnimation recovery() { - return getAnimation(RECOVERY); + public IAnimation dazed() { + return getAnimation(DAZED); } private File getFileFromName(String fileName) { diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityPhase.java b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityPhase.java index 6338279ba..0611a0274 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityPhase.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/AbilityPhase.java @@ -4,5 +4,5 @@ public enum AbilityPhase { IDLE, // Not executing WINDUP, // Charging up (telegraph visible) ACTIVE, // Executing (damage happens) - RECOVERY // Finishing animation + DAZED // Stunned after interrupt during WINDUP (cannot attack) } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java index 696367ce8..7a1d9babf 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java @@ -46,10 +46,8 @@ public class AbilityCharge extends Ability { this.maxRange = 20.0f; this.minRange = 4.0f; this.lockMovement = false; // Movement IS the ability - this.cooldownTicks = 80; + this.cooldownTicks = 0; this.windUpTicks = 20; - this.activeTicks = 40; - this.recoveryTicks = 10; // LINE telegraph showing charge path this.telegraphType = TelegraphType.LINE; this.showTelegraph = true; @@ -161,11 +159,13 @@ public class AbilityCharge extends Ability { npc.motionX = 0; npc.motionZ = 0; npc.velocityChanged = true; + signalCompletion(); return; } if (isChargeBlocked(npc)) { stopMomentum(npc); + signalCompletion(); return; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java index 8274b4d79..b3052eeac 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCutter.java @@ -38,6 +38,7 @@ public class AbilityCutter extends Ability { private SweepMode sweepMode = SweepMode.SWIPE; private float sweepSpeed = 6.0f; + private int spinDurationTicks = 60; // Duration for SPIN mode private boolean piercing = true; private float innerRadius = 0.0f; @@ -52,10 +53,8 @@ public class AbilityCutter extends Ability { this.targetingMode = TargetingMode.AOE_SELF; this.maxRange = 8.0f; this.lockMovement = true; - this.cooldownTicks = 80; + this.cooldownTicks = 0; this.windUpTicks = 20; - this.activeTicks = 15; - this.recoveryTicks = 15; this.telegraphType = TelegraphType.CONE; this.windUpSound = "random.bow"; this.activeSound = "random.break"; @@ -110,6 +109,7 @@ public class AbilityCutter extends Ability { switch (sweepMode) { case SWIPE: if (currentRotation > arcAngle / 2.0f) { + signalCompletion(); // Swipe arc complete return; } performSweepDamage(npc, world, innerRadius, range, currentRotation); @@ -117,6 +117,10 @@ public class AbilityCutter extends Ability { break; case SPIN: + if (tick >= spinDurationTicks) { + signalCompletion(); // Spin duration complete + return; + } currentRotation = (currentRotation + sweepSpeed) % 360.0f; hitEntities.clear(); performSweepDamage(npc, world, innerRadius, range, currentRotation); @@ -195,6 +199,7 @@ public class AbilityCutter extends Ability { nbt.setFloat("knockback", knockback); nbt.setString("sweepMode", sweepMode.name()); nbt.setFloat("sweepSpeed", sweepSpeed); + nbt.setInteger("spinDurationTicks", spinDurationTicks); nbt.setBoolean("piercing", piercing); nbt.setFloat("innerRadius", innerRadius); } @@ -211,6 +216,7 @@ public class AbilityCutter extends Ability { this.sweepMode = SweepMode.SWIPE; } this.sweepSpeed = nbt.hasKey("sweepSpeed") ? nbt.getFloat("sweepSpeed") : 6.0f; + this.spinDurationTicks = nbt.hasKey("spinDurationTicks") ? nbt.getInteger("spinDurationTicks") : 60; this.piercing = !nbt.hasKey("piercing") || nbt.getBoolean("piercing"); this.innerRadius = nbt.hasKey("innerRadius") ? nbt.getFloat("innerRadius") : 0.0f; } @@ -264,6 +270,14 @@ public class AbilityCutter extends Ability { this.sweepSpeed = sweepSpeed; } + public int getSpinDurationTicks() { + return spinDurationTicks; + } + + public void setSpinDurationTicks(int spinDurationTicks) { + this.spinDurationTicks = Math.max(1, spinDurationTicks); + } + public boolean isPiercing() { return piercing; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java index 4edc18f82..586e402a8 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java @@ -87,10 +87,8 @@ public class AbilityDash extends Ability { this.maxRange = 20.0f; this.minRange = 0.0f; this.lockMovement = false; - this.cooldownTicks = 40; + this.cooldownTicks = 0; this.windUpTicks = 5; - this.activeTicks = 8; - this.recoveryTicks = 10; // No telegraph for dash - it's a quick evasive move this.telegraphType = TelegraphType.NONE; this.showTelegraph = false; @@ -174,6 +172,7 @@ public class AbilityDash extends Ability { npc.motionX = 0; npc.motionZ = 0; npc.velocityChanged = true; + signalCompletion(); return; } @@ -181,6 +180,7 @@ public class AbilityDash extends Ability { npc.motionX = 0; npc.motionZ = 0; npc.velocityChanged = true; + signalCompletion(); return; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java index 95dcd4afb..67fa23cdf 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDisc.java @@ -72,7 +72,7 @@ public class AbilityDisc extends Ability { private AnchorPoint anchorPoint = AnchorPoint.FRONT; // Transient state for disc entity (used during windup charging) - private transient int discEntityId = -1; + private transient EntityAbilityDisc discEntity = null; public AbilityDisc() { this.typeId = "ability.cnpc.disc"; @@ -80,10 +80,8 @@ public class AbilityDisc extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 30.0f; this.minRange = 5.0f; - this.cooldownTicks = 80; + this.cooldownTicks = 0; this.windUpTicks = 20; - this.activeTicks = 1; - this.recoveryTicks = 10; this.telegraphType = TelegraphType.CIRCLE; this.showTelegraph = true; } @@ -111,17 +109,19 @@ public class AbilityDisc extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - if (world.isRemote) return; - - // Find and start moving the disc that was spawned during windup - if (discEntityId != -1) { - Entity entity = world.getEntityByID(discEntityId); - if (entity instanceof EntityAbilityDisc) { - EntityAbilityDisc disc = (EntityAbilityDisc) entity; - disc.startMoving(target); - } - discEntityId = -1; + if (world.isRemote) { + signalCompletion(); + return; } + + // Start moving the disc that was spawned during windup + if (discEntity != null && !discEntity.isDead) { + discEntity.startMoving(target); + } + discEntity = null; + + // Disc entity manages itself - ability is done + signalCompletion(); } @Override @@ -131,7 +131,7 @@ public class AbilityDisc extends Ability { // Spawn disc in charging mode on first tick of windup if (tick == 1) { // Create disc in charging mode - follows NPC based on anchor point during windup - EntityAbilityDisc disc = EntityAbilityDisc.createCharging( + discEntity = EntityAbilityDisc.createCharging( world, npc, target, discRadius, discThickness, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, damage, knockback, knockbackUp, @@ -145,8 +145,7 @@ public class AbilityDisc extends Ability { windUpTicks // Charge duration = windup duration ); - world.spawnEntityInWorld(disc); - discEntityId = disc.getEntityId(); + world.spawnEntityInWorld(discEntity); } } @@ -159,15 +158,12 @@ public class AbilityDisc extends Ability { } @Override - public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { - // Despawn charging disc if interrupted during windup - if (discEntityId != -1) { - Entity entity = npc.worldObj.getEntityByID(discEntityId); - if (entity != null) { - entity.setDead(); - } - discEntityId = -1; + public void cleanup() { + // Despawn disc entity if still alive + if (discEntity != null && !discEntity.isDead) { + discEntity.setDead(); } + discEntity = null; } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java index 18969b43c..3bcc5072c 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityEnergyBeam.java @@ -71,7 +71,7 @@ public class AbilityEnergyBeam extends Ability { private AnchorPoint anchorPoint = AnchorPoint.FRONT; // Transient state for beam entity (used during windup charging) - private transient int beamEntityId = -1; + private transient EntityAbilityBeam beamEntity = null; public AbilityEnergyBeam() { this.typeId = "ability.cnpc.beam"; @@ -79,10 +79,8 @@ public class AbilityEnergyBeam extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 20.0f; this.minRange = 5.0f; - this.cooldownTicks = 150; + this.cooldownTicks = 0; this.windUpTicks = 40; - this.activeTicks = 200; // Match maxLifetime to keep NPC locked while beam is active - this.recoveryTicks = 5; this.telegraphType = TelegraphType.CIRCLE; this.showTelegraph = true; } @@ -110,17 +108,19 @@ public class AbilityEnergyBeam extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - if (world.isRemote) return; - - // Find and start firing the beam that was spawned during windup - if (beamEntityId != -1) { - Entity entity = world.getEntityByID(beamEntityId); - if (entity instanceof EntityAbilityBeam) { - EntityAbilityBeam beam = (EntityAbilityBeam) entity; - beam.startFiring(target); - } - beamEntityId = -1; + if (world.isRemote) { + signalCompletion(); + return; } + + // Start firing the beam that was spawned during windup + if (beamEntity != null && !beamEntity.isDead) { + beamEntity.startFiring(target); + } + beamEntity = null; + + // Beam entity manages itself - ability is done + signalCompletion(); } @Override @@ -132,7 +132,7 @@ public class AbilityEnergyBeam extends Ability { float offsetDist = 1.0f; // Create beam in charging mode - follows NPC based on anchor point during windup - EntityAbilityBeam beam = EntityAbilityBeam.createCharging( + beamEntity = EntityAbilityBeam.createCharging( world, npc, target, beamWidth, headSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, damage, knockback, knockbackUp, @@ -147,8 +147,7 @@ public class AbilityEnergyBeam extends Ability { anchorPoint // Anchor point for charging position ); - world.spawnEntityInWorld(beam); - beamEntityId = beam.getEntityId(); + world.spawnEntityInWorld(beamEntity); } } @@ -161,15 +160,12 @@ public class AbilityEnergyBeam extends Ability { } @Override - public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { - // Despawn charging beam if interrupted during windup - if (beamEntityId != -1) { - Entity entity = npc.worldObj.getEntityByID(beamEntityId); - if (entity != null) { - entity.setDead(); - } - beamEntityId = -1; + public void cleanup() { + // Despawn beam entity if still alive + if (beamEntity != null && !beamEntity.isDead) { + beamEntity.setDead(); } + beamEntity = null; } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java index 404589c6e..831ef97fd 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java @@ -25,6 +25,7 @@ public class AbilityGuard extends Ability { private static final Random RANDOM = new Random(); // Type-specific parameters + private int durationTicks = 60; private float damageReduction = 0.5f; private boolean canCounter = false; private CounterType counterType = CounterType.FLAT; @@ -48,10 +49,8 @@ public class AbilityGuard extends Ability { this.name = "Guard"; this.targetingMode = TargetingMode.SELF; this.lockMovement = true; - this.cooldownTicks = 120; + this.cooldownTicks = 0; this.windUpTicks = 10; - this.activeTicks = 60; - this.recoveryTicks = 10; this.interruptible = false; // Hard to interrupt while guarding // No telegraph for guard - it's a defensive stance this.telegraphType = TelegraphType.NONE; @@ -95,6 +94,11 @@ public class AbilityGuard extends Ability { if (canCounter && counterTriggered && lastAttacker != null && !world.isRemote) { performCounter(npc, world); } + + // Check if guard duration has ended + if (tick >= durationTicks) { + signalCompletion(); + } } /** @@ -175,6 +179,7 @@ public class AbilityGuard extends Ability { @Override public void writeTypeNBT(NBTTagCompound nbt) { + nbt.setInteger("durationTicks", durationTicks); nbt.setFloat("damageReduction", damageReduction); nbt.setBoolean("canCounter", canCounter); nbt.setString("counterType", counterType.name()); @@ -186,6 +191,7 @@ public class AbilityGuard extends Ability { @Override public void readTypeNBT(NBTTagCompound nbt) { + this.durationTicks = nbt.hasKey("durationTicks") ? nbt.getInteger("durationTicks") : 60; this.damageReduction = nbt.hasKey("damageReduction") ? nbt.getFloat("damageReduction") : 0.5f; this.canCounter = nbt.hasKey("canCounter") && nbt.getBoolean("canCounter"); try { @@ -206,6 +212,14 @@ public class AbilityGuard extends Ability { } // Getters & Setters + public int getDurationTicks() { + return durationTicks; + } + + public void setDurationTicks(int durationTicks) { + this.durationTicks = Math.max(1, durationTicks); + } + public float getDamageReduction() { return damageReduction; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java index 3161c5dbe..3e9998f6f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java @@ -42,6 +42,7 @@ public class AbilityHazard extends Ability { FOLLOW_TARGET } + private int durationTicks = 100; private float radius = 4.0f; private float innerRadius = 0.0f; private float coneAngle = 45.0f; @@ -81,10 +82,8 @@ public class AbilityHazard extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 15.0f; this.lockMovement = true; - this.cooldownTicks = 200; + this.cooldownTicks = 0; this.windUpTicks = 30; - this.activeTicks = 100; - this.recoveryTicks = 10; this.telegraphType = TelegraphType.CIRCLE; } @@ -232,6 +231,12 @@ public class AbilityHazard extends Ability { public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { if (world.isRemote) return; + // Check if hazard duration has ended + if (tick >= durationTicks) { + signalCompletion(); + return; + } + damagedThisTick.clear(); ticksSinceDamage++; @@ -342,6 +347,7 @@ public class AbilityHazard extends Ability { @Override public void writeTypeNBT(NBTTagCompound nbt) { + nbt.setInteger("durationTicks", durationTicks); nbt.setFloat("radius", radius); nbt.setFloat("innerRadius", innerRadius); nbt.setFloat("coneAngle", coneAngle); @@ -366,6 +372,7 @@ public class AbilityHazard extends Ability { @Override public void readTypeNBT(NBTTagCompound nbt) { + this.durationTicks = nbt.hasKey("durationTicks") ? nbt.getInteger("durationTicks") : 100; this.radius = nbt.hasKey("radius") ? nbt.getFloat("radius") : 4.0f; this.innerRadius = nbt.hasKey("innerRadius") ? nbt.getFloat("innerRadius") : 0.0f; this.coneAngle = nbt.hasKey("coneAngle") ? nbt.getFloat("coneAngle") : 45.0f; @@ -404,6 +411,14 @@ public class AbilityHazard extends Ability { } // Getters & Setters + public int getDurationTicks() { + return durationTicks; + } + + public void setDurationTicks(int durationTicks) { + this.durationTicks = Math.max(1, durationTicks); + } + public float getRadius() { return radius; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java index 3cf04db2c..59ef4751a 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java @@ -25,6 +25,7 @@ import java.util.List; public class AbilityHeal extends Ability { // Type-specific parameters + private int durationTicks = 60; private float healAmount = 10.0f; private float healPercent = 0.0f; private boolean healSelf = true; @@ -40,10 +41,8 @@ public class AbilityHeal extends Ability { this.name = "Heal"; this.targetingMode = TargetingMode.SELF; this.lockMovement = true; - this.cooldownTicks = 200; + this.cooldownTicks = 0; this.windUpTicks = 30; - this.activeTicks = 10; - this.recoveryTicks = 10; // No telegraph for heal - it's a self/ally buff this.telegraphType = TelegraphType.NONE; this.showTelegraph = false; @@ -92,6 +91,9 @@ public class AbilityHeal extends Ability { healEntity(ally); spawnHealParticles(world, ally); } + + // Instant heal completes immediately + signalCompletion(); } // If not instant, HoT healing is applied in onActiveTick } @@ -100,16 +102,16 @@ public class AbilityHeal extends Ability { public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { if (world.isRemote || instantHeal) return; - // Heal over time - distribute heal across active ticks + // Heal over time - distribute heal across duration ticks if (tick % 10 == 0) { // Calculate tick-based heal for fixed amount - float tickHeal = (healAmount / (float) activeTicks) * 10; + float tickHeal = (healAmount / (float) durationTicks) * 10; if (healSelf) { float selfTickHeal = tickHeal; // Add percentage-based heal portion if (healPercent > 0) { - selfTickHeal += (npc.getMaxHealth() * healPercent / (float) activeTicks) * 10; + selfTickHeal += (npc.getMaxHealth() * healPercent / (float) durationTicks) * 10; } npc.heal(selfTickHeal); if (tick % 20 == 0) { @@ -123,7 +125,7 @@ public class AbilityHeal extends Ability { float allyTickHeal = tickHeal; // Add percentage-based heal portion for each ally if (healPercent > 0) { - allyTickHeal += (ally.getMaxHealth() * healPercent / (float) activeTicks) * 10; + allyTickHeal += (ally.getMaxHealth() * healPercent / (float) durationTicks) * 10; } ally.heal(allyTickHeal); if (tick % 20 == 0) { @@ -133,6 +135,11 @@ public class AbilityHeal extends Ability { } } } + + // Check if heal duration has ended + if (tick >= durationTicks) { + signalCompletion(); + } } /** @@ -202,6 +209,7 @@ public class AbilityHeal extends Ability { @Override public void writeTypeNBT(NBTTagCompound nbt) { + nbt.setInteger("durationTicks", durationTicks); nbt.setFloat("healAmount", healAmount); nbt.setFloat("healPercent", healPercent); nbt.setBoolean("healSelf", healSelf); @@ -212,6 +220,7 @@ public class AbilityHeal extends Ability { @Override public void readTypeNBT(NBTTagCompound nbt) { + this.durationTicks = nbt.hasKey("durationTicks") ? nbt.getInteger("durationTicks") : 60; this.healAmount = nbt.hasKey("healAmount") ? nbt.getFloat("healAmount") : 10.0f; this.healPercent = nbt.hasKey("healPercent") ? nbt.getFloat("healPercent") : 0.0f; this.healSelf = !nbt.hasKey("healSelf") || nbt.getBoolean("healSelf"); @@ -221,6 +230,14 @@ public class AbilityHeal extends Ability { } // Getters & Setters + public int getDurationTicks() { + return durationTicks; + } + + public void setDurationTicks(int durationTicks) { + this.durationTicks = Math.max(1, durationTicks); + } + public float getHealAmount() { return healAmount; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java index fc68200b7..32335daeb 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeavyHit.java @@ -29,10 +29,8 @@ public class AbilityHeavyHit extends Ability { this.maxRange = 3.0f; this.minRange = 0.0f; this.lockMovement = true; - this.cooldownTicks = 80; + this.cooldownTicks = 0; this.windUpTicks = 30; - this.activeTicks = 5; - this.recoveryTicks = 10; this.telegraphType = TelegraphType.POINT; this.showTelegraph = false; this.windUpSound = "random.anvil_use"; @@ -63,7 +61,10 @@ public class AbilityHeavyHit extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - if (world.isRemote || target == null) return; + if (world.isRemote || target == null) { + signalCompletion(); + return; + } // Apply damage with scripted event support boolean wasHit = applyAbilityDamage(npc, target, damage, knockback); @@ -72,6 +73,9 @@ public class AbilityHeavyHit extends Ability { if (wasHit) { applyEffects(target); } + + // Heavy Hit is instant + signalCompletion(); } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java index 77df6ff35..8084aaad4 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityLaserShot.java @@ -60,10 +60,8 @@ public class AbilityLaserShot extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 35.0f; this.minRange = 3.0f; - this.cooldownTicks = 60; + this.cooldownTicks = 0; this.windUpTicks = 15; - this.activeTicks = 1; - this.recoveryTicks = 5; this.telegraphType = TelegraphType.LINE; this.showTelegraph = true; } @@ -101,7 +99,10 @@ public class AbilityLaserShot extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - if (world.isRemote) return; + if (world.isRemote) { + signalCompletion(); + return; + } double spawnX = npc.posX; double spawnY = npc.posY + npc.getEyeHeight() * 0.8; @@ -120,10 +121,14 @@ public class AbilityLaserShot extends Ability { ); world.spawnEntityInWorld(laser); + + // Laser entity manages itself - ability is done + signalCompletion(); } @Override public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { + // Laser entity manages itself } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java index 38ffd8db4..6bc6da964 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityOrb.java @@ -69,7 +69,7 @@ public class AbilityOrb extends Ability { private AnchorPoint anchorPoint = AnchorPoint.FRONT; // Transient state for orb entity (used during windup charging) - private transient int orbEntityId = -1; + private transient EntityAbilityOrb orbEntity = null; public AbilityOrb() { this.typeId = "ability.cnpc.orb"; @@ -77,10 +77,8 @@ public class AbilityOrb extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 25.0f; this.minRange = 5.0f; - this.cooldownTicks = 100; + this.cooldownTicks = 0; this.windUpTicks = 30; - this.activeTicks = 1; // Minimal - just spawn and done - this.recoveryTicks = 10; this.telegraphType = TelegraphType.CIRCLE; this.showTelegraph = true; } @@ -108,17 +106,19 @@ public class AbilityOrb extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - if (world.isRemote) return; - - // Find and start moving the orb that was spawned during windup - if (orbEntityId != -1) { - Entity entity = world.getEntityByID(orbEntityId); - if (entity instanceof EntityAbilityOrb) { - EntityAbilityOrb orb = (EntityAbilityOrb) entity; - orb.startMoving(target); - } - orbEntityId = -1; + if (world.isRemote) { + signalCompletion(); + return; } + + // Start moving the orb that was spawned during windup + if (orbEntity != null && !orbEntity.isDead) { + orbEntity.startMoving(target); + } + orbEntity = null; + + // Orb entity manages itself - ability is done + signalCompletion(); } @Override @@ -128,7 +128,7 @@ public class AbilityOrb extends Ability { // Spawn orb in charging mode on first tick of windup if (tick == 1) { // Create orb in charging mode - follows NPC based on anchor point during windup - EntityAbilityOrb orb = EntityAbilityOrb.createCharging( + orbEntity = EntityAbilityOrb.createCharging( world, npc, target, orbSize, innerColor, outerColor, outerColorEnabled, outerColorWidth, rotationSpeed, damage, knockback, knockbackUp, @@ -141,8 +141,7 @@ public class AbilityOrb extends Ability { windUpTicks // Charge duration = windup duration ); - world.spawnEntityInWorld(orb); - orbEntityId = orb.getEntityId(); + world.spawnEntityInWorld(orbEntity); } } @@ -157,15 +156,12 @@ public class AbilityOrb extends Ability { } @Override - public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { - // Despawn charging orb if interrupted during windup - if (orbEntityId != -1) { - Entity entity = npc.worldObj.getEntityByID(orbEntityId); - if (entity != null) { - entity.setDead(); - } - orbEntityId = -1; + public void cleanup() { + // Despawn orb entity if still alive + if (orbEntity != null && !orbEntity.isDead) { + orbEntity.setDead(); } + orbEntity = null; } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java index 8ff9f5410..4a12ae4eb 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java @@ -38,10 +38,8 @@ public class AbilityProjectile extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.minRange = 5.0f; this.maxRange = 20.0f; - this.cooldownTicks = 60; + this.cooldownTicks = 0; this.windUpTicks = 15; - this.activeTicks = 5; - this.recoveryTicks = 10; // No telegraph for projectile - it's a ranged attack this.telegraphType = TelegraphType.NONE; this.showTelegraph = false; @@ -122,6 +120,9 @@ public class AbilityProjectile extends Ability { // Spawn projectile particles (visual trail) spawnProjectileParticles(world, npc, target); + + // Projectile is instant + signalCompletion(); } private void spawnProjectileParticles(World world, EntityNPCInterface npc, EntityLivingBase target) { diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java index b5a35831f..71d888978 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityShockwave.java @@ -28,19 +28,14 @@ public class AbilityShockwave extends Ability { private float damage = 8.0f; private int maxTargets = 10; - // Runtime state - private transient boolean executed = false; - public AbilityShockwave() { this.typeId = "ability.cnpc.shockwave"; this.name = "Shockwave"; this.targetingMode = TargetingMode.AOE_SELF; this.maxRange = 15.0f; this.lockMovement = true; - this.cooldownTicks = 100; + this.cooldownTicks = 0; this.windUpTicks = 25; - this.activeTicks = 5; - this.recoveryTicks = 10; this.telegraphType = TelegraphType.CIRCLE; this.windUpSound = "random.explode"; this.activeSound = "random.explode"; @@ -74,13 +69,7 @@ public class AbilityShockwave extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - executed = false; - } - - @Override - public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { - if (executed) return; - executed = true; + // Shockwave is instant - apply effect immediately after windup // Get all entities in radius AxisAlignedBB box = npc.boundingBox.expand(pushRadius, pushRadius / 2, pushRadius); @@ -124,16 +113,14 @@ public class AbilityShockwave extends Ability { applyEffects(entity); } } + + // Shockwave completes instantly + signalCompletion(); } @Override - public void onComplete(EntityNPCInterface npc, EntityLivingBase target) { - executed = false; - } - - @Override - public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { - executed = false; + public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { + // Shockwave is instant - nothing to do per-tick } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySlam.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySlam.java index d2c17a3e8..dcb914a96 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySlam.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySlam.java @@ -49,11 +49,8 @@ public class AbilitySlam extends Ability { this.name = "Slam"; this.targetingMode = TargetingMode.AOE_SELF; // Can also be AOE_TARGET to leap to target this.windUpTicks = 30; - this.activeTicks = 60; // Max time in air (used as timeout if waitForCompletion fails) - this.recoveryTicks = 10; - this.cooldownTicks = 100; + this.cooldownTicks = 0; this.lockMovement = true; - this.waitForCompletion = true; // Ability completes when NPC lands, not by activeTicks this.minRange = 2.0f; this.maxRange = 15.0f; this.telegraphType = TelegraphType.CIRCLE; diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java index b7ca2aa22..ca41ed6e3 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java @@ -54,10 +54,8 @@ public class AbilitySweeper extends Ability { this.maxRange = 15.0f; this.minRange = 0.0f; this.lockMovement = true; - this.cooldownTicks = 200; + this.cooldownTicks = 0; this.windUpTicks = 60; - this.activeTicks = 400; // Long duration - entity controls actual end - this.recoveryTicks = 5; // Short recovery // Circle telegraph to show range this.telegraphType = TelegraphType.CIRCLE; this.showTelegraph = true; @@ -86,36 +84,36 @@ public class AbilitySweeper extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - if (!world.isRemote) { - 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, - innerColor, outerColor, outerColorEnabled, outerColorWidth, - sweepSpeed, numberOfRotations, - damage, damageInterval, piercing, - lockOnTarget); - world.spawnEntityInWorld(activeEntity); - - LogWriter.info("[Sweeper] Spawned sweeper entity"); + if (world.isRemote) { + signalCompletion(); + 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, + innerColor, outerColor, outerColorEnabled, outerColorWidth, + sweepSpeed, numberOfRotations, + damage, damageInterval, piercing, + lockOnTarget); + world.spawnEntityInWorld(activeEntity); + + LogWriter.info("[Sweeper] Spawned sweeper entity"); + // Entity manages itself - completion signaled from onActiveTick when entity dies } @Override public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { - // Entity handles everything - nothing to do here - // Check if entity died early (entity manages its own death based on rotations) - if (activeEntity != null && activeEntity.isDead) { - // Entity finished, ability can end early - // The ability system will handle the recovery phase + // Entity handles everything - check if entity finished its rotations + if (activeEntity == null || activeEntity.isDead) { + signalCompletion(); } } @Override - public void reset() { - super.reset(); - + public void cleanup() { // Clean up entity if still alive if (activeEntity != null && !activeEntity.isDead) { activeEntity.setDead(); diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java index a79223d5d..668b2f04d 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java @@ -59,10 +59,8 @@ public class AbilityTeleport extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 30.0f; this.minRange = 5.0f; - this.cooldownTicks = 100; + this.cooldownTicks = 0; this.windUpTicks = 10; - this.activeTicks = 40; - this.recoveryTicks = 10; // No telegraph for teleport - it's instant repositioning this.telegraphType = TelegraphType.NONE; this.showTelegraph = false; @@ -101,7 +99,10 @@ public class AbilityTeleport extends Ability { @Override public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { int blinkLimit = mode == TeleportMode.BLINK ? blinkCount : 1; - if (currentBlink >= blinkLimit) return; + if (currentBlink >= blinkLimit) { + signalCompletion(); + return; + } ticksSinceLastBlink++; @@ -109,6 +110,11 @@ public class AbilityTeleport extends Ability { performBlink(npc, target, world); currentBlink++; ticksSinceLastBlink = 0; + + // Check if this was the last blink + if (currentBlink >= blinkLimit) { + signalCompletion(); + } } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java index 77ac4a5fe..dbb7273cd 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java @@ -34,6 +34,7 @@ public class AbilityTrap extends Ability { AHEAD_OF_CASTER } + private int durationTicks = 200; private TrapPlacement placement = TrapPlacement.AT_TARGET; private float placementDistance = 5.0f; private float triggerRadius = 2.0f; @@ -64,10 +65,8 @@ public class AbilityTrap extends Ability { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 15.0f; this.lockMovement = true; - this.cooldownTicks = 150; + this.cooldownTicks = 0; this.windUpTicks = 20; - this.activeTicks = 200; - this.recoveryTicks = 10; this.telegraphType = TelegraphType.CIRCLE; } @@ -180,6 +179,12 @@ public class AbilityTrap extends Ability { @Override public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { + // Check if trap duration has ended + if (tick >= durationTicks) { + signalCompletion(); + return; + } + if (!armed) { if (tick >= armTime) { armed = true; @@ -190,6 +195,7 @@ public class AbilityTrap extends Ability { ticksSinceLastTrigger++; if (maxTriggers > 0 && triggerCount >= maxTriggers) { + signalCompletion(); // All triggers used, trap is done return; } @@ -277,6 +283,7 @@ public class AbilityTrap extends Ability { @Override public void writeTypeNBT(NBTTagCompound nbt) { + nbt.setInteger("durationTicks", durationTicks); nbt.setString("placement", placement.name()); nbt.setFloat("placementDistance", placementDistance); nbt.setFloat("triggerRadius", triggerRadius); @@ -294,6 +301,7 @@ public class AbilityTrap extends Ability { @Override public void readTypeNBT(NBTTagCompound nbt) { + this.durationTicks = nbt.hasKey("durationTicks") ? nbt.getInteger("durationTicks") : 200; try { this.placement = TrapPlacement.valueOf(nbt.getString("placement")); } catch (Exception e) { @@ -314,6 +322,14 @@ public class AbilityTrap extends Ability { } // Getters & Setters + public int getDurationTicks() { + return durationTicks; + } + + public void setDurationTicks(int durationTicks) { + this.durationTicks = Math.max(1, durationTicks); + } + public TrapPlacement getPlacement() { return placement; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java index 666b19bbc..70c1c96b7 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java @@ -46,10 +46,8 @@ public class AbilityVortex extends Ability { this.targetingMode = TargetingMode.AOE_SELF; this.maxRange = 15.0f; this.lockMovement = true; - this.cooldownTicks = 120; + this.cooldownTicks = 0; this.windUpTicks = 30; - this.activeTicks = 40; - this.recoveryTicks = 5; this.telegraphType = TelegraphType.CIRCLE; this.windUpSound = "mob.ghast.charge"; this.activeSound = "mob.ghast.fireball"; @@ -119,6 +117,7 @@ public class AbilityVortex extends Ability { @Override public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { if (pullComplete || pulledEntities.isEmpty()) { + signalCompletion(); return; } @@ -174,6 +173,7 @@ public class AbilityVortex extends Ability { if (!anyStillPulling && pulledEntities.isEmpty()) { pullComplete = true; + signalCompletion(); } } diff --git a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java index 5a7e32d28..593c8aa19 100644 --- a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java +++ b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java @@ -7,104 +7,87 @@ import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.controllers.data.Frame; import noppes.npcs.controllers.data.FramePart; +import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.entity.data.ModelScalePart; /** * Utility class for calculating world positions based on anchor points. - * Used for positioning charging effects on different body parts. - * Animation-aware: reads arm positions from NPC animation data when available. + * Supports both EntityNPCInterface and EntityPlayer with animation and model size awareness. */ public class AnchorPointHelper { - // ==================== TUNABLE CONSTANTS ==================== - // These can be adjusted to fine-tune positioning + // Default biped model constants (in model units, 1 unit = 1/16 block) + private static final float MODEL_SCALE = 1f / 16f; - // Shoulder position in model units (default biped arm rotation points) - private static final float SHOULDER_X_RIGHT = -5.0f; // Right arm is on the right side (-X in model space) - private static final float SHOULDER_X_LEFT = 5.0f; // Left arm is on the left side (+X in model space) - private static final float SHOULDER_Y = 2.0f; // Shoulder height from model origin - private static final float SHOULDER_Z = 0.0f; // Shoulder depth + // Shoulder position relative to model origin + private static final float SHOULDER_Y = 2f; + private static final float SHOULDER_X_OFFSET = 5f; // Distance from center to shoulder - // Hand offset in model units (where items are held, relative to shoulder after rotation) - // In arm's local space: X = toward/away from body, Y = down the arm, Z = forward/back - private static float HAND_OFFSET_X_RIGHT = -2.0f; // Slightly toward body for right - private static float HAND_OFFSET_X_LEFT = 2.0f; // Slightly toward body for left - private static float HAND_OFFSET_Y = 14.0f; // Down the arm (arm is ~12 units long) - private static float HAND_OFFSET_Z = 0.0f; // Forward from arm + // Palm position (in arm's local space, relative to shoulder) + // Arm is 12 units long; palm is near the end + private static final float PALM_DOWN = 11f; // Distance down the arm to palm center + private static final float PALM_FORWARD = 2f; // Forward offset to palm surface (not center of hand) + private static final float PALM_INWARD = 0f; // Lateral offset (0 = centered on arm) - // Height of shoulder relative to entity position (feet) - private static final float SHOULDER_HEIGHT_BLOCKS = 1.35f; + // Default height offsets as fraction of entity height + private static final float FRONT_HEIGHT = 0.7f; + private static final float CENTER_HEIGHT = 0.5f; + private static final float ARM_HEIGHT = 0.75f; + private static final float ABOVE_HEAD_HEIGHT = 1.2f; + private static final float CHEST_HEIGHT = 0.65f; - // Model scale factor (1/16 - converts model units to blocks) - private static final float MODEL_SCALE = 0.0625f; + // Distance in front for FRONT anchor + private static final float DEFAULT_FRONT_DISTANCE = 1.0f; - // Fallback offsets (in blocks) when no animation - private static final float ARM_LATERAL_OFFSET = 0.35f; - private static final float ARM_FORWARD_OFFSET = 0.3f; - private static final float FRONT_OFFSET = 1.0f; - - // Height multipliers relative to eye height - private static final float FRONT_HEIGHT_MULT = 0.7f; - private static final float CENTER_HEIGHT_MULT = 0.5f; - private static final float ARM_HEIGHT_MULT = 0.75f; - private static final float ABOVE_HEAD_HEIGHT_MULT = 1.3f; - private static final float CHEST_HEIGHT_MULT = 0.5f; + // Fallback arm positioning (when no animation) + private static final float FALLBACK_LATERAL = 0.35f; + private static final float FALLBACK_FORWARD = 0.3f; /** - * Calculate the world position for a given anchor point on an entity. + * Calculate world position for an anchor point on an entity. */ public static Vec3 calculateAnchorPosition(EntityLivingBase entity, AnchorPoint anchor) { - return calculateAnchorPosition(entity, anchor, FRONT_OFFSET); + return calculateAnchorPosition(entity, anchor, DEFAULT_FRONT_DISTANCE); } /** - * Calculate the world position for a given anchor point on an entity. + * Calculate world position for an anchor point with custom front offset. */ public static Vec3 calculateAnchorPosition(EntityLivingBase entity, AnchorPoint anchor, float frontOffset) { + float scale = getModelScale(entity); + float height = entity.height; + double x = entity.posX; double y = entity.posY; double z = entity.posZ; - float eyeHeight = entity.getEyeHeight(); - // Body yaw in radians (used for arm positioning) - // Minecraft: yaw 0 = south (+Z), 90 = west (-X), 180 = north (-Z), 270 = east (+X) - float bodyYawRad = (float) Math.toRadians(entity.renderYawOffset); - float headYawRad = (float) Math.toRadians(entity.rotationYawHead); + float headYaw = (float) Math.toRadians(entity.rotationYawHead); + float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); switch (anchor) { case FRONT: - // In front of entity face (use head yaw) - x -= Math.sin(headYawRad) * frontOffset; - y += eyeHeight * FRONT_HEIGHT_MULT; - z += Math.cos(headYawRad) * frontOffset; + x -= Math.sin(headYaw) * frontOffset * scale; + y += height * FRONT_HEIGHT; + z += Math.cos(headYaw) * frontOffset * scale; break; case CENTER: - y += eyeHeight * CENTER_HEIGHT_MULT; + y += height * CENTER_HEIGHT; break; case RIGHT_HAND: - Vec3 rightPos = getAnimatedHandPosition(entity, true); - if (rightPos != null) { - return rightPos; - } - // Fallback - return calculateFallbackHandPosition(entity, bodyYawRad, true); + return calculateHandPosition(entity, true, scale); case LEFT_HAND: - Vec3 leftPos = getAnimatedHandPosition(entity, false); - if (leftPos != null) { - return leftPos; - } - // Fallback - return calculateFallbackHandPosition(entity, bodyYawRad, false); + return calculateHandPosition(entity, false, scale); case ABOVE_HEAD: - y += eyeHeight * ABOVE_HEAD_HEIGHT_MULT; + y += height * ABOVE_HEAD_HEIGHT; break; case CHEST: - y += eyeHeight * CHEST_HEIGHT_MULT; + y += height * CHEST_HEIGHT; break; } @@ -112,17 +95,51 @@ public class AnchorPointHelper { } /** - * Calculate hand position using NPC animation data. - * Uses the same transformation logic as the renderer. + * Get model scale factor for an entity. + * NPCs have configurable model size, players use default scale. */ - private static Vec3 getAnimatedHandPosition(EntityLivingBase entity, boolean rightArm) { - if (!(entity instanceof EntityNPCInterface)) { - return null; + private static float getModelScale(EntityLivingBase entity) { + if (entity instanceof EntityNPCInterface) { + int modelSize = ((EntityNPCInterface) entity).display.modelSize; + return modelSize / 5f; // modelSize 5 = 100% scale + } + return 1f; + } + + // Default arm scale (no scaling) + private static final ModelScalePart DEFAULT_ARM_SCALE = new ModelScalePart(); + + /** + * Get arm scale for an entity. + * EntityCustomNpc has per-part scaling, others use default (1,1,1). + */ + private static ModelScalePart getArmScale(EntityLivingBase entity) { + if (entity instanceof EntityCustomNpc) { + return ((EntityCustomNpc) entity).modelData.modelScale.arms; + } + return DEFAULT_ARM_SCALE; + } + + /** + * Calculate hand position using animation data if available. + */ + private static Vec3 calculateHandPosition(EntityLivingBase entity, boolean rightHand, float scale) { + // Try to get animated position first + Vec3 animatedPos = getAnimatedHandPosition(entity, rightHand, scale); + if (animatedPos != null) { + return animatedPos; } - EntityNPCInterface npc = (EntityNPCInterface) entity; - AnimationData animData = npc.display.animationData; + // Fallback to static position + return calculateFallbackHandPosition(entity, rightHand, scale); + } + /** + * Calculate hand position from animation data. + * Works for both NPCs and Players. + */ + private static Vec3 getAnimatedHandPosition(EntityLivingBase entity, boolean rightHand, float scale) { + AnimationData animData = AnimationData.getData(entity); if (animData == null || !animData.isActive() || animData.animation == null) { return null; } @@ -132,146 +149,172 @@ public class AnchorPointHelper { return null; } - EnumAnimationPart armPart = rightArm ? EnumAnimationPart.RIGHT_ARM : EnumAnimationPart.LEFT_ARM; - if (!frame.frameParts.containsKey(armPart)) { - return null; - } - + EnumAnimationPart armPart = rightHand ? EnumAnimationPart.RIGHT_ARM : EnumAnimationPart.LEFT_ARM; FramePart part = frame.frameParts.get(armPart); if (part == null) { return null; } - // Ensure interpolation is up to date - part.interpolateOffset(); - part.interpolateAngles(); + // Get arm scale for EntityCustomNpc + ModelScalePart armScale = getArmScale(entity); - // === STEP 1: Get shoulder position in model space === - float shoulderX = rightArm ? SHOULDER_X_RIGHT : SHOULDER_X_LEFT; + // Get rotation and pivot values + float[] rotations = getRotations(part, entity); + float[] pivots = getPivots(part, entity); + + // Shoulder position in model space + float shoulderX = rightHand ? -SHOULDER_X_OFFSET : SHOULDER_X_OFFSET; float shoulderY = SHOULDER_Y; - float shoulderZ = SHOULDER_Z; + float shoulderZ = 0f; - // Add animation pivot offsets - if (part.prevPivots != null) { - shoulderX += part.prevPivots[0]; - shoulderY += part.prevPivots[1]; - shoulderZ += part.prevPivots[2]; - } + // Add pivot offsets + shoulderX += pivots[0]; + shoulderY += pivots[1]; + shoulderZ += pivots[2]; - // === STEP 2: Get hand offset in arm's local space === - float handX = rightArm ? HAND_OFFSET_X_RIGHT : HAND_OFFSET_X_LEFT; - float handY = HAND_OFFSET_Y; - float handZ = HAND_OFFSET_Z; + // Palm offset in arm's local space (before rotation) + // Apply arm scaling to the palm position + float palmX = (rightHand ? -PALM_INWARD : PALM_INWARD) * armScale.scaleX; + float palmY = PALM_DOWN * armScale.scaleY; + float palmZ = PALM_FORWARD * armScale.scaleZ; - // === STEP 3: Apply arm rotations to hand offset (Z → Y → X order) === - // Rotations are in radians (already converted by interpolateAngles) - float rotX = part.prevRotations != null ? part.prevRotations[0] : 0; - float rotY = part.prevRotations != null ? part.prevRotations[1] : 0; - float rotZ = part.prevRotations != null ? part.prevRotations[2] : 0; + // Apply arm rotations (order: Z -> Y -> X) + double hx = palmX, hy = palmY, hz = palmZ; - // Start with hand offset - double hx = handX; - double hy = handY; - double hz = handZ; - - // Apply Z rotation first - double cosZ = Math.cos(rotZ); - double sinZ = Math.sin(rotZ); + // Z rotation + double cosZ = Math.cos(rotations[2]); + double sinZ = Math.sin(rotations[2]); double newX = hx * cosZ - hy * sinZ; double newY = hx * sinZ + hy * cosZ; hx = newX; hy = newY; - // Apply Y rotation - double cosY = Math.cos(rotY); - double sinY = Math.sin(rotY); + // Y rotation + double cosY = Math.cos(rotations[1]); + double sinY = Math.sin(rotations[1]); newX = hx * cosY + hz * sinY; double newZ = -hx * sinY + hz * cosY; hx = newX; hz = newZ; - // Apply X rotation - double cosX = Math.cos(rotX); - double sinX = Math.sin(rotX); + // X rotation + double cosX = Math.cos(rotations[0]); + double sinX = Math.sin(rotations[0]); newY = hy * cosX - hz * sinX; newZ = hy * sinX + hz * cosX; hy = newY; hz = newZ; - // === STEP 4: Combine shoulder + rotated hand offset (in model units) === + // Combine shoulder + rotated hand offset double modelX = shoulderX + hx; double modelY = shoulderY + hy; double modelZ = shoulderZ + hz; - // === STEP 5: Convert to blocks === - double blockX = modelX * MODEL_SCALE; - double blockY = modelY * MODEL_SCALE; - double blockZ = modelZ * MODEL_SCALE; + // Convert to blocks and apply model scale + double blockX = modelX * MODEL_SCALE * scale; + double blockY = modelY * MODEL_SCALE * scale; + double blockZ = modelZ * MODEL_SCALE * scale; - // === STEP 6: Apply body yaw rotation === - // In model space: +X = left, -X = right, +Z = back, -Z = front - // Need to rotate to align with entity's facing direction + // Apply body yaw rotation float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); double cosYaw = Math.cos(bodyYaw); double sinYaw = Math.sin(bodyYaw); - // Rotate around Y axis (body rotation) double worldOffsetX = blockX * cosYaw + blockZ * sinYaw; double worldOffsetZ = -blockX * sinYaw + blockZ * cosYaw; - // === STEP 7: Final world position === + // Calculate shoulder height based on entity and scale + float shoulderHeight = entity.height * ARM_HEIGHT; + + // Final world position double worldX = entity.posX + worldOffsetX; - double worldY = entity.posY + SHOULDER_HEIGHT_BLOCKS - blockY; // Subtract because +Y in model is down + double worldY = entity.posY + shoulderHeight - blockY; double worldZ = entity.posZ + worldOffsetZ; return Vec3.createVectorHelper(worldX, worldY, worldZ); } + /** + * Get rotation values from FramePart. + * Uses interpolated values on client, raw values on server. + */ + private static float[] getRotations(FramePart part, EntityLivingBase entity) { + if (entity.worldObj.isRemote) { + // Client side - use interpolated values (already in radians) + part.interpolateAngles(); + return part.prevRotations; + } else { + // Server side - convert raw degrees to radians + float pi = (float) Math.PI / 180f; + return new float[]{ + part.rotation[0] * pi, + part.rotation[1] * pi, + part.rotation[2] * pi + }; + } + } + + /** + * Get pivot values from FramePart. + * Uses interpolated values on client, raw values on server. + */ + private static float[] getPivots(FramePart part, EntityLivingBase entity) { + if (entity.worldObj.isRemote) { + // Client side - use interpolated values + part.interpolateOffset(); + return part.prevPivots; + } else { + // Server side - use raw values + return part.pivot; + } + } + /** * Calculate fallback hand position when no animation is active. */ - private static Vec3 calculateFallbackHandPosition(EntityLivingBase entity, float bodyYawRad, boolean rightHand) { - double x = entity.posX; - double y = entity.posY; - double z = entity.posZ; - float eyeHeight = entity.getEyeHeight(); + private static Vec3 calculateFallbackHandPosition(EntityLivingBase entity, boolean rightHand, float scale) { + float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); + + // Get arm scale for EntityCustomNpc + ModelScalePart armScale = getArmScale(entity); // Perpendicular direction for lateral offset - float perpYaw = bodyYawRad + (float) (rightHand ? Math.PI / 2 : -Math.PI / 2); + float perpYaw = bodyYaw + (rightHand ? (float) (Math.PI / 2) : (float) (-Math.PI / 2)); - // Lateral offset (perpendicular to body facing) - double lateralX = -Math.sin(perpYaw) * ARM_LATERAL_OFFSET; - double lateralZ = Math.cos(perpYaw) * ARM_LATERAL_OFFSET; + // Calculate offsets scaled by model size and arm scale + double lateralX = -Math.sin(perpYaw) * FALLBACK_LATERAL * scale * armScale.scaleX; + double lateralZ = Math.cos(perpYaw) * FALLBACK_LATERAL * scale * armScale.scaleX; + double forwardX = -Math.sin(bodyYaw) * FALLBACK_FORWARD * scale * armScale.scaleZ; + double forwardZ = Math.cos(bodyYaw) * FALLBACK_FORWARD * scale * armScale.scaleZ; - // Forward offset (in facing direction) - double forwardX = -Math.sin(bodyYawRad) * ARM_FORWARD_OFFSET; - double forwardZ = Math.cos(bodyYawRad) * ARM_FORWARD_OFFSET; + // Arm length affects vertical position + double armLengthOffset = (1 - armScale.scaleY) * 0.3; - x += lateralX + forwardX; - y += eyeHeight * ARM_HEIGHT_MULT; - z += lateralZ + forwardZ; + double x = entity.posX + lateralX + forwardX; + double y = entity.posY + entity.height * ARM_HEIGHT - armLengthOffset; + double z = entity.posZ + lateralZ + forwardZ; return Vec3.createVectorHelper(x, y, z); } /** - * Get the height multiplier for a given anchor point. + * Get default height multiplier for an anchor point. */ public static float getHeightMultiplier(AnchorPoint anchor) { switch (anchor) { case FRONT: - return FRONT_HEIGHT_MULT; + return FRONT_HEIGHT; case CENTER: - return CENTER_HEIGHT_MULT; + return CENTER_HEIGHT; case RIGHT_HAND: case LEFT_HAND: - return ARM_HEIGHT_MULT; + return ARM_HEIGHT; case ABOVE_HEAD: - return ABOVE_HEAD_HEIGHT_MULT; + return ABOVE_HEAD_HEIGHT; case CHEST: - return CHEST_HEIGHT_MULT; + return CHEST_HEIGHT; default: - return FRONT_HEIGHT_MULT; + return FRONT_HEIGHT; } } } diff --git a/src/main/java/noppes/npcs/DataAbilities.java b/src/main/java/noppes/npcs/DataAbilities.java index a9c670647..92bb1241c 100644 --- a/src/main/java/noppes/npcs/DataAbilities.java +++ b/src/main/java/noppes/npcs/DataAbilities.java @@ -170,8 +170,8 @@ public class DataAbilities { currentAbility.onActiveTick(npc, target, npc.worldObj, currentAbility.getCurrentTick()); break; - case RECOVERY: - // Recovery phase - just wait + case DAZED: + // Dazed phase - NPC cannot attack, just wait for daze to end break; case IDLE: @@ -222,12 +222,10 @@ public class DataAbilities { releaseLockedRotation(); // Calculate cooldown: random(min, max) + ability offset - int baseCooldown = minCooldown; - if (maxCooldown > minCooldown) { - baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1); - } - int totalCooldown = baseCooldown + currentAbility.getCooldownTicks(); - cooldownEndTime = npc.worldObj.getTotalWorldTime() + totalCooldown; + int abilityCooldownOffset = currentAbility.getCooldownTicks(); + rollCooldown(); + // Add ability-specific cooldown offset + cooldownEndTime += abilityCooldownOffset; currentAbility = null; lastTarget = null; @@ -539,8 +537,8 @@ public class DataAbilities { /** * Interrupt the currently executing ability. - * The ability will transition to RECOVERY phase (dazed state) and continue ticking. - * When RECOVERY completes, the ability will move to IDLE and onAbilityComplete() is called. + * If interrupted during WINDUP, the ability will transition to DAZED phase. + * When DAZED completes, the ability will move to IDLE and onAbilityComplete() is called. */ public void interruptCurrentAbility(DamageSource source, float damage) { if (currentAbility != null) { @@ -559,10 +557,10 @@ public class DataAbilities { NpcAPI.EVENT_BUS.post(interruptEvent); currentAbility.onInterrupt(npc, source, damage); - currentAbility.interrupt(); // This now transitions to RECOVERY, not IDLE + currentAbility.interrupt(); // Transitions to DAZED if interrupted during WINDUP - // Don't clear currentAbility - let it tick through RECOVERY phase - // When RECOVERY ends and phase becomes IDLE, onAbilityComplete() will be called + // Don't clear currentAbility - let it tick through DAZED phase + // When DAZED ends and phase becomes IDLE, onAbilityComplete() will be called } } @@ -631,10 +629,13 @@ public class DataAbilities { /** * Reset all runtime state (cooldowns, current ability). * Called when NPC respawns or combat ends. + * Rolls cooldown so NPC doesn't immediately use an ability. */ public void reset() { stopCurrentAbility(); - resetCooldown(); + + // Roll cooldown so NPC doesn't immediately attack after reset + rollCooldown(); // Reset execution state on all abilities for (Ability ability : abilities) { @@ -642,6 +643,18 @@ public class DataAbilities { } } + /** + * Roll a new cooldown using the min/max range. + * Called after ability completes and on reset. + */ + private void rollCooldown() { + int baseCooldown = minCooldown; + if (maxCooldown > minCooldown) { + baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1); + } + cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown; + } + // ═══════════════════════════════════════════════════════════════════ // ABILITY LIST MANAGEMENT // ═══════════════════════════════════════════════════════════════════ @@ -706,7 +719,7 @@ public class DataAbilities { * Rules: * - WINDUP phase: Block AI if lockMovement is true * - ACTIVE phase: Block AI if lockMovement OR hasAbilityMovement is true - * - RECOVERY phase: Block AI if lockMovement is true + * - DAZED phase: Always block AI (NPC is stunned) */ public boolean isAbilityControllingMovement() { if (currentAbility == null || !currentAbility.isExecuting()) { @@ -727,9 +740,9 @@ public class DataAbilities { // - hasAbilityMovement is true (ability is moving the NPC itself) return currentAbility.isLockMovement() || currentAbility.hasAbilityMovement(); - case RECOVERY: - // During recovery, block if lockMovement is set - return currentAbility.isLockMovement(); + case DAZED: + // During dazed phase, always block - NPC is stunned from interrupt + return true; default: return false; @@ -739,7 +752,7 @@ public class DataAbilities { /** * Check if NPC's look direction should be locked to target. * Only locks during ACTIVE phase when lockMovement is true. - * This allows the NPC to freely track target during WINDUP and RECOVERY. + * This allows the NPC to freely track target during WINDUP and DAZED. */ public boolean shouldLockLookDirection() { if (currentAbility == null || !currentAbility.isExecuting()) { diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java index 6c5323707..040c999a4 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java @@ -61,8 +61,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi // Timing protected int cooldownTicks; protected int windUpTicks; - protected int activeTicks; - protected int recoveryTicks; + protected int dazedTicks; // ═══════════════════════════════════════════════════════════════════════════ // CACHED VALUES - Target Tab @@ -115,8 +114,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi // Timing this.cooldownTicks = ability.getCooldownTicks(); this.windUpTicks = ability.getWindUpTicks(); - this.activeTicks = ability.getActiveTicks(); - this.recoveryTicks = ability.getRecoveryTicks(); + this.dazedTicks = ability.getDazedTicks(); // Target this.minRange = ability.getMinRange(); @@ -254,42 +252,36 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi y += 24; - // Row 3: Interruptible + // Row 3: Interruptible + Dazed Ticks (only if interruptible) addLabel(new GuiNpcLabel(6, "ability.interruptible", col1LabelX, y + 5)); addButton(new GuiNpcButton(14, guiLeft + 85, y, 40, 20, new String[]{"gui.no", "gui.yes"}, interruptible ? 1 : 0)); + // Only show dazed ticks if interruptible is enabled + if (interruptible) { + addLabel(new GuiNpcLabel(12, "ability.dazed", col2LabelX, y + 5)); + GuiNpcTextField dazedField = new GuiNpcTextField(13, this, fontRendererObj, col2FieldX, y, 40, 20, String.valueOf(dazedTicks)); + dazedField.setIntegersOnly(); + dazedField.setMinMaxDefault(0, 1000, 80); + addTextField(dazedField); + } + y += 28; // Separator - Timing section header addLabel(new GuiNpcLabel(7, "ability.timing", col1LabelX, y)); y += 14; - // Row 4: Windup Ticks + Active Ticks + // Row 4: Windup Ticks + Cooldown Ticks addLabel(new GuiNpcLabel(10, "ability.windup", col1LabelX, y + 5)); GuiNpcTextField windupField = new GuiNpcTextField(11, this, fontRendererObj, col1FieldX, y, 40, 20, String.valueOf(windUpTicks)); windupField.setIntegersOnly(); windupField.setMinMaxDefault(0, 1000, 20); addTextField(windupField); - addLabel(new GuiNpcLabel(11, "ability.active", col2LabelX, y + 5)); - GuiNpcTextField activeField = new GuiNpcTextField(12, this, fontRendererObj, col2FieldX, y, 40, 20, String.valueOf(activeTicks)); - activeField.setIntegersOnly(); - activeField.setMinMaxDefault(1, 1000, 10); - addTextField(activeField); - - y += 24; - - // Row 5: Recovery Ticks + Cooldown Ticks - addLabel(new GuiNpcLabel(12, "ability.recovery", col1LabelX, y + 5)); - GuiNpcTextField recoveryField = new GuiNpcTextField(13, this, fontRendererObj, col1FieldX, y, 40, 20, String.valueOf(recoveryTicks)); - recoveryField.setIntegersOnly(); - recoveryField.setMinMaxDefault(0, 1000, 20); - addTextField(recoveryField); - addLabel(new GuiNpcLabel(13, "ability.cooldown", col2LabelX, y + 5)); GuiNpcTextField cooldownField = new GuiNpcTextField(10, this, fontRendererObj, col2FieldX, y, 40, 20, String.valueOf(cooldownTicks)); cooldownField.setIntegersOnly(); - cooldownField.setMinMaxDefault(0, 10000, 100); + cooldownField.setMinMaxDefault(0, 10000, 0); addTextField(cooldownField); } @@ -632,6 +624,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi // General tab buttons else if (id == 14) { interruptible = ((GuiNpcButton) guibutton).getValue() == 1; + initGui(); // Refresh to show/hide dazed ticks field } else if (id == 16) { lockMovement = ((GuiNpcButton) guibutton).getValue() == 1; } @@ -764,10 +757,8 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi cooldownTicks = textField.getInteger(); } else if (id == 11) { windUpTicks = textField.getInteger(); - } else if (id == 12) { - activeTicks = textField.getInteger(); } else if (id == 13) { - recoveryTicks = textField.getInteger(); + dazedTicks = textField.getInteger(); } // Visual-specific fields (200+) - delegate to subclass @@ -865,8 +856,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi // Timing ability.setCooldownTicks(cooldownTicks); ability.setWindUpTicks(windUpTicks); - ability.setActiveTicks(activeTicks); - ability.setRecoveryTicks(recoveryTicks); + ability.setDazedTicks(dazedTicks); // Target ability.setMinRange(minRange); @@ -914,8 +904,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi this.cooldownTicks = ability.getCooldownTicks(); this.windUpTicks = ability.getWindUpTicks(); - this.activeTicks = ability.getActiveTicks(); - this.recoveryTicks = ability.getRecoveryTicks(); + this.dazedTicks = ability.getDazedTicks(); this.minRange = ability.getMinRange(); this.maxRange = ability.getMaxRange(); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java index 10f5ab8c1..f3dbc64c7 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java @@ -68,8 +68,15 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig { y += 24; - // Row 5: Effects button - addButton(new GuiNpcButton(150, labelX, y, 80, 20, "ability.effects")); + // Row 5: Spin Duration (only for SPIN mode) + Effects button + if (cutter.getSweepMode() == AbilityCutter.SweepMode.SPIN) { + addLabel(new GuiNpcLabel(108, "ability.duration", labelX, y + 5)); + GuiNpcTextField durationField = createIntField(108, fieldX, y, 50, cutter.getSpinDurationTicks()); + durationField.setMinMaxDefault(1, 1000, 60); + addTextField(durationField); + } + + addButton(new GuiNpcButton(150, col2LabelX, y, 80, 20, "ability.effects")); } @Override @@ -78,6 +85,7 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig { switch (id) { case 106: cutter.setSweepMode(AbilityCutter.SweepMode.values()[value]); + initGui(); // Refresh to show/hide duration field break; case 107: cutter.setPiercing(value == 1); @@ -121,6 +129,9 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig { case 105: cutter.setSweepSpeed(parseFloat(field, cutter.getSweepSpeed())); break; + case 108: + cutter.setSpinDurationTicks(field.getInteger()); + break; } } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java index 25383c926..183d66814 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java @@ -31,9 +31,14 @@ public class SubGuiAbilityGuard extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 165; int col2FieldX = guiLeft + 225; - // Row 1: Damage Reduction - addLabel(new GuiNpcLabel(100, "ability.dmgReduce", labelX, y + 5)); - addTextField(createFloatField(100, fieldX, y, 50, guard.getDamageReduction())); + // Row 1: Duration + Damage Reduction + addLabel(new GuiNpcLabel(99, "ability.duration", labelX, y + 5)); + GuiNpcTextField durationField = createIntField(99, fieldX, y, 50, guard.getDurationTicks()); + durationField.setMinMaxDefault(1, 1000, 60); + addTextField(durationField); + + addLabel(new GuiNpcLabel(100, "ability.dmgReduce", col2LabelX, y + 5)); + addTextField(createFloatField(100, col2FieldX, y, 50, guard.getDamageReduction())); y += 24; @@ -112,6 +117,9 @@ public class SubGuiAbilityGuard extends SubGuiAbilityConfig { @Override protected void handleTypeTextField(int id, GuiNpcTextField field) { switch (id) { + case 99: + guard.setDurationTicks(field.getInteger()); + break; case 100: guard.setDamageReduction(parseFloat(field, guard.getDamageReduction())); break; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java index 8a91798d0..c9633c0f9 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java @@ -31,14 +31,22 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 145; int col2FieldX = guiLeft + 205; - // Row 1: Shape + Placement - addLabel(new GuiNpcLabel(100, "ability.shape", labelX, y + 5)); - String[] shapes = {"Circle", "Ring", "Cone"}; - addButton(new GuiNpcButton(100, fieldX, y, 55, 20, shapes, hazard.getShape().ordinal())); + // Row 1: Duration + Shape + addLabel(new GuiNpcLabel(99, "ability.duration", labelX, y + 5)); + GuiNpcTextField durationField = createIntField(99, fieldX, y, 50, hazard.getDurationTicks()); + durationField.setMinMaxDefault(1, 2000, 100); + addTextField(durationField); - addLabel(new GuiNpcLabel(101, "ability.placement", col2LabelX, y + 5)); + addLabel(new GuiNpcLabel(100, "ability.shape", col2LabelX, y + 5)); + String[] shapes = {"Circle", "Ring", "Cone"}; + addButton(new GuiNpcButton(100, col2FieldX, y, 55, 20, shapes, hazard.getShape().ordinal())); + + y += 24; + + // Row 2: Placement + addLabel(new GuiNpcLabel(101, "ability.placement", labelX, y + 5)); String[] placements = {"Caster", "Target", "FollowCast", "FollowTgt"}; - addButton(new GuiNpcButton(101, col2FieldX, y, 60, 20, placements, hazard.getPlacement().ordinal())); + addButton(new GuiNpcButton(101, fieldX, y, 70, 20, placements, hazard.getPlacement().ordinal())); y += 24; @@ -116,6 +124,9 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig { @Override protected void handleTypeTextField(int id, GuiNpcTextField field) { switch (id) { + case 99: + hazard.setDurationTicks(field.getInteger()); + break; case 102: hazard.setRadius(parseFloat(field, hazard.getRadius())); break; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java index 8b679fb25..010da51cf 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java @@ -27,7 +27,20 @@ public class SubGuiAbilityHeal extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 145; int col2FieldX = guiLeft + 205; - // Row 1: Heal Amount + Heal Percent + // Row 1: Instant Heal + Duration (only shown if not instant) + addLabel(new GuiNpcLabel(103, "dialog.instant", labelX, y + 5)); + addButton(new GuiNpcButton(103, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isInstantHeal() ? 1 : 0)); + + if (!heal.isInstantHeal()) { + addLabel(new GuiNpcLabel(99, "ability.duration", col2LabelX, y + 5)); + GuiNpcTextField durationField = createIntField(99, col2FieldX, y, 50, heal.getDurationTicks()); + durationField.setMinMaxDefault(1, 1000, 60); + addTextField(durationField); + } + + y += 24; + + // Row 2: Heal Amount + Heal Percent addLabel(new GuiNpcLabel(100, "ability.healAmount", labelX, y + 5)); addTextField(createFloatField(100, fieldX, y, 50, heal.getHealAmount())); @@ -36,16 +49,13 @@ public class SubGuiAbilityHeal extends SubGuiAbilityConfig { y += 24; - // Row 2: Heal Radius + Instant Heal + // Row 3: Heal Radius addLabel(new GuiNpcLabel(102, "ability.healRadius", labelX, y + 5)); addTextField(createFloatField(102, fieldX, y, 50, heal.getHealRadius())); - addLabel(new GuiNpcLabel(103, "dialog.instant", col2LabelX, y + 5)); - addButton(new GuiNpcButton(103, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isInstantHeal() ? 1 : 0)); - y += 24; - // Row 3: Heal Self + Heal Allies + // Row 4: Heal Self + Heal Allies addLabel(new GuiNpcLabel(104, "ability.healSelf", labelX, y + 5)); addButton(new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isHealSelf() ? 1 : 0)); @@ -59,6 +69,7 @@ public class SubGuiAbilityHeal extends SubGuiAbilityConfig { switch (id) { case 103: heal.setInstantHeal(value == 1); + initGui(); // Refresh to show/hide duration field break; case 104: heal.setHealSelf(value == 1); @@ -72,6 +83,9 @@ public class SubGuiAbilityHeal extends SubGuiAbilityConfig { @Override protected void handleTypeTextField(int id, GuiNpcTextField field) { switch (id) { + case 99: + heal.setDurationTicks(field.getInteger()); + break; case 100: heal.setHealAmount(parseFloat(field, heal.getHealAmount())); break; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java index 2c0fc3a68..c846565c4 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java @@ -31,13 +31,21 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig { int col2LabelX = guiLeft + 145; int col2FieldX = guiLeft + 205; - // Row 1: Placement + Trigger Radius - addLabel(new GuiNpcLabel(100, "ability.placement", labelX, y + 5)); - String[] placements = {"Caster", "Target", "Ahead"}; - addButton(new GuiNpcButton(100, fieldX, y, 55, 20, placements, trap.getPlacement().ordinal())); + // Row 1: Duration + Placement + addLabel(new GuiNpcLabel(99, "ability.duration", labelX, y + 5)); + GuiNpcTextField durationField = createIntField(99, fieldX, y, 50, trap.getDurationTicks()); + durationField.setMinMaxDefault(1, 2000, 200); + addTextField(durationField); - addLabel(new GuiNpcLabel(101, "ability.triggerRad", col2LabelX, y + 5)); - addTextField(createFloatField(101, col2FieldX, y, 50, trap.getTriggerRadius())); + addLabel(new GuiNpcLabel(100, "ability.placement", col2LabelX, y + 5)); + String[] placements = {"Caster", "Target", "Ahead"}; + addButton(new GuiNpcButton(100, col2FieldX, y, 55, 20, placements, trap.getPlacement().ordinal())); + + y += 24; + + // Row 2: Trigger Radius + addLabel(new GuiNpcLabel(101, "ability.triggerRad", labelX, y + 5)); + addTextField(createFloatField(101, fieldX, y, 50, trap.getTriggerRadius())); y += 24; @@ -90,6 +98,9 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig { @Override protected void handleTypeTextField(int id, GuiNpcTextField field) { switch (id) { + case 99: + trap.setDurationTicks(field.getInteger()); + break; case 101: trap.setTriggerRadius(parseFloat(field, trap.getTriggerRadius())); break; From 4330405f961283fab1058973f6c22f0a3721dbb7 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 27 Jan 2026 04:12:39 -0500 Subject: [PATCH 12/15] Fix Cooldown Logic --- src/api | 2 +- src/main/java/noppes/npcs/DataAbilities.java | 44 ++++++++++++++++---- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/api b/src/api index ae73e1b88..2054012fa 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit ae73e1b885415701c1ee20b64c1d0ae9c9089efc +Subproject commit 2054012fae799fa233b99824b4f649d311eff86f diff --git a/src/main/java/noppes/npcs/DataAbilities.java b/src/main/java/noppes/npcs/DataAbilities.java index 92bb1241c..0ff0aa8a1 100644 --- a/src/main/java/noppes/npcs/DataAbilities.java +++ b/src/main/java/noppes/npcs/DataAbilities.java @@ -166,8 +166,20 @@ public class DataAbilities { // Call onExecute currentAbility.onExecute(npc, target, npc.worldObj); + + // Check if ability completed during onExecute (signalCompletion was called) + if (currentAbility.getPhase() == AbilityPhase.IDLE) { + handleAbilityCompletion(target); + return; + } } currentAbility.onActiveTick(npc, target, npc.worldObj, currentAbility.getCurrentTick()); + + // Check if ability completed during onActiveTick (signalCompletion was called) + if (currentAbility.getPhase() == AbilityPhase.IDLE) { + handleAbilityCompletion(target); + return; + } break; case DAZED: @@ -175,17 +187,31 @@ public class DataAbilities { break; case IDLE: - // Ability completed - currentAbility.onComplete(npc, target); - - // Fire complete event - AbilityEvent.CompleteEvent completeEvent = new AbilityEvent.CompleteEvent( - npc.wrappedNPC, currentAbility, target); - NpcAPI.EVENT_BUS.post(completeEvent); - - onAbilityComplete(); + // Ability completed (reached via tick() phase transition from DAZED) + handleAbilityCompletion(target); break; } + } + + /** + * Handle ability completion - called when ability phase becomes IDLE. + * This can happen from: + * - signalCompletion() called in onExecute() or onActiveTick() + * - tick() transitioning from DAZED to IDLE + */ + private void handleAbilityCompletion(EntityLivingBase target) { + if (currentAbility == null) return; + + // Call onComplete callback + currentAbility.onComplete(npc, target); + + // Fire complete event + AbilityEvent.CompleteEvent completeEvent = new AbilityEvent.CompleteEvent( + npc.wrappedNPC, currentAbility, target); + NpcAPI.EVENT_BUS.post(completeEvent); + + // Clean up and roll cooldown + onAbilityComplete(); // Clear AI pathfinding if ability is controlling movement // But DON'T zero motion - let the ability set it if needed From 76fb9ee52fdf194d2102967ab246ac1f83eb5f53 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 27 Jan 2026 14:46:17 -0500 Subject: [PATCH 13/15] Fix Dazed Ticks and other smaller issues --- .../data/ability/type/AbilityDash.java | 14 +++---- .../data/ability/type/AbilityGuard.java | 6 +-- .../data/ability/type/AbilityHeal.java | 27 ++++++------- .../data/ability/type/AbilityTeleport.java | 5 ++- .../data/ability/type/AbilityVortex.java | 39 +++++++++---------- .../assets/customnpcs/lang/en_US.lang | 3 +- 6 files changed, 44 insertions(+), 50 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java index 586e402a8..cd4d42ac7 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDash.java @@ -199,8 +199,6 @@ public class AbilityDash extends Ability { npc.motionX = 0; npc.motionZ = 0; npc.velocityChanged = true; - dashDirection = null; - chosenDirection = null; } @Override @@ -208,23 +206,21 @@ public class AbilityDash extends Ability { npc.motionX = 0; npc.motionZ = 0; npc.velocityChanged = true; + } + + @Override + public void cleanup() { dashDirection = null; chosenDirection = null; } private boolean isDashBlocked(EntityNPCInterface npc) { + if (dashDirection == null) return true; double nextX = dashDirection.xCoord * dashSpeed; double nextZ = dashDirection.zCoord * dashSpeed; return !npc.worldObj.getCollidingBoundingBoxes(npc, npc.boundingBox.copy().offset(nextX, 0, nextZ)).isEmpty(); } - @Override - public void reset() { - super.reset(); - dashDirection = null; - chosenDirection = null; - } - @Override public float getTelegraphRadius() { return 0; // No telegraph for dash diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java index 831ef97fd..fd9f25a24 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityGuard.java @@ -116,11 +116,7 @@ public class AbilityGuard extends Ability { lastAttacker = attacker; lastDamageTaken = damage; counterTriggered = true; - - if (interruptible) { - performCounter(npc, npc.worldObj); - npc.abilities.interruptCurrentAbility(source, damage); - } + // Counter will be performed in onActiveTick - don't self-interrupt } private void performCounter(EntityNPCInterface npc, World world) { diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java index 59ef4751a..f19a7cb02 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHeal.java @@ -34,7 +34,14 @@ public class AbilityHeal extends Ability { private boolean instantHeal = true; // Runtime state - private transient List healedAllies = new ArrayList<>(); + private transient List healedAllies; + + private List getHealedAllies() { + if (healedAllies == null) { + healedAllies = new ArrayList<>(); + } + return healedAllies; + } public AbilityHeal() { this.typeId = "ability.cnpc.heal"; @@ -73,7 +80,7 @@ public class AbilityHeal extends Ability { public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { if (world.isRemote) return; - healedAllies.clear(); + getHealedAllies().clear(); // Always find allies if we're healing them (needed for both instant and HoT) if (healAllies && healRadius > 0) { @@ -87,7 +94,7 @@ public class AbilityHeal extends Ability { spawnHealParticles(world, npc); } - for (EntityLivingBase ally : healedAllies) { + for (EntityLivingBase ally : getHealedAllies()) { healEntity(ally); spawnHealParticles(world, ally); } @@ -120,7 +127,7 @@ public class AbilityHeal extends Ability { } if (healAllies && healRadius > 0) { - for (EntityLivingBase ally : healedAllies) { + for (EntityLivingBase ally : getHealedAllies()) { if (!ally.isDead) { float allyTickHeal = tickHeal; // Add percentage-based heal portion for each ally @@ -164,7 +171,7 @@ public class AbilityHeal extends Ability { if (living instanceof EntityNPCInterface) { float dist = npc.getDistanceToEntity(living); if (dist <= healRadius) { - healedAllies.add(living); + getHealedAllies().add(living); } } } @@ -192,14 +199,8 @@ public class AbilityHeal extends Ability { } @Override - public void onInterrupt(EntityNPCInterface npc, net.minecraft.util.DamageSource source, float damage) { - healedAllies.clear(); - } - - @Override - public void reset() { - super.reset(); - healedAllies.clear(); + public void cleanup() { + getHealedAllies().clear(); } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java index 668b2f04d..218432fc9 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTeleport.java @@ -374,7 +374,10 @@ public class AbilityTeleport extends Ability { double dist = Math.sqrt(Math.pow(living.posX - x, 2) + Math.pow(living.posZ - z, 2)); if (dist <= damageRadius) { // Apply damage with scripted event support (no knockback for teleport damage) - applyAbilityDamage(npc, living, damage, 0); + boolean wasHit = applyAbilityDamage(npc, living, damage, 0); + if (wasHit) { + applyEffects(living); + } } } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java index 70c1c96b7..fef61779e 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityVortex.java @@ -8,7 +8,6 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphType; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.DamageSource; import net.minecraft.world.World; import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig; import noppes.npcs.client.gui.advanced.ability.SubGuiAbilityVortex; @@ -36,10 +35,17 @@ public class AbilityVortex extends Ability { private float pullDamage = 0.0f; // Runtime state - private transient Set pulledEntities = new HashSet<>(); + private transient Set pulledEntities; private transient boolean pullComplete = false; private transient int ticksSincePullDamage = 0; + private Set getPulledEntities() { + if (pulledEntities == null) { + pulledEntities = new HashSet<>(); + } + return pulledEntities; + } + public AbilityVortex() { this.typeId = "ability.cnpc.vortex"; this.name = "Vortex"; @@ -82,7 +88,7 @@ public class AbilityVortex extends Ability { @Override public void onExecute(EntityNPCInterface npc, EntityLivingBase target, World world) { - pulledEntities.clear(); + getPulledEntities().clear(); pullComplete = false; ticksSincePullDamage = 0; @@ -98,7 +104,7 @@ public class AbilityVortex extends Ability { double dist = npc.getDistanceToEntity(entity); if (dist <= pullRadius) { - pulledEntities.add(entity.getUniqueID()); + getPulledEntities().add(entity.getUniqueID()); count++; if (count >= maxTargets) break; } @@ -108,7 +114,7 @@ public class AbilityVortex extends Ability { if (target != null && !target.isDead) { double dist = npc.getDistanceToEntity(target); if (dist <= pullRadius) { - pulledEntities.add(target.getUniqueID()); + getPulledEntities().add(target.getUniqueID()); } } } @@ -116,7 +122,7 @@ public class AbilityVortex extends Ability { @Override public void onActiveTick(EntityNPCInterface npc, EntityLivingBase target, World world, int tick) { - if (pullComplete || pulledEntities.isEmpty()) { + if (pullComplete || getPulledEntities().isEmpty()) { signalCompletion(); return; } @@ -128,10 +134,10 @@ public class AbilityVortex extends Ability { boolean anyStillPulling = false; ticksSincePullDamage++; - for (UUID uuid : new HashSet<>(pulledEntities)) { + for (UUID uuid : new HashSet<>(getPulledEntities())) { EntityLivingBase entity = findEntity(npc, world, uuid); if (entity == null || entity.isDead) { - pulledEntities.remove(uuid); + getPulledEntities().remove(uuid); continue; } @@ -141,7 +147,7 @@ public class AbilityVortex extends Ability { double dist = Math.sqrt(dx * dx + dy * dy + dz * dz); if (dist <= 1.0f) { - pulledEntities.remove(uuid); + getPulledEntities().remove(uuid); onTargetArrived(npc, entity, world); continue; } @@ -155,7 +161,7 @@ public class AbilityVortex extends Ability { AxisAlignedBB nextBox = entity.boundingBox.copy().offset(nextX, nextY, nextZ); if (!world.getCollidingBoundingBoxes(entity, nextBox).isEmpty()) { - pulledEntities.remove(uuid); + getPulledEntities().remove(uuid); continue; } @@ -171,7 +177,7 @@ public class AbilityVortex extends Ability { } } - if (!anyStillPulling && pulledEntities.isEmpty()) { + if (!anyStillPulling && getPulledEntities().isEmpty()) { pullComplete = true; signalCompletion(); } @@ -206,15 +212,8 @@ public class AbilityVortex extends Ability { } @Override - public void onComplete(EntityNPCInterface npc, EntityLivingBase target) { - pulledEntities.clear(); - pullComplete = false; - ticksSincePullDamage = 0; - } - - @Override - public void onInterrupt(EntityNPCInterface npc, DamageSource source, float damage) { - pulledEntities.clear(); + public void cleanup() { + getPulledEntities().clear(); pullComplete = false; ticksSincePullDamage = 0; } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 01e3ae541..8ac2d99c0 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1512,8 +1512,7 @@ ability.maxRange=Max Range ability.timing=Timing (ticks) ability.cooldown=Cooldown ability.windup=Wind Up -ability.active=Active -ability.recovery=Recovery +ability.dazed=Dazed Ticks ability.interruptible=Interruptible ability.threshold=Threshold ability.lockMove=Lock Move From 6d39b3c0267cb78a0b6488e548061a61b503fcc5 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 27 Jan 2026 15:21:59 -0500 Subject: [PATCH 14/15] Fix Anchor Points for Animations --- .../kamkeel/npcs/util/AnchorPointHelper.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java index 593c8aa19..79ad2cea4 100644 --- a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java +++ b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java @@ -178,33 +178,33 @@ public class AnchorPointHelper { float palmY = PALM_DOWN * armScale.scaleY; float palmZ = PALM_FORWARD * armScale.scaleZ; - // Apply arm rotations (order: Z -> Y -> X) + // Apply arm rotations (order: X -> Y -> Z, matching GL's reverse application) double hx = palmX, hy = palmY, hz = palmZ; - // Z rotation - double cosZ = Math.cos(rotations[2]); - double sinZ = Math.sin(rotations[2]); - double newX = hx * cosZ - hy * sinZ; - double newY = hx * sinZ + hy * cosZ; - hx = newX; - hy = newY; - - // Y rotation - double cosY = Math.cos(rotations[1]); - double sinY = Math.sin(rotations[1]); - newX = hx * cosY + hz * sinY; - double newZ = -hx * sinY + hz * cosY; - hx = newX; - hz = newZ; - - // X rotation + // X rotation first double cosX = Math.cos(rotations[0]); double sinX = Math.sin(rotations[0]); - newY = hy * cosX - hz * sinX; - newZ = hy * sinX + hz * cosX; + double newY = hy * cosX - hz * sinX; + double newZ = hy * sinX + hz * cosX; hy = newY; hz = newZ; + // Y rotation second + double cosY = Math.cos(rotations[1]); + double sinY = Math.sin(rotations[1]); + double newX = hx * cosY + hz * sinY; + newZ = -hx * sinY + hz * cosY; + hx = newX; + hz = newZ; + + // Z rotation last + double cosZ = Math.cos(rotations[2]); + double sinZ = Math.sin(rotations[2]); + newX = hx * cosZ - hy * sinZ; + newY = hx * sinZ + hy * cosZ; + hx = newX; + hy = newY; + // Combine shoulder + rotated hand offset double modelX = shoulderX + hx; double modelY = shoulderY + hy; @@ -216,12 +216,15 @@ public class AnchorPointHelper { double blockZ = modelZ * MODEL_SCALE * scale; // Apply body yaw rotation + // Renderer uses glRotate(180 - yaw), so: cos(180-yaw) = -cos(yaw), sin(180-yaw) = sin(yaw) + // Y-axis rotation: x' = x*cos + z*sin, z' = -x*sin + z*cos + // Substituting: x' = -x*cos(yaw) + z*sin(yaw), z' = -x*sin(yaw) - z*cos(yaw) float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); double cosYaw = Math.cos(bodyYaw); double sinYaw = Math.sin(bodyYaw); double worldOffsetX = blockX * cosYaw + blockZ * sinYaw; - double worldOffsetZ = -blockX * sinYaw + blockZ * cosYaw; + double worldOffsetZ = blockX * sinYaw - blockZ * cosYaw; // Calculate shoulder height based on entity and scale float shoulderHeight = entity.height * ARM_HEIGHT; From c6810c05eae419986345ff31853c108913f5be4e Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 27 Jan 2026 16:43:47 -0500 Subject: [PATCH 15/15] More Ability Fixes. --- .../data/ability/type/AbilitySweeper.java | 4 +- .../kamkeel/npcs/util/AnchorPointHelper.java | 29 ++++--- .../npcs/client/gui/SubGuiColorSelector.java | 6 +- .../client/gui/advanced/GuiNPCAbilities.java | 29 ++++++- .../gui/advanced/SubGuiAbilityConfig.java | 85 +++++++++++++++---- .../advanced/ability/SubGuiAbilityCutter.java | 8 +- .../advanced/ability/SubGuiAbilityDash.java | 4 +- .../advanced/ability/SubGuiAbilityDisc.java | 47 +++++++--- .../ability/SubGuiAbilityEnergyBeam.java | 46 ++++++---- .../advanced/ability/SubGuiAbilityGuard.java | 5 +- .../advanced/ability/SubGuiAbilityHazard.java | 12 ++- .../advanced/ability/SubGuiAbilityHeal.java | 12 ++- .../ability/SubGuiAbilityLaserShot.java | 17 ++-- .../advanced/ability/SubGuiAbilityOrb.java | 34 +++++--- .../ability/SubGuiAbilityProjectile.java | 26 ++++-- .../ability/SubGuiAbilitySweeper.java | 8 +- .../ability/SubGuiAbilityTeleport.java | 16 +++- .../advanced/ability/SubGuiAbilityTrap.java | 4 +- .../advanced/ability/SubGuiAbilityVortex.java | 8 +- .../gui/select/GuiAnimationSelection.java | 5 +- .../npcs/client/gui/util/GuiNPCInterface.java | 47 +++++++--- .../assets/customnpcs/lang/en_US.lang | 49 ++++++++++- 22 files changed, 378 insertions(+), 123 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java index ca41ed6e3..5a61c5dce 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilitySweeper.java @@ -30,7 +30,7 @@ public class AbilitySweeper extends Ability { // Type-specific parameters private float beamLength = 10.0f; private float beamWidth = 0.3f; // Thin like beam trail - private float beamHeight = 0.8f; // Height above ground (low enough to jump over) + private float beamHeight = 0.5f; // Height above ground (low enough to jump over) private float damage = 5.0f; private int damageInterval = 5; private boolean piercing = true; @@ -172,7 +172,7 @@ public class AbilitySweeper extends Ability { public void readTypeNBT(NBTTagCompound nbt) { this.beamLength = nbt.hasKey("beamLength") ? nbt.getFloat("beamLength") : 10.0f; this.beamWidth = nbt.hasKey("beamWidth") ? nbt.getFloat("beamWidth") : 0.3f; - this.beamHeight = nbt.hasKey("beamHeight") ? nbt.getFloat("beamHeight") : 0.8f; + this.beamHeight = nbt.hasKey("beamHeight") ? nbt.getFloat("beamHeight") : 0.5f; this.damage = nbt.hasKey("damage") ? nbt.getFloat("damage") : 5.0f; this.damageInterval = nbt.hasKey("damageInterval") ? nbt.getInteger("damageInterval") : 5; this.piercing = !nbt.hasKey("piercing") || nbt.getBoolean("piercing"); diff --git a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java index 79ad2cea4..45e4f3eab 100644 --- a/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java +++ b/src/main/java/kamkeel/npcs/util/AnchorPointHelper.java @@ -40,9 +40,10 @@ public class AnchorPointHelper { // Distance in front for FRONT anchor private static final float DEFAULT_FRONT_DISTANCE = 1.0f; - // Fallback arm positioning (when no animation) - private static final float FALLBACK_LATERAL = 0.35f; - private static final float FALLBACK_FORWARD = 0.3f; + // Fallback arm positioning (when no animation, arms hang at sides) + private static final float FALLBACK_LATERAL = 0.35f; // Distance from body center to arm + private static final float FALLBACK_FORWARD = 0.1f; // Slight forward offset + private static final float FALLBACK_ARM_HEIGHT = 0.45f; // Hand height when arms hang down (near hip) /** * Calculate world position for an anchor point on an entity. @@ -274,6 +275,7 @@ public class AnchorPointHelper { /** * Calculate fallback hand position when no animation is active. + * Represents arms hanging at sides in default idle pose. */ private static Vec3 calculateFallbackHandPosition(EntityLivingBase entity, boolean rightHand, float scale) { float bodyYaw = (float) Math.toRadians(entity.renderYawOffset); @@ -281,20 +283,23 @@ public class AnchorPointHelper { // Get arm scale for EntityCustomNpc ModelScalePart armScale = getArmScale(entity); - // Perpendicular direction for lateral offset + // Perpendicular direction for lateral offset (right = +90°, left = -90° from body facing) float perpYaw = bodyYaw + (rightHand ? (float) (Math.PI / 2) : (float) (-Math.PI / 2)); - // Calculate offsets scaled by model size and arm scale - double lateralX = -Math.sin(perpYaw) * FALLBACK_LATERAL * scale * armScale.scaleX; - double lateralZ = Math.cos(perpYaw) * FALLBACK_LATERAL * scale * armScale.scaleX; - double forwardX = -Math.sin(bodyYaw) * FALLBACK_FORWARD * scale * armScale.scaleZ; - double forwardZ = Math.cos(bodyYaw) * FALLBACK_FORWARD * scale * armScale.scaleZ; + // Calculate lateral offset - arms hang at sides + // Scale by model size, but not by arm scale (lateral distance is fixed by skeleton) + double lateralX = -Math.sin(perpYaw) * FALLBACK_LATERAL * scale; + double lateralZ = Math.cos(perpYaw) * FALLBACK_LATERAL * scale; - // Arm length affects vertical position - double armLengthOffset = (1 - armScale.scaleY) * 0.3; + // Small forward offset + double forwardX = -Math.sin(bodyYaw) * FALLBACK_FORWARD * scale; + double forwardZ = Math.cos(bodyYaw) * FALLBACK_FORWARD * scale; + + // Arm length affects vertical position - longer arms = lower hands + double armLengthOffset = armScale.scaleY * 0.3 * scale; double x = entity.posX + lateralX + forwardX; - double y = entity.posY + entity.height * ARM_HEIGHT - armLengthOffset; + double y = entity.posY + entity.height * FALLBACK_ARM_HEIGHT + armLengthOffset; double z = entity.posZ + lateralZ + forwardZ; return Vec3.createVectorHelper(x, y, z); diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiColorSelector.java b/src/main/java/noppes/npcs/client/gui/SubGuiColorSelector.java index 947825f5a..be8c07f8a 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiColorSelector.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiColorSelector.java @@ -25,10 +25,10 @@ public class SubGuiColorSelector extends SubGuiInterface implements ITextfieldLi public int color; public SubGuiColorSelector(int color) { - xSize = 176; + xSize = 182; ySize = 222; this.color = color; - setBackground("smallbg.png"); + setBackground("menubg.png"); } @Override @@ -40,7 +40,7 @@ public class SubGuiColorSelector extends SubGuiInterface implements ITextfieldLi this.addTextField(textfield = new GuiNpcTextField(0, this, guiLeft + 53, guiTop + 20, 70, 20, getColor())); textfield.setTextColor(color); - addButton(new GuiNpcButton(66, guiLeft + 112, guiTop + 198, 60, 20, "gui.done")); + addButton(new GuiNpcButton(66, guiLeft + 112, guiTop + 175, 60, 20, "gui.done")); } public String getColor() { diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAbilities.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAbilities.java index c0fb15596..9abcebbe7 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAbilities.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAbilities.java @@ -73,15 +73,15 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC addLabel(new GuiNpcLabel(100, "gui.enabled", guiLeft + 5, y + 5)); addButton(new GuiNpcButton(100, guiLeft + 55, y, 50, 20, new String[]{"gui.no", "gui.yes"}, abilitiesEnabled ? 1 : 0)); - // Cooldown range: Min Cooldown and Max Cooldown + // Cooldown range: Min Cooldown and Max Cooldown (spaced apart more) addLabel(new GuiNpcLabel(101, "ability.minCooldown", guiLeft + 115, y + 5)); - GuiNpcTextField minField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 185, y, 40, 20, String.valueOf(minCooldown)); + GuiNpcTextField minField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 165, y, 40, 20, String.valueOf(minCooldown)); minField.setIntegersOnly(); minField.setMinMaxDefault(0, 10000, 20); addTextField(minField); - addLabel(new GuiNpcLabel(102, "ability.maxCooldown", guiLeft + 235, y + 5)); - GuiNpcTextField maxField = new GuiNpcTextField(102, this, fontRendererObj, guiLeft + 305, y, 40, 20, String.valueOf(maxCooldown)); + addLabel(new GuiNpcLabel(102, "ability.maxCooldown", guiLeft + 260, y + 5)); + GuiNpcTextField maxField = new GuiNpcTextField(102, this, fontRendererObj, guiLeft + 310, y, 40, 20, String.valueOf(maxCooldown)); maxField.setIntegersOnly(); maxField.setMinMaxDefault(0, 10000, 60); addTextField(maxField); @@ -123,6 +123,14 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC // Load button (under the add/remove arrows) addButton(new GuiNpcButton(75, centerX, y + 90, 40, 20, "gui.load")); + // On/Off toggle for selected ability (under Load button) + if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) { + Ability selectedAbility = npcAbilities.get(selectedAbilityIndex); + GuiNpcButton toggleBtn = new GuiNpcButton(77, centerX, y + 112, 40, 20, + new String[]{"gui.off", "gui.on"}, selectedAbility.isEnabled() ? 1 : 0); + addButton(toggleBtn); + } + // Right side buttons: Edit and Up/Down carrots with Save button addButton(new GuiNpcButton(72, guiLeft + 210, y + 145, 55, 20, "gui.edit")); getButton(72).setEnabled(selectedAbilityIndex >= 0); @@ -243,6 +251,19 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC return; } + // Toggle selected ability on/off + if (id == 77) { + if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) { + Ability ability = npcAbilities.get(selectedAbilityIndex); + ability.setEnabled(((GuiNpcButton) guibutton).getValue() == 1); + updateNpcAbilitiesList(); + selectAbilityByIndex(selectedAbilityIndex); + initGui(); + save(); + } + return; + } + initGui(); } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java index 040c999a4..831420473 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityConfig.java @@ -4,6 +4,9 @@ import kamkeel.npcs.controllers.data.ability.Ability; import kamkeel.npcs.controllers.data.ability.Condition; import kamkeel.npcs.controllers.data.ability.TargetingMode; import kamkeel.npcs.controllers.data.telegraph.TelegraphType; +import noppes.npcs.controllers.data.Animation; +import noppes.npcs.controllers.data.Frame; +import noppes.npcs.controllers.AnimationController; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; @@ -140,7 +143,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi this.hasTypeSettings = ability.hasTypeSettings(); this.hasVisualSettings = hasVisualSettings(); - setBackground("menubg.png"); + setBackground("menubg.png", 217); xSize = 356; ySize = 200; } @@ -248,13 +251,17 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi addTextField(weightField); addLabel(new GuiNpcLabel(5, "ability.lockMove", col2LabelX, y + 5)); - addButton(new GuiNpcButton(16, col2FieldX, y, 40, 20, new String[]{"gui.no", "gui.yes"}, lockMovement ? 1 : 0)); + GuiNpcButton lockMoveBtn = new GuiNpcButton(16, col2FieldX, y, 40, 20, new String[]{"gui.no", "gui.yes"}, lockMovement ? 1 : 0); + lockMoveBtn.setHoverText("ability.hover.lockMove"); + addButton(lockMoveBtn); y += 24; // Row 3: Interruptible + Dazed Ticks (only if interruptible) addLabel(new GuiNpcLabel(6, "ability.interruptible", col1LabelX, y + 5)); - addButton(new GuiNpcButton(14, guiLeft + 85, y, 40, 20, new String[]{"gui.no", "gui.yes"}, interruptible ? 1 : 0)); + GuiNpcButton interruptBtn = new GuiNpcButton(14, guiLeft + 85, y, 40, 20, new String[]{"gui.no", "gui.yes"}, interruptible ? 1 : 0); + interruptBtn.setHoverText("ability.hover.interruptible"); + addButton(interruptBtn); // Only show dazed ticks if interruptible is enabled if (interruptible) { @@ -278,6 +285,13 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi windupField.setMinMaxDefault(0, 1000, 20); addTextField(windupField); + // Sync button - only show if windup animation is selected + if (windUpAnimationId >= 0) { + GuiNpcButton syncBtn = new GuiNpcButton(17, guiLeft + 115, y, 40, 20, "gui.sync"); + syncBtn.setHoverText("ability.hover.sync"); + addButton(syncBtn); + } + addLabel(new GuiNpcLabel(13, "ability.cooldown", col2LabelX, y + 5)); GuiNpcTextField cooldownField = new GuiNpcTextField(10, this, fontRendererObj, col2FieldX, y, 40, 20, String.valueOf(cooldownTicks)); cooldownField.setIntegersOnly(); @@ -387,7 +401,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi if (!targetingModeLocked) { String[] targetingModes = getAvailableTargetingModes(); int selectedIndex = getTargetingModeIndex(targetingMode); - addButton(new GuiNpcButton(4, col1FieldX, y, 90, 20, targetingModes, selectedIndex)); + GuiNpcButton targetBtn = new GuiNpcButton(4, col1FieldX, y, 90, 20, targetingModes, selectedIndex); + targetBtn.setHoverText("ability.hover.targeting"); + addButton(targetBtn); } else { String modeName = "ability.target." + targetingMode.name().toLowerCase(); addLabel(new GuiNpcLabel(23, modeName, col1FieldX, y + 5)); @@ -534,7 +550,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi // Show Telegraph addLabel(new GuiNpcLabel(41, "ability.showTelegraph", col1LabelX, y + 5)); - addButton(new GuiNpcButton(20, guiLeft + 95, y, 40, 20, new String[]{"gui.no", "gui.yes"}, showTelegraph ? 1 : 0)); + GuiNpcButton telegraphBtn = new GuiNpcButton(20, guiLeft + 95, y, 40, 20, new String[]{"gui.no", "gui.yes"}, showTelegraph ? 1 : 0); + telegraphBtn.setHoverText("ability.hover.showTelegraph"); + addButton(telegraphBtn); // Telegraph Type (separate column) String typeKey = ability.getTelegraphType().name().toLowerCase(); @@ -544,20 +562,20 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi y += 24; - // Colors - addLabel(new GuiNpcLabel(44, "ability.windUpColor", col1LabelX, y + 5)); - String windUpHex = String.format("%06X", windUpColor & 0xFFFFFF); - GuiNpcButton windUpColorBtn = new GuiNpcButton(22, guiLeft + 95, y, 55, 20, windUpHex); - windUpColorBtn.setEnabled(showTelegraph); - windUpColorBtn.setTextColor(windUpColor & 0xFFFFFF); - addButton(windUpColorBtn); + // Colors - only show when telegraph is enabled + if (showTelegraph) { + addLabel(new GuiNpcLabel(44, "ability.windUpColor", col1LabelX, y + 5)); + String windUpHex = String.format("%06X", windUpColor & 0xFFFFFF); + GuiNpcButton windUpColorBtn = new GuiNpcButton(22, guiLeft + 95, y, 55, 20, windUpHex); + windUpColorBtn.setTextColor(windUpColor & 0xFFFFFF); + addButton(windUpColorBtn); - addLabel(new GuiNpcLabel(45, "ability.activeColor", guiLeft + 200, y + 5)); - String activeHex = String.format("%06X", activeColor & 0xFFFFFF); - GuiNpcButton activeColorBtn = new GuiNpcButton(24, guiLeft + 280, y, 55, 20, activeHex); - activeColorBtn.setEnabled(showTelegraph); - activeColorBtn.setTextColor(activeColor & 0xFFFFFF); - addButton(activeColorBtn); + addLabel(new GuiNpcLabel(45, "ability.activeColor", guiLeft + 200, y + 5)); + String activeHex = String.format("%06X", activeColor & 0xFFFFFF); + GuiNpcButton activeColorBtn = new GuiNpcButton(24, guiLeft + 280, y, 55, 20, activeHex); + activeColorBtn.setTextColor(activeColor & 0xFFFFFF); + addButton(activeColorBtn); + } } } @@ -627,6 +645,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi initGui(); // Refresh to show/hide dazed ticks field } else if (id == 16) { lockMovement = ((GuiNpcButton) guibutton).getValue() == 1; + } else if (id == 17) { + // Sync windup ticks with animation duration + syncWindupWithAnimation(); } // Target tab - Targeting mode @@ -918,6 +939,34 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi initGui(); } + // ═══════════════════════════════════════════════════════════════════════════ + // SYNC ANIMATION + // ═══════════════════════════════════════════════════════════════════════════ + + /** + * Syncs windup ticks with the selected windup animation's total duration. + */ + private void syncWindupWithAnimation() { + if (windUpAnimationId < 0 || AnimationController.Instance == null) { + return; + } + + Animation animation = (Animation) AnimationController.Instance.get(windUpAnimationId); + if (animation == null || animation.frames.isEmpty()) { + return; + } + + // Calculate total duration by summing all frame durations + int totalDuration = 0; + for (Frame frame : animation.frames) { + totalDuration += frame.getDuration(); + } + + // Update the cached value and refresh GUI + windUpTicks = totalDuration; + initGui(); + } + // ═══════════════════════════════════════════════════════════════════════════ // HELPER METHODS FOR SUBCLASSES // ═══════════════════════════════════════════════════════════════════════════ diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java index f3dbc64c7..f10c63eef 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityCutter.java @@ -61,10 +61,14 @@ public class SubGuiAbilityCutter extends SubGuiAbilityConfig { // Row 4: Sweep Mode + Piercing addLabel(new GuiNpcLabel(106, "ability.sweepMode", labelX, y + 5)); String[] sweepModes = {"Swipe", "Spin"}; - addButton(new GuiNpcButton(106, fieldX, y, 70, 20, sweepModes, cutter.getSweepMode().ordinal())); + GuiNpcButton sweepModeBtn = new GuiNpcButton(106, fieldX, y, 70, 20, sweepModes, cutter.getSweepMode().ordinal()); + sweepModeBtn.setHoverText("ability.hover.sweepMode"); + addButton(sweepModeBtn); addLabel(new GuiNpcLabel(107, "ability.piercing", col2LabelX, y + 5)); - addButton(new GuiNpcButton(107, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, cutter.isPiercing() ? 1 : 0)); + GuiNpcButton piercingBtn = new GuiNpcButton(107, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, cutter.isPiercing() ? 1 : 0); + piercingBtn.setHoverText("ability.hover.piercing"); + addButton(piercingBtn); y += 24; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDash.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDash.java index 26bfd6610..f113b3c1c 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDash.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDash.java @@ -30,7 +30,9 @@ public class SubGuiAbilityDash extends SubGuiAbilityConfig { // Row 1: Dash Mode addLabel(new GuiNpcLabel(100, "ability.mode", labelX, y + 5)); String[] dashModes = {"Aggressive", "Defensive"}; - addButton(new GuiNpcButton(100, fieldX, y, 80, 20, dashModes, dash.getDashMode().ordinal())); + GuiNpcButton modeBtn = new GuiNpcButton(100, fieldX, y, 80, 20, dashModes, dash.getDashMode().ordinal()); + modeBtn.setHoverText("ability.hover.dashMode"); + addButton(modeBtn); y += 24; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java index 33c5372fd..2b804d99b 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityDisc.java @@ -57,30 +57,42 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { y += 24; - // Row 3: Homing + Homing Strength + // Row 3: Homing + Homing Strength (only show strength if homing) addLabel(new GuiNpcLabel(104, "ability.homing", labelX, y + 5)); - addButton(new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.isHoming() ? 1 : 0)); + GuiNpcButton homingBtn = new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.isHoming() ? 1 : 0); + homingBtn.setHoverText("ability.hover.homing"); + addButton(homingBtn); - addLabel(new GuiNpcLabel(105, "ability.homingStr", col2LabelX, y + 5)); - addTextField(createFloatField(105, col2FieldX, y, 50, disc.getHomingStrength())); + if (disc.isHoming()) { + addLabel(new GuiNpcLabel(105, "ability.homingStr", col2LabelX, y + 5)); + addTextField(createFloatField(105, col2FieldX, y, 50, disc.getHomingStrength())); + } y += 24; - // Row 4: Boomerang + Boomerang Delay + // Row 4: Boomerang + Boomerang Delay (only show delay if boomerang) addLabel(new GuiNpcLabel(106, "ability.boomerang", labelX, y + 5)); - addButton(new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.isBoomerang() ? 1 : 0)); + GuiNpcButton boomerangBtn = new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.isBoomerang() ? 1 : 0); + boomerangBtn.setHoverText("ability.hover.boomerang"); + addButton(boomerangBtn); - addLabel(new GuiNpcLabel(107, "ability.boomerangDelay", col2LabelX, y + 5)); - addTextField(createIntField(107, col2FieldX, y, 50, disc.getBoomerangDelay())); + if (disc.isBoomerang()) { + addLabel(new GuiNpcLabel(107, "ability.boomerangDelay", col2LabelX, y + 5)); + addTextField(createIntField(107, col2FieldX, y, 50, disc.getBoomerangDelay())); + } y += 24; - // Row 5: Explosive + Explosion Radius + // Row 5: Explosive + Explosion Radius (only show radius if explosive) addLabel(new GuiNpcLabel(108, "ability.explosive", labelX, y + 5)); - addButton(new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.isExplosive() ? 1 : 0)); + GuiNpcButton explosiveBtn = new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.isExplosive() ? 1 : 0); + explosiveBtn.setHoverText("ability.hover.explosive"); + addButton(explosiveBtn); - addLabel(new GuiNpcLabel(109, "ability.explosionRad", col2LabelX, y + 5)); - addTextField(createFloatField(109, col2FieldX, y, 50, disc.getExplosionRadius())); + if (disc.isExplosive()) { + addLabel(new GuiNpcLabel(109, "ability.explosionRad", col2LabelX, y + 5)); + addTextField(createFloatField(109, col2FieldX, y, 50, disc.getExplosionRadius())); + } y += 24; @@ -110,7 +122,9 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { // Row 1: Anchor Point addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5)); - addButton(new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), disc.getAnchorPoint().getId())); + GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), disc.getAnchorPoint().getId()); + anchorBtn.setHoverText("ability.hover.anchorPoint"); + addButton(anchorBtn); y += 24; @@ -149,7 +163,9 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { // Row 4: Lightning Effect Enabled addLabel(new GuiNpcLabel(205, "ability.lightning", labelX, y + 5)); - addButton(new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.hasLightningEffect() ? 1 : 0)); + GuiNpcButton lightningBtn = new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, disc.hasLightningEffect() ? 1 : 0); + lightningBtn.setHoverText("ability.hover.lightning"); + addButton(lightningBtn); // Only show Lightning settings if Lightning is enabled if (disc.hasLightningEffect()) { @@ -174,12 +190,15 @@ public class SubGuiAbilityDisc extends SubGuiAbilityConfig { switch (id) { case 104: disc.setHoming(value == 1); + initGui(); break; case 106: disc.setBoomerang(value == 1); + initGui(); break; case 108: disc.setExplosive(value == 1); + initGui(); break; case 150: setSubGui(new SubGuiAbilityEffects(disc.getEffects())); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java index 626fac6b9..6e90428ce 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityEnergyBeam.java @@ -58,30 +58,40 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { y += 24; - // Row 3: Homing + Homing Strength + // Row 3: Homing + Homing Strength (only show strength if homing) addLabel(new GuiNpcLabel(104, "ability.homing", labelX, y + 5)); - addButton(new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, beam.isHoming() ? 1 : 0)); + GuiNpcButton homingBtn = new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, beam.isHoming() ? 1 : 0); + homingBtn.setHoverText("ability.hover.homing"); + addButton(homingBtn); - addLabel(new GuiNpcLabel(105, "ability.homingStr", col2LabelX, y + 5)); - addTextField(createFloatField(105, col2FieldX, y, 50, beam.getHomingStrength())); + if (beam.isHoming()) { + addLabel(new GuiNpcLabel(105, "ability.homingStr", col2LabelX, y + 5)); + addTextField(createFloatField(105, col2FieldX, y, 50, beam.getHomingStrength())); + } y += 24; - // Row 4: Homing Range + Max Distance - addLabel(new GuiNpcLabel(106, "ability.homingRange", labelX, y + 5)); - addTextField(createFloatField(106, fieldX, y, 50, beam.getHomingRange())); + // Row 4: Max Distance (+ Homing Range only if homing) + if (beam.isHoming()) { + addLabel(new GuiNpcLabel(106, "ability.homingRange", labelX, y + 5)); + addTextField(createFloatField(106, fieldX, y, 50, beam.getHomingRange())); + } - addLabel(new GuiNpcLabel(107, "ability.maxDist", col2LabelX, y + 5)); - addTextField(createFloatField(107, col2FieldX, y, 50, beam.getMaxDistance())); + addLabel(new GuiNpcLabel(107, "ability.maxDist", beam.isHoming() ? col2LabelX : labelX, y + 5)); + addTextField(createFloatField(107, beam.isHoming() ? col2FieldX : fieldX, y, 50, beam.getMaxDistance())); y += 24; - // Row 5: Explosive + Explosion Radius + // Row 5: Explosive + Explosion Radius (only show radius if explosive) addLabel(new GuiNpcLabel(108, "ability.explosive", labelX, y + 5)); - addButton(new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, beam.isExplosive() ? 1 : 0)); + GuiNpcButton explosiveBtn = new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, beam.isExplosive() ? 1 : 0); + explosiveBtn.setHoverText("ability.hover.explosive"); + addButton(explosiveBtn); - addLabel(new GuiNpcLabel(109, "ability.explosionRad", col2LabelX, y + 5)); - addTextField(createFloatField(109, col2FieldX, y, 50, beam.getExplosionRadius())); + if (beam.isExplosive()) { + addLabel(new GuiNpcLabel(109, "ability.explosionRad", col2LabelX, y + 5)); + addTextField(createFloatField(109, col2FieldX, y, 50, beam.getExplosionRadius())); + } y += 24; @@ -108,7 +118,9 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { // Row 1: Anchor Point addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5)); - addButton(new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), beam.getAnchorPoint().getId())); + GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), beam.getAnchorPoint().getId()); + anchorBtn.setHoverText("ability.hover.anchorPoint"); + addButton(anchorBtn); y += 24; @@ -147,7 +159,9 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { // Row 4: Lightning Effect Enabled (only affects head) addLabel(new GuiNpcLabel(205, "ability.lightning", labelX, y + 5)); - addButton(new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, beam.hasLightningEffect() ? 1 : 0)); + GuiNpcButton lightningBtn = new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, beam.hasLightningEffect() ? 1 : 0); + lightningBtn.setHoverText("ability.hover.lightning"); + addButton(lightningBtn); // Only show Lightning settings if Lightning is enabled if (beam.hasLightningEffect()) { @@ -172,9 +186,11 @@ public class SubGuiAbilityEnergyBeam extends SubGuiAbilityConfig { switch (id) { case 104: beam.setHoming(value == 1); + initGui(); break; case 108: beam.setExplosive(value == 1); + initGui(); break; case 150: setSubGui(new SubGuiAbilityEffects(beam.getEffects())); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java index 183d66814..a975a97fc 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityGuard.java @@ -44,11 +44,14 @@ public class SubGuiAbilityGuard extends SubGuiAbilityConfig { // Row 2: Can Counter + Counter Type addLabel(new GuiNpcLabel(101, "ability.canCounter", labelX, y + 5)); - addButton(new GuiNpcButton(101, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, guard.isCanCounter() ? 1 : 0)); + GuiNpcButton canCounterBtn = new GuiNpcButton(101, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, guard.isCanCounter() ? 1 : 0); + canCounterBtn.setHoverText("ability.hover.canCounter"); + addButton(canCounterBtn); addLabel(new GuiNpcLabel(102, "ability.counterType", col2LabelX, y + 5)); String[] types = {"Flat", "Percent"}; GuiNpcButton counterTypeButton = new GuiNpcButton(102, col2FieldX, y, 60, 20, types, guard.getCounterType().ordinal()); + counterTypeButton.setHoverText("ability.hover.counterType"); counterTypeButton.setEnabled(guard.isCanCounter()); addButton(counterTypeButton); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java index c9633c0f9..9822d9f90 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHazard.java @@ -39,14 +39,18 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(100, "ability.shape", col2LabelX, y + 5)); String[] shapes = {"Circle", "Ring", "Cone"}; - addButton(new GuiNpcButton(100, col2FieldX, y, 55, 20, shapes, hazard.getShape().ordinal())); + GuiNpcButton shapeBtn = new GuiNpcButton(100, col2FieldX, y, 55, 20, shapes, hazard.getShape().ordinal()); + shapeBtn.setHoverText("ability.hover.shape"); + addButton(shapeBtn); y += 24; // Row 2: Placement addLabel(new GuiNpcLabel(101, "ability.placement", labelX, y + 5)); String[] placements = {"Caster", "Target", "FollowCast", "FollowTgt"}; - addButton(new GuiNpcButton(101, fieldX, y, 70, 20, placements, hazard.getPlacement().ordinal())); + GuiNpcButton placementBtn = new GuiNpcButton(101, fieldX, y, 70, 20, placements, hazard.getPlacement().ordinal()); + placementBtn.setHoverText("ability.hover.placement"); + addButton(placementBtn); y += 24; @@ -82,7 +86,9 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig { addTextField(createIntField(108, fieldX, y, 50, hazard.getPoisonLevel())); addLabel(new GuiNpcLabel(109, "ability.affectsCaster", col2LabelX, y + 5)); - addButton(new GuiNpcButton(109, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, hazard.isAffectsCaster() ? 1 : 0)); + GuiNpcButton affectsCasterBtn = new GuiNpcButton(109, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, hazard.isAffectsCaster() ? 1 : 0); + affectsCasterBtn.setHoverText("ability.hover.affectsCaster"); + addButton(affectsCasterBtn); y += 24; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java index 010da51cf..490b4773a 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityHeal.java @@ -29,7 +29,9 @@ public class SubGuiAbilityHeal extends SubGuiAbilityConfig { // Row 1: Instant Heal + Duration (only shown if not instant) addLabel(new GuiNpcLabel(103, "dialog.instant", labelX, y + 5)); - addButton(new GuiNpcButton(103, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isInstantHeal() ? 1 : 0)); + GuiNpcButton instantBtn = new GuiNpcButton(103, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isInstantHeal() ? 1 : 0); + instantBtn.setHoverText("ability.hover.instant"); + addButton(instantBtn); if (!heal.isInstantHeal()) { addLabel(new GuiNpcLabel(99, "ability.duration", col2LabelX, y + 5)); @@ -57,10 +59,14 @@ public class SubGuiAbilityHeal extends SubGuiAbilityConfig { // Row 4: Heal Self + Heal Allies addLabel(new GuiNpcLabel(104, "ability.healSelf", labelX, y + 5)); - addButton(new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isHealSelf() ? 1 : 0)); + GuiNpcButton healSelfBtn = new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isHealSelf() ? 1 : 0); + healSelfBtn.setHoverText("ability.hover.healSelf"); + addButton(healSelfBtn); addLabel(new GuiNpcLabel(105, "ability.healAllies", col2LabelX, y + 5)); - addButton(new GuiNpcButton(105, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isHealAllies() ? 1 : 0)); + GuiNpcButton healAlliesBtn = new GuiNpcButton(105, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, heal.isHealAllies() ? 1 : 0); + healAlliesBtn.setHoverText("ability.hover.healAllies"); + addButton(healAlliesBtn); } @Override diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java index 614a8bce0..50e8fa92c 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityLaserShot.java @@ -65,12 +65,16 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { y += 24; - // Row 4: Explosive + Explosion Radius + // Row 4: Explosive + Explosion Radius (only show radius if explosive) addLabel(new GuiNpcLabel(106, "ability.explosive", labelX, y + 5)); - addButton(new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, laser.isExplosive() ? 1 : 0)); + GuiNpcButton explosiveBtn = new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, laser.isExplosive() ? 1 : 0); + explosiveBtn.setHoverText("ability.hover.explosive"); + addButton(explosiveBtn); - addLabel(new GuiNpcLabel(107, "ability.explosionRad", col2LabelX, y + 5)); - addTextField(createFloatField(107, col2FieldX, y, 50, laser.getExplosionRadius())); + if (laser.isExplosive()) { + addLabel(new GuiNpcLabel(107, "ability.explosionRad", col2LabelX, y + 5)); + addTextField(createFloatField(107, col2FieldX, y, 50, laser.getExplosionRadius())); + } y += 24; @@ -124,7 +128,9 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { // Row 3: Lightning Effect Enabled addLabel(new GuiNpcLabel(204, "ability.lightning", labelX, y + 5)); - addButton(new GuiNpcButton(204, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, laser.hasLightningEffect() ? 1 : 0)); + GuiNpcButton lightningBtn = new GuiNpcButton(204, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, laser.hasLightningEffect() ? 1 : 0); + lightningBtn.setHoverText("ability.hover.lightning"); + addButton(lightningBtn); // Only show Lightning settings if Lightning is enabled if (laser.hasLightningEffect()) { @@ -149,6 +155,7 @@ public class SubGuiAbilityLaserShot extends SubGuiAbilityConfig { switch (id) { case 106: laser.setExplosive(value == 1); + initGui(); break; case 150: setSubGui(new SubGuiAbilityEffects(laser.getEffects())); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java index c43569c46..858eeefa7 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityOrb.java @@ -57,21 +57,29 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { y += 24; - // Row 3: Homing + Homing Strength + // Row 3: Homing + Homing Strength (only show strength if homing) addLabel(new GuiNpcLabel(104, "ability.homing", labelX, y + 5)); - addButton(new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.isHoming() ? 1 : 0)); + GuiNpcButton homingBtn = new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.isHoming() ? 1 : 0); + homingBtn.setHoverText("ability.hover.homing"); + addButton(homingBtn); - addLabel(new GuiNpcLabel(105, "ability.homingStr", col2LabelX, y + 5)); - addTextField(createFloatField(105, col2FieldX, y, 50, orb.getHomingStrength())); + if (orb.isHoming()) { + addLabel(new GuiNpcLabel(105, "ability.homingStr", col2LabelX, y + 5)); + addTextField(createFloatField(105, col2FieldX, y, 50, orb.getHomingStrength())); + } y += 24; - // Row 4: Explosive + Explosion Radius + // Row 4: Explosive + Explosion Radius (only show radius if explosive) addLabel(new GuiNpcLabel(106, "ability.explosive", labelX, y + 5)); - addButton(new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.isExplosive() ? 1 : 0)); + GuiNpcButton explosiveBtn = new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.isExplosive() ? 1 : 0); + explosiveBtn.setHoverText("ability.hover.explosive"); + addButton(explosiveBtn); - addLabel(new GuiNpcLabel(107, "ability.explosionRad", col2LabelX, y + 5)); - addTextField(createFloatField(107, col2FieldX, y, 50, orb.getExplosionRadius())); + if (orb.isExplosive()) { + addLabel(new GuiNpcLabel(107, "ability.explosionRad", col2LabelX, y + 5)); + addTextField(createFloatField(107, col2FieldX, y, 50, orb.getExplosionRadius())); + } y += 24; @@ -98,7 +106,9 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { // Row 1: Anchor Point addLabel(new GuiNpcLabel(210, "ability.anchorPoint", labelX, y + 5)); - addButton(new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), orb.getAnchorPoint().getId())); + GuiNpcButton anchorBtn = new GuiNpcButton(210, fieldX, y, 80, 20, AnchorPoint.getDisplayNames(), orb.getAnchorPoint().getId()); + anchorBtn.setHoverText("ability.hover.anchorPoint"); + addButton(anchorBtn); y += 24; @@ -137,7 +147,9 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { // Row 4: Lightning Effect Enabled addLabel(new GuiNpcLabel(205, "ability.lightning", labelX, y + 5)); - addButton(new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.hasLightningEffect() ? 1 : 0)); + GuiNpcButton lightningBtn = new GuiNpcButton(205, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, orb.hasLightningEffect() ? 1 : 0); + lightningBtn.setHoverText("ability.hover.lightning"); + addButton(lightningBtn); // Only show Lightning settings if Lightning is enabled if (orb.hasLightningEffect()) { @@ -162,9 +174,11 @@ public class SubGuiAbilityOrb extends SubGuiAbilityConfig { switch (id) { case 104: orb.setHoming(value == 1); + initGui(); break; case 106: orb.setExplosive(value == 1); + initGui(); break; case 150: setSubGui(new SubGuiAbilityEffects(orb.getEffects())); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java index 52bf7a092..fe66fa242 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityProjectile.java @@ -58,21 +58,29 @@ public class SubGuiAbilityProjectile extends SubGuiAbilityConfig { y += 24; - // Row 3: Explosive + Explosion Radius + // Row 3: Explosive + Explosion Radius (only show radius if explosive) addLabel(new GuiNpcLabel(104, "ability.explosive", labelX, y + 5)); - addButton(new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, projectile.isExplosive() ? 1 : 0)); + GuiNpcButton explosiveBtn = new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, projectile.isExplosive() ? 1 : 0); + explosiveBtn.setHoverText("ability.hover.explosive"); + addButton(explosiveBtn); - addLabel(new GuiNpcLabel(105, "ability.explosionRad", col2LabelX, y + 5)); - addTextField(createFloatField(105, col2FieldX, y, 50, projectile.getExplosionRadius())); + if (projectile.isExplosive()) { + addLabel(new GuiNpcLabel(105, "ability.explosionRad", col2LabelX, y + 5)); + addTextField(createFloatField(105, col2FieldX, y, 50, projectile.getExplosionRadius())); + } y += 24; - // Row 4: Homing + Homing Strength + // Row 4: Homing + Homing Strength (only show strength if homing) addLabel(new GuiNpcLabel(106, "ability.homing", labelX, y + 5)); - addButton(new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, projectile.isHoming() ? 1 : 0)); + GuiNpcButton homingBtn = new GuiNpcButton(106, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, projectile.isHoming() ? 1 : 0); + homingBtn.setHoverText("ability.hover.homing"); + addButton(homingBtn); - addLabel(new GuiNpcLabel(107, "ability.homingStr", col2LabelX, y + 5)); - addTextField(createFloatField(107, col2FieldX, y, 50, projectile.getHomingStrength())); + if (projectile.isHoming()) { + addLabel(new GuiNpcLabel(107, "ability.homingStr", col2LabelX, y + 5)); + addTextField(createFloatField(107, col2FieldX, y, 50, projectile.getHomingStrength())); + } y += 24; @@ -90,9 +98,11 @@ public class SubGuiAbilityProjectile extends SubGuiAbilityConfig { break; case 104: projectile.setExplosive(value == 1); + initGui(); break; case 106: projectile.setHoming(value == 1); + initGui(); break; case 150: setSubGui(new SubGuiAbilityEffects(projectile.getEffects())); diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java index 9a3dc2fe8..1561b408a 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilitySweeper.java @@ -71,13 +71,17 @@ public class SubGuiAbilitySweeper extends SubGuiAbilityConfig { addTextField(createIntField(106, fieldX, y, 50, sweeper.getNumberOfRotations())); addLabel(new GuiNpcLabel(107, "ability.piercing", col2LabelX, y + 5)); - addButton(new GuiNpcButton(107, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, sweeper.isPiercing() ? 1 : 0)); + GuiNpcButton piercingBtn = new GuiNpcButton(107, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, sweeper.isPiercing() ? 1 : 0); + piercingBtn.setHoverText("ability.hover.piercing"); + addButton(piercingBtn); y += 24; // Row 5: Lock On Target addLabel(new GuiNpcLabel(108, "ability.lockTarget", labelX, y + 5)); - addButton(new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, sweeper.isLockOnTarget() ? 1 : 0)); + GuiNpcButton lockTargetBtn = new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, sweeper.isLockOnTarget() ? 1 : 0); + lockTargetBtn.setHoverText("ability.hover.lockTarget"); + addButton(lockTargetBtn); y += 24; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java index 1dfb12d22..e39918d2d 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTeleport.java @@ -54,7 +54,9 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig { addTextField(createIntField(103, fieldX, y, 50, teleport.getBlinkDelayTicks())); addLabel(new GuiNpcLabel(105, "ability.lineOfSight", col2LabelX, y + 5)); - addButton(new GuiNpcButton(105, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isRequireLineOfSight() ? 1 : 0)); + GuiNpcButton losBtn1 = new GuiNpcButton(105, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isRequireLineOfSight() ? 1 : 0); + losBtn1.setHoverText("ability.hover.lineOfSight"); + addButton(losBtn1); y += 24; break; case SINGLE: @@ -63,7 +65,9 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig { addTextField(createFloatField(101, fieldX, y, 50, teleport.getBlinkRadius())); addLabel(new GuiNpcLabel(105, "ability.lineOfSight", col2LabelX, y + 5)); - addButton(new GuiNpcButton(105, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isRequireLineOfSight() ? 1 : 0)); + GuiNpcButton losBtn2 = new GuiNpcButton(105, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isRequireLineOfSight() ? 1 : 0); + losBtn2.setHoverText("ability.hover.lineOfSight"); + addButton(losBtn2); y += 24; break; case BEHIND: @@ -85,10 +89,14 @@ public class SubGuiAbilityTeleport extends SubGuiAbilityConfig { // Damage at Start/End addLabel(new GuiNpcLabel(108, "ability.dmgAtStart", labelX, y + 5)); - addButton(new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isDamageAtStart() ? 1 : 0)); + GuiNpcButton dmgStartBtn = new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isDamageAtStart() ? 1 : 0); + dmgStartBtn.setHoverText("ability.hover.dmgAtStart"); + addButton(dmgStartBtn); addLabel(new GuiNpcLabel(109, "ability.dmgAtEnd", col2LabelX, y + 5)); - addButton(new GuiNpcButton(109, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isDamageAtEnd() ? 1 : 0)); + GuiNpcButton dmgEndBtn = new GuiNpcButton(109, col2FieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, teleport.isDamageAtEnd() ? 1 : 0); + dmgEndBtn.setHoverText("ability.hover.dmgAtEnd"); + addButton(dmgEndBtn); y += 24; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java index c846565c4..edeb59635 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityTrap.java @@ -39,7 +39,9 @@ public class SubGuiAbilityTrap extends SubGuiAbilityConfig { addLabel(new GuiNpcLabel(100, "ability.placement", col2LabelX, y + 5)); String[] placements = {"Caster", "Target", "Ahead"}; - addButton(new GuiNpcButton(100, col2FieldX, y, 55, 20, placements, trap.getPlacement().ordinal())); + GuiNpcButton placementBtn = new GuiNpcButton(100, col2FieldX, y, 55, 20, placements, trap.getPlacement().ordinal()); + placementBtn.setHoverText("ability.hover.placement"); + addButton(placementBtn); y += 24; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java index 4cc7bc89a..b56828470 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/ability/SubGuiAbilityVortex.java @@ -51,7 +51,9 @@ public class SubGuiAbilityVortex extends SubGuiAbilityConfig { // Row 3: AOE + Max Targets addLabel(new GuiNpcLabel(104, "ability.aoe", labelX, y + 5)); - addButton(new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, vortex.isAoe() ? 1 : 0)); + GuiNpcButton aoeBtn = new GuiNpcButton(104, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, vortex.isAoe() ? 1 : 0); + aoeBtn.setHoverText("ability.hover.aoe"); + addButton(aoeBtn); addLabel(new GuiNpcLabel(105, "ability.maxTargets", col2LabelX, y + 5)); addTextField(createIntField(105, col2FieldX, y, 50, vortex.getMaxTargets())); @@ -65,7 +67,9 @@ public class SubGuiAbilityVortex extends SubGuiAbilityConfig { // Row 5: Damage on Pull + Pull Damage addLabel(new GuiNpcLabel(108, "ability.dmgOnPull", labelX, y + 5)); - addButton(new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, vortex.isDamageOnPull() ? 1 : 0)); + GuiNpcButton dmgOnPullBtn = new GuiNpcButton(108, fieldX, y, 50, 20, new String[]{"gui.no", "gui.yes"}, vortex.isDamageOnPull() ? 1 : 0); + dmgOnPullBtn.setHoverText("ability.hover.dmgOnPull"); + addButton(dmgOnPullBtn); addLabel(new GuiNpcLabel(109, "ability.pullDamage", col2LabelX, y + 5)); addTextField(createFloatField(109, col2FieldX, y, 50, vortex.getPullDamage())); diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiAnimationSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiAnimationSelection.java index 882f5817b..cc3e06cca 100644 --- a/src/main/java/noppes/npcs/client/gui/select/GuiAnimationSelection.java +++ b/src/main/java/noppes/npcs/client/gui/select/GuiAnimationSelection.java @@ -58,7 +58,7 @@ public class GuiAnimationSelection extends SubGuiInterface implements ICustomScr if (scrollAnimations == null) { scrollAnimations = new GuiCustomScroll(this, 0, 0); - scrollAnimations.setSize(212, 163); + scrollAnimations.setSize(212, 150); } scrollAnimations.setList(getSearchList()); if (selectedName != null) { @@ -68,7 +68,8 @@ public class GuiAnimationSelection extends SubGuiInterface implements ICustomScr scrollAnimations.guiTop = guiTop + 14; this.addScroll(scrollAnimations); - addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 179, 212, 20, search)); + // Search textbox - moved up to avoid overlapping with buttons + addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 166, 212, 20, search)); } @Override diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 8444c5c1d..11bbaf451 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -57,6 +57,7 @@ public abstract class GuiNPCInterface extends GuiScreen { public float bgScaleX = 1; public float bgScaleY = 1; public float bgScaleZ = 1; + public int bgTextureHeight = 256; // Actual content height in texture (for bottom border stitching) public GuiNPCInterface(EntityNPCInterface npc) { this.player = Minecraft.getMinecraft().thePlayer; @@ -74,6 +75,11 @@ public abstract class GuiNPCInterface extends GuiScreen { background = new ResourceLocation("customnpcs", "textures/gui/" + texture); } + public void setBackground(String texture, int textureHeight) { + background = new ResourceLocation("customnpcs", "textures/gui/" + texture); + bgTextureHeight = textureHeight; + } + public ResourceLocation getResource(String texture) { return new ResourceLocation("customnpcs", "textures/gui/" + texture); } @@ -421,23 +427,44 @@ public abstract class GuiNPCInterface extends GuiScreen { GL11.glTranslatef(guiLeft, guiTop, 0); GL11.glScalef(bgScale * bgScaleX, bgScale * bgScaleY, bgScale * bgScaleZ); mc.renderEngine.bindTexture(background); + + // Handle Y dimension: if ySize < texture content height, stitch bottom border + int topHeight = ySize; + int bottomHeight = 0; + int bottomTextureV = 0; + if (ySize < bgTextureHeight) { + // Keep bottom border from texture bottom (last 6 pixels of actual content) + bottomHeight = 6; + topHeight = ySize - bottomHeight; + bottomTextureV = bgTextureHeight - bottomHeight; + } + if (xSize > 256) { // GUI wider than texture: draw left portion, then right portion from texture edge - drawTexturedModalRect(0, 0, 0, 0, 250, ySize); - drawTexturedModalRect(250, 0, 256 - (xSize - 250), 0, xSize - 250, ySize); + drawTexturedModalRect(0, 0, 0, 0, 250, topHeight); + drawTexturedModalRect(250, 0, 256 - (xSize - 250), 0, xSize - 250, topHeight); + if (bottomHeight > 0) { + drawTexturedModalRect(0, topHeight, 0, bottomTextureV, 250, bottomHeight); + drawTexturedModalRect(250, topHeight, 256 - (xSize - 250), bottomTextureV, xSize - 250, bottomHeight); + } } else if (xSize < 256) { // GUI narrower than texture: stitch left and right edges together - // Left portion (first half of GUI) int leftWidth = xSize / 2; - // Right portion width (remaining) int rightWidth = xSize - leftWidth; - // Draw left side from texture start - drawTexturedModalRect(0, 0, 0, 0, leftWidth, ySize); - // Draw right side from texture end (256 - rightWidth) - drawTexturedModalRect(leftWidth, 0, 256 - rightWidth, 0, rightWidth, ySize); + // Draw top portion + drawTexturedModalRect(0, 0, 0, 0, leftWidth, topHeight); + drawTexturedModalRect(leftWidth, 0, 256 - rightWidth, 0, rightWidth, topHeight); + // Draw bottom border strip + if (bottomHeight > 0) { + drawTexturedModalRect(0, topHeight, 0, bottomTextureV, leftWidth, bottomHeight); + drawTexturedModalRect(leftWidth, topHeight, 256 - rightWidth, bottomTextureV, rightWidth, bottomHeight); + } } else { - // GUI exactly 256px: draw full texture - drawTexturedModalRect(0, 0, 0, 0, xSize, ySize); + // GUI exactly 256px wide + drawTexturedModalRect(0, 0, 0, 0, xSize, topHeight); + if (bottomHeight > 0) { + drawTexturedModalRect(0, topHeight, 0, bottomTextureV, xSize, bottomHeight); + } } GL11.glPopMatrix(); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 8ac2d99c0..750a75f54 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -115,6 +115,7 @@ gui.play=Play gui.selectSound=Select Sound gui.selectnpc=Select NPC gui.select=Select +gui.sync=Sync gui.range=Range gui.partly=Partially gui.copy=Copy @@ -1504,6 +1505,8 @@ menu.abilities=Abilities ability.availableTypes=Available Types ability.npcAbilities=NPC Abilities ability.globalCooldown=Global Cooldown +ability.minCooldown=Min CD +ability.maxCooldown=Max CD ability.edit=Edit Ability ability.weight=Weight ability.targeting=Targeting @@ -1679,7 +1682,7 @@ ability.innerColor=Inner Color ability.outerColor=Outer Color ability.outerEnabled=Outer Glow ability.outerWidth=Outer Width -ability.lightning=Enable Lightning +ability.lightning=Lightning ability.lightningDensity=Density ability.lightningRadius=Radius ability.anchorPoint=Anchor Point @@ -1725,6 +1728,50 @@ ability.typeId=Type ID ability.conditions=Conditions ability.noTypeSettings=No type-specific settings +ability.hover.weight=Higher weight = more likely to be chosen when multiple abilities available +ability.hover.lockMove=Prevents NPC from moving while ability is charging or active +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) +ability.hover.cooldown=Time before ability can be used again (20 ticks = 1 second) +ability.hover.sync=Set windup ticks to match animation duration +ability.hover.minRange=Target must be at least this far away +ability.hover.maxRange=Target must be within this distance +ability.hover.targeting=How the ability selects its target +ability.hover.conditions=Requirements that must be met for ability to activate +ability.hover.showTelegraph=Show visual warning indicator during windup +ability.hover.windUpColor=Color of telegraph during charge-up phase +ability.hover.activeColor=Color of telegraph when ability is active +ability.hover.homing=Projectile tracks toward target +ability.hover.homingStr=How aggressively the projectile tracks (higher = tighter turns) +ability.hover.explosive=Creates explosion on impact +ability.hover.explosionRad=Size of explosion radius +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.damage=Base damage dealt to targets +ability.hover.speed=Movement speed of projectile +ability.hover.lifetime=Maximum ticks before despawning +ability.hover.knockback=Push force applied to targets +ability.hover.boomerang=Projectile returns to caster after reaching max distance +ability.hover.dashMode=Aggressive dashes toward target, Defensive dashes away +ability.hover.aoe=Affects all valid targets in range instead of just one +ability.hover.dmgOnPull=Deal damage continuously while pulling targets +ability.hover.lineOfSight=Requires clear line of sight to the target +ability.hover.dmgAtStart=Deal damage at the teleport origin location +ability.hover.dmgAtEnd=Deal damage at the teleport destination +ability.hover.instant=Heals instantly instead of over time +ability.hover.healSelf=Ability can heal the casting NPC +ability.hover.healAllies=Ability can heal nearby allied NPCs +ability.hover.placement=Where the ability effect is placed (Caster, Target, etc.) +ability.hover.lockTarget=Sweeper beam tracks the target's position +ability.hover.canCounter=Enable counterattack when blocking damage +ability.hover.counterType=Flat = fixed damage, Percent = % of blocked damage +ability.hover.shape=Shape of the hazard zone (Circle, Ring, Cone) +ability.hover.affectsCaster=Hazard can damage the NPC that created it +ability.hover.sweepMode=Swipe = single arc attack, Spin = continuous rotation + # Conditions condition.edit=Edit Condition condition.hp_above=NPC HP Above