Page 1 of 1
on_recipe_successfully_finished event
Posted: Sat Sep 25, 2021 3:50 pm
by nullium21
Asking for a recipe called "on_recipe_successfully_finished": triggered when an entity has finished crafting a recipe AND has outputted a result (for probability-based recipes).
Must be filterable by entity type/name and recipe name/category.
Should probably be opt-in like on_entity_destroyed is:
LuaBootstrap.register_on_entity_destroyed.
I need this to avoid checking every single crafter every tick ;) jk, i just want to disable a recipe once it's been crafted.
Re: on_recipe_successfully_finished event
Posted: Sat Sep 25, 2021 5:11 pm
by Silari
Already been asked before and told no due to performance hit:
viewtopic.php?f=28&t=47728&p=275519&hil ... te#p275519 though maybe using a registration system would help. Requiring a result was output seems a pointless thing to enforce since it'd be much better to simply include the results in the event, and allow setting a filter like other events - it wouldn't help the performance impact and would be more useful since people may want to know if a recipe output nothing.
And asked before with no reply:
viewtopic.php?f=28&t=44269&p=256630&hil ... te#p256630
Both those threads are pretty old. Thought I remembered a more recent one but can't find it.
Re: on_recipe_successfully_finished event
Posted: Sat Sep 25, 2021 8:58 pm
by quyxkh
You can shut off the on_tick hook when it completes, since this is by definition a one-shot cost this will be *vastly* cheaper than hooking every single recipe completion.
Re: on_recipe_successfully_finished event
Posted: Sat Sep 25, 2021 11:01 pm
by DaveMcW
Here is a funny hack.
Use an inserter to remove the item. Wire the inserter to activate a mining drill. Use the mining drill to deplete a resource patch, which triggers the
on_resource_depleted event.
Obviously everything in this contraption should be invisible and inside the area of the original assembling machine.
Re: on_recipe_successfully_finished event
Posted: Sun Sep 26, 2021 5:47 am
by nullium21
quyxkh wrote: Sat Sep 25, 2021 8:58 pm
You can shut off the on_tick hook when it completes, since this is by definition a one-shot cost this will be *vastly* cheaper than hooking every single recipe completion.
i wanted this entity to be reusable but this sounds reasonable too. i could even disable both the entity and the recipe... thanks!
DaveMcW wrote: Sat Sep 25, 2021 11:01 pm
Here is a funny hack.
Use an inserter to remove the item. Wire the inserter to activate a mining drill. Use the mining drill to deplete a resource patch, which triggers the
on_resource_depleted event.
Obviously everything in this contraption should be invisible and inside the area of the original assembling machine.
wow, it must be quite difficult to set up... i mean, it's at least 4 entities. but it *is* a funny hack!
Silari wrote:
Requiring a result was output seems a pointless thing to enforce since it'd be much better to simply include the results in the event, and allow setting a filter like other events - it wouldn't help the performance impact and would be more useful since people may want to know if a recipe output nothing.
yeah, i was only thinking about my usecase. this could easily be a flag in the filter.
hm, i didn't see those threads...
about the performance hit, that was the reason i suggested registering specific entities for it.
Re: on_recipe_successfully_finished event
Posted: Sun Sep 26, 2021 7:34 am
by quyxkh
Thinking out loud here, you could keep the per-tick overhead down to checking each player, look at the recipe of anything they've got selected, then only watch the devices that change to that recipe. Not sure what other events you'd have to watch, on_settings_pasted and on_x_built_entity for blueprints and such I suppose.