Page 1 of 1

Edit blueprint in a mod

Posted: Sun Nov 03, 2019 2:43 pm
by Hermios
Hi
Is that possible to edit a blueprint in a mod (add, delete, modify or replace elements etc.)? If yes, how?
Thanks

Niko

Re: Edit blueprint in a mod

Posted: Mon Nov 04, 2019 11:00 am
by mrvn
Short answere: yes.

There are events for when a blueprint is created where you can modify things before they are encoded as a blueprint. Just search the list of events in the API for blueprint.

There are also mods that modify a blueprint later. No idea how but you can look there for how to do it. For example https://mods.factorio.com/mod/LandfillEverything

Re: Edit blueprint in a mod

Posted: Tue Nov 05, 2019 8:17 am
by darkfrei
mrvn wrote: Mon Nov 04, 2019 11:00 am There are events for when a blueprint is created where you can modify things before they are encoded as a blueprint. Just search the list of events in the API for blueprint.
So if I have placeholder entity and I replace it with the another one, theoretically I can choose with the BluePrint the last one, but get the first one?
For example https://mods.factorio.com/mod/BurnerOffshorePump
Here is the pump (placeholder), they can define where the player can place the pump, but than I replace it with the assembling machine with recipe "water". How can I make them blueprintable?

Re: Edit blueprint in a mod

Posted: Thu Nov 07, 2019 10:47 am
by mrvn
Setting the mining placed by field isn't enough?

Re: Edit blueprint in a mod

Posted: Thu Nov 07, 2019 11:31 am
by darkfrei
mrvn wrote: Thu Nov 07, 2019 10:47 am Setting the mining placed by field isn't enough?
Can you please provide an example?

Re: Edit blueprint in a mod

Posted: Thu Nov 07, 2019 11:34 am
by DaveMcW

Code: Select all

entity.placeable_by = item.name
entity.minable.result = item.name

Re: Edit blueprint in a mod

Posted: Thu Nov 07, 2019 9:29 pm
by darkfrei
DaveMcW wrote: Thu Nov 07, 2019 11:34 am

Code: Select all

entity.placeable_by = item.name
entity.minable.result = item.name
By rails it's a table, just adding the entity.placeable_by = item_name gets error.

Code: Select all

data.raw["curved-rail"]["curved-rail"].placeable_by = {item = "rail", count = 4} 
UPD
No, I cannot select the entity with "assembling_machine_entity.placeable_by = offshore_pump_item_name".
2019-11-07T22_40_57-Window.png
2019-11-07T22_40_57-Window.png (161.67 KiB) Viewed 2997 times

Re: Edit blueprint in a mod

Posted: Sat Nov 09, 2019 12:09 pm
by Hermios
Hi
Thanks for the answer.
I clearly overengineered my system, and the "placeably by" is the appropriate solution:

My situation is the same as Darkfrei: When placing an entity, the first entitiy E1 is replaced by a second E2 (E1 must be destroyed)
When blueprinting, E2 is taken in consideration. So, my blueprint contains E2
Then, if I define "minable.result" and placeably by from E2 for the item I,
-> When mining E2 (by robot or player)-> I got item I
-> By applying my blueprint, with E2, since E2 is placeably by I, an item I can be consumed to place E2
Though, I still don't see how to edit a blueprint via a mod. This could be very nice to add such content to the API.
But at least, this first problem is solved.
Many thanks for your help and advice, everyone
Niko

Re: Edit blueprint in a mod

Posted: Mon Nov 11, 2019 11:48 am
by mrvn
darkfrei wrote: Thu Nov 07, 2019 9:29 pm
DaveMcW wrote: Thu Nov 07, 2019 11:34 am

Code: Select all

entity.placeable_by = item.name
entity.minable.result = item.name
By rails it's a table, just adding the entity.placeable_by = item_name gets error.

Code: Select all

data.raw["curved-rail"]["curved-rail"].placeable_by = {item = "rail", count = 4} 
UPD
No, I cannot select the entity with "assembling_machine_entity.placeable_by = offshore_pump_item_name".
2019-11-07T22_40_57-Window.png
Did you make it selectable? Maybe share the complete prototype of the entities / items involved.

Re: Edit blueprint in a mod

Posted: Mon Nov 11, 2019 5:49 pm
by darkfrei
mrvn wrote: Mon Nov 11, 2019 11:48 am Did you make it selectable? Maybe share the complete prototype of the entities / items involved.
I don't make it unselectable, so it's just

Code: Select all

local replacement_table = {
  ['offshore-pump'] = 'burner-offshore-pump',
  ['burner-offshore-pump-placeholder'] = 'burner-offshore-pump',
  ['electric-offshore-pump-placeholder'] = 'electric-offshore-pump'
  }

function on_built_entity (event)
  local ent = event.created_entity or event.entity
  local name = ent.name
  local bop_name = replacement_table[name] -- table with 
  if not bop_name then return else end
  local surface = ent.surface
  surface.create_entity{name=bop_name, position=ent.position, direction=ent.direction, force=ent.force, fast_replace=true, spill=false, raise_built=true, create_build_effect_smoke=false}
  ent.destroy()
end

Re: Edit blueprint in a mod

Posted: Mon Nov 11, 2019 6:20 pm
by darkfrei
Interesting, but this small mod works as expected.