-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
registered_crafts table #15765
base: master
Are you sure you want to change the base?
registered_crafts table #15765
Conversation
This would be a useful feature, as it would make things glcraft's "zzzz" load-first-of-all bootstrap mod not really necessary anymore: https://gitlab.com/Kimapr/glcraft/-/blob/master/zzzz_glcraft_crafthook/init.lua?ref_type=heads While there are already core functions for retrieving crafting results based on recipe input, there is no way to get a full table of all of them, short of hijacking the register_craft function as such. It would also be more consistent with other registries that also provide such a table with the registered entries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add documentation about it in lua_api.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see multiple problems with this (besides what roller already said):
- The
registered_crafts
are not indexed by anything useful. It's just a flat list, tricking users into writing unnecessarily slow code. This is in contrast to many other registration functions and correspondingregistered_*
tables, where we have names (e.g. node names). - No recipe definition table normalization is done; for example a user of this table would have to handle both itemstrings and itemstacks. This is a mistake other
registered_*
tables have made too but which I would like to avoid for new API additions. - The deprecations are absolutely unacceptable. You are deprecating useful functions which can leverage engine-internal indexes and instead forcing people to replace them with inefficient boilerplate iteration of a list of registered crafts, creating completely unnecessary and counterproductive work for them. Undo that now.
- Furthermore, there is a glaring bug in your implementation:
clear_craft
does not update the list. (And fixing this would make the PR a good bit nastier: You now need a way to match recipes, going back to my normalization point, or for the C++ side recipes to know the indices inregistered_crafts
.)
While there are already core functions for retrieving crafting results based on recipe input, there is no way to get a full table of all of them, short of hijacking the register_craft function as such.
How so? What's the problem with iterating over registered items and finding all recipes that have any item as an output using core.get_all_craft_recipes(item)
? Sure, it's a few more lines of code and unnecessarily using an index, but it should be possible. What am I missing?
It would also be more consistent with other registries that also provide such a table with the registered entries.
I disagree, the big difference being that other registries typically have obvious useful indices (names), or you need to iterate effectively all of them anyways (e.g. lists of callbacks), neither of which is the case here; and the indexing by output item (for which the keys are just the registered items, which you can already iterate) is already provided.
So far this PR is between low priority and possible close in my opinion; I do not support it. Maybe @Kimapr can convince me otherwise.
end | ||
local pos | ||
for i, def in pairs(core.registered_crafts[name]) do | ||
if dump(def) == dump(recipe) or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other way this will give false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you would need a recursive lua table compare (or have to manually implement recipe def compare) here. your normalization is also incomplete.
but i don't think this is the right approach to begin with.
end | ||
end | ||
if pos then | ||
core.registered_crafts[name][pos] = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this table isn't even a list anymore after this
builtin/game/deprecated.lua
Outdated
@@ -61,3 +61,36 @@ function core.register_on_auth_fail(func) | |||
end | |||
end) | |||
end | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still deprecating things you shouldn't be deprecating
You cannot check registered crafts to find your one from mod, so we need to create a
registered_crafts
table for that, I sure this will solve manu amount of problems about crafts.If we add this table system in mods code, (like,
init.lua
) it will not identify many amount of crafts, as needed.