-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Adding minetest.clear_craft(recipe) to Lua modding API #4034
Conversation
This would take care of #2319 if I reckon this correctly. |
@mtango688 yes it is. |
It would be good to have the motivation for this change included in the commit message (not the PR). Can you amend the commit and include something like: "Removing craft recipes is useful for mods that are altering default crafts or eliminating easy ways of obtaining items." Would just work. |
@sofar github commits can not be edited. |
Yes you can. Just push --force an amended commit. |
std::vector<CraftDefinition*> new_vec_by_input; | ||
for (std::vector<CraftDefinition*>::iterator i2 = unhashed_inputs_vec.begin(); | ||
i2 != unhashed_inputs_vec.end(); ++i2) { | ||
if(def != *i2) |
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.
{ on same line and space between if and (
lol |
@est31 Thank you! |
I was thinking this was merged already :( |
From what I can remember it looked mostly okay, but I didn't +1 because of the freeze. |
Giving it a "looks good" 👍 now. |
for (std::vector<CraftDefinition*>::iterator i2 = unhashed_inputs_vec.begin(); | ||
i2 != unhashed_inputs_vec.end(); ++i2) { | ||
if(def != *i2) | ||
{ |
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.
if (condition)
statement;
no braces if statement is only a single statement - space after if
@sofar extra spaces added to code. Thank you for checking code style for me. |
i = unhashed_inputs_vec.size(); i > 0; i--) { | ||
CraftDefinition *def = unhashed_inputs_vec[i - 1]; | ||
// If the input doesn't match the recipe definition, this recipe definition later will be added back in source map. | ||
if (!def->check(input, gamedef)){ |
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.
one more space
A few more missed style elements, plus it would be nice to get the |
@sofar 'reserve()' is more or less obvious for those, who know C++ enough. Anyway, comments are added. |
Ah, I just didn't see you added them before already - this looks fine. |
I took the default planks recipe, and threw it in https://github.com/minetest/minetest_game/blob/master/mods/default/crafting.lua#L3 minetest.clear_craft({
output = 'default:wood 4'
}) throws an error: minetest.clear_craft({
recipe = {
{'default:tree'},
}
}) Throws an error: Note that the documentation says that the formatting should be identical to the thing passed to |
@sofar that sounds like a documentation error to me. IMO clear_craft really should make you specify both the output and the recipe. |
@mtango688, @sofar Yes, it is my mistake in documentation.
Seems work fine for me. Did you specify 'default' in 'depends.txt' of your test mod? |
Ok, it works, I perhaps missed the dependency on default, which isn't entirely obvious. Perhaps the error message should be more clear -> "There is no recipe for this (input|output)" ? |
@paramat Yes, i saw sofars' question. And answer is: yes, perhaps. |
👍 this is working well and great for subgames (and badly needed). |
@est31 maybe you'd like to re-assess your +1 due to recent changes? |
@Foghrye4 please can you fix the long lines? Max 90 columns with tab size = 4. Applies to comments too. |
@paramat sure. Done. |
okay, re-approved, and merged; see above. |
2 more to go. |
This function allow modders remove previously registered recipes either by output or by input and type (including "fuel" and "cooking"). Plus, removed recipes no longer visible via crafting guides, because they eliminated from registry.