From 5f75ea7d3a38b460e68ec1c13d7162df201a21fe Mon Sep 17 00:00:00 2001 From: themode Date: Mon, 25 Jan 2021 19:33:53 +0100 Subject: [PATCH] Remove unnecessary casts --- .../server/collision/CollisionUtils.java | 4 ++-- .../net/minestom/server/entity/Entity.java | 19 ++++++++++--------- .../net/minestom/server/utils/Vector.java | 12 ++++++------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/minestom/server/collision/CollisionUtils.java b/src/main/java/net/minestom/server/collision/CollisionUtils.java index dbdf738c2..a55d0f172 100644 --- a/src/main/java/net/minestom/server/collision/CollisionUtils.java +++ b/src/main/java/net/minestom/server/collision/CollisionUtils.java @@ -115,9 +115,9 @@ public class CollisionUtils { } // find the corner which moved the least - float smallestDisplacement = Float.POSITIVE_INFINITY; + double smallestDisplacement = Double.POSITIVE_INFINITY; for (int i = 0; i < corners.length; i++) { - final float displacement = (float) corners[i].distance(cornersCopy[i]); + final double displacement = corners[i].distance(cornersCopy[i]); if (displacement < smallestDisplacement) { smallestDisplacement = displacement; } diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 354b6eff8..cf8a169c5 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -93,9 +93,9 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P // Velocity protected Vector velocity = new Vector(); // Movement in block per second - protected float gravityDragPerTick; - protected float gravityAcceleration; - protected float gravityTerminalVelocity; + protected double gravityDragPerTick; + protected double gravityAcceleration; + protected double gravityTerminalVelocity; protected int gravityTickCount; // Number of tick where gravity tick was applied private boolean autoViewable; @@ -485,8 +485,8 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P Vector newVelocityOut = new Vector(); // Gravity force - final float gravityY = !noGravity ? Math.min( - gravityDragPerTick + (gravityAcceleration * (float) gravityTickCount), + final double gravityY = !noGravity ? Math.min( + gravityDragPerTick + (gravityAcceleration * (double) gravityTickCount), gravityTerminalVelocity) : 0f; final Vector deltaPos = new Vector( @@ -711,7 +711,8 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P * Changes the internal entity bounding box. *

* WARNING: this does not change the entity hit-box which is client-side. - * @param x the bounding box X size + * + * @param x the bounding box X size * @param y the bounding box Y size * @param z the bounding box Z size */ @@ -814,7 +815,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P * * @return the gravity drag per tick in block */ - public float getGravityDragPerTick() { + public double getGravityDragPerTick() { return gravityDragPerTick; } @@ -823,7 +824,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P * * @return the gravity acceleration in block */ - public float getGravityAcceleration() { + public double getGravityAcceleration() { return gravityAcceleration; } @@ -832,7 +833,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P * * @return the maximum gravity velocity in block */ - public float getGravityTerminalVelocity() { + public double getGravityTerminalVelocity() { return gravityTerminalVelocity; } diff --git a/src/main/java/net/minestom/server/utils/Vector.java b/src/main/java/net/minestom/server/utils/Vector.java index e3c36bb7b..225f174f1 100644 --- a/src/main/java/net/minestom/server/utils/Vector.java +++ b/src/main/java/net/minestom/server/utils/Vector.java @@ -422,15 +422,15 @@ public class Vector implements PublicCloneable { double sinTheta = Math.sin(angle); double dotProduct = this.dot(axis); - this.x = (float) (x2 * dotProduct * (1d - cosTheta) + this.x = x2 * dotProduct * (1d - cosTheta) + x * cosTheta - + (-z2 * y + y2 * z) * sinTheta); - this.y = (float) (y2 * dotProduct * (1d - cosTheta) + + (-z2 * y + y2 * z) * sinTheta; + this.y = y2 * dotProduct * (1d - cosTheta) + y * cosTheta - + (z2 * x - x2 * z) * sinTheta); - this.z = (float) (z2 * dotProduct * (1d - cosTheta) + + (z2 * x - x2 * z) * sinTheta; + this.z = z2 * dotProduct * (1d - cosTheta) + z * cosTheta - + (-y2 * x + x2 * y) * sinTheta); + + (-y2 * x + x2 * y) * sinTheta; return this; }