mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 01:19:41 +00:00
Fix DBC Flying Issue with Abilities
This commit is contained in:
1 parent
6fdf9daf24
commit
1e45d96253
6 files changed
+42
-25
No files matched your search
@@ -30,6 +30,7 @@ public final class PlayerAbilityStatePacket extends AbstractPacket {
|
||||
public static final byte FLAG_ROTATION_LOCKED = 2;
|
||||
public static final byte FLAG_HAS_ABILITY_MOVEMENT = 4;
|
||||
public static final byte FLAG_POSITION_LOCKED = 8;
|
||||
public static final byte FLAG_WAS_FLYING_AT_LOCK = 16;
|
||||
|
||||
private byte flags;
|
||||
private float lockedYaw;
|
||||
|
||||
@@ -57,6 +57,7 @@ public abstract class AbstractDataAbilities {
|
||||
* Position lock state
|
||||
*/
|
||||
protected boolean positionLocked = false;
|
||||
protected boolean wasFlyingAtLock = false;
|
||||
protected double lockedPosX = 0;
|
||||
protected double lockedPosY = 0;
|
||||
protected double lockedPosZ = 0;
|
||||
@@ -530,6 +531,13 @@ public abstract class AbstractDataAbilities {
|
||||
lockedPosY = entity.posY;
|
||||
lockedPosZ = entity.posZ;
|
||||
positionLocked = true;
|
||||
|
||||
// Record flight state at lock time so airborne players stay at their height
|
||||
// even if their flight system deactivates during input suppression
|
||||
wasFlyingAtLock = entity instanceof net.minecraft.entity.player.EntityPlayer
|
||||
&& AbilityController.Instance != null
|
||||
&& AbilityController.Instance.isPlayerFlying((net.minecraft.entity.player.EntityPlayer) entity);
|
||||
|
||||
onPositionLockChanged(true);
|
||||
}
|
||||
|
||||
@@ -538,9 +546,17 @@ public abstract class AbstractDataAbilities {
|
||||
*/
|
||||
protected void releaseLockedPosition() {
|
||||
positionLocked = false;
|
||||
wasFlyingAtLock = false;
|
||||
onPositionLockChanged(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the entity was flying when the position lock was captured.
|
||||
*/
|
||||
public boolean wasFlyingAtLock() {
|
||||
return wasFlyingAtLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for subclass to react to position lock state changes (e.g., NPC sets data watcher flag).
|
||||
*/
|
||||
|
||||
@@ -106,9 +106,14 @@ public class ScriptPlayerEventHandler {
|
||||
if (playerData.abilityData.isMovementLocked()) {
|
||||
Ability current = playerData.abilityData.getCurrentAbility();
|
||||
if (current == null || !current.hasAbilityMovement()) {
|
||||
boolean sFlying = playerData.abilityData.wasFlyingAtLock()
|
||||
|| AbilityController.Instance.isPlayerFlying(player);
|
||||
|
||||
player.motionX = 0;
|
||||
if (!AbilityController.Instance.isPlayerFlying(player)) {
|
||||
if (!sFlying) {
|
||||
player.motionY = Math.min(player.motionY, 0);
|
||||
} else {
|
||||
player.motionY = 0;
|
||||
}
|
||||
player.motionZ = 0;
|
||||
player.velocityChanged = true;
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ClientAbilityState {
|
||||
public static boolean rotationLocked = false;
|
||||
public static boolean hasAbilityMovement = false;
|
||||
public static boolean positionLocked = false;
|
||||
public static boolean wasFlyingAtLock = false;
|
||||
public static float lockedYaw = 0;
|
||||
public static float lockedPitch = 0;
|
||||
|
||||
@@ -26,6 +27,7 @@ public class ClientAbilityState {
|
||||
rotationLocked = (flags & PlayerAbilityStatePacket.FLAG_ROTATION_LOCKED) != 0;
|
||||
hasAbilityMovement = (flags & PlayerAbilityStatePacket.FLAG_HAS_ABILITY_MOVEMENT) != 0;
|
||||
positionLocked = (flags & PlayerAbilityStatePacket.FLAG_POSITION_LOCKED) != 0;
|
||||
wasFlyingAtLock = (flags & PlayerAbilityStatePacket.FLAG_WAS_FLYING_AT_LOCK) != 0;
|
||||
lockedYaw = yaw;
|
||||
lockedPitch = pitch;
|
||||
}
|
||||
@@ -53,6 +55,7 @@ public class ClientAbilityState {
|
||||
rotationLocked = false;
|
||||
hasAbilityMovement = false;
|
||||
positionLocked = false;
|
||||
wasFlyingAtLock = false;
|
||||
lockedYaw = 0;
|
||||
lockedPitch = 0;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,6 @@ public class ClientTickHandler {
|
||||
// Only suppress when no GUI screen is open (screens already capture input).
|
||||
if (mc.currentScreen == null && ClientAbilityState.shouldSuppressMovementInput()) {
|
||||
// Unpress movement keybinds at the source BEFORE updatePlayerMoveState() reads them.
|
||||
// This is more robust than just zeroing movementInput fields, because
|
||||
// updatePlayerMoveState() reads directly from keybind pressed state.
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindForward.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindBack.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindLeft.getKeyCode(), false);
|
||||
@@ -91,7 +89,6 @@ public class ClientTickHandler {
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindSneak.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindSprint.getKeyCode(), false);
|
||||
|
||||
// Also zero the movementInput values directly as a safety net
|
||||
mc.thePlayer.movementInput.moveForward = 0;
|
||||
mc.thePlayer.movementInput.moveStrafe = 0;
|
||||
mc.thePlayer.movementInput.jump = false;
|
||||
@@ -128,17 +125,20 @@ public class ClientTickHandler {
|
||||
mc.thePlayer.movementInput.jump = false;
|
||||
mc.thePlayer.movementInput.sneak = false;
|
||||
|
||||
// Zero horizontal motion (unless ability provides its own movement)
|
||||
// Zero all motion — position lock holds the player in place (server is authoritative)
|
||||
if (!ClientAbilityState.hasAbilityMovement) {
|
||||
mc.thePlayer.motionX = 0;
|
||||
mc.thePlayer.motionZ = 0;
|
||||
}
|
||||
|
||||
// Prevent jumping when locked (allow gravity only if not flying)
|
||||
// Zero vertical motion: grounded players can't jump, flying players are frozen in air
|
||||
if ((ClientAbilityState.movementLocked || ClientAbilityState.positionLocked)
|
||||
&& !ClientAbilityState.hasAbilityMovement
|
||||
&& !AbilityController.Instance.isPlayerFlying(mc.thePlayer)) {
|
||||
mc.thePlayer.motionY = Math.min(mc.thePlayer.motionY, 0);
|
||||
&& !ClientAbilityState.hasAbilityMovement) {
|
||||
if (ClientAbilityState.wasFlyingAtLock) {
|
||||
mc.thePlayer.motionY = 0;
|
||||
} else {
|
||||
mc.thePlayer.motionY = Math.min(mc.thePlayer.motionY, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -798,23 +798,12 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
private void applyPositionLock(EntityPlayer player) {
|
||||
if (!positionLocked) return;
|
||||
|
||||
boolean flying = AbilityController.Instance != null
|
||||
&& AbilityController.Instance.isPlayerFlying(player);
|
||||
|
||||
if (flying) {
|
||||
// Flying players: lock X/Z only, preserve Y freedom
|
||||
player.setPosition(lockedPosX, player.posY, lockedPosZ);
|
||||
player.prevPosX = lockedPosX;
|
||||
player.prevPosZ = lockedPosZ;
|
||||
} else {
|
||||
// Grounded players: full position lock including Y
|
||||
player.setPosition(lockedPosX, lockedPosY, lockedPosZ);
|
||||
player.prevPosX = lockedPosX;
|
||||
player.prevPosY = lockedPosY;
|
||||
player.prevPosZ = lockedPosZ;
|
||||
player.motionY = 0;
|
||||
}
|
||||
player.setPosition(lockedPosX, lockedPosY, lockedPosZ);
|
||||
player.prevPosX = lockedPosX;
|
||||
player.prevPosY = lockedPosY;
|
||||
player.prevPosZ = lockedPosZ;
|
||||
player.motionX = 0;
|
||||
player.motionY = 0;
|
||||
player.motionZ = 0;
|
||||
}
|
||||
|
||||
@@ -841,6 +830,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (positionLocked) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_POSITION_LOCKED;
|
||||
}
|
||||
if (wasFlyingAtLock) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_WAS_FLYING_AT_LOCK;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user