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?
Programmatically placing blueprint
-
- Burner Inserter
- Posts: 19
- Joined: Thu Jul 07, 2016 8:00 pm
- Contact:
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Programmatically placing blueprint
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: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Programmatically placing blueprint
The recursive blueprints / blueprint printer mod comes to mind. They use a marker (wooden chest or special chest) in the blueprint to position it.
-
- Burner Inserter
- Posts: 19
- Joined: Thu Jul 07, 2016 8:00 pm
- Contact:
Re: Programmatically placing blueprint
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.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.[...]
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.
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.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Programmatically placing blueprint
You're right. Seems i never encountered a situation where it made a difference :).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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.