-
Notifications
You must be signed in to change notification settings - Fork 497
/
BptBlockPipe.java
202 lines (161 loc) · 6.04 KB
/
BptBlockPipe.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
/**
* Copyright (c) SpaceToad, 2011-2012
* 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.transport.blueprints;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport;
import buildcraft.api.blueprints.BlockSignature;
import buildcraft.api.blueprints.BptBlock;
import buildcraft.api.blueprints.BptSlotInfo;
import buildcraft.api.blueprints.IBptContext;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.TriggerParameter;
import buildcraft.core.Version;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.GateVanilla;
import buildcraft.transport.Pipe;
import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@Deprecated
public class BptBlockPipe extends BptBlock {
public BptBlockPipe(int blockId) {
super(blockId);
}
@Override
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> requirements) {
int pipeId = slot.cpt.getInteger("pipeId");
requirements.add(new ItemStack(pipeId, 1, 0));
if (slot.cpt.hasKey("wire0")) {
requirements.add(new ItemStack(BuildCraftTransport.redPipeWire));
}
if (slot.cpt.hasKey("wire1")) {
requirements.add(new ItemStack(BuildCraftTransport.bluePipeWire));
}
if (slot.cpt.hasKey("wire2")) {
requirements.add(new ItemStack(BuildCraftTransport.greenPipeWire));
}
if (slot.cpt.hasKey("wire3")) {
requirements.add(new ItemStack(BuildCraftTransport.yellowPipeWire));
}
if (slot.cpt.hasKey("gate")) {
int gateId = slot.cpt.getInteger("gate");
if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) {
requirements.add(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1));
} else {
requirements.add(new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1));
}
}
if (BuildCraftCore.itemBptProps[pipeId] != null) {
BuildCraftCore.itemBptProps[pipeId].addRequirements(slot, requirements);
}
}
@Override
public boolean isValid(BptSlotInfo slot, IBptContext context) {
Pipe pipe = BlockGenericPipe.getPipe(context.world(), slot.x, slot.y, slot.z);
if (BlockGenericPipe.isValid(pipe))
return pipe.itemID == slot.cpt.getInteger("pipeId");
else
return false;
}
@Override
public void rotateLeft(BptSlotInfo slot, IBptContext context) {
int pipeId = slot.cpt.getInteger("pipeId");
if (BuildCraftCore.itemBptProps[pipeId] != null) {
BuildCraftCore.itemBptProps[pipeId].rotateLeft(slot, context);
}
}
@Override
public void buildBlock(BptSlotInfo slot, IBptContext context) {
int pipeId = slot.cpt.getInteger("pipeId");
Pipe pipe = BlockGenericPipe.createPipe(pipeId);
for (int i = 0; i < pipe.wireSet.length; ++i)
if (slot.cpt.hasKey("wire" + i)) {
pipe.wireSet[i] = true;
}
if (slot.cpt.hasKey("gate")) {
// / TODO: Does not save/load custom gates
int gateId = slot.cpt.getInteger("gate");
GateVanilla newGate;
if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) {
newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1));
} else {
newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1));
}
pipe.gate = newGate;
for (int i = 0; i < 8; ++i) {
if (slot.cpt.hasKey("trigger" + i)) {
pipe.activatedTriggers[i] = ActionManager.triggers[slot.cpt.getInteger("trigger" + i)];
}
if (slot.cpt.hasKey("triggerParameter" + i)) {
ItemStack s = ItemStack.loadItemStackFromNBT((NBTTagCompound) slot.cpt.getTag("triggerParameter" + i));
if (s != null) {
pipe.triggerParameters[i] = new TriggerParameter();
pipe.triggerParameters[i].set(s);
}
}
if (slot.cpt.hasKey("action" + i)) {
pipe.activatedActions[i] = ActionManager.actions[slot.cpt.getInteger("action" + i)];
}
}
}
BlockGenericPipe.placePipe(pipe, context.world(), slot.x, slot.y, slot.z, slot.blockId, slot.meta);
if (BuildCraftCore.itemBptProps[pipeId] != null) {
BuildCraftCore.itemBptProps[pipeId].buildBlock(slot, context);
}
}
@Override
public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) {
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
if (BlockGenericPipe.isValid(pipe)) {
bptSlot.cpt.setInteger("pipeId", pipe.itemID);
for (int i = 0; i < pipe.wireSet.length; ++i)
if (pipe.wireSet[i]) {
bptSlot.cpt.setInteger("wire" + i, 1);
}
// / TODO: Does not save/load custom gates
if (pipe.hasGate()) {
bptSlot.cpt.setInteger("gate", pipe.gate.kind.ordinal());
if (pipe.gate instanceof GateVanilla) {
bptSlot.cpt.setBoolean("hasPulser", ((GateVanilla) pipe.gate).hasPulser());
}
for (int i = 0; i < 8; ++i) {
if (pipe.activatedTriggers[i] != null) {
bptSlot.cpt.setInteger("trigger" + i, pipe.activatedTriggers[i].getId());
}
if (pipe.triggerParameters[i] != null) {
NBTTagCompound subCpt = new NBTTagCompound();
pipe.triggerParameters[i].getItemStack().writeToNBT(subCpt);
bptSlot.cpt.setTag("triggerParameter" + i, subCpt);
}
if (pipe.activatedActions[i] != null) {
bptSlot.cpt.setInteger("action" + i, pipe.activatedActions[i].getId());
}
}
}
if (BuildCraftCore.itemBptProps[pipe.itemID] != null) {
BuildCraftCore.itemBptProps[pipe.itemID].initializeFromWorld(bptSlot, context, x, y, z);
}
}
}
@Override
public void postProcessing(BptSlotInfo slot, IBptContext context) {
int pipeId = slot.cpt.getInteger("pipeId");
if (BuildCraftCore.itemBptProps[pipeId] != null) {
BuildCraftCore.itemBptProps[pipeId].postProcessing(slot, context);
}
}
@Override
public BlockSignature getSignature(Block block) {
BlockSignature sig = super.getSignature(block);
sig.mod = "BuildCraftTransport";
sig.modVersion = Version.VERSION;
return sig;
}
}