diff options
author | Paramat <paramat@users.noreply.github.com> | 2018-10-24 15:03:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-24 15:03:21 +0100 |
commit | 622e2235ee700cf92843d2e99a47e36fd4508cf0 (patch) | |
tree | aea0ff7e6ea2781e2ffabba01b000896d1e6065b /src/script | |
parent | ff35bffe186eae942bae74bd6f0b08ae31f344e0 (diff) | |
download | minetest-622e2235ee700cf92843d2e99a47e36fd4508cf0.tar.gz minetest-622e2235ee700cf92843d2e99a47e36fd4508cf0.tar.bz2 minetest-622e2235ee700cf92843d2e99a47e36fd4508cf0.zip |
clear_craft: Return false if recipe not found, don't throw error (#7804)
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/lua_api/l_craft.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/script/lua_api/l_craft.cpp b/src/script/lua_api/l_craft.cpp index 64177109e..0899b945e 100644 --- a/src/script/lua_api/l_craft.cpp +++ b/src/script/lua_api/l_craft.cpp @@ -294,11 +294,14 @@ int ModApiCraft::l_clear_craft(lua_State *L) std::string type = getstringfield_default(L, table, "type", "shaped"); CraftOutput c_output(output, 0); if (!output.empty()) { - if (craftdef->clearCraftRecipesByOutput(c_output, getServer(L))) - return 0; + if (craftdef->clearCraftRecipesByOutput(c_output, getServer(L))) { + lua_pushboolean(L, true); + return 1; + } - throw LuaError("No craft recipe known for output" - " (output=\"" + output + "\")"); + warningstream << "No craft recipe known for output" << std::endl; + lua_pushboolean(L, false); + return 1; } std::vector<std::string> recipe; int width = 0; @@ -347,10 +350,15 @@ int ModApiCraft::l_clear_craft(lua_State *L) } else { throw LuaError("Unknown crafting definition type: \"" + type + "\""); } - if (!craftdef->clearCraftRecipesByInput(method, width, recipe, getServer(L))) - throw LuaError("No crafting specified for input"); - lua_pop(L, 1); - return 0; + + if (!craftdef->clearCraftRecipesByInput(method, width, recipe, getServer(L))) { + warningstream << "No craft recipe matches input" << std::endl; + lua_pushboolean(L, false); + return 1; + } + + lua_pushboolean(L, true); + return 1; } // get_craft_result(input) |