1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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()
This commit is contained in:
Paul Ouellette 2019-08-10 17:28:00 -04:00 committed by sfan5
parent 86d7f84b89
commit 120155f312
6 changed files with 119 additions and 124 deletions

View file

@ -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;