Package org.geysermc.geyser.util
Class MathUtils
java.lang.Object
org.geysermc.geyser.util.MathUtils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
ceil(float floatNumber)
Round the given float to the next whole numberstatic long
chunkPositionToLong(int x, int z)
Packs a chunk's X and Z coordinates into a singlelong
.static double
constrain(double num, double min, double max)
If number is greater than the max, set it to max, and if number is lower than low, set it to low.static int
constrain(int num, int min, int max)
If number is greater than the max, set it to max, and if number is lower than low, set it to low.static int
getGlobalPaletteForSize(int size)
static byte
getNbtByte(Object value)
Ensures the resulting object is a byte.
-
Field Details
-
SQRT_OF_TWO
public static final double SQRT_OF_TWO
-
-
Constructor Details
-
MathUtils
public MathUtils()
-
-
Method Details
-
ceil
public static int ceil(float floatNumber)Round the given float to the next whole number- Parameters:
floatNumber
- Float to round- Returns:
- Rounded number
-
constrain
public static double constrain(double num, double min, double max)If number is greater than the max, set it to max, and if number is lower than low, set it to low.- Parameters:
num
- number to calculatemin
- the lowest value the number can bemax
- the greatest value the number can be- Returns:
- - min if num is lower than min
- max if num is greater than max
- num otherwise
-
constrain
public static int constrain(int num, int min, int max)If number is greater than the max, set it to max, and if number is lower than low, set it to low.- Parameters:
num
- number to calculatemin
- the lowest value the number can bemax
- the greatest value the number can be- Returns:
- - min if num is lower than min
- max if num is greater than max
- num otherwise
-
getNbtByte
Ensures the resulting object is a byte. Java Edition does not care whether a byte is encoded as an integer or not; it converts it into a byte anyway.- Parameters:
value
- The value to convert- Returns:
- The converted byte
-
chunkPositionToLong
public static long chunkPositionToLong(int x, int z)Packs a chunk's X and Z coordinates into a singlelong
.- Parameters:
x
- the X coordinatez
- the Z coordinate- Returns:
- the packed coordinates
-
getGlobalPaletteForSize
public static int getGlobalPaletteForSize(int size)- Returns:
- the bits per entry used when this number is the maximum amount of entries.
-