mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Improve log messages for core.clear_craft
This commit is contained in:
parent
0c7149b8df
commit
c5abecbd3c
1 changed files with 21 additions and 27 deletions
|
@ -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<std::string> 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<ItemStack> 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue