CLASS net/minecraft/class_3532 net/minecraft/util/math/MathHelper COMMENT Contains math-related helper methods. This includes {@code float}-specific extensions COMMENT to {@link Math}, linear interpolation (lerp), and color-related methods. COMMENT COMMENT
Trigonometric functions defined in this class use the "sine table", a pre-calculated COMMENT table of {@code sin(N)} ({@code 0 <= N < pi * 2}). FIELD field_15722 COSINE_OF_ARCSINE_TABLE [D COMMENT Holds values of cos(arcsin(x)): {@code COSINE_OF_ARCSINE_TABLE[i]} is equal to COMMENT {@code Math.cos(Math.arcsin(i / 256.0))}. COMMENT COMMENT
This is used by {@link MathHelper#atan2} to approximate the inverse COMMENT tangent function. FIELD field_15723 MULTIPLY_DE_BRUIJN_BIT_POSITION [I FIELD field_15724 SQUARE_ROOT_OF_TWO F FIELD field_15725 SINE_TABLE [F FIELD field_15726 RANDOM Lnet/minecraft/class_5819; FIELD field_15727 ARCSINE_TABLE [D COMMENT Holds values of arcsin(x): {@code ARCSINE_TABLE[i]} is equal to COMMENT {@code Math.arcsin(i / 256.0)}. COMMENT COMMENT
This is used by {@link MathHelper#atan2} to approximate the inverse COMMENT tangent function. FIELD field_15728 ROUNDER_256THS D COMMENT A constant for rounding a double to the nearest multiple of 1/256. COMMENT COMMENT
When this constant is added to a double that is not too large, then the COMMENT bits of the result's mantissa reflect the original number times 256. COMMENT Consequently, adding this constant and then subtracting it rounds such COMMENT doubles to the nearest multiple of 1/256. COMMENT COMMENT
This is used by {@link MathHelper#atan2} to produce an index into COMMENT {@link MathHelper#ARCSINE_TABLE} and {@link MathHelper#COSINE_OF_ARCSINE_TABLE}. FIELD field_29844 PI F FIELD field_29845 HALF_PI F FIELD field_29846 TAU F COMMENT Tau is equal to {@code 2 * PI}. FIELD field_29847 RADIANS_PER_DEGREE F FIELD field_29848 DEGREES_PER_RADIAN F FIELD field_29849 EPSILON F FIELD field_29853 HALF_PI_RADIANS_SINE_TABLE_INDEX J FIELD field_29856 DEGREES_TO_SINE_TABLE_INDEX F FIELD field_29857 ARCSINE_MACLAURIN_3 D COMMENT Used for the third-order Maclaurin series approximation of the arcsin function, COMMENT x + x^3/6. FIELD field_29859 ARCSINE_TABLE_LENGTH I COMMENT The total number of entries in {@link MathHelper#ARCSINE_TABLE} and COMMENT {@link MathHelper#COSINE_OF_ARCSINE_TABLE}. COMMENT COMMENT
These tables have 257 elements because they store values for multiples of COMMENT 1/256 from 0 to 1, inclusive. FIELD field_46242 Y_AXIS Lorg/joml/Vector3f; FIELD field_46243 X_AXIS Lorg/joml/Vector3f; FIELD field_46244 Z_AXIS Lorg/joml/Vector3f; METHOD method_15338 wrapDegrees (D)D COMMENT Wraps an angle in degrees to the interval {@code [-180, 180)}. ARG 0 degrees METHOD method_15339 smallestEncompassingPowerOfTwo (I)I ARG 0 value METHOD method_15340 clamp (III)I ARG 0 value ARG 1 min ARG 2 max METHOD method_15341 floorMod (FF)F ARG 0 dividend ARG 1 divisor METHOD method_15342 ceilLog2 (I)I COMMENT {@return ceil(log2({@code value}))} COMMENT COMMENT
The vanilla implementation uses the de Bruijn sequence. COMMENT COMMENT @see Integer#numberOfLeadingZeros(int) ARG 0 value COMMENT the input value METHOD method_15343 parseInt (Ljava/lang/String;I)I ARG 0 string ARG 1 fallback METHOD method_15344 nextFloat (Lnet/minecraft/class_5819;FF)F ARG 0 random ARG 1 min ARG 2 max METHOD method_15345 fastInverseSqrt (D)D COMMENT {@return an approximation of {@code 1 / Math.sqrt(x)}} ARG 0 x METHOD method_15347 approximatelyEquals (FF)Z ARG 0 a ARG 1 b METHOD method_15348 stepTowards (FFF)F COMMENT Steps from {@code from} towards {@code to}, changing the value by at most {@code step}. ARG 0 from ARG 1 to ARG 2 step METHOD method_15349 atan2 (DD)D COMMENT {@return an approximation of {@code Math.atan2(y, x)}} COMMENT COMMENT @implNote This implementation transforms the arguments such that they COMMENT lie in the first quadrant. If {@code y > x}, then {@code x} and {@code y} COMMENT are swapped to minimize the error of the initial approximation. COMMENT {@code x} and {@code y} are normalized, and an initial approximation COMMENT of the result and the sine of the deviation from the true value are COMMENT obtained using the {@link MathHelper#ARCSINE_TABLE} and COMMENT {@link MathHelper#COSINE_OF_ARCSINE_TABLE} lookup tables. The error COMMENT itself is approximated using the third-order Maclaurin series polynomial COMMENT for arcsin. Finally, the implementation undoes any transformations that COMMENT were performed initially. ARG 0 y ARG 2 x METHOD method_15350 clamp (DDD)D ARG 0 value ARG 2 min ARG 4 max METHOD method_15351 floorLog2 (I)I COMMENT {@return floor(log2({@code value}))} COMMENT COMMENT
The vanilla implementation uses the de Bruijn sequence. COMMENT COMMENT @see Integer#numberOfLeadingZeros(int) ARG 0 value COMMENT the input value METHOD method_15352 isPowerOfTwo (I)Z ARG 0 value METHOD method_15353 packRgb (FFF)I ARG 0 r ARG 1 g ARG 2 b METHOD method_15354 idealHash (I)I ARG 0 value METHOD method_15355 sqrt (F)F ARG 0 value METHOD method_15356 angleBetween (FF)F ARG 0 first ARG 1 second METHOD method_15357 floor (D)I ARG 0 value METHOD method_15360 binarySearch (IILjava/util/function/IntPredicate;)I COMMENT Finds the minimum value in {@code [min, max)} that satisfies the COMMENT monotonic {@code predicate}. COMMENT COMMENT
The {@code predicate} must be monotonic, i.e. if for any {@code a}, COMMENT {@code predicate.test(a)} is {@code true}, then for all {@code b > a}, COMMENT {@code predicate.test(b)} must also be {@code true}. COMMENT COMMENT
Examples: COMMENT
For the return value {@code result}, {@code getLerpProgress(value, oldStart, oldEnd)} COMMENT is approximately equal to {@code getLerpProgress(result, newStart, newEnd)} COMMENT (accounting for floating point errors). COMMENT COMMENT @return the mapped value ARG 0 value COMMENT the input value ARG 2 oldStart COMMENT the starting value of the original range ARG 4 oldEnd COMMENT the end value of the original range ARG 6 newStart COMMENT the starting value of the new range ARG 8 newEnd COMMENT the end value of the new range METHOD method_33723 square (D)D ARG 0 n METHOD method_33825 magnitude (DDD)D ARG 0 a ARG 2 b ARG 4 c METHOD method_34945 (Lnet/minecraft/class_243;Lnet/minecraft/class_243;Lnet/minecraft/class_238;)Z ARG 0 origin ARG 1 direction ARG 2 box METHOD method_34954 square (I)I ARG 0 n METHOD method_34956 perlinFadeDerivative (D)D ARG 0 value METHOD method_37166 clampedLerp (FFF)F ARG 0 start ARG 1 end ARG 2 delta METHOD method_37958 clampedMap (FFFFF)F COMMENT Linearly maps a value from one number range to another COMMENT and clamps the result. COMMENT COMMENT @return the mapped value, clamped between {@code newStart} and {@code newEnd} COMMENT @see #map(float, float, float, float, float) the unclamped variant ARG 0 value COMMENT the input value ARG 1 oldStart COMMENT the starting value of the original range ARG 2 oldEnd COMMENT the end value of the original range ARG 3 newStart COMMENT the starting value of the new range ARG 4 newEnd COMMENT the end value of the new range METHOD method_37959 map (FFFFF)F COMMENT Linearly maps a value from one number range to another, unclamped. COMMENT COMMENT
For the return value {@code result}, {@code getLerpProgress(value, oldStart, oldEnd)} COMMENT is approximately equal to {@code getLerpProgress(result, newStart, newEnd)} COMMENT (accounting for floating point errors). COMMENT COMMENT @return the mapped value ARG 0 value COMMENT the input value ARG 1 oldStart COMMENT the starting value of the original range ARG 2 oldEnd COMMENT the end value of the original range ARG 3 newStart COMMENT the starting value of the new range ARG 4 newEnd COMMENT the end value of the new range METHOD method_37960 getLerpProgress (FFF)F ARG 0 value ARG 1 start ARG 2 end METHOD method_38652 square (J)J ARG 0 n METHOD method_38788 ceilDiv (II)I ARG 0 a ARG 1 b METHOD method_38961 roundDownToMultiple (DI)I COMMENT {@return {@code a} rounded down to the nearest multiple of {@code b}} ARG 0 a ARG 2 b METHOD method_39241 hypot (DD)D ARG 0 a ARG 2 b METHOD method_41189 squaredHypot (DD)D ARG 0 a ARG 2 b METHOD method_41190 squaredMagnitude (DDD)D ARG 0 a ARG 2 b ARG 4 c METHOD method_41303 catmullRom (FFFFF)F COMMENT Interpolates a point on a Catmull-Rom Spline. This spline has a property that if there are two COMMENT splines with arguments {@code p0, p1, p2, p3} and {@code p1, p2, p3, p4}, the resulting curve COMMENT will have a continuous first derivative at {@code p2}, where the two input curves connect. For COMMENT higher-dimensional curves, the interpolation on the curve is done component-wise: for COMMENT inputs {@code delta, (p0x, p0y), (p1x, p1y), (p2x, p2y), (p3x, p3y)}, the output is COMMENT {@code (catmullRom(delta, p0x, p1x, p2x, p3x), catmullRom(delta, p0y, p1y, p2y, p3y))}. COMMENT COMMENT @see Cubic Hermite spline (Catmull–Rom spline) ARG 0 delta COMMENT the progress along the interpolation ARG 1 p0 COMMENT the previous data point to assist in curve-smoothing ARG 2 p1 COMMENT the output if {@code delta} is 0 ARG 3 p2 COMMENT the output if {@code delta} is 1 ARG 4 p3 COMMENT the next data point to assist in curve-smoothing METHOD method_42117 stream (IIII)Ljava/util/stream/IntStream; ARG 0 seed ARG 1 lowerBound ARG 2 upperBound ARG 3 steps METHOD method_42118 (IIIII)I ARG 4 i METHOD method_42119 (IIII)Z ARG 3 i METHOD method_42120 stream (III)Ljava/util/stream/IntStream; ARG 0 seed ARG 1 lowerBound ARG 2 upperBound METHOD method_48116 floorDiv (II)I ARG 0 dividend ARG 1 divisor METHOD method_48117 isMultipleOf (II)Z ARG 0 a ARG 1 b METHOD method_48118 inverseSqrt (D)D ARG 0 x METHOD method_48119 inverseSqrt (F)F ARG 0 x METHOD method_48781 lerp (FII)I ARG 0 delta ARG 1 start ARG 2 end METHOD method_52468 lerpAngleDegrees (DDD)D ARG 0 delta ARG 2 start ARG 4 end METHOD method_53062 clamp (JJJ)J ARG 0 value ARG 2 min ARG 4 max METHOD method_53063 lerpPositive (FII)I COMMENT {@return linear interpolation of {@code delta} between {@code start} and {@code end}, COMMENT except that for any positive {@code delta} the value is positive} COMMENT COMMENT
Like {@link #lerp(float, int, int)}, {@code lerpPositive(0, 0, 10)} returns {@code 0}. COMMENT However, if the delta is {@code 0.01f}, the {@code lerp} method would return {@code 0} COMMENT since {@code 0.01 * 10} floored is {@code 0}. This method returns {@code 1} in this COMMENT situation. COMMENT COMMENT @apiNote This is used to calculate redstone comparator output and boss bar percentage. COMMENT COMMENT @see #lerp(float, int, int) ARG 0 delta ARG 1 start ARG 2 end METHOD method_53948 rotateAround (Lorg/joml/Vector3f;Lorg/joml/Quaternionf;Lorg/joml/Quaternionf;)Lorg/joml/Quaternionf; ARG 0 axis ARG 1 rotation ARG 2 result