Skip to content

Commit

Permalink
Optimize decimal formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jan 8, 2021
1 parent 83ed180 commit 60ec3f1
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class CollisionManager {
* This check doesn't allow players right up against the block, so they must be pushed slightly away.
*/
public static final double COLLISION_TOLERANCE = 0.00001;
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.#####");

public CollisionManager(GeyserSession session) {
this.session = session;
Expand Down Expand Up @@ -151,8 +152,7 @@ public Vector3d adjustBedrockPosition(Vector3f bedrockPosition, boolean onGround

if (!onGround) {
// Trim the position to prevent rounding errors that make Java think we are clipping into a block
DecimalFormat format = new DecimalFormat("#.#####");
position = Vector3d.from(position.getX(), Double.parseDouble(format.format(position.getY())), position.getZ());
position = Vector3d.from(position.getX(), Double.parseDouble(DECIMAL_FORMAT.format(position.getY())), position.getZ());
}
} else {
// When chunk caching is off, we have to rely on this
Expand Down

0 comments on commit 60ec3f1

Please sign in to comment.