PositionAndRotation .java

net.minecraft.core.PositionAndRotation (interface, 84 lines): members: Immutable, immutable, Mutable, xRot, position, yRot, STREAM_CODEC. imports: ByteBuf.

net.minecraft.coreinterface84 linescommon1.9 KB

API Surface (8)

PositionAndRotation immutable()
Vec3 position()
float yRot()
float xRot()
PositionAndRotation immutable()
void set(final Vec3 position, final float yRot, final float xRot)
void addDelta(final Vec3 delta)
void addRotation(final float yRot, final float xRot)

Fields & Constants (1)

STREAM_CODEC

Code Graph: Dependencies (3)

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

Full Source

PositionAndRotation.java84 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.core;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.Objects;
5
import net.minecraft.network.codec.ByteBufCodecs;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.world.phys.Vec3;
8
9
public interface PositionAndRotation {
10
	StreamCodec<ByteBuf, PositionAndRotation> STREAM_CODEC = StreamCodec.composite(
11
		Vec3.STREAM_CODEC,
12
		PositionAndRotation::position,
13
		ByteBufCodecs.FLOAT,
14
		PositionAndRotation::yRot,
15
		ByteBufCodecs.FLOAT,
16
		PositionAndRotation::xRot,
17
		PositionAndRotation::of
18
	);
19
20
	Vec3 position();
21
22
	float yRot();
23
24
	float xRot();
25
26
	PositionAndRotation immutable();
27
28
	default boolean is(final Vec3 position, final float yRot, final float xRot) {
29
		return this.yRot() == yRot && this.xRot() == xRot && Objects.equals(this.position(), position);
30
	}
31
32
	static PositionAndRotation of(final Vec3 position, final float yRot, final float xRot) {
33
		return new PositionAndRotation.Immutable(position, yRot, xRot);
34
	}
35
36
	record Immutable(Vec3 position, float yRot, float xRot) implements PositionAndRotation {
37
		@Override
38
		public PositionAndRotation immutable() {
39
			return this;
40
		}
41
	}
42
43
	class Mutable implements PositionAndRotation {
44
		private Vec3 position = Vec3.ZERO;
45
		private float yRot;
46
		private float xRot;
47
48
		@Override
49
		public Vec3 position() {
50
			return this.position;
51
		}
52
53
		@Override
54
		public float yRot() {
55
			return this.yRot;
56
		}
57
58
		@Override
59
		public float xRot() {
60
			return this.xRot;
61
		}
62
63
		@Override
64
		public PositionAndRotation immutable() {
65
			return PositionAndRotation.of(this.position, this.yRot, this.xRot);
66
		}
67
68
		public void set(final Vec3 position, final float yRot, final float xRot) {
69
			this.position = position;
70
			this.yRot = yRot;
71
			this.xRot = xRot;
72
		}
73
74
		public void addDelta(final Vec3 delta) {
75
			this.position = this.position.add(delta);
76
		}
77
78
		public void addRotation(final float yRot, final float xRot) {
79
			this.yRot += yRot;
80
			this.xRot += xRot;
81
		}
82
	}
83
}
84

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