Project

General

Profile

Bug #28269

CheckPartStorage and StoreCargoPartAtSlot don't work with partial stacks in inventory

Added by goufalite over 2 years ago. Updated over 2 years ago.

Status:
New
Severity:
Low
Assignee:
-
Category:
Modding
Target version:
-
Start date:
07/13/2021
% Done:

0%

Version:
Platform:
Windows
Expansion:
Breaking Ground, Core Game, Making History
Language:
English (US)
Mod Related:
Yes
Votes:
Arrow u r green
Arrow d r red

Description

The CheckPartStorage(craftPart) returns false even if a stack is not complete, the API says "Checks if the part can be stored Without actually storing it.", this is confusing...

StoreCargoPartAtSlot(craftPart, -1) adds the part the next empty slot. But once the inventory has no empty slots but still stackable space it fails, but leaves an error "Unable to store part - there are no free slots. Unable find part with name=evaRepairKit"

How to reproduce :

- grab a part which has some inventory slots (command pod, hitchhiker's pod)
- fill the inventory with 1 eva repair kit

Create a PartModule which can add an eva repair kit using CheckPartStorage and StoreCargoPartAtSlot => see picture, if a free slot is available it will be put in, but if there is no slots available is will not work

Expected :
- CheckPartStorage should return true if a stack is not complete, if the part is stackable and if the max mass/volume is not reached
- StoreCargoPartAtSlot(Part, -1) should add the part to the stack and update the volume, UI, etc...

The workaround is to completely code again the inventory check behavior by looking at each cargo slot, see if it is stackable and doesn't pass the mass/volume limit.

cargoslot.png (433 KB) cargoslot.png goufalite, 07/13/2021 08:49 AM
58249

History

#1 Updated by gotmachine over 2 years ago

The CheckPartStorage() method is a relic of the pre-1.11 inventory implementation and shouldn't be used.
Same applies to the bool StoreCargoPartAtSlot(string partName, int slotIndex) overload
They forgot to mark it as depreciated.

The correct way to spawn a brand new inventory part in 1.11+ is :
AvailablePart ap = PartLoader.getPartInfoByName(partName);
inventory.StoreCargoPartAtSlot(ap.partPrefab, -1);

Note that this won't attempt to fill an existing stack. To achieve that, there is no other way than iterating on the stored parts and checking the quantity vs stackCapacity fields.

Also available in: Atom PDF