diff options
author | repo-alt <wvk17@yandex.ru> | 2022-01-14 12:22:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-14 10:22:44 +0100 |
commit | 119de99ec6386aa413480e5dd6a3e815c9fe06f8 (patch) | |
tree | d125e92908b3e1c9fa8155395c61ea3c91ea49f4 | |
parent | a4ad3baca6504fba551adc4011b6616f583b3086 (diff) | |
download | GT5-Unofficial-119de99ec6386aa413480e5dd6a3e815c9fe06f8.tar.gz GT5-Unofficial-119de99ec6386aa413480e5dd6a3e815c9fe06f8.tar.bz2 GT5-Unofficial-119de99ec6386aa413480e5dd6a3e815c9fe06f8.zip |
ME output bus cache refactored (#868)
* Allow toolbox usage for maintenance w/o opening GUI
(Also resolves https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/9044)
* ME output bus cache refactored
Now the bus will infinitely cache items until you connect it to ME network
(this means that any other (overflow) output buses will never receive anything by default)
This behaviour is toggleable by the screwdriver.
3 files changed, 56 insertions, 84 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java index c29cc2c33a..44e3771ab8 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java @@ -1,5 +1,6 @@ package gregtech.api.metatileentity.implementations; +import com.mojang.authlib.GameProfile; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ItemList; @@ -26,6 +27,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.FakePlayer; + import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_AUTOMAINTENANCE; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_AUTOMAINTENANCE_GLOW; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_AUTOMAINTENANCE_IDLE; 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 6b1ee8c941..1ad96087bc 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 @@ -7,6 +7,7 @@ import appeng.api.networking.security.IActionHost; import appeng.api.networking.security.MachineSource; import appeng.api.storage.IMEMonitor; import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; import appeng.api.util.AECableType; import appeng.me.GridAccessException; import appeng.me.helpers.AENetworkProxy; @@ -25,6 +26,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_HATCH; @@ -32,10 +35,11 @@ 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; + IItemList<IAEItemStack> itemCache = GregTech_API.mAE2 ? AEApi.instance().storage().createItemList() : null; long lastOutputTick = 0; long tickCounter = 0; boolean lastOutputFailed = false; + boolean infiniteCache = true; public GT_MetaTileEntity_Hatch_OutputBus_ME(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional, 1, new String[]{ @@ -83,73 +87,10 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc */ @Optional.Method(modid = "appliedenergistics2") public int store(final ItemStack stack) { - if (stack == null) - return 0; - try { - AENetworkProxy proxy = getProxy(); - if (proxy == null) - { - 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; - 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; + if (!infiniteCache && lastOutputFailed) + return stack.stackSize; + itemCache.add(AEApi.instance().storage().createItemStack(stack)); + return 0; } @Optional.Method(modid = "appliedenergistics2") @@ -171,6 +112,14 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc } @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (!getBaseMetaTileEntity().getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide), getBaseMetaTileEntity())) + return; + infiniteCache = !infiniteCache; + GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.infiniteCache." + infiniteCache)); + } + + @Override @Optional.Method(modid = "appliedenergistics2") public AENetworkProxy getProxy() { if (gridProxy == null) { @@ -191,8 +140,6 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc @Optional.Method(modid = "appliedenergistics2") private void flushCachedStack() { - if (cachedStack == null) - return; AENetworkProxy proxy = getProxy(); if (proxy == null) { lastOutputFailed = true; @@ -200,14 +147,17 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc } try { 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(); + for (IAEItemStack s: itemCache) { + if (s.getStackSize() == 0) + continue; + IAEItemStack rest = Platform.poweredInsert(proxy.getEnergy(), sg, s, getRequest()); + if (rest != null && rest.getStackSize() > 0) { + lastOutputFailed = true; + s.setStackSize(rest.getStackSize()); + break; + } + s.setStackSize(0); } - else - cachedStack = null; } catch( final GridAccessException ignored ) { @@ -228,19 +178,36 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); - if (cachedStack != null) { - NBTTagCompound tTag = new NBTTagCompound(); - cachedStack.writeToNBT(tTag); - aNBT.setTag("cachedStack", tTag); + + if (GregTech_API.mAE2) { + NBTTagList items = new NBTTagList(); + for (IAEItemStack s: itemCache) { + if (s.getStackSize() == 0) + continue; + NBTTagCompound tag = new NBTTagCompound(); + s.getItemStack().writeToNBT(tag); + items.appendTag(tag); + } + aNBT.setTag("cachedItems", items); } } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - NBTBase t = aNBT.getTag("cachedStack"); - if (t instanceof NBTTagCompound) - cachedStack = GT_Utility.loadItem((NBTTagCompound)t); + + if (GregTech_API.mAE2) { + NBTBase t = aNBT.getTag("cachedStack"); // legacy + if (t instanceof NBTTagCompound) + itemCache.add(AEApi.instance().storage().createItemStack(GT_Utility.loadItem((NBTTagCompound) t))); + t = aNBT.getTag("cachedItems"); + if (t instanceof NBTTagList) { + NBTTagList l = (NBTTagList)t; + for (int i = 0; i < l.tagCount(); ++i) { + itemCache.add(AEApi.instance().storage().createItemStack(GT_Utility.loadItem(l.getCompoundTagAt(i)))); + } + } + } } public boolean isLastOutputFailed() { diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index daf178e798..e430765d48 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -151,6 +151,8 @@ GT5U.hatch.disableSort.true=Sorting mode: OFF GT5U.hatch.disableSort.false=Sorting mode: ON GT5U.hatch.disableLimited.true=Limiting mode: OFF GT5U.hatch.disableLimited.false=Limiting mode: ON +GT5U.hatch.infiniteCache.true=ME Output bus will infinitely cache item, until you connect it to ME +GT5U.hatch.infiniteCache.false=ME Output bus will stop accepting items when offline for more than 2 seconds GT5U.multiblock.pollution=Pollution reduced to GT5U.multiblock.energy=Stored Energy |