PathfindingContext .java

net.minecraft.world.level.pathfinder.PathfindingContext (class): members: mobPosition, getPathTypeFromState, mutablePos, cache, getBlockState, level.

net.minecraft.world.level.pathfinderclass44 linescommon1.3 KB

API Surface (4)

PathType getPathTypeFromState(final int x, final int y, final int z)
BlockState getBlockState(final BlockPos pos)
CollisionGetter level()
BlockPos mobPosition()

Fields & Constants (4)

level
cache
mobPosition
mutablePos

Full Source

PathfindingContext.java44 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.pathfinder;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.world.entity.Mob;
6
import net.minecraft.world.level.CollisionGetter;
7
import net.minecraft.world.level.block.state.BlockState;
8
import org.jspecify.annotations.Nullable;
9
10
public class PathfindingContext {
11
	private final CollisionGetter level;
12
	private final @Nullable PathTypeCache cache;
13
	private final BlockPos mobPosition;
14
	private final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
15
16
	public PathfindingContext(final CollisionGetter level, final Mob mob) {
17
		this.level = level;
18
		if (mob.level() instanceof ServerLevel serverLevel) {
19
			this.cache = serverLevel.getPathTypeCache();
20
		} else {
21
			this.cache = null;
22
		}
23
24
		this.mobPosition = mob.blockPosition();
25
	}
26
27
	public PathType getPathTypeFromState(final int x, final int y, final int z) {
28
		BlockPos pos = this.mutablePos.set(x, y, z);
29
		return this.cache == null ? WalkNodeEvaluator.getPathTypeFromState(this.level, pos) : this.cache.getOrCompute(this.level, pos);
30
	}
31
32
	public BlockState getBlockState(final BlockPos pos) {
33
		return this.level.getBlockState(pos);
34
	}
35
36
	public CollisionGetter level() {
37
		return this.level;
38
	}
39
40
	public BlockPos mobPosition() {
41
		return this.mobPosition;
42
	}
43
}
44

Decompiled Minecraft 26.3 source of PathfindingContext (net/minecraft/world/level/pathfinder/PathfindingContext.java) with Mojang official mappings, stored verbatim on the site.