Page 1 of 1

InventoryPosition stack position is 0-based in BlueprintInsertPlan

Posted: Mon Oct 28, 2024 7:11 pm
by kajacx
When going through a logistic request's BlueprintInsertPlan, the "stack" slot number in InventoryPosition is 0-indexed, instead of 1-index.

Minimal reproducible example (control.lua):

Code: Select all

script.on_event({ defines.events.on_entity_settings_pasted },
function(event)
    local source = event.source
    local source_modules = source and source.get_module_inventory()
    
    if not source_modules then
        return
    end

    local target_requests = source.surface.find_entities_filtered({
        area = {
            { source.position.x - 0.01, source.position.y - 0.01 },
            { source.position.x + 0.01, source.position.y + 0.01 }
        },
        name = "item-request-proxy",
        force = source.force
    })
    
    for _, request in pairs(target_requests) do
        for _, insert in pairs(request.insert_plan) do
            for _, inserted_item in pairs(insert.items.in_inventory) do
                game.print("Slot " .. inserted_item.stack .. " has " .. insert.id.name)
            end
        end
    end
end)
Resulting output:
Image

Re: InventoryPosition stack position is 0-based in BlueprintInsertPlan

Posted: Thu Oct 31, 2024 6:55 pm
by Rseding91
Thanks for the report. Given these strings are now in every blueprint string that contains modules created since space-age has been released... I suspect they might be stuck this way. I'm going to move this to minor issues unless another developer wants to make an attempt at migrating old strings and changing it for future things.