Page 1 of 1

Store entity placeholder into blueprint [SOLVED]

Posted: Sat Mar 27, 2021 5:58 pm
by oldskoolmatt
Hello everyone, this blueprint thing is really bugging me out, i have an entity-placeholder which on creation gets destroyed by the script in control.lua, and is replaced with another entity, though the script works, the script-generated entity is not blueprintable.
Is there a way to have the blueprint tool to look at the generated entity as its placeholder? (WANTED-ENTITY looks like PLACEHOLDER-ENTITY to the blueprint tool and gets stored in the blueprint as such)

the code is as follow:

IN CONTROL.LUA

Code: Select all

placeholder_table =
{
  ["ENTITY-PLACEHOLDER"] = "WANTED-ENTITY",
}
[...]
local placeholder = event.created_entity or event.entity
local placeholder_name = placeholder.name
local surface = placeholder.surface
local position = placeholder.position
local direction = placeholder.direction
local force = placeholder.force
local name = placeholder_table[placeholder_name]
if not name then return else end
		
placeholder.destroy()   --destroys "ENTITY-PLACEHOLDER"
surface.create_entity   --replaces it with "WANTED-ENTITY"
{
  name = name,
  position = position,
  direction = direction,
  force = force,
  fast_replace = true,
  spill = false,
  raise_built = true,
  create_build_effect_smoke = false
}
[...]
IN DATA.LUA

Code: Select all

RECIPE
[...]
result = "ENTITY"   --item name
[...]

ITEM:
[...]
name = "ENTITY"   -- item name
place_result = "ENTITY-PLACEHOLDER",   --entity placed
[...]

ENTITY-PLACEHOLDER:   -- note that if this entity is placed down with /editor it is indeed blueprintable
[...]
name = "ENTITY-PLACEHOLDER"
minable = {mining_time = 0.1, result = "ENTITY"}   --item name
[...]

WANTED-ENTITY:
[...]
name = "WANTED-ENTITY"
minable = {mining_time = 0.1, result = "ENTITY"}   --drops the above "ITEM"
placeable_by = {item = "ENTITY", count = 1}   --placed by the above "ITEM"
[...]

Re: Store entity placeholder into blueprint

Posted: Sat Mar 27, 2021 8:18 pm
by Silari
https://wiki.factorio.com/Prototype/Entity#placeable_by is supposed to tell the game what to use in a blueprint for the given entity, so it might work for this. Haven't tried it myself though.

Re: Store entity placeholder into blueprint

Posted: Sat Mar 27, 2021 8:26 pm
by oldskoolmatt
Silari wrote: Sat Mar 27, 2021 8:18 pm https://wiki.factorio.com/Prototype/Entity#placeable_by is supposed to tell the game what to use in a blueprint for the given entity, so it might work for this. Haven't tried it myself though.
I was aware of this, but it doesn't seem to work, i tried any combination of "placeable_by" that's why i'm trying to understand if there's a way to override the value gotten by the blueprint tool via control.lua (also if you look the "wanted-entity" points to the item that places down the placeholder with a placeable_by)

Re: Store entity placeholder into blueprint

Posted: Sat Mar 27, 2021 8:37 pm
by DaveMcW
You are doing the same thing the game does for curved rails. Note how the WANTED_ENTITY, curved-rail, appears in the preview but not in the Components box.

rail-blueprint.png
rail-blueprint.png (277.93 KiB) Viewed 1820 times

But you don't really want this, do you? You want each entity to appear as its own component.

Re: Store entity placeholder into blueprint

Posted: Sat Mar 27, 2021 8:47 pm
by oldskoolmatt
DaveMcW wrote: Sat Mar 27, 2021 8:37 pm You are doing the same thing the game does for curved rails. Note how the WANTED_ENTITY, curved-rail, appears in the preview but not in the Components box.

But you don't really want this, do you? You want each entity to appear as its own component.
Thing is that the entity doesn't appear at all nor the blueprint gets created if i select the single entity, else if i select it along with other entities only the other entities show up, there's not even a green square appearing around the scripted entity, just nothing happens.

Re: Store entity placeholder into blueprint

Posted: Sat Mar 27, 2021 8:48 pm
by DaveMcW
Then you did something wrong. What happens if you use a known good item like "rail" in placeable_by?

Re: Store entity placeholder into blueprint

Posted: Sat Mar 27, 2021 8:55 pm
by oldskoolmatt
DaveMcW wrote: Sat Mar 27, 2021 8:48 pm Then you did something wrong. What happens if you use a known good item like "rail" in placeable_by?
FOUND THE CULPRIT!!!

WANTED-ENTITY:

Code: Select all

[...]
name = "WANTED-ENTITY"
flags = {"placeable-player", "placeable-off-grid"}
minable = {mining_time = 0.1, result = "ENTITY"}   --drops the above "ITEM"
placeable_by = {item = "ENTITY", count = 1}   --placed by the above "ITEM"
[...]
REPLACED WITH:

Code: Select all

[...]
name = "WANTED-ENTITY"
flags = {"placeable-player", "placeable-off-grid", "player-creation"}
minable = {mining_time = 0.1, result = "ENTITY"}   --drops the above "ITEM"
placeable_by = {item = "ENTITY", count = 1}   --placed by the above "ITEM"
[...]
Apparently the entity has to be marked as player creation in order to be blueprintable.
Hopefully this can help someone else as i was literally going berserk over it