aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorPaul Ouellette <oue.paul18@gmail.com>2019-08-10 17:28:00 -0400
committersfan5 <sfan5@live.de>2019-08-10 23:28:00 +0200
commit120155f312cb1977b9a325acc7c7679103eb3800 (patch)
tree1cb5c07716be7d4579fa614555f9d74c12ea07eb /src/script/lua_api
parent86d7f84b899a507e979f1845f2057cce6f84e743 (diff)
downloadminetest-120155f312cb1977b9a325acc7c7679103eb3800.tar.gz
minetest-120155f312cb1977b9a325acc7c7679103eb3800.tar.bz2
minetest-120155f312cb1977b9a325acc7c7679103eb3800.zip
Fix some issues with minetest.clear_craft (#8712)
* Fix some issues with minetest.clear_craft - Fix memory leak - Fix crafts with an output count not being cleared when clearing by input. - Fix recipe list being reversed when clearing by input. * Add CraftInput::empty()
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_craft.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/script/lua_api/l_craft.cpp b/src/script/lua_api/l_craft.cpp
index 0899b945e..18622ee00 100644
--- a/src/script/lua_api/l_craft.cpp
+++ b/src/script/lua_api/l_craft.cpp
@@ -294,7 +294,7 @@ 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))) {
+ if (craftdef->clearCraftsByOutput(c_output, getServer(L))) {
lua_pushboolean(L, true);
return 1;
}
@@ -351,7 +351,13 @@ int ModApiCraft::l_clear_craft(lua_State *L)
throw LuaError("Unknown crafting definition type: \"" + type + "\"");
}
- if (!craftdef->clearCraftRecipesByInput(method, width, recipe, getServer(L))) {
+ std::vector<ItemStack> items;
+ items.reserve(recipe.size());
+ for (const auto &item : recipe)
+ items.emplace_back(item, 1, 0, getServer(L)->idef());
+ CraftInput input(method, width, items);
+
+ if (!craftdef->clearCraftsByInput(input, getServer(L))) {
warningstream << "No craft recipe matches input" << std::endl;
lua_pushboolean(L, false);
return 1;