Bug #28269
CheckPartStorage and StoreCargoPartAtSlot don't work with partial stacks in inventory
0%
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.
History
#1 Updated by gotmachine about 3 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.