RotationSegment .java

net.minecraft.world.level.block.state.properties.RotationSegment (class): members: convertToDirection, getMaxSegmentIndex, MAX_SEGMENT_INDEX, SOUTH_180.

net.minecraft.world.level.block.state.propertiesclass42 linescommon1.2 KB

API Surface (5)

int getMaxSegmentIndex()
int convertToSegment(final Direction direction)
int convertToSegment(final float rotDegrees)
Optional<Direction> convertToDirection(final int segment)
float convertToDegrees(final int segment)

Fields & Constants (6)

SEGMENTED_ANGLE16
MAX_SEGMENT_INDEX
NORTH_0
EAST_90
SOUTH_180
WEST_270

Code Graph: Dependencies (2)

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

Full Source

RotationSegment.java42 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block.state.properties;
2
3
import java.util.Optional;
4
import net.minecraft.core.Direction;
5
import net.minecraft.util.SegmentedAnglePrecision;
6
7
public class RotationSegment {
8
	private static final SegmentedAnglePrecision SEGMENTED_ANGLE16 = new SegmentedAnglePrecision(4);
9
	private static final int MAX_SEGMENT_INDEX = SEGMENTED_ANGLE16.getMask();
10
	private static final int NORTH_0 = 0;
11
	private static final int EAST_90 = 4;
12
	private static final int SOUTH_180 = 8;
13
	private static final int WEST_270 = 12;
14
15
	public static int getMaxSegmentIndex() {
16
		return MAX_SEGMENT_INDEX;
17
	}
18
19
	public static int convertToSegment(final Direction direction) {
20
		return SEGMENTED_ANGLE16.fromDirection(direction);
21
	}
22
23
	public static int convertToSegment(final float rotDegrees) {
24
		return SEGMENTED_ANGLE16.fromDegrees(rotDegrees);
25
	}
26
27
	public static Optional<Direction> convertToDirection(final int segment) {
28
		Direction result = switch (segment) {
29
			case 0 -> Direction.NORTH;
30
			case 4 -> Direction.EAST;
31
			case 8 -> Direction.SOUTH;
32
			case 12 -> Direction.WEST;
33
			default -> null;
34
		};
35
		return Optional.ofNullable(result);
36
	}
37
38
	public static float convertToDegrees(final int segment) {
39
		return SEGMENTED_ANGLE16.toDegrees(segment);
40
	}
41
}
42

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