Programmatically placing blueprint

Place to get help with not working mods / modding interface.
Post Reply
Graveeater
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Jul 07, 2016 8:00 pm
Contact:

Programmatically placing blueprint

Post by Graveeater » Thu Aug 08, 2019 10:42 am

I want to take a small area and place a blueprint (using lua) of that area at a different position.
I can get this working if the area is filled with 1x1 entities. But I run into problems as soon as
- there are large entities overlapping the boundary of the area
- the first/last row/column is empty
In these cases the blueprint will either be larger or smaller than expected. When I now try to place it in the center of the destination it quite often is offset by one (or more) tiles.

I don't know how to correct for this offset and various attempts have failed. I think I have a working solution for empty rows/cols (using find_entities before and reducing the area) but I am currently stuck with the overlapping large entities.

Does anyone have a good Idea how to do this?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3250
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Programmatically placing blueprint

Post by eradicator » Thu Aug 08, 2019 11:53 am

Maybe LuaSurface.clone_area()? Though with your requirement to copy entities entirely contained within the area sounds pretty much like you'll need to do a LuaEntityPrototype.collision_box comparition manually for each entity and then decide yourself. As all API interfaces (clone, find_entities, etc) are based on the *center* of each entity and don't care much about the size. And blueprints are always centered on the average center of all contain entities, so they do *not* store the position relative to the size of the "selecion box" you draw, figuratively speaking. Yes, they *can* be created with an offset, but it's not what the engine does by default.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: Programmatically placing blueprint

Post by mrvn » Thu Aug 08, 2019 11:54 am

The recursive blueprints / blueprint printer mod comes to mind. They use a marker (wooden chest or special chest) in the blueprint to position it.

Graveeater
Burner Inserter
Burner Inserter
Posts: 18
Joined: Thu Jul 07, 2016 8:00 pm
Contact:

Re: Programmatically placing blueprint

Post by Graveeater » Wed Aug 14, 2019 11:01 am

eradicator wrote:
Thu Aug 08, 2019 11:53 am
Maybe LuaSurface.clone_area()? Though with your requirement to copy entities entirely contained within the area sounds pretty much like you'll need to do a LuaEntityPrototype.collision_box comparition manually for each entity and then decide yourself. As all API interfaces (clone, find_entities, etc) are based on the *center* of each entity and don't care much about the size.[...]
I think I was unclear here, I don't mind that entities on the border of the area are included, in fact since that is the behaviour of player blueprints I want it.
The problem for me was, that this messed up the placement of the blueprint.
Also I believe your statement is wrong, find_entities will find entities where the center is outside the area but parts of the entity are inside, just like blueprints.
However clone_area is not useful to me, as I want ghosts instead of real entities.
mrvn wrote:
Thu Aug 08, 2019 11:54 am
The recursive blueprints / blueprint printer mod comes to mind. They use a marker (wooden chest or special chest) in the blueprint to position it.
That is a great Idea, I first was reluctant to add a marker, but then I noticed that any entity will do. So I just pick the top_left one. I also needed the actual size of the blueprint which was possible. Using some addition subtraction I am now able to compute the correct center for the blueprint.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3250
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Programmatically placing blueprint

Post by eradicator » Wed Aug 14, 2019 11:54 am

Graveeater wrote:
Wed Aug 14, 2019 11:01 am
Also I believe your statement is wrong, find_entities will find entities where the center is outside the area but parts of the entity are inside, just like blueprints.
You're right. Seems i never encountered a situation where it made a difference :).
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: Google [Bot]