PositionPath .java

net.minecraft.world.entity.PositionPath (interface): members: endPosition, stepped, Stepped, Linear, Type, STREAM_CODEC, type. imports: ByIdMap, ByteBuf.

net.minecraft.world.entityinterface68 linescommon2.2 KB

API Surface (3)

PositionPath.Type type()
PositionPath.Type type()
StreamCodec<ByteBuf, ? extends PositionPath> streamCodec()

Fields & Constants (1)

STREAM_CODEC

Code Graph: Dependencies (6)

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

Full Source

PositionPath.java68 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.List;
5
import java.util.function.IntFunction;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.util.ByIdMap;
9
import net.minecraft.world.phys.Vec3;
10
11
public sealed interface PositionPath permits PositionPath.Linear, PositionPath.Stepped {
12
	StreamCodec<ByteBuf, PositionPath> STREAM_CODEC = PositionPath.Type.STREAM_CODEC.dispatch(PositionPath::type, PositionPath.Type::streamCodec);
13
14
	Vec3 endPosition();
15
16
	PositionPath.Type type();
17
18
	static PositionPath of(final Vec3 position) {
19
		return new PositionPath.Linear(position);
20
	}
21
22
	static PositionPath stepped(final List<PositionStep> steps) {
23
		return new PositionPath.Stepped(steps);
24
	}
25
26
	record Linear(Vec3 endPosition) implements PositionPath {
27
		public static final StreamCodec<ByteBuf, PositionPath.Linear> STREAM_CODEC = Vec3.STREAM_CODEC
28
			.map(PositionPath.Linear::new, PositionPath.Linear::endPosition);
29
30
		@Override
31
		public PositionPath.Type type() {
32
			return PositionPath.Type.LINEAR;
33
		}
34
	}
35
36
	record Stepped(Vec3 endPosition, List<PositionStep> steps) implements PositionPath {
37
		public static final StreamCodec<ByteBuf, PositionPath.Stepped> STREAM_CODEC = PositionStep.STREAM_CODEC
38
			.apply(ByteBufCodecs.list())
39
			.map(PositionPath.Stepped::new, PositionPath.Stepped::steps);
40
41
		public Stepped(final List<PositionStep> steps) {
42
			this(steps.getLast().position(), steps);
43
		}
44
45
		@Override
46
		public PositionPath.Type type() {
47
			return PositionPath.Type.STEPPED;
48
		}
49
	}
50
51
	enum Type {
52
		LINEAR(PositionPath.Linear.STREAM_CODEC),
53
		STEPPED(PositionPath.Stepped.STREAM_CODEC);
54
55
		public static final IntFunction<PositionPath.Type> BY_ID = ByIdMap.continuous(Enum::ordinal, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
56
		public static final StreamCodec<ByteBuf, PositionPath.Type> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, Enum::ordinal);
57
		private final StreamCodec<ByteBuf, ? extends PositionPath> streamCodec;
58
59
		Type(final StreamCodec<ByteBuf, ? extends PositionPath> streamCodec) {
60
			this.streamCodec = streamCodec;
61
		}
62
63
		public StreamCodec<ByteBuf, ? extends PositionPath> streamCodec() {
64
			return this.streamCodec;
65
		}
66
	}
67
}
68

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