Class RandomPos
java.lang.Object
net.minecraft.world.entity.ai.util.RandomPos
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BlockPos
generateRandomDirection
(RandomSource random, int horizontalDistance, int verticalDistance) Gets a random position within a certain distance.static BlockPos
generateRandomDirectionWithinRadians
(RandomSource random, int maxHorizontalDifference, int yRange, int y, double x, double z, double maxAngleDelta) static Vec3
generateRandomPos
(Supplier<BlockPos> posSupplier, ToDoubleFunction<BlockPos> toDoubleFunction) Tries 10 times to maximize the return value of the position to double function based on the supplied positionstatic Vec3
generateRandomPos
(PathfinderMob mob, Supplier<BlockPos> posSupplier) static BlockPos
generateRandomPosTowardDirection
(PathfinderMob mob, int range, RandomSource random, BlockPos pos) static BlockPos
moveUpOutOfSolid
(BlockPos pos, int maxY, Predicate<BlockPos> posPredicate) static BlockPos
moveUpToAboveSolid
(BlockPos pos, int aboveSolidAmount, int maxY, Predicate<BlockPos> posPredicate) Finds a position above based on the conditions.
-
Field Details
-
RANDOM_POS_ATTEMPTS
private static final int RANDOM_POS_ATTEMPTS- See Also:
-
-
Constructor Details
-
RandomPos
public RandomPos()
-
-
Method Details
-
generateRandomDirection
public static BlockPos generateRandomDirection(RandomSource random, int horizontalDistance, int verticalDistance) Gets a random position within a certain distance. -
generateRandomDirectionWithinRadians
@Nullable public static BlockPos generateRandomDirectionWithinRadians(RandomSource random, int maxHorizontalDifference, int yRange, int y, double x, double z, double maxAngleDelta) - Parameters:
maxHorizontalDifference
- The maximum value in x and z, in absolute value, that could be returned.yRange
- The range plus or minus the y position to be choseny
- The target y positionx
- The x offset to the target positionz
- The z offset to the target positionmaxAngleDelta
- The maximum variance of the returned angle, from the base angle being a vector from (0, 0) to (x , z).- Returns:
- a random (x, y, z) coordinate by picking a point (x, z), adding a random angle, up to a difference of
maxAngleDelta
. The y position is randomly chosen from the range[y - yRange, y + yRange]
. Will benull
if the chosen coordinate is outside a distance ofmaxHorizontalDistance
from the origin.
-
moveUpOutOfSolid
- Returns:
- the highest above position that is within the provided conditions
-
moveUpToAboveSolid
public static BlockPos moveUpToAboveSolid(BlockPos pos, int aboveSolidAmount, int maxY, Predicate<BlockPos> posPredicate) Finds a position above based on the conditions. After it finds the position once, it will continue to move up until aboveSolidAmount is reached or the position is no longer valid -
generateRandomPos
-
generateRandomPos
@Nullable public static Vec3 generateRandomPos(Supplier<BlockPos> posSupplier, ToDoubleFunction<BlockPos> toDoubleFunction) Tries 10 times to maximize the return value of the position to double function based on the supplied position -
generateRandomPosTowardDirection
public static BlockPos generateRandomPosTowardDirection(PathfinderMob mob, int range, RandomSource random, BlockPos pos) - Returns:
- a random position within range, only if the mob is currently restricted
-