Skip to content

Commit 622e223

Browse files
authoredOct 24, 2018
clear_craft: Return false if recipe not found, don't throw error (#7804)
1 parent ff35bff commit 622e223

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed
 

Diff for: ‎doc/lua_api.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3555,7 +3555,7 @@ Call these functions only at load time!
35553555
ignored. For input use the same recipe table syntax as for
35563556
`minetest.register_craft(recipe)`. For output specify only the item,
35573557
without a quantity.
3558-
* If no erase candidate could be found, Lua exception will be thrown.
3558+
* Returns false if no erase candidate could be found, otherwise returns true.
35593559
* **Warning**! The type field ("shaped", "cooking" or any other) will be
35603560
ignored if the recipe contains output. Erasing is then done independently
35613561
from the crafting method.

Diff for: ‎src/script/lua_api/l_craft.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,14 @@ int ModApiCraft::l_clear_craft(lua_State *L)
294294
std::string type = getstringfield_default(L, table, "type", "shaped");
295295
CraftOutput c_output(output, 0);
296296
if (!output.empty()) {
297-
if (craftdef->clearCraftRecipesByOutput(c_output, getServer(L)))
298-
return 0;
297+
if (craftdef->clearCraftRecipesByOutput(c_output, getServer(L))) {
298+
lua_pushboolean(L, true);
299+
return 1;
300+
}
299301

300-
throw LuaError("No craft recipe known for output"
301-
" (output=\"" + output + "\")");
302+
warningstream << "No craft recipe known for output" << std::endl;
303+
lua_pushboolean(L, false);
304+
return 1;
302305
}
303306
std::vector<std::string> recipe;
304307
int width = 0;
@@ -347,10 +350,15 @@ int ModApiCraft::l_clear_craft(lua_State *L)
347350
} else {
348351
throw LuaError("Unknown crafting definition type: \"" + type + "\"");
349352
}
350-
if (!craftdef->clearCraftRecipesByInput(method, width, recipe, getServer(L)))
351-
throw LuaError("No crafting specified for input");
352-
lua_pop(L, 1);
353-
return 0;
353+
354+
if (!craftdef->clearCraftRecipesByInput(method, width, recipe, getServer(L))) {
355+
warningstream << "No craft recipe matches input" << std::endl;
356+
lua_pushboolean(L, false);
357+
return 1;
358+
}
359+
360+
lua_pushboolean(L, true);
361+
return 1;
354362
}
355363

356364
// get_craft_result(input)

0 commit comments

Comments
 (0)
Please sign in to comment.