Merge remote-tracking branch 'origin/syntax-highlighter-unified' into syntax-highlighter-unified

This commit is contained in:
bigguy345 committed 2026-03-09 00:38:08 +02:00
commit 879dca7391
14 files changed
+220 -168

No files matched your search

@@ -785,6 +785,9 @@ public abstract class AbstractDataAbilities {
// Fire tick event
fireTickEvent(currentAbility, target);
// Script may have completed/cancelled the ability during the tick event
if (currentAbility == null || !currentAbility.isExecuting()) return;
// Fire extender tick hook (e.g., per-tick resource drain)
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target,
currentAbility.getPhase(), currentAbility.getCurrentTick())) {
+69 -26
View File
@@ -88,7 +88,11 @@ public class DataAbilities extends AbstractDataAbilities {
*/
private transient boolean hitScanActive = false;
private transient EntityLivingBase hitScanTarget = null;
private transient float currentTrackDelay = 0;
private transient float currentTrackSpeed = 0;
private transient float trackedYaw = 0;
private transient float trackedPitch = 0;
private transient boolean trackLerpedThisTick = false;
private transient boolean preserveTrackedRotation = false;
/**
* Bit flag for rotation control (LOCKED or TRACK) in data watcher slot 15
@@ -219,19 +223,28 @@ public class DataAbilities extends AbstractDataAbilities {
@Override
protected void onPreExecute(Ability ability, EntityLivingBase target) {
// Snap NPC to face target before execute so startMoving() reads correct rotation
// Face target before execute so startMoving() reads correct rotation
// Use trackSpeed so the NPC plays catchup rather than instant-snapping
if (ability.isHitScanForCurrentPhase() && target != null) {
faceTarget(target);
float speed = ability.getTrackSpeed();
if (speed <= 0) {
faceTarget(target);
} else {
faceTarget(target, speed);
}
}
}
@Override
protected void onPostPhaseTick(Ability ability, EntityLivingBase target) {
// Reset per-tick lerp flag so faceTarget only computes the lerp once per tick
trackLerpedThisTick = false;
// Update hit scan state - actual facing is deferred to applyRotationControl()
// which runs AFTER super.onLivingUpdate() to override AI look helper
if (ability != null && ability.isExecuting() && target != null) {
if (ability.isHitScanForCurrentPhase()) {
enableHitScan(target, ability.getTrackDelay());
enableHitScan(target, ability.getTrackSpeed());
} else {
// Release hit scan if it was previously active
if (hitScanActive) {
@@ -254,7 +267,10 @@ public class DataAbilities extends AbstractDataAbilities {
@Override
protected void onBurstDelayReleaseLocks() {
if (hitScanActive) releaseRotationControl();
if (hitScanActive) {
preserveTrackedRotation = true;
releaseRotationControl();
}
}
@Override
@@ -881,31 +897,44 @@ public class DataAbilities extends AbstractDataAbilities {
/**
* Enable hit scan tracking for the given target.
*/
private void enableHitScan(EntityLivingBase target, float trackDelay) {
private void enableHitScan(EntityLivingBase target, float trackSpeed) {
if (!hitScanActive) {
hitScanActive = true;
npc.setBoolFlag(true, ROTATION_CONTROLLED_FLAG);
// Preserve tracked rotation across burst delays so the NPC doesn't snap
if (!preserveTrackedRotation) {
trackedYaw = npc.rotationYawHead;
trackedPitch = npc.rotationPitch;
}
preserveTrackedRotation = false;
}
hitScanTarget = target;
currentTrackDelay = trackDelay;
currentTrackSpeed = trackSpeed;
}
private static final double DEG_TO_RAD = Math.PI / 180.0;
private static final double RAD_TO_DEG = 180.0 / Math.PI;
/**
* Face the target with optional track delay.
* When trackDelay <= 0, snaps instantly (legacy behavior).
* When trackDelay > 0, lerps toward the target each tick.
* Face the target with optional track speed (linear speed in blocks/second).
* When trackSpeed <= 0, snaps instantly.
* When trackSpeed > 0, the NPC's aim point moves at trackSpeed blocks/second,
* converted to angular velocity based on distance. This makes tracking feel
* consistent regardless of range — directly comparable to player movement speed.
*/
private void faceTarget(EntityLivingBase target, float trackDelay) {
private void faceTarget(EntityLivingBase target, float trackSpeed) {
double dx = target.posX - npc.posX;
double dz = target.posZ - npc.posZ;
double dy = (target.posY + target.getEyeHeight() * 0.5) - (npc.posY + npc.getEyeHeight());
double distXZ = Math.sqrt(dx * dx + dz * dz);
float targetYaw = (float) (Math.atan2(-dx, dz) * 180.0 / Math.PI);
float targetPitch = (float) (-(Math.atan2(dy, distXZ)) * 180.0 / Math.PI);
float targetYaw = (float) (Math.atan2(-dx, dz) * RAD_TO_DEG);
float targetPitch = (float) (-(Math.atan2(dy, distXZ)) * RAD_TO_DEG);
if (trackDelay <= 0) {
// Instant snap (legacy behavior)
if (trackSpeed <= 0) {
// Instant snap
trackedYaw = targetYaw;
trackedPitch = targetPitch;
npc.rotationYaw = targetYaw;
npc.rotationYawHead = targetYaw;
npc.renderYawOffset = targetYaw;
@@ -915,14 +944,28 @@ public class DataAbilities extends AbstractDataAbilities {
npc.prevRenderYawOffset = targetYaw;
npc.prevRotationPitch = targetPitch;
} else {
float lerpFactor = 1.0f / (1.0f + trackDelay);
if (!trackLerpedThisTick) {
trackLerpedThisTick = true;
// Wrap yaw difference to [-180, 180] for correct interpolation
float yawDiff = wrapAngle(targetYaw - npc.rotationYawHead);
float pitchDiff = targetPitch - npc.rotationPitch;
// Convert linear speed (blocks/sec) to angular speed (degrees/tick)
// using the actual distance to the target
double dist = Math.max(1.0, Math.sqrt(dx * dx + dy * dy + dz * dz));
float blocksPerTick = trackSpeed / 20.0f;
float maxAngularSpeed = (float) (Math.atan2(blocksPerTick, dist) * RAD_TO_DEG);
float newYaw = npc.rotationYawHead + yawDiff * lerpFactor;
float newPitch = npc.rotationPitch + pitchDiff * lerpFactor;
float yawDiff = wrapAngle(targetYaw - trackedYaw);
float pitchDiff = targetPitch - trackedPitch;
float totalAngle = (float) Math.sqrt(yawDiff * yawDiff + pitchDiff * pitchDiff);
if (totalAngle > maxAngularSpeed) {
float scale = maxAngularSpeed / totalAngle;
yawDiff *= scale;
pitchDiff *= scale;
}
trackedYaw = trackedYaw + yawDiff;
trackedPitch = trackedPitch + pitchDiff;
}
// Set prev to current before updating (for smooth client interpolation)
npc.prevRotationYaw = npc.rotationYaw;
@@ -930,10 +973,10 @@ public class DataAbilities extends AbstractDataAbilities {
npc.prevRenderYawOffset = npc.renderYawOffset;
npc.prevRotationPitch = npc.rotationPitch;
npc.rotationYaw = newYaw;
npc.rotationYawHead = newYaw;
npc.renderYawOffset = newYaw;
npc.rotationPitch = newPitch;
npc.rotationYaw = trackedYaw;
npc.rotationYawHead = trackedYaw;
npc.renderYawOffset = trackedYaw;
npc.rotationPitch = trackedPitch;
}
}
@@ -976,7 +1019,7 @@ public class DataAbilities extends AbstractDataAbilities {
// Server: apply the appropriate rotation
if (hitScanActive && hitScanTarget != null && !hitScanTarget.isDead) {
faceTarget(hitScanTarget, currentTrackDelay);
faceTarget(hitScanTarget, currentTrackSpeed);
} else if (rotationLocked) {
npc.rotationYaw = lockedYaw;
npc.rotationYawHead = lockedYawHead;
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityBeam;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyBeam;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyBeam<T extends EntityAbilityBeam> extends ScriptEnergyProjectile<T> implements IEnergyBeam {
@@ -60,27 +59,7 @@ public class ScriptEnergyBeam<T extends EntityAbilityBeam> extends ScriptEnergyP
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startFiring(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startFiring(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startFiring(target);
}
}
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityDisc;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyDisc;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyDisc<T extends EntityAbilityDisc> extends ScriptEnergyProjectile<T> implements IEnergyDisc {
@@ -76,27 +75,7 @@ public class ScriptEnergyDisc<T extends EntityAbilityDisc> extends ScriptEnergyP
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startMoving(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
}
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityLaser;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyLaser;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnergyProjectile<T> implements IEnergyLaser {
@@ -92,18 +91,12 @@ public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnerg
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
@@ -111,6 +104,6 @@ public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnerg
if (len > 0) {
entity.setDirection(dx / len, dy / len, dz / len);
}
entity.startMoving(null);
ensureSpawned();
}
}
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityOrb;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyOrb;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyOrb<T extends EntityAbilityOrb> extends ScriptEnergyProjectile<T> implements IEnergyOrb {
@@ -28,27 +27,7 @@ public class ScriptEnergyOrb<T extends EntityAbilityOrb> extends ScriptEnergyPro
}
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startMoving(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
}
@@ -1,7 +1,6 @@
package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityEnergyProjectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.EventHooks;
import noppes.npcs.api.entity.IEnergyProjectile;
@@ -261,8 +260,14 @@ public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends Sc
public void fireAt(IEntity target) {
if (target != null) {
Entity mcTarget = target.getMCEntity();
setMotionToward(mcTarget.posX, mcTarget.posY + mcTarget.getEyeHeight(), mcTarget.posZ);
EntityLivingBase living = resolveLivingTarget(target);
if (living != null) {
entity.setTargetEntityId(living.getEntityId());
setMotionToward(living.posX, living.posY + living.getEyeHeight(), living.posZ);
} else {
net.minecraft.entity.Entity mcTarget = target.getMCEntity();
setMotionToward(mcTarget.posX, mcTarget.posY + mcTarget.getEyeHeight(), mcTarget.posZ);
}
}
ensureSpawned();
}
@@ -273,24 +278,22 @@ public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends Sc
}
public void fireDirection(float yaw, float pitch) {
float yawRad = (float) Math.toRadians(yaw);
float pitchRad = (float) Math.toRadians(pitch);
entity.motionX = -Math.sin(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
entity.motionY = -Math.sin(pitchRad) * entity.getSpeed();
entity.motionZ = Math.cos(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
setMotionFromDirection(yaw, pitch);
ensureSpawned();
}
public void fireFrom(IEntityLivingBase caster) {
if (caster == null) return;
initFromCaster(caster);
fireDirection(caster.getRotation(), caster.getPitch());
launchFromOwner(null);
ensureSpawned();
}
public void fireFrom(IEntityLivingBase caster, IEntity target) {
if (caster == null) return;
initFromCaster(caster);
fireAt(target);
launchFromOwner(resolveLivingTarget(target));
ensureSpawned();
}
/**
@@ -304,6 +307,37 @@ public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends Sc
entity.setStartPosition(mc.posX, eyeY, mc.posZ);
}
/**
* Hook for subclasses to call their entity's full launch sequence (startMoving/startFiring).
* Called by fireFrom methods — handles look-vector snap, charge exit, homing init, etc.
* Default: sets motion toward target, or along owner's look direction if target is null.
*/
protected void launchFromOwner(EntityLivingBase target) {
if (target != null) {
setMotionToward(target.posX, target.posY + target.getEyeHeight(), target.posZ);
} else {
net.minecraft.entity.Entity owner = entity.getOwnerEntity();
if (owner != null) {
setMotionFromDirection(owner.rotationYaw, owner.rotationPitch);
}
}
}
private void setMotionFromDirection(float yaw, float pitch) {
float yawRad = (float) Math.toRadians(yaw);
float pitchRad = (float) Math.toRadians(pitch);
entity.motionX = -Math.sin(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
entity.motionY = -Math.sin(pitchRad) * entity.getSpeed();
entity.motionZ = Math.cos(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
}
protected static EntityLivingBase resolveLivingTarget(IEntity target) {
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
return (EntityLivingBase) target.getMCEntity();
}
return null;
}
/**
* Calculates and sets motion from the projectile's current position toward a target point.
*/
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityEnergySlicer;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergySlicer;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergySlicer<T extends EntityEnergySlicer> extends ScriptEnergyProjectile<T> implements IEnergySlicer {
@@ -48,27 +47,7 @@ public class ScriptEnergySlicer<T extends EntityEnergySlicer> extends ScriptEner
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startMoving(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
}