Skip to content

Fix angle wrapping in lookAt to prevent large packet deltas#7

Merged
EastArctica merged 5 commits intomainfrom
copilot/fix-lookat-pitch-wrapping
Jan 19, 2026
Merged

Fix angle wrapping in lookAt to prevent large packet deltas#7
EastArctica merged 5 commits intomainfrom
copilot/fix-lookat-pitch-wrapping

Conversation

Copy link

Copilot AI commented Jan 15, 2026

The lookAt method used Mth.wrapDegrees naively without considering previous rotation values, causing large packet deltas when angles crossed the wrap boundary (e.g., 179° → -179° = 358° delta instead of 2°).

Changes

  • Added safeWrapDegrees helper method: Wraps target angle relative to previous angle by computing the delta, wrapping it to [-180°, 180°], then adding back to previous value
  • Updated lookAt to use safe wrapping: Both yaw and pitch now wrapped relative to their previous values (base.yRotO, base.xRotO) before being set, with pitch additionally clamped to [-90°, 90°]

Example

// Before: naive wrapping could cause 358° delta
base.setYRot(Mth.wrapDegrees(180f));  // when current is -179°

// After: safe wrapping produces 2° delta
float safeYaw = safeWrapDegrees(-179f, 180f);  // returns 181° (equivalent to -179°)

The wrapping strategy ensures angles sent to the server are equivalent to the target but minimize the delta from the previous tick.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • ldtteam.jfrog.io
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx4G -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14-bin/38aieal9i53h9rfe7vjup95b9/gradle-8.14/lib/gradle-daemon-main-8.14.jar (dns block)
  • maven.kikugie.dev
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx4G -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.14-bin/38aieal9i53h9rfe7vjup95b9/gradle-8.14/lib/gradle-daemon-main-8.14.jar (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Pitch values are incorrectly wrapped in lookAt</issue_title>
<issue_description>Currently in ClientPlayerEntityHelper.java's lookAt method, we use MathHelper.wrapDegrees to wrap around. This method naively wraps the degrees as it does not know the previous value.

This can be fixed via updating the implementation here to properly utilize the prevPitch value we set.

    /**
     * Wraps {@code targetYaw} into an equivalent angle that is
     * closest to {@code lastYaw}, preventing large packet deltas.
     *
     * @param lastYaw the yaw last sent to the server
     * @param targetYaw the desired logical yaw
     * @return a yaw value safe to send this tick
     */
    private static float safeWrapDegrees(float lastYaw, float targetYaw) {
        float delta = MathHelper.wrapDegrees(targetYaw - lastYaw);
        return lastYaw + delta;
    }

    /**
     * @param yaw (was pitch prior to 1.2.6)
     * @param pitch (was yaw prior to 1.2.6)
     * @return self for chaining.
     * @since 1.0.3
     */
    public ClientPlayerEntityHelper<T> lookAt(double yaw, double pitch) {
        base.prevYaw = base.getYaw();
        base.prevPitch = base.getPitch();

        float safeYaw = safeWrapDegrees(base.prevYaw, (float) yaw);
        float safePitch = MathHelper.clamp((float) pitch, -90.0F, 90.0F);

        base.setYaw(safeYaw);
        base.setPitch(safePitch);

        if (base.getVehicle() != null) {
            base.getVehicle().onPassengerLookAround(base);
        }

        return this;
    }
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 3 commits January 15, 2026 04:00
Co-authored-by: EastArctica <32211444+EastArctica@users.noreply.github.com>
Co-authored-by: EastArctica <32211444+EastArctica@users.noreply.github.com>
Co-authored-by: EastArctica <32211444+EastArctica@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect pitch wrapping in lookAt method Fix angle wrapping in lookAt to prevent large packet deltas Jan 15, 2026
Copilot AI requested a review from EastArctica January 15, 2026 04:06
@EastArctica EastArctica marked this pull request as ready for review January 19, 2026 22:09
@EastArctica EastArctica merged commit b16c03b into main Jan 19, 2026
2 checks passed
@EastArctica EastArctica deleted the copilot/fix-lookat-pitch-wrapping branch January 19, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pitch values are incorrectly wrapped in lookAt

2 participants