Package net.minecraft.util.math
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_TABLEprivate static double[]COSINE_TABLEprivate static int[]MULTIPLY_DE_BRUIJN_BIT_POSITIONprivate static RandomRANDOMprivate static float[]SINE_TABLEprivate static doubleSMALLEST_FRACTION_FREE_DOUBLEstatic floatSQUARE_ROOT_OF_TWO -
Constructor Summary
Constructors Constructor Description MathHelper() -
Method Summary
Modifier and Type Method Description static floatabs(float value)static intabs(int value)static doubleabsMax(double a, double b)static floatangleBetween(float first, float second)static booleanapproximatelyEquals(double a, double b)static booleanapproximatelyEquals(float a, float b)static doubleatan2(double y, double x)static doubleaverage(long[] array)static intbinarySearch(int start, int end, IntPredicate leftPredicate)static intceil(double value)static intceil(float value)static doubleclamp(double value, double min, double max)static floatclamp(float value, float min, float max)static intclamp(int value, int min, int max)static longclamp(long value, long min, long max)static doubleclampedLerp(double start, double end, double delta)static floatcos(float value)static intfastFloor(double value)static floatfastInverseCbrt(float x)static doublefastInverseSqrt(double x)static floatfastInverseSqrt(float x)static intfloor(double value)static intfloor(float value)static intfloorDiv(int dividend, int divisor)static doublefloorMod(double dividend, double divisor)static floatfloorMod(float dividend, float divisor)static intfloorMod(int dividend, int divisor)static doublefractionalPart(double value)static floatfractionalPart(float value)static floatfwrapDegrees(double degrees)Deprecated.static doublegetLerpProgress(double value, double start, double end)Gets the fraction of the way thatvalueis betweenstartandend.static longhashCode(int x, int y, int z)static longhashCode(Vec3i vec)static inthsvToRgb(float hue, float saturation, float value)static intidealHash(int value)static booleanisPowerOfTwo(int value)static doublelerp(double delta, double start, double end)static floatlerp(float delta, float start, float end)static doublelerp2(double deltaX, double deltaY, double x0y0, double x1y0, double x0y1, double x1y1)A two-dimensional lerp between values on the 4 corners of the unit square.static doublelerp3(double deltaX, double deltaY, double deltaZ, double x0y0z0, double x1y0z0, double x0y1z0, double x1y1z0, double x0y0z1, double x1y0z1, double x0y1z1, double x1y1z1)A three-dimensional lerp between values on the 8 corners of the unit cube.static floatlerpAngle(float start, float end, float delta)Deprecated.static floatlerpAngleDegrees(float delta, float start, float end)static longlfloor(double value)static intlog2(int value)static intlog2DeBruijn(int value)static floatmethod_24504(float float2, float float3)static doublenextDouble(Random random, double min, double max)static floatnextFloat(Random random, float min, float max)static intnextInt(Random random, int min, int max)static intpackRgb(float r, float g, float b)static intpackRgb(int r, int g, int b)static intparseInt(String string, int fallback)static doubleperlinFade(double value)static UUIDrandomUuid()static UUIDrandomUuid(Random random)static introundUpToMultiple(int value, int divisor)Returns a value farther than or as far asvaluefrom zero that is a multiple ofdivisor.static intsign(double value)static floatsin(float value)static intsmallestEncompassingPowerOfTwo(int value)static floatsqrt(double value)static floatsqrt(float value)static floatsquare(float n)static floatstepAngleTowards(float from, float to, float step)Steps fromfromdegrees towardstodegrees, changing the value by at moststepdegrees.static floatstepTowards(float from, float to, float step)Steps fromfromtowardsto, changing the value by at moststep.static floatstepUnwrappedAngleTowards(float from, float to, float step)Steps fromfromdegrees towardstodegrees, changing the value by at moststepdegrees.static floatsubtractAngles(float start, float end)static doublewrapDegrees(double degrees)Wraps an angle in degrees to the interval[-180, 180).static floatwrapDegrees(float degrees)Wraps an angle in degrees to the interval[-180, 180).static intwrapDegrees(int degrees)Wraps an angle in degrees to the interval[-180, 180).
-
Field Details
-
SQUARE_ROOT_OF_TWO
public static final float SQUARE_ROOT_OF_TWO -
SINE_TABLE
private static final float[] SINE_TABLE -
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 value) -
cos
public static float cos(float value) -
sqrt
public static float sqrt(float value) -
sqrt
public static float sqrt(double value) -
floor
public static int floor(float value) -
fastFloor
@Environment(CLIENT) public static int fastFloor(double value) -
floor
public static int floor(double value) -
lfloor
public static long lfloor(double value) -
abs
public static float abs(float value) -
abs
public static int abs(int value) -
ceil
public static int ceil(float value) -
ceil
public static int ceil(double value) -
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 a, double b) -
floorDiv
public static int floorDiv(int dividend, int divisor) -
nextInt
-
nextFloat
-
nextDouble
-
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 dividend, int divisor) -
floorMod
@Environment(CLIENT) public static float floorMod(float dividend, float divisor) -
floorMod
@Environment(CLIENT) public static double floorMod(double dividend, double divisor) -
wrapDegrees
@Environment(CLIENT) public static int wrapDegrees(int degrees)Wraps an angle in degrees to the interval[-180, 180). -
wrapDegrees
public static float wrapDegrees(float degrees)Wraps an angle in degrees to the interval[-180, 180). -
wrapDegrees
public static double wrapDegrees(double degrees)Wraps an angle in degrees to the interval[-180, 180). -
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 fromfromdegrees towardstodegrees, changing the value by at moststepdegrees. -
stepTowards
public static float stepTowards(float from, float to, float step)Steps fromfromtowardsto, changing the value by at moststep. -
stepUnwrappedAngleTowards
public static float stepUnwrappedAngleTowards(float from, float to, float step)Steps fromfromdegrees towardstodegrees, changing the value by at moststepdegrees.This method does not wrap the resulting angle, so
stepAngleTowards(float, float, float)should be used in preference. -
parseInt
-
smallestEncompassingPowerOfTwo
public static int smallestEncompassingPowerOfTwo(int value) -
isPowerOfTwo
public static boolean isPowerOfTwo(int value) -
log2DeBruijn
public static int log2DeBruijn(int value) -
log2
public static int log2(int value) -
roundUpToMultiple
public static int roundUpToMultiple(int value, int divisor)Returns a value farther than or as far asvaluefrom zero that is a multiple ofdivisor. -
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
-
hashCode
public static long hashCode(int x, int y, int z) -
randomUuid
-
randomUuid
-
getLerpProgress
public static double getLerpProgress(double value, double start, double end)Gets the fraction of the way thatvalueis betweenstartandend. This is the delta value needed to lerp betweenstartandendto getvalue. In other words,getLerpProgress(lerp(delta, start, end), start, end) == delta.- Parameters:
value- the result of the lerp functionstart- the value interpolated fromend- 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 value) -
binarySearch
-
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 x0y0, double x1y0, double x0y1, double x1y1)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 squaredeltaY- the y-coordinate on the unit squarex0y0- the output ifdeltaXis 0 anddeltaYis 0x1y0- the output ifdeltaXis 1 anddeltaYis 0x0y1- the output ifdeltaXis 0 anddeltaYis 1x1y1- the output ifdeltaXis 1 anddeltaYis 1
-
lerp3
public static double lerp3(double deltaX, double deltaY, double deltaZ, double x0y0z0, double x1y0z0, double x0y1z0, double x1y1z0, double x0y0z1, double x1y0z1, double x0y1z1, double x1y1z1)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 cubedeltaY- the y-coordinate on the unit cubedeltaZ- the z-coordinate on the unit cubex0y0z0- the output ifdeltaXis 0,deltaYis 0 anddeltaZis 0x1y0z0- the output ifdeltaXis 1,deltaYis 0 anddeltaZis 0x0y1z0- the output ifdeltaXis 0,deltaYis 1 anddeltaZis 0x1y1z0- the output ifdeltaXis 1,deltaYis 1 anddeltaZis 0x0y0z1- the output ifdeltaXis 0,deltaYis 0 anddeltaZis 1x1y0z1- the output ifdeltaXis 1,deltaYis 0 anddeltaZis 1x0y1z1- the output ifdeltaXis 0,deltaYis 1 anddeltaZis 1x1y1z1- the output ifdeltaXis 1,deltaYis 1 anddeltaZis 1
-
perlinFade
public static double perlinFade(double value) -
sign
public static int sign(double value) -
lerpAngleDegrees
@Environment(CLIENT) public static float lerpAngleDegrees(float delta, float start, float end) -
lerpAngle
Deprecated. -
fwrapDegrees
Deprecated. -
method_24504
@Environment(CLIENT) public static float method_24504(float float2, float float3) -
square
public static float square(float n)
-