-
Notifications
You must be signed in to change notification settings - Fork 497
/
GateVanilla.java
323 lines (275 loc) · 7.63 KB
/
GateVanilla.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package buildcraft.transport;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.transport.IPipe;
import buildcraft.core.DefaultProps;
import buildcraft.core.GuiIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.StringUtil;
import buildcraft.core.utils.Utils;
import buildcraft.transport.pipes.PipePowerWood;
import buildcraft.transport.triggers.ActionEnergyPulser;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class GateVanilla extends Gate {
private EnergyPulser pulser;
public GateVanilla(Pipe pipe) {
super(pipe);
}
public GateVanilla(Pipe pipe, ItemStack stack) {
super(pipe, stack);
if (stack.itemID == BuildCraftTransport.pipeGateAutarchic.shiftedIndex)
addEnergyPulser(pipe);
}
// / SAVING & LOADING
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
if (pulser != null) {
NBTTagCompound nbttagcompoundC = new NBTTagCompound();
pulser.writeToNBT(nbttagcompoundC);
nbttagcompound.setTag("Pulser", nbttagcompoundC);
}
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
// Load pulser if any
if (nbttagcompound.hasKey("Pulser")) {
NBTTagCompound nbttagcompoundP = nbttagcompound.getCompoundTag("Pulser");
addEnergyPulser(pipe);
pulser.readFromNBT(nbttagcompoundP);
}
}
// GUI
@Override
public void openGui(EntityPlayer player) {
if (!CoreProxy.proxy.isRenderWorld(player.worldObj))
player.openGui(BuildCraftTransport.instance, GuiIds.GATES, pipe.worldObj, pipe.xCoord, pipe.yCoord, pipe.zCoord);
}
// / UPDATING
@Override
public void update() {
if (hasPulser())
pulser.update();
}
// / INFORMATION
public boolean hasPulser() {
return pulser != null;
}
@Override
public String getName() {
switch (kind) {
case Single:
return StringUtil.localize("item.pipeGate.0");
case AND_2:
return StringUtil.localize("item.pipeGate.1");
case AND_3:
return StringUtil.localize("item.pipeGate.3");
case AND_4:
return StringUtil.localize("item.pipeGate.5");
case OR_2:
return StringUtil.localize("item.pipeGate.2");
case OR_3:
return StringUtil.localize("item.pipeGate.4");
case OR_4:
return StringUtil.localize("item.pipeGate.6");
default:
return "";
}
}
@Override
public GateConditional getConditional() {
if (kind == GateKind.OR_2 || kind == GateKind.OR_3 || kind == GateKind.OR_4)
return GateConditional.OR;
else if (kind == GateKind.AND_2 || kind == GateKind.AND_3 || kind == GateKind.AND_4)
return GateConditional.AND;
else
return GateConditional.None;
}
/**
* Tries to add an energy pulser to gates that accept energy.
*
* @param pipe
* @return
*/
private boolean addEnergyPulser(Pipe pipe) {
if (!(pipe instanceof IPowerReceptor) || pipe instanceof PipePowerWood){
pulser = new EnergyPulser(null);
return false;
}
pulser = new EnergyPulser((IPowerReceptor) pipe);
return true;
}
/**
* Drops a gate item of the specified kind.
*
* @param kind
* @param world
* @param i
* @param j
* @param k
*/
@Override
public void dropGate(World world, int i, int j, int k) {
int gateDamage = 0;
switch (kind) {
case Single:
gateDamage = 0;
break;
case AND_2:
gateDamage = 1;
break;
case OR_2:
gateDamage = 2;
break;
case AND_3:
gateDamage = 3;
break;
case OR_3:
gateDamage = 4;
break;
case AND_4:
gateDamage = 5;
break;
case OR_4:
default:
gateDamage = 6;
break;
}
Item gateItem;
if (hasPulser())
gateItem = BuildCraftTransport.pipeGateAutarchic;
else
gateItem = BuildCraftTransport.pipeGate;
Utils.dropItems(world, new ItemStack(gateItem, 1, gateDamage), i, j, k);
}
// / ACTIONS
@Override
public void addActions(LinkedList<IAction> list) {
if (pipe.wireSet[IPipe.WireColor.Red.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_2.ordinal())
list.add(BuildCraftTransport.actionRedSignal);
if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_3.ordinal())
list.add(BuildCraftTransport.actionBlueSignal);
if (pipe.wireSet[IPipe.WireColor.Green.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal())
list.add(BuildCraftTransport.actionGreenSignal);
if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal())
list.add(BuildCraftTransport.actionYellowSignal);
if (hasPulser())
list.add(BuildCraftTransport.actionEnergyPulser);
}
@Override
public void startResolution() {
if (hasPulser())
pulser.disablePulse();
}
@Override
public boolean resolveAction(IAction action) {
if (action instanceof ActionEnergyPulser) {
pulser.enablePulse();
return true;
}
return false;
}
// / TRIGGERS
@Override
public void addTrigger(LinkedList<ITrigger> list) {
if (pipe.wireSet[IPipe.WireColor.Red.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_2.ordinal()) {
list.add(BuildCraftTransport.triggerRedSignalActive);
list.add(BuildCraftTransport.triggerRedSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_3.ordinal()) {
list.add(BuildCraftTransport.triggerBlueSignalActive);
list.add(BuildCraftTransport.triggerBlueSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Green.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal()) {
list.add(BuildCraftTransport.triggerGreenSignalActive);
list.add(BuildCraftTransport.triggerGreenSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal()) {
list.add(BuildCraftTransport.triggerYellowSignalActive);
list.add(BuildCraftTransport.triggerYellowSignalInactive);
}
}
// / TEXTURES
@Override
public final int getTexture(boolean isSignalActive) {
boolean isGateActive = isSignalActive;
if (hasPulser() && pulser.isActive())
isGateActive = true;
int n = getTextureRow();
switch (kind) {
case None:
break;
case Single:
if (!isGateActive)
return n * 16 + 12;
else
return n * 16 + 13;
case AND_2:
if (!isGateActive) {
if (hasPulser())
return 9 * 16 + 0;
else
return 6 * 16 + 7;
} else if (hasPulser())
return 9 * 16 + 1;
else
return 6 * 16 + 8;
case OR_2:
if (!isGateActive) {
if (hasPulser())
return 9 * 16 + 2;
else
return 6 * 16 + 9;
} else if (hasPulser())
return 9 * 16 + 3;
else
return 6 * 16 + 10;
case AND_3:
if (!isGateActive)
return n * 16 + 4;
else
return n * 16 + 5;
case OR_3:
if (!isGateActive)
return n * 16 + 6;
else
return n * 16 + 7;
case AND_4:
if (!isGateActive)
return n * 16 + 8;
else
return n * 16 + 9;
case OR_4:
if (!isGateActive)
return n * 16 + 10;
else
return n * 16 + 11;
}
return 0;
}
private int getTextureRow() {
if (hasPulser())
return 9;
else
return 8;
}
@Override
public String getGuiFile() {
if (kind == GateKind.Single)
return DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_1.png";
else if (kind == GateKind.AND_2 || kind == GateKind.OR_2)
return DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_2.png";
else if (kind == GateKind.AND_3 || kind == GateKind.OR_3)
return DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_3.png";
else
return DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_4.png";
}
}