Planet Crucible


Crucible is a high-pressure planet with a crafting chain built around creating metallic hydrogen.

Content
a day ago
2.0
7.70K
Factorio: Space Age Icon Space Age Mod
Planets Transportation Armor Environment Mining Fluids Manufacturing

b table expected, got nil

3 days ago

模组加载失败:planet-crucible/prototypes/item.lua:578: bad argument #1 of 3 to 'insert' (table expected, got nil)
stack traceback:
[C]: in function 'insert'
planet-crucible/prototypes/item.lua:578: in main chunk
[C]: in function 'require'
planet-crucible/data.lua:4: in main chunk

3 days ago

Thanks for reporting! Can you provide the other mods enabled when you get this error?

3 days ago

I wasn't able to reproduce it, but I think I understand enough from just the error message to fix it. Should be fixed with the next update.

3 days ago

thank you ,it has been fixed in 0.5.5

2 days ago

Error while running event planet-crucible::on_entity_died (ID 4)
Unknown item name: cargo-crate-planet-crucible-hydrogen-plate
stack traceback:
[C]: in function 'get_item_count_filtered'
planet-crucible/control-helpers.lua:8: in function 'check_inventory_for_explosion'
planet-crucible/control-helpers.lua:26: in function 'check_inventory_for_explosions'
planet-crucible/control-helpers.lua:40: in function 'check_inventories_for_explosions'
planet-crucible/control.lua:33: in function <planet-crucible/control.lua:32>

The aforementioned error occurred; it is recommended to add an existence check to avoid the error.

2 days ago

i fixed

local mod_data = prototypes.mod_data.planet_crucible_mod_data.data

function ensure_storage_cache_is_setup()
    storage.gps_tag_to_lens_insert_plan = storage.gps_tag_to_lens_insert_plan or {}
end

local function check_inventory_for_explosion(entity, inventory, prototype_name, projectile_name)
    -- 检查物品原型是否存在
    if not prototypes.item[prototype_name] then
        log("Warning: Unknown item name: " .. prototype_name .. " - skipping explosion check")
        return false
    end

    if inventory.get_item_count_filtered({name = prototype_name}) <= 0 then
        return false
    end

    return entity.surface.create_entity({
        name = projectile_name,
        position = entity.position,
        target = entity.position,
        source = entity
    }) ~= nil
end

local function check_inventory_for_explosions(entity, inventory)
    if not inventory then
        return
    end

    -- 添加安全检查
    if not mod_data or not mod_data.items_destroyed_into_huge_explosion then
        return
    end

    for _, prototype_name in pairs(mod_data.items_destroyed_into_huge_explosion) do
        if check_inventory_for_explosion(entity, inventory, prototype_name, "planet-crucible-dummy-entity") then
            return
        end
    end

    if not mod_data.items_destroyed_into_medium_explosion then
        return
    end

    for _, prototype_name in pairs(mod_data.items_destroyed_into_medium_explosion) do
        if check_inventory_for_explosion(entity, inventory, prototype_name, "planet-crucible-explosive-rocket") then
            return
        end
    end
end

function check_inventories_for_explosions(entity)
    -- 添加实体有效性检查
    if not entity or not entity.valid then
        return
    end

    local max_index = entity.get_max_inventory_index()
    if not max_index then
        return
    end

    for i = 1, max_index do
        local inventory = entity.get_inventory(i)
        if inventory and inventory.valid then
            check_inventory_for_explosions(entity, inventory)
        end
    end
end

