Package net.darkhax.bookshelf.api.util
Class MathsHelper
java.lang.Object
net.darkhax.bookshelf.api.util.MathsHelper
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DecimalFormatA decimal format that only preserves two decimal places. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intadjustToRange(int initial, int min, int max) Takes an integer value and fits it within a range.static Map<net.minecraft.core.Direction,net.minecraft.world.phys.shapes.VoxelShape> createHorizontalShapes(double x1, double y1, double z1, double x2, double y2, double z2) Creates a rotated variant of a voxel shape for each horizontal direction.static intgetAverage(int first, int second) Gets the middle integer between two other integers.static net.minecraft.world.phys.AABBgetBoundsForPixels(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) Creates a bounding box using pixel size.static doublegetDistanceBetweenPoints(net.minecraft.world.phys.Vec3 firstPos, net.minecraft.world.phys.Vec3 secondPos) Calculates the distance between two Vec3 positions.static intgetPercentage(int value, int total) Gets the percentage of an integer.static doublegetPixelDistance(int pixels) Gets the distance in world for an amount of pixels.static booleanisInRange(double min, double max, double value) Checks if a double is within range of two other doubles.static intmultiplyColor(int color, float factor) Multiplies an int packed color and returns a new int packed number.static intnextIntInclusive(Random rand, int min, int max) Used to retrieve a random integer between the two provided integers.static StringprofileNanoTime(long start, long stop) static net.minecraft.world.phys.shapes.VoxelShaperotateShape(net.minecraft.core.Direction facing, double x1, double y1, double z1, double x2, double y2, double z2) Creates a voxel shape that has been rotated a given direction.static doubleround(double value, int places) This method can be used to round a double to a certain amount of places.static booleantryPercentage(double percent) A method which handles the calculating of percentages.
-
Field Details
-
DECIMAL_2
A decimal format that only preserves two decimal places.
-
-
Constructor Details
-
MathsHelper
public MathsHelper()
-
-
Method Details
-
isInRange
public static boolean isInRange(double min, double max, double value) Checks if a double is within range of two other doubles.- Parameters:
min- : The smallest valid value.max- : The largest valid value.value- : The value to check.- Returns:
- boolean: Whether or not the value is within the provided scope.
-
getDistanceBetweenPoints
public static double getDistanceBetweenPoints(net.minecraft.world.phys.Vec3 firstPos, net.minecraft.world.phys.Vec3 secondPos) Calculates the distance between two Vec3 positions.- Parameters:
firstPos- : The first position to work with.secondPos- : The second position to work with.- Returns:
- double: The distance between the two provided locations.
-
round
public static double round(double value, int places) This method can be used to round a double to a certain amount of places.- Parameters:
value- : The double being round.places- : The amount of places to round the double to.- Returns:
- double: The double entered however being rounded to the amount of places specified.
-
nextIntInclusive
Used to retrieve a random integer between the two provided integers. The integers provided are also possible outcomes.- Parameters:
rand- An instance of random.min- The minimum value which can be returned by this method.max- The maximum value which can be returned by this method.- Returns:
- An integer between the min and max, including the min and max.
-
tryPercentage
public static boolean tryPercentage(double percent) A method which handles the calculating of percentages. While this isn't a particularly difficult piece of code, it has been added for the sake of simplicity.- Parameters:
percent- : The percent chance that this method should return true. 1.00 = 100%- Returns:
- boolean: Returns are randomly true or false, based on the suplied percentage.
-
getAverage
public static int getAverage(int first, int second) Gets the middle integer between two other integers. The order is not important.- Parameters:
first- : The first integer.second- : The second integer.- Returns:
- int: The integer that is between the two provided integers.
-
getPercentage
public static int getPercentage(int value, int total) Gets the percentage of an integer. Result is an integer and decimal is lost.- Parameters:
value- The value to get the percentage of.total- The total/max value.- Returns:
- The percentage as an integer.
-
getPixelDistance
public static double getPixelDistance(int pixels) Gets the distance in world for an amount of pixels. A basic block is a cubic meter, and each pixel is 1/16th of a block.- Parameters:
pixels- The amount of pixels- Returns:
- The distance in game for those pixels.
-
getBoundsForPixels
public static net.minecraft.world.phys.AABB getBoundsForPixels(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) Creates a bounding box using pixel size.- Parameters:
minX- The min X pos.minY- The min Y pos.minZ- The min Z pos.maxX- The max X pos.maxY- The max Y pos.maxZ- The max Z pos.- Returns:
- A bounding box that is made to a pixel specific size.
-
adjustToRange
public static int adjustToRange(int initial, int min, int max) Takes an integer value and fits it within a range. If the initial value is less than the minimum it will be set to the minimum. If the initial value is greater than the maximum it will be lowered to the maximum.- Parameters:
initial- The initial value.min- The minimum value.max- The maximum value.- Returns:
- The adjusted value.
-
multiplyColor
public static int multiplyColor(int color, float factor) Multiplies an int packed color and returns a new int packed number.- Parameters:
color- The base color.factor- The value to multiply the color by. Less than 1 will darken. Greater than 1 will lighten.- Returns:
- The resulting color as a packed integer.
-
createHorizontalShapes
public static Map<net.minecraft.core.Direction,net.minecraft.world.phys.shapes.VoxelShape> createHorizontalShapes(double x1, double y1, double z1, double x2, double y2, double z2) Creates a rotated variant of a voxel shape for each horizontal direction. The default/base input is expected to be oriented north.- Parameters:
x1- The min x coordinate.y1- The min y coordinate.z1- The min z coordinate.x2- The max x coordinate.y2- The max y coordinate.z2- The max z coordinate.- Returns:
- A map containing rotated shape variants for each horizontal direction.
-
rotateShape
public static net.minecraft.world.phys.shapes.VoxelShape rotateShape(net.minecraft.core.Direction facing, double x1, double y1, double z1, double x2, double y2, double z2) Creates a voxel shape that has been rotated a given direction. The default/base input is expected to be oriented north. Thanks to Gigaherz for writing the original version of this code.- Parameters:
facing- The direction to rotate the shape.x1- The min x coordinate.y1- The min y coordinate.z1- The min z coordinate.x2- The max x coordinate.y2- The max y coordinate.z2- The max z coordinate.- Returns:
- A voxel shape that has been rotated in the specified direction.
-
profileNanoTime
-