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 pRandom, int pHorizontalDistance, int pVerticalDistance) Gets a random position within a certain distance.static BlockPos
generateRandomDirectionWithinRadians
(RandomSource pRandom, int pMaxHorizontalDifference, int pYRange, int pY, double pX, double pZ, double pMaxAngleDelta) static Vec3
generateRandomPos
(Supplier<BlockPos> pPosSupplier, ToDoubleFunction<BlockPos> pToDoubleFunction) Tries 10 times to maximize the return value of the position to double function based on the supplied positionstatic Vec3
generateRandomPos
(PathfinderMob pMob, Supplier<BlockPos> pPosSupplier) static BlockPos
generateRandomPosTowardDirection
(PathfinderMob pMob, int pRange, RandomSource pRandom, BlockPos pPos) static BlockPos
moveUpOutOfSolid
(BlockPos pPos, int pMaxY, Predicate<BlockPos> pPosPredicate) static BlockPos
moveUpToAboveSolid
(BlockPos pPos, int pAboveSolidAmount, int pMaxY, Predicate<BlockPos> pPosPredicate) 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 pRandom, int pHorizontalDistance, int pVerticalDistance) Gets a random position within a certain distance. -
generateRandomDirectionWithinRadians
@Nullable public static BlockPos generateRandomDirectionWithinRadians(RandomSource pRandom, int pMaxHorizontalDifference, int pYRange, int pY, double pX, double pZ, double pMaxAngleDelta) - Parameters:
pMaxHorizontalDifference
- The maximum value in x and z, in absolute value , that could be returned.pYRange
- The range plus or minus the y position to be chosenpY
- The target y positionpX
- The x offset to the target positionpZ
- The z offset to the target positionpMaxAngleDelta
- 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
public static BlockPos moveUpOutOfSolid(BlockPos pPos, int pMaxY, Predicate<BlockPos> pPosPredicate) - Returns:
- the highest above position that is within the provided conditions
-
moveUpToAboveSolid
public static BlockPos moveUpToAboveSolid(BlockPos pPos, int pAboveSolidAmount, int pMaxY, Predicate<BlockPos> pPosPredicate) 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> pPosSupplier, ToDoubleFunction<BlockPos> pToDoubleFunction) 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 pMob, int pRange, RandomSource pRandom, BlockPos pPos) - Returns:
- a random position within range, only if the mob is currently restricted
-