-
Notifications
You must be signed in to change notification settings - Fork 497
/
Gate.java
108 lines (83 loc) · 2.44 KB
/
Gate.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
package buildcraft.transport;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadArrays;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public abstract class Gate {
public static enum GateKind {
None, Single, AND_2, OR_2, AND_3, OR_3, AND_4, OR_4;
public static GateKind getKindFromDamage(ItemStack itemstack) {
switch (itemstack.getItemDamage()) {
case 0:
return Single;
case 1:
return AND_2;
case 2:
return OR_2;
case 3:
return AND_3;
case 4:
return OR_3;
case 5:
return AND_4;
case 6:
return OR_4;
default:
return None;
}
}
}
public static enum GateConditional {
None, AND, OR
}
protected Pipe pipe;
public GateKind kind;
// / CONSTRUCTOR
public Gate(Pipe pipe) {
this.pipe = pipe;
}
public Gate(Pipe pipe, ItemStack stack) {
this.pipe = pipe;
kind = GateKind.getKindFromDamage(stack);
}
// / SAVING & LOADING
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("Kind", kind.ordinal());
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
kind = Gate.GateKind.values()[nbttagcompound.getInteger("Kind")];
}
// / SMP
public PacketPayload toPayload() {
PacketPayloadArrays payload = new PacketPayloadArrays(1, 0, 0);
payload.intPayload[0] = kind.ordinal();
return payload;
}
// GUI
public abstract void openGui(EntityPlayer player);
// / UPDATING
public abstract void update();
public abstract void dropGate();
// / INFORMATION
public abstract String getName();
public abstract GateConditional getConditional();
// / ACTIONS
public abstract void addActions(LinkedList<IAction> list);
public abstract void startResolution();
public abstract boolean resolveAction(IAction action, int count);
// / TRIGGERS
public abstract void addTrigger(LinkedList<ITrigger> list);
// / TEXTURES
public abstract int getTextureIconIndex(boolean isSignalActive);
public abstract ResourceLocation getGuiFile();
public static boolean isGateItem(ItemStack stack) {
return stack.itemID == BuildCraftTransport.pipeGate.itemID || stack.itemID == BuildCraftTransport.pipeGateAutarchic.itemID;
}
}