NovaEngineering-Source / ModularMachinery-Community-Edition

Customize your machinery with more powerful features.
https://www.curseforge.com/minecraft/mc-mods/modularmachinery-community-edition
GNU General Public License v3.0
28 stars 12 forks source link

[Bug] Item Output Hatches constantly try to output to full Storage Drawer drawers #13

Closed jchung01 closed 1 year ago

jchung01 commented 1 year ago

(Using latest version r31) Item output hatches will try to auto-output to full drawers from the Storage Drawers mod in a laggy way due to Storage Drawer's usage of a "virtual" slot. The reason for the lag is that each slot in the hatch will be replaced by itself unchanged due to being allowed to call setStackInSlotStrict when trying to insert into the virtual slot. This is roughly the explanation:

The performance of the auto-output function of Item Output hatches depends on checking if the inventory's item slot(s) are full. This check does not behave correctly with auto outputting to drawers because these drawers utilize a "virtual" slot at slot 0 that is always empty. When the hatch inserts an item into the virtual slot of a full drawer, the returned notInserted ItemStack will just be returned unchanged. So even though the drawer/its real slot is "full", the hatch does not know that while checking the virtual slot, iterating through the hatch's slots. This means that the hatch is ticking more than it usually would for auto-outputting to a full inventory with the lag scaling off the number of slots in the hatch that have the item.

I believe one workaround would be to add an extra break safeguard against inserts that return the ItemStack unchanged in the internal loop by checking notInserted.getCount() == internalStack.getCount().

Here's a comparison using LagGoggles of an Item Output Hatch's tick time when auto-outputting to a full drawer (indirect fullness due to virtual slot) vs vanilla inventories (can directly check fullness): 2023-04-24_23 46 31 2023-04-24_23 46 42

KasumiNova commented 1 year ago

Thanks for the feedback, I will add this judgment to R32. Also I may plan to rewrite some of the output logic to reduce the performance consumption in some special scenarios.

KasumiNova commented 1 year ago

Fixed in the Release of R32.