Package tk.airshipcraft.commonlib.utils.math
package tk.airshipcraft.commonlib.utils.math
Provides a comprehensive suite of mathematical utilities tailored for game development in Minecraft. This package includes classes for biased random selection, general math operations, random number generation, raycasting in a Minecraft world, and vector math operations. These utilities are essential for creating immersive and dynamic gameplay experiences in Minecraft plugins.
Classes in this package:
BiasedRandomPicker
: Enables biased random selection of objects based on assigned probabilities, useful for non-uniform random outcomes.Maths
: Offers a collection of general mathematical functions such as clamping, normalization, linear interpolation, and specialized rounding methods.RandomMath
: Provides methods for generating random numbers within specified ranges, including Gaussian distribution and boolean values.RayCast
: Facilitates ray casting in Minecraft, enabling detection of blocks or entities along a line, useful for shooting mechanics, line of sight calculations, and more.VectorMath
: Contains methods for vector mathematical operations including rotation, randomization, and scaling, crucial for managing entity movements and interactions.
Usage Examples:
BiasedRandomPicker:
Map<String, Double> weightMap = Map.of("option1", 0.5, "option2", 0.3, "option3", 0.2);
BiasedRandomPicker<String> picker = new BiasedRandomPicker<>(weightMap);
String randomChoice = picker.getRandom();
System.out.println(randomChoice); // Outputs a randomly chosen option based on weights.
Maths:
int clampedValue = Maths.clamp(15, 0, 10);
System.out.println(clampedValue); // Outputs 10, as it's the max clamp value.
double normalizedValue = Maths.norm(75, 50, 100);
System.out.println(normalizedValue); // Outputs 0.5, halfway between min and max.
RayCast:
RayCast raycaster = new RayCast();
Entity hitEntity = raycaster.raycast(player, player.getDirection(), 100);
if (hitEntity != null) {
System.out.println("Hit: " + hitEntity.getName());
}
These utilities can be combined and used in various aspects of game mechanics, such as AI decision making, user input processing, and environmental interactions.
- Since:
- 1.0
-
ClassesClassDescriptionThis class allows for random selection of objects based on assigned probabilities.A utility class offering a collection of mathematical functions commonly used in game development.Utility class for generating random numbers within specified ranges.Provides functionality to perform ray casts in Minecraft, which is a process of simulating "rays" to detect blocks or entities along a line.Utility class for vector mathematical operations.