Blueprint Sandboxes


Temporary Editor-lite permissions in Lab-like environments for designing and experimenting.

Content
5 months ago
1.1 - 2.0
108K
Blueprints

b Miniloaders and Upgrade Planner

5 days ago

Hi,

I am maintaining the Miniloader Redux (https://mods.factorio.com/mod/miniloader-redux) mod and I am chasing this bug report with Blueprint Sandboxes: https://github.com/hgschmie/factorio-miniloader-redux/issues/35

I tracked that down to Blueprint sandboxes only firing "script_built" when upgrading. In the normal game, when using the upgrade planner, the game fires "on_robot_mined_entity" on the old entity and then "on_robot_built_entity" to create the upgraded version.

The same when doing a fast replace: First "on_player_mined_entity" is fired for the old entity, then "on_built_entity" for the new entity.

With the Blueprint sandboxes not firing a delete event, the internal state of the miniloader (which consists of multiple, hidden entities) gets confused and as a result, the upgrade fails.

This seems to be tied to the blueprint sandbox intercepting various events (mainly God.Upgrade) and trying to upgrade by doing a fast replace. Unfortunately, create_entity with fast replace does not raise a delete event.

4 days ago

Looking through the mod code, it seems that you try to "emulate" upgrading entities by doing create_entity with fast replace. This does not work, there is a specific method on the LuaEntity for upgrading/fast replacing in your scenario. Replace the "God.Upgrade()" method with this piece of code:

-- Immediately turn one Entity into another
---@param entity LuaEntity
function God.Upgrade(entity)
    if entity.valid and entity.to_be_upgraded() then
        local result = entity.apply_upgrade()

        if result == nil then
            if entity.valid then
                log("Upgrade Failed, Cancelling: " .. entity.name)
                entity.cancel_upgrade(entity.force)
            else
                log("Upgrade Failed, Old Entity Gone too!")
            end
        end
    end
end

to make that work.

New response