Skip to content

Commit b9e8b49

Browse files
authored
Fix the cleanroom multiblock overriding the cleanroom provider set by cleaning hatches. (#2706)
1 parent 219277e commit b9e8b49

File tree

8 files changed

+64
-13
lines changed

8 files changed

+64
-13
lines changed

src/main/java/gregtech/api/metatileentity/WorkableTieredMetaTileEntity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public abstract class WorkableTieredMetaTileEntity extends TieredMetaTileEntity
4747

4848
public final boolean handlesRecipeOutputs;
4949

50+
@Nullable
5051
private ICleanroomProvider cleanroom;
5152

5253
public WorkableTieredMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap,
@@ -210,7 +211,12 @@ public ICleanroomProvider getCleanroom() {
210211
}
211212

212213
@Override
213-
public void setCleanroom(ICleanroomProvider provider) {
214+
public void setCleanroom(@NotNull ICleanroomProvider provider) {
214215
this.cleanroom = provider;
215216
}
217+
218+
@Override
219+
public void unsetCleanroom() {
220+
this.cleanroom = null;
221+
}
216222
}

src/main/java/gregtech/api/metatileentity/multiblock/DummyCleanroom.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ public void setCleanAmount(int amount) {}
6464

6565
@Override
6666
public void adjustCleanAmount(int amount) {}
67+
68+
// Have a higher priority than the cleanroom multiblock (which doesn't override getPriority so it'll return 0)
69+
// doesn't replace the set cleanroom in multiblocks.
70+
@Override
71+
public int getPriority() {
72+
return Integer.MAX_VALUE;
73+
}
6774
}

src/main/java/gregtech/api/metatileentity/multiblock/ICleanroomProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,13 @@ public interface ICleanroomProvider {
4949
* @return the tier {@link gregtech.api.GTValues#V} of energy the cleanroom uses at minimum
5050
*/
5151
int getEnergyTier();
52+
53+
/**
54+
* Get the priority of this cleanroom provider to determine which should be used.
55+
*
56+
* @return the priority this cleanroom provider should have over other cleanrooms.
57+
*/
58+
default int getPriority() {
59+
return 0;
60+
}
5261
}

src/main/java/gregtech/api/metatileentity/multiblock/ICleanroomReceiver.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gregtech.api.metatileentity.multiblock;
22

3+
import org.jetbrains.annotations.NotNull;
34
import org.jetbrains.annotations.Nullable;
45

56
/**
@@ -19,5 +20,11 @@ public interface ICleanroomReceiver {
1920
*
2021
* @param provider the cleanroom to assign to this machine
2122
*/
22-
void setCleanroom(ICleanroomProvider provider);
23+
void setCleanroom(@NotNull ICleanroomProvider provider);
24+
25+
/**
26+
* Set the receiver's reference to null. Use instead of passing {@code null} to
27+
* {@link ICleanroomReceiver#setCleanroom(ICleanroomProvider)}
28+
*/
29+
void unsetCleanroom();
2330
}

src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public abstract class RecipeMapMultiblockController extends MultiblockWithDispla
5151

5252
private boolean isDistinct = false;
5353

54+
@Nullable
5455
private ICleanroomProvider cleanroom;
5556

5657
public RecipeMapMultiblockController(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap) {
@@ -320,7 +321,14 @@ public ICleanroomProvider getCleanroom() {
320321
}
321322

322323
@Override
323-
public void setCleanroom(ICleanroomProvider provider) {
324-
this.cleanroom = provider;
324+
public void setCleanroom(@NotNull ICleanroomProvider provider) {
325+
if (cleanroom == null || provider.getPriority() > cleanroom.getPriority()) {
326+
this.cleanroom = provider;
327+
}
328+
}
329+
330+
@Override
331+
public void unsetCleanroom() {
332+
this.cleanroom = null;
325333
}
326334
}

src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCleanroom.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ public void invalidateStructure() {
150150
resetTileAbilities();
151151
this.cleanroomLogic.invalidate();
152152
this.cleanAmount = MIN_CLEAN_AMOUNT;
153-
cleanroomReceivers.forEach(receiver -> receiver.setCleanroom(null));
153+
cleanroomReceivers.forEach(receiver -> {
154+
if (receiver.getCleanroom() == this) {
155+
receiver.unsetCleanroom();
156+
}
157+
});
154158
cleanroomReceivers.clear();
155159
}
156160

src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,20 @@ public int getItemOutputLimit() {
239239
}
240240

241241
@Override
242-
public void setCleanroom(ICleanroomProvider provider) {
242+
public void setCleanroom(@NotNull ICleanroomProvider provider) {
243243
super.setCleanroom(provider);
244244

245245
// Sync Cleanroom Change to Internal Workable MTE
246246
((ProcessingArrayWorkable) this.recipeMapWorkable).updateCleanroom();
247247
}
248248

249+
@Override
250+
public void unsetCleanroom() {
251+
super.unsetCleanroom();
252+
253+
((ProcessingArrayWorkable) this.recipeMapWorkable).updateCleanroom();
254+
}
255+
249256
@SuppressWarnings("InnerClassMayBeStatic")
250257
protected class ProcessingArrayWorkable extends MultiblockRecipeLogic {
251258

@@ -269,8 +276,8 @@ public void invalidate() {
269276
super.invalidate();
270277

271278
// invalidate mte's cleanroom reference
272-
if (mte != null && mte instanceof ICleanroomReceiver) {
273-
((ICleanroomReceiver) mte).setCleanroom(null);
279+
if (mte != null && mte instanceof ICleanroomReceiver cleanroomMTE) {
280+
cleanroomMTE.unsetCleanroom();
274281
}
275282

276283
// Reset locally cached variables upon invalidation
@@ -284,7 +291,7 @@ public void invalidate() {
284291

285292
/**
286293
* Checks if a provided Recipe Map is valid to be used in the processing array
287-
* Will filter out anything in the config blacklist, and also any non-singleblock machines
294+
* Will filter out anything in the config blacklist, and also any non-single block machines
288295
*
289296
* @param recipeMap The recipeMap to check
290297
* @return {@code true} if the provided recipeMap is valid for use
@@ -360,7 +367,11 @@ private void updateCleanroom() {
360367
receiver.setCleanroom(DUMMY_CLEANROOM);
361368
} else {
362369
ICleanroomProvider provider = ((RecipeMapMultiblockController) metaTileEntity).getCleanroom();
363-
if (provider != null) receiver.setCleanroom(provider);
370+
if (provider == null) {
371+
receiver.unsetCleanroom();
372+
} else {
373+
receiver.setCleanroom(provider);
374+
}
364375
}
365376
}
366377
}

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityCleaningMaintenanceHatch.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
5252
@Override
5353
public void addToMultiBlock(MultiblockControllerBase controllerBase) {
5454
super.addToMultiBlock(controllerBase);
55-
if (controllerBase instanceof ICleanroomReceiver &&
56-
((ICleanroomReceiver) controllerBase).getCleanroom() == null) {
57-
((ICleanroomReceiver) controllerBase).setCleanroom(DUMMY_CLEANROOM);
55+
if (controllerBase instanceof ICleanroomReceiver cleanroomReceiver) {
56+
cleanroomReceiver.setCleanroom(DUMMY_CLEANROOM);
5857
}
5958
}
6059

0 commit comments

Comments
 (0)