plethora icon indicating copy to clipboard operation
plethora copied to clipboard

Additional item transfer function

Open TheElementalOfDestruction opened this issue 4 years ago • 1 comments

Explanation:

This suggestion is for a function that acts like a sort of combination between inventory.pushItems and inventory.pullItems. It would be defined (in the lua docs) as something like this (with the current name for the function being "pu:

[[function name]](fromName:string, toSlot:int[, limit:int]) -- Pull as many items as 
possible from another inventory into the specified slot in this inventory.

How it works:

First checks to see if toSlot has an items in it. If it is full, the function returns immediately. It might be easiest to just use the metadata value of maxCount but that would be problematic for Black Hole Units and Black Hole Controllers from Industrial Foregoing.

Next, the function should look through the inventory specified by fromName, and essentially do the equivalent of calling pullItems on each non-empty slot until toSlot is at capacity. If an item already exists in toSlot or an item is placed there (but the slot is not full) then the equivalent of doing pullItems should only be done for slots that actually have the specific item.

The function will finally return the number of items moved.

Uses:

The only one I can think of at the moment is inventory compression, making it so that partial itemstacks across chests are easily merged together, reducing the total number of slots used. I'm finding this difficult to do efficiently with just pushItems and pullItems.

Hrmr, I guess an alternative would be to make toSlot optional too, in {push,pull}Items, meaning you can do .pullItems("left", nil, nil, 1) to pull into the first slot. Means we don't need to add a new method, and seems largely consistent with what's there already.

I'm finding this difficult to do efficiently with just pushItems and pullItems.

It should be fairly trivial to do with list - once you know what's in your destination slot and source inventory, you can manually filter the slots to pull from. You could even parallelise it if you really wanted, which often helps a lot.

SquidDev avatar Aug 25 '19 08:08 SquidDev