|
1 | 1 | package multiteam.multicore_lib.setup.utilities; |
2 | 2 |
|
| 3 | +import net.minecraft.util.math.vector.Vector3f; |
| 4 | + |
3 | 5 | public class MathF { //Why MathF? Because in unity, there was a class with Mathematical functions, and i grown quiet fond of this name. In the honor of my C# past, you shall now be named MathF! |
4 | 6 |
|
5 | | - public float rescaleValues(float minFrom, float maxFrom, float minTo, float maxTo, float valueToScale){ |
| 7 | + /** |
| 8 | + * Calculates a number in between two scales. |
| 9 | + * Useful for minecraft's float values where it uses a scale between 0-1 instead of 0-16 for blocks and such. |
| 10 | + * To a quicker acces to a solution for the problem mentioned above, see BlockToFloatScale() |
| 11 | + **/ |
| 12 | + public static float rescaleValues(float minFrom, float maxFrom, float minTo, float maxTo, float valueToScale){ |
6 | 13 | float OldRange = (maxFrom - minFrom); |
7 | 14 | float NewRange = (maxTo - minTo); |
8 | 15 |
|
9 | 16 | return (((valueToScale - minFrom) * NewRange) / OldRange) + minTo; |
10 | 17 | } |
11 | 18 |
|
| 19 | + /** |
| 20 | + * Used to calculate quickly from 0-16 to 0-1 with less values |
| 21 | + **/ |
| 22 | + public static float BlockToFloatScale(float value){ |
| 23 | + return rescaleValues(0.0f, 16.0f, 0.0f, 1.0f, value); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Does the same as above except with a Vector3f |
| 28 | + **/ |
| 29 | + public static Vector3f BlockToFloatScaleVector3f(Vector3f BlockScaledVector){ |
| 30 | + return new Vector3f(BlockToFloatScale(BlockScaledVector.x()),BlockToFloatScale(BlockScaledVector.y()),BlockToFloatScale(BlockScaledVector.z())); |
| 31 | + } |
| 32 | + |
12 | 33 | } |
0 commit comments