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_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 thatvalue
is betweenstart
andend
.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 asvalue
from zero that is a multiple ofdivisor
.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 fromfrom
degrees towardsto
degrees, changing the value by at moststep
degrees.static float
stepTowards(float from, float to, float step)
Steps fromfrom
towardsto
, changing the value by at moststep
.static float
stepUnwrappedAngleTowards(float from, float to, float step)
Steps fromfrom
degrees towardsto
degrees, changing the value by at moststep
degrees.static float
subtractAngles(float start, float end)
static double
wrapDegrees(double double2)
static float
wrapDegrees(float float2)
static int
wrapDegrees(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 fromfrom
degrees towardsto
degrees, changing the value by at moststep
degrees. -
stepTowards
public static float stepTowards(float from, float to, float step)Steps fromfrom
towardsto
, changing the value by at moststep
. -
stepUnwrappedAngleTowards
public static float stepUnwrappedAngleTowards(float from, float to, float step)Steps fromfrom
degrees towardsto
degrees, changing the value by at moststep
degrees.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) -
roundUpToMultiple
public static int roundUpToMultiple(int value, int divisor)Returns a value farther than or as far asvalue
from 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 thatvalue
is betweenstart
andend
. This is the delta value needed to lerp betweenstart
andend
to 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 ifdeltaX
is 0 anddeltaY
is 0val10
- The output ifdeltaX
is 1 anddeltaY
is 0val01
- The output ifdeltaX
is 0 anddeltaY
is 1val11
- The output ifdeltaX
is 1 anddeltaY
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 cubedeltaY
- The y-coordinate on the unit cubedeltaZ
- The z-coordinate on the unit cubeval000
- The output ifdeltaX
is 0,deltaY
is 0 anddeltaZ
is 0val100
- The output ifdeltaX
is 1,deltaY
is 0 anddeltaZ
is 0val010
- The output ifdeltaX
is 0,deltaY
is 1 anddeltaZ
is 0val110
- The output ifdeltaX
is 1,deltaY
is 1 anddeltaZ
is 0val001
- The output ifdeltaX
is 0,deltaY
is 0 anddeltaZ
is 1val101
- The output ifdeltaX
is 1,deltaY
is 0 anddeltaZ
is 1val011
- The output ifdeltaX
is 0,deltaY
is 1 anddeltaZ
is 1val111
- The output ifdeltaX
is 1,deltaY
is 1 anddeltaZ
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. -
fwrapDegrees
Deprecated. -
method_24504
@Environment(CLIENT) public static float method_24504(float float2, float float3) -
square
public static float square(float n)
-