-
Notifications
You must be signed in to change notification settings - Fork 497
/
SchematicRotateMeta.java
72 lines (60 loc) · 1.62 KB
/
SchematicRotateMeta.java
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.builders.schematics;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicTile;
public class SchematicRotateMeta extends SchematicTile {
int[] rot;
boolean rotateForward;
int infoMask = 0;
public SchematicRotateMeta(int[] rotations, boolean rotateForward) {
rot = rotations;
for (int element : rot) {
if (element < 4) {
infoMask = (infoMask < 3 ? 3 : infoMask);
} else if (element < 8) {
infoMask = (infoMask < 7 ? 7 : infoMask);
} else if (element < 16) {
infoMask = (infoMask < 15 ? 15 : infoMask);
}
}
this.rotateForward = rotateForward;
}
@Override
public boolean isValid(IBuilderContext context, int x, int y, int z) {
return block == context.world().getBlock(x, y, z);
}
@Override
public void rotateLeft(IBuilderContext context) {
int pos = meta & infoMask;
int others = meta - pos;
if (rotateForward) {
if (pos == rot[0]) {
pos = rot[1];
} else if (pos == rot[1]) {
pos = rot[2];
} else if (pos == rot[2]) {
pos = rot[3];
} else if (pos == rot[3]) {
pos = rot[0];
}
} else {
if (pos == rot[0]) {
pos = rot[3];
} else if (pos == rot[1]) {
pos = rot[2];
} else if (pos == rot[2]) {
pos = rot[0];
} else if (pos == rot[3]) {
pos = rot[1];
}
}
meta = pos + others;
}
}