mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 18:44:26 +00:00
Compare commits
12
Commits
dev
...
new-abilities
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ab1dd1e16 | ||
|
|
7c4159dcd2 | ||
|
|
c2c6079b43 | ||
|
|
fb3a392f2e | ||
|
|
956d2e27be | ||
|
|
9546500b4b | ||
|
|
a2beef0549 | ||
|
|
0222a4984e | ||
|
|
d4a89dad1d | ||
|
|
ca7f3f937b | ||
|
|
a59d2d0088 | ||
|
|
9c82fabf1b |
No files matched your search
@@ -2,6 +2,7 @@ package kamkeel.npcs.client.renderer;
|
|||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||||
|
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.entity.RenderManager;
|
import net.minecraft.client.renderer.entity.RenderManager;
|
||||||
@@ -25,7 +26,7 @@ public class EnergyChargePreviewRenderer {
|
|||||||
|
|
||||||
float partialTicks = event.partialTicks;
|
float partialTicks = event.partialTicks;
|
||||||
|
|
||||||
for (EntityEnergyProjectile entity : EnergyChargePreviewManager.ClientInstance.getPreviews()) {
|
for (EntityEnergyAbility entity : EnergyChargePreviewManager.ClientInstance.getPreviews()) {
|
||||||
if (entity == null || entity.isDead) continue;
|
if (entity == null || entity.isDead) continue;
|
||||||
|
|
||||||
double x = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks - RenderManager.renderPosX;
|
double x = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks - RenderManager.renderPosX;
|
||||||
|
|||||||
@@ -0,0 +1,279 @@
|
|||||||
|
package kamkeel.npcs.client.renderer;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.PillarOrigin;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.PillarShape;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders EntityAbilityPillar.
|
||||||
|
*
|
||||||
|
* Radius: snaps immediately to targetRadius when charging ends — no interpolation.
|
||||||
|
* Height: grows linearly with no easing, at the speed defined in pillarData.
|
||||||
|
*
|
||||||
|
* FROM_GROUND: baseY = posY, tipY = posY + height (grows up).
|
||||||
|
* FROM_ABOVE: baseY = posY, tipY = posY - height (grows down from ceiling anchor).
|
||||||
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class RenderEnergyPillar extends RenderEnergy {
|
||||||
|
|
||||||
|
private static final int CIRCLE_SEGMENTS = 24;
|
||||||
|
private static final float INNER_SCALE = 0.6f;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTicks) {
|
||||||
|
EntityAbilityPillar pillar = (EntityAbilityPillar) entity;
|
||||||
|
|
||||||
|
if (shouldSkipInitialActiveRender(pillar)) return;
|
||||||
|
|
||||||
|
setupRenderState();
|
||||||
|
float proximityAlpha = getProximityAlphaFactor(pillar, x, y, z);
|
||||||
|
|
||||||
|
if (pillar.isCharging()) {
|
||||||
|
renderCharging(pillar, x, y, z, partialTicks, proximityAlpha);
|
||||||
|
restoreRenderState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Radius: use raw value directly — snaps on charging end, no interpolation needed
|
||||||
|
float radius = pillar.getPillarRadius();
|
||||||
|
// Height: linearly interpolated between prev and current (no easing)
|
||||||
|
float height = pillar.getInterpolatedPillarHeight(partialTicks);
|
||||||
|
|
||||||
|
if (radius <= 0.01f || height <= 0.01f) {
|
||||||
|
restoreRenderState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float baseY, tipY;
|
||||||
|
if (pillar.getPillarOrigin() == PillarOrigin.FROM_ABOVE) {
|
||||||
|
baseY = (float) y;
|
||||||
|
tipY = (float) y - height;
|
||||||
|
} else {
|
||||||
|
baseY = (float) y;
|
||||||
|
tipY = (float) y + height;
|
||||||
|
}
|
||||||
|
|
||||||
|
float rotationAngle = pillar.getRotationSpeed() != 0f
|
||||||
|
? (pillar.ticksExisted + partialTicks) * pillar.getRotationSpeed() : 0f;
|
||||||
|
|
||||||
|
float innerRadius = radius * INNER_SCALE;
|
||||||
|
int innerColor = pillar.getInnerColor();
|
||||||
|
int outerColor = pillar.getOuterColor();
|
||||||
|
float innerAlpha = pillar.getInnerAlpha() * proximityAlpha;
|
||||||
|
|
||||||
|
if (pillar.isOuterColorEnabled()) {
|
||||||
|
float outerRadius = innerRadius + pillar.getOuterColorWidth() * radius;
|
||||||
|
float outerAlpha = pillar.getOuterColorAlpha() * proximityAlpha;
|
||||||
|
float midRadius = innerRadius + (outerRadius - innerRadius) * 0.5f;
|
||||||
|
|
||||||
|
GL11.glDepthMask(false);
|
||||||
|
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, outerRadius, outerColor, outerAlpha * 0.4f, rotationAngle);
|
||||||
|
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, midRadius, outerColor, outerAlpha * 0.7f, rotationAngle);
|
||||||
|
GL11.glDepthMask(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, innerRadius, innerColor, innerAlpha, rotationAngle);
|
||||||
|
|
||||||
|
if (pillar.hasLightningEffect()) {
|
||||||
|
float midWorldY = (baseY + tipY) * 0.5f;
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslated(x, midWorldY, z);
|
||||||
|
renderAttachedLightning(pillar, INNER_SCALE, radius);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
restoreRenderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== CHARGING ====================
|
||||||
|
|
||||||
|
private void renderCharging(EntityAbilityPillar pillar, double x, double y, double z,
|
||||||
|
float partialTicks, float proximityAlpha) {
|
||||||
|
// Use targetRadius directly — pillarRadius during charging is only 0.01 initially
|
||||||
|
// and grows via DataWatcher which is unavailable on preview entities.
|
||||||
|
float targetRadius = pillar.getPillarData().targetRadius;
|
||||||
|
float chargeProgress = pillar.getInterpolatedChargeProgress(partialTicks);
|
||||||
|
float renderRadius = targetRadius * chargeProgress;
|
||||||
|
|
||||||
|
if (renderRadius <= 0.01f) return;
|
||||||
|
|
||||||
|
float pulseTime = pillar.ticksExisted + partialTicks;
|
||||||
|
renderRadius *= (1.0f + (float) Math.sin(pulseTime * 0.2f) * 0.08f);
|
||||||
|
|
||||||
|
float baseY = (float) y;
|
||||||
|
float tipY = baseY + 0.05f;
|
||||||
|
|
||||||
|
float rotationAngle = pillar.getRotationSpeed() != 0f
|
||||||
|
? (pillar.ticksExisted + partialTicks) * pillar.getRotationSpeed() : 0f;
|
||||||
|
|
||||||
|
float innerRadius = renderRadius * INNER_SCALE;
|
||||||
|
int innerColor = pillar.getInnerColor();
|
||||||
|
int outerColor = pillar.getOuterColor();
|
||||||
|
float innerAlpha = pillar.getInnerAlpha() * proximityAlpha;
|
||||||
|
|
||||||
|
if (pillar.hasLightningEffect()) {
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslated(x, y + 0.025f, z);
|
||||||
|
renderAttachedLightning(pillar, INNER_SCALE, renderRadius);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pillar.isOuterColorEnabled()) {
|
||||||
|
float outerRadius = innerRadius + pillar.getOuterColorWidth() * renderRadius;
|
||||||
|
float outerAlpha = pillar.getOuterColorAlpha() * proximityAlpha;
|
||||||
|
float midRadius = innerRadius + (outerRadius - innerRadius) * 0.5f;
|
||||||
|
|
||||||
|
GL11.glDepthMask(false);
|
||||||
|
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, outerRadius, outerColor, outerAlpha * 0.4f, rotationAngle);
|
||||||
|
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, midRadius, outerColor, outerAlpha * 0.7f, rotationAngle);
|
||||||
|
GL11.glDepthMask(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderPillarShape(pillar.getPillarShape(), x, baseY, tipY, z, innerRadius, innerColor, innerAlpha, rotationAngle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== SHAPE DISPATCH ====================
|
||||||
|
|
||||||
|
private void renderPillarShape(PillarShape shape, double x, float baseY, float tipY,
|
||||||
|
double z, float radius, int color, float alpha, float rotationAngle) {
|
||||||
|
if (shape == PillarShape.SQUARE) {
|
||||||
|
renderSquarePillar(x, baseY, tipY, z, radius, color, alpha, rotationAngle);
|
||||||
|
} else {
|
||||||
|
renderCylinderPillar(x, baseY, tipY, z, radius, color, alpha, rotationAngle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== CYLINDER ====================
|
||||||
|
|
||||||
|
private void renderCylinderPillar(double cx, float baseY, float tipY, double cz,
|
||||||
|
float radius, int color, float alpha, float rotationAngle) {
|
||||||
|
float[] rgb = extractRGB(color);
|
||||||
|
float r = rgb[0], g = rgb[1], b = rgb[2];
|
||||||
|
|
||||||
|
float[] cosTable = new float[CIRCLE_SEGMENTS + 1];
|
||||||
|
float[] sinTable = new float[CIRCLE_SEGMENTS + 1];
|
||||||
|
double rotRad = Math.toRadians(rotationAngle);
|
||||||
|
for (int i = 0; i <= CIRCLE_SEGMENTS; i++) {
|
||||||
|
double angle = 2.0 * Math.PI * i / CIRCLE_SEGMENTS + rotRad;
|
||||||
|
cosTable[i] = (float) Math.cos(angle);
|
||||||
|
sinTable[i] = (float) Math.sin(angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tessellator tess = Tessellator.instance;
|
||||||
|
|
||||||
|
tess.startDrawingQuads();
|
||||||
|
tess.setColorRGBA_F(r, g, b, alpha);
|
||||||
|
for (int i = 0; i < CIRCLE_SEGMENTS; i++) {
|
||||||
|
float x1 = (float) cx + cosTable[i] * radius;
|
||||||
|
float z1 = (float) cz + sinTable[i] * radius;
|
||||||
|
float x2 = (float) cx + cosTable[i + 1] * radius;
|
||||||
|
float z2 = (float) cz + sinTable[i + 1] * radius;
|
||||||
|
tess.setNormal((cosTable[i] + cosTable[i + 1]) * 0.5f, 0, (sinTable[i] + sinTable[i + 1]) * 0.5f);
|
||||||
|
tess.addVertex(x1, baseY, z1);
|
||||||
|
tess.addVertex(x2, baseY, z2);
|
||||||
|
tess.addVertex(x2, tipY, z2);
|
||||||
|
tess.addVertex(x1, tipY, z1);
|
||||||
|
}
|
||||||
|
tess.draw();
|
||||||
|
|
||||||
|
float capMinY = Math.min(baseY, tipY);
|
||||||
|
float capMaxY = Math.max(baseY, tipY);
|
||||||
|
|
||||||
|
tess.startDrawingQuads();
|
||||||
|
tess.setColorRGBA_F(r, g, b, alpha);
|
||||||
|
tess.setNormal(0, -1, 0);
|
||||||
|
for (int i = 0; i < CIRCLE_SEGMENTS; i++) {
|
||||||
|
float x1 = (float) cx + cosTable[i] * radius;
|
||||||
|
float z1 = (float) cz + sinTable[i] * radius;
|
||||||
|
float x2 = (float) cx + cosTable[i + 1] * radius;
|
||||||
|
float z2 = (float) cz + sinTable[i + 1] * radius;
|
||||||
|
tess.addVertex((float) cx, capMinY, (float) cz);
|
||||||
|
tess.addVertex(x2, capMinY, z2);
|
||||||
|
tess.addVertex(x1, capMinY, z1);
|
||||||
|
tess.addVertex((float) cx, capMinY, (float) cz);
|
||||||
|
}
|
||||||
|
tess.draw();
|
||||||
|
|
||||||
|
tess.startDrawingQuads();
|
||||||
|
tess.setColorRGBA_F(r, g, b, alpha);
|
||||||
|
tess.setNormal(0, 1, 0);
|
||||||
|
for (int i = 0; i < CIRCLE_SEGMENTS; i++) {
|
||||||
|
float x1 = (float) cx + cosTable[i] * radius;
|
||||||
|
float z1 = (float) cz + sinTable[i] * radius;
|
||||||
|
float x2 = (float) cx + cosTable[i + 1] * radius;
|
||||||
|
float z2 = (float) cz + sinTable[i + 1] * radius;
|
||||||
|
tess.addVertex((float) cx, capMaxY, (float) cz);
|
||||||
|
tess.addVertex(x1, capMaxY, z1);
|
||||||
|
tess.addVertex(x2, capMaxY, z2);
|
||||||
|
tess.addVertex((float) cx, capMaxY, (float) cz);
|
||||||
|
}
|
||||||
|
tess.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== SQUARE ====================
|
||||||
|
|
||||||
|
private void renderSquarePillar(double cx, float baseY, float tipY, double cz,
|
||||||
|
float radius, int color, float alpha, float rotationAngle) {
|
||||||
|
float[] rgb = extractRGB(color);
|
||||||
|
float r = rgb[0], g = rgb[1], b = rgb[2];
|
||||||
|
|
||||||
|
double rotRad = Math.toRadians(rotationAngle);
|
||||||
|
float cosA = (float) Math.cos(rotRad);
|
||||||
|
float sinA = (float) Math.sin(rotRad);
|
||||||
|
|
||||||
|
float[] lx = {-radius, radius, radius, -radius};
|
||||||
|
float[] lz = {-radius, -radius, radius, radius};
|
||||||
|
float[][] corners = new float[4][2];
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
corners[i][0] = (float) cx + lx[i] * cosA - lz[i] * sinA;
|
||||||
|
corners[i][1] = (float) cz + lx[i] * sinA + lz[i] * cosA;
|
||||||
|
}
|
||||||
|
|
||||||
|
float capMinY = Math.min(baseY, tipY);
|
||||||
|
float capMaxY = Math.max(baseY, tipY);
|
||||||
|
|
||||||
|
Tessellator tess = Tessellator.instance;
|
||||||
|
tess.startDrawingQuads();
|
||||||
|
tess.setColorRGBA_F(r, g, b, alpha);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
int next = (i + 1) % 4;
|
||||||
|
float x1 = corners[i][0], z1 = corners[i][1];
|
||||||
|
float x2 = corners[next][0], z2 = corners[next][1];
|
||||||
|
float nx = (x1 + x2) * 0.5f - (float) cx;
|
||||||
|
float nz = (z1 + z2) * 0.5f - (float) cz;
|
||||||
|
float nlen = (float) Math.sqrt(nx * nx + nz * nz);
|
||||||
|
if (nlen > 0) { nx /= nlen; nz /= nlen; }
|
||||||
|
tess.setNormal(nx, 0, nz);
|
||||||
|
tess.addVertex(x1, baseY, z1);
|
||||||
|
tess.addVertex(x2, baseY, z2);
|
||||||
|
tess.addVertex(x2, tipY, z2);
|
||||||
|
tess.addVertex(x1, tipY, z1);
|
||||||
|
}
|
||||||
|
|
||||||
|
tess.setNormal(0, -1, 0);
|
||||||
|
tess.addVertex(corners[0][0], capMinY, corners[0][1]);
|
||||||
|
tess.addVertex(corners[3][0], capMinY, corners[3][1]);
|
||||||
|
tess.addVertex(corners[2][0], capMinY, corners[2][1]);
|
||||||
|
tess.addVertex(corners[1][0], capMinY, corners[1][1]);
|
||||||
|
|
||||||
|
tess.setNormal(0, 1, 0);
|
||||||
|
tess.addVertex(corners[0][0], capMaxY, corners[0][1]);
|
||||||
|
tess.addVertex(corners[1][0], capMaxY, corners[1][1]);
|
||||||
|
tess.addVertex(corners[2][0], capMaxY, corners[2][1]);
|
||||||
|
tess.addVertex(corners[3][0], capMaxY, corners[3][1]);
|
||||||
|
|
||||||
|
tess.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResourceLocation getEntityTexture(Entity entity) {
|
||||||
|
return WHITE_TEXTURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,14 +32,7 @@ import kamkeel.npcs.controllers.data.ability.type.AbilitySlam;
|
|||||||
import kamkeel.npcs.controllers.data.ability.type.AbilityTeleport;
|
import kamkeel.npcs.controllers.data.ability.type.AbilityTeleport;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.AbilityTrap;
|
import kamkeel.npcs.controllers.data.ability.type.AbilityTrap;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.AbilityVortex;
|
import kamkeel.npcs.controllers.data.ability.type.AbilityVortex;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityBeam;
|
import kamkeel.npcs.controllers.data.ability.type.energy.*;
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityDisc;
|
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityDome;
|
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityLaser;
|
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityOrb;
|
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityShield;
|
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilitySweeper;
|
|
||||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityWall;
|
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import noppes.npcs.controllers.data.AbilityScript;
|
import noppes.npcs.controllers.data.AbilityScript;
|
||||||
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
||||||
@@ -177,6 +170,8 @@ public class AbilityController implements IAbilityHandler {
|
|||||||
registerType(AbilityDome::new);
|
registerType(AbilityDome::new);
|
||||||
registerType(AbilityWall::new);
|
registerType(AbilityWall::new);
|
||||||
registerType(AbilityShield::new);
|
registerType(AbilityShield::new);
|
||||||
|
|
||||||
|
registerType(AbilityPillar::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerBuiltinConditionTypes() {
|
private void registerBuiltinConditionTypes() {
|
||||||
|
|||||||
+140
@@ -0,0 +1,140 @@
|
|||||||
|
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||||
|
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.PillarMode;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.PillarOrigin;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.PillarShape;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups pillar-specific configuration for EntityAbilityPillar.
|
||||||
|
* Enum types are owned by EntityAbilityPillar; this class handles serialization only.
|
||||||
|
*/
|
||||||
|
public class EnergyPillarData {
|
||||||
|
|
||||||
|
public float targetRadius = 2.0f;
|
||||||
|
public float targetHeight = 10.0f;
|
||||||
|
public float radiusGrowSpeed = 0.5f;
|
||||||
|
public float heightGrowSpeed = 1.0f;
|
||||||
|
public PillarMode mode = PillarMode.ANCHORED;
|
||||||
|
public PillarOrigin origin = PillarOrigin.FROM_GROUND;
|
||||||
|
public PillarShape shape = PillarShape.CIRCLE;
|
||||||
|
public int spawnDelay = 10;
|
||||||
|
|
||||||
|
public EnergyPillarData() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnergyPillarData(float targetRadius, float targetHeight,
|
||||||
|
float radiusGrowSpeed, float heightGrowSpeed,
|
||||||
|
PillarMode mode, PillarOrigin origin, PillarShape shape,
|
||||||
|
int spawnDelay) {
|
||||||
|
this.targetRadius = targetRadius;
|
||||||
|
this.targetHeight = targetHeight;
|
||||||
|
this.radiusGrowSpeed = radiusGrowSpeed;
|
||||||
|
this.heightGrowSpeed = heightGrowSpeed;
|
||||||
|
this.mode = mode != null ? mode : PillarMode.ANCHORED;
|
||||||
|
this.origin = origin != null ? origin : PillarOrigin.FROM_GROUND;
|
||||||
|
this.shape = shape != null ? shape : PillarShape.CIRCLE;
|
||||||
|
this.spawnDelay = Math.max(0, spawnDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTargetRadius() {
|
||||||
|
return targetRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetRadius(float targetRadius) {
|
||||||
|
this.targetRadius = targetRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTargetHeight() {
|
||||||
|
return targetHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetHeight(float targetHeight) {
|
||||||
|
this.targetHeight = targetHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRadiusGrowSpeed() {
|
||||||
|
return radiusGrowSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadiusGrowSpeed(float radiusGrowSpeed) {
|
||||||
|
this.radiusGrowSpeed = radiusGrowSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHeightGrowSpeed() {
|
||||||
|
return heightGrowSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeightGrowSpeed(float heightGrowSpeed) {
|
||||||
|
this.heightGrowSpeed = heightGrowSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PillarMode getMode() {
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode(PillarMode mode) {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PillarOrigin getOrigin() {
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrigin(PillarOrigin origin) {
|
||||||
|
this.origin = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PillarShape getShape() {
|
||||||
|
return shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShape(PillarShape shape) {
|
||||||
|
this.shape = shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpawnDelay() {
|
||||||
|
return spawnDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpawnDelay(int spawnDelay) {
|
||||||
|
this.spawnDelay = spawnDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeNBT(NBTTagCompound nbt) {
|
||||||
|
nbt.setFloat("targetRadius", targetRadius);
|
||||||
|
nbt.setFloat("targetHeight", targetHeight);
|
||||||
|
nbt.setFloat("radiusGrowSpeed", radiusGrowSpeed);
|
||||||
|
nbt.setFloat("heightGrowSpeed", heightGrowSpeed);
|
||||||
|
nbt.setInteger("pillarMode", mode.ordinal());
|
||||||
|
nbt.setInteger("pillarOrigin", origin.ordinal());
|
||||||
|
nbt.setInteger("pillarShape", shape.ordinal());
|
||||||
|
nbt.setInteger("spawnDelay", spawnDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readNBT(NBTTagCompound nbt) {
|
||||||
|
this.targetRadius = nbt.hasKey("targetRadius") ? nbt.getFloat("targetRadius") : 1.0f;
|
||||||
|
this.targetHeight = nbt.hasKey("targetHeight") ? nbt.getFloat("targetHeight") : 2.0f;
|
||||||
|
this.radiusGrowSpeed = nbt.hasKey("radiusGrowSpeed") ? nbt.getFloat("radiusGrowSpeed") : 0.1f;
|
||||||
|
this.heightGrowSpeed = nbt.hasKey("heightGrowSpeed") ? nbt.getFloat("heightGrowSpeed") : 0.2f;
|
||||||
|
|
||||||
|
int modeOrd = nbt.hasKey("pillarMode") ? nbt.getInteger("pillarMode") : 0;
|
||||||
|
this.mode = (modeOrd >= 0 && modeOrd < PillarMode.values().length) ? PillarMode.values()[modeOrd] : PillarMode.ANCHORED;
|
||||||
|
|
||||||
|
int originOrd = nbt.hasKey("pillarOrigin") ? nbt.getInteger("pillarOrigin") : 0;
|
||||||
|
this.origin = (originOrd >= 0 && originOrd < PillarOrigin.values().length) ? PillarOrigin.values()[originOrd] : PillarOrigin.FROM_GROUND;
|
||||||
|
|
||||||
|
int shapeOrd = nbt.hasKey("pillarShape") ? nbt.getInteger("pillarShape") : 0;
|
||||||
|
this.shape = (shapeOrd >= 0 && shapeOrd < PillarShape.values().length) ? PillarShape.values()[shapeOrd] : PillarShape.CIRCLE;
|
||||||
|
|
||||||
|
this.spawnDelay = nbt.hasKey("spawnDelay") ? Math.max(0, nbt.getInteger("spawnDelay")) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnergyPillarData copy() {
|
||||||
|
return new EnergyPillarData(
|
||||||
|
targetRadius, targetHeight,
|
||||||
|
radiusGrowSpeed, heightGrowSpeed,
|
||||||
|
mode, origin, shape, spawnDelay
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+562
@@ -0,0 +1,562 @@
|
|||||||
|
package kamkeel.npcs.controllers.data.ability.type.energy;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyCombatData;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.enums.HitType;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
|
||||||
|
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||||
|
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||||
|
import kamkeel.npcs.entity.EntityEnergyZone;
|
||||||
|
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeRemovePacket;
|
||||||
|
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeSpawnPacket;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.util.DamageSource;
|
||||||
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base for all energy zone abilities (Pillar, etc.).
|
||||||
|
* Extends AbilityEnergy for shared visual/lightning data.
|
||||||
|
*
|
||||||
|
* Handles:
|
||||||
|
* - Multi-zone support with staggered spawning via fireDelay
|
||||||
|
* - Charge visual lifecycle via EnergyChargeSpawnPacket + EnergyChargeTracker
|
||||||
|
* - Windup -> execute -> active -> complete lifecycle
|
||||||
|
* - Telegraph infrastructure (subclass defines shape and radius)
|
||||||
|
* - NBT persistence for shared fields
|
||||||
|
*
|
||||||
|
* Subclasses must implement:
|
||||||
|
* - createEntity() — instantiate the zone entity
|
||||||
|
* - setupEntityCharging() — configure entity for charge visual
|
||||||
|
* - setupEntityPreview() — configure entity for GUI preview
|
||||||
|
* - createEntityArray() — typed array creation (generics limitation)
|
||||||
|
* - getZoneTelegraphRadius() — telegraph size
|
||||||
|
* - addTypeDefinitions() — type-specific GUI fields
|
||||||
|
* - writeTypeSpecificNBT()
|
||||||
|
* - readTypeSpecificNBT()
|
||||||
|
*
|
||||||
|
* @param <E> The zone entity type this ability spawns
|
||||||
|
*/
|
||||||
|
public abstract class AbilityEnergyZone<E extends EntityEnergyZone> extends AbilityEnergy {
|
||||||
|
|
||||||
|
protected static final int MAX_ZONES = 8;
|
||||||
|
|
||||||
|
// ==================== ZONE COUNT & STAGGER ====================
|
||||||
|
|
||||||
|
protected int zoneCount = 1;
|
||||||
|
protected int fireDelay = 0;
|
||||||
|
|
||||||
|
// ==================== SHARED DATA ====================
|
||||||
|
|
||||||
|
protected final EnergyCombatData combatData;
|
||||||
|
protected final EnergyLifespanData lifespanData;
|
||||||
|
|
||||||
|
// ==================== RUNTIME STATE ====================
|
||||||
|
|
||||||
|
protected transient E[] entities;
|
||||||
|
protected transient boolean[] zoneSpawned;
|
||||||
|
protected transient int spawnedCount;
|
||||||
|
protected transient String[] chargeVisualIds;
|
||||||
|
protected transient EntityLivingBase chargeVisualCaster;
|
||||||
|
|
||||||
|
protected transient List<double[]> preCalculatedPositions = new ArrayList<>();
|
||||||
|
|
||||||
|
// ==================== CONSTRUCTOR ====================
|
||||||
|
|
||||||
|
protected AbilityEnergyZone(EnergyDisplayData displayData,
|
||||||
|
EnergyCombatData combatData,
|
||||||
|
EnergyLifespanData lifespanData) {
|
||||||
|
super(displayData);
|
||||||
|
this.combatData = combatData;
|
||||||
|
this.lifespanData = lifespanData;
|
||||||
|
this.burstOverlap = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ABSTRACT METHODS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a single zone entity at the given position.
|
||||||
|
* Called when a zone actually spawns.
|
||||||
|
*/
|
||||||
|
protected abstract E createEntity(EntityLivingBase caster, EntityLivingBase target,
|
||||||
|
double x, double y, double z,
|
||||||
|
EnergyDisplayData resolved, int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure entity for charge visual during windup (non-preview).
|
||||||
|
*/
|
||||||
|
protected abstract void setupEntityCharging(E entity, int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure entity for GUI preview mode.
|
||||||
|
*/
|
||||||
|
protected abstract void setupEntityPreview(E entity, EntityLivingBase caster,
|
||||||
|
EnergyDisplayData resolved, int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create typed array. Required because Java generics cannot create generic arrays.
|
||||||
|
*/
|
||||||
|
protected abstract E[] createEntityArray(int size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegraph radius for this zone type.
|
||||||
|
*/
|
||||||
|
protected abstract float getZoneTelegraphRadius();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add type-specific GUI field definitions.
|
||||||
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
protected abstract void addTypeDefinitions(List<FieldDef> defs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write type-specific fields to NBT.
|
||||||
|
* Shared data classes are written by the base class.
|
||||||
|
*/
|
||||||
|
protected abstract void writeTypeSpecificNBT(NBTTagCompound nbt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read type-specific fields from NBT.
|
||||||
|
* Shared data classes are read by the base class.
|
||||||
|
*/
|
||||||
|
protected abstract void readTypeSpecificNBT(NBTTagCompound nbt);
|
||||||
|
|
||||||
|
// ==================== OVERRIDABLE HOOKS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the spawn position for zone index.
|
||||||
|
* Default uses preCalculatedPositions when available, falls back to target position.
|
||||||
|
* Subclasses override for type-specific positioning (e.g. Pillar MOVING mode).
|
||||||
|
*/
|
||||||
|
protected double[] getSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||||
|
if (index < preCalculatedPositions.size()) {
|
||||||
|
return preCalculatedPositions.get(index);
|
||||||
|
}
|
||||||
|
if (target != null) {
|
||||||
|
return new double[]{target.posX, target.posY, target.posZ};
|
||||||
|
}
|
||||||
|
return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the display data for a specific zone index.
|
||||||
|
* Default returns the shared displayData. Override for per-zone color overrides.
|
||||||
|
*/
|
||||||
|
protected EnergyDisplayData resolveDisplay(int index) {
|
||||||
|
return displayData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ZONE COUNT ====================
|
||||||
|
|
||||||
|
public int getZoneCount() {
|
||||||
|
return zoneCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZoneCount(int count) {
|
||||||
|
this.zoneCount = Math.max(1, Math.min(count, MAX_ZONES));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFireDelay() {
|
||||||
|
return fireDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFireDelay(int delay) {
|
||||||
|
this.fireDelay = Math.max(0, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== RUNTIME STATE INIT ====================
|
||||||
|
|
||||||
|
protected void initRuntimeState(EntityLivingBase caster) {
|
||||||
|
entities = createEntityArray(zoneCount);
|
||||||
|
zoneSpawned = new boolean[zoneCount];
|
||||||
|
spawnedCount = 0;
|
||||||
|
chargeVisualIds = new String[zoneCount];
|
||||||
|
chargeVisualCaster = caster;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ENTITY CREATION ====================
|
||||||
|
|
||||||
|
protected E createZoneEntity(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||||
|
return createZoneEntityAt(caster, target, index, getSpawnPosition(caster, target, index));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected E createZoneEntityAt(EntityLivingBase caster, EntityLivingBase target, int index, double[] pos) {
|
||||||
|
EnergyDisplayData resolved = resolveDisplay(index);
|
||||||
|
E entity = createEntity(caster, target, pos[0], pos[1], pos[2], resolved, index);
|
||||||
|
entity.setSourceAbility(this);
|
||||||
|
entity.setIgnoreIFrames(this.isIgnoreIFrames());
|
||||||
|
entity.setEffects(this.effects);
|
||||||
|
// Copy ability combat data to entity so hitType, damage, knockback are in sync
|
||||||
|
noppes.npcs.controllers.data.MagicData resolvedMagic = resolveMagicData(caster);
|
||||||
|
if (resolvedMagic != null) {
|
||||||
|
entity.setMagicData(resolvedMagic.copy());
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get spawn position for charge visual during windup.
|
||||||
|
* Default: same as getSpawnPosition. Override for types where windup position
|
||||||
|
* differs from execute position (e.g. Pillar MOVING uses target pos during windup).
|
||||||
|
*/
|
||||||
|
protected double[] getWindupSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||||
|
return getSpawnPosition(caster, target, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void spawnZoneEntity(E entity, int index) {
|
||||||
|
if (entity == null) return;
|
||||||
|
spawnAbilityEntity(entity);
|
||||||
|
entities[index] = entity;
|
||||||
|
if (!zoneSpawned[index]) {
|
||||||
|
zoneSpawned[index] = true;
|
||||||
|
spawnedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void spawnZoneAt(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||||
|
if (entities != null && entities[index] != null && !entities[index].isDead) return;
|
||||||
|
E entity = createZoneEntity(caster, target, index);
|
||||||
|
spawnZoneEntity(entity, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== CHARGE VISUAL ====================
|
||||||
|
|
||||||
|
protected String getChargeVisualId(EntityLivingBase caster, int index) {
|
||||||
|
return "energy_charge:" + caster.getEntityId() + ":" + executionStartTime + ":" + burstIndex + ":" + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void spawnChargeVisual(EntityLivingBase caster, EntityLivingBase target, int index, int chargeDuration) {
|
||||||
|
if (isPreview() || caster == null || caster.worldObj == null || caster.worldObj.isRemote) return;
|
||||||
|
if (chargeVisualIds == null || index < 0 || index >= chargeVisualIds.length) return;
|
||||||
|
|
||||||
|
double[] windupPos = getWindupSpawnPosition(caster, target, index);
|
||||||
|
E previewEntity = createZoneEntityAt(caster, target, index, windupPos);
|
||||||
|
previewEntity.setPreviewMode(true);
|
||||||
|
previewEntity.setPreviewOwner(caster);
|
||||||
|
setupEntityCharging(previewEntity, index);
|
||||||
|
previewEntity.setChargeDuration(Math.max(1, chargeDuration));
|
||||||
|
previewEntity.setTargetEntity(target);
|
||||||
|
|
||||||
|
String id = getChargeVisualId(caster, index);
|
||||||
|
chargeVisualIds[index] = id;
|
||||||
|
chargeVisualCaster = caster;
|
||||||
|
EnergyChargeSpawnPacket.sendToTracking(id, previewEntity, caster);
|
||||||
|
|
||||||
|
EnergyChargeTracker.Instance.add(new EnergyChargeTracker.ChargeEntry(
|
||||||
|
id,
|
||||||
|
previewEntity.getClass().getName(),
|
||||||
|
previewEntity.exportSpawnNBT(),
|
||||||
|
caster.getEntityId(),
|
||||||
|
(int) caster.worldObj.getTotalWorldTime()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeChargeVisual(EntityLivingBase caster, int index) {
|
||||||
|
if (isPreview() || caster == null || caster.worldObj == null || caster.worldObj.isRemote) return;
|
||||||
|
if (chargeVisualIds == null || index < 0 || index >= chargeVisualIds.length) return;
|
||||||
|
|
||||||
|
String id = chargeVisualIds[index];
|
||||||
|
if (id != null && !id.isEmpty()) {
|
||||||
|
EnergyChargeRemovePacket.sendToTracking(id, caster);
|
||||||
|
EnergyChargeTracker.Instance.remove(id, caster.getEntityId());
|
||||||
|
chargeVisualIds[index] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeAllChargeVisuals(EntityLivingBase caster) {
|
||||||
|
if (chargeVisualIds == null || caster == null) return;
|
||||||
|
for (int i = 0; i < chargeVisualIds.length; i++) {
|
||||||
|
removeChargeVisual(caster, i);
|
||||||
|
}
|
||||||
|
if (!isPreview() && caster.worldObj != null && !caster.worldObj.isRemote) {
|
||||||
|
EnergyChargeTracker.Instance.removeAllForCaster(caster.getEntityId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== LIFECYCLE ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowOverlap() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowFreeOnCast() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTargetingModeLocked() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetingMode[] getAllowedTargetingModes() {
|
||||||
|
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReadyForBurstCompletion(int activeTick) {
|
||||||
|
return fireDelay <= 0 || activeTick >= fireDelay * (zoneCount - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detach() {
|
||||||
|
entities = null;
|
||||||
|
zoneSpawned = null;
|
||||||
|
spawnedCount = 0;
|
||||||
|
preCalculatedPositions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, int tick) {
|
||||||
|
if (caster.worldObj.isRemote && !isPreview()) return;
|
||||||
|
|
||||||
|
if (tick == 1) {
|
||||||
|
initRuntimeState(caster);
|
||||||
|
|
||||||
|
if (isPreview()) {
|
||||||
|
for (int i = 0; i < zoneCount; i++) {
|
||||||
|
E previewEntity = createZoneEntity(caster, target, i);
|
||||||
|
setupEntityPreview(previewEntity, caster, resolveDisplay(i), i);
|
||||||
|
spawnAbilityEntity(previewEntity);
|
||||||
|
entities[i] = previewEntity;
|
||||||
|
zoneSpawned[i] = true;
|
||||||
|
spawnedCount++;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < zoneCount; i++) {
|
||||||
|
spawnChargeVisual(caster, target, i, windUpTicks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetForBurst() {
|
||||||
|
removeAllChargeVisuals(chargeVisualCaster);
|
||||||
|
if (!burstOverlap) {
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
entities = null;
|
||||||
|
zoneSpawned = null;
|
||||||
|
spawnedCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExecute(EntityLivingBase caster, EntityLivingBase target) {
|
||||||
|
if (isPreview()) {
|
||||||
|
if (entities == null) {
|
||||||
|
initRuntimeState(caster);
|
||||||
|
for (int i = 0; i < zoneCount; i++) {
|
||||||
|
E previewEntity = createZoneEntity(caster, target, i);
|
||||||
|
setupEntityPreview(previewEntity, caster, resolveDisplay(i), i);
|
||||||
|
spawnAbilityEntity(previewEntity);
|
||||||
|
entities[i] = previewEntity;
|
||||||
|
zoneSpawned[i] = true;
|
||||||
|
spawnedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entities == null || zoneSpawned == null || entities.length != zoneCount) {
|
||||||
|
initRuntimeState(caster);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeAllChargeVisuals(caster);
|
||||||
|
|
||||||
|
spawnZoneAt(caster, target, 0);
|
||||||
|
|
||||||
|
if (fireDelay <= 0) {
|
||||||
|
for (int i = 1; i < zoneCount; i++) {
|
||||||
|
spawnZoneAt(caster, target, i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 1; i < zoneCount; i++) {
|
||||||
|
spawnChargeVisual(caster, target, i, fireDelay * i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, int tick) {
|
||||||
|
if (entities == null || zoneSpawned == null) {
|
||||||
|
signalCompletion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fireDelay > 0) {
|
||||||
|
for (int i = 1; i < zoneCount; i++) {
|
||||||
|
if (tick == fireDelay * i) {
|
||||||
|
removeChargeVisual(caster, i);
|
||||||
|
spawnZoneAt(caster, target, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFreeOnCast()) {
|
||||||
|
int lastSpawnTick = fireDelay > 0 ? fireDelay * (zoneCount - 1) : 0;
|
||||||
|
if (tick >= lastSpawnTick) {
|
||||||
|
signalCompletion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean allDead = spawnedCount >= zoneCount;
|
||||||
|
if (allDead) {
|
||||||
|
for (E entity : entities) {
|
||||||
|
if (entity == null || entity.isDead) continue;
|
||||||
|
if (!isPreview() && tick > 5 && entity.worldObj != null
|
||||||
|
&& entity.worldObj.getEntityByID(entity.getEntityId()) != entity) {
|
||||||
|
entity.setDead();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allDead = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allDead) {
|
||||||
|
int lastSpawnTick = fireDelay > 0 ? fireDelay * (zoneCount - 1) : 0;
|
||||||
|
int maxLifetime = lifespanData.getMaxLifetime() > 0 ? lifespanData.getMaxLifetime() : 200;
|
||||||
|
if (tick > lastSpawnTick + maxLifetime + 20) {
|
||||||
|
cleanup();
|
||||||
|
allDead = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allDead) {
|
||||||
|
signalCompletion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
|
||||||
|
removeAllChargeVisuals(caster);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {
|
||||||
|
removeAllChargeVisuals(caster);
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanup() {
|
||||||
|
removeAllChargeVisuals(chargeVisualCaster);
|
||||||
|
if (entities != null) {
|
||||||
|
for (int i = 0; i < entities.length; i++) {
|
||||||
|
if (entities[i] != null && !entities[i].isDead) {
|
||||||
|
entities[i].setDead();
|
||||||
|
}
|
||||||
|
entities[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entities = null;
|
||||||
|
zoneSpawned = null;
|
||||||
|
spawnedCount = 0;
|
||||||
|
chargeVisualIds = null;
|
||||||
|
chargeVisualCaster = null;
|
||||||
|
preCalculatedPositions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== PREVIEW ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxPreviewDuration() {
|
||||||
|
return lifespanData.getMaxLifetime() > 0 ? Math.min(lifespanData.getMaxLifetime(), 100) : 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== NBT ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void writeTypeNBT(NBTTagCompound nbt) {
|
||||||
|
writeTypeSpecificNBT(nbt);
|
||||||
|
|
||||||
|
nbt.setInteger("zoneCount", zoneCount);
|
||||||
|
nbt.setInteger("fireDelay", fireDelay);
|
||||||
|
|
||||||
|
writeEnergyNBT(nbt);
|
||||||
|
combatData.writeNBT(nbt);
|
||||||
|
lifespanData.writeNBT(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void readTypeNBT(NBTTagCompound nbt) {
|
||||||
|
readTypeSpecificNBT(nbt);
|
||||||
|
|
||||||
|
this.zoneCount = Math.max(1, Math.min(nbt.getInteger("zoneCount"), MAX_ZONES));
|
||||||
|
this.fireDelay = Math.max(0, nbt.getInteger("fireDelay"));
|
||||||
|
|
||||||
|
readEnergyNBT(nbt);
|
||||||
|
combatData.readNBT(nbt);
|
||||||
|
lifespanData.readNBT(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== GUI ====================
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@Override
|
||||||
|
public final void getAbilityDefinitions(List<FieldDef> defs) {
|
||||||
|
defs.add(FieldDef.enumField("ability.hitType", HitType.class,
|
||||||
|
() -> HitType.fromOrdinal(getHitType()),
|
||||||
|
v -> setHitType(v.ordinal()))
|
||||||
|
.hover("ability.hover.hitType"));
|
||||||
|
defs.add(FieldDef.intField("ability.multiHitDelay", this::getMultiHitDelayTicks, this::setMultiHitDelayTicks)
|
||||||
|
.range(1, 200)
|
||||||
|
.visibleWhen(() -> getHitType() == HitType.MULTI.ordinal())
|
||||||
|
.hover("ability.hover.multiHitDelay"));
|
||||||
|
defs.add(FieldDef.intField("ability.maxHits", this::getMaxHits, this::setMaxHits)
|
||||||
|
.range(1, EnergyCombatData.MAX_HITS)
|
||||||
|
.visibleWhen(() -> getHitType() != HitType.SINGLE.ordinal())
|
||||||
|
.hover("ability.hover.maxHits"));
|
||||||
|
|
||||||
|
defs.add(FieldDef.row(
|
||||||
|
FieldDef.intField("ability.zoneCount", this::getZoneCount, this::setZoneCount)
|
||||||
|
.range(1, MAX_ZONES),
|
||||||
|
FieldDef.intField("ability.fireDelay", this::getFireDelay, this::setFireDelay)
|
||||||
|
.range(0, 200).visibleWhen(() -> zoneCount > 1)
|
||||||
|
));
|
||||||
|
|
||||||
|
addTypeDefinitions(defs);
|
||||||
|
|
||||||
|
addEnergyColorDefinitions(defs);
|
||||||
|
|
||||||
|
defs.add(FieldDef.section("ability.section.effects").tab("ability.tab.visual"));
|
||||||
|
defs.add(FieldDef.floatField("ability.rotationSpeed", this::getRotationSpeed, this::setRotationSpeed)
|
||||||
|
.tab("ability.tab.visual"));
|
||||||
|
addEnergyLightningDefinitions(defs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== COMBAT GETTERS & SETTERS ====================
|
||||||
|
|
||||||
|
public float getDamage() { return combatData.getDamage(); }
|
||||||
|
public void setDamage(float damage) { combatData.setDamage(damage); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getDisplayDamage() { return combatData.getDamage(); }
|
||||||
|
|
||||||
|
public float getKnockback() { return combatData.knockback; }
|
||||||
|
public void setKnockback(float knockback) { combatData.setKnockback(knockback); }
|
||||||
|
|
||||||
|
public int getHitType() { return combatData.hitType.ordinal(); }
|
||||||
|
public void setHitType(int hitType) { combatData.hitType = HitType.fromOrdinal(hitType); }
|
||||||
|
|
||||||
|
public int getMultiHitDelayTicks() { return combatData.multiHitDelayTicks; }
|
||||||
|
public void setMultiHitDelayTicks(int delay) { combatData.multiHitDelayTicks = Math.max(1, delay); }
|
||||||
|
|
||||||
|
public int getMaxHits() { return combatData.getMaxHits(); }
|
||||||
|
public void setMaxHits(int maxHits) { combatData.setMaxHits(maxHits); }
|
||||||
|
|
||||||
|
public int getMaxLifetime() { return lifespanData.getMaxLifetime(); }
|
||||||
|
public void setMaxLifetime(int ticks) { lifespanData.setMaxLifetime(ticks); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,487 @@
|
|||||||
|
package kamkeel.npcs.controllers.data.ability.type.energy;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.energy.*;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.enums.LockMode;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldDefs;
|
||||||
|
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||||
|
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||||
|
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.OffsetAxis;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.PillarMode;
|
||||||
|
import kamkeel.npcs.entity.EntityAbilityPillar.PillarShape;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.Vec3;
|
||||||
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static kamkeel.npcs.entity.EntityAbilityPillar.MIN_HEIGHT;
|
||||||
|
import static kamkeel.npcs.entity.EntityAbilityPillar.MIN_RADIUS;
|
||||||
|
import static kamkeel.npcs.entity.EntityAbilityPillar.MAX_ZONE_HEIGHT;
|
||||||
|
import static kamkeel.npcs.entity.EntityAbilityPillar.MAX_ZONE_RADIUS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pillar zone ability.
|
||||||
|
*
|
||||||
|
* ANCHORED: spawns at target position at execute time.
|
||||||
|
* - trackTarget: predicts where target will be based on current velocity, spawns there.
|
||||||
|
* - followTarget (requires homing): pillar chases target after spawn.
|
||||||
|
* When count > 1: each pillar after index 0 gets a random nearby position.
|
||||||
|
*
|
||||||
|
* MOVING: spawns in front of caster and travels forward.
|
||||||
|
* - Without homing: straight line.
|
||||||
|
* - With homing: steers toward target.
|
||||||
|
* When count > 1: pillarOffset spaces pillars along offsetAxis relative to look vector.
|
||||||
|
* OffsetAxis.Z = along look direction (one behind the other).
|
||||||
|
* OffsetAxis.X = perpendicular to look direction (side by side).
|
||||||
|
*
|
||||||
|
* TODO 1. fix charging visual for ABOVE origin; 2. fix hitbox for ABOVE origin; 3. fix trackTarget to actually track the player
|
||||||
|
*/
|
||||||
|
public class AbilityPillar extends AbilityEnergyZone<EntityAbilityPillar> {
|
||||||
|
|
||||||
|
// ==================== CONFIG ====================
|
||||||
|
|
||||||
|
private EnergyPillarData pillarData = new EnergyPillarData();
|
||||||
|
private EnergyHomingData homingData = new EnergyHomingData();
|
||||||
|
|
||||||
|
private float pillarOffset = 0f;
|
||||||
|
private OffsetAxis offsetAxis = OffsetAxis.Z;
|
||||||
|
|
||||||
|
/** ANCHORED only: follow target after spawn (requires homing). */
|
||||||
|
private boolean followTarget = false;
|
||||||
|
|
||||||
|
/** ANCHORED only: predict target position at spawn time from target velocity. */
|
||||||
|
private boolean trackTarget = false;
|
||||||
|
|
||||||
|
// ==================== CONSTRUCTOR ====================
|
||||||
|
|
||||||
|
public AbilityPillar() {
|
||||||
|
super(new EnergyDisplayData(), new EnergyCombatData(), new EnergyLifespanData());
|
||||||
|
this.typeId = "ability.cnpc.pillar";
|
||||||
|
this.name = "Pillar";
|
||||||
|
this.targetingMode = TargetingMode.AGGRO_TARGET;
|
||||||
|
this.maxRange = 25.0f;
|
||||||
|
this.minRange = 5.0f;
|
||||||
|
this.cooldownTicks = 0;
|
||||||
|
this.windUpTicks = 30;
|
||||||
|
this.lockMovement = LockMode.WINDUP;
|
||||||
|
this.telegraphType = pillarData.shape.getTelegraphType();
|
||||||
|
this.showTelegraph = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ABSTRACT IMPLEMENTATIONS ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EntityAbilityPillar createEntity(EntityLivingBase caster, EntityLivingBase target,
|
||||||
|
double x, double y, double z,
|
||||||
|
EnergyDisplayData resolved, int index) {
|
||||||
|
return new EntityAbilityPillar(caster.worldObj, caster, x, y, z,
|
||||||
|
pillarData, resolved, combatData, homingData, lightningData, lifespanData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setupEntityCharging(EntityAbilityPillar entity, int index) {
|
||||||
|
entity.setupCharging(windUpTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setupEntityPreview(EntityAbilityPillar entity, EntityLivingBase caster,
|
||||||
|
EnergyDisplayData resolved, int index) {
|
||||||
|
entity.setupPreview(caster, pillarData, resolved, lightningData, windUpTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EntityAbilityPillar[] createEntityArray(int size) {
|
||||||
|
return new EntityAbilityPillar[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getZoneTelegraphRadius() {
|
||||||
|
return pillarData.targetRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== SPAWN POSITIONS ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected double[] getSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||||
|
if (pillarData.mode == PillarMode.MOVING) {
|
||||||
|
return getMovingSpawnPosition(caster, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ANCHORED: spawn at target's current position at execute time
|
||||||
|
if (index == 0) {
|
||||||
|
if (target == null) return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||||
|
|
||||||
|
double spawnX = target.posX;
|
||||||
|
double spawnZ = target.posZ;
|
||||||
|
|
||||||
|
if (trackTarget) {
|
||||||
|
double motionX = target.posX - target.prevPosX;
|
||||||
|
double motionZ = target.posZ - target.prevPosZ;
|
||||||
|
|
||||||
|
// Predict where target will be based on current motion and spawnDelay
|
||||||
|
double prediction = pillarData.spawnDelay * homingData.getHomingStrength();
|
||||||
|
|
||||||
|
spawnX += motionX * prediction;
|
||||||
|
spawnZ += motionZ * prediction;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new double[]{spawnX, target.posY, spawnZ};
|
||||||
|
}
|
||||||
|
|
||||||
|
// index > 0: random nearby position
|
||||||
|
double baseX = target != null ? target.posX : caster.posX;
|
||||||
|
double baseZ = target != null ? target.posZ : caster.posZ;
|
||||||
|
double baseY = target != null ? target.posY : caster.posY;
|
||||||
|
float spread = Math.max(pillarData.targetRadius * 2.0f, 3.0f);
|
||||||
|
double angle = Math.random() * Math.PI * 2;
|
||||||
|
double dist = Math.sqrt(Math.random()) * spread;
|
||||||
|
return new double[]{baseX + Math.cos(angle) * dist, baseY, baseZ + Math.sin(angle) * dist};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected double[] getWindupSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||||
|
if (pillarData.mode == PillarMode.MOVING) {
|
||||||
|
return getMovingSpawnPosition(caster, index);
|
||||||
|
}
|
||||||
|
if (index == 0 && !preCalculatedPositions.isEmpty()) {
|
||||||
|
return preCalculatedPositions.get(0);
|
||||||
|
}
|
||||||
|
if (target != null) return new double[]{target.posX, target.posY, target.posZ};
|
||||||
|
return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spawn position for MOVING mode.
|
||||||
|
* OffsetAxis.Z = offset along look direction (one behind the other).
|
||||||
|
* OffsetAxis.X = offset perpendicular to look direction (side by side).
|
||||||
|
*/
|
||||||
|
private double[] getMovingSpawnPosition(EntityLivingBase caster, int index) {
|
||||||
|
Vec3 look = caster.getLookVec();
|
||||||
|
if (look == null) return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||||
|
|
||||||
|
float baseDist = Math.max(1.0f, pillarData.targetRadius);
|
||||||
|
|
||||||
|
// Forward direction (normalized XZ)
|
||||||
|
double fwdX = look.xCoord;
|
||||||
|
double fwdZ = look.zCoord;
|
||||||
|
double fwdLen = Math.sqrt(fwdX * fwdX + fwdZ * fwdZ);
|
||||||
|
if (fwdLen > 0) { fwdX /= fwdLen; fwdZ /= fwdLen; }
|
||||||
|
|
||||||
|
// Right direction = perpendicular to forward in XZ plane
|
||||||
|
double rightX = fwdZ;
|
||||||
|
double rightZ = -fwdX;
|
||||||
|
|
||||||
|
double ox, oz;
|
||||||
|
if (offsetAxis == OffsetAxis.Z) {
|
||||||
|
// Along look direction
|
||||||
|
ox = fwdX * pillarOffset * index;
|
||||||
|
oz = fwdZ * pillarOffset * index;
|
||||||
|
} else {
|
||||||
|
// Perpendicular to look direction
|
||||||
|
// Center the group: offset by -(count-1)/2 * spacing + index * spacing
|
||||||
|
double centerOffset = -(zoneCount - 1) * 0.5 * pillarOffset + index * pillarOffset;
|
||||||
|
ox = rightX * centerOffset;
|
||||||
|
oz = rightZ * centerOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new double[]{
|
||||||
|
caster.posX + fwdX * baseDist + ox,
|
||||||
|
caster.posY,
|
||||||
|
caster.posZ + fwdZ * baseDist + oz
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== EXECUTE ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void spawnZoneAt(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||||
|
super.spawnZoneAt(caster, target, index);
|
||||||
|
EntityAbilityPillar entity = entities[index];
|
||||||
|
if (entity == null || entity.isDead) return;
|
||||||
|
|
||||||
|
if (target != null) {
|
||||||
|
entity.setTarget(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pillarData.mode == PillarMode.ANCHORED) {
|
||||||
|
entity.setFollowTarget(followTarget && homingData.isHoming());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pillarData.mode == PillarMode.MOVING && !homingData.isHoming()) {
|
||||||
|
Vec3 look = caster.getLookVec();
|
||||||
|
double mx = 0, mz = 0;
|
||||||
|
if (target != null) {
|
||||||
|
double dx = target.posX - entity.posX;
|
||||||
|
double dz = target.posZ - entity.posZ;
|
||||||
|
double len = Math.sqrt(dx * dx + dz * dz);
|
||||||
|
if (len > 0) { mx = (dx / len) * homingData.getSpeed(); mz = (dz / len) * homingData.getSpeed(); }
|
||||||
|
} else if (look != null) {
|
||||||
|
mx = look.xCoord * homingData.getSpeed();
|
||||||
|
mz = look.zCoord * homingData.getSpeed();
|
||||||
|
}
|
||||||
|
entity.setInitialMotion(mx, mz);
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.startGrowing();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== TELEGRAPH ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
|
||||||
|
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster)) return null;
|
||||||
|
|
||||||
|
Telegraph telegraph = pillarData.shape == PillarShape.SQUARE
|
||||||
|
? Telegraph.square(pillarData.targetRadius)
|
||||||
|
: Telegraph.circle(pillarData.targetRadius);
|
||||||
|
|
||||||
|
telegraph.setDurationTicks(windUpTicks);
|
||||||
|
telegraph.setColor(windUpColor);
|
||||||
|
telegraph.setWarningColor(activeColor);
|
||||||
|
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
|
||||||
|
telegraph.setHeightOffset(telegraphHeightOffset);
|
||||||
|
|
||||||
|
double telegraphX, telegraphZ, telegraphY;
|
||||||
|
|
||||||
|
if (pillarData.mode == PillarMode.MOVING) {
|
||||||
|
double[] pos = getMovingSpawnPosition(caster, 0);
|
||||||
|
telegraphX = pos[0];
|
||||||
|
telegraphZ = pos[2];
|
||||||
|
telegraphY = findGroundLevel(caster.worldObj, telegraphX, caster.posY, telegraphZ);
|
||||||
|
} else {
|
||||||
|
if (target == null) return null;
|
||||||
|
// Regular: start at target's current position, telegraph follows target
|
||||||
|
telegraphX = target.posX;
|
||||||
|
telegraphZ = target.posZ;
|
||||||
|
telegraphY = findGroundLevel(caster.worldObj, telegraphX, target.posY, telegraphZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
preCalculatedPositions.clear();
|
||||||
|
preCalculatedPositions.add(new double[]{telegraphX, telegraphY, telegraphZ});
|
||||||
|
|
||||||
|
TelegraphInstance instance = new TelegraphInstance(
|
||||||
|
telegraph, telegraphX, telegraphY, telegraphZ, caster.rotationYaw);
|
||||||
|
instance.setCasterEntityId(caster.getEntityId());
|
||||||
|
|
||||||
|
// ANCHORED: telegraph follows target in real time (regular and trackTarget)
|
||||||
|
// MOVING: telegraph is static at spawn point
|
||||||
|
if (pillarData.mode == PillarMode.ANCHORED && target != null) {
|
||||||
|
instance.setEntityIdToFollow(target.getEntityId());
|
||||||
|
} else {
|
||||||
|
instance.setEntityIdToFollow(-1);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getTelegraphRadius() {
|
||||||
|
return pillarData.targetRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== NBT ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeTypeSpecificNBT(NBTTagCompound nbt) {
|
||||||
|
pillarData.writeNBT(nbt);
|
||||||
|
homingData.writeNBT(nbt);
|
||||||
|
nbt.setFloat("pillarOffset", pillarOffset);
|
||||||
|
nbt.setInteger("offsetAxis", offsetAxis.ordinal());
|
||||||
|
nbt.setBoolean("followTarget", followTarget);
|
||||||
|
nbt.setBoolean("trackTarget", trackTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readTypeSpecificNBT(NBTTagCompound nbt) {
|
||||||
|
pillarData.readNBT(nbt);
|
||||||
|
homingData.readNBT(nbt);
|
||||||
|
this.pillarOffset = nbt.hasKey("pillarOffset") ? nbt.getFloat("pillarOffset") : 0f;
|
||||||
|
int axisOrd = nbt.hasKey("offsetAxis") ? nbt.getInteger("offsetAxis") : 1;
|
||||||
|
this.offsetAxis = (axisOrd >= 0 && axisOrd < OffsetAxis.values().length)
|
||||||
|
? OffsetAxis.values()[axisOrd] : OffsetAxis.Z;
|
||||||
|
this.followTarget = nbt.hasKey("followTarget") && nbt.getBoolean("followTarget");
|
||||||
|
this.trackTarget = nbt.hasKey("trackTarget") && nbt.getBoolean("trackTarget");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== GUI ====================
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@Override
|
||||||
|
protected void addTypeDefinitions(List<FieldDef> defs) {
|
||||||
|
FieldDef.insertAfter(defs, "ability.fireDelay", FieldDef.row(
|
||||||
|
FieldDef.floatField("ability.pillar.offset", this::getPillarOffset, this::setPillarOffset).range(0f, 20f),
|
||||||
|
FieldDef.enumField("ability.pillar.offsetAxis", OffsetAxis.class, this::getOffsetAxis, this::setOffsetAxis)
|
||||||
|
).visibleWhen(() -> zoneCount > 1 && pillarData.mode == PillarMode.MOVING));
|
||||||
|
|
||||||
|
defs.add(FieldDef.section("ability.section.pillar"));
|
||||||
|
|
||||||
|
defs.add(FieldDef.enumField("ability.pillarMode", PillarMode.class,
|
||||||
|
this::getMode, this::setMode));
|
||||||
|
|
||||||
|
defs.add(FieldDef.enumField("ability.pillarOrigin", EntityAbilityPillar.PillarOrigin.class,
|
||||||
|
this::getOrigin, this::setOrigin));
|
||||||
|
|
||||||
|
defs.add(FieldDef.enumField("ability.pillarShape", PillarShape.class,
|
||||||
|
this::getShape, this::setShape));
|
||||||
|
|
||||||
|
defs.add(FieldDef.intField("ability.pillar.spawnDelay",
|
||||||
|
this::getSpawnDelay, this::setSpawnDelay).range(0, getMaxLifetime()));
|
||||||
|
|
||||||
|
defs.add(FieldDef.section("ability.section.size"));
|
||||||
|
|
||||||
|
defs.add(FieldDef.row(
|
||||||
|
FieldDef.floatField("ability.pillar.targetRadius", this::getTargetRadius, this::setTargetRadius).range(0.1f, 64f),
|
||||||
|
FieldDef.floatField("ability.pillar.targetHeight", this::getTargetHeight, this::setTargetHeight).range(0.1f, 64f)
|
||||||
|
));
|
||||||
|
|
||||||
|
defs.add(FieldDef.row(
|
||||||
|
FieldDef.floatField("ability.pillar.radiusGrowSpeed", this::getRadiusGrowSpeed, this::setRadiusGrowSpeed),
|
||||||
|
FieldDef.floatField("ability.pillar.heightGrowSpeed", this::getHeightGrowSpeed, this::setRadiusGrowSpeed)
|
||||||
|
));
|
||||||
|
|
||||||
|
defs.add(FieldDef.section("ability.section.movement"));
|
||||||
|
|
||||||
|
defs.add(FieldDef.floatField("ability.speed", this::getPillarSpeed, this::setPillarSpeed)
|
||||||
|
.range(0.01f, 10f));
|
||||||
|
|
||||||
|
defs.add(FieldDef.boolField("ability.homing", this::isHoming, this::setHoming));
|
||||||
|
|
||||||
|
defs.add(FieldDef.row(
|
||||||
|
FieldDef.floatField("ability.homingStrength", this::getHomingStrength, this::setHomingStrength),
|
||||||
|
FieldDef.floatField("ability.homingRange", this::getHomingRange, this::setHomingRange)
|
||||||
|
).visibleWhen(this::isHoming));
|
||||||
|
|
||||||
|
// ANCHORED-only options
|
||||||
|
defs.add(FieldDef.boolField("ability.pillar.trackTarget", this::isTrackTarget, this::setTrackTarget)
|
||||||
|
.visibleWhen(() -> pillarData.mode == PillarMode.ANCHORED));
|
||||||
|
|
||||||
|
defs.add(FieldDef.boolField("ability.pillar.followTarget", this::isFollowTarget, this::setFollowTarget)
|
||||||
|
.visibleWhen(() -> pillarData.mode == PillarMode.ANCHORED && homingData.isHoming()));
|
||||||
|
|
||||||
|
defs.add(FieldDef.section("ability.section.combat"));
|
||||||
|
|
||||||
|
defs.add(FieldDef.floatField("ability.damage", this::getDamage, this::setDamage).range(0f, 1000f));
|
||||||
|
defs.add(FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback).range(0f, 10f));
|
||||||
|
defs.add(FieldDef.intField("ability.maxLifetime", this::getMaxLifetime, this::setMaxLifetime).range(1, 1200));
|
||||||
|
|
||||||
|
defs.add(AbilityFieldDefs.effectsListField("ability.effects", this::getEffects, this::setEffects));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== GETTERS & SETTERS ====================
|
||||||
|
|
||||||
|
public EnergyPillarData getPillarData() { return pillarData; }
|
||||||
|
public void setPillarData(EnergyPillarData data) { this.pillarData = data != null ? data : new EnergyPillarData(); }
|
||||||
|
|
||||||
|
public float getPillarOffset() { return pillarOffset; }
|
||||||
|
public void setPillarOffset(float offset) { this.pillarOffset = Math.max(0f, Math.min(20f, offset)); }
|
||||||
|
|
||||||
|
public OffsetAxis getOffsetAxis() { return offsetAxis; }
|
||||||
|
public void setOffsetAxis(OffsetAxis axis) { this.offsetAxis = axis != null ? axis : OffsetAxis.Z; }
|
||||||
|
|
||||||
|
public boolean isFollowTarget() { return followTarget; }
|
||||||
|
public void setFollowTarget(boolean v) { this.followTarget = v; }
|
||||||
|
|
||||||
|
public boolean isTrackTarget() { return trackTarget; }
|
||||||
|
public void setTrackTarget(boolean v) { this.trackTarget = v; }
|
||||||
|
|
||||||
|
public float getTargetRadius() {
|
||||||
|
return pillarData.targetRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetRadius(float targetRadius) {
|
||||||
|
pillarData.targetRadius = Math.max(MIN_RADIUS, Math.min(MAX_ZONE_RADIUS, targetRadius));
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getTargetHeight() {
|
||||||
|
return pillarData.targetHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetHeight(float targetHeight) {
|
||||||
|
pillarData.targetHeight = Math.max(MIN_HEIGHT, Math.min(MAX_ZONE_HEIGHT, targetHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRadiusGrowSpeed() {
|
||||||
|
return pillarData.radiusGrowSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadiusGrowSpeed(float radiusGrowSpeed) {
|
||||||
|
pillarData.radiusGrowSpeed = Math.max(0.01f, radiusGrowSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHeightGrowSpeed() {
|
||||||
|
return pillarData.heightGrowSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeightGrowSpeed(float heightGrowSpeed) {
|
||||||
|
pillarData.heightGrowSpeed = Math.max(0.01f, heightGrowSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PillarMode getMode() {
|
||||||
|
return pillarData.mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode(PillarMode mode) {
|
||||||
|
pillarData.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityAbilityPillar.PillarOrigin getOrigin() {
|
||||||
|
return pillarData.origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrigin(EntityAbilityPillar.PillarOrigin origin) {
|
||||||
|
pillarData.origin = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PillarShape getShape() {
|
||||||
|
return pillarData.shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShape(PillarShape shape) {
|
||||||
|
pillarData.shape = shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpawnDelay() {
|
||||||
|
return pillarData.spawnDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpawnDelay(int spawnDelay) {
|
||||||
|
pillarData.spawnDelay = Math.max(0, Math.min(getMaxLifetime(), spawnDelay));
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPillarSpeed() {
|
||||||
|
return homingData.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPillarSpeed(float speed) {
|
||||||
|
homingData.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHoming() {
|
||||||
|
return homingData.homing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHoming(boolean homing) {
|
||||||
|
homingData.homing = homing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHomingStrength() {
|
||||||
|
return homingData.homingStrength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHomingStrength(float strength) {
|
||||||
|
homingData.homingStrength = strength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHomingRange() {
|
||||||
|
return homingData.homingRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHomingRange(float range) {
|
||||||
|
homingData.homingRange = range;
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-6
@@ -1,6 +1,6 @@
|
|||||||
package kamkeel.npcs.controllers.data.energycharge;
|
package kamkeel.npcs.controllers.data.energycharge;
|
||||||
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -18,13 +18,13 @@ public class EnergyChargePreviewManager {
|
|||||||
|
|
||||||
public static EnergyChargePreviewManager ClientInstance;
|
public static EnergyChargePreviewManager ClientInstance;
|
||||||
|
|
||||||
private final ConcurrentHashMap<String, EntityEnergyProjectile> previews = new ConcurrentHashMap<String, EntityEnergyProjectile>();
|
private final ConcurrentHashMap<String, EntityEnergyAbility> previews = new ConcurrentHashMap<String, EntityEnergyAbility>();
|
||||||
|
|
||||||
public static void initClient() {
|
public static void initClient() {
|
||||||
ClientInstance = new EnergyChargePreviewManager();
|
ClientInstance = new EnergyChargePreviewManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPreview(String instanceId, EntityEnergyProjectile entity) {
|
public void addPreview(String instanceId, EntityEnergyAbility entity) {
|
||||||
if (instanceId == null || entity == null) return;
|
if (instanceId == null || entity == null) return;
|
||||||
previews.put(instanceId, entity);
|
previews.put(instanceId, entity);
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ public class EnergyChargePreviewManager {
|
|||||||
previews.remove(instanceId);
|
previews.remove(instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<EntityEnergyProjectile> getPreviews() {
|
public Collection<EntityEnergyAbility> getPreviews() {
|
||||||
return previews.values();
|
return previews.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,9 +55,9 @@ public class EnergyChargePreviewManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<EntityEnergyProjectile> iterator = previews.values().iterator();
|
Iterator<EntityEnergyAbility> iterator = previews.values().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
EntityEnergyProjectile entity = iterator.next();
|
EntityEnergyAbility entity = iterator.next();
|
||||||
if (entity == null || entity.isDead || entity.worldObj != world) {
|
if (entity == null || entity.isDead || entity.worldObj != world) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -0,0 +1,442 @@
|
|||||||
|
package kamkeel.npcs.entity;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.energy.*;
|
||||||
|
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pillar zone entity.
|
||||||
|
*
|
||||||
|
* Lifecycle:
|
||||||
|
* 1. Charging — charge visual grows in radius at ground level during windup.
|
||||||
|
* 2. spawnDelay — entity is alive, not growing, no damage.
|
||||||
|
* 3. Active — pillarHeight grows linearly at heightGrowSpeed; damage checks begin.
|
||||||
|
*
|
||||||
|
* Radius snaps to targetRadius immediately when charging ends — no interpolation.
|
||||||
|
* Height grows linearly with no easing.
|
||||||
|
*
|
||||||
|
* FROM_ABOVE: posY = top anchor. Hitbox: posY - height to posY.
|
||||||
|
* FROM_GROUND: posY = ground anchor. Hitbox: posY to posY + height.
|
||||||
|
*
|
||||||
|
* ANCHORED modes:
|
||||||
|
* - followTarget: pillar moves directly toward target each tick (requires homing=true).
|
||||||
|
* - trackTarget: spawn position predicted once from target velocity at spawn time.
|
||||||
|
*/
|
||||||
|
public class EntityAbilityPillar extends EntityEnergyZone {
|
||||||
|
|
||||||
|
public static final float MIN_HEIGHT = 0.05f;
|
||||||
|
public static final float MIN_RADIUS = 0.01f;
|
||||||
|
private static final int DW_PILLAR_RADIUS = 21;
|
||||||
|
private static final int DW_PILLAR_HEIGHT = 22;
|
||||||
|
|
||||||
|
// ==================== ENUMS ====================
|
||||||
|
|
||||||
|
public enum PillarMode { ANCHORED, MOVING }
|
||||||
|
|
||||||
|
public enum PillarOrigin { FROM_GROUND, FROM_ABOVE }
|
||||||
|
|
||||||
|
public enum PillarShape {
|
||||||
|
CIRCLE, SQUARE;
|
||||||
|
|
||||||
|
public TelegraphType getTelegraphType() {
|
||||||
|
return this == CIRCLE ? TelegraphType.CIRCLE : TelegraphType.SQUARE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum OffsetAxis { X, Z }
|
||||||
|
|
||||||
|
// ==================== CONFIG ====================
|
||||||
|
|
||||||
|
private EnergyPillarData pillarData = new EnergyPillarData();
|
||||||
|
|
||||||
|
// ==================== DIMENSIONS ====================
|
||||||
|
|
||||||
|
private float pillarRadius = 0.01f;
|
||||||
|
private float pillarHeight = MIN_HEIGHT;
|
||||||
|
|
||||||
|
// Height interpolation only — radius snaps immediately
|
||||||
|
private float renderPillarHeight = MIN_HEIGHT;
|
||||||
|
private float prevRenderPillarHeight = MIN_HEIGHT;
|
||||||
|
|
||||||
|
// ==================== HOMING ====================
|
||||||
|
|
||||||
|
protected EnergyHomingData homingData = new EnergyHomingData();
|
||||||
|
|
||||||
|
// ==================== ANCHORED MODES ====================
|
||||||
|
|
||||||
|
/** If true, pillar follows target directly each tick (ANCHORED + homing only). */
|
||||||
|
private boolean followTarget = false;
|
||||||
|
|
||||||
|
// ==================== RUNTIME STATE ====================
|
||||||
|
|
||||||
|
private boolean growing = false;
|
||||||
|
private int spawnDelayTick = 0;
|
||||||
|
|
||||||
|
// ==================== CONSTRUCTORS ====================
|
||||||
|
|
||||||
|
public EntityAbilityPillar(World world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityAbilityPillar(World world, EntityLivingBase owner,
|
||||||
|
double x, double y, double z,
|
||||||
|
EnergyPillarData pillarData, EnergyDisplayData display,
|
||||||
|
EnergyCombatData combat, EnergyHomingData homing,
|
||||||
|
EnergyLightningData lightning, EnergyLifespanData lifespan) {
|
||||||
|
super(world);
|
||||||
|
this.ownerEntityId = owner != null ? owner.getEntityId() : -1;
|
||||||
|
this.pillarData = pillarData != null ? pillarData.copy() : new EnergyPillarData();
|
||||||
|
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||||
|
this.combatData = combat != null ? combat.copy() : new EnergyCombatData();
|
||||||
|
this.homingData = homing != null ? homing.copy() : new EnergyHomingData();
|
||||||
|
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||||
|
this.lifespanData = lifespan != null ? lifespan.copy() : new EnergyLifespanData();
|
||||||
|
|
||||||
|
if (this.pillarData.origin == PillarOrigin.FROM_ABOVE) {
|
||||||
|
this.setPosition(x, y + this.pillarData.targetHeight, z);
|
||||||
|
} else {
|
||||||
|
snapToGround(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
setPillarRadiusInternal(0.01f);
|
||||||
|
setPillarHeightInternal(MIN_HEIGHT);
|
||||||
|
syncHitbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ENTITY INIT ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void entityInit() {
|
||||||
|
super.entityInit();
|
||||||
|
this.dataWatcher.addObject(DW_PILLAR_RADIUS, 0.01f);
|
||||||
|
this.dataWatcher.addObject(DW_PILLAR_HEIGHT, MIN_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== INTERNAL SETTERS ====================
|
||||||
|
|
||||||
|
private void setPillarRadiusInternal(float value) {
|
||||||
|
this.pillarRadius = value;
|
||||||
|
if (!previewMode && worldObj != null && !worldObj.isRemote) {
|
||||||
|
this.dataWatcher.updateObject(DW_PILLAR_RADIUS, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPillarHeightInternal(float value) {
|
||||||
|
this.pillarHeight = value;
|
||||||
|
if (!previewMode && worldObj != null && !worldObj.isRemote) {
|
||||||
|
this.dataWatcher.updateObject(DW_PILLAR_HEIGHT, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== SETUP ====================
|
||||||
|
|
||||||
|
public void setTarget(EntityLivingBase target) {
|
||||||
|
this.targetEntityId = target != null ? target.getEntityId() : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFollowTarget(boolean follow) {
|
||||||
|
this.followTarget = follow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInitialMotion(double mx, double mz) {
|
||||||
|
this.motionX = mx;
|
||||||
|
this.motionZ = mz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setupPreview(EntityLivingBase owner, EnergyPillarData pillarData,
|
||||||
|
EnergyDisplayData display, EnergyLightningData lightning,
|
||||||
|
int chargeDuration) {
|
||||||
|
setupPreview(owner);
|
||||||
|
this.pillarData = pillarData != null ? pillarData.copy() : new EnergyPillarData();
|
||||||
|
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||||
|
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||||
|
setupCharging(chargeDuration);
|
||||||
|
setPillarRadiusInternal(0.01f);
|
||||||
|
setPillarHeightInternal(MIN_HEIGHT);
|
||||||
|
this.renderPillarHeight = MIN_HEIGHT;
|
||||||
|
this.prevRenderPillarHeight = MIN_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startGrowing() {
|
||||||
|
setCharging(false);
|
||||||
|
this.spawnDelayTick = 0;
|
||||||
|
this.growing = pillarData.spawnDelay <= 0;
|
||||||
|
// Radius snaps immediately to target — no interpolation
|
||||||
|
setPillarRadiusInternal(pillarData.targetRadius);
|
||||||
|
setPillarHeightInternal(MIN_HEIGHT);
|
||||||
|
this.renderPillarHeight = MIN_HEIGHT;
|
||||||
|
this.prevRenderPillarHeight = MIN_HEIGHT;
|
||||||
|
syncHitbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== CHARGING ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateCharging() {
|
||||||
|
chargeTick++;
|
||||||
|
|
||||||
|
// Follow entity position during charging preview (e.g. charge visual follows target)
|
||||||
|
if (pillarData.mode == PillarMode.ANCHORED && targetEntityId != -1 && worldObj != null) {
|
||||||
|
Entity target = getTargetEntity();
|
||||||
|
if (target instanceof EntityLivingBase && !target.isDead) {
|
||||||
|
snapToGround(target.posX, target.posY, target.posZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Radius grows during charging for the visual disc effect
|
||||||
|
float progress = getChargeProgress();
|
||||||
|
setPillarRadiusInternal(pillarData.targetRadius * progress);
|
||||||
|
setPillarHeightInternal(MIN_HEIGHT);
|
||||||
|
syncHitbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ZONE UPDATE ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateZone() {
|
||||||
|
prevRenderPillarHeight = renderPillarHeight;
|
||||||
|
|
||||||
|
if (worldObj.isRemote) {
|
||||||
|
float dwRadius = this.dataWatcher.getWatchableObjectFloat(DW_PILLAR_RADIUS);
|
||||||
|
float dwHeight = this.dataWatcher.getWatchableObjectFloat(DW_PILLAR_HEIGHT);
|
||||||
|
// Radius: snap directly, no interpolation
|
||||||
|
this.pillarRadius = dwRadius;
|
||||||
|
// Height: linear tracking, no easing
|
||||||
|
this.pillarHeight = dwHeight;
|
||||||
|
renderPillarHeight = pillarHeight;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// spawnDelay: no growth, no damage
|
||||||
|
if (!growing) {
|
||||||
|
spawnDelayTick++;
|
||||||
|
if (spawnDelayTick >= pillarData.spawnDelay) {
|
||||||
|
growing = true;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linear height growth — no easing, exact speed per tick
|
||||||
|
if (pillarHeight < pillarData.targetHeight) {
|
||||||
|
setPillarHeightInternal(Math.min(pillarData.targetHeight, pillarHeight + pillarData.heightGrowSpeed));
|
||||||
|
}
|
||||||
|
// Radius stays at targetRadius (set in startGrowing)
|
||||||
|
|
||||||
|
syncHitbox();
|
||||||
|
|
||||||
|
if (pillarData.mode == PillarMode.MOVING) {
|
||||||
|
updateMovement();
|
||||||
|
} else if (pillarData.mode == PillarMode.ANCHORED && followTarget) {
|
||||||
|
updateFollowTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
// No damage during spawnDelay — only when growing
|
||||||
|
if (pillarHeight > MIN_HEIGHT) {
|
||||||
|
checkEntityCollision();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== MOVEMENT ====================
|
||||||
|
|
||||||
|
private void updateMovement() {
|
||||||
|
if (!homingData.isHoming()) {
|
||||||
|
this.posX += motionX;
|
||||||
|
this.posZ += motionZ;
|
||||||
|
repositionY();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity target = getTargetEntity();
|
||||||
|
if (target == null || !target.isEntityAlive()) {
|
||||||
|
this.posX += motionX;
|
||||||
|
this.posZ += motionZ;
|
||||||
|
repositionY();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double dx = target.posX - posX;
|
||||||
|
double dz = target.posZ - posZ;
|
||||||
|
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||||
|
|
||||||
|
if (dist > 0 && dist <= homingData.getHomingRange()) {
|
||||||
|
float strength = homingData.getHomingStrength();
|
||||||
|
double desiredVX = (dx / dist) * homingData.getSpeed();
|
||||||
|
double desiredVZ = (dz / dist) * homingData.getSpeed();
|
||||||
|
motionX += (desiredVX - motionX) * strength;
|
||||||
|
motionZ += (desiredVZ - motionZ) * strength;
|
||||||
|
|
||||||
|
double vLen = Math.sqrt(motionX * motionX + motionZ * motionZ);
|
||||||
|
if (vLen > 0) {
|
||||||
|
motionX = (motionX / vLen) * homingData.getSpeed();
|
||||||
|
motionZ = (motionZ / vLen) * homingData.getSpeed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.posX += motionX;
|
||||||
|
this.posZ += motionZ;
|
||||||
|
repositionY();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ANCHORED followTarget: moves directly toward target each tick.
|
||||||
|
*/
|
||||||
|
private void updateFollowTarget() {
|
||||||
|
Entity target = getTargetEntity();
|
||||||
|
if (target == null || !target.isEntityAlive()) return;
|
||||||
|
|
||||||
|
double dx = target.posX - posX;
|
||||||
|
double dz = target.posZ - posZ;
|
||||||
|
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||||
|
|
||||||
|
if (dist > 0.1) {
|
||||||
|
float speed = homingData.getSpeed();
|
||||||
|
double step = Math.min(dist, speed);
|
||||||
|
this.posX += (dx / dist) * step;
|
||||||
|
this.posZ += (dz / dist) * step;
|
||||||
|
repositionY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void repositionY() {
|
||||||
|
if (pillarData.origin == PillarOrigin.FROM_ABOVE) {
|
||||||
|
double groundY = kamkeel.npcs.controllers.data.ability.Ability.findGroundLevel(worldObj, posX, posY, posZ);
|
||||||
|
this.setPosition(posX, groundY + pillarData.targetHeight, posZ);
|
||||||
|
} else {
|
||||||
|
snapToGround(posX, posY, posZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== COLLISION ====================
|
||||||
|
|
||||||
|
private void checkEntityCollision() {
|
||||||
|
AxisAlignedBB broadBox = buildHitBox();
|
||||||
|
if (broadBox == null) return;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, broadBox);
|
||||||
|
|
||||||
|
for (EntityLivingBase entity : entities) {
|
||||||
|
if (shouldIgnoreEntity(entity)) continue;
|
||||||
|
if (!canHitEntityNow(entity)) continue;
|
||||||
|
if (!isInPillar(entity)) continue;
|
||||||
|
|
||||||
|
boolean hit = applyDamage(entity, getDamage());
|
||||||
|
if (hit) {
|
||||||
|
applyEffects(entity);
|
||||||
|
recordEntityHit(entity);
|
||||||
|
if (shouldTerminateAfterHit()) {
|
||||||
|
this.setDead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AxisAlignedBB buildHitBox() {
|
||||||
|
float minY, maxY;
|
||||||
|
if (pillarData.origin == PillarOrigin.FROM_ABOVE) {
|
||||||
|
maxY = (float) posY;
|
||||||
|
minY = (float) posY - pillarHeight;
|
||||||
|
} else {
|
||||||
|
minY = (float) posY;
|
||||||
|
maxY = (float) posY + pillarHeight;
|
||||||
|
}
|
||||||
|
return AxisAlignedBB.getBoundingBox(
|
||||||
|
posX - pillarRadius, minY, posZ - pillarRadius,
|
||||||
|
posX + pillarRadius, maxY, posZ + pillarRadius);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInPillar(EntityLivingBase entity) {
|
||||||
|
double dx = entity.posX - posX;
|
||||||
|
double dz = entity.posZ - posZ;
|
||||||
|
switch (pillarData.shape) {
|
||||||
|
case SQUARE: return Math.abs(dx) <= pillarRadius && Math.abs(dz) <= pillarRadius;
|
||||||
|
case CIRCLE: default: return Math.sqrt(dx * dx + dz * dz) <= pillarRadius;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncHitbox() {
|
||||||
|
float w = Math.max(0.1f, pillarRadius * 2.0f);
|
||||||
|
float h = Math.max(0.1f, pillarHeight);
|
||||||
|
this.setSize(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public boolean isInRangeToRenderDist(double distance) {
|
||||||
|
double extent = Math.max(pillarRadius, pillarHeight) * 2.0D;
|
||||||
|
double range = Math.max(128.0D, extent * 4.0D + 64.0D);
|
||||||
|
return distance < range * range;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== RENDERER GETTERS ====================
|
||||||
|
|
||||||
|
public float getPillarRadius() { return pillarRadius; }
|
||||||
|
public float getPillarHeight() { return pillarHeight; }
|
||||||
|
public float getInterpolatedPillarHeight(float partialTicks) {
|
||||||
|
return prevRenderPillarHeight + (renderPillarHeight - prevRenderPillarHeight) * partialTicks;
|
||||||
|
}
|
||||||
|
public PillarMode getPillarMode() { return pillarData.mode; }
|
||||||
|
public PillarOrigin getPillarOrigin() { return pillarData.origin; }
|
||||||
|
public PillarShape getPillarShape() { return pillarData.shape; }
|
||||||
|
public boolean isGrowing() { return growing; }
|
||||||
|
public EnergyPillarData getPillarData() { return pillarData; }
|
||||||
|
|
||||||
|
// ==================== SETTERS ====================
|
||||||
|
|
||||||
|
public void setPillarData(EnergyPillarData data) { this.pillarData = data != null ? data.copy() : new EnergyPillarData(); }
|
||||||
|
public void setHomingData(EnergyHomingData homing) { this.homingData = homing != null ? homing.copy() : new EnergyHomingData(); }
|
||||||
|
|
||||||
|
// ==================== NBT ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeZoneNBT(NBTTagCompound nbt) {
|
||||||
|
pillarData.writeNBT(nbt);
|
||||||
|
homingData.writeNBT(nbt);
|
||||||
|
nbt.setFloat("PillarRadius", pillarRadius);
|
||||||
|
nbt.setFloat("PillarHeight", pillarHeight);
|
||||||
|
nbt.setInteger("SpawnDelayTick", spawnDelayTick);
|
||||||
|
nbt.setBoolean("Growing", growing);
|
||||||
|
nbt.setBoolean("FollowTarget", followTarget);
|
||||||
|
nbt.setInteger("TargetEntityId", targetEntityId);
|
||||||
|
nbt.setDouble("MotionX", motionX);
|
||||||
|
nbt.setDouble("MotionZ", motionZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readZoneNBT(NBTTagCompound nbt) {
|
||||||
|
pillarData.readNBT(nbt);
|
||||||
|
homingData.readNBT(nbt);
|
||||||
|
|
||||||
|
float radius = Math.max(0.01f, nbt.getFloat("PillarRadius"));
|
||||||
|
float height = Math.max(MIN_HEIGHT, nbt.getFloat("PillarHeight"));
|
||||||
|
|
||||||
|
this.pillarRadius = radius;
|
||||||
|
this.pillarHeight = height;
|
||||||
|
|
||||||
|
if (this.dataWatcher != null) {
|
||||||
|
this.dataWatcher.updateObject(DW_PILLAR_RADIUS, radius);
|
||||||
|
this.dataWatcher.updateObject(DW_PILLAR_HEIGHT, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderPillarHeight = height;
|
||||||
|
this.prevRenderPillarHeight = height;
|
||||||
|
|
||||||
|
this.spawnDelayTick = nbt.getInteger("SpawnDelayTick");
|
||||||
|
this.growing = nbt.getBoolean("Growing");
|
||||||
|
this.followTarget = nbt.hasKey("FollowTarget") && nbt.getBoolean("FollowTarget");
|
||||||
|
this.targetEntityId = nbt.hasKey("TargetEntityId") ? nbt.getInteger("TargetEntityId") : -1;
|
||||||
|
this.motionX = nbt.getDouble("MotionX");
|
||||||
|
this.motionZ = nbt.getDouble("MotionZ");
|
||||||
|
|
||||||
|
syncHitbox();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,550 @@
|
|||||||
|
package kamkeel.npcs.entity;
|
||||||
|
|
||||||
|
import kamkeel.npcs.controllers.AbilityController;
|
||||||
|
import kamkeel.npcs.controllers.EnergyController;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.effect.AbilityPotionEffect;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyCombatData;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.enums.HitType;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.enums.TargetFilter;
|
||||||
|
import kamkeel.npcs.controllers.data.ability.util.AbilityTargetHelper;
|
||||||
|
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.util.DamageSource;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import noppes.npcs.NpcDamageSource;
|
||||||
|
import noppes.npcs.entity.EntityNPCInterface;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for all energy zone entities.
|
||||||
|
* Extends EntityEnergyAbility for shared visual/owner/charging/magic state.
|
||||||
|
*
|
||||||
|
* Provides:
|
||||||
|
* - Lifetime management via deathWorldTime (robust to chunk unload)
|
||||||
|
* - Combat pipeline: sourceAbility -> customDamageData -> native fallback
|
||||||
|
* - Hit type tracking: SINGLE, MULTI, PIERCE
|
||||||
|
* - Effects application
|
||||||
|
* - affectsCaster flag
|
||||||
|
* - Charging infrastructure (hook only — subclass defines growth behavior)
|
||||||
|
* - Size interpolation: radius/height with target/render/prev layers
|
||||||
|
*
|
||||||
|
* Subclasses must implement:
|
||||||
|
* - updateZone() — tick logic (damage, movement, etc.)
|
||||||
|
* - writeZoneNBT() — type-specific NBT write
|
||||||
|
* - readZoneNBT() — type-specific NBT read
|
||||||
|
*
|
||||||
|
* Subclasses may override:
|
||||||
|
* - updateCharging() — charging growth behavior (default: increments chargeTick only)
|
||||||
|
* - shouldIgnoreEntity() — damage/collision filter
|
||||||
|
*/
|
||||||
|
public abstract class EntityEnergyZone extends EntityEnergyAbility {
|
||||||
|
|
||||||
|
// ==================== SAFETY CONSTANTS ====================
|
||||||
|
|
||||||
|
public static final float MAX_ZONE_RADIUS = 64.0f;
|
||||||
|
public static final float MAX_ZONE_HEIGHT = 64.0f;
|
||||||
|
protected static final double GROUND_OFFSET = 0.05;
|
||||||
|
|
||||||
|
// ==================== LIFESPAN ====================
|
||||||
|
|
||||||
|
protected EnergyLifespanData lifespanData = new EnergyLifespanData();
|
||||||
|
protected long deathWorldTime = -1;
|
||||||
|
|
||||||
|
// ==================== COMBAT ====================
|
||||||
|
|
||||||
|
protected EnergyCombatData combatData = new EnergyCombatData();
|
||||||
|
protected List<AbilityPotionEffect> effects = new ArrayList<>();
|
||||||
|
protected boolean affectsCaster = false;
|
||||||
|
|
||||||
|
// ==================== HIT TRACKING ====================
|
||||||
|
|
||||||
|
/** Entities hit exactly once — PIERCE: never again; SINGLE: zone dies on first hit. */
|
||||||
|
protected final Set<Integer> hitOnceEntities = new HashSet<>();
|
||||||
|
|
||||||
|
/** Last tick each entity was hit, used for MULTI delay. */
|
||||||
|
protected final Map<Integer, Integer> lastHitTickByEntity = new HashMap<>();
|
||||||
|
|
||||||
|
protected int hitCount = 0;
|
||||||
|
|
||||||
|
protected int targetEntityId = -1;
|
||||||
|
|
||||||
|
// ==================== SIZE — LOGICAL ====================
|
||||||
|
|
||||||
|
/** Current radius used for collision and damage checks. */
|
||||||
|
protected float radius = 1.0f;
|
||||||
|
|
||||||
|
/** Current height used for collision and damage checks. */
|
||||||
|
protected float height = 1.0f;
|
||||||
|
|
||||||
|
// ==================== SIZE — INTERPOLATION ====================
|
||||||
|
|
||||||
|
/** Target radius the zone is growing or shrinking toward. */
|
||||||
|
protected float targetRadius = 1.0f;
|
||||||
|
|
||||||
|
/** Target height the zone is growing or shrinking toward. */
|
||||||
|
protected float targetHeight = 1.0f;
|
||||||
|
|
||||||
|
/** Smoothed radius sent to the renderer each frame. */
|
||||||
|
protected float renderRadius = 1.0f;
|
||||||
|
|
||||||
|
/** Smoothed height sent to the renderer each frame. */
|
||||||
|
protected float renderHeight = 1.0f;
|
||||||
|
|
||||||
|
/** Previous-tick render radius for partialTicks interpolation. */
|
||||||
|
protected float prevRenderRadius = 1.0f;
|
||||||
|
|
||||||
|
/** Previous-tick render height for partialTicks interpolation. */
|
||||||
|
protected float prevRenderHeight = 1.0f;
|
||||||
|
|
||||||
|
// ==================== CONSTRUCTOR ====================
|
||||||
|
|
||||||
|
public EntityEnergyZone(World world) {
|
||||||
|
super(world);
|
||||||
|
this.setSize(0.1f, 0.1f);
|
||||||
|
this.noClip = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ENTITY LIFECYCLE ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdate() {
|
||||||
|
this.prevPosX = this.posX;
|
||||||
|
this.prevPosY = this.posY;
|
||||||
|
this.prevPosZ = this.posZ;
|
||||||
|
this.prevRenderRadius = this.renderRadius;
|
||||||
|
this.prevRenderHeight = this.renderHeight;
|
||||||
|
|
||||||
|
if (!previewMode) {
|
||||||
|
super.onUpdate();
|
||||||
|
} else {
|
||||||
|
this.ticksExisted++;
|
||||||
|
|
||||||
|
if (isCharging() && chargeDuration > 0 && chargeTick > chargeDuration + PREVIEW_CHARGE_GRACE) {
|
||||||
|
this.setDead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ticksExisted > HARD_LIFETIME_CAP) {
|
||||||
|
this.setDead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// During charging, snap render values so they follow subclass growth without lag.
|
||||||
|
// After charging, lerp smoothly toward current logical size.
|
||||||
|
if (isCharging()) {
|
||||||
|
this.renderRadius = this.radius;
|
||||||
|
this.renderHeight = this.height;
|
||||||
|
updateCharging();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.renderRadius += (this.radius - this.renderRadius) * 0.15f;
|
||||||
|
this.renderHeight += (this.height - this.renderHeight) * 0.15f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!previewMode) {
|
||||||
|
if (deathWorldTime < 0 && worldObj != null) {
|
||||||
|
deathWorldTime = worldObj.getTotalWorldTime() + lifespanData.getMaxLifetime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deathWorldTime > 0 && worldObj.getTotalWorldTime() >= deathWorldTime) {
|
||||||
|
this.setDead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ownerEntityId >= 0 && ticksExisted > 5) {
|
||||||
|
Entity owner = worldObj.getEntityByID(ownerEntityId);
|
||||||
|
if (owner != null) {
|
||||||
|
if (owner.isDead) {
|
||||||
|
this.setDead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (owner instanceof EntityNPCInterface && ((EntityNPCInterface) owner).isKilled()) {
|
||||||
|
this.setDead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateZone();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== HOOKS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass tick logic — damage, movement, custom behavior.
|
||||||
|
* Called every tick after charging ends and lifetime is validated.
|
||||||
|
*/
|
||||||
|
protected abstract void updateZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charging growth hook. Called every tick while isCharging() is true.
|
||||||
|
* Default implementation increments chargeTick only.
|
||||||
|
* Override to define what dimensions grow during the windup phase.
|
||||||
|
*/
|
||||||
|
protected void updateCharging() {
|
||||||
|
chargeTick++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== CHARGING SETUP ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize charging state. Subclasses call this and then set their own target values.
|
||||||
|
* Does not zero radius or height — subclass decides starting values.
|
||||||
|
*/
|
||||||
|
public void setupCharging(int chargeDuration) {
|
||||||
|
setCharging(true);
|
||||||
|
this.chargeDuration = chargeDuration;
|
||||||
|
this.chargeTick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== DAMAGE PIPELINE ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply damage to a target through the full energy pipeline:
|
||||||
|
* sourceAbility extender -> customDamageData -> native damage source.
|
||||||
|
*
|
||||||
|
* @param target entity to damage
|
||||||
|
* @param damage raw damage amount
|
||||||
|
* @return true if damage was applied
|
||||||
|
*/
|
||||||
|
protected boolean applyDamage(EntityLivingBase target, float damage) {
|
||||||
|
if (previewMode) return false;
|
||||||
|
if (target == null) return false;
|
||||||
|
if (damage <= 0 && sourceAbility == null && customDamageData == null) return false;
|
||||||
|
|
||||||
|
Entity owner = getOwnerEntity();
|
||||||
|
int previousHurtResistantTime = Ability.clearHurtResistanceIfNeeded(target, ignoreIFrames);
|
||||||
|
try {
|
||||||
|
boolean handled = false;
|
||||||
|
|
||||||
|
if (sourceAbility != null && owner instanceof EntityLivingBase) {
|
||||||
|
double dx = target.posX - posX;
|
||||||
|
double dz = target.posZ - posZ;
|
||||||
|
handled = AbilityController.Instance.fireOnAbilityDamage(
|
||||||
|
sourceAbility, (EntityLivingBase) owner, target,
|
||||||
|
damage, 0.0f, 0.0f, dx, dz, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handled && customDamageData != null && owner instanceof EntityLivingBase) {
|
||||||
|
double dx = target.posX - posX;
|
||||||
|
double dz = target.posZ - posZ;
|
||||||
|
handled = EnergyController.Instance.fireOnEnergyDamage(
|
||||||
|
this, (EntityLivingBase) owner, target,
|
||||||
|
damage, 0.0f, 0.0f, dx, dz, 1.0f, customDamageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handled) {
|
||||||
|
float finalDamage = damage;
|
||||||
|
|
||||||
|
if (magicData != null && !magicData.isEmpty() && owner instanceof EntityLivingBase) {
|
||||||
|
finalDamage = AttributeAttackUtil.calculateAbilityDamage(
|
||||||
|
(EntityLivingBase) owner, target, damage, magicData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (owner instanceof EntityNPCInterface) {
|
||||||
|
return target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), finalDamage);
|
||||||
|
} else if (owner instanceof EntityPlayer) {
|
||||||
|
return target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), finalDamage);
|
||||||
|
} else if (owner instanceof EntityLivingBase) {
|
||||||
|
return target.attackEntityFrom(DamageSource.causeMobDamage((EntityLivingBase) owner), finalDamage);
|
||||||
|
} else {
|
||||||
|
return target.attackEntityFrom(new NpcDamageSource("npc_ability", null), finalDamage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
Ability.restoreHurtResistanceIfNeeded(target, ignoreIFrames, previousHurtResistantTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply potion effects to a target.
|
||||||
|
*/
|
||||||
|
protected void applyEffects(EntityLivingBase target) {
|
||||||
|
if (target == null || effects.isEmpty()) return;
|
||||||
|
for (AbilityPotionEffect effect : effects) {
|
||||||
|
effect.apply(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== HIT TYPE LOGIC ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this zone can hit the given entity right now, based on hit type.
|
||||||
|
*/
|
||||||
|
protected boolean canHitEntityNow(EntityLivingBase entity) {
|
||||||
|
if (entity == null) return false;
|
||||||
|
int entityId = entity.getEntityId();
|
||||||
|
switch (combatData.hitType) {
|
||||||
|
case SINGLE:
|
||||||
|
case PIERCE:
|
||||||
|
return !hitOnceEntities.contains(entityId);
|
||||||
|
case MULTI:
|
||||||
|
Integer lastTick = lastHitTickByEntity.get(entityId);
|
||||||
|
if (lastTick == null) return true;
|
||||||
|
return (ticksExisted - lastTick) >= Math.max(1, combatData.multiHitDelayTicks);
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record that an entity was hit this tick.
|
||||||
|
*/
|
||||||
|
protected void recordEntityHit(EntityLivingBase entity) {
|
||||||
|
if (entity == null) return;
|
||||||
|
int entityId = entity.getEntityId();
|
||||||
|
hitOnceEntities.add(entityId);
|
||||||
|
lastHitTickByEntity.put(entityId, ticksExisted);
|
||||||
|
hitCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the zone should die after a successful hit (SINGLE only).
|
||||||
|
*/
|
||||||
|
protected boolean shouldTerminateAfterHit() {
|
||||||
|
return combatData.hitType == HitType.SINGLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ENTITY FILTER ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether an entity should be ignored for damage and collision.
|
||||||
|
* Subclasses may override to add type-specific filters.
|
||||||
|
*/
|
||||||
|
protected boolean shouldIgnoreEntity(EntityLivingBase entity) {
|
||||||
|
if (entity == null) return true;
|
||||||
|
Entity owner = getOwnerEntity();
|
||||||
|
if (entity == owner && !affectsCaster) return true;
|
||||||
|
if (owner instanceof EntityLivingBase) {
|
||||||
|
return !AbilityTargetHelper.shouldAffect((EntityLivingBase) owner, entity, TargetFilter.ENEMIES, affectsCaster);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTargetEntityId() {
|
||||||
|
return targetEntityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetEntityId(int id) {
|
||||||
|
this.targetEntityId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity getTargetEntity() {
|
||||||
|
if (targetEntityId == -1) return null;
|
||||||
|
return worldObj.getEntityByID(targetEntityId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetEntity(Entity entity) {
|
||||||
|
if (entity == null) return;
|
||||||
|
this.targetEntityId = entity.getEntityId();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== SIZE INTERPOLATION ====================
|
||||||
|
|
||||||
|
public float getInterpolatedRadius(float partialTicks) {
|
||||||
|
return prevRenderRadius + (renderRadius - prevRenderRadius) * partialTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getInterpolatedHeight(float partialTicks) {
|
||||||
|
return prevRenderHeight + (renderHeight - prevRenderHeight) * partialTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Snap all radius interpolation layers to a single value.
|
||||||
|
* Use on init or after teleport to avoid pop artifacts.
|
||||||
|
*/
|
||||||
|
protected void setVisualRadius(float value) {
|
||||||
|
this.radius = value;
|
||||||
|
this.renderRadius = value;
|
||||||
|
this.prevRenderRadius = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Snap all height interpolation layers to a single value.
|
||||||
|
*/
|
||||||
|
protected void setVisualHeight(float value) {
|
||||||
|
this.height = value;
|
||||||
|
this.renderHeight = value;
|
||||||
|
this.prevRenderHeight = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== GROUND SNAP ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Position this zone at ground level beneath x/y/z.
|
||||||
|
*/
|
||||||
|
protected void snapToGround(double x, double y, double z) {
|
||||||
|
double groundY = Ability.findGroundLevel(worldObj, x, y, z) + GROUND_OFFSET;
|
||||||
|
this.setPosition(x, groundY, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== PREVIEW ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up this zone for GUI preview rendering.
|
||||||
|
*/
|
||||||
|
public void setupPreview(EntityLivingBase owner) {
|
||||||
|
this.previewMode = true;
|
||||||
|
this.previewOwner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== GETTERS & SETTERS ====================
|
||||||
|
|
||||||
|
public float getDamage() { return combatData.getDamage(); }
|
||||||
|
public void setDamage(float damage) { combatData.setDamage(damage); }
|
||||||
|
|
||||||
|
public float getKnockback() { return combatData.knockback; }
|
||||||
|
public void setKnockback(float knockback) { combatData.setKnockback(knockback); }
|
||||||
|
|
||||||
|
public int getHitType() { return combatData.hitType.ordinal(); }
|
||||||
|
public void setHitType(int hitType) { combatData.hitType = HitType.fromOrdinal(hitType); }
|
||||||
|
|
||||||
|
public int getMultiHitDelayTicks() { return combatData.multiHitDelayTicks; }
|
||||||
|
public void setMultiHitDelayTicks(int ticks) { combatData.multiHitDelayTicks = Math.max(1, ticks); }
|
||||||
|
|
||||||
|
public boolean isAffectsCaster() { return affectsCaster; }
|
||||||
|
public void setAffectsCaster(boolean affectsCaster) { this.affectsCaster = affectsCaster; }
|
||||||
|
|
||||||
|
public int getMaxLifetime() { return lifespanData.getMaxLifetime(); }
|
||||||
|
public void setMaxLifetime(int ticks) { lifespanData.setMaxLifetime(ticks); }
|
||||||
|
|
||||||
|
public float getRadius() { return radius; }
|
||||||
|
public void setRadius(float radius) { this.radius = sanitize(radius, 1.0f, MAX_ZONE_RADIUS); }
|
||||||
|
|
||||||
|
public float getZoneHeight() { return height; }
|
||||||
|
public void setZoneHeight(float height) { this.height = sanitize(height, 1.0f, MAX_ZONE_HEIGHT); }
|
||||||
|
|
||||||
|
public float getTargetRadius() { return targetRadius; }
|
||||||
|
public void setTargetRadius(float radius) { this.targetRadius = sanitize(radius, 1.0f, MAX_ZONE_RADIUS); }
|
||||||
|
|
||||||
|
public float getTargetHeight() { return targetHeight; }
|
||||||
|
public void setTargetHeight(float height) { this.targetHeight = sanitize(height, 1.0f, MAX_ZONE_HEIGHT); }
|
||||||
|
|
||||||
|
public void setEffects(List<AbilityPotionEffect> effects) {
|
||||||
|
if (effects == null || effects.isEmpty()) {
|
||||||
|
this.effects = new ArrayList<>();
|
||||||
|
} else {
|
||||||
|
this.effects = new ArrayList<>(effects.size());
|
||||||
|
for (AbilityPotionEffect effect : effects) {
|
||||||
|
this.effects.add(effect.copy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== NBT ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeSpawnNBT(NBTTagCompound nbt) {
|
||||||
|
writeEnergyBaseNBT(nbt);
|
||||||
|
writeZoneBaseNBT(nbt);
|
||||||
|
writeZoneNBT(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readSpawnNBT(NBTTagCompound nbt) {
|
||||||
|
readEnergyBaseNBT(nbt);
|
||||||
|
readZoneBaseNBT(nbt);
|
||||||
|
readZoneNBT(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void writeZoneBaseNBT(NBTTagCompound nbt) {
|
||||||
|
nbt.setDouble("PosX", posX);
|
||||||
|
nbt.setDouble("PosY", posY);
|
||||||
|
nbt.setDouble("PosZ", posZ);
|
||||||
|
|
||||||
|
nbt.setFloat("Radius", radius);
|
||||||
|
nbt.setFloat("Height", height);
|
||||||
|
nbt.setFloat("TargetRadius", targetRadius);
|
||||||
|
nbt.setFloat("TargetHeight", targetHeight);
|
||||||
|
|
||||||
|
lifespanData.writeNBT(nbt);
|
||||||
|
nbt.setLong("DeathWorldTime", deathWorldTime);
|
||||||
|
|
||||||
|
combatData.writeNBT(nbt);
|
||||||
|
nbt.setBoolean("AffectsCaster", affectsCaster);
|
||||||
|
|
||||||
|
nbt.setBoolean("Charging", isCharging());
|
||||||
|
nbt.setInteger("ChargeDuration", chargeDuration);
|
||||||
|
nbt.setInteger("ChargeTick", chargeTick);
|
||||||
|
|
||||||
|
nbt.setInteger("TargetEntityId", targetEntityId);
|
||||||
|
|
||||||
|
NBTTagList effectsList = new NBTTagList();
|
||||||
|
for (AbilityPotionEffect effect : effects) {
|
||||||
|
effectsList.appendTag(effect.writeNBT());
|
||||||
|
}
|
||||||
|
nbt.setTag("Effects", effectsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void readZoneBaseNBT(NBTTagCompound nbt) {
|
||||||
|
if (nbt.hasKey("PosX")) {
|
||||||
|
double px = nbt.getDouble("PosX");
|
||||||
|
double py = nbt.getDouble("PosY");
|
||||||
|
double pz = nbt.getDouble("PosZ");
|
||||||
|
this.setPosition(px, py, pz);
|
||||||
|
this.prevPosX = px; this.prevPosY = py; this.prevPosZ = pz;
|
||||||
|
this.lastTickPosX = px; this.lastTickPosY = py; this.lastTickPosZ = pz;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.radius = sanitize(nbt.getFloat("Radius"), 1.0f, MAX_ZONE_RADIUS);
|
||||||
|
this.height = sanitize(nbt.getFloat("Height"), 1.0f, MAX_ZONE_HEIGHT);
|
||||||
|
this.targetRadius = sanitize(nbt.getFloat("TargetRadius"), 1.0f, MAX_ZONE_RADIUS);
|
||||||
|
this.targetHeight = sanitize(nbt.getFloat("TargetHeight"), 1.0f, MAX_ZONE_HEIGHT);
|
||||||
|
|
||||||
|
this.renderRadius = this.radius;
|
||||||
|
this.prevRenderRadius = this.radius;
|
||||||
|
this.renderHeight = this.height;
|
||||||
|
this.prevRenderHeight = this.height;
|
||||||
|
|
||||||
|
lifespanData.readNBT(nbt);
|
||||||
|
this.deathWorldTime = nbt.hasKey("DeathWorldTime") ? nbt.getLong("DeathWorldTime") : -1;
|
||||||
|
|
||||||
|
combatData.readNBT(nbt);
|
||||||
|
this.affectsCaster = nbt.getBoolean("AffectsCaster");
|
||||||
|
|
||||||
|
boolean isChargingVal = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
|
||||||
|
this.charging = isChargingVal;
|
||||||
|
if (!worldObj.isRemote) {
|
||||||
|
this.dataWatcher.updateObject(DW_CHARGING, (byte) (isChargingVal ? 1 : 0));
|
||||||
|
}
|
||||||
|
this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 0;
|
||||||
|
this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0;
|
||||||
|
this.targetEntityId = nbt.hasKey("TargetEntityId") ? nbt.getInteger("TargetEntityId") : -1;
|
||||||
|
|
||||||
|
this.effects.clear();
|
||||||
|
if (nbt.hasKey("Effects")) {
|
||||||
|
NBTTagList effectsList = nbt.getTagList("Effects", 10);
|
||||||
|
for (int i = 0; i < effectsList.tagCount(); i++) {
|
||||||
|
AbilityPotionEffect effect = AbilityPotionEffect.fromNBT(effectsList.getCompoundTagAt(i));
|
||||||
|
if (effect != null && effect.isValid()) {
|
||||||
|
this.effects.add(effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass-specific NBT write. Called after writeZoneBaseNBT.
|
||||||
|
*/
|
||||||
|
protected abstract void writeZoneNBT(NBTTagCompound nbt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclass-specific NBT read. Called after readZoneBaseNBT.
|
||||||
|
*/
|
||||||
|
protected abstract void readZoneNBT(NBTTagCompound nbt);
|
||||||
|
}
|
||||||
+6
-6
@@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side;
|
|||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||||
import kamkeel.npcs.network.AbstractPacket;
|
import kamkeel.npcs.network.AbstractPacket;
|
||||||
import kamkeel.npcs.network.PacketChannel;
|
import kamkeel.npcs.network.PacketChannel;
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
@@ -68,7 +68,7 @@ public final class EnergyChargeSpawnPacket extends AbstractPacket {
|
|||||||
World world = Minecraft.getMinecraft().theWorld;
|
World world = Minecraft.getMinecraft().theWorld;
|
||||||
if (world == null) return;
|
if (world == null) return;
|
||||||
|
|
||||||
EntityEnergyProjectile preview = createPreviewEntity(className, world);
|
EntityEnergyAbility preview = createPreviewEntity(className, world);
|
||||||
if (preview == null) return;
|
if (preview == null) return;
|
||||||
|
|
||||||
preview.setPreviewMode(true);
|
preview.setPreviewMode(true);
|
||||||
@@ -84,22 +84,22 @@ public final class EnergyChargeSpawnPacket extends AbstractPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
private static EntityEnergyProjectile createPreviewEntity(String className, World world) {
|
private static EntityEnergyAbility createPreviewEntity(String className, World world) {
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = Class.forName(className);
|
Class<?> clazz = Class.forName(className);
|
||||||
if (!EntityEnergyProjectile.class.isAssignableFrom(clazz)) {
|
if (!EntityEnergyAbility.class.isAssignableFrom(clazz)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Constructor<?> constructor = clazz.getConstructor(World.class);
|
Constructor<?> constructor = clazz.getConstructor(World.class);
|
||||||
Object instance = constructor.newInstance(world);
|
Object instance = constructor.newInstance(world);
|
||||||
return (EntityEnergyProjectile) instance;
|
return (EntityEnergyAbility) instance;
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendToTracking(String instanceId, EntityEnergyProjectile previewEntity, Entity trackingEntity) {
|
public static void sendToTracking(String instanceId, EntityEnergyAbility previewEntity, Entity trackingEntity) {
|
||||||
if (previewEntity == null || trackingEntity == null) return;
|
if (previewEntity == null || trackingEntity == null) return;
|
||||||
String className = previewEntity.getClass().getName();
|
String className = previewEntity.getClass().getName();
|
||||||
NBTTagCompound nbt = previewEntity.exportSpawnNBT();
|
NBTTagCompound nbt = previewEntity.exportSpawnNBT();
|
||||||
|
|||||||
@@ -29,17 +29,7 @@ import kamkeel.npcs.controllers.TelegraphController;
|
|||||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||||
import kamkeel.npcs.developer.Developer;
|
import kamkeel.npcs.developer.Developer;
|
||||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
import kamkeel.npcs.entity.*;
|
||||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
|
||||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
|
||||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
|
||||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
|
||||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
|
||||||
import kamkeel.npcs.network.PacketHandler;
|
import kamkeel.npcs.network.PacketHandler;
|
||||||
import kamkeel.npcs.util.BukkitUtil;
|
import kamkeel.npcs.util.BukkitUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -304,6 +294,7 @@ public class CustomNpcs {
|
|||||||
registerNewEntity(EntityEnergyDome.class, "energydome", 64, 3, true);
|
registerNewEntity(EntityEnergyDome.class, "energydome", 64, 3, true);
|
||||||
registerNewEntity(EntityEnergyPanel.class, "energypanel", 64, 3, true);
|
registerNewEntity(EntityEnergyPanel.class, "energypanel", 64, 3, true);
|
||||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
||||||
|
registerNewEntity(EntityAbilityPillar.class, "abilitypillar", 64, 1, true);
|
||||||
|
|
||||||
new RecipeController();
|
new RecipeController();
|
||||||
|
|
||||||
|
|||||||
@@ -7,31 +7,11 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
|||||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||||
import kamkeel.npcs.addon.client.DBCClient;
|
import kamkeel.npcs.addon.client.DBCClient;
|
||||||
import kamkeel.npcs.client.command.CommandCNPCDebugger;
|
import kamkeel.npcs.client.command.CommandCNPCDebugger;
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergyBeam;
|
import kamkeel.npcs.client.renderer.*;
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergyDisc;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergyLaser;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergyOrb;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderSweeper;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderZone;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergyDome;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergyPanel;
|
|
||||||
import kamkeel.npcs.client.renderer.EnergyChargePreviewRenderer;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergyExplosion;
|
|
||||||
import kamkeel.npcs.client.renderer.RenderEnergySlicer;
|
|
||||||
import kamkeel.npcs.client.renderer.TelegraphRenderer;
|
|
||||||
import kamkeel.npcs.client.renderer.lightning.LightningHandler;
|
import kamkeel.npcs.client.renderer.lightning.LightningHandler;
|
||||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
import kamkeel.npcs.entity.*;
|
||||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
|
||||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
|
||||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
|
||||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergyExplosion;
|
|
||||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.model.ModelBiped;
|
import net.minecraft.client.model.ModelBiped;
|
||||||
@@ -294,6 +274,7 @@ public class ClientProxy extends CommonProxy {
|
|||||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyPanel.class, new RenderEnergyPanel());
|
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyPanel.class, new RenderEnergyPanel());
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySlicer.class, new RenderEnergySlicer());
|
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySlicer.class, new RenderEnergySlicer());
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyExplosion.class, new RenderEnergyExplosion());
|
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyExplosion.class, new RenderEnergyExplosion());
|
||||||
|
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityPillar.class, new RenderEnergyPillar());
|
||||||
|
|
||||||
RenderingRegistry.registerEntityRenderingHandler(EntityCustomNpc.class, new RenderCustomNpc());
|
RenderingRegistry.registerEntityRenderingHandler(EntityCustomNpc.class, new RenderCustomNpc());
|
||||||
|
|
||||||
|
|||||||
@@ -288,10 +288,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
|||||||
|
|
||||||
// Set the script context for context-aware hook autocomplete
|
// Set the script context for context-aware hook autocomplete
|
||||||
activeArea.setScriptContext(getScriptContext());
|
activeArea.setScriptContext(getScriptContext());
|
||||||
activeArea.enableCodeHighlighting();
|
|
||||||
|
|
||||||
updateScriptDocumentImports(activeArea, container);
|
updateScriptDocumentImports(activeArea, container);
|
||||||
|
|
||||||
|
activeArea.enableCodeHighlighting();
|
||||||
|
|
||||||
// Setup fullscreen key binding
|
// Setup fullscreen key binding
|
||||||
GuiScriptTextArea.KEYS.FULLSCREEN.setTask(e -> {
|
GuiScriptTextArea.KEYS.FULLSCREEN.setTask(e -> {
|
||||||
if (e.isPress()) {
|
if (e.isPress()) {
|
||||||
@@ -299,7 +299,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
activeArea.enableCodeHighlighting();
|
|
||||||
this.addTextField(activeArea);
|
this.addTextField(activeArea);
|
||||||
|
|
||||||
// ==================== FULLSCREEN BUTTON ====================
|
// ==================== FULLSCREEN BUTTON ====================
|
||||||
@@ -458,7 +457,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
|||||||
this.getTextField(2).setText(this.getTextField(2).getText() + addString);
|
this.getTextField(2).setText(this.getTextField(2).getText() + addString);
|
||||||
previousHookClicked = "";
|
previousHookClicked = "";
|
||||||
|
|
||||||
updateScriptDocumentImports(getActiveScriptArea(), container);
|
GuiScriptTextArea activeArea = getActiveScriptArea();
|
||||||
|
updateScriptDocumentImports(activeArea, container);
|
||||||
|
activeArea.enableCodeHighlighting();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
previousHookClicked = hook;
|
previousHookClicked = hook;
|
||||||
}
|
}
|
||||||
@@ -484,10 +486,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
|||||||
for (String fqn : ctx.getNamespaceFQNs())
|
for (String fqn : ctx.getNamespaceFQNs())
|
||||||
wildcardImports.add(fqn + ".*");
|
wildcardImports.add(fqn + ".*");
|
||||||
activeArea.addImplicitImports(wildcardImports.toArray(new String[0]));
|
activeArea.addImplicitImports(wildcardImports.toArray(new String[0]));
|
||||||
|
|
||||||
|
|
||||||
// Format to update which implicit imports are actually used
|
|
||||||
activeArea.formatCodeText();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3504,9 +3504,6 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
|||||||
public void setLanguage(String language) {
|
public void setLanguage(String language) {
|
||||||
if (this.container != null) {
|
if (this.container != null) {
|
||||||
this.container.setLanguage(language);
|
this.container.setLanguage(language);
|
||||||
if (this.enableCodeHighlighting) {
|
|
||||||
this.container.formatCodeText();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -368,45 +368,53 @@ public class ScriptDocument {
|
|||||||
* fieldAccesses, etc.) are shared between languages.
|
* fieldAccesses, etc.) are shared between languages.
|
||||||
*/
|
*/
|
||||||
public void formatCodeText() {
|
public void formatCodeText() {
|
||||||
// Clear previous state (same for both languages)
|
ScriptProfiler.begin("formatCodeText");
|
||||||
errors.clear();
|
try {
|
||||||
imports.clear();
|
errors.clear();
|
||||||
methods.clear();
|
imports.clear();
|
||||||
globalFields.clear();
|
methods.clear();
|
||||||
wildcardPackages.clear();
|
globalFields.clear();
|
||||||
excludedRanges.clear();
|
wildcardPackages.clear();
|
||||||
methodLocals.clear();
|
excludedRanges.clear();
|
||||||
topLevelLocals.clear();
|
methodLocals.clear();
|
||||||
scriptTypes.clear();
|
topLevelLocals.clear();
|
||||||
scriptTypesByFullName.clear();
|
scriptTypes.clear();
|
||||||
scriptTypesByDotName.clear();
|
scriptTypesByFullName.clear();
|
||||||
innerScopes.clear();
|
scriptTypesByDotName.clear();
|
||||||
methodCalls.clear();
|
innerScopes.clear();
|
||||||
externalFieldAssignments.clear();
|
methodCalls.clear();
|
||||||
declarationErrors.clear();
|
externalFieldAssignments.clear();
|
||||||
scriptMethodSamContexts.clear();
|
declarationErrors.clear();
|
||||||
objectLiterals.clear();
|
scriptMethodSamContexts.clear();
|
||||||
lambdaCache.clear();
|
objectLiterals.clear();
|
||||||
|
lambdaCache.clear();
|
||||||
|
|
||||||
// Unified pipeline for both languages
|
List<ScriptLine.Mark> marks = formatUnified();
|
||||||
List<ScriptLine.Mark> marks = formatUnified();
|
|
||||||
|
|
||||||
// Phase 5: Resolve conflicts and sort
|
ScriptProfiler.begin("resolveConflicts");
|
||||||
marks = resolveConflicts(marks);
|
marks = resolveConflicts(marks);
|
||||||
|
ScriptProfiler.end("resolveConflicts");
|
||||||
|
|
||||||
// Phase 6: Build tokens for each line
|
ScriptProfiler.begin("buildTokensPerLine");
|
||||||
for (ScriptLine line : lines) {
|
for (ScriptLine line : lines) {
|
||||||
line.buildTokensFromMarks(marks, text, this);
|
line.buildTokensFromMarks(marks, text, this);
|
||||||
|
}
|
||||||
|
ScriptProfiler.end("buildTokensPerLine");
|
||||||
|
|
||||||
|
ScriptProfiler.begin("removeUnusedImplicitImports");
|
||||||
|
removeUnusedImplicitImports();
|
||||||
|
ScriptProfiler.end("removeUnusedImplicitImports");
|
||||||
|
|
||||||
|
ScriptProfiler.begin("computeIndentGuides");
|
||||||
|
computeIndentGuides(marks);
|
||||||
|
ScriptProfiler.end("computeIndentGuides");
|
||||||
|
|
||||||
|
ScriptProfiler.begin("populateErrors");
|
||||||
|
populateErrors();
|
||||||
|
ScriptProfiler.end("populateErrors");
|
||||||
|
} finally {
|
||||||
|
ScriptProfiler.end("formatCodeText");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase 6.5: Now that tokens are built, remove implicit imports that aren't actually used
|
|
||||||
removeUnusedImplicitImports();
|
|
||||||
|
|
||||||
// Phase 7: Compute indent guides
|
|
||||||
computeIndentGuides(marks);
|
|
||||||
|
|
||||||
// Phase 8: Populate centralized error list from all error sources
|
|
||||||
populateErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the last JS analyzer for autocomplete (deprecated - use methods/globalFields/methodLocals instead)
|
// Store the last JS analyzer for autocomplete (deprecated - use methods/globalFields/methodLocals instead)
|
||||||
@@ -428,17 +436,23 @@ public class ScriptDocument {
|
|||||||
private List<ScriptLine.Mark> formatUnified() {
|
private List<ScriptLine.Mark> formatUnified() {
|
||||||
TypeChecker.enterTypeCheckingContext(isJavaScript());
|
TypeChecker.enterTypeCheckingContext(isJavaScript());
|
||||||
|
|
||||||
// Phase 1: Find excluded regions (strings/comments) - same for both
|
ScriptProfiler.begin("findExcludedRanges");
|
||||||
findExcludedRanges();
|
findExcludedRanges();
|
||||||
|
ScriptProfiler.end("findExcludedRanges");
|
||||||
|
|
||||||
// Phase 2: Parse imports (Java only, JS skips this)
|
ScriptProfiler.begin("parseImports");
|
||||||
parseImports();
|
parseImports();
|
||||||
|
ScriptProfiler.end("parseImports");
|
||||||
|
|
||||||
// Phase 3: Parse structure (methods, fields, locals) - language aware
|
ScriptProfiler.begin("parseStructure");
|
||||||
parseStructure();
|
parseStructure();
|
||||||
|
ScriptProfiler.end("parseStructure");
|
||||||
|
|
||||||
// Phase 4: Build marks - language aware
|
ScriptProfiler.begin("buildMarks");
|
||||||
return buildMarks();
|
List<ScriptLine.Mark> result = buildMarks();
|
||||||
|
ScriptProfiler.end("buildMarks");
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -737,41 +751,48 @@ public class ScriptDocument {
|
|||||||
* Uses the SAME logic and data structures for both Java and JavaScript.
|
* Uses the SAME logic and data structures for both Java and JavaScript.
|
||||||
*/
|
*/
|
||||||
private void parseStructure() {
|
private void parseStructure() {
|
||||||
// Clear import references before re-parsing
|
|
||||||
for (ImportData imp : imports) {
|
for (ImportData imp : imports) {
|
||||||
imp.clearReferences();
|
imp.clearReferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse script-defined types (classes, interfaces, enums) - Java only
|
|
||||||
if (!isJavaScript()) {
|
if (!isJavaScript()) {
|
||||||
|
ScriptProfiler.begin("parseScriptTypes");
|
||||||
parseScriptTypes();
|
parseScriptTypes();
|
||||||
|
ScriptProfiler.end("parseScriptTypes");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse methods/functions - UNIFIED for both languages
|
ScriptProfiler.begin("parseMethodDeclarations");
|
||||||
parseMethodDeclarations();
|
parseMethodDeclarations();
|
||||||
|
ScriptProfiler.end("parseMethodDeclarations");
|
||||||
|
|
||||||
// Parse inner callable scopes (lambdas, JS function expressions)
|
ScriptProfiler.begin("parseInnerCallableScopes");
|
||||||
parseInnerCallableScopes();
|
parseInnerCallableScopes();
|
||||||
|
ScriptProfiler.end("parseInnerCallableScopes");
|
||||||
|
|
||||||
// Parse local variables inside methods/functions - UNIFIED for both languages
|
ScriptProfiler.begin("parseLocalVariables");
|
||||||
parseLocalVariables();
|
parseLocalVariables();
|
||||||
|
ScriptProfiler.end("parseLocalVariables");
|
||||||
|
|
||||||
// Parse global fields (outside methods) - UNIFIED for both languages
|
ScriptProfiler.begin("parseGlobalFields");
|
||||||
parseGlobalFields();
|
parseGlobalFields();
|
||||||
|
ScriptProfiler.end("parseGlobalFields");
|
||||||
|
|
||||||
// Must run before parseAssignments: sets inferredType on lambda params so that
|
ScriptProfiler.begin("inferLambdaParameterTypes");
|
||||||
// body variable resolution (e.g. "act" in "int x = act.getData()") works correctly.
|
|
||||||
inferLambdaParameterTypes();
|
inferLambdaParameterTypes();
|
||||||
|
ScriptProfiler.end("inferLambdaParameterTypes");
|
||||||
|
|
||||||
// Parse and validate assignments (reassignments) - UNIFIED for both languages
|
ScriptProfiler.begin("parseAssignments");
|
||||||
parseAssignments();
|
parseAssignments();
|
||||||
|
ScriptProfiler.end("parseAssignments");
|
||||||
|
|
||||||
// Cache object literals after globals/locals are available for accurate value-type inference
|
ScriptProfiler.begin("parseObjectLiterals");
|
||||||
parseObjectLiterals();
|
parseObjectLiterals();
|
||||||
|
ScriptProfiler.end("parseObjectLiterals");
|
||||||
|
|
||||||
// Detect method overrides and interface implementations for script types - Java only
|
|
||||||
if (!isJavaScript()) {
|
if (!isJavaScript()) {
|
||||||
|
ScriptProfiler.begin("detectMethodInheritance");
|
||||||
detectMethodInheritance();
|
detectMethodInheritance();
|
||||||
|
ScriptProfiler.end("detectMethodInheritance");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4593,80 +4614,91 @@ public class ScriptDocument {
|
|||||||
private List<ScriptLine.Mark> buildMarks() {
|
private List<ScriptLine.Mark> buildMarks() {
|
||||||
List<ScriptLine.Mark> marks = new ArrayList<>();
|
List<ScriptLine.Mark> marks = new ArrayList<>();
|
||||||
|
|
||||||
// Strings first to protect their content
|
ScriptProfiler.begin("markStrings");
|
||||||
addPatternMarks(marks, STRING_PATTERN, TokenType.STRING);
|
addPatternMarks(marks, STRING_PATTERN, TokenType.STRING);
|
||||||
|
ScriptProfiler.end("markStrings");
|
||||||
|
|
||||||
// JSDoc comments with fragmented marking (avoids conflicts with @tags and {Type})
|
ScriptProfiler.begin("markJSDocElements");
|
||||||
markJSDocElements(marks);
|
markJSDocElements(marks);
|
||||||
|
ScriptProfiler.end("markJSDocElements");
|
||||||
|
|
||||||
// Regular comments (non-JSDoc)
|
ScriptProfiler.begin("markComments");
|
||||||
markNonJSDocComments(marks);
|
markNonJSDocComments(marks);
|
||||||
|
ScriptProfiler.end("markComments");
|
||||||
|
|
||||||
// Keywords - same for both languages (KEYWORD_PATTERN includes JS keywords like function, var, let, const)
|
ScriptProfiler.begin("markKeywords");
|
||||||
addPatternMarks(marks, KEYWORD_PATTERN, TokenType.KEYWORD);
|
addPatternMarks(marks, KEYWORD_PATTERN, TokenType.KEYWORD);
|
||||||
if(isJavaScript())
|
if(isJavaScript())
|
||||||
addPatternMarks(marks, KEYWORD_JS_PATTERN, TokenType.KEYWORD);
|
addPatternMarks(marks, KEYWORD_JS_PATTERN, TokenType.KEYWORD);
|
||||||
|
ScriptProfiler.end("markKeywords");
|
||||||
|
|
||||||
// Numbers - same for both languages
|
|
||||||
addPatternMarks(marks, NUMBER_PATTERN, TokenType.LITERAL);
|
addPatternMarks(marks, NUMBER_PATTERN, TokenType.LITERAL);
|
||||||
|
|
||||||
if (isJavaScript()) {
|
if (isJavaScript()) {
|
||||||
markObjectLiteralKeys(marks);
|
markObjectLiteralKeys(marks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import statements - Java only
|
|
||||||
if (!isJavaScript()) {
|
if (!isJavaScript()) {
|
||||||
markImports(marks);
|
markImports(marks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class/interface/enum declarations - Java only
|
|
||||||
if (!isJavaScript()) {
|
if (!isJavaScript()) {
|
||||||
markClassDeclarations(marks);
|
markClassDeclarations(marks);
|
||||||
markEnumConstants(marks);
|
markEnumConstants(marks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifiers - Java only
|
|
||||||
if (!isJavaScript()) {
|
if (!isJavaScript()) {
|
||||||
addPatternMarks(marks, MODIFIER_PATTERN, TokenType.KEYWORD);
|
addPatternMarks(marks, MODIFIER_PATTERN, TokenType.KEYWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type declarations and usages - Java only (JS doesn't have explicit types)
|
|
||||||
if (!isJavaScript()) {
|
if (!isJavaScript()) {
|
||||||
|
ScriptProfiler.begin("markTypeDeclarations");
|
||||||
markTypeDeclarations(marks);
|
markTypeDeclarations(marks);
|
||||||
|
ScriptProfiler.end("markTypeDeclarations");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods/functions - UNIFIED (uses shared 'methods' list)
|
ScriptProfiler.begin("markMethodDeclarations");
|
||||||
markMethodDeclarations(marks);
|
markMethodDeclarations(marks);
|
||||||
|
ScriptProfiler.end("markMethodDeclarations");
|
||||||
|
|
||||||
// Method calls - UNIFIED (stores in shared 'methodCalls' list)
|
ScriptProfiler.begin("markMethodCalls");
|
||||||
markMethodCalls(marks);
|
markMethodCalls(marks);
|
||||||
|
ScriptProfiler.end("markMethodCalls");
|
||||||
|
|
||||||
// Variables and fields - UNIFIED (uses shared globalFields, methodLocals)
|
ScriptProfiler.begin("markVariables");
|
||||||
markVariables(marks);
|
markVariables(marks);
|
||||||
|
ScriptProfiler.end("markVariables");
|
||||||
|
|
||||||
// Chained field accesses - UNIFIED (uses resolveVariable which handles both)
|
ScriptProfiler.begin("markChainedFieldAccesses");
|
||||||
markChainedFieldAccesses(marks);
|
markChainedFieldAccesses(marks);
|
||||||
markImportedClassUsages(marks);
|
ScriptProfiler.end("markChainedFieldAccesses");
|
||||||
|
|
||||||
|
ScriptProfiler.begin("markImportedClassUsages");
|
||||||
|
markImportedClassUsages(marks);
|
||||||
|
ScriptProfiler.end("markImportedClassUsages");
|
||||||
|
|
||||||
// Java-specific final passes
|
|
||||||
if (!isJavaScript()) {
|
if (!isJavaScript()) {
|
||||||
|
ScriptProfiler.begin("markCastTypes");
|
||||||
markCastTypes(marks);
|
markCastTypes(marks);
|
||||||
|
ScriptProfiler.end("markCastTypes");
|
||||||
|
|
||||||
markUnusedImports(marks);
|
markUnusedImports(marks);
|
||||||
// Mark method reference expressions (target::methodName)
|
|
||||||
markMethodReferences(marks);
|
markMethodReferences(marks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark lambda and method reference operators (-> and ::)
|
|
||||||
markLambdaOperators(marks);
|
markLambdaOperators(marks);
|
||||||
|
|
||||||
// Mark lambda/function parameters with type info
|
ScriptProfiler.begin("markInnerScopeParams");
|
||||||
markInnerScopeParameters(marks);
|
markInnerScopeParameters(marks);
|
||||||
|
ScriptProfiler.end("markInnerScopeParams");
|
||||||
|
|
||||||
// Validate lambda return types
|
ScriptProfiler.begin("validateLambdaReturnTypes");
|
||||||
validateLambdaReturnTypes(marks);
|
validateLambdaReturnTypes(marks);
|
||||||
|
ScriptProfiler.end("validateLambdaReturnTypes");
|
||||||
|
|
||||||
// Final pass: Mark any remaining unmarked identifiers as undefined
|
ScriptProfiler.begin("markUndefinedIdentifiers");
|
||||||
markUndefinedIdentifiers(marks);
|
markUndefinedIdentifiers(marks);
|
||||||
|
ScriptProfiler.end("markUndefinedIdentifiers");
|
||||||
|
|
||||||
return marks;
|
return marks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,435 @@
|
|||||||
|
package noppes.npcs.client.gui.util.script.interpreter;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Profiler for the ScriptDocument parsing/marking pipeline.
|
||||||
|
* <p>
|
||||||
|
* <b>Usage:</b>
|
||||||
|
* <pre>
|
||||||
|
* ScriptProfiler.setEnabled(true);
|
||||||
|
* ScriptProfiler.setReportingThresholdMs(5.0);
|
||||||
|
* // Results auto-print to System.out when root section ends.
|
||||||
|
* // Or: ScriptProfiler.getLastReport();
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* When disabled, begin/end are single boolean checks with zero overhead.
|
||||||
|
* Single-threaded only (Minecraft client thread).
|
||||||
|
*/
|
||||||
|
public final class ScriptProfiler {
|
||||||
|
|
||||||
|
private static boolean enabled = false;
|
||||||
|
private static double reportingThresholdMs = 0.0;
|
||||||
|
private static boolean autoPrint = true;
|
||||||
|
private static int maxHistory = 50;
|
||||||
|
|
||||||
|
private static final Deque<ActiveSection> sectionStack = new ArrayDeque<>();
|
||||||
|
private static final List<SectionResult> currentResults = new ArrayList<>();
|
||||||
|
private static int currentDepth = 0;
|
||||||
|
private static int beginSequence = 0;
|
||||||
|
private static final Deque<ProfileSnapshot> history = new ArrayDeque<>();
|
||||||
|
private static String lastReport = null;
|
||||||
|
private static ProfileSnapshot lastSnapshot = null;
|
||||||
|
private static final Map<String, AccumulatedStats> accumulatedStats = new LinkedHashMap<>();
|
||||||
|
private static int invocationCount = 0;
|
||||||
|
|
||||||
|
public static void setEnabled(boolean enable) {
|
||||||
|
enabled = enable;
|
||||||
|
if (!enable) {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setReportingThresholdMs(double thresholdMs) {
|
||||||
|
reportingThresholdMs = thresholdMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAutoPrint(boolean auto) {
|
||||||
|
autoPrint = auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begin timing a named section. Sections nest: begin("A") -> begin("B") -> end("B") -> end("A").
|
||||||
|
*/
|
||||||
|
public static void begin(String name) {
|
||||||
|
if (!enabled) return;
|
||||||
|
sectionStack.push(new ActiveSection(name, System.nanoTime(), currentDepth, beginSequence++));
|
||||||
|
currentDepth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End timing a named section. Must match the most recent begin().
|
||||||
|
*/
|
||||||
|
public static void end(String name) {
|
||||||
|
if (!enabled) return;
|
||||||
|
if (sectionStack.isEmpty()) {
|
||||||
|
System.err.println("[ScriptProfiler] WARNING: end('" + name + "') called with no active section");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActiveSection active = sectionStack.pop();
|
||||||
|
currentDepth--;
|
||||||
|
|
||||||
|
if (!active.name.equals(name)) {
|
||||||
|
System.err.println("[ScriptProfiler] WARNING: end('" + name + "') doesn't match begin('" + active.name + "')");
|
||||||
|
}
|
||||||
|
|
||||||
|
long elapsed = System.nanoTime() - active.startNano;
|
||||||
|
currentResults.add(new SectionResult(active.name, active.depth, elapsed, active.beginOrder));
|
||||||
|
|
||||||
|
if (sectionStack.isEmpty()) {
|
||||||
|
finalizeReport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience: time a Runnable.
|
||||||
|
*/
|
||||||
|
public static void time(String name, Runnable work) {
|
||||||
|
begin(name);
|
||||||
|
try {
|
||||||
|
work.run();
|
||||||
|
} finally {
|
||||||
|
end(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLastReport() {
|
||||||
|
return lastReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProfileSnapshot getLastSnapshot() {
|
||||||
|
return lastSnapshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ProfileSnapshot> getHistory() {
|
||||||
|
return new ArrayList<>(history);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, AccumulatedStats> getAccumulatedStats() {
|
||||||
|
return Collections.unmodifiableMap(accumulatedStats);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getInvocationCount() {
|
||||||
|
return invocationCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reset() {
|
||||||
|
sectionStack.clear();
|
||||||
|
currentResults.clear();
|
||||||
|
currentDepth = 0;
|
||||||
|
beginSequence = 0;
|
||||||
|
history.clear();
|
||||||
|
lastReport = null;
|
||||||
|
lastSnapshot = null;
|
||||||
|
accumulatedStats.clear();
|
||||||
|
invocationCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetStats() {
|
||||||
|
history.clear();
|
||||||
|
accumulatedStats.clear();
|
||||||
|
invocationCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Summary of accumulated stats across all invocations -
|
||||||
|
* identifies consistent bottlenecks vs. one-off spikes.
|
||||||
|
*/
|
||||||
|
public static String getAccumulatedReport() {
|
||||||
|
if (accumulatedStats.isEmpty()) {
|
||||||
|
return "[ScriptProfiler] No accumulated data.";
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("\n============================================================\n");
|
||||||
|
sb.append(" SCRIPT PROFILER - ACCUMULATED STATS\n");
|
||||||
|
sb.append(" Invocations: ").append(invocationCount).append("\n");
|
||||||
|
sb.append("============================================================\n");
|
||||||
|
sb.append(String.format(" %-30s | %7s | %7s | %7s\n", "Section", "Avg(ms)", "Max(ms)", "Min(ms)"));
|
||||||
|
sb.append("------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
for (Map.Entry<String, AccumulatedStats> entry : accumulatedStats.entrySet()) {
|
||||||
|
AccumulatedStats stats = entry.getValue();
|
||||||
|
String indent = getIndent(stats.depth);
|
||||||
|
String label = indent + truncate(entry.getKey(), 30 - indent.length());
|
||||||
|
sb.append(String.format(" %-30s | %7.2f | %7.2f | %7.2f\n",
|
||||||
|
label, stats.getAverageMs(), stats.getMaxMs(), stats.getMinMs()));
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("============================================================\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== Internals ========================
|
||||||
|
|
||||||
|
private static void finalizeReport() {
|
||||||
|
invocationCount++;
|
||||||
|
|
||||||
|
List<SectionResult> results = new ArrayList<>(currentResults);
|
||||||
|
Collections.sort(results, new Comparator<SectionResult>() {
|
||||||
|
public int compare(SectionResult a, SectionResult b) {
|
||||||
|
return Integer.compare(a.beginOrder, b.beginOrder);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ProfileSnapshot snapshot = new ProfileSnapshot(results, System.currentTimeMillis());
|
||||||
|
lastSnapshot = snapshot;
|
||||||
|
|
||||||
|
history.addLast(snapshot);
|
||||||
|
while (history.size() > maxHistory) {
|
||||||
|
history.removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SectionResult r : results) {
|
||||||
|
AccumulatedStats stats = accumulatedStats.get(r.name);
|
||||||
|
if (stats == null) {
|
||||||
|
stats = new AccumulatedStats(r.depth);
|
||||||
|
accumulatedStats.put(r.name, stats);
|
||||||
|
}
|
||||||
|
stats.record(r.elapsedNanos);
|
||||||
|
}
|
||||||
|
|
||||||
|
String report = buildReport(snapshot);
|
||||||
|
lastReport = report;
|
||||||
|
|
||||||
|
if (autoPrint) {
|
||||||
|
double totalMs = snapshot.getTotalMs();
|
||||||
|
if (totalMs >= reportingThresholdMs) {
|
||||||
|
System.out.println(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentResults.clear();
|
||||||
|
currentDepth = 0;
|
||||||
|
beginSequence = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildReport(ProfileSnapshot snapshot) {
|
||||||
|
List<SectionResult> results = snapshot.results;
|
||||||
|
if (results.isEmpty()) return "[ScriptProfiler] Empty report.";
|
||||||
|
|
||||||
|
SectionResult root = null;
|
||||||
|
for (SectionResult r : results) {
|
||||||
|
if (r.depth == 0) {
|
||||||
|
root = r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (root == null) root = results.get(0);
|
||||||
|
|
||||||
|
double totalMs = root.elapsedNanos / 1_000_000.0;
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("\n================================================================\n");
|
||||||
|
sb.append(" SCRIPT DOCUMENT PROFILER - Pipeline Breakdown\n");
|
||||||
|
sb.append(" Total: ").append(String.format("%.2fms", totalMs));
|
||||||
|
sb.append(" | Lines: ").append(getLineCount());
|
||||||
|
sb.append(" | Chars: ").append(getCharCount());
|
||||||
|
sb.append("\n================================================================\n");
|
||||||
|
sb.append(String.format(" %-36s | %8s | %5s | %s\n", "Stage", "Time(ms)", " % ", "Bar"));
|
||||||
|
sb.append("----------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
for (SectionResult r : results) {
|
||||||
|
double ms = r.elapsedNanos / 1_000_000.0;
|
||||||
|
double pct = (root.elapsedNanos > 0) ? (100.0 * r.elapsedNanos / root.elapsedNanos) : 0;
|
||||||
|
String indent = getIndent(r.depth);
|
||||||
|
String label = indent + truncate(r.name, 36 - indent.length());
|
||||||
|
String bar = makeBar(pct, 8);
|
||||||
|
|
||||||
|
String flag = "";
|
||||||
|
if (r.depth > 0 && (pct > 20.0 || ms > 5.0)) {
|
||||||
|
flag = " << SLOW";
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(String.format(" %-36s | %8.2f | %4.1f%% | %-8s %s\n",
|
||||||
|
label, ms, pct, bar, flag));
|
||||||
|
}
|
||||||
|
|
||||||
|
long childSum = 0;
|
||||||
|
for (SectionResult r : results) {
|
||||||
|
if (r.depth == 1) {
|
||||||
|
childSum += r.elapsedNanos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (root.elapsedNanos > 0) {
|
||||||
|
long unaccounted = root.elapsedNanos - childSum;
|
||||||
|
if (unaccounted > 0) {
|
||||||
|
double uMs = unaccounted / 1_000_000.0;
|
||||||
|
double uPct = 100.0 * unaccounted / root.elapsedNanos;
|
||||||
|
sb.append(String.format(" %-36s | %8.2f | %4.1f%% | %-8s\n",
|
||||||
|
" (overhead/unlisted)", uMs, uPct, makeBar(uPct, 8)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("================================================================\n");
|
||||||
|
sb.append(buildBottleneckSummary(results, root.elapsedNanos));
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildBottleneckSummary(List<SectionResult> results, long totalNanos) {
|
||||||
|
if (results.size() <= 1) return "";
|
||||||
|
|
||||||
|
List<SectionResult> sorted = new ArrayList<>();
|
||||||
|
for (SectionResult r : results) {
|
||||||
|
if (r.depth > 0) sorted.add(r);
|
||||||
|
}
|
||||||
|
Collections.sort(sorted, new Comparator<SectionResult>() {
|
||||||
|
public int compare(SectionResult a, SectionResult b) {
|
||||||
|
return Long.compare(b.elapsedNanos, a.elapsedNanos);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(" Top bottlenecks:\n");
|
||||||
|
int count = Math.min(3, sorted.size());
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
SectionResult r = sorted.get(i);
|
||||||
|
double ms = r.elapsedNanos / 1_000_000.0;
|
||||||
|
double pct = totalNanos > 0 ? (100.0 * r.elapsedNanos / totalNanos) : 0;
|
||||||
|
sb.append(String.format(" %d. %-30s %7.2fms (%4.1f%%)\n", i + 1, r.name, ms, pct));
|
||||||
|
}
|
||||||
|
sb.append("\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getIndent(int depth) {
|
||||||
|
if (depth <= 0) return "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < depth; i++) sb.append(" ");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String truncate(String s, int max) {
|
||||||
|
if (max <= 0) return "";
|
||||||
|
if (s.length() <= max) return s;
|
||||||
|
return s.substring(0, max - 2) + "..";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String makeBar(double pct, int maxLen) {
|
||||||
|
int filled = (int) Math.round(pct / 100.0 * maxLen);
|
||||||
|
filled = Math.min(filled, maxLen);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < filled; i++) sb.append('#');
|
||||||
|
for (int i = filled; i < maxLen; i++) sb.append('.');
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String pad(int n) {
|
||||||
|
if (n <= 0) return "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < n; i++) sb.append(' ');
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getLineCount() {
|
||||||
|
ScriptDocument doc = ScriptDocument.INSTANCE;
|
||||||
|
return doc != null ? doc.getLines().size() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getCharCount() {
|
||||||
|
ScriptDocument doc = ScriptDocument.INSTANCE;
|
||||||
|
return doc != null ? doc.getText().length() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ======================== Data Classes ========================
|
||||||
|
|
||||||
|
private static class ActiveSection {
|
||||||
|
final String name;
|
||||||
|
final long startNano;
|
||||||
|
final int depth;
|
||||||
|
final int beginOrder;
|
||||||
|
|
||||||
|
ActiveSection(String name, long startNano, int depth, int beginOrder) {
|
||||||
|
this.name = name;
|
||||||
|
this.startNano = startNano;
|
||||||
|
this.depth = depth;
|
||||||
|
this.beginOrder = beginOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SectionResult {
|
||||||
|
public final String name;
|
||||||
|
public final int depth;
|
||||||
|
public final long elapsedNanos;
|
||||||
|
final int beginOrder;
|
||||||
|
|
||||||
|
SectionResult(String name, int depth, long elapsedNanos, int beginOrder) {
|
||||||
|
this.name = name;
|
||||||
|
this.depth = depth;
|
||||||
|
this.elapsedNanos = elapsedNanos;
|
||||||
|
this.beginOrder = beginOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getElapsedMs() {
|
||||||
|
return elapsedNanos / 1_000_000.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProfileSnapshot {
|
||||||
|
public final List<SectionResult> results;
|
||||||
|
public final long timestampMs;
|
||||||
|
|
||||||
|
ProfileSnapshot(List<SectionResult> results, long timestampMs) {
|
||||||
|
this.results = Collections.unmodifiableList(results);
|
||||||
|
this.timestampMs = timestampMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTotalMs() {
|
||||||
|
if (results.isEmpty()) return 0;
|
||||||
|
return results.get(0).getElapsedMs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSectionMs(String name) {
|
||||||
|
for (SectionResult r : results) {
|
||||||
|
if (r.name.equals(name)) return r.getElapsedMs();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AccumulatedStats {
|
||||||
|
public final int depth;
|
||||||
|
private long totalNanos;
|
||||||
|
private long maxNanos;
|
||||||
|
private long minNanos;
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
AccumulatedStats(int depth) {
|
||||||
|
this.depth = depth;
|
||||||
|
this.totalNanos = 0;
|
||||||
|
this.maxNanos = Long.MIN_VALUE;
|
||||||
|
this.minNanos = Long.MAX_VALUE;
|
||||||
|
this.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void record(long nanos) {
|
||||||
|
totalNanos += nanos;
|
||||||
|
if (nanos > maxNanos) maxNanos = nanos;
|
||||||
|
if (nanos < minNanos) minNanos = nanos;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getAverageMs() {
|
||||||
|
return count > 0 ? (totalNanos / (double) count) / 1_000_000.0 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxMs() {
|
||||||
|
return maxNanos != Long.MIN_VALUE ? maxNanos / 1_000_000.0 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinMs() {
|
||||||
|
return minNanos != Long.MAX_VALUE ? minNanos / 1_000_000.0 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScriptProfiler() {}
|
||||||
|
}
|
||||||
@@ -190,6 +190,9 @@ public class ScriptTextContainer extends JavaTextContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 1. initScriptEditor.setLanguage
|
||||||
|
* 2. initScriptEditorTab.enableCodeHighlighting
|
||||||
|
* 3. initScriptEditor.updateScriptDocumentImports
|
||||||
* Main formatting entry point - matches JavaTextContainer signature.
|
* Main formatting entry point - matches JavaTextContainer signature.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -199,7 +202,9 @@ public class ScriptTextContainer extends JavaTextContainer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptProfiler.setEnabled(true);
|
||||||
document.formatCodeText();
|
document.formatCodeText();
|
||||||
|
ScriptProfiler.setEnabled(false);
|
||||||
rebuildLineData();
|
rebuildLineData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user