Edit blueprint in a mod

Place to get help with not working mods / modding interface.
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Edit blueprint in a mod

Post 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

mrvn
Smart Inserter
Smart Inserter
Posts: 5795
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Edit blueprint in a mod

Post 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

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Edit blueprint in a mod

Post 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?

mrvn
Smart Inserter
Smart Inserter
Posts: 5795
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Edit blueprint in a mod

Post by mrvn »

Setting the mining placed by field isn't enough?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Edit blueprint in a mod

Post 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?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3713
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Edit blueprint in a mod

Post by DaveMcW »

Code: Select all

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

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Edit blueprint in a mod

Post 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 2955 times

Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 80
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Edit blueprint in a mod

Post 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

mrvn
Smart Inserter
Smart Inserter
Posts: 5795
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Edit blueprint in a mod

Post 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.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Edit blueprint in a mod

Post 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
Attachments
BurnerOffshorePump_0.0.6.zip
for 0.17
(245.16 KiB) Downloaded 94 times
Last edited by darkfrei on Mon Nov 11, 2019 6:20 pm, edited 1 time in total.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Edit blueprint in a mod

Post by darkfrei »

Interesting, but this small mod works as expected.
Attachments
small-burner-offshore-pump_0.0.1.zip
for 0.17
(32.65 KiB) Downloaded 105 times

Post Reply

Return to “Modding help”