Companion Drones for 2.0


Tired of the lonely factory life? This drone(s) will follow, assist, and protect you, handling construction, repairs, combat, and manage its inventory all by itself. Toggle between building and combat roles on the fly with hotkeys or the shortcut bar, fine-tune its behavior with customizeable options, and toggle between Modes to enable progression over time or to make the mod more suitable for large modpacks like Angels or Bob's. Maintained by Maoman

Content
9 months ago
2.0
11.5K
Logistics Combat

g blueprint paste crash

4 months ago

Received a crash when trying to use a belt balancer blueprint.

Error while running event companion-drones-mjlfix::on_pre_build (ID 9)
LuaItemStack doesn't contain key contents.
stack traceback:
[C]: in function 'index'
__companion-drones-mjlfix
/script/companion.lua:2252: in function <companion-drones-mjlfix/script/companion.lua:2240>
(...tail calls...)
companion-drones-mjlfix/script/companion.lua:2281: in function 'get_blueprint_area'
companion-drones-mjlfix/script/companion.lua:2314: in function 'handler'
core/lualib/event_handler.lua:72: in function <core/lualib/event_handler.lua:70>

4 months ago

+1

Huge lag spike on placing blueprints

4 months ago

+1

4 months ago

I found a work around, first disable auto build of the companion then place the blueprint and turn in back on

4 months ago

Gotcha. I didn’t even have a companion out at the time but that will help others

3 months ago
(updated 3 months ago)

I'm gonna be totally honest with y'all: almost 100% of the blueprint code comes from the original mod author, and it breaks almost every time I poke at it. So, unfortunately, any blueprint related issues are most likely here to stay.

a day ago

Hi MrJakobLaich / Maoman,

I saw the earlier comments here:

  • ashragnorok reported the crash with a belt balancer blueprint
  • Fortheking55 mentioned huge lag spikes when placing blueprints
  • Raukie found the workaround: disable companion auto-build, place the blueprint, then turn it back on
  • Maoman wrote that the blueprint code mostly comes from the original author and tends to break whenever touched

We hit the same crash on Factorio 2.0.77 with companion-drones-mjlfix 3.1.2:

Error while running event companion-drones-mjlfix::on_pre_build (ID 9)
LuaItemStack doesn't contain key contents.

Stacktrace:

companion-drones-mjlfix/script/companion.lua:2252
in get_all_blueprint_entities()
called from get_blueprint_area()
called from on_pre_build

The workaround from Raukie also makes sense with what we saw: the crash only happens when companion construction / auto-build is active and the mod tries to inspect the blueprint in on_pre_build.

We tested a minimal defensive fix on our server. The goal was not to rewrite the fragile blueprint logic, only to avoid the server crash.

Root cause seems to be this line:

for _, item in pairs(blueprint_record.contents) do

That works when the object exposes contents, but crashes when the cursor blueprint/book is represented as a LuaItemStack or item-backed blueprint book.

Our tested fix was:

  1. Add a small helper like get_blueprint_book_children(record).
  2. First try record.contents through pcall.
  3. If that fails, try record.get_inventory(defines.inventory.item_main) and iterate valid inventory slots.
  4. Replace direct blueprint_record.contents iteration with that helper.
  5. Wrap calls to get_all_blueprint_entities() from get_blueprint_area() in pcall, so unknown cursor/blueprint states get ignored instead of crashing the whole server.

After this patch:
- the server no longer crashes on the problematic blueprint
- companion construction still works for our tested case
- if the mod cannot understand a blueprint object, it falls back safely instead of killing the multiplayer session

So this may be a low-risk guard around the existing blueprint code rather than a major blueprint rewrite.

I can provide the exact diff if that helps.

New response