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
|
package gregtech.api.multitileentity.multiblock.base;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.LongStream;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import gregtech.api.enums.GT_Values;
import gregtech.api.logic.ComplexParallelProcessingLogic;
import gregtech.api.logic.interfaces.PollutionLogicHost;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.GT_Waila;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public abstract class ComplexParallelController<T extends ComplexParallelController<T>> extends PowerController<T> {
protected ComplexParallelProcessingLogic processingLogic;
protected int maxComplexParallels = 0;
protected int currentComplexParallels = 0;
protected long[] maxProgressTimes = new long[0];
protected long[] progressTimes = new long[0];
public ComplexParallelController() {
isSimpleMachine = false;
}
protected void setMaxComplexParallels(int parallel) {
if (parallel != maxComplexParallels) {
if (maxComplexParallels != 0) {
stopMachine(false);
}
maxProgressTimes = new long[parallel];
progressTimes = new long[parallel];
}
maxComplexParallels = parallel;
}
@Override
protected void runMachine(long tick) {
if (acceptsFuel() && isActive()) {
if (!consumeFuel()) {
stopMachine(true);
return;
}
}
if (hasThingsToDo()) {
markDirty();
runningTick(tick);
}
if ((tick % TICKS_BETWEEN_RECIPE_CHECKS == 0 || hasWorkJustBeenEnabled() || hasInventoryBeenModified())
&& maxComplexParallels != currentComplexParallels) {
if (isAllowedToWork() && maxComplexParallels > currentComplexParallels) {
wasEnabled = false;
boolean started = false;
for (int i = 0; i < maxComplexParallels; i++) {
if (maxProgressTimes[i] <= 0 && checkRecipe(i)) {
currentComplexParallels++;
started = true;
}
}
if (started) {
setActive(true);
updateSlots();
markDirty();
issueClientUpdate();
}
}
}
}
@Override
protected void runningTick(long tick) {
consumeEnergy();
boolean allStopped = true;
for (int i = 0; i < maxComplexParallels; i++) {
if (maxProgressTimes[i] > 0 && ++progressTimes[i] >= maxProgressTimes[i]) {
progressTimes[i] = 0;
maxProgressTimes[i] = 0;
outputItems(i);
outputFluids(i);
if (isAllowedToWork()) {
if (checkRecipe(i)) {
allStopped = false;
} else {
currentComplexParallels--;
}
}
updateSlots();
} else if (maxProgressTimes[i] > 0) {
allStopped = false;
}
}
if (allStopped) {
setActive(false);
issueClientUpdate();
}
if (this instanceof PollutionLogicHost && tick % POLLUTION_TICK == 0) {
doPollution();
}
emitEnergy();
}
protected boolean checkRecipe(int index) {
ComplexParallelProcessingLogic processingLogic = getComplexProcessingLogic();
if (processingLogic == null || index < 0 || index >= maxComplexParallels) {
return false;
}
processingLogic.clear(index);
boolean result = processingLogic.setInputItems(index, getInputItems(index))
.setInputFluids(index, getInputFluids(index))
.setTileEntity(this)
.setVoidProtection(index, isVoidProtectionEnabledForItem(index), isVoidProtectionEnabledForFluid(index))
.setEut(index, getEutForComplexParallel(index))
.setPerfectOverclock(hasPerfectOverclock())
.process(index);
setDuration(index, processingLogic.getDuration(index));
setEut(processingLogic.getTotalEU());
return result;
}
protected void outputItems(int index) {
ComplexParallelProcessingLogic processingLogic = getComplexProcessingLogic();
if (processingLogic != null && index >= 0 && index < maxComplexParallels) {
outputItems(processingLogic.getOutputItems(index));
}
}
protected void outputFluids(int index) {
ComplexParallelProcessingLogic processingLogic = getComplexProcessingLogic();
if (processingLogic != null && index >= 0 && index < maxComplexParallels) {
outputFluids(processingLogic.getOutputFluids(index));
}
}
protected ComplexParallelProcessingLogic getComplexProcessingLogic() {
return processingLogic;
}
@Override
public boolean hasThingsToDo() {
return LongStream.of(maxProgressTimes)
.sum() > 0;
}
@Override
protected void stopMachine(boolean powerShutDown) {
super.stopMachine(powerShutDown);
for (int i = 0; i < maxComplexParallels; i++) {
maxProgressTimes[i] = 0;
}
}
protected void setDuration(int index, long duration) {
if (duration < 0) {
duration = -duration;
}
if (index >= 0 && index < maxComplexParallels) {
maxProgressTimes[index] = duration;
}
}
protected ItemStack[] getInputItems(int index) {
return getInputItems();
}
protected FluidStack[] getInputFluids(int index) {
return getInputFluids();
}
protected boolean isVoidProtectionEnabledForItem(int index) {
return protectsExcessItem();
}
protected boolean isVoidProtectionEnabledForFluid(int index) {
return protectsExcessFluid();
}
protected boolean hasPerfectOverclock() {
return false;
}
protected long getEutForComplexParallel(int index) {
// As default behavior we'll give the parallel all remaining EU we have
return GT_Values.V[tier] - eut;
}
@Override
protected void addProgressStringToScanner(EntityPlayer player, int logLevel, ArrayList<String> list) {
for (int i = 0; i < maxComplexParallels; i++) {
list.add(
StatCollector.translateToLocal("GT5U.multiblock.Progress") + " "
+ (i + 1)
+ ": "
+ EnumChatFormatting.GREEN
+ GT_Utility.formatNumbers(progressTimes[i] > 20 ? progressTimes[i] / 20 : progressTimes[i])
+ EnumChatFormatting.RESET
+ (progressTimes[i] > 20 ? " s / " : " ticks / ")
+ EnumChatFormatting.YELLOW
+ GT_Utility
.formatNumbers(maxProgressTimes[i] > 20 ? maxProgressTimes[i] / 20 : maxProgressTimes[i])
+ EnumChatFormatting.RESET
+ (maxProgressTimes[i] > 20 ? " s" : " ticks"));
}
}
@Override
public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
int z) {
super.getWailaNBTData(player, tile, tag, world, x, y, z);
tag.setInteger("maxComplexParallels", maxComplexParallels);
for (int i = 0; i < maxComplexParallels; i++) {
tag.setLong("maxProgress" + i, maxProgressTimes[i]);
tag.setLong("progress" + i, progressTimes[i]);
}
}
@Override
public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
super.getWailaBody(itemStack, currentTip, accessor, config);
final NBTTagCompound tag = accessor.getNBTData();
maxComplexParallels = tag.getInteger("maxComplexParallels");
for (int i = 0; i < maxComplexParallels; i++) {
long maxProgress = tag.getLong("maxProgress" + i);
long progress = tag.getLong("progress" + i);
currentTip.add(
"Process " + (i + 1)
+ ": "
+ GT_Waila
.getMachineProgressString(maxProgress > 0 && maxProgress >= progress, maxProgress, progress));
}
}
}
|