Add event on_blueprint_placed

Things that already exist in the current mod API
Post Reply
saors
Inserter
Inserter
Posts: 34
Joined: Wed May 17, 2017 12:09 am
Contact:

Add event on_blueprint_placed

Post by saors »

It'd be nice if there was an event for when the player placed a blueprint.
This event would give info like the bounding box of the blueprint and what surface the blueprint was placed on.


Other details might be nice too, but I don't need them specifically...
(like read the blueprint contents or what logistics network it's placed in (if any)).

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add event on_blueprint_placed

Post by Rseding91 »

The player built entity event is fired for each entity in the blueprint.
If you want to get ahold of me I'm almost always on Discord.

saors
Inserter
Inserter
Posts: 34
Joined: Wed May 17, 2017 12:09 am
Contact:

Re: Add event on_blueprint_placed

Post by saors »

The problem I'm currently experiencing with player_built_entity is that if you do calculations on the location that the individual entity within a blueprint is placed, then you get severe lag (especially on servers) as the calculation is being done on each entity.
If the blueprint is large enough, players are kicked from the server after timing out while "The server is not responding".

I figured the best way to tackle this would be to have different logic for individual entities compared to a blueprint.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add event on_blueprint_placed

Post by Rseding91 »

saors wrote:The problem I'm currently experiencing with player_built_entity is that if you do calculations on the location that the individual entity within a blueprint is placed, then you get severe lag (especially on servers) as the calculation is being done on each entity.
If the blueprint is large enough, players are kicked from the server after timing out while "The server is not responding".

I figured the best way to tackle this would be to have different logic for individual entities compared to a blueprint.
Just ignore the fact it came from a blueprint - that doesn't matter anyway. Treat it like any other entity built and handle it as such.
If you want to get ahold of me I'm almost always on Discord.

saors
Inserter
Inserter
Posts: 34
Joined: Wed May 17, 2017 12:09 am
Contact:

Re: Add event on_blueprint_placed

Post by saors »

Thank you for the quick responses.

I don't currently have logic for if it's a blueprint or not, which is the problem. If a player places a 300 entity blueprint, the event (on_built_entity) is called 300 times (very quickly) causing severe lag.

I don't think my suggestion will help anyway, as even if I were to get the bounding box, I can't tell the on_built_entity event to ignore those entities without running into the same problem of calling the event a few hundred times.

I think a better API improvement request would be to have the ability to limit the number of responses an event gives per x seconds (ignoring the rest of them if it reaches the max).
I'm going to tinker with this idea some more and if it's unnecessarily difficult to manually implement then I will probably just open a request to see if it's be possible and get some feedback.

Thanks!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add event on_blueprint_placed

Post by Rseding91 »

What is your mod doing that it's taking so long to process in the entity built event? Do you have a working mod example that shows the slowdown?
If you want to get ahold of me I'm almost always on Discord.

saors
Inserter
Inserter
Posts: 34
Joined: Wed May 17, 2017 12:09 am
Contact:

Re: Add event on_blueprint_placed

Post by saors »

Please ignore this post. I've made a huge mistake and wasn't filtering properly, which was allowing a complex method to be ran every time an entity was built...

I'm very sorry :shock: :( :oops: , thanks for the responses though!

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2633
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Add event on_blueprint_placed

Post by steinio »

saors wrote:Please ignore this post. I've made a huge mistake and wasn't filtering properly, which was allowing a complex method to be ran every time an entity was built...

I'm very sorry :shock: :( :oops: , thanks for the responses though!
No, please post your failed and successful code so we can learn from it.
Image

Transport Belt Repair Man

View unread Posts

Post Reply

Return to “Already exists”