SegmentedAnglePrecision .java

net.minecraft.util.SegmentedAnglePrecision (class): members: fromDegreesWithTurns, toDegreesWithTurns, angleToDegree, degreeToAngle, fromDirection, mask.

net.minecraft.utilclass66 linescommon1.7 KB

API Surface (8)

boolean isSameAxis(final int binaryAngleA, final int binaryAngleB)
int fromDirection(final Direction direction)
int fromDegreesWithTurns(final float degrees)
int fromDegrees(final float degrees)
float toDegreesWithTurns(final int binaryAngle)
float toDegrees(final int binaryAngle)
int normalize(final int binaryAngle)
int getMask()

Fields & Constants (4)

mask
precision
degreeToAngle
angleToDegree

String literals (2)

"Precision cannot be less than 2 bits"
"Precision cannot be greater than 30 bits"

Code Graph: Dependencies (1)

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

Full Source

SegmentedAnglePrecision.java66 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util;
2
3
import net.minecraft.core.Direction;
4
5
public class SegmentedAnglePrecision {
6
	private final int mask;
7
	private final int precision;
8
	private final float degreeToAngle;
9
	private final float angleToDegree;
10
11
	public SegmentedAnglePrecision(final int bitPrecision) {
12
		if (bitPrecision < 2) {
13
			throw new IllegalArgumentException("Precision cannot be less than 2 bits");
14
		}
15
16
		if (bitPrecision > 30) {
17
			throw new IllegalArgumentException("Precision cannot be greater than 30 bits");
18
		}
19
20
		int twoPi = 1 << bitPrecision;
21
		this.mask = twoPi - 1;
22
		this.precision = bitPrecision;
23
		this.degreeToAngle = twoPi / 360.0F;
24
		this.angleToDegree = 360.0F / twoPi;
25
	}
26
27
	public boolean isSameAxis(final int binaryAngleA, final int binaryAngleB) {
28
		int semicircleMask = this.getMask() >> 1;
29
		return (binaryAngleA & semicircleMask) == (binaryAngleB & semicircleMask);
30
	}
31
32
	public int fromDirection(final Direction direction) {
33
		if (direction.getAxis().isVertical()) {
34
			return 0;
35
		}
36
37
		int segmentedAngle2bit = direction.get2DDataValue();
38
		return segmentedAngle2bit << this.precision - 2;
39
	}
40
41
	public int fromDegreesWithTurns(final float degrees) {
42
		return Math.round(degrees * this.degreeToAngle);
43
	}
44
45
	public int fromDegrees(final float degrees) {
46
		return this.normalize(this.fromDegreesWithTurns(degrees));
47
	}
48
49
	public float toDegreesWithTurns(final int binaryAngle) {
50
		return binaryAngle * this.angleToDegree;
51
	}
52
53
	public float toDegrees(final int binaryAngle) {
54
		float degrees = this.toDegreesWithTurns(this.normalize(binaryAngle));
55
		return degrees >= 180.0F ? degrees - 360.0F : degrees;
56
	}
57
58
	public int normalize(final int binaryAngle) {
59
		return binaryAngle & this.mask;
60
	}
61
62
	public int getMask() {
63
		return this.mask;
64
	}
65
}
66

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