From 83b5d8703d5f34f17a70f30fa04ce13f41c44afe Mon Sep 17 00:00:00 2001 From: repo_alt Date: Tue, 20 Jul 2021 15:15:58 +0300 Subject: Made digital chest prioritized like partitioned cell --- .../tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java index d78dd722fa..9c8c5faaf9 100644 --- a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java +++ b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java @@ -102,7 +102,10 @@ public abstract class GT_MetaTileEntity_DigitalChestBase extends GT_MetaTileEnti @Optional.Method(modid = "appliedenergistics2") @Override public boolean isPrioritized(appeng.api.storage.data.IAEItemStack iaeItemStack) { - return false; + ItemStack s = getItemStack(); + if (s == null || iaeItemStack == null) + return false; + return iaeItemStack.isSameType(s); } @Optional.Method(modid = "appliedenergistics2") -- cgit From cc08b8898a3cdc3a207fe93ff7d2d6b359a66f9b Mon Sep 17 00:00:00 2001 From: repo_alt Date: Thu, 22 Jul 2021 12:41:17 +0300 Subject: Added caching to the ME output bus, to reduce stress on ME system in high output rate cases Also, added item detector cover support to the bus, so that the item detector will signal "full" in case of ME failure https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/8231 --- .../gregtech/common/covers/GT_Cover_ItemMeter.java | 18 +++- .../GT_MetaTileEntity_Hatch_OutputBus_ME.java | 100 +++++++++++++++++++-- 2 files changed, 109 insertions(+), 9 deletions(-) (limited to 'src/main/java/gregtech/common') diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java index 0bd90745a4..f1c1bc7df7 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java @@ -6,10 +6,13 @@ import gregtech.api.gui.widgets.GT_GuiFakeItemButton; import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase; import net.minecraft.client.gui.GuiButton; @@ -43,13 +46,22 @@ public class GT_Cover_ItemMeter extends GT_CoverBehavior { long tMax = 0; long tUsed = 0; - if (aTileEntity instanceof GT_MetaTileEntity_DigitalChestBase) { - GT_MetaTileEntity_DigitalChestBase dc = (GT_MetaTileEntity_DigitalChestBase)aTileEntity; + IMetaTileEntity mte = ((IGregTechTileEntity)aTileEntity).getMetaTileEntity(); + if (mte instanceof GT_MetaTileEntity_DigitalChestBase) { + GT_MetaTileEntity_DigitalChestBase dc = (GT_MetaTileEntity_DigitalChestBase)mte; tMax = dc.getMaxItemCount(); // currently it is limited by int, but there is not much reason for that ItemStack[] inv = dc.getStoredItemData(); if (inv != null && inv.length > 1 && inv[1] != null) tUsed = inv[1].stackSize; - } else { + } + else if (mte instanceof GT_MetaTileEntity_Hatch_OutputBus_ME) { + if (((GT_MetaTileEntity_Hatch_OutputBus_ME)mte).isLastOutputFailed()) + { + tMax = 64; + tUsed = 64; + } + } + else { int[] tSlots = (aCoverVariable & SLOT_MASK) > 0 ? new int[] {(aCoverVariable & SLOT_MASK) - 1} : aTileEntity.getAccessibleSlotsFromSide(aSide); 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 9b74b979f4..ef3689f64c 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 @@ -21,8 +21,12 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Utility; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_HATCH; @@ -30,6 +34,10 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_HATCH; public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatch_OutputBus { private BaseActionSource requestSource = null; private AENetworkProxy gridProxy = null; + ItemStack cachedStack = null; + long lastOutputTick = 0; + long tickCounter = 0; + boolean lastOutputFailed = false; public GT_MetaTileEntity_Hatch_OutputBus_ME(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional, 1, new String[]{ @@ -82,16 +90,67 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc try { AENetworkProxy proxy = getProxy(); if (proxy == null) - return stack.stackSize; - IMEMonitor sg = proxy.getStorage().getItemInventory(); - IAEItemStack toStore = AEApi.instance().storage().createItemStack(stack); - IAEItemStack rest = Platform.poweredInsert( proxy.getEnergy(), sg, toStore, getRequest()); - if (rest != null) - return (int)rest.getStackSize(); + { + lastOutputFailed = true; + int cacheSize = cachedStack == null ? 0 : cachedStack.stackSize; + cachedStack = null; + return stack.stackSize + cacheSize; + } + if (lastOutputFailed) // if last output failed, don't buffer + { + IMEMonitor sg = proxy.getStorage().getItemInventory(); + IAEItemStack toStore = AEApi.instance().storage().createItemStack(stack); + IAEItemStack rest = Platform.poweredInsert(proxy.getEnergy(), sg, toStore, getRequest()); + if (rest != null && rest.getStackSize() > 0) + return (int) rest.getStackSize(); + else + lastOutputFailed = false; + } + else if (cachedStack != null && ((tickCounter > (lastOutputTick+20)) || !cachedStack.isItemEqual(stack))) + { + lastOutputTick = tickCounter; + boolean sameStack = cachedStack.isItemEqual(stack); + if (sameStack) + cachedStack.stackSize += stack.stackSize; + 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(); + if (sameStack) // return all that was cached to sender + { + cachedStack = null; + return (int) rest.getStackSize(); + } + else // leave the cache, and return input to sender + { + cachedStack.stackSize = (int)rest.getStackSize(); + return stack.stackSize; + } + } + else + { + if (!sameStack) + cachedStack = stack.copy(); + else + cachedStack = null; + return 0; + } + } + else + { + if (cachedStack == null) + cachedStack = stack.copy(); + else + cachedStack.stackSize += stack.stackSize; + } return 0; } catch( final GridAccessException ignored ) { + lastOutputFailed = true; } return stack.stackSize; } @@ -131,4 +190,33 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc @Optional.Method(modid = "appliedenergistics2") public void gridChanged() { } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + tickCounter = aTick; + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) + { + super.saveNBTData(aNBT); + if (cachedStack != null) { + NBTTagCompound tTag = new NBTTagCompound(); + cachedStack.writeToNBT(tTag); + aNBT.setTag("cachedStack", tTag); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + NBTBase t = aNBT.getTag("cachedStack"); + if (t instanceof NBTTagCompound) + cachedStack = GT_Utility.loadItem((NBTTagCompound)t); + } + + public boolean isLastOutputFailed() { + return lastOutputFailed; + } } -- cgit