Skip to content

Commit 5649a36

Browse files
fix central monitor causing EMI error & fix possible crash (GregTechCEu#3632)
Co-authored-by: jurrejelle <jurre@jilles.com>
1 parent 6fc8095 commit 5649a36

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/main/java/com/gregtechceu/gtceu/common/data/machines/GTMultiMachines.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ public class GTMultiMachines {
11351135
.pattern((definition) -> FactoryBlockPattern.start()
11361136
.aisle("BCB", "BBB", "BBB", "BBB")
11371137
.where('C', Predicates.controller(Predicates.blocks(definition.get())))
1138-
.where('B', CentralMonitorMachine.BLOCK_PREDICATE)
1138+
.where('B', CentralMonitorMachine.getMultiPredicate())
11391139
.build())
11401140
.modelProperty(RecipeLogic.STATUS_PROPERTY, RecipeLogic.Status.IDLE)
11411141
.model(createWorkableCasingMachineModel(

src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CentralMonitorMachine.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ public class CentralMonitorMachine extends WorkableElectricMultiblockMachine
6969
public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(CentralMonitorMachine.class,
7070
WorkableMultiblockMachine.MANAGED_FIELD_HOLDER);
7171

72-
public static TraceabilityPredicate BLOCK_PREDICATE;
73-
7472
@Persisted
7573
@DescSynced
7674
@Getter
@@ -85,10 +83,15 @@ public class CentralMonitorMachine extends WorkableElectricMultiblockMachine
8583

8684
private MultiblockState patternFindingState;
8785

86+
private static TraceabilityPredicate MULTI_PREDICATE = null;
87+
8888
public CentralMonitorMachine(IMachineBlockEntity holder) {
8989
super(holder);
90-
if (BLOCK_PREDICATE == null) {
91-
BLOCK_PREDICATE = Predicates.abilities(PartAbility.INPUT_ENERGY)
90+
}
91+
92+
public static TraceabilityPredicate getMultiPredicate() {
93+
if (MULTI_PREDICATE == null) {
94+
MULTI_PREDICATE = Predicates.abilities(PartAbility.INPUT_ENERGY)
9295
.setMinGlobalLimited(1).setMaxGlobalLimited(2).setPreviewCount(1)
9396
.or(Predicates.abilities(PartAbility.DATA_ACCESS).setPreviewCount(1)
9497
.or(Predicates.machines(GTMachines.BATTERY_BUFFER_4).setPreviewCount(0))
@@ -98,6 +101,7 @@ public CentralMonitorMachine(IMachineBlockEntity holder) {
98101
.or(Predicates.machines(GTMachines.MONITOR))
99102
.or(Predicates.blocks(GTBlocks.CASING_ALUMINIUM_FROSTPROOF.get()));
100103
}
104+
return MULTI_PREDICATE;
101105
}
102106

103107
@Override
@@ -172,7 +176,7 @@ public boolean isValidMonitorBlock(Level level, BlockPos pos) {
172176
if (level.isOutsideBuildHeight(pos)) return false;
173177

174178
MultiblockState state = getPatternFindingState();
175-
if (!state.update(pos, BLOCK_PREDICATE)) {
179+
if (!state.update(pos, getMultiPredicate())) {
176180
return false;
177181
}
178182
state.io = IO.BOTH;
@@ -258,7 +262,7 @@ public BlockPattern getPattern() {
258262

259263
return FactoryBlockPattern.start()
260264
.aisle(aisle)
261-
.where('B', BLOCK_PREDICATE)
265+
.where('B', getMultiPredicate())
262266
.where('C', Predicates.controller(Predicates.blocks(this.getDefinition().get())))
263267
.build();
264268
}
@@ -405,6 +409,8 @@ public Widget createUIWidget() {
405409
label.setOnPressCallback(click -> {
406410
group.getRelativePositions().forEach(pos -> {
407411
BlockPos rel = toRelative(pos);
412+
if (imageButtons.size() - 1 < rel.getY()) return;
413+
if (imageButtons.get(rel.getY()).size() - 1 < rel.getX()) return;
408414
imageButtons.get(rel.getY()).get(rel.getX()).accept(null);
409415
});
410416
if (group.getTargetRaw() != null) {
@@ -500,6 +506,8 @@ public Widget createUIWidget() {
500506
while (it.hasNext()) {
501507
IMonitorComponent c = it.next();
502508
BlockPos rel = toRelative(c.getPos());
509+
if (imageButtons.size() - 1 < rel.getY()) continue;
510+
if (imageButtons.get(rel.getY()).size() - 1 < rel.getX()) continue;
503511
imageButtons.get(rel.getY()).get(rel.getX()).accept(it);
504512
}
505513
if (!selectedTargets.isEmpty()) {

0 commit comments

Comments
 (0)