Class MathHelper

java.lang.Object
net.minecraft.util.math.MathHelper

public class MathHelper
extends Object
  • Field Summary

    Fields
    Modifier and Type Field Description
    private static double[] ARCSINE_TABLE  
    private static double[] COSINE_TABLE  
    private static int[] MULTIPLY_DE_BRUIJN_BIT_POSITION  
    private static Random RANDOM  
    private static float[] SINE_TABLE  
    private static double SMALLEST_FRACTION_FREE_DOUBLE  
    static float SQUARE_ROOT_OF_TWO  
  • Constructor Summary

    Constructors
    Constructor Description
    MathHelper()  
  • Method Summary

    Modifier and Type Method Description
    static float abs​(float float2)  
    static int abs​(int int2)  
    static double absMax​(double double2, double double3)  
    static float angleBetween​(float first, float second)  
    static boolean approximatelyEquals​(double a, double b)  
    static boolean approximatelyEquals​(float a, float b)  
    static double atan2​(double y, double x)  
    static double average​(long[] array)  
    static int binarySearch​(int start, int end, IntPredicate leftPredicate)  
    static int ceil​(double double2)  
    static int ceil​(float float2)  
    static double clamp​(double value, double min, double max)  
    static float clamp​(float value, float min, float max)  
    static int clamp​(int value, int min, int max)  
    static long clamp​(long value, long min, long max)  
    static double clampedLerp​(double start, double end, double delta)  
    static float cos​(float float2)  
    static int fastFloor​(double double2)  
    static float fastInverseCbrt​(float x)  
    static double fastInverseSqrt​(double x)  
    static float fastInverseSqrt​(float x)  
    static int floor​(double double2)  
    static int floor​(float float2)  
    static int floorDiv​(int int2, int int3)  
    static double floorMod​(double double2, double double3)  
    static float floorMod​(float float2, float float3)  
    static int floorMod​(int int2, int int3)  
    static double fractionalPart​(double value)  
    static float fractionalPart​(float value)  
    static float fwrapDegrees​(double degrees)
    Deprecated.
    static double getLerpProgress​(double value, double start, double end)
    Gets the fraction of the way that value is between start and end.
    static long hashCode​(int x, int y, int z)  
    static long hashCode​(Vec3i vec)  
    static int hsvToRgb​(float hue, float saturation, float value)  
    static int idealHash​(int int2)  
    static boolean isPowerOfTwo​(int int2)  
    static double lerp​(double delta, double start, double end)  
    static float lerp​(float delta, float start, float end)  
    static double lerp2​(double deltaX, double deltaY, double val00, double val10, double val01, double val11)
    A two-dimensional lerp between values on the 4 corners of the unit square.
    static double lerp3​(double deltaX, double deltaY, double deltaZ, double val000, double val100, double val010, double val110, double val001, double val101, double val011, double val111)
    A three-dimensional lerp between values on the 8 corners of the unit cube.
    static float lerpAngle​(float start, float end, float delta)
    Deprecated.
    static float lerpAngleDegrees​(float delta, float start, float end)  
    static long lfloor​(double double2)  
    static int log2​(int int2)  
    static int log2DeBruijn​(int int2)  
    static float method_24504​(float float2, float float3)  
    static double nextDouble​(Random random, double min, double max)  
    static float nextFloat​(Random random, float min, float max)  
    static int nextInt​(Random random, int min, int max)  
    static int packRgb​(float r, float g, float b)  
    static int packRgb​(int r, int g, int b)  
    static int parseInt​(String string, int fallback)  
    static double perlinFade​(double double2)  
    static UUID randomUuid()  
    static UUID randomUuid​(Random random)  
    static int roundUpToMultiple​(int value, int divisor)
    Returns a value farther than or as far as value from zero that is a multiple of divisor.
    static int sign​(double double2)  
    static float sin​(float float2)  
    static int smallestEncompassingPowerOfTwo​(int value)  
    static float sqrt​(double double2)  
    static float sqrt​(float float2)  
    static float square​(float n)  
    static float stepAngleTowards​(float from, float to, float step)
    Steps from from degrees towards to degrees, changing the value by at most step degrees.
    static float stepTowards​(float from, float to, float step)
    Steps from from towards to, changing the value by at most step.
    static float stepUnwrappedAngleTowards​(float from, float to, float step)
    Steps from from degrees towards to degrees, changing the value by at most step degrees.
    static float subtractAngles​(float start, float end)  
    static double wrapDegrees​(double double2)  
    static float wrapDegrees​(float float2)  
    static int wrapDegrees​(int int2)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SQUARE_ROOT_OF_TWO

      public static final float SQUARE_ROOT_OF_TWO
    • SINE_TABLE

      private static final float[] SINE_TABLE
    • RANDOM

      private static final Random RANDOM
    • MULTIPLY_DE_BRUIJN_BIT_POSITION

      private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION
    • SMALLEST_FRACTION_FREE_DOUBLE

      private static final double SMALLEST_FRACTION_FREE_DOUBLE
    • ARCSINE_TABLE

      private static final double[] ARCSINE_TABLE
    • COSINE_TABLE

      private static final double[] COSINE_TABLE
  • Constructor Details

    • MathHelper

      public MathHelper()
  • Method Details

    • sin

      public static float sin​(float float2)
    • cos

      public static float cos​(float float2)
    • sqrt

      public static float sqrt​(float float2)
    • sqrt

      public static float sqrt​(double double2)
    • floor

      public static int floor​(float float2)
    • fastFloor

      @Environment(CLIENT) public static int fastFloor​(double double2)
    • floor

      public static int floor​(double double2)
    • lfloor

      public static long lfloor​(double double2)
    • abs

      public static float abs​(float float2)
    • abs

      public static int abs​(int int2)
    • ceil

      public static int ceil​(float float2)
    • ceil

      public static int ceil​(double double2)
    • clamp

      public static int clamp​(int value, int min, int max)
    • clamp

      @Environment(CLIENT) public static long clamp​(long value, long min, long max)
    • clamp

      public static float clamp​(float value, float min, float max)
    • clamp

      public static double clamp​(double value, double min, double max)
    • clampedLerp

      public static double clampedLerp​(double start, double end, double delta)
    • absMax

      public static double absMax​(double double2, double double3)
    • floorDiv

      public static int floorDiv​(int int2, int int3)
    • nextInt

      public static int nextInt​(Random random, int min, int max)
    • nextFloat

      public static float nextFloat​(Random random, float min, float max)
    • nextDouble

      public static double nextDouble​(Random random, double min, double max)
    • average

      public static double average​(long[] array)
    • approximatelyEquals

      @Environment(CLIENT) public static boolean approximatelyEquals​(float a, float b)
    • approximatelyEquals

      public static boolean approximatelyEquals​(double a, double b)
    • floorMod

      public static int floorMod​(int int2, int int3)
    • floorMod

      @Environment(CLIENT) public static float floorMod​(float float2, float float3)
    • floorMod

      @Environment(CLIENT) public static double floorMod​(double double2, double double3)
    • wrapDegrees

      @Environment(CLIENT) public static int wrapDegrees​(int int2)
    • wrapDegrees

      public static float wrapDegrees​(float float2)
    • wrapDegrees

      public static double wrapDegrees​(double double2)
    • subtractAngles

      public static float subtractAngles​(float start, float end)
    • angleBetween

      public static float angleBetween​(float first, float second)
    • stepAngleTowards

      public static float stepAngleTowards​(float from, float to, float step)
      Steps from from degrees towards to degrees, changing the value by at most step degrees.
    • stepTowards

      public static float stepTowards​(float from, float to, float step)
      Steps from from towards to, changing the value by at most step.
    • stepUnwrappedAngleTowards

      public static float stepUnwrappedAngleTowards​(float from, float to, float step)
      Steps from from degrees towards to degrees, changing the value by at most step degrees.

      This method does not wrap the resulting angle, so stepAngleTowards(float, float, float) should be used in preference.

    • parseInt

      @Environment(CLIENT) public static int parseInt​(String string, int fallback)
    • smallestEncompassingPowerOfTwo

      public static int smallestEncompassingPowerOfTwo​(int value)
    • isPowerOfTwo

      public static boolean isPowerOfTwo​(int int2)
    • log2DeBruijn

      public static int log2DeBruijn​(int int2)
    • log2

      public static int log2​(int int2)
    • roundUpToMultiple

      public static int roundUpToMultiple​(int value, int divisor)
      Returns a value farther than or as far as value from zero that is a multiple of divisor.
    • packRgb

      @Environment(CLIENT) public static int packRgb​(float r, float g, float b)
    • packRgb

      @Environment(CLIENT) public static int packRgb​(int r, int g, int b)
    • fractionalPart

      public static float fractionalPart​(float value)
    • fractionalPart

      public static double fractionalPart​(double value)
    • hashCode

      public static long hashCode​(Vec3i vec)
    • hashCode

      public static long hashCode​(int x, int y, int z)
    • randomUuid

      public static UUID randomUuid​(Random random)
    • randomUuid

      public static UUID randomUuid()
    • getLerpProgress

      public static double getLerpProgress​(double value, double start, double end)
      Gets the fraction of the way that value is between start and end. This is the delta value needed to lerp between start and end to get value. In other words, getLerpProgress(lerp(delta, start, end), start, end) == delta.
      Parameters:
      value - The result of the lerp function
      start - The value interpolated from
      end - The value interpolated to
    • atan2

      public static double atan2​(double y, double x)
    • fastInverseSqrt

      @Environment(CLIENT) public static float fastInverseSqrt​(float x)
    • fastInverseSqrt

      public static double fastInverseSqrt​(double x)
    • fastInverseCbrt

      @Environment(CLIENT) public static float fastInverseCbrt​(float x)
    • hsvToRgb

      public static int hsvToRgb​(float hue, float saturation, float value)
    • idealHash

      public static int idealHash​(int int2)
    • binarySearch

      public static int binarySearch​(int start, int end, IntPredicate leftPredicate)
    • lerp

      public static float lerp​(float delta, float start, float end)
    • lerp

      public static double lerp​(double delta, double start, double end)
    • lerp2

      public static double lerp2​(double deltaX, double deltaY, double val00, double val10, double val01, double val11)
      A two-dimensional lerp between values on the 4 corners of the unit square. Arbitrary values are specified for the corners and the output is interpolated between them.
      Parameters:
      deltaX - The x-coordinate on the unit square
      deltaY - The y-coordinate on the unit square
      val00 - The output if deltaX is 0 and deltaY is 0
      val10 - The output if deltaX is 1 and deltaY is 0
      val01 - The output if deltaX is 0 and deltaY is 1
      val11 - The output if deltaX is 1 and deltaY is 1
    • lerp3

      public static double lerp3​(double deltaX, double deltaY, double deltaZ, double val000, double val100, double val010, double val110, double val001, double val101, double val011, double val111)
      A three-dimensional lerp between values on the 8 corners of the unit cube. Arbitrary values are specified for the corners and the output is interpolated between them.
      Parameters:
      deltaX - The x-coordinate on the unit cube
      deltaY - The y-coordinate on the unit cube
      deltaZ - The z-coordinate on the unit cube
      val000 - The output if deltaX is 0, deltaY is 0 and deltaZ is 0
      val100 - The output if deltaX is 1, deltaY is 0 and deltaZ is 0
      val010 - The output if deltaX is 0, deltaY is 1 and deltaZ is 0
      val110 - The output if deltaX is 1, deltaY is 1 and deltaZ is 0
      val001 - The output if deltaX is 0, deltaY is 0 and deltaZ is 1
      val101 - The output if deltaX is 1, deltaY is 0 and deltaZ is 1
      val011 - The output if deltaX is 0, deltaY is 1 and deltaZ is 1
      val111 - The output if deltaX is 1, deltaY is 1 and deltaZ is 1
    • perlinFade

      public static double perlinFade​(double double2)
    • sign

      public static int sign​(double double2)
    • lerpAngleDegrees

      @Environment(CLIENT) public static float lerpAngleDegrees​(float delta, float start, float end)
    • lerpAngle

      @Deprecated public static float lerpAngle​(float start, float end, float delta)
      Deprecated.
    • fwrapDegrees

      @Environment(CLIENT) @Deprecated public static float fwrapDegrees​(double degrees)
      Deprecated.
    • method_24504

      @Environment(CLIENT) public static float method_24504​(float float2, float float3)
    • square

      public static float square​(float n)