mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 15:41:38 +01:00
Use intrinsics math floor
This commit is contained in:
parent
b178a6adac
commit
d61174235b
@ -49,7 +49,7 @@ public interface Point {
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
default int blockX() {
|
||||
return MathUtils.floor(x());
|
||||
return (int) Math.floor(x());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +59,7 @@ public interface Point {
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
default int blockY() {
|
||||
return MathUtils.floor(y());
|
||||
return (int) Math.floor(y());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +69,7 @@ public interface Point {
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
default int blockZ() {
|
||||
return MathUtils.floor(z());
|
||||
return (int) Math.floor(z());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -536,9 +536,9 @@ public final class Vec implements Point {
|
||||
);
|
||||
|
||||
Operator FLOOR = (x, y, z) -> new Vec(
|
||||
MathUtils.floor(x),
|
||||
MathUtils.floor(y),
|
||||
MathUtils.floor(z)
|
||||
Math.floor(x),
|
||||
Math.floor(y),
|
||||
Math.floor(z)
|
||||
);
|
||||
|
||||
@NotNull Vec apply(double x, double y, double z);
|
||||
|
@ -1,9 +1,11 @@
|
||||
package net.minestom.server.utils;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public final class MathUtils {
|
||||
|
||||
private MathUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static int square(int num) {
|
||||
@ -91,20 +93,7 @@ public final class MathUtils {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
public static int floor(double num) {
|
||||
final int floor = (int) num;
|
||||
return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63);
|
||||
}
|
||||
|
||||
public static double mod(final double a, final double b) {
|
||||
return (a % b + b) % b;
|
||||
}
|
||||
|
||||
public static Integer tryParse(String string) {
|
||||
try {
|
||||
return Integer.parseInt(string);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public final class ChunkUtils {
|
||||
*/
|
||||
public static int getChunkCoordinate(double xz) {
|
||||
assert Chunk.CHUNK_SIZE_X == Chunk.CHUNK_SIZE_Z;
|
||||
return Math.floorDiv(MathUtils.floor(xz), Chunk.CHUNK_SIZE_X);
|
||||
return Math.floorDiv((int) Math.floor(xz), Chunk.CHUNK_SIZE_X);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user