function get_lens_insert_plan(entity)
    if not entity or not entity.valid or not entity.force.create_ghost_on_entity_death or entity.name ~= "planet-crucible-laser-turret" then
        return
    end

    if entity.item_request_proxy and entity.item_request_proxy.insert_plan then
        return entity.item_request_proxy.insert_plan
    end

    if entity.gps_tag then
        storage.gps_tag_to_lens_insert_plan[entity.gps_tag] = nil
    end

    local inventory = entity.get_inventory(defines.inventory.turret_ammo)
    if not inventory or not inventory.valid or inventory.is_empty() then
        return
    end

    local removal_indices = {}
    if entity.item_request_proxy and entity.item_request_proxy.removal_plan then
        for _, removal_plan in pairs(entity.item_request_proxy.removal_plan) do
            for _, item in pairs(removal_plan.items) do
                if item.in_inventory then
                    removal_indices[item.in_inventory.stack + 1] = true
                end
            end
        end
    end

    local insert_plan = {}
    for i = 1, #inventory do
        if removal_indices[i] or not inventory[i].valid_for_read then
            goto continue
        end

        insert_plan[i] = {
            id = {
                name = inventory[i].name,
                quality = inventory[i].quality.name
            },
            items = {
                in_inventory = {{
                    inventory = defines.inventory.turret_ammo,
                    stack = i - 1,
                    count = inventory[i].count
                }}
            }
        }
        ::continue::
    end

    return insert_plan
end

function update_insert_plan(ghost_or_bp_entity, new_insert_plan)
    if not new_insert_plan or table_size(new_insert_plan) == 0 then
        return false
    end

    local property_name = ((ghost_or_bp_entity.type == "entity-ghost") and "insert_plan") or "items"
    if ghost_or_bp_entity[property_name] then
        for insert_plan in pairs(ghost_or_bp_entity[property_name]) do
            for inventory_position in pairs(insert_plan.in_inventory) do
                if inventory_position.inventory == defines.inventory.turret_ammo then
                    return false
                end
            end
        end
        for insert_plan in pairs(ghost_or_bp_entity[property_name]) do
            table.insert(new_insert_plan, insert_plan)
        end
    end
    ghost_or_bp_entity[property_name] = new_insert_plan
    return true
end

function handle_lens_turret_died(entity)
    if not entity or not entity.valid then
        return
    end

    local insert_plan = get_lens_insert_plan(entity)
    if insert_plan and table_size(insert_plan) > 0 and entity.gps_tag then
        storage.gps_tag_to_lens_insert_plan[entity.gps_tag] = insert_plan
    end
end

function handle_post_lens_turret_died(ghost)
    -- 修复语法错误:应该使用 == 而不是单个 =
    if not ghost or not ghost.valid or ghost.ghost_type ~= "planet-crucible-laser-turret" then
        return
    end

    local stored_insert_plan = storage.gps_tag_to_lens_insert_plan[ghost.gps_tag]
    if not stored_insert_plan then
        return
    end

    storage.gps_tag_to_lens_insert_plan[ghost.gps_tag] = nil
    update_insert_plan(ghost, stored_insert_plan)
end

function add_lenses_to_bp(bp_entities, bp_to_world)
    local was_modified = false
    for i, bp_entity in ipairs(bp_entities) do
        if bp_entity.name ~= "planet-crucible-laser-turret" then
            goto continue
        end

        local entity = bp_to_world[i]
        if not entity or not entity.valid or entity.name ~= "planet-crucible-laser-turret" then
            goto continue
        end

        if update_insert_plan(bp_entity, get_lens_insert_plan(entity)) then
            was_modified = true
        end
        ::continue::
    end
    return was_modified
end

function handle_bplib_extract(event)
    -- Preserve external wire connections
    if remote.call("rigor-module", "is_player_holding_cut_paste_tool", event.player_index) then
        return
    end

    if not event.blueprint then
        return
    end

    local bp_entities = event.blueprint.get_blueprint_entities()
    if not bp_entities then
        return
    end

    if not event.entities or table_size(event.entities) == 0 then
        return
    end

    if add_lenses_to_bp(bp_entities, event.entities) then
        event.blueprint.set_blueprint_entities(bp_entities)
    end
end
2 days ago

Thanks, I'll work on a fix. Any nonexistent item will be removed from the relevant table in the data stage.

a day ago

Should be fixed with v0.5.7.

New response