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 float2)static intabs(int int2)static doubleabsMax(double double2, double double3)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 double2)static intceil(float float2)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 float2)static intfastFloor(double double2)static floatfastInverseCbrt(float x)static doublefastInverseSqrt(double x)static floatfastInverseSqrt(float x)static intfloor(double double2)static intfloor(float float2)static intfloorDiv(int int2, int int3)static doublefloorMod(double double2, double double3)static floatfloorMod(float float2, float float3)static intfloorMod(int int2, int int3)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 int2)static booleanisPowerOfTwo(int int2)static doublelerp(double delta, double start, double end)static floatlerp(float delta, float start, float end)static doublelerp2(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 doublelerp3(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 floatlerpAngle(float start, float end, float delta)Deprecated.static floatlerpAngleDegrees(float delta, float start, float end)static doublelerpFromProgress(double lerpValue, double lerpStart, double lerpEnd, double start, double end)static longlfloor(double double2)static intlog2(int int2)static intlog2DeBruijn(int int2)static floatnextBetween(Random random, float min, float max)static intnextBetween(Random random, int min, int max)static doublenextDouble(Random random, double min, double max)static floatnextFloat(Random random, float min, float max)static floatnextGaussian(Random random, float mean, float deviation)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 float2)static intsmallestEncompassingPowerOfTwo(int value)static floatsqrt(double double2)static floatsqrt(float float2)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 floatwrap(float value, float maxDeviation)static doublewrapDegrees(double double2)static floatwrapDegrees(float float2)static intwrapDegrees(int int2)
-
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 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
-
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 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 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 int2) -
log2DeBruijn
public static int log2DeBruijn(int int2) -
log2
public static int log2(int int2) -
packRgb
public static int packRgb(float r, float g, float b) -
packRgb
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 int2) -
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 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 squaredeltaY- The y-coordinate on the unit squareval00- The output ifdeltaXis 0 anddeltaYis 0val10- The output ifdeltaXis 1 anddeltaYis 0val01- The output ifdeltaXis 0 anddeltaYis 1val11- The output ifdeltaXis 1 anddeltaYis 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 cubedeltaY- The y-coordinate on the unit cubedeltaZ- The z-coordinate on the unit cubeval000- The output ifdeltaXis 0,deltaYis 0 anddeltaZis 0val100- The output ifdeltaXis 1,deltaYis 0 anddeltaZis 0val010- The output ifdeltaXis 0,deltaYis 1 anddeltaZis 0val110- The output ifdeltaXis 1,deltaYis 1 anddeltaZis 0val001- The output ifdeltaXis 0,deltaYis 0 anddeltaZis 1val101- The output ifdeltaXis 1,deltaYis 0 anddeltaZis 1val011- The output ifdeltaXis 0,deltaYis 1 anddeltaZis 1val111- 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. -
wrap
@Environment(CLIENT) public static float wrap(float value, float maxDeviation) -
square
public static float square(float n) -
lerpFromProgress
public static double lerpFromProgress(double lerpValue, double lerpStart, double lerpEnd, double start, double end) -
roundUpToMultiple
public static int roundUpToMultiple(int value, int divisor)Returns a value farther than or as far asvaluefrom zero that is a multiple ofdivisor. -
nextBetween
-
nextBetween
-
nextGaussian
-