aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0865-Stop-large-look-changes-from-crashing-the-server.patch
blob: 1a4fc80ccb71f49e29fce7cf5b6280ff58ff850f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MWHunter <s0521458@student.rockvalleycollege.edu>
Date: Wed, 24 Aug 2022 09:54:11 -0400
Subject: [PATCH] Stop large look changes from crashing the server

Co-authored-by: Jaren Knodel <Jaren@Knodel.com>

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 680e1d6f2e3391e377be5c488e0554ccbb852f84..14d9bd4b32f2d7f34283e1efcd780c07ac498d6c 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3037,37 +3037,15 @@ public abstract class LivingEntity extends Entity implements Attackable {
         this.level().getProfiler().pop();
         this.level().getProfiler().push("rangeChecks");
 
-        while (this.getYRot() - this.yRotO < -180.0F) {
-            this.yRotO -= 360.0F;
-        }
-
-        while (this.getYRot() - this.yRotO >= 180.0F) {
-            this.yRotO += 360.0F;
-        }
+        // Paper start - stop large pitch and yaw changes from crashing the server
+        this.yRotO += Math.round((this.getYRot() - this.yRotO) / 360.0F) * 360.0F;
 
-        while (this.yBodyRot - this.yBodyRotO < -180.0F) {
-            this.yBodyRotO -= 360.0F;
-        }
+        this.yBodyRotO += Math.round((this.yBodyRot - this.yBodyRotO) / 360.0F) * 360.0F;
 
-        while (this.yBodyRot - this.yBodyRotO >= 180.0F) {
-            this.yBodyRotO += 360.0F;
-        }
-
-        while (this.getXRot() - this.xRotO < -180.0F) {
-            this.xRotO -= 360.0F;
-        }
+        this.xRotO += Math.round((this.getXRot() - this.xRotO) / 360.0F) * 360.0F;
 
-        while (this.getXRot() - this.xRotO >= 180.0F) {
-            this.xRotO += 360.0F;
-        }
-
-        while (this.yHeadRot - this.yHeadRotO < -180.0F) {
-            this.yHeadRotO -= 360.0F;
-        }
-
-        while (this.yHeadRot - this.yHeadRotO >= 180.0F) {
-            this.yHeadRotO += 360.0F;
-        }
+        this.yHeadRotO += Math.round((this.yHeadRot - this.yHeadRotO) / 360.0F) * 360.0F;
+        // Paper end
 
         this.level().getProfiler().pop();
         this.animStep += f2;
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index 24b549cb21926a02d736f0bbb991006b9453068d..6d7ac0c8c171834fa8da94f158258a4774d80ec4 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -251,13 +251,7 @@ public abstract class Projectile extends Entity implements TraceableEntity {
     }
 
     protected static float lerpRotation(float prevRot, float newRot) {
-        while (newRot - prevRot < -180.0F) {
-            prevRot -= 360.0F;
-        }
-
-        while (newRot - prevRot >= 180.0F) {
-            prevRot += 360.0F;
-        }
+        prevRot += Math.round((newRot - prevRot) / 360.0F) * 360.0F; // Paper - stop large look changes from crashing the server
 
         return Mth.lerp(0.2F, prevRot, newRot);
     }