mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 23:09:05 +00:00
Fix some Projectile Firing
This commit is contained in:
1 parent
f818568bd3
commit
de92d57f13
7 files changed
+207
-275
No files matched your search
@@ -83,6 +83,15 @@ public class EntityAbilityBeam extends EntityEnergyProjectile {
|
||||
return Math.max(0, trailPoints.size() - trailStartIndex);
|
||||
}
|
||||
|
||||
private void resetHeadOffsets() {
|
||||
headOffsetX = 0;
|
||||
headOffsetY = 0;
|
||||
headOffsetZ = 0;
|
||||
prevHeadOffsetX = 0;
|
||||
prevHeadOffsetY = 0;
|
||||
prevHeadOffsetZ = 0;
|
||||
}
|
||||
|
||||
private void resetTrailStorage() {
|
||||
trailPoints.clear();
|
||||
trailPointAges.clear();
|
||||
@@ -135,12 +144,7 @@ public class EntityAbilityBeam extends EntityEnergyProjectile {
|
||||
setBeamMode(modeFromAnchored(anchoredMode));
|
||||
|
||||
// Initialize head offset at origin (0,0,0 relative)
|
||||
this.headOffsetX = 0;
|
||||
this.headOffsetY = 0;
|
||||
this.headOffsetZ = 0;
|
||||
this.prevHeadOffsetX = 0;
|
||||
this.prevHeadOffsetY = 0;
|
||||
this.prevHeadOffsetZ = 0;
|
||||
resetHeadOffsets();
|
||||
|
||||
// Add initial trail point at origin (relative 0,0,0)
|
||||
trailPoints.add(Vec3.createVectorHelper(0, 0, 0));
|
||||
@@ -154,79 +158,42 @@ public class EntityAbilityBeam extends EntityEnergyProjectile {
|
||||
}
|
||||
|
||||
public void setupCharging(EnergyAnchorData anchor, int chargeDuration, float chargeOffsetDistance) {
|
||||
setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
setupChargingState(anchor, chargeDuration);
|
||||
this.chargeOffsetDistance = chargeOffsetDistance;
|
||||
this.anchorData = anchor;
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
clearMotion();
|
||||
}
|
||||
|
||||
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);
|
||||
setupPreviewState(owner, display, lightning, anchor, chargeDuration);
|
||||
|
||||
// Set visual properties
|
||||
this.beamWidth = beamWidth;
|
||||
this.headSize = headSize;
|
||||
this.size = headSize;
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
setVisualSize(headSize);
|
||||
|
||||
// Set charging state
|
||||
this.setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
this.chargeOffsetDistance = chargeOffsetDistance;
|
||||
this.anchorData = anchor;
|
||||
|
||||
// Initial position at anchor point
|
||||
Vec3 pos = AnchorPointHelper.calculateAnchorPosition(owner, anchorData, chargeOffsetDistance);
|
||||
this.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
this.prevPosX = pos.xCoord;
|
||||
this.prevPosY = pos.yCoord;
|
||||
this.prevPosZ = pos.zCoord;
|
||||
this.startX = pos.xCoord;
|
||||
this.startY = pos.yCoord;
|
||||
this.startZ = pos.zCoord;
|
||||
setChargeOriginFromAnchor(owner, anchorData, chargeOffsetDistance);
|
||||
|
||||
// Initialize head offsets
|
||||
this.headOffsetX = 0;
|
||||
this.headOffsetY = 0;
|
||||
this.headOffsetZ = 0;
|
||||
this.prevHeadOffsetX = 0;
|
||||
this.prevHeadOffsetY = 0;
|
||||
this.prevHeadOffsetZ = 0;
|
||||
resetHeadOffsets();
|
||||
|
||||
// Clear motion
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
clearMotion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start preview firing (simulates firing toward a point in front of NPC).
|
||||
*/
|
||||
public void startPreviewFiring() {
|
||||
beginLookVectorLaunch(true);
|
||||
startPreviewFiringDefault();
|
||||
|
||||
// Reset head offset to origin
|
||||
headOffsetX = 0;
|
||||
headOffsetY = 0;
|
||||
headOffsetZ = 0;
|
||||
prevHeadOffsetX = 0;
|
||||
prevHeadOffsetY = 0;
|
||||
prevHeadOffsetZ = 0;
|
||||
resetHeadOffsets();
|
||||
|
||||
// Reset trail
|
||||
resetTrailStorage();
|
||||
trailPoints.add(Vec3.createVectorHelper(0, 0, 0));
|
||||
if (isFadingMode()) trailPointAges.add(0);
|
||||
|
||||
// Fire along look vector for parity with real launch behavior.
|
||||
setMotionAlongLookVectorOrFallback(getSpeed(), getSpeed(), 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,24 +201,16 @@ public class EntityAbilityBeam extends EntityEnergyProjectile {
|
||||
* Called by ability when windup ends.
|
||||
*/
|
||||
public void startFiring(EntityLivingBase target) {
|
||||
beginLookVectorLaunch(false);
|
||||
startMovingTowardTargetFromStartDefault(target);
|
||||
|
||||
// Head starts at the origin (tail position)
|
||||
headOffsetX = 0;
|
||||
headOffsetY = 0;
|
||||
headOffsetZ = 0;
|
||||
prevHeadOffsetX = 0;
|
||||
prevHeadOffsetY = 0;
|
||||
prevHeadOffsetZ = 0;
|
||||
resetHeadOffsets();
|
||||
|
||||
// Initialize trail with just the origin point
|
||||
resetTrailStorage();
|
||||
trailPoints.add(Vec3.createVectorHelper(0, 0, 0));
|
||||
if (isFadingMode()) trailPointAges.add(0);
|
||||
|
||||
// Calculate velocity toward target when provided; otherwise along look vector.
|
||||
setMotionTowardTargetOrLookVector(target, startX, startY, startZ, getSpeed(), getSpeed(), 0, 0);
|
||||
|
||||
if (DEBUG_LOGGING && !worldObj.isRemote) {
|
||||
LogWriter.info("[Beam] startFiring: origin=(" + startX + "," + startY + "," + startZ +
|
||||
") headOffset=(" + headOffsetX + "," + headOffsetY + "," + headOffsetZ +
|
||||
|
||||
@@ -94,18 +94,7 @@ public class EntityAbilityDisc extends EntityEnergyProjectile {
|
||||
* Can be fired when transitioning to active phase.
|
||||
*/
|
||||
public void setupPreview(EntityLivingBase owner, float discRadius, float discThickness, EnergyDisplayData display, EnergyLightningData lightning, EnergyAnchorData anchor, int chargeDuration, boolean vertical) {
|
||||
this.setPreviewMode(true);
|
||||
this.setPreviewOwner(owner);
|
||||
|
||||
// Set visual properties
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
|
||||
// Set charging state
|
||||
this.setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
this.anchorData = anchor;
|
||||
setupPreviewState(owner, display, lightning, anchor, chargeDuration);
|
||||
this.vertical = vertical;
|
||||
|
||||
// Store target size and start at 0 for grow effect
|
||||
@@ -113,32 +102,16 @@ public class EntityAbilityDisc extends EntityEnergyProjectile {
|
||||
this.targetDiscThickness = discThickness;
|
||||
this.discRadius = 0.01f;
|
||||
this.discThickness = 0.01f;
|
||||
this.size = 0.01f;
|
||||
this.renderCurrentSize = 0.01f;
|
||||
this.prevRenderSize = 0.01f;
|
||||
|
||||
// Initial position at anchor point
|
||||
Vec3 pos = AnchorPointHelper.calculateAnchorPosition(owner, anchorData);
|
||||
this.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
this.prevPosX = pos.xCoord;
|
||||
this.prevPosY = pos.yCoord;
|
||||
this.prevPosZ = pos.zCoord;
|
||||
this.startX = pos.xCoord;
|
||||
this.startY = pos.yCoord;
|
||||
this.startZ = pos.zCoord;
|
||||
|
||||
// Clear motion
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
setVisualSize(0.01f);
|
||||
setChargeOriginFromAnchor(owner, anchorData);
|
||||
clearMotion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start preview firing (simulates firing toward a point in front of NPC).
|
||||
*/
|
||||
public void startPreviewFiring() {
|
||||
beginLookVectorLaunch(true);
|
||||
setMotionAlongLookVectorOrFallback(getSpeed(), getSpeed(), 0, 0);
|
||||
startPreviewFiringDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,8 +119,7 @@ public class EntityAbilityDisc extends EntityEnergyProjectile {
|
||||
* Called by ability when windup ends.
|
||||
*/
|
||||
public void startMoving(EntityLivingBase target) {
|
||||
beginLookVectorLaunch(false);
|
||||
setMotionTowardTargetOrLookVector(target, posX, posY, posZ, getSpeed(), getSpeed(), 0, 0);
|
||||
startMovingTowardTargetDefault(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,6 @@ import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLightningData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyTrajectoryData;
|
||||
import kamkeel.npcs.util.AnchorPointHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -619,44 +618,39 @@ public class EntityAbilityLaser extends EntityEnergyProjectile {
|
||||
public void setupPreview(EntityLivingBase owner, float laserWidth, EnergyDisplayData display,
|
||||
EnergyLightningData lightning, EnergyAnchorData anchor, int chargeDuration,
|
||||
float expansionSpeed, float maxDistance) {
|
||||
this.setPreviewMode(true);
|
||||
this.setPreviewOwner(owner);
|
||||
setupPreviewState(owner, display, lightning, anchor, chargeDuration);
|
||||
|
||||
// Set visual properties
|
||||
// Laser-specific visual/behavior state.
|
||||
this.laserWidth = laserWidth;
|
||||
this.size = laserWidth;
|
||||
this.displayData = display;
|
||||
this.expansionSpeed = expansionSpeed;
|
||||
this.lifespanData.maxDistance = Math.min(maxDistance, 5.0f); // Limit for GUI preview
|
||||
this.lightningData = lightning;
|
||||
this.currentLength = 0.0f;
|
||||
this.fullyExtended = false;
|
||||
this.ticksSinceFullExtension = 0;
|
||||
|
||||
// Charge as an orb at the configured anchor, matching other energy projectiles.
|
||||
setupCharging(anchor, chargeDuration);
|
||||
Vec3 pos = AnchorPointHelper.calculateAnchorPosition(owner, anchorData);
|
||||
this.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
this.prevPosX = pos.xCoord;
|
||||
this.prevPosY = pos.yCoord;
|
||||
this.prevPosZ = pos.zCoord;
|
||||
this.startX = pos.xCoord;
|
||||
this.startY = pos.yCoord;
|
||||
this.startZ = pos.zCoord;
|
||||
this.endX = pos.xCoord;
|
||||
this.endY = pos.yCoord;
|
||||
this.endZ = pos.zCoord;
|
||||
// Charge as an orb from tiny size to laser width while anchored.
|
||||
this.targetSize = laserWidth;
|
||||
setVisualSize(0.01f);
|
||||
setChargeOriginFromAnchor(owner, anchorData);
|
||||
clearMotion();
|
||||
this.endX = posX;
|
||||
this.endY = posY;
|
||||
this.endZ = posZ;
|
||||
|
||||
// Precompute initial direction from owner look for launch.
|
||||
Vec3 look = owner.getLookVec();
|
||||
Vec3 look = owner == null ? null : owner.getLookVec();
|
||||
if (look == null) {
|
||||
float yaw = (float) Math.toRadians(owner.rotationYaw);
|
||||
float pitch = (float) Math.toRadians(owner.rotationPitch);
|
||||
look = Vec3.createVectorHelper(
|
||||
-Math.sin(yaw) * Math.cos(pitch),
|
||||
-Math.sin(pitch),
|
||||
Math.cos(yaw) * Math.cos(pitch)
|
||||
);
|
||||
if (owner != null) {
|
||||
float yaw = (float) Math.toRadians(owner.rotationYaw);
|
||||
float pitch = (float) Math.toRadians(owner.rotationPitch);
|
||||
look = Vec3.createVectorHelper(
|
||||
-Math.sin(yaw) * Math.cos(pitch),
|
||||
-Math.sin(pitch),
|
||||
Math.cos(yaw) * Math.cos(pitch)
|
||||
);
|
||||
} else {
|
||||
look = Vec3.createVectorHelper(1.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
this.dirX = look.xCoord;
|
||||
this.dirY = look.yCoord;
|
||||
|
||||
@@ -7,16 +7,10 @@ import kamkeel.npcs.controllers.data.ability.data.energy.EnergyHomingData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLightningData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyTrajectoryData;
|
||||
import kamkeel.npcs.util.AnchorPointHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.LogWriter;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Orb projectile - spherical homing energy ball.
|
||||
@@ -27,8 +21,6 @@ import java.util.Locale;
|
||||
public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
private static final int HOMING_STARTUP_TICKS = 4;
|
||||
private static final int HOMING_RAMP_TICKS = 8;
|
||||
private static final boolean DEBUG_ORB_FIRE_TRACE = false;
|
||||
private static final int DEBUG_TRACE_TICKS = 14;
|
||||
|
||||
public EntityAbilityOrb(World world) {
|
||||
super(world);
|
||||
@@ -59,47 +51,20 @@ public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
* Can be fired when transitioning to active phase.
|
||||
*/
|
||||
public void setupPreview(EntityLivingBase owner, float orbSize, EnergyDisplayData display, EnergyLightningData lightning, EnergyAnchorData anchor, int chargeDuration) {
|
||||
this.setPreviewMode(true);
|
||||
this.setPreviewOwner(owner);
|
||||
|
||||
// Set visual properties
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
|
||||
// Set charging state
|
||||
this.setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
this.anchorData = anchor;
|
||||
setupPreviewState(owner, display, lightning, anchor, chargeDuration);
|
||||
|
||||
// Store target size and start at 0 for grow effect
|
||||
this.targetSize = orbSize;
|
||||
this.size = 0.01f;
|
||||
this.renderCurrentSize = 0.01f;
|
||||
this.prevRenderSize = 0.01f;
|
||||
|
||||
// Initial position follows anchor helper during charging.
|
||||
Vec3 pos = AnchorPointHelper.calculateAnchorPosition(owner, anchorData);
|
||||
this.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
this.prevPosX = pos.xCoord;
|
||||
this.prevPosY = pos.yCoord;
|
||||
this.prevPosZ = pos.zCoord;
|
||||
this.startX = pos.xCoord;
|
||||
this.startY = pos.yCoord;
|
||||
this.startZ = pos.zCoord;
|
||||
|
||||
// Clear motion
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
setVisualSize(0.01f);
|
||||
setChargeOriginFromAnchor(owner, anchorData);
|
||||
clearMotion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start preview firing (simulates firing toward a point in front of NPC).
|
||||
*/
|
||||
public void startPreviewFiring() {
|
||||
beginLookVectorLaunch(true);
|
||||
setMotionAlongLookVectorOrFallback(getSpeed(), getSpeed(), 0, 0);
|
||||
startPreviewFiringDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,28 +72,7 @@ public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
* Called by ability when windup ends.
|
||||
*/
|
||||
public void startMoving(EntityLivingBase target) {
|
||||
// Launch strictly along owner's look vector using shared launch origin.
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner instanceof EntityLivingBase) {
|
||||
Vec3 look = getOwnerLookVector();
|
||||
if (look != null) {
|
||||
debugTrace("startMoving:before", look, -1.0f);
|
||||
if (beginLookVectorLaunch((EntityLivingBase) owner, look, false)) {
|
||||
debugTrace("setLaunchPosition", look, -1.0f);
|
||||
}
|
||||
motionX = look.xCoord * getSpeed();
|
||||
motionY = look.yCoord * getSpeed();
|
||||
motionZ = look.zCoord * getSpeed();
|
||||
debugTrace("startMoving:after", look, -1.0f);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback if owner is unavailable.
|
||||
setCharging(false);
|
||||
syncStartPositionToCurrent();
|
||||
setMotionAlongLookVectorOrFallback(getSpeed(), getSpeed(), 0, 0);
|
||||
debugTrace("startMoving:fallback", null, -1.0f);
|
||||
startMovingAlongLookVectorDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,17 +90,13 @@ public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
}
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
if (shouldDebugTick()) debugTrace("client:beforeInterpolation", null, -1.0f);
|
||||
handleClientInterpolation();
|
||||
if (shouldDebugTick()) debugTrace("client:afterInterpolation", null, -1.0f);
|
||||
} else {
|
||||
// Server-side logic
|
||||
if (shouldDebugTick()) debugTrace("server:beforeMovement", null, -1.0f);
|
||||
updateMovement();
|
||||
checkBlockCollision();
|
||||
checkEntityCollision();
|
||||
this.moveEntity(motionX, motionY, motionZ);
|
||||
if (shouldDebugTick()) debugTrace("server:afterMove", null, -1.0f);
|
||||
}
|
||||
|
||||
// Check wall collision
|
||||
@@ -180,11 +120,9 @@ public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
if (ticksExisted > HOMING_STARTUP_TICKS) {
|
||||
int homingTicks = ticksExisted - HOMING_STARTUP_TICKS;
|
||||
if (homingTicks >= HOMING_RAMP_TICKS) {
|
||||
if (shouldDebugTick()) debugTrace("updateMovement:homingFull", null, 1.0f);
|
||||
updateHoming();
|
||||
} else {
|
||||
float ramp = homingTicks / (float) HOMING_RAMP_TICKS;
|
||||
if (shouldDebugTick()) debugTrace("updateMovement:homingRamp", null, ramp);
|
||||
updateHomingWithRamp(ramp);
|
||||
}
|
||||
}
|
||||
@@ -235,43 +173,6 @@ public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
processEntitiesInHitBox(hitBox, nextX, nextY, nextZ);
|
||||
}
|
||||
|
||||
private boolean shouldDebugTick() {
|
||||
return DEBUG_ORB_FIRE_TRACE && !isCharging() && !previewMode && ticksExisted <= DEBUG_TRACE_TICKS;
|
||||
}
|
||||
|
||||
private void debugTrace(String stage, Vec3 look, float ramp) {
|
||||
if (!DEBUG_ORB_FIRE_TRACE || worldObj == null) return;
|
||||
|
||||
String side = worldObj.isRemote ? "CLIENT" : "SERVER";
|
||||
Entity owner = getOwnerEntity();
|
||||
String ownerInfo = owner == null
|
||||
? "null"
|
||||
: owner.getEntityId() + "@(" + fmt(owner.posX) + "," + fmt(owner.posY) + "," + fmt(owner.posZ) + ")";
|
||||
String lookInfo = look == null
|
||||
? "null"
|
||||
: "(" + fmt(look.xCoord) + "," + fmt(look.yCoord) + "," + fmt(look.zCoord) + ")";
|
||||
|
||||
LogWriter.info(
|
||||
"[OrbFireTrace][" + side + "][" + stage + "] "
|
||||
+ "id=" + getEntityId()
|
||||
+ " tick=" + ticksExisted
|
||||
+ " charging=" + isCharging()
|
||||
+ " start=(" + fmt(startX) + "," + fmt(startY) + "," + fmt(startZ) + ")"
|
||||
+ " pos=(" + fmt(posX) + "," + fmt(posY) + "," + fmt(posZ) + ")"
|
||||
+ " prev=(" + fmt(prevPosX) + "," + fmt(prevPosY) + "," + fmt(prevPosZ) + ")"
|
||||
+ " motion=(" + fmt(motionX) + "," + fmt(motionY) + "," + fmt(motionZ) + ")"
|
||||
+ " size=" + fmt(size)
|
||||
+ " speed=" + fmt(getSpeed())
|
||||
+ " ramp=" + (ramp < 0 ? "n/a" : fmt(ramp))
|
||||
+ " owner=" + ownerInfo
|
||||
+ " look=" + lookInfo
|
||||
);
|
||||
}
|
||||
|
||||
private static String fmt(double v) {
|
||||
return String.format(Locale.ROOT, "%.4f", v);
|
||||
}
|
||||
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
// Legacy getter for renderer compatibility
|
||||
|
||||
@@ -61,7 +61,6 @@ import java.util.UUID;
|
||||
* Design inspired by LouisXIV's energy attack system.
|
||||
*/
|
||||
public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
// ==================== ACTIVE PROJECTILE TRACKING ====================
|
||||
private static final Map<Integer, List<WeakReference<EntityEnergyProjectile>>> activeProjectiles = new HashMap<>();
|
||||
|
||||
@@ -380,10 +379,42 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
@Override
|
||||
public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) {
|
||||
int steps = Math.max(1, posRotationIncrements);
|
||||
double dx = x - this.posX;
|
||||
double dy = y - this.posY;
|
||||
double dz = z - this.posZ;
|
||||
double dotToCurrentMotion = dx * this.motionX + dy * this.motionY + dz * this.motionZ;
|
||||
|
||||
// Spawn-time and large correction snaps: avoid visible startup rubber-banding.
|
||||
if (worldObj != null && worldObj.isRemote) {
|
||||
double distSq = dx * dx + dy * dy + dz * dz;
|
||||
// Launch-time stale tracker packets can arrive one update late and point behind
|
||||
// an already-predicted projectile. Skipping these avoids visible backward "bounce".
|
||||
if (ticksExisted <= 24 && distSq <= 4.0D && dotToCurrentMotion < -0.0025D) {
|
||||
return;
|
||||
}
|
||||
if (ticksExisted <= 2 || distSq > 16.0D) {
|
||||
this.setPosition(x, y, z);
|
||||
syncPositionState(x, y, z, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.interpTargetX = x;
|
||||
this.interpTargetY = y;
|
||||
this.interpTargetZ = z;
|
||||
this.interpSteps = posRotationIncrements;
|
||||
if (worldObj != null && worldObj.isRemote && ticksExisted <= 24 && dotToCurrentMotion < 0.0D) {
|
||||
// Keep existing velocity when correction points opposite current travel
|
||||
// to prevent launch-time reverse lerp.
|
||||
this.interpTargetMotionX = this.motionX;
|
||||
this.interpTargetMotionY = this.motionY;
|
||||
this.interpTargetMotionZ = this.motionZ;
|
||||
} else {
|
||||
this.interpTargetMotionX = dx / steps;
|
||||
this.interpTargetMotionY = dy / steps;
|
||||
this.interpTargetMotionZ = dz / steps;
|
||||
}
|
||||
this.interpSteps = steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -815,6 +846,38 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
return positioned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default preview launch: snap to look-vector origin and fire along look.
|
||||
*/
|
||||
protected void startPreviewFiringDefault() {
|
||||
beginLookVectorLaunch(true);
|
||||
setMotionAlongLookVectorOrFallback(getSpeed(), getSpeed(), 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default active launch: snap to look-vector origin and fire toward target when available.
|
||||
*/
|
||||
protected void startMovingTowardTargetDefault(EntityLivingBase target) {
|
||||
beginLookVectorLaunch(false);
|
||||
setMotionTowardTargetOrLookVector(target, posX, posY, posZ, getSpeed(), getSpeed(), 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default active launch from fixed origin fields (used by beam-like projectiles).
|
||||
*/
|
||||
protected void startMovingTowardTargetFromStartDefault(EntityLivingBase target) {
|
||||
beginLookVectorLaunch(false);
|
||||
setMotionTowardTargetOrLookVector(target, startX, startY, startZ, getSpeed(), getSpeed(), 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default active launch strictly along look vector.
|
||||
*/
|
||||
protected void startMovingAlongLookVectorDefault() {
|
||||
beginLookVectorLaunch(false);
|
||||
setMotionAlongLookVectorOrFallback(getSpeed(), getSpeed(), 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the owner's look vector.
|
||||
* Falls back to yaw/pitch math if look vector is unavailable.
|
||||
@@ -836,7 +899,7 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared launch origin: owner position + chest height + look-vector offset.
|
||||
* Shared launch origin: owner eye position + look-vector offset.
|
||||
*
|
||||
* @param syncPositionState When true, sync prev/lastTick/interp targets to this position.
|
||||
*/
|
||||
@@ -855,7 +918,7 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
if (owner == null || look == null) return false;
|
||||
|
||||
double originX = owner.posX;
|
||||
double originY = owner.posY + owner.height * 0.7;
|
||||
double originY = owner.posY + owner.getEyeHeight();
|
||||
double originZ = owner.posZ;
|
||||
|
||||
float frontDist = computeLaunchFrontDistance(owner, look, originX, originY, originZ);
|
||||
@@ -1011,23 +1074,87 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
// ==================== CHARGING METHODS (projectile-specific) ====================
|
||||
|
||||
/**
|
||||
* Shared charging-state bootstrap used by both world and preview setup paths.
|
||||
*/
|
||||
protected void setupChargingState(EnergyAnchorData anchor, int chargeDuration) {
|
||||
setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
this.anchorData = anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared preview bootstrap used by projectile preview setup methods.
|
||||
*/
|
||||
protected void setupPreviewState(EntityLivingBase owner, EnergyDisplayData display,
|
||||
EnergyLightningData lightning, EnergyAnchorData anchor,
|
||||
int chargeDuration) {
|
||||
this.setPreviewMode(true);
|
||||
this.setPreviewOwner(owner);
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
setupChargingState(anchor, chargeDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set size and render-size state to a single value.
|
||||
*/
|
||||
protected void setVisualSize(float value) {
|
||||
this.size = value;
|
||||
this.renderCurrentSize = value;
|
||||
this.prevRenderSize = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set entity/start state to a fixed position used as charging/launch origin.
|
||||
*/
|
||||
protected void setChargeOrigin(Vec3 pos) {
|
||||
if (pos == null) return;
|
||||
this.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
this.prevPosX = pos.xCoord;
|
||||
this.prevPosY = pos.yCoord;
|
||||
this.prevPosZ = pos.zCoord;
|
||||
this.startX = pos.xCoord;
|
||||
this.startY = pos.yCoord;
|
||||
this.startZ = pos.zCoord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve and apply charging/launch origin from anchor position.
|
||||
*/
|
||||
protected void setChargeOriginFromAnchor(EntityLivingBase owner, EnergyAnchorData anchor) {
|
||||
if (owner == null || anchor == null) return;
|
||||
setChargeOrigin(AnchorPointHelper.calculateAnchorPosition(owner, anchor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve and apply charging/launch origin from anchor position with forward offset.
|
||||
*/
|
||||
protected void setChargeOriginFromAnchor(EntityLivingBase owner, EnergyAnchorData anchor, float offsetDistance) {
|
||||
if (owner == null || anchor == null) return;
|
||||
setChargeOrigin(AnchorPointHelper.calculateAnchorPosition(owner, anchor, offsetDistance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Zero current motion.
|
||||
*/
|
||||
protected void clearMotion() {
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup this entity in charging mode (for windup phase).
|
||||
* Grows from 0 to current size over chargeDuration ticks.
|
||||
* Subclasses with different charging behavior should override or use their own method.
|
||||
*/
|
||||
public void setupCharging(EnergyAnchorData anchor, int chargeDuration) {
|
||||
setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
this.anchorData = anchor;
|
||||
setupChargingState(anchor, chargeDuration);
|
||||
this.targetSize = this.size;
|
||||
this.size = 0.01f;
|
||||
this.renderCurrentSize = 0.01f;
|
||||
this.prevRenderSize = 0.01f;
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
setVisualSize(0.01f);
|
||||
clearMotion();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,50 +68,29 @@ public class EntityEnergySlicer extends EntityEnergyProjectile {
|
||||
public void setupPreview(EntityLivingBase owner, float width, float thickness,
|
||||
EnergyDisplayData display, EnergyLightningData lightning,
|
||||
EnergyAnchorData anchor, int chargeDuration) {
|
||||
this.setPreviewMode(true);
|
||||
this.setPreviewOwner(owner);
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
this.setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
this.anchorData = anchor;
|
||||
setupPreviewState(owner, display, lightning, anchor, chargeDuration);
|
||||
|
||||
this.targetSliceWidth = width;
|
||||
this.targetSliceThickness = thickness;
|
||||
this.sliceWidth = 0.01f;
|
||||
this.sliceThickness = 0.01f;
|
||||
this.size = 0.01f;
|
||||
this.renderCurrentSize = 0.01f;
|
||||
this.prevRenderSize = 0.01f;
|
||||
|
||||
Vec3 pos = kamkeel.npcs.util.AnchorPointHelper.calculateAnchorPosition(owner, anchorData);
|
||||
this.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
this.prevPosX = pos.xCoord;
|
||||
this.prevPosY = pos.yCoord;
|
||||
this.prevPosZ = pos.zCoord;
|
||||
this.startX = pos.xCoord;
|
||||
this.startY = pos.yCoord;
|
||||
this.startZ = pos.zCoord;
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
setVisualSize(0.01f);
|
||||
setChargeOriginFromAnchor(owner, anchorData);
|
||||
clearMotion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start preview firing.
|
||||
*/
|
||||
public void startPreviewFiring() {
|
||||
beginLookVectorLaunch(true);
|
||||
setMotionAlongLookVectorOrFallback(getSpeed(), getSpeed(), 0, 0);
|
||||
startPreviewFiringDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the slicer moving (exit charging mode).
|
||||
*/
|
||||
public void startMoving(EntityLivingBase target) {
|
||||
beginLookVectorLaunch(false);
|
||||
setMotionTowardTargetOrLookVector(target, posX, posY, posZ, getSpeed(), getSpeed(), 0, 0);
|
||||
startMovingTowardTargetDefault(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -292,15 +292,15 @@ public class CustomNpcs {
|
||||
registerNewEntity(EntityChairMount.class, "CustomNpcChairMount", 64, 10, false);
|
||||
registerNewEntity(EntityProjectile.class, "throwableitem", 64, 3, true);
|
||||
registerNewEntity(EntityMagicProjectile.class, "magicprojectile", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityOrb.class, "abilityorb", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityDisc.class, "abilitydisc", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityLaser.class, "abilitylaser", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityBeam.class, "abilitybeam", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityOrb.class, "abilityorb", 64, 1, true);
|
||||
registerNewEntity(EntityAbilityDisc.class, "abilitydisc", 64, 1, true);
|
||||
registerNewEntity(EntityAbilityLaser.class, "abilitylaser", 64, 1, true);
|
||||
registerNewEntity(EntityAbilityBeam.class, "abilitybeam", 64, 1, true);
|
||||
registerNewEntity(EntityAbilitySweeper.class, "abilitysweeper", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityZone.class, "abilityzone", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityDome.class, "energydome", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityPanel.class, "energypanel", 64, 3, true);
|
||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 3, true);
|
||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
||||
|
||||
new RecipeController();
|
||||
|
||||
|
||||
Reference in new issue
Block a user