Cargo Crates


Pack large quantities of goods into single-use crates for easier bulk logistics.

Content
3 days ago
2.0
3.33K
Transportation Logistics Logistic network Manufacturing Storage

b [need more data] bug

13 days ago

模组加载失败:cargo_crates/maps.lua:88: attempt to index field '?' (a nil value)
stack traceback:
cargo_crates/maps.lua:88: in function 'loader'
cargo_crates/maps.lua:100: in function 'call_loaders'
cargo_crates/weight.lua:15: in function 'calc'
cargo_crates/data-final-fixes.lua:3: in main chunk

13 days ago

fixed by llm

-- Calculates some other maps/lookup tables for use in weight.lua

local maps = {}

local loaders = {}

-- Add items
table.insert(loaders, function()
local items = {}

for class, _ in pairs(defines.prototypes.item) do
    if data.raw[class] ~= nil then
        for _, item in pairs(data.raw[class]) do
            items[item.name] = item
        end
    end
end

maps.items = items

end)

-- Add fluids
table.insert(loaders, function()
local fluids = {}

for _, fluid in pairs(data.raw.fluid) do
    fluids[fluid.name] = fluid
end

maps.fluids = fluids

end)

-- Add recipes
table.insert(loaders, function()
local recipes = {}

for _, recipe in pairs(data.raw.recipe) do
    recipes[recipe.name] = recipe
end

maps.recipes = recipes

end)

-- Add recipe --> subgroup map(最终加固版)
table.insert(loaders, function()
local recipe_subgroup = {}

local type_to_lookup = {
    item = maps.items,
    fluid = maps.fluids,
}

for _, recipe in pairs(maps.recipes) do
    if recipe.subgroup ~= nil then
        recipe_subgroup[recipe.name] = recipe.subgroup
    elseif recipe.results == nil then
        recipe_subgroup[recipe.name] = "other"
    else
        local assigned = false

        -- 情况1:明确指定了 main_product(且不是空字符串)
        if recipe.main_product and recipe.main_product ~= "" then
            for _, result in pairs(recipe.results) do
                if result.name and result.name == recipe.main_product then
                    local rtype = result.type or "item"
                    local lookup = type_to_lookup[rtype]
                    if lookup and lookup[result.name] and lookup[result.name].subgroup then
                        recipe_subgroup[recipe.name] = lookup[result.name].subgroup
                        assigned = true
                        break
                    end
                end
            end
        end

        -- 情况2:只有一个结果,且有 name
        if not assigned and #recipe.results == 1 then
            local result = recipe.results[1]
            if result.name then
                local rtype = result.type or "item"
                local lookup = type_to_lookup[rtype]
                if lookup and lookup[result.name] and lookup[result.name].subgroup then
                    recipe_subgroup[recipe.name] = lookup[result.name].subgroup
                    assigned = true
                end
            end
        end

        -- 兜底
        if not assigned then
            recipe_subgroup[recipe.name] = "other"
        end
    end
end

maps.recipe_subgroup = recipe_subgroup

end)

-- Mapping of item --> recipes that produce it(同时加固)
table.insert(loaders, function()
local item_to_recipe = {}

for _, item in pairs(maps.items) do
    item_to_recipe[item.name] = {}
end

for _, recipe in pairs(maps.recipes) do
    if recipe.results ~= nil then
        for _, result in pairs(recipe.results) do
            -- 只处理 type 为 item(或未指定 type 默认 item)且有 name 的结果
            if (result.type == "item" or result.type == nil) and result.name then
                if item_to_recipe[result.name] then  -- 额外防护,万一 items 中漏了
                    item_to_recipe[result.name][recipe.name] = true
                end
            end
        end
    end
end

maps.item_to_recipe = item_to_recipe

end)

-- Called at the start of weight calculation to populate maps
maps.call_loaders = function()
for _, loader in pairs(loaders) do
loader()
end
end

return maps

13 days ago

Thats not a fix. Error is caused by load order. I need to know mod combination that causes it in order to fix it

12 days ago

too many mod,maybe just check nil value can fix it,if you want to know ,you can see my own mod

12 days ago
(updated 12 days ago)

It need value to calculate weights. Without it or if you decide to ignore it, it won't be.

It is load order issue

New response