From 6cba2cb7c752e8cba1f60b17c6671bac9ea7d760 Mon Sep 17 00:00:00 2001 From: MrGazdag <44264503+MrGazdag@users.noreply.github.com> Date: Sun, 4 Jul 2021 17:18:17 +0200 Subject: [PATCH] Fix Vector rotation The Vector class' rotateAround methods were modifying the used variables during the rotation, which should not be the case. Bukkit's similar Vector class manages to do this correctly. --- .../net/minestom/server/utils/Vector.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minestom/server/utils/Vector.java b/src/main/java/net/minestom/server/utils/Vector.java index 1833b8a7b..2357e0e92 100644 --- a/src/main/java/net/minestom/server/utils/Vector.java +++ b/src/main/java/net/minestom/server/utils/Vector.java @@ -327,8 +327,11 @@ public class Vector implements PublicCloneable { double angleCos = Math.cos(angle); double angleSin = Math.sin(angle); - this.y = angleCos * getY() - angleSin * getZ(); - this.z = angleSin * getY() + angleCos * getZ(); + double oldY = getY(); + double oldZ = getZ(); + + this.y = angleCos * oldY - angleSin * oldZ; + this.z = angleSin * oldY + angleCos * oldZ; return this; } @@ -349,8 +352,11 @@ public class Vector implements PublicCloneable { double angleCos = Math.cos(angle); double angleSin = Math.sin(angle); - this.x = angleCos * getX() + angleSin * getZ(); - this.z = -angleSin * getX() + angleCos * getZ(); + double oldX = getX(); + double oldZ = getZ(); + + this.x = angleCos * oldX + angleSin * oldZ; + this.z = -angleSin * oldX + angleCos * oldZ; return this; } @@ -371,8 +377,11 @@ public class Vector implements PublicCloneable { double angleCos = Math.cos(angle); double angleSin = Math.sin(angle); - this.x = angleCos * getX() - angleSin * getY(); - this.y = angleSin * getX() + angleCos * getY(); + double oldX = getX(); + double oldY = getY(); + + this.x = angleCos * oldX - angleSin * oldY; + this.y = angleSin * oldX + angleCos * oldY; return this; }