mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 20:22:37 +00:00
pillar entity
This commit is contained in:
1 parent
ca7f3f937b
commit
d4a89dad1d
6 files changed
+1276
-33
No files matched your search
@@ -0,0 +1,320 @@
|
||||
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 noppes.npcs.LogWriter;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* Renders EntityAbilityPillar as a vertical energy column.
|
||||
*
|
||||
* Shape modes:
|
||||
* - CIRCLE: cylindrical pillar rendered with triangulated segments.
|
||||
* - SQUARE: rectangular prism pillar.
|
||||
*
|
||||
* Both modes render three color layers (outer glow, mid, inner core)
|
||||
* following the same pattern as RenderEnergyLaser.
|
||||
*
|
||||
* Origin modes:
|
||||
* - FROM_GROUND: base at posY, tip grows upward.
|
||||
* - FROM_ABOVE: base at posY + height, tip grows downward.
|
||||
*/
|
||||
@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;
|
||||
|
||||
noppes.npcs.LogWriter.info("RenderEnergyPillar: tick=" + pillar.ticksExisted
|
||||
+ " charging=" + pillar.isCharging()
|
||||
+ " growing=" + pillar.isGrowing()
|
||||
+ " radius=" + pillar.getPillarRadius()
|
||||
+ " height=" + pillar.getPillarHeight());
|
||||
|
||||
if (shouldSkipInitialActiveRender(pillar)) return;
|
||||
|
||||
setupRenderState();
|
||||
|
||||
float proximityAlpha = getProximityAlphaFactor(pillar, x, y, z);
|
||||
|
||||
if (pillar.isCharging()) {
|
||||
renderCharging(pillar, x, y, z, partialTicks, proximityAlpha);
|
||||
restoreRenderState();
|
||||
return;
|
||||
}
|
||||
|
||||
float radius = pillar.getInterpolatedPillarRadius(partialTicks);
|
||||
float height = pillar.getInterpolatedPillarHeight(partialTicks);
|
||||
|
||||
if (radius <= 0.01f || height <= 0.01f) {
|
||||
restoreRenderState();
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve Y extents based on origin
|
||||
float baseY, tipY;
|
||||
if (pillar.getPillarOrigin() == PillarOrigin.FROM_ABOVE) {
|
||||
baseY = (float) y + height;
|
||||
tipY = (float) y;
|
||||
} else {
|
||||
baseY = (float) y;
|
||||
tipY = (float) y + height;
|
||||
}
|
||||
|
||||
// Rotation around Y axis
|
||||
float rotationAngle = 0f;
|
||||
float rotationSpeed = pillar.getRotationSpeed();
|
||||
if (rotationSpeed != 0f) {
|
||||
rotationAngle = (pillar.ticksExisted + partialTicks) * rotationSpeed;
|
||||
}
|
||||
|
||||
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) {
|
||||
float radius = pillar.getInterpolatedPillarRadius(partialTicks);
|
||||
float chargeProgress = pillar.getInterpolatedChargeProgress(partialTicks);
|
||||
float renderRadius = radius * chargeProgress;
|
||||
|
||||
if (renderRadius <= 0.01f) return;
|
||||
|
||||
// Pulse effect
|
||||
float pulseTime = pillar.ticksExisted + partialTicks;
|
||||
float pulse = (float) Math.sin(pulseTime * 0.2f) * 0.08f;
|
||||
renderRadius *= (1.0f + pulse);
|
||||
|
||||
float height = 0.05f; // MIN_HEIGHT — flat disc during charging
|
||||
float baseY = (float) y;
|
||||
float tipY = baseY + height;
|
||||
|
||||
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 + height * 0.5f, 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 ====================
|
||||
|
||||
/**
|
||||
* Render a cylindrical pillar with lateral faces and top/bottom caps.
|
||||
* Rotation is applied around Y axis.
|
||||
*/
|
||||
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;
|
||||
|
||||
// Lateral faces
|
||||
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;
|
||||
|
||||
float nx = (cosTable[i] + cosTable[i + 1]) * 0.5f;
|
||||
float nz = (sinTable[i] + sinTable[i + 1]) * 0.5f;
|
||||
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.draw();
|
||||
|
||||
// Bottom cap
|
||||
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, baseY, (float) cz);
|
||||
tess.addVertex(x2, baseY, z2);
|
||||
tess.addVertex(x1, baseY, z1);
|
||||
tess.addVertex((float) cx, baseY, (float) cz);
|
||||
}
|
||||
tess.draw();
|
||||
|
||||
// Top cap
|
||||
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, tipY, (float) cz);
|
||||
tess.addVertex(x1, tipY, z1);
|
||||
tess.addVertex(x2, tipY, z2);
|
||||
tess.addVertex((float) cx, tipY, (float) cz);
|
||||
}
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
// ==================== SQUARE ====================
|
||||
|
||||
/**
|
||||
* Render a rectangular prism pillar with four lateral faces and top/bottom caps.
|
||||
* Rotation is applied around Y axis.
|
||||
*/
|
||||
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];
|
||||
|
||||
// Four corners of the square, rotated around Y
|
||||
double rotRad = Math.toRadians(rotationAngle);
|
||||
float cosA = (float) Math.cos(rotRad);
|
||||
float sinA = (float) Math.sin(rotRad);
|
||||
|
||||
// Local corners before rotation: (±radius, ±radius)
|
||||
float[][] corners = new float[4][2];
|
||||
float[] lx = {-radius, radius, radius, -radius};
|
||||
float[] lz = {-radius, -radius, radius, radius};
|
||||
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;
|
||||
}
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
tess.startDrawingQuads();
|
||||
tess.setColorRGBA_F(r, g, b, alpha);
|
||||
|
||||
// Four lateral faces
|
||||
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];
|
||||
|
||||
// Outward normal (midpoint of edge, normalized)
|
||||
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);
|
||||
}
|
||||
|
||||
// Bottom cap
|
||||
tess.setNormal(0, -1, 0);
|
||||
tess.addVertex(corners[0][0], baseY, corners[0][1]);
|
||||
tess.addVertex(corners[3][0], baseY, corners[3][1]);
|
||||
tess.addVertex(corners[2][0], baseY, corners[2][1]);
|
||||
tess.addVertex(corners[1][0], baseY, corners[1][1]);
|
||||
|
||||
// Top cap
|
||||
tess.setNormal(0, 1, 0);
|
||||
tess.addVertex(corners[0][0], tipY, corners[0][1]);
|
||||
tess.addVertex(corners[1][0], tipY, corners[1][1]);
|
||||
tess.addVertex(corners[2][0], tipY, corners[2][1]);
|
||||
tess.addVertex(corners[3][0], tipY, corners[3][1]);
|
||||
|
||||
tess.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected net.minecraft.util.ResourceLocation getEntityTexture(Entity entity) {
|
||||
return WHITE_TEXTURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
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.1f;
|
||||
public float heightGrowSpeed = 0.2f;
|
||||
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 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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyPillarData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyHomingData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLightningData;
|
||||
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 — a column of energy that rises from the ground or falls from the sky.
|
||||
*
|
||||
* Behavior modes:
|
||||
* - ANCHORED: spawns at a fixed position and stays there.
|
||||
* - MOVING: spawns in front of the caster and travels forward,
|
||||
* optionally homing toward a target.
|
||||
*
|
||||
* Lifecycle:
|
||||
* 1. Charging — pillarRadius grows from 0 to targetRadius; pillarHeight stays at MIN_HEIGHT.
|
||||
* 2. spawnDelay — fully charged, position locks (ANCHORED) or begins moving (MOVING).
|
||||
* Height growth has not started yet.
|
||||
* 3. Active — pillarHeight grows toward targetHeight at heightGrowSpeed per tick;
|
||||
* pillarRadius continues toward targetRadius at radiusGrowSpeed per tick.
|
||||
* Damage checks run once height exceeds MIN_HEIGHT.
|
||||
*/
|
||||
public class EntityAbilityPillar extends EntityEnergyZone {
|
||||
|
||||
// ==================== CONSTANTS ====================
|
||||
|
||||
private static final float MIN_HEIGHT = 0.05f;
|
||||
|
||||
// ==================== ENUMS ====================
|
||||
|
||||
public enum PillarMode {
|
||||
ANCHORED,
|
||||
MOVING
|
||||
}
|
||||
|
||||
public enum PillarOrigin {
|
||||
FROM_GROUND,
|
||||
FROM_ABOVE
|
||||
}
|
||||
|
||||
public enum PillarShape {
|
||||
CIRCLE,
|
||||
SQUARE;
|
||||
|
||||
public TelegraphType getTelegraphType() {
|
||||
if (this == CIRCLE) {
|
||||
return TelegraphType.CIRCLE;
|
||||
} else {
|
||||
return TelegraphType.SQUARE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== PILLAR CONFIG ====================
|
||||
|
||||
private EnergyPillarData pillarData = new EnergyPillarData();
|
||||
|
||||
// ==================== PILLAR DIMENSIONS ====================
|
||||
|
||||
private float pillarRadius = 0.01f;
|
||||
private float pillarHeight = MIN_HEIGHT;
|
||||
|
||||
private float renderPillarRadius = 0.01f;
|
||||
private float renderPillarHeight = MIN_HEIGHT;
|
||||
|
||||
private float prevRenderPillarRadius = 0.01f;
|
||||
private float prevRenderPillarHeight = MIN_HEIGHT;
|
||||
|
||||
// ==================== HOMING ====================
|
||||
|
||||
protected EnergyHomingData homingData = new EnergyHomingData();
|
||||
private int targetEntityId = -1;
|
||||
|
||||
// ==================== 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,
|
||||
EnergyLightningData lightning,
|
||||
EnergyHomingData homing) {
|
||||
super(world);
|
||||
|
||||
this.ownerEntityId = owner != null ? owner.getEntityId() : -1;
|
||||
this.pillarData = pillarData != null ? pillarData.copy() : new EnergyPillarData();
|
||||
this.homingData = homing != null ? homing.copy() : new EnergyHomingData();
|
||||
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||
|
||||
snapToGround(x, y, z);
|
||||
|
||||
this.pillarRadius = 0.01f;
|
||||
this.pillarHeight = MIN_HEIGHT;
|
||||
setVisualRadius(0.01f);
|
||||
setVisualHeight(MIN_HEIGHT);
|
||||
|
||||
syncHitbox();
|
||||
}
|
||||
|
||||
// ==================== SETUP ====================
|
||||
|
||||
/**
|
||||
* Set the entity this pillar tracks in MOVING+homing mode.
|
||||
*/
|
||||
public void setTarget(EntityLivingBase target) {
|
||||
this.targetEntityId = target != null ? target.getEntityId() : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up for GUI preview rendering.
|
||||
*/
|
||||
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);
|
||||
this.pillarRadius = 0.01f;
|
||||
this.pillarHeight = MIN_HEIGHT;
|
||||
setVisualRadius(0.01f);
|
||||
setVisualHeight(MIN_HEIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the ability when charging ends.
|
||||
* Starts the spawnDelay countdown, or immediately begins growing if spawnDelay is 0.
|
||||
*/
|
||||
public void startGrowing() {
|
||||
setCharging(false);
|
||||
this.spawnDelayTick = 0;
|
||||
this.growing = pillarData.spawnDelay <= 0;
|
||||
}
|
||||
|
||||
// ==================== CHARGING ====================
|
||||
|
||||
@Override
|
||||
protected void updateCharging() {
|
||||
chargeTick++;
|
||||
float progress = getChargeProgress();
|
||||
this.pillarRadius = pillarData.targetRadius * progress;
|
||||
this.pillarHeight = MIN_HEIGHT;
|
||||
syncHitbox();
|
||||
}
|
||||
|
||||
// ==================== ZONE UPDATE ====================
|
||||
|
||||
@Override
|
||||
protected void updateZone() {
|
||||
prevRenderPillarRadius = renderPillarRadius;
|
||||
prevRenderPillarHeight = renderPillarHeight;
|
||||
|
||||
if (!growing) {
|
||||
spawnDelayTick++;
|
||||
if (spawnDelayTick >= pillarData.spawnDelay) {
|
||||
growing = true;
|
||||
}
|
||||
renderPillarRadius += (pillarRadius - renderPillarRadius) * 0.15f;
|
||||
renderPillarHeight += (pillarHeight - renderPillarHeight) * 0.15f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
renderPillarRadius += (pillarRadius - renderPillarRadius) * 0.15f;
|
||||
renderPillarHeight += (pillarHeight - renderPillarHeight) * 0.15f;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pillarRadius < pillarData.targetRadius) {
|
||||
pillarRadius = Math.min(pillarData.targetRadius, pillarRadius + pillarData.radiusGrowSpeed);
|
||||
}
|
||||
if (pillarHeight < pillarData.targetHeight) {
|
||||
pillarHeight = Math.min(pillarData.targetHeight, pillarHeight + pillarData.heightGrowSpeed);
|
||||
}
|
||||
|
||||
syncHitbox();
|
||||
|
||||
if (pillarData.mode == PillarMode.MOVING) {
|
||||
updateMovement();
|
||||
}
|
||||
|
||||
if (pillarHeight > MIN_HEIGHT) {
|
||||
checkEntityCollision();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== MOVEMENT (MOVING mode) ====================
|
||||
|
||||
private void updateMovement() {
|
||||
if (!homingData.isHoming()) {
|
||||
this.posX += motionX;
|
||||
this.posZ += motionZ;
|
||||
snapToGround(posX, posY, posZ);
|
||||
return;
|
||||
}
|
||||
|
||||
Entity target = getTargetEntity();
|
||||
if (target == null || !target.isEntityAlive()) {
|
||||
this.posX += motionX;
|
||||
this.posZ += motionZ;
|
||||
snapToGround(posX, posY, posZ);
|
||||
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;
|
||||
snapToGround(posX, posY, posZ);
|
||||
}
|
||||
|
||||
// ==================== COLLISION ====================
|
||||
|
||||
private void checkEntityCollision() {
|
||||
AxisAlignedBB broadBox = AxisAlignedBB.getBoundingBox(
|
||||
posX - pillarRadius, posY, posZ - pillarRadius,
|
||||
posX + pillarRadius, posY + pillarHeight, posZ + pillarRadius
|
||||
);
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Narrow-phase XZ check using PillarShape.
|
||||
* AABB broad phase already filtered by Y; this checks the XZ footprint.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync entity bounding box to current pillar dimensions.
|
||||
* Called after any dimension change so Minecraft chunk tracking stays accurate.
|
||||
*/
|
||||
private void syncHitbox() {
|
||||
float w = Math.max(0.1f, pillarRadius * 2.0f);
|
||||
float h = Math.max(0.1f, pillarHeight);
|
||||
this.setSize(w, h);
|
||||
}
|
||||
|
||||
// ==================== ENTITY HELPERS ====================
|
||||
|
||||
public Entity getTargetEntity() {
|
||||
if (targetEntityId == -1) return null;
|
||||
return worldObj.getEntityByID(targetEntityId);
|
||||
}
|
||||
|
||||
// ==================== RENDERER GETTERS ====================
|
||||
|
||||
public float getPillarRadius() { return pillarRadius; }
|
||||
public float getPillarHeight() { return pillarHeight; }
|
||||
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; }
|
||||
|
||||
public float getInterpolatedPillarRadius(float partialTicks) {
|
||||
return prevRenderPillarRadius + (renderPillarRadius - prevRenderPillarRadius) * partialTicks;
|
||||
}
|
||||
|
||||
public float getInterpolatedPillarHeight(float partialTicks) {
|
||||
return prevRenderPillarHeight + (renderPillarHeight - prevRenderPillarHeight) * partialTicks;
|
||||
}
|
||||
|
||||
// ==================== 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.setInteger("TargetEntityId", targetEntityId);
|
||||
nbt.setDouble("MotionX", motionX);
|
||||
nbt.setDouble("MotionZ", motionZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readZoneNBT(NBTTagCompound nbt) {
|
||||
pillarData.readNBT(nbt);
|
||||
homingData.readNBT(nbt);
|
||||
|
||||
this.pillarRadius = Math.max(0.01f, nbt.getFloat("PillarRadius"));
|
||||
this.pillarHeight = Math.max(MIN_HEIGHT, nbt.getFloat("PillarHeight"));
|
||||
this.spawnDelayTick = nbt.getInteger("SpawnDelayTick");
|
||||
this.growing = nbt.getBoolean("Growing");
|
||||
this.targetEntityId = nbt.hasKey("TargetEntityId") ? nbt.getInteger("TargetEntityId") : -1;
|
||||
this.motionX = nbt.getDouble("MotionX");
|
||||
this.motionZ = nbt.getDouble("MotionZ");
|
||||
|
||||
this.renderPillarRadius = this.pillarRadius;
|
||||
this.prevRenderPillarRadius = this.pillarRadius;
|
||||
this.renderPillarHeight = this.pillarHeight;
|
||||
this.prevRenderPillarHeight = this.pillarHeight;
|
||||
|
||||
syncHitbox();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,509 @@
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* 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 ====================
|
||||
|
||||
protected static final float MAX_ZONE_RADIUS = 64.0f;
|
||||
protected static final float MAX_ZONE_HEIGHT = 64.0f;
|
||||
protected static final double GROUND_OFFSET = 0.005;
|
||||
|
||||
// ==================== 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;
|
||||
|
||||
// ==================== 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;
|
||||
}
|
||||
|
||||
// ==================== 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.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);
|
||||
|
||||
NBTTagList effectsList = new NBTTagList();
|
||||
for (AbilityPotionEffect effect : effects) {
|
||||
effectsList.appendTag(effect.writeNBT());
|
||||
}
|
||||
nbt.setTag("Effects", effectsList);
|
||||
}
|
||||
|
||||
protected void readZoneBaseNBT(NBTTagCompound nbt) {
|
||||
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.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);
|
||||
}
|
||||
@@ -29,17 +29,7 @@ import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||
import kamkeel.npcs.developer.Developer;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
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.entity.*;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.util.BukkitUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -304,6 +294,7 @@ public class CustomNpcs {
|
||||
registerNewEntity(EntityEnergyDome.class, "energydome", 64, 3, true);
|
||||
registerNewEntity(EntityEnergyPanel.class, "energypanel", 64, 3, true);
|
||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
||||
registerNewEntity(EntityAbilityPillar.class, "abilitypillar", 64, 1, true);
|
||||
|
||||
new RecipeController();
|
||||
|
||||
|
||||
@@ -7,31 +7,11 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.client.command.CommandCNPCDebugger;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyBeam;
|
||||
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.*;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningHandler;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargePreviewManager;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
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 kamkeel.npcs.entity.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
@@ -294,6 +274,7 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyPanel.class, new RenderEnergyPanel());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySlicer.class, new RenderEnergySlicer());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyExplosion.class, new RenderEnergyExplosion());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityPillar.class, new RenderEnergyPillar());
|
||||
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityCustomNpc.class, new RenderCustomNpc());
|
||||
|
||||
|
||||
Reference in new issue
Block a user