diff options
author | Martin Robertz <dream-master@gmx.net> | 2021-07-23 08:26:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-23 08:26:28 +0200 |
commit | 21af3cfb1f0915d1041c370bd39cf5341e307f58 (patch) | |
tree | 8317554fcf80ab36a0c48c3fdd13d73e8bb98960 /src/main | |
parent | ad85b6950f9693d636ea1867ac388d7c7ed47e73 (diff) | |
parent | cc08b8898a3cdc3a207fe93ff7d2d6b359a66f9b (diff) | |
download | GT5-Unofficial-21af3cfb1f0915d1041c370bd39cf5341e307f58.tar.gz GT5-Unofficial-21af3cfb1f0915d1041c370bd39cf5341e307f58.tar.bz2 GT5-Unofficial-21af3cfb1f0915d1041c370bd39cf5341e307f58.zip |
Merge pull request #600 from repo-alt/experimental
ME Output bus optimization
Diffstat (limited to 'src/main')
3 files changed, 113 insertions, 10 deletions
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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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; + } } 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") |