Skip to content

Commit 7141fcf

Browse files
Fix Stocking Buses running recipes while offline (#2608)
1 parent 7509825 commit 7141fcf

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityAEHostablePart.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public abstract class MetaTileEntityAEHostablePart<T extends IAEStack<T>> extend
4545
private int meUpdateTick;
4646
protected boolean isOnline;
4747
private boolean allowExtraConnections;
48+
protected boolean meStatusChanged = false;
4849

4950
public MetaTileEntityAEHostablePart(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch,
5051
Class<? extends IStorageChannel<T>> storageChannel) {
@@ -158,6 +159,9 @@ public boolean updateMEStatus() {
158159
if (this.isOnline != isOnline) {
159160
writeCustomData(UPDATE_ONLINE_STATUS, buf -> buf.writeBoolean(isOnline));
160161
this.isOnline = isOnline;
162+
this.meStatusChanged = true;
163+
} else {
164+
this.meStatusChanged = false;
161165
}
162166
}
163167
return this.isOnline;

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEStockingBus.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,22 @@ protected ExportOnlyAEStockingItemList getAEItemHandler() {
6464
@Override
6565
public void update() {
6666
super.update();
67-
if (!getWorld().isRemote && isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
68-
refreshList();
69-
syncME();
67+
if (!getWorld().isRemote) {
68+
if (isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
69+
refreshList();
70+
syncME();
71+
}
72+
73+
// Immediately clear cached items if the status changed, to prevent running recipes while offline
74+
if (this.meStatusChanged && !this.isOnline) {
75+
if (autoPull) {
76+
clearInventory(0);
77+
} else {
78+
for (int i = 0; i < CONFIG_SIZE; i++) {
79+
getAEItemHandler().getInventory()[i].setStack(null);
80+
}
81+
}
82+
}
7083
}
7184
}
7285

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/appeng/MetaTileEntityMEStockingHatch.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,22 @@ protected ExportOnlyAEStockingFluidList getAEFluidHandler() {
6464
@Override
6565
public void update() {
6666
super.update();
67-
if (!getWorld().isRemote && isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
68-
refreshList();
69-
syncME();
67+
if (!getWorld().isRemote) {
68+
if (isWorkingEnabled() && autoPull && getOffsetTimer() % 100 == 0) {
69+
refreshList();
70+
syncME();
71+
}
72+
73+
// Immediately clear cached fluids if the status changed, to prevent running recipes while offline
74+
if (this.meStatusChanged && !this.isOnline) {
75+
if (autoPull) {
76+
this.getAEFluidHandler().clearConfig();
77+
} else {
78+
for (int i = 0; i < CONFIG_SIZE; i++) {
79+
getAEFluidHandler().getInventory()[i].setStack(null);
80+
}
81+
}
82+
}
7083
}
7184
}
7285

0 commit comments

Comments
 (0)