Class MathUtils

java.lang.Object
org.geysermc.geyser.util.MathUtils

public class MathUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    ceil​(float floatNumber)
    Round the given float to the next whole number
    static long
    chunkPositionToLong​(int x, int z)
    Packs a chunk's X and Z coordinates into a single long.
    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
     
    static byte
    getNbtByte​(Object value)
    Ensures the resulting object is a byte.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 calculate
      min - the lowest value the number can be
      max - 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 calculate
      min - the lowest value the number can be
      max - 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

      public static byte getNbtByte(Object value)
      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 single long.
      Parameters:
      x - the X coordinate
      z - 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.