AirAndWaterRandomPos .java

net.minecraft.world.entity.ai.util.AirAndWaterRandomPos (class, 50 lines): members: maxXzRadiansDifference, generateRandomPos, horizontalDist, xDir, zDir.

net.minecraft.world.entity.ai.utilclass50 linescommon1.6 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

Fields & Constants (7)

mob
horizontalDist
verticalDist
flyingHeight
xDir
zDir
maxXzRadiansDifference

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

AirAndWaterRandomPos.java50 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.util;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.world.entity.PathfinderMob;
5
import net.minecraft.world.phys.Vec3;
6
import org.jspecify.annotations.Nullable;
7
8
public class AirAndWaterRandomPos {
9
	public static @Nullable Vec3 getPos(
10
		final PathfinderMob mob,
11
		final int horizontalDist,
12
		final int verticalDist,
13
		final int flyingHeight,
14
		final double xDir,
15
		final double zDir,
16
		final double maxXzRadiansDifference
17
	) {
18
		boolean restrict = GoalUtils.mobRestricted(mob, horizontalDist);
19
		return RandomPos.generateRandomPos(
20
			mob, () -> generateRandomPos(mob, horizontalDist, verticalDist, flyingHeight, xDir, zDir, maxXzRadiansDifference, restrict)
21
		);
22
	}
23
24
	public static @Nullable BlockPos generateRandomPos(
25
		final PathfinderMob mob,
26
		final int horizontalDist,
27
		final int verticalDist,
28
		final int flyingHeight,
29
		final double xDir,
30
		final double zDir,
31
		final double maxXzRadiansDifference,
32
		final boolean restrict
33
	) {
34
		BlockPos direction = RandomPos.generateRandomDirectionWithinRadians(
35
			mob.getRandom(), 0.0, horizontalDist, verticalDist, flyingHeight, xDir, zDir, maxXzRadiansDifference
36
		);
37
		if (direction == null) {
38
			return null;
39
		} else {
40
			BlockPos pos = RandomPos.generateRandomPosTowardDirection(mob, horizontalDist, mob.getRandom(), direction);
41
			if (!GoalUtils.isOutsideLimits(pos, mob) && !GoalUtils.isRestricted(restrict, mob, pos)) {
42
				pos = RandomPos.moveUpOutOfSolid(pos, mob.level().getMaxY(), blockPos -> GoalUtils.isSolid(mob, blockPos));
43
				return GoalUtils.hasMalus(mob, pos) ? null : pos;
44
			} else {
45
				return null;
46
			}
47
		}
48
	}
49
}
50

Decompiled Minecraft 26.3 source of AirAndWaterRandomPos (net/minecraft/world/entity/ai/util/AirAndWaterRandomPos.java) with Mojang official mappings, stored verbatim on the site.