-
Notifications
You must be signed in to change notification settings - Fork 497
/
PatternStairs.java
191 lines (155 loc) · 3.59 KB
/
PatternStairs.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* Copyright (c) SpaceToad, 2011 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.filler.pattern;
import buildcraft.api.core.IBox;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public class PatternStairs extends FillerPattern {
public PatternStairs() {
super("stairs");
}
@Override
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
int xMin = (int) box.pMin().x;
int yMin = (int) box.pMin().y;
int zMin = (int) box.pMin().z;
int xMax = (int) box.pMax().x;
int yMax = (int) box.pMax().y;
int zMax = (int) box.pMax().z;
int sizeX = xMax - xMin + 1;
int sizeZ = zMax - zMin + 1;
int height;
int heightStep;
int dimX = 0;
int dimZ = 0;
if (tile.yCoord <= yMin) {
height = yMin;
heightStep = 1;
} else {
height = yMax;
heightStep = -1;
}
int kind = 0;
int steps[] = new int[]{0, 0, 0, 0};
int x = 0, z = 0;
int stepDiagX = 0, stepDiagZ = 0;
if (tile.xCoord == xMin - 1) {
steps[0] = 1;
} else if (tile.xCoord == xMax + 1) {
steps[1] = 1;
} else if (tile.zCoord == zMin - 1) {
steps[2] = 1;
} else if (tile.zCoord == zMax + 1) {
steps[3] = 1;
} else {
kind = 1;
if (tile.xCoord <= xMin) {
x = xMin;
} else if (tile.xCoord >= xMax) {
x = xMax;
}
if (tile.zCoord <= zMin) {
z = zMin;
} else if (tile.zCoord >= zMax) {
z = zMax;
}
if (heightStep == 1) {
stepDiagX = -1;
dimX = sizeX - 1;
stepDiagZ = -1;
dimZ = sizeZ - 1;
} else {
stepDiagX = 1;
dimX = 0;
stepDiagZ = 1;
dimZ = 0;
}
}
int x1 = 0, x2 = 0, z1 = 0, z2 = 0;
x1 = xMin;
x2 = xMax;
z1 = zMin;
z2 = zMax;
if (heightStep == -1) {
if (steps[0] == 1) {
x1 = xMax - sizeX + 1;
x2 = x1;
}
if (steps[1] == 1) {
x2 = xMin + sizeX - 1;
x1 = x2;
}
if (steps[2] == 1) {
z1 = zMax - sizeZ + 1;
z2 = z1;
}
if (steps[3] == 1) {
z2 = zMin + sizeZ - 1;
z1 = z2;
}
}
if (kind == 0) {
while (x2 - x1 + 1 > 0 && z2 - z1 + 1 > 0 && x2 - x1 < sizeX && z2 - z1 < sizeZ && height >= yMin && height <= yMax) {
if (fill(x1, height, z1, x2, height, z2, stackToPlace, tile.getWorldObj()))
return false;
if (heightStep == 1) {
x1 += steps[0];
x2 -= steps[1];
z1 += steps[2];
z2 -= steps[3];
} else {
x2 += steps[0];
x1 -= steps[1];
z2 += steps[2];
z1 -= steps[3];
}
height += heightStep;
}
} else if (kind == 1) {
while (dimX >= 0 && dimX < sizeX && dimZ >= 0 && dimZ < sizeZ && height >= yMin && height <= yMax) {
if (heightStep == 1) {
if (tile.xCoord >= xMax) {
x1 = x - sizeX + 1;
x2 = x1 + dimX;
} else {
x2 = x + sizeX - 1;
x1 = x2 - dimX;
}
if (tile.zCoord >= zMax) {
z1 = z - sizeZ + 1;
z2 = z1 + dimZ;
} else {
z2 = z + sizeZ - 1;
z1 = z2 - dimZ;
}
} else if (heightStep == -1) {
if (tile.xCoord <= xMin) {
x1 = x;
x2 = x1 + dimX;
} else {
x2 = x;
x1 = x2 - dimX;
}
if (tile.zCoord <= zMin) {
z1 = z;
z2 = z1 + dimZ;
} else {
z2 = z;
z1 = z2 - dimZ;
}
}
if (fill(x1, height, z1, x2, height, z2, stackToPlace, tile.getWorldObj()))
return false;
dimX += stepDiagX;
dimZ += stepDiagZ;
height += heightStep;
}
}
return true;
}
}