Quadrant .java

com.mojang.math.Quadrant (enum): members: R0, R90, R180, R270, rotateVertexIndex, fromXYZAngles, fromXYAngles, parseJson, rotationZ, rotationX, rotationY.

com.mojang.mathenum65 linescommon2.3 KB

API Surface (4)

Quadrant parseJson(final int degrees)
OctahedralGroup fromXYAngles(final Quadrant xRotation, final Quadrant yRotation)
OctahedralGroup fromXYZAngles(final Quadrant xRotation, final Quadrant yRotation, final Quadrant zRotation)
int rotateVertexIndex(final int index)

Fields & Constants (5)

CODEC
shift
rotationX
rotationY
rotationZ

String literals (2)

"Invalid rotation "
" found, only 0/90/180/270 allowed"

Code Graph: Dependencies (2)

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

Full Source

Quadrant.java65 lines · Minecraft 26.3 · verbatim
1
package com.mojang.math;
2
3
import com.google.gson.JsonParseException;
4
import com.mojang.serialization.Codec;
5
import com.mojang.serialization.DataResult;
6
import net.minecraft.util.Mth;
7
8
public enum Quadrant {
9
	R0(0, OctahedralGroup.IDENTITY, OctahedralGroup.IDENTITY, OctahedralGroup.IDENTITY),
10
	R90(1, OctahedralGroup.BLOCK_ROT_X_90, OctahedralGroup.BLOCK_ROT_Y_90, OctahedralGroup.BLOCK_ROT_Z_90),
11
	R180(2, OctahedralGroup.BLOCK_ROT_X_180, OctahedralGroup.BLOCK_ROT_Y_180, OctahedralGroup.BLOCK_ROT_Z_180),
12
	R270(3, OctahedralGroup.BLOCK_ROT_X_270, OctahedralGroup.BLOCK_ROT_Y_270, OctahedralGroup.BLOCK_ROT_Z_270);
13
14
	public static final Codec<Quadrant> CODEC = Codec.INT.comapFlatMap(degrees -> {
15
		return switch (Mth.positiveModulo(degrees, 360)) {
16
			case 0 -> DataResult.success(R0);
17
			case 90 -> DataResult.success(R90);
18
			case 180 -> DataResult.success(R180);
19
			case 270 -> DataResult.success(R270);
20
			default -> DataResult.error(() -> "Invalid rotation " + degrees + " found, only 0/90/180/270 allowed");
21
		};
22
	}, quadrant -> {
23
		return switch (quadrant) {
24
			case R0 -> 0;
25
			case R90 -> 90;
26
			case R180 -> 180;
27
			case R270 -> 270;
28
		};
29
	});
30
	public final int shift;
31
	public final OctahedralGroup rotationX;
32
	public final OctahedralGroup rotationY;
33
	public final OctahedralGroup rotationZ;
34
35
	Quadrant(final int shift, final OctahedralGroup rotationX, final OctahedralGroup rotationY, final OctahedralGroup rotationZ) {
36
		this.shift = shift;
37
		this.rotationX = rotationX;
38
		this.rotationY = rotationY;
39
		this.rotationZ = rotationZ;
40
	}
41
42
	@Deprecated
43
	public static Quadrant parseJson(final int degrees) {
44
		return switch (Mth.positiveModulo(degrees, 360)) {
45
			case 0 -> R0;
46
			case 90 -> R90;
47
			case 180 -> R180;
48
			case 270 -> R270;
49
			default -> throw new JsonParseException("Invalid rotation " + degrees + " found, only 0/90/180/270 allowed");
50
		};
51
	}
52
53
	public static OctahedralGroup fromXYAngles(final Quadrant xRotation, final Quadrant yRotation) {
54
		return yRotation.rotationY.compose(xRotation.rotationX);
55
	}
56
57
	public static OctahedralGroup fromXYZAngles(final Quadrant xRotation, final Quadrant yRotation, final Quadrant zRotation) {
58
		return zRotation.rotationZ.compose(yRotation.rotationY.compose(xRotation.rotationX));
59
	}
60
61
	public int rotateVertexIndex(final int index) {
62
		return (index + this.shift) % 4;
63
	}
64
}
65

Decompiled Minecraft 26.3 source of Quadrant (com/mojang/math/Quadrant.java) with Mojang official mappings, stored verbatim on the site.