diff options
Diffstat (limited to 'src/main/java/gregtech/common/tileentities')
2 files changed, 98 insertions, 7 deletions
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") |