From 41e3bfddf317ebb56f8c6e0110a0d47db29e1780 Mon Sep 17 00:00:00 2001 From: repo_alt Date: Sat, 24 Jul 2021 11:34:14 +0300 Subject: Missing bit of ME output bus optimization (leftover piece of cached stack gets stuck in the bus) --- .../GT_MetaTileEntity_Hatch_OutputBus_ME.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/common/tileentities') diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java index ef3689f64c..4b6ce12e65 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java @@ -118,7 +118,6 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc if (rest != null && rest.getStackSize() > 0) { lastOutputFailed = true; - cachedStack.stackSize = (int)rest.getStackSize(); if (sameStack) // return all that was cached to sender { cachedStack = null; @@ -191,9 +190,39 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc public void gridChanged() { } + @Optional.Method(modid = "appliedenergistics2") + private void flushCachedStack() + { + if (cachedStack == null) + return; + AENetworkProxy proxy = getProxy(); + if (proxy == null) { + lastOutputFailed = true; + return; + } + try { + IMEMonitor sg = proxy.getStorage().getItemInventory(); + IAEItemStack toStore = AEApi.instance().storage().createItemStack(cachedStack); + IAEItemStack rest = Platform.poweredInsert(proxy.getEnergy(), sg, toStore, getRequest()); + if (rest != null && rest.getStackSize() > 0) { + lastOutputFailed = true; + cachedStack.stackSize = (int) rest.getStackSize(); + } + else + cachedStack = null; + } + catch( final GridAccessException ignored ) + { + lastOutputFailed = true; + } + lastOutputTick = tickCounter; + } + @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { tickCounter = aTick; + if (tickCounter > (lastOutputTick + 40)) + flushCachedStack(); super.onPostTick(aBaseMetaTileEntity, aTick); } -- cgit