forked from fnuecke/oc2
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathRobotOperationSide.java
More file actions
50 lines (41 loc) · 1.64 KB
/
RobotOperationSide.java
File metadata and controls
50 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* SPDX-License-Identifier: MIT */
package li.cil.oc2.api.util;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
import javax.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
/**
* A more restrictive version of {@link Side}, intended for robot operation APIs.
*/
public enum RobotOperationSide {
@SerializedName(value="front", alternate={"FRONT", "f"}) FRONT(Direction.SOUTH),
@SerializedName(value="up", alternate={"TOP", "top", "UP", "u"}) UP(Direction.UP),
@SerializedName(value="down", alternate={"BOTTOM", "bottom", "DOWN", "d"}) DOWN(Direction.DOWN),
;
private final Direction direction;
RobotOperationSide(final Direction direction) {
this.direction = direction;
}
RobotOperationSide(final RobotOperationSide parent) {
this(parent.direction);
}
/**
* Gets the world-space direction for the specified side relative to the specified entity.
*
* @param entity the entity to which the side is relative.
* @param side the side to convert to a world-space direction.
* @return a world-space direction.
*/
public static Direction toGlobal(final Entity entity, @Nullable final RobotOperationSide side) {
Direction direction = side == null
? RobotOperationSide.FRONT.direction
: side.direction;
if (direction.getAxis().isHorizontal()) {
final int horizontalIndex = entity.getDirection().get2DDataValue();
for (int i = 0; i < horizontalIndex; i++) {
direction = direction.getClockWise();
}
}
return direction;
}
}