aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrepo_alt <wvk17@yandex.ru>2021-07-22 12:41:17 +0300
committerrepo_alt <wvk17@yandex.ru>2021-07-22 12:41:17 +0300
commitcc08b8898a3cdc3a207fe93ff7d2d6b359a66f9b (patch)
treedb36775b4cbb358d2650ce4643870f2f514e454b
parent2ea19215d5a003f46a9aa3652bed0b72ffa8e202 (diff)
downloadGT5-Unofficial-cc08b8898a3cdc3a207fe93ff7d2d6b359a66f9b.tar.gz
GT5-Unofficial-cc08b8898a3cdc3a207fe93ff7d2d6b359a66f9b.tar.bz2
GT5-Unofficial-cc08b8898a3cdc3a207fe93ff7d2d6b359a66f9b.zip
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
-rw-r--r--src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java18
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java100
2 files changed, 109 insertions, 9 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;
+ }
}