Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Additional item transfer function #230

Open
TheElementalOfDestruction opened this issue Aug 25, 2019 · 1 comment
Open

Additional item transfer function #230

TheElementalOfDestruction opened this issue Aug 25, 2019 · 1 comment
Labels
enhancement An improvement to an existing feature, or a new one

Comments

@TheElementalOfDestruction

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.

@TheElementalOfDestruction TheElementalOfDestruction added the enhancement An improvement to an existing feature, or a new one label Aug 25, 2019
@SquidDev
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement An improvement to an existing feature, or a new one
Projects
None yet
Development

No branches or pull requests

2 participants