Refine mount GUI layout and flight handling

This commit is contained in:
Kam committed 2025-11-07 22:44:22 -05:00
1 parent 9744209938
commit c33ac04d11
4 files changed
+63 -9

No files matched your search

@@ -4,7 +4,6 @@ import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.role.RoleSavePacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.util.GuiNPCInterface2;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
@@ -31,7 +30,7 @@ public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener
}
int leftLabelX = guiLeft + 4;
int leftFieldX = guiLeft + 140;
int leftFieldX = guiLeft + 116;
int leftY = guiTop + 6;
leftY = addOffsetRow(0, 10, "role.mount.offsetx", role.getOffsetX(), leftLabelX, leftFieldX, leftY);
@@ -43,10 +42,6 @@ public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener
addButton(new GuiNpcButton(101, leftFieldX, leftY, 60, 20, new String[]{"gui.no", "gui.yes"}, role.isSprintAllowed() ? 1 : 0));
leftY += 24;
GuiNpcLabel speedLabel = new GuiNpcLabel(5, "", leftLabelX, leftY + 5);
speedLabel.label = StatCollector.translateToLocalFormatted("role.mount.walkspeed", npc.ais.getWalkingSpeed());
addLabel(speedLabel);
int rightLabelX = guiLeft + 214;
int rightFieldX = guiLeft + 320;
int rightY = guiTop + 6;
@@ -107,6 +107,8 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
return;
}
boolean flightModeActive = isMountFlightModeActive();
boolean aboveLimit = false;
double heightOffGround = this.posY - this.worldObj.getTopSolidOrLiquidBlock((int) this.posX, (int) this.posZ);
if (heightOffGround < 0) {
@@ -132,6 +134,12 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
this.flyLimitAllow = true;
setNpcFlyingState(true);
if (flightModeActive) {
super.performMountedMovement(strafe, forward, moveSpeed);
this.velocityChanged = true;
return;
}
double d3 = this.motionY;
super.performMountedMovement(strafe, forward, moveSpeed);
this.motionY = d3;
@@ -2128,11 +2128,59 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
public void performMountedMovement(float strafe, float forward, float moveSpeed) {
this.moveStrafing = strafe;
this.moveForward = forward;
if (!worldObj.isRemote) {
this.setAIMoveSpeed(moveSpeed);
super.moveEntityWithHeading(strafe, forward);
if (isMountFlightModeActive()) {
performMountedFlightMovement(strafe, forward, moveSpeed);
return;
}
if (!worldObj.isRemote) {
this.setAIMoveSpeed(moveSpeed);
}
super.moveEntityWithHeading(strafe, forward);
updateMountedLimbSwing();
}
protected boolean isMountFlightModeActive() {
return NPCMountUtil.isMountInFlightMode(mountState);
}
private void performMountedFlightMovement(float strafe, float forward, float moveSpeed) {
if (!worldObj.isRemote) {
this.setAIMoveSpeed(moveSpeed);
}
float inputMagnitude = MathHelper.sqrt_float(strafe * strafe + forward * forward);
if (inputMagnitude < 1.0E-3F) {
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
if (Math.abs(this.motionX) < 0.003D) {
this.motionX = 0.0D;
}
if (Math.abs(this.motionZ) < 0.003D) {
this.motionZ = 0.0D;
}
} else {
float normStrafe = strafe / inputMagnitude;
float normForward = forward / inputMagnitude;
float yawRad = this.rotationYaw * (float) Math.PI / 180.0F;
double sinYaw = Math.sin(yawRad);
double cosYaw = Math.cos(yawRad);
double targetMotionX = (normStrafe * cosYaw - normForward * sinYaw) * moveSpeed;
double targetMotionZ = (normForward * cosYaw + normStrafe * sinYaw) * moveSpeed;
this.motionX = targetMotionX;
this.motionZ = targetMotionZ;
}
this.moveEntity(this.motionX, this.motionY, this.motionZ);
this.velocityChanged = true;
if (!this.onGround) {
this.isAirBorne = true;
}
updateMountedLimbSwing();
}
private void updateMountedLimbSwing() {
this.prevLimbSwingAmount = this.limbSwingAmount;
double deltaX = this.posX - this.prevPosX;
double deltaZ = this.posZ - this.prevPosZ;
@@ -236,6 +236,9 @@ public final class NPCMountUtil {
npc.setNpcJumpingState(false);
return;
}
if (npc.canFly()) {
return;
}
if (npc.onGround) {
npc.motionY = 0.0D;
npc.setNpcFlyingState(false);