mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 03:25:02 +00:00
Added API classes to Energy Projectile
This commit is contained in:
1 parent
7ee6c8aa53
commit
bc4f82e55f
19 files changed
+506
-541
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
|
||||
import kamkeel.npcs.controllers.data.ability.data.*;
|
||||
import kamkeel.npcs.util.AnchorPointHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -15,7 +14,6 @@ import noppes.npcs.LogWriter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Beam projectile - head with trailing path that curves with homing.
|
||||
@@ -28,13 +26,6 @@ import java.util.UUID;
|
||||
*/
|
||||
public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
|
||||
// Beam-specific movement properties
|
||||
private float speed = 0.5f;
|
||||
private boolean homing = true;
|
||||
private float homingStrength = 0.35f; // Increased from 0.15 for better tracking
|
||||
private float homingRange = 20.0f;
|
||||
private UUID siblingUUID = null;
|
||||
|
||||
// Beam shape properties
|
||||
private float beamWidth = 0.3f;
|
||||
private float headSize = 0.5f;
|
||||
@@ -59,7 +50,6 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
private int chargeDuration = 40;
|
||||
private int chargeTick = 0;
|
||||
private float chargeOffsetDistance = 1.0f;
|
||||
private EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.FRONT);
|
||||
|
||||
// Trail fading for non-anchored beams (comet effect)
|
||||
private boolean fadeTrail = false;
|
||||
@@ -112,20 +102,18 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
public EntityAbilityBeam(World world, EntityLivingBase owner, EntityLivingBase target,
|
||||
double x, double y, double z,
|
||||
float beamWidth, float headSize,
|
||||
EnergyDisplayData color, EnergyCombatData combat,
|
||||
EnergyTrajectoryData homing, EnergyLightningData lightning,
|
||||
EnergyDisplayData display, EnergyCombatData combat,
|
||||
EnergyHomingData homing, EnergyLightningData lightning,
|
||||
EnergyLifespanData lifespan,
|
||||
boolean anchoredMode) {
|
||||
super(world);
|
||||
|
||||
// Initialize base properties via parent
|
||||
initProjectile(owner, target, x, y, z, headSize, color, combat, lightning, lifespan);
|
||||
initProjectile(owner, target, x, y, z, headSize, display, combat, lightning, lifespan);
|
||||
|
||||
// Beam-specific properties from homing data
|
||||
this.speed = homing.speed;
|
||||
this.homing = homing.homing;
|
||||
this.homingStrength = homing.homingStrength;
|
||||
this.homingRange = homing.homingRange;
|
||||
|
||||
this.homingData = homing;
|
||||
this.beamWidth = beamWidth;
|
||||
this.headSize = headSize;
|
||||
|
||||
@@ -155,16 +143,16 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
double dz = target.posZ - z;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
this.motionX = (dx / len) * speed;
|
||||
this.motionY = (dy / len) * speed;
|
||||
this.motionZ = (dz / len) * speed;
|
||||
this.motionX = (dx / len) * getSpeed();
|
||||
this.motionY = (dy / len) * getSpeed();
|
||||
this.motionZ = (dz / len) * getSpeed();
|
||||
}
|
||||
} else {
|
||||
float yaw = (float) Math.toRadians(owner.rotationYaw);
|
||||
float pitch = (float) Math.toRadians(owner.rotationPitch);
|
||||
this.motionX = -Math.sin(yaw) * Math.cos(pitch) * speed;
|
||||
this.motionY = -Math.sin(pitch) * speed;
|
||||
this.motionZ = Math.cos(yaw) * Math.cos(pitch) * speed;
|
||||
this.motionX = -Math.sin(yaw) * Math.cos(pitch) * getSpeed();
|
||||
this.motionY = -Math.sin(pitch) * getSpeed();
|
||||
this.motionZ = Math.cos(yaw) * Math.cos(pitch) * getSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +168,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
this.motionZ = 0;
|
||||
}
|
||||
|
||||
public void setupPreview(EntityLivingBase owner, float beamWidth, float headSize, EnergyDisplayData color, EnergyLightningData lightning, EnergyAnchorData anchor, int chargeDuration, float chargeOffsetDistance) {
|
||||
public void setupPreview(EntityLivingBase owner, float beamWidth, float headSize, EnergyDisplayData display, EnergyLightningData lightning, EnergyAnchorData anchor, int chargeDuration, float chargeOffsetDistance) {
|
||||
this.setPreviewMode(true);
|
||||
this.setPreviewOwner(owner);
|
||||
|
||||
@@ -188,15 +176,8 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
this.beamWidth = beamWidth;
|
||||
this.headSize = headSize;
|
||||
this.size = headSize;
|
||||
this.innerColor = color.innerColor;
|
||||
this.outerColor = color.outerColor;
|
||||
this.outerColorEnabled = color.outerColorEnabled;
|
||||
this.outerColorWidth = color.outerColorWidth;
|
||||
this.outerColorAlpha = color.outerColorAlpha;
|
||||
this.rotationSpeed = color.rotationSpeed;
|
||||
this.lightningEffect = lightning.lightningEffect;
|
||||
this.lightningDensity = lightning.lightningDensity;
|
||||
this.lightningRadius = lightning.lightningRadius;
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
|
||||
// Set charging state
|
||||
this.setCharging(true);
|
||||
@@ -252,15 +233,15 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
prevPosZ = posZ;
|
||||
|
||||
// Fire forward based on owner facing direction
|
||||
Entity owner = getOwner();
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner != null) {
|
||||
float yaw = (float) Math.toRadians(owner.rotationYaw);
|
||||
float pitch = 0; // Fire horizontally
|
||||
motionX = -Math.sin(yaw) * Math.cos(pitch) * speed;
|
||||
motionY = -Math.sin(pitch) * speed;
|
||||
motionZ = Math.cos(yaw) * Math.cos(pitch) * speed;
|
||||
motionX = -Math.sin(yaw) * Math.cos(pitch) * getSpeed();
|
||||
motionY = -Math.sin(pitch) * getSpeed();
|
||||
motionZ = Math.cos(yaw) * Math.cos(pitch) * getSpeed();
|
||||
} else {
|
||||
motionX = speed;
|
||||
motionX = getSpeed();
|
||||
motionY = 0;
|
||||
motionZ = 0;
|
||||
}
|
||||
@@ -303,7 +284,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
if (fadeTrail) trailPointAges.add(0);
|
||||
|
||||
// Calculate velocity toward target (head starts at origin = startX/Y/Z)
|
||||
Entity owner = getOwner();
|
||||
Entity owner = getOwnerEntity();
|
||||
|
||||
if (target != null) {
|
||||
double dx = target.posX - startX;
|
||||
@@ -311,16 +292,16 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
double dz = target.posZ - startZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
motionX = (dx / len) * speed;
|
||||
motionY = (dy / len) * speed;
|
||||
motionZ = (dz / len) * speed;
|
||||
motionX = (dx / len) * getSpeed();
|
||||
motionY = (dy / len) * getSpeed();
|
||||
motionZ = (dz / len) * getSpeed();
|
||||
}
|
||||
} else if (owner != null) {
|
||||
float yaw = (float) Math.toRadians(owner.rotationYaw);
|
||||
float pitch = (float) Math.toRadians(owner.rotationPitch);
|
||||
motionX = -Math.sin(yaw) * Math.cos(pitch) * speed;
|
||||
motionY = -Math.sin(pitch) * speed;
|
||||
motionZ = Math.cos(yaw) * Math.cos(pitch) * speed;
|
||||
motionX = -Math.sin(yaw) * Math.cos(pitch) * getSpeed();
|
||||
motionY = -Math.sin(pitch) * getSpeed();
|
||||
motionZ = Math.cos(yaw) * Math.cos(pitch) * getSpeed();
|
||||
}
|
||||
|
||||
if (DEBUG_LOGGING && !worldObj.isRemote) {
|
||||
@@ -338,9 +319,9 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
headOffsetY * headOffsetY +
|
||||
headOffsetZ * headOffsetZ
|
||||
);
|
||||
boolean exceeded = distFromOrigin >= maxDistance;
|
||||
boolean exceeded = distFromOrigin >= getMaxDistance();
|
||||
if (exceeded && !worldObj.isRemote && DEBUG_LOGGING) {
|
||||
LogWriter.info("[Beam] DEAD: Max distance exceeded. dist=" + distFromOrigin + " max=" + maxDistance);
|
||||
LogWriter.info("[Beam] DEAD: Max distance exceeded. dist=" + distFromOrigin + " max=" + getMaxDistance());
|
||||
}
|
||||
return exceeded;
|
||||
}
|
||||
@@ -394,7 +375,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
|
||||
// Update origin if attached to owner
|
||||
if (attachedToOwner) {
|
||||
Entity owner = getOwner();
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner != null) {
|
||||
startX = owner.posX;
|
||||
startY = owner.posY + owner.getEyeHeight() * 0.7;
|
||||
@@ -438,7 +419,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
private void updateCharging() {
|
||||
chargeTick++;
|
||||
|
||||
Entity owner = getOwner();
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner == null || owner.isDead) {
|
||||
setDead();
|
||||
return;
|
||||
@@ -529,7 +510,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
|
||||
// Update origin if attached to owner
|
||||
if (attachedToOwner) {
|
||||
Entity owner = getOwner();
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner != null) {
|
||||
startX = owner.posX;
|
||||
startY = owner.posY + owner.getEyeHeight() * 0.7;
|
||||
@@ -550,9 +531,9 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
}
|
||||
|
||||
private void updateHoming() {
|
||||
if (!homing) return;
|
||||
if (!isHoming()) return;
|
||||
|
||||
Entity target = getTarget();
|
||||
Entity target = getTargetEntity();
|
||||
if (target == null || !target.isEntityAlive()) return;
|
||||
|
||||
// Calculate world position of head
|
||||
@@ -565,18 +546,18 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
double dz = target.posZ - headWorldZ;
|
||||
double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
|
||||
if (dist <= homingRange && dist > 0) {
|
||||
if (dist <= getHomingRange() && dist > 0) {
|
||||
// Calculate effective homing strength - increases when closer to commit to target
|
||||
float effectiveStrength = homingStrength;
|
||||
if (dist < homingRange * 0.3) {
|
||||
effectiveStrength = Math.min(1.0f, homingStrength * 2.5f);
|
||||
} else if (dist < homingRange * 0.6) {
|
||||
effectiveStrength = Math.min(0.8f, homingStrength * 1.5f);
|
||||
float effectiveStrength = getHomingStrength();
|
||||
if (dist < getHomingRange() * 0.3) {
|
||||
effectiveStrength = Math.min(1.0f, getHomingStrength() * 2.5f);
|
||||
} else if (dist < getHomingRange() * 0.6) {
|
||||
effectiveStrength = Math.min(0.8f, getHomingStrength() * 1.5f);
|
||||
}
|
||||
|
||||
double desiredVX = (dx / dist) * speed;
|
||||
double desiredVY = (dy / dist) * speed;
|
||||
double desiredVZ = (dz / dist) * speed;
|
||||
double desiredVX = (dx / dist) * getSpeed();
|
||||
double desiredVY = (dy / dist) * getSpeed();
|
||||
double desiredVZ = (dz / dist) * getSpeed();
|
||||
|
||||
motionX += (desiredVX - motionX) * effectiveStrength;
|
||||
motionY += (desiredVY - motionY) * effectiveStrength;
|
||||
@@ -584,9 +565,9 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
|
||||
double vLen = Math.sqrt(motionX * motionX + motionY * motionY + motionZ * motionZ);
|
||||
if (vLen > 0) {
|
||||
motionX = (motionX / vLen) * speed;
|
||||
motionY = (motionY / vLen) * speed;
|
||||
motionZ = (motionZ / vLen) * speed;
|
||||
motionX = (motionX / vLen) * getSpeed();
|
||||
motionY = (motionY / vLen) * getSpeed();
|
||||
motionZ = (motionZ / vLen) * getSpeed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -604,7 +585,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
|
||||
if (blockHit != null && blockHit.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
hasHit = true;
|
||||
if (explosive) {
|
||||
if (isExplosive()) {
|
||||
posX = blockHit.hitVec.xCoord;
|
||||
posY = blockHit.hitVec.yCoord;
|
||||
posZ = blockHit.hitVec.zCoord;
|
||||
@@ -632,7 +613,7 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
}
|
||||
hasHit = true;
|
||||
|
||||
if (explosive) {
|
||||
if (isExplosive()) {
|
||||
posX = headX;
|
||||
posY = headY;
|
||||
posZ = headZ;
|
||||
@@ -646,12 +627,6 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldIgnoreEntity(Entity entity) {
|
||||
if (entity.getPersistentID().equals(siblingUUID)) return true;
|
||||
return super.shouldIgnoreEntity(entity);
|
||||
}
|
||||
|
||||
// ==================== GETTERS FOR RENDERER ====================
|
||||
|
||||
public float getBeamWidth() {
|
||||
@@ -750,26 +725,10 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
return trailFadeTime;
|
||||
}
|
||||
|
||||
public UUID getSiblingUUID() {
|
||||
return siblingUUID;
|
||||
}
|
||||
|
||||
public void setSiblingUUID(UUID siblingUUID) {
|
||||
if (siblingUUID == null)
|
||||
return;
|
||||
|
||||
if (this.siblingUUID == null)
|
||||
this.siblingUUID = siblingUUID;
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
protected void readProjectileNBT(NBTTagCompound nbt) {
|
||||
this.speed = nbt.hasKey("Speed") ? nbt.getFloat("Speed") : 0.5f;
|
||||
this.homing = !nbt.hasKey("Homing") || nbt.getBoolean("Homing");
|
||||
this.homingStrength = nbt.hasKey("HomingStrength") ? nbt.getFloat("HomingStrength") : 0.15f;
|
||||
this.homingRange = nbt.hasKey("HomingRange") ? nbt.getFloat("HomingRange") : 20.0f;
|
||||
this.beamWidth = nbt.hasKey("BeamWidth") ? nbt.getFloat("BeamWidth") : 0.3f;
|
||||
this.headSize = nbt.hasKey("HeadSize") ? nbt.getFloat("HeadSize") : 0.5f;
|
||||
this.headOffsetX = nbt.hasKey("HeadOffsetX") ? nbt.getDouble("HeadOffsetX") : 0;
|
||||
@@ -790,7 +749,6 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
this.fadeTrail = nbt.hasKey("FadeTrail") && nbt.getBoolean("FadeTrail");
|
||||
this.trailFadeTime = nbt.hasKey("TrailFadeTime") ? nbt.getInteger("TrailFadeTime") : 20;
|
||||
|
||||
this.anchorData.readNBT(nbt);
|
||||
|
||||
// Read trail points (relative to origin)
|
||||
trailPoints.clear();
|
||||
@@ -805,16 +763,10 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
this.siblingUUID = nbt.hasKey("SiblingUUID") ? UUID.fromString(nbt.getString("SiblingUUID")) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeProjectileNBT(NBTTagCompound nbt) {
|
||||
nbt.setFloat("Speed", speed);
|
||||
nbt.setBoolean("Homing", homing);
|
||||
nbt.setFloat("HomingStrength", homingStrength);
|
||||
nbt.setFloat("HomingRange", homingRange);
|
||||
nbt.setFloat("BeamWidth", beamWidth);
|
||||
nbt.setFloat("HeadSize", headSize);
|
||||
nbt.setDouble("HeadOffsetX", headOffsetX);
|
||||
@@ -841,9 +793,5 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
trailList.appendTag(pointNbt);
|
||||
}
|
||||
nbt.setTag("Trail", trailList);
|
||||
|
||||
if (siblingUUID instanceof UUID) {
|
||||
nbt.setString("SiblingUUID", siblingUUID.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user