Companion Drones 2.0 [WIP]

by kubiixx

Adds friends - now to Factorio 2.0 WORK IN PROGRESS - crashes may occur - use with caution !

Content
11 days ago
2.0
2.44K

b [FIXED] Blueprint bug 2.0.3

29 days ago

When placing a blueprint from a book, still getting this error :

The mod Companion Drones 2.0 (2.0.3) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event companion-drones::on_pre_build (ID 9)
Record is not a BlueprintRecord.
stack traceback:
[C]: in function 'get_blueprint_entities'
companion-drones/script/companion.lua:1519: in function 'get_blueprint_area'
companion-drones/script/companion.lua:1557: in function 'handler'
core/lualib/event_handler.lua:47: in function <core/lualib/event_handler.lua:45>

29 days ago

Yes I know about this, but looks like what worked in 1.1 is broken
I must find a workaround or better proper solution

28 days ago

I found a workaround. I'll tell you on discord

28 days ago

Thanks for a tip, i have made it little different - when blueprint book is used, calculate the area from largest blueprint in current blueprint book

20 days ago
(updated 20 days ago)

Seems you didn't entirely fix it :

The mod Companion Drones 2.0 (2.0.6) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event companion-drones::on_pre_build (ID 9)
Record is not a BlueprintRecord.
stack traceback:
    [C]: in function 'get_blueprint_entities'
    __companion-drones__/script/companion.lua:1545: in function 'get_blueprint_area'
    __companion-drones__/script/companion.lua:1585: in function 'handler'
    __core__/lualib/event_handler.lua:47: in function <__core__/lualib/event_handler.lua:45>

You didn't take into account the fact that it might be a book within a book ? :3
Or rather, the book in the player's cursor contains not only blueprints but also more books.

Here's how I fixed it :
Before get_blueprint_area, add this function :

local function get_all_blueprint_entities(blueprint_record)
  local entities = {}

  -- Check if the item is a blueprint book
  if blueprint_record.type == "blueprint-book" then
    -- Recursively process each item inside the book
    for _, item in pairs(blueprint_record.contents) do
      local nested_entities = get_all_blueprint_entities(item)
      for _, nested_entity in pairs(nested_entities) do
        table.insert(entities, nested_entity)
      end
    end
  elseif blueprint_record.type == "blueprint" then
    -- Add entities if it's a single blueprint
    local blueprint_entities = blueprint_record.get_blueprint_entities()
    if blueprint_entities then
      for _, entity in pairs(blueprint_entities) do
        table.insert(entities, entity)
      end
    end
  end

  return entities
end

Then edit the elseif of the get_blueprint_area function like so :

elseif player.cursor_record.type == "blueprint-book" then
  local all_entities = get_all_blueprint_entities(player.cursor_record)
  if #all_entities > 0 then
    entities[#entities + 1] = all_entities
  else
    max = dissect_area_size
  end
end
19 days ago

Thank I will implement this in 2.0.7

19 days ago

Should be fixed in 2.0.7 - hope there are no more edge cases like this

New response