diff --git a/src/script/lua_api/l_craft.cpp b/src/script/lua_api/l_craft.cpp index f3b6fd41c..15e2a5a57 100644 --- a/src/script/lua_api/l_craft.cpp +++ b/src/script/lua_api/l_craft.cpp @@ -271,66 +271,52 @@ int ModApiCraft::l_clear_craft(lua_State *L) luaL_checktype(L, 1, LUA_TTABLE); int table = 1; - // Get the writable craft definition manager from the server IWritableCraftDefManager *craftdef = getServer(L)->getWritableCraftDefManager(); std::string output = getstringfield_default(L, table, "output", ""); std::string type = getstringfield_default(L, table, "type", "shaped"); - CraftOutput c_output(output, 0); + if (!output.empty()) { + CraftOutput c_output(output, 0); if (craftdef->clearCraftsByOutput(c_output, getServer(L))) { lua_pushboolean(L, true); return 1; } - warningstream << "No craft recipe known for output" << std::endl; + warningstream << "No craft recipe known for output '" << output + << "'" << std::endl; lua_pushboolean(L, false); return 1; } + std::vector recipe; int width = 0; CraftMethod method = CRAFT_METHOD_NORMAL; - /* - CraftDefinitionShaped - */ + if (type == "shaped") { lua_getfield(L, table, "recipe"); if (lua_isnil(L, -1)) throw LuaError("Either output or recipe has to be defined"); if (!readCraftRecipeShaped(L, -1, width, recipe)) throw LuaError("Invalid crafting recipe"); - } - /* - CraftDefinitionShapeless - */ - else if (type == "shapeless") { + } else if (type == "shapeless") { lua_getfield(L, table, "recipe"); if (lua_isnil(L, -1)) throw LuaError("Either output or recipe has to be defined"); if (!readCraftRecipeShapeless(L, -1, recipe)) throw LuaError("Invalid crafting recipe"); - } - /* - CraftDefinitionCooking - */ - else if (type == "cooking") { + } else if (type == "cooking") { method = CRAFT_METHOD_COOKING; std::string rec = getstringfield_default(L, table, "recipe", ""); if (rec.empty()) - throw LuaError("Crafting definition (cooking)" - " is missing a recipe"); + throw LuaError("Crafting definition (cooking) is missing a recipe"); recipe.push_back(rec); - } - /* - CraftDefinitionFuel - */ - else if (type == "fuel") { + } else if (type == "fuel") { method = CRAFT_METHOD_FUEL; std::string rec = getstringfield_default(L, table, "recipe", ""); if (rec.empty()) - throw LuaError("Crafting definition (fuel)" - " is missing a recipe"); + throw LuaError("Crafting definition (fuel) is missing a recipe"); recipe.push_back(rec); } else { throw LuaError("Unknown crafting definition type: \"" + type + "\""); @@ -338,12 +324,20 @@ int ModApiCraft::l_clear_craft(lua_State *L) std::vector items; items.reserve(recipe.size()); - for (const auto &item : recipe) + 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; + warningstream << "No craft recipe matches input (type: " << type + << ", items: ["; + for (size_t i = 0; i < items.size(); ++i) { + warningstream << "'" << items[i].name << "'"; + if (i != items.size() - 1) + warningstream << ", "; + } + warningstream << "])" << std::endl; lua_pushboolean(L, false); return 1; }