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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
package gregtech.common.tileentities.machines.multi.purification;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
import static gregtech.api.enums.GTValues.AuthorNotAPenguin;
import static gregtech.api.enums.HatchElement.InputBus;
import static gregtech.api.enums.HatchElement.InputHatch;
import static gregtech.api.enums.HatchElement.OutputHatch;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_GLOW;
import static gregtech.api.util.GTRecipeBuilder.SECONDS;
import static gregtech.api.util.GTStructureUtility.ofFrame;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import com.google.common.collect.ImmutableList;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.Materials;
import gregtech.api.enums.SoundResource;
import gregtech.api.enums.Textures;
import gregtech.api.enums.TierEU;
import gregtech.api.interfaces.IHatchElement;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTEHatch;
import gregtech.api.metatileentity.implementations.MTEHatchInput;
import gregtech.api.metatileentity.implementations.MTEHatchInputBus;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.RecipeMaps;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTStructureUtility;
import gregtech.api.util.GTUtility;
import gregtech.api.util.IGTHatchAdder;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.api.util.shutdown.SimpleShutDownReason;
public class MTEPurificationUnitPhAdjustment extends MTEPurificationUnitBase<MTEPurificationUnitPhAdjustment>
implements ISurvivalConstructable {
private static final String STRUCTURE_PIECE_MAIN = "main";
private static final int STRUCTURE_X_OFFSET = 7;
private static final int STRUCTURE_Y_OFFSET = 4;
private static final int STRUCTURE_Z_OFFSET = 1;
private static final String[][] structure = new String[][] {
// spotless:off
{ "E E E E", "EAAAE EAAAE", "EAGAE EAHAE", "EAGAE EAHAE", "EAGAE EAHAE", "EAAAE EAAAE" },
{ " AAA AAA ", "A A A A", "A A A A", "A A A A", "A ABB~BBA A", "AAAAA AAAAA" },
{ " AXA AYA ", "A A A A", "G A A H", "G ABBBBBA H", "G H", "AAAAABRBRBAAAAA" },
{ " AAA AAA ", "A A A A", "A A A A", "A A A A", "A AIIIIIA A", "AAAAA AAAAA" },
{ "E E E E", "EAAAE EAAAE", "EAGAE EAHAE", "EAGAE EAHAE", "EAGAE EAHAE", "EAAAE EAAAE" } };
// spotless:on
private static final int CASING_INDEX_MIDDLE = getTextureIndex(GregTechAPI.sBlockCasings9, 7);
private static final int CASING_INDEX_TOWER = getTextureIndex(GregTechAPI.sBlockCasings9, 8);
/**
* The current pH value of the water inside the multiblock
*/
private float currentpHValue = 0.0f;
/**
* The multiblock will try to consume catalyst every CONSUME_INTERVAL ticks.
*/
private static final int CONSUME_INTERVAL = 1 * SECONDS;
/**
* Maximum deviation the initial pH value can have away from the neutral value.
*/
private static final float INITIAL_PH_DEVIATION = 2.5f;
/**
* pH value of entirely pH neutral water.
*/
private static final float PH_NEUTRAL_VALUE = 7.0f;
/**
* Maximum deviation from the neutral value that is allowed for the recipe to succeed.
*/
private static final float PH_MAX_DEVIATION = 0.05f;
/**
* Change in pH value for each piece of alkaline dust supplied.
*/
public static final float PH_PER_ALKALINE_DUST = 0.01f;
/**
* Change in pH value for every 10L of acid supplied.
*/
public static final float PH_PER_10_ACID_LITER = -0.01f;
/**
* Alkaline catalyst material
*/
public static final Materials ALKALINE_MATERIAL = Materials.SodiumHydroxide;
/**
* Acidic catalyst material
*/
public static final Materials ACIDIC_MATERIAL = Materials.HydrochloricAcid;
/**
* The input hatch for the acidic material
*/
private MTEHatchInput acidInputHatch;
/**
* The input bus for the alkaline material
*/
private MTEHatchInputBus alkalineInputBus;
/**
* List of all placed sensor hatches in the multi, so we can update them with the proper pH value when it changes.
*/
private final ArrayList<MTEHatchPHSensor> sensorHatches = new ArrayList<>();
private static final IStructureDefinition<MTEPurificationUnitPhAdjustment> STRUCTURE_DEFINITION = StructureDefinition
.<MTEPurificationUnitPhAdjustment>builder()
.addShape(STRUCTURE_PIECE_MAIN, structure)
// Extreme Corrosion Resistant Casing
.addElement('A', ofBlock(GregTechAPI.sBlockCasings9, 8))
// Naquadah Reinforced Water Plant Casing
.addElement('B', ofBlock(GregTechAPI.sBlockCasings9, 7))
.addElement('E', ofFrame(Materials.NaquadahAlloy))
// pH Resistant Glass
.addElement('G', ofBlock(GregTechAPI.sBlockGlass1, 0))
.addElement('H', ofBlock(GregTechAPI.sBlockGlass1, 0))
// Regular I/O hatches
.addElement(
'I',
ofChain(
lazy(
t -> GTStructureUtility.<MTEPurificationUnitPhAdjustment>buildHatchAdder()
.atLeastList(t.getAllowedHatches())
.dot(1)
.casingIndex(CASING_INDEX_MIDDLE)
.build()),
// Naquadah Reinforced Water Plant Casing
ofBlock(GregTechAPI.sBlockCasings9, 7)))
.addElement(
'R',
ofChain(
lazy(
t -> GTStructureUtility.<MTEPurificationUnitPhAdjustment>buildHatchAdder()
.atLeast(SpecialHatchElement.PhSensor)
.dot(2)
.cacheHint(() -> "pH Sensor Hatch")
.casingIndex(CASING_INDEX_MIDDLE)
.build()),
// Naquadah Reinforced Water Plant Casing
ofBlock(GregTechAPI.sBlockCasings9, 7)))
// Special I/O hatches
.addElement(
'X',
lazy(
t -> GTStructureUtility.<MTEPurificationUnitPhAdjustment>buildHatchAdder()
.atLeast(InputBus)
.dot(3)
.adder(MTEPurificationUnitPhAdjustment::addAlkalineBusToMachineList)
.cacheHint(() -> "Input Bus (" + ALKALINE_MATERIAL.mLocalizedName + ")")
.casingIndex(CASING_INDEX_TOWER)
.allowOnly(ForgeDirection.UP)
.build()))
.addElement(
'Y',
lazy(
t -> GTStructureUtility.<MTEPurificationUnitPhAdjustment>buildHatchAdder()
.atLeast(InputHatch)
.dot(4)
.adder(MTEPurificationUnitPhAdjustment::addAcidHatchToMachineList)
.cacheHint(() -> "Input Hatch (" + ACIDIC_MATERIAL.mLocalizedName + ")")
.casingIndex(CASING_INDEX_TOWER)
.allowOnly(ForgeDirection.UP)
.build()))
.build();
private List<IHatchElement<? super MTEPurificationUnitPhAdjustment>> getAllowedHatches() {
return ImmutableList.of(InputHatch, OutputHatch);
}
@Override
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection aFacing,
int colorIndex, boolean aActive, boolean redstoneLevel) {
if (side == aFacing) {
if (aActive) return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_INDEX_MIDDLE),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE)
.extFacing()
.build(),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE_GLOW)
.extFacing()
.glow()
.build() };
return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_INDEX_MIDDLE),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR)
.extFacing()
.build(),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_GLOW)
.extFacing()
.glow()
.build() };
}
return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(CASING_INDEX_MIDDLE) };
}
public MTEPurificationUnitPhAdjustment(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}
public MTEPurificationUnitPhAdjustment(String aName) {
super(aName);
}
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTEPurificationUnitPhAdjustment(this.mName);
}
@Override
public void construct(ItemStack stackSize, boolean hintsOnly) {
buildPiece(
STRUCTURE_PIECE_MAIN,
stackSize,
hintsOnly,
STRUCTURE_X_OFFSET,
STRUCTURE_Y_OFFSET,
STRUCTURE_Z_OFFSET);
}
@Override
public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) {
return survivialBuildPiece(
STRUCTURE_PIECE_MAIN,
stackSize,
STRUCTURE_X_OFFSET,
STRUCTURE_Y_OFFSET,
STRUCTURE_Z_OFFSET,
elementBudget,
env,
true);
}
@Override
public IStructureDefinition<MTEPurificationUnitPhAdjustment> getStructureDefinition() {
return STRUCTURE_DEFINITION;
}
@Override
public RecipeMap<?> getRecipeMap() {
return RecipeMaps.purificationPhAdjustmentRecipes;
}
public boolean addAcidHatchToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
if (aTileEntity == null) return false;
IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
if (aMetaTileEntity == null) return false;
if (aMetaTileEntity instanceof MTEHatchInput) {
((MTEHatch) aMetaTileEntity).updateTexture(aBaseCasingIndex);
((MTEHatchInput) aMetaTileEntity).mRecipeMap = null;
acidInputHatch = (MTEHatchInput) aMetaTileEntity;
return true;
}
return false;
}
public boolean addAlkalineBusToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
if (aTileEntity == null) return false;
IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
if (aMetaTileEntity == null) return false;
if (aMetaTileEntity instanceof MTEHatchInputBus) {
((MTEHatch) aMetaTileEntity).updateTexture(aBaseCasingIndex);
((MTEHatchInputBus) aMetaTileEntity).mRecipeMap = null;
alkalineInputBus = (MTEHatchInputBus) aMetaTileEntity;
return true;
}
return false;
}
public boolean addSensorHatchToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
if (aTileEntity == null) return false;
IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
if (aMetaTileEntity instanceof MTEHatchPHSensor) {
((MTEHatch) aMetaTileEntity).updateTexture(aBaseCasingIndex);
return this.sensorHatches.add((MTEHatchPHSensor) aMetaTileEntity);
}
return false;
}
@Override
protected MultiblockTooltipBuilder createTooltip() {
final MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder();
tt.addMachineType("Purification Unit")
.addInfo(
EnumChatFormatting.AQUA + ""
+ EnumChatFormatting.BOLD
+ "Water Tier: "
+ EnumChatFormatting.WHITE
+ GTUtility.formatNumbers(getWaterTier())
+ EnumChatFormatting.RESET)
.addInfo("Must be linked to a Purification Plant using a data stick to work.")
.addSeparator()
.addInfo(
"Initial pH value every cycle varies from " + EnumChatFormatting.RED
+ (PH_NEUTRAL_VALUE - INITIAL_PH_DEVIATION)
+ EnumChatFormatting.GRAY
+ " - "
+ EnumChatFormatting.RED
+ (PH_NEUTRAL_VALUE + INITIAL_PH_DEVIATION)
+ " pH"
+ EnumChatFormatting.GRAY
+ ".")
.addInfo(
"If the pH value is within " + EnumChatFormatting.RED
+ PH_MAX_DEVIATION
+ " pH "
+ EnumChatFormatting.GRAY
+ "of 7.0 pH at the end of the cycle, the recipe always succeeds.")
.addInfo("Otherwise, the recipe always fails.")
.addInfo("Use a pH Sensor Hatch to read the current pH value.")
.addInfo("For safety, the machine will shut down if the pH goes below 0 or exceeds 14.")
.addSeparator()
.addInfo(
"Every " + EnumChatFormatting.RED
+ CONSUME_INTERVAL
+ EnumChatFormatting.GRAY
+ " ticks, consumes ALL "
+ EnumChatFormatting.WHITE
+ ALKALINE_MATERIAL.mLocalizedName
+ EnumChatFormatting.GRAY
+ " and "
+ EnumChatFormatting.WHITE
+ ACIDIC_MATERIAL.mLocalizedName
+ EnumChatFormatting.GRAY
+ " in the special hatches.")
.addInfo(
EnumChatFormatting.RED + "Raises "
+ EnumChatFormatting.GRAY
+ "the pH value by "
+ EnumChatFormatting.RED
+ PH_PER_ALKALINE_DUST
+ " pH "
+ EnumChatFormatting.GRAY
+ "per piece of "
+ EnumChatFormatting.WHITE
+ ALKALINE_MATERIAL.getDust(1)
.getDisplayName()
+ EnumChatFormatting.GRAY
+ ".")
.addInfo(
EnumChatFormatting.RED + "Lowers "
+ EnumChatFormatting.GRAY
+ "the pH value by "
+ EnumChatFormatting.RED
+ -PH_PER_10_ACID_LITER
+ " pH "
+ EnumChatFormatting.GRAY
+ "per "
+ EnumChatFormatting.RED
+ "10L "
+ EnumChatFormatting.GRAY
+ "of "
+ EnumChatFormatting.WHITE
+ ACIDIC_MATERIAL.getFluid(1L)
.getLocalizedName()
+ EnumChatFormatting.GRAY
+ ".")
.addSeparator()
.addInfo(
EnumChatFormatting.AQUA + ""
+ EnumChatFormatting.ITALIC
+ "The fourth step of water purification is to neutralize the solution and bring its pH to exactly 7, rendering")
.addInfo(
EnumChatFormatting.AQUA + ""
+ EnumChatFormatting.ITALIC
+ "the solution inert with no hydrogen ion activity beyond water’s natural amphiproticity. Acids and bases from soils")
.addInfo(
EnumChatFormatting.AQUA + ""
+ EnumChatFormatting.ITALIC
+ "and geology cause natural alkalinity variations in water which can cause corrosive reactions with sensitive")
.addInfo(
EnumChatFormatting.AQUA + ""
+ EnumChatFormatting.ITALIC
+ "materials. This necessitates the use of the corresponding neutralizing agents to pH balance the water.")
.beginStructureBlock(7, 4, 7, false)
.addCasingInfoExactlyColored(
"Stabilized Naquadah Water Plant Casing",
EnumChatFormatting.GRAY,
16,
EnumChatFormatting.GOLD,
false)
.addCasingInfoExactlyColored(
"Chemical Grade Glass",
EnumChatFormatting.GRAY,
18,
EnumChatFormatting.GOLD,
false)
.addCasingInfoExactlyColored(
"Naquadah Alloy Frame Box",
EnumChatFormatting.GRAY,
48,
EnumChatFormatting.GOLD,
false)
.addCasingInfoExactlyColored(
"Inert Neutralization Water Plant Casing",
EnumChatFormatting.GRAY,
67 * 2,
EnumChatFormatting.GOLD,
false)
.addController("Front center")
.addOtherStructurePart("Input Hatch (Water)", EnumChatFormatting.GOLD + "1+", 1)
.addOtherStructurePart("Output Hatch", EnumChatFormatting.GOLD + "1", 1)
.addOtherStructurePart("pH Sensor Hatch", EnumChatFormatting.GOLD + "2", 2)
.addOtherStructurePart("Input Bus (Sodium Hydroxide)", EnumChatFormatting.GOLD + "1", 3)
.addOtherStructurePart("Input Hatch (Hydrochloric Acid)", EnumChatFormatting.GOLD + "1", 4)
.toolTipFinisher(AuthorNotAPenguin);
return tt;
}
@Override
public void startCycle(int cycleTime, int progressTime) {
super.startCycle(cycleTime, progressTime);
// Randomize initial pH value
ThreadLocalRandom random = ThreadLocalRandom.current();
// Generate random integer in [-RNG_PRECISION, RNG_PRECISION]
final int RNG_PRECISION = 1000;
int rng = random.nextInt(-RNG_PRECISION, RNG_PRECISION);
// Remap to [-1.0, 1.0] and then to [-INITIAL_PH_DEVIATION, INITIAL_PH_DEVIATION]
float deviation = ((float) rng / RNG_PRECISION) * INITIAL_PH_DEVIATION;
// Round to 2 digits
this.currentpHValue = Math.round((PH_NEUTRAL_VALUE + deviation) * 100.0f) / 100.0f;
}
@Override
protected void runMachine(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.runMachine(aBaseMetaTileEntity, aTick);
// Eat all acid and alkaline material every second
if (mMaxProgresstime > 0 && aTick % CONSUME_INTERVAL == 0) {
// Important that we drain backwards, since draining stacks can auto-sort the bus
long totalAlkalineDrained = 0;
for (int i = alkalineInputBus.getSizeInventory() - 1; i >= 0; --i) {
ItemStack stack = alkalineInputBus.getStackInSlot(i);
// If this ItemStack is the alkaline material, drain it entirely and record the amount drained
if (stack != null && stack.isItemEqual(ALKALINE_MATERIAL.getDust(1))) {
totalAlkalineDrained += stack.stackSize;
alkalineInputBus.decrStackSize(i, stack.stackSize);
}
}
// Now do fluid, this is simpler since we only need to bother with one slot
FluidStack stack = acidInputHatch.getDrainableStack();
int numMultiples = 0;
if (stack != null && stack.isFluidEqual(ACIDIC_MATERIAL.getFluid(1))) {
int acidAvailable = stack.amount;
// We only care about multiples of 10, but we still drain all.
numMultiples = Math.floorDiv(acidAvailable, 10);
acidInputHatch.drain(acidAvailable, true);
} else {
// Little easier egg: Fluoroantimonic acid has a pH value of -31, it's an acid so strong it will
// instantly shatter the glass in the structure.
Fluid acid = FluidRegistry.getFluid("fluoroantimonic acid");
if (stack != null && stack.getFluid()
.equals(acid)) {
// TODO: Actually break the glass and trigger achievement lol
}
}
// Adjust pH with to new value
this.currentpHValue = this.currentpHValue + totalAlkalineDrained * PH_PER_ALKALINE_DUST
+ numMultiples * PH_PER_10_ACID_LITER;
// Clamp pH to sensible values
this.currentpHValue = Math.min(Math.max(this.currentpHValue, 0.0f), 14.0f);
// Round to 2 decimals
this.currentpHValue = Math.round(this.currentpHValue * 100.0f) / 100.0f;
// If pH is 0 or 14, stop the machine
if (Math.abs(this.currentpHValue) < 0.001 || Math.abs(this.currentpHValue - 14.0f) < 0.001) {
stopMachine(SimpleShutDownReason.ofNormal("critical_ph_value"));
}
}
}
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
super.onPostTick(aBaseMetaTileEntity, aTimer);
// Update sensor hatch
for (MTEHatchPHSensor hatch : sensorHatches) {
hatch.updateRedstoneOutput(this.currentpHValue);
}
}
@Override
public float calculateFinalSuccessChance() {
// Success chance is 100% when inside target range, 0% otherwise
float distance = Math.abs(this.currentpHValue - PH_NEUTRAL_VALUE);
if (distance <= PH_MAX_DEVIATION) {
return 100.0f;
} else {
return 0.0f;
}
}
@Override
public boolean isCorrectMachinePart(ItemStack aStack) {
return true;
}
@Override
public int getWaterTier() {
return 4;
}
@Override
public long getBasePowerUsage() {
return TierEU.RECIPE_ZPM;
}
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
if (!checkPiece(STRUCTURE_PIECE_MAIN, STRUCTURE_X_OFFSET, STRUCTURE_Y_OFFSET, STRUCTURE_Z_OFFSET)) return false;
// Do not form without positioned hatches
if (acidInputHatch == null || alkalineInputBus == null) return false;
return super.checkMachine(aBaseMetaTileEntity, aStack);
}
@Override
public String[] getInfoData() {
ArrayList<String> infoData = new ArrayList<>(Arrays.asList(super.getInfoData()));
infoData.add("Current pH Value: " + EnumChatFormatting.YELLOW + currentpHValue + " pH");
return infoData.toArray(new String[] {});
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setFloat("mCurrentpH", this.currentpHValue);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
this.currentpHValue = aNBT.getFloat("mCurrentpH");
}
@Override
protected SoundResource getActivitySoundLoop() {
return SoundResource.GT_MACHINES_PURIFICATION_PH_LOOP;
}
private enum SpecialHatchElement implements IHatchElement<MTEPurificationUnitPhAdjustment> {
PhSensor(MTEPurificationUnitPhAdjustment::addSensorHatchToMachineList, MTEHatchPHSensor.class) {
@Override
public long count(MTEPurificationUnitPhAdjustment gtMetaTileEntityPurificationUnitPhAdjustment) {
return gtMetaTileEntityPurificationUnitPhAdjustment.sensorHatches.size();
}
};
private final List<Class<? extends IMetaTileEntity>> mteClasses;
private final IGTHatchAdder<MTEPurificationUnitPhAdjustment> adder;
@SafeVarargs
SpecialHatchElement(IGTHatchAdder<MTEPurificationUnitPhAdjustment> adder,
Class<? extends IMetaTileEntity>... mteClasses) {
this.mteClasses = Collections.unmodifiableList(Arrays.asList(mteClasses));
this.adder = adder;
}
@Override
public List<? extends Class<? extends IMetaTileEntity>> mteClasses() {
return mteClasses;
}
public IGTHatchAdder<? super MTEPurificationUnitPhAdjustment> adder() {
return adder;
}
}
}
|