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);
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
int table = 1;
|
int table = 1;
|
||||||
|
|
||||||
// Get the writable craft definition manager from the server
|
|
||||||
IWritableCraftDefManager *craftdef =
|
IWritableCraftDefManager *craftdef =
|
||||||
getServer(L)->getWritableCraftDefManager();
|
getServer(L)->getWritableCraftDefManager();
|
||||||
|
|
||||||
std::string output = getstringfield_default(L, table, "output", "");
|
std::string output = getstringfield_default(L, table, "output", "");
|
||||||
std::string type = getstringfield_default(L, table, "type", "shaped");
|
std::string type = getstringfield_default(L, table, "type", "shaped");
|
||||||
CraftOutput c_output(output, 0);
|
|
||||||
if (!output.empty()) {
|
if (!output.empty()) {
|
||||||
|
CraftOutput c_output(output, 0);
|
||||||
if (craftdef->clearCraftsByOutput(c_output, getServer(L))) {
|
if (craftdef->clearCraftsByOutput(c_output, getServer(L))) {
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
return 1;
|
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);
|
lua_pushboolean(L, false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> recipe;
|
std::vector<std::string> recipe;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
CraftMethod method = CRAFT_METHOD_NORMAL;
|
CraftMethod method = CRAFT_METHOD_NORMAL;
|
||||||
/*
|
|
||||||
CraftDefinitionShaped
|
|
||||||
*/
|
|
||||||
if (type == "shaped") {
|
if (type == "shaped") {
|
||||||
lua_getfield(L, table, "recipe");
|
lua_getfield(L, table, "recipe");
|
||||||
if (lua_isnil(L, -1))
|
if (lua_isnil(L, -1))
|
||||||
throw LuaError("Either output or recipe has to be defined");
|
throw LuaError("Either output or recipe has to be defined");
|
||||||
if (!readCraftRecipeShaped(L, -1, width, recipe))
|
if (!readCraftRecipeShaped(L, -1, width, recipe))
|
||||||
throw LuaError("Invalid crafting recipe");
|
throw LuaError("Invalid crafting recipe");
|
||||||
}
|
} else if (type == "shapeless") {
|
||||||
/*
|
|
||||||
CraftDefinitionShapeless
|
|
||||||
*/
|
|
||||||
else if (type == "shapeless") {
|
|
||||||
lua_getfield(L, table, "recipe");
|
lua_getfield(L, table, "recipe");
|
||||||
if (lua_isnil(L, -1))
|
if (lua_isnil(L, -1))
|
||||||
throw LuaError("Either output or recipe has to be defined");
|
throw LuaError("Either output or recipe has to be defined");
|
||||||
if (!readCraftRecipeShapeless(L, -1, recipe))
|
if (!readCraftRecipeShapeless(L, -1, recipe))
|
||||||
throw LuaError("Invalid crafting recipe");
|
throw LuaError("Invalid crafting recipe");
|
||||||
}
|
} else if (type == "cooking") {
|
||||||
/*
|
|
||||||
CraftDefinitionCooking
|
|
||||||
*/
|
|
||||||
else if (type == "cooking") {
|
|
||||||
method = CRAFT_METHOD_COOKING;
|
method = CRAFT_METHOD_COOKING;
|
||||||
std::string rec = getstringfield_default(L, table, "recipe", "");
|
std::string rec = getstringfield_default(L, table, "recipe", "");
|
||||||
if (rec.empty())
|
if (rec.empty())
|
||||||
throw LuaError("Crafting definition (cooking)"
|
throw LuaError("Crafting definition (cooking) is missing a recipe");
|
||||||
" is missing a recipe");
|
|
||||||
recipe.push_back(rec);
|
recipe.push_back(rec);
|
||||||
}
|
} else if (type == "fuel") {
|
||||||
/*
|
|
||||||
CraftDefinitionFuel
|
|
||||||
*/
|
|
||||||
else if (type == "fuel") {
|
|
||||||
method = CRAFT_METHOD_FUEL;
|
method = CRAFT_METHOD_FUEL;
|
||||||
std::string rec = getstringfield_default(L, table, "recipe", "");
|
std::string rec = getstringfield_default(L, table, "recipe", "");
|
||||||
if (rec.empty())
|
if (rec.empty())
|
||||||
throw LuaError("Crafting definition (fuel)"
|
throw LuaError("Crafting definition (fuel) is missing a recipe");
|
||||||
" is missing a recipe");
|
|
||||||
recipe.push_back(rec);
|
recipe.push_back(rec);
|
||||||
} else {
|
} else {
|
||||||
throw LuaError("Unknown crafting definition type: \"" + type + "\"");
|
throw LuaError("Unknown crafting definition type: \"" + type + "\"");
|
||||||
|
@ -338,12 +324,20 @@ int ModApiCraft::l_clear_craft(lua_State *L)
|
||||||
|
|
||||||
std::vector<ItemStack> items;
|
std::vector<ItemStack> items;
|
||||||
items.reserve(recipe.size());
|
items.reserve(recipe.size());
|
||||||
for (const auto &item : recipe)
|
for (const auto &item : recipe) {
|
||||||
items.emplace_back(item, 1, 0, getServer(L)->idef());
|
items.emplace_back(item, 1, 0, getServer(L)->idef());
|
||||||
|
}
|
||||||
CraftInput input(method, width, items);
|
CraftInput input(method, width, items);
|
||||||
|
|
||||||
if (!craftdef->clearCraftsByInput(input, getServer(L))) {
|
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);
|
lua_pushboolean(L, false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue