Better Fix to Lock Movement and Rotation Locking during Abilities. Fix Interupting on Projectile Abilities

This commit is contained in:
Kam committed 2026-02-04 14:48:54 -05:00
1 parent 86055202a9
commit 326626ad8e
26 files changed
+266 -51

No files matched your search

+52 -9
View File
@@ -18,6 +18,7 @@ import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.AbilityEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -147,10 +148,15 @@ public class DataAbilities {
// Remove telegraph - it has served its purpose
removeTelegraph(currentAbility);
// Lock rotation if movement is locked during ACTIVE phase
// Capture current rotation values to force them every tick
if (currentAbility.isMovementLockedDuringActive()) {
captureLockedRotation();
// Handle rotation lock transition from WINDUP to ACTIVE
if (currentAbility.isRotationLockedDuringActive()) {
// ACTIVE or WINDUP_AND_ACTIVE: capture (or keep) rotation lock
if (!rotationLocked) {
captureLockedRotation();
}
} else if (rotationLocked) {
// WINDUP only: release the lock now that windup is over
releaseLockedRotation();
}
// Play active sound and animation
@@ -390,6 +396,9 @@ public class DataAbilities {
executeImmediate(ability, target);
} else {
// Normal windup flow
if (ability.isRotationLockedDuringWindup()) {
captureLockedRotation();
}
spawnTelegraph(ability, target);
playAbilitySound(ability.getWindUpSound());
playAbilityAnimation(ability.getWindUpAnimation());
@@ -403,8 +412,8 @@ public class DataAbilities {
* Called when windUpTicks is 0.
*/
private void executeImmediate(Ability ability, EntityLivingBase target) {
// Lock rotation if movement is locked during ACTIVE phase
if (ability.isMovementLockedDuringActive()) {
// Lock rotation if rotation is locked during ACTIVE phase
if (ability.isRotationLockedDuringActive()) {
captureLockedRotation();
}
@@ -934,9 +943,12 @@ public class DataAbilities {
// ROTATION LOCKING
// ═══════════════════════════════════════════════════════════════════
/** Bit flag for rotation lock in the existing data watcher slot 15 bitfield */
private static final int ROTATION_LOCKED_FLAG = 16;
/**
* Capture current rotation values to lock NPC's look direction.
* Called when entering ACTIVE phase with movement locked during active.
* Called when entering a locked phase (WINDUP or ACTIVE depending on LockMovementType).
*/
private void captureLockedRotation() {
lockedYaw = npc.rotationYaw;
@@ -944,22 +956,53 @@ public class DataAbilities {
lockedRenderYawOffset = npc.renderYawOffset;
lockedPitch = npc.rotationPitch;
rotationLocked = true;
npc.setBoolFlag(true, ROTATION_LOCKED_FLAG);
}
/**
* Release the rotation lock.
* Called when leaving ACTIVE phase or ability completes.
* Called when leaving the locked phase or ability completes.
*/
private void releaseLockedRotation() {
rotationLocked = false;
npc.setBoolFlag(false, ROTATION_LOCKED_FLAG);
}
/**
* Apply locked rotation values to the NPC.
* Called AFTER super.onLivingUpdate() in EntityNPCInterface to override
* any rotation changes made by the look helper or AI tasks.
* any rotation changes made by the look helper, AI tasks, or body smoothing.
* Runs on both client and server.
*/
public void applyLockedRotation() {
if (npc.worldObj.isRemote) {
// Client-side: check bit 16 in the existing flags data watcher (slot 15)
boolean flagActive = npc.getBoolFlag(ROTATION_LOCKED_FLAG);
if (!flagActive) {
rotationLocked = false;
return;
}
// First tick the flag is active: capture current rotation values
if (!rotationLocked) {
lockedYaw = npc.rotationYaw;
lockedYawHead = npc.rotationYawHead;
lockedRenderYawOffset = npc.renderYawOffset;
lockedPitch = npc.rotationPitch;
rotationLocked = true;
}
// Force all rotation values back to locked state
npc.rotationYaw = lockedYaw;
npc.rotationYawHead = lockedYawHead;
npc.renderYawOffset = lockedRenderYawOffset;
npc.rotationPitch = lockedPitch;
npc.prevRotationYaw = lockedYaw;
npc.prevRotationYawHead = lockedYawHead;
npc.prevRenderYawOffset = lockedRenderYawOffset;
npc.prevRotationPitch = lockedPitch;
return;
}
// Server-side: use stored locked values
if (!rotationLocked) {
return;
}
@@ -93,7 +93,9 @@ public class EntityAIAmbushTarget extends EntityAIBase {
* Updates the task
*/
public void updateTask() {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
if (!this.theEntity.abilities.isRotationLocked()) {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
}
}
private Vec3 findHidingSpot() {
@@ -118,7 +118,9 @@ public class EntityAIAttackTarget extends EntityAIBase {
* Updates the task
*/
public void updateTask() {
this.npc.getLookHelper().setLookPositionWithEntity(this.entityTarget, 30.0F, 30.0F);
if (!this.npc.abilities.isRotationLocked()) {
this.npc.getLookHelper().setLookPositionWithEntity(this.entityTarget, 30.0F, 30.0F);
}
// Skip pathfinding updates if ability is controlling movement
if (!navOverride && !this.npc.abilities.isAbilityControllingMovement() && --this.field_75445_i <= 0) {
@@ -63,7 +63,7 @@ public class EntityAIDodgeShoot extends EntityAIBase {
* Updates the task
*/
public void updateTask() {
if (this.entity.getAttackTarget() != null)
if (this.entity.getAttackTarget() != null && !this.entity.abilities.isRotationLocked())
this.entity.getLookHelper().setLookPositionWithEntity(this.entity.getAttackTarget(), 30.0F, 30.0F);
}
}
@@ -55,7 +55,9 @@ public class EntityAIFollow extends EntityAIBase {
if (updateTick < 10)
return;
updateTick = 0;
this.npc.getLookHelper().setLookPositionWithEntity(owner, 10.0F, (float) this.npc.getVerticalFaceSpeed());
if (!this.npc.abilities.isRotationLocked()) {
this.npc.getLookHelper().setLookPositionWithEntity(owner, 10.0F, (float) this.npc.getVerticalFaceSpeed());
}
double speed = 1 + distance / 150;
if (speed > 3)
@@ -26,7 +26,7 @@ public class EntityAILook extends EntityAIBase {
*/
@Override
public boolean shouldExecute() {
return !npc.isAttacking() && npc.getNavigator().noPath() && !npc.isPlayerSleeping() && npc.isEntityAlive();
return !npc.abilities.isRotationLocked() && !npc.isAttacking() && npc.getNavigator().noPath() && !npc.isPlayerSleeping() && npc.isEntityAlive();
}
/**
@@ -91,7 +91,9 @@ public class EntityAIOrbitTarget extends EntityAIBase {
* Updates the task
*/
public void updateTask() {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
if (!this.theEntity.abilities.isRotationLocked()) {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
}
if (this.theEntity.getNavigator().noPath() && this.tick >= 0) {
if (this.theEntity.onGround && !this.theEntity.isInWater()) {
double d0 = this.targetDistance * (double) (MathHelper.cos(angle / 180.0F * (float) Math.PI));
@@ -100,7 +100,9 @@ public class EntityAIRangedAttack extends EntityAIBase {
* Updates the task
*/
public void updateTask() {
this.entityHost.getLookHelper().setLookPositionWithEntity(this.attackTarget, 30.0F, 30.0F);
if (!this.entityHost.abilities.isRotationLocked()) {
this.entityHost.getLookHelper().setLookPositionWithEntity(this.attackTarget, 30.0F, 30.0F);
}
double var1 = this.entityHost.getDistanceSq(this.attackTarget.posX, this.attackTarget.boundingBox.minY, this.attackTarget.posZ);
float field_82642_h = this.entityHost.stats.rangedRange * this.entityHost.stats.rangedRange;
@@ -68,7 +68,9 @@ public class EntityAIStalkTarget extends EntityAIBase {
* Updates the task
*/
public void updateTask() {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
if (!this.theEntity.abilities.isRotationLocked()) {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
}
if (this.theEntity.getNavigator().noPath() || this.overRide) {
if (this.isLookingAway()) {
@@ -31,7 +31,7 @@ public class EntityAIWatchClosest extends EntityAIBase {
*/
@Override
public boolean shouldExecute() {
if (this.theWatcher.getRNG().nextFloat() >= this.field_75331_e || theWatcher.isInteracting()) {
if (this.theWatcher.abilities.isRotationLocked() || this.theWatcher.getRNG().nextFloat() >= this.field_75331_e || theWatcher.isInteracting()) {
return false;
} else {
if (this.theWatcher.getAttackTarget() != null) {
@@ -8,6 +8,7 @@ import net.minecraft.pathfinding.PathPoint;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import noppes.npcs.constants.AiMutex;
import noppes.npcs.entity.EntityNPCInterface;
public class EntityAIZigZagTarget extends EntityAIBase {
private EntityCreature theEntity;
@@ -82,6 +83,8 @@ public class EntityAIZigZagTarget extends EntityAIBase {
* Updates the task
*/
public void updateTask() {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
if (!(this.theEntity instanceof EntityNPCInterface) || !((EntityNPCInterface) this.theEntity).abilities.isRotationLocked()) {
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
}
}
}
@@ -1693,7 +1693,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
}
/**
* 1: walking, 2:interacting, 4:attacking, 8:killed
* 1: walking, 2:interacting, 4:attacking, 8:killed, 16:rotationLocked
*/
public boolean getBoolFlag(int id) {
return (dataWatcher.getWatchableObjectInt(15) & id) != 0;