Compare commits

...

1 Commits

Author SHA1 Message Date
Pascal Abresch 2ca2a179e7 Remove Craftmethods enum 2021-09-01 22:02:22 +02:00
4 changed files with 14 additions and 42 deletions

View File

@ -299,7 +299,7 @@ bool CraftInput::empty() const
std::string CraftInput::dump() const std::string CraftInput::dump() const
{ {
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
os << "(method=" << ((int)method) << ", items=" os << "(method=" << (method) << ", items="
<< craftDumpMatrix(items, width) << ")"; << craftDumpMatrix(items, width) << ")";
return os.str(); return os.str();
} }

View File

@ -32,15 +32,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
The crafting method depends on the inventory list The crafting method depends on the inventory list
that the crafting input comes from. that the crafting input comes from.
*/ */
enum CraftMethod
{ // Crafting grid
// Crafting grid static std::string CRAFT_METHOD_NORMAL = "normal";
CRAFT_METHOD_NORMAL, // Cooking something in a furnace
// Cooking something in a furnace static std::string CRAFT_METHOD_COOKING = "cooking";
CRAFT_METHOD_COOKING, // Using something as fuel for a furnace
// Using something as fuel for a furnace static std::string CRAFT_METHOD_FUEL = "fuel";
CRAFT_METHOD_FUEL,
};
/* /*
The type a hash can be. The earlier a type is mentioned in this enum, The type a hash can be. The earlier a type is mentioned in this enum,
@ -69,13 +67,13 @@ const int craft_hash_type_max = (int) CRAFT_HASH_TYPE_UNHASHED;
*/ */
struct CraftInput struct CraftInput
{ {
CraftMethod method = CRAFT_METHOD_NORMAL; std::string method = CRAFT_METHOD_NORMAL;
unsigned int width = 0; unsigned int width = 0;
std::vector<ItemStack> items; std::vector<ItemStack> items;
CraftInput() = default; CraftInput() = default;
CraftInput(CraftMethod method_, unsigned int width_, CraftInput(std::string method_, unsigned int width_,
const std::vector<ItemStack> &items_): const std::vector<ItemStack> &items_):
method(method_), width(width_), items(items_) method(method_), width(width_), items(items_)
{} {}

View File

@ -26,14 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h" #include "server.h"
#include "craftdef.h" #include "craftdef.h"
struct EnumString ModApiCraft::es_CraftMethod[] =
{
{CRAFT_METHOD_NORMAL, "normal"},
{CRAFT_METHOD_COOKING, "cooking"},
{CRAFT_METHOD_FUEL, "fuel"},
{0, NULL},
};
// helper for register_craft // helper for register_craft
bool ModApiCraft::readCraftRecipeShaped(lua_State *L, int index, bool ModApiCraft::readCraftRecipeShaped(lua_State *L, int index,
int &width, std::vector<std::string> &recipe) int &width, std::vector<std::string> &recipe)
@ -305,7 +297,7 @@ int ModApiCraft::l_clear_craft(lua_State *L)
} }
std::vector<std::string> recipe; std::vector<std::string> recipe;
int width = 0; int width = 0;
CraftMethod method = CRAFT_METHOD_NORMAL; std::string method = CRAFT_METHOD_NORMAL;
/* /*
CraftDefinitionShaped CraftDefinitionShaped
*/ */
@ -374,8 +366,6 @@ int ModApiCraft::l_get_craft_result(lua_State *L)
int input_i = 1; int input_i = 1;
std::string method_s = getstringfield_default(L, input_i, "method", "normal"); std::string method_s = getstringfield_default(L, input_i, "method", "normal");
enum CraftMethod method = (CraftMethod)getenumfield(L, input_i, "method",
es_CraftMethod, CRAFT_METHOD_NORMAL);
int width = 1; int width = 1;
lua_getfield(L, input_i, "width"); lua_getfield(L, input_i, "width");
if(lua_isnumber(L, -1)) if(lua_isnumber(L, -1))
@ -387,7 +377,7 @@ int ModApiCraft::l_get_craft_result(lua_State *L)
IGameDef *gdef = getServer(L); IGameDef *gdef = getServer(L);
ICraftDefManager *cdef = gdef->cdef(); ICraftDefManager *cdef = gdef->cdef();
CraftInput input(method, width, items); CraftInput input(CRAFT_METHOD_NORMAL, width, items);
CraftOutput output; CraftOutput output;
std::vector<ItemStack> output_replacements; std::vector<ItemStack> output_replacements;
bool got = cdef->getCraftResult(input, output, output_replacements, true, gdef); bool got = cdef->getCraftResult(input, output, output_replacements, true, gdef);
@ -436,25 +426,11 @@ static void push_craft_recipe(lua_State *L, IGameDef *gdef,
lua_setfield(L, -2, "items"); lua_setfield(L, -2, "items");
setintfield(L, -1, "width", input.width); setintfield(L, -1, "width", input.width);
std::string method_s; lua_pushstring(L, input.method.c_str());
switch (input.method) {
case CRAFT_METHOD_NORMAL:
method_s = "normal";
break;
case CRAFT_METHOD_COOKING:
method_s = "cooking";
break;
case CRAFT_METHOD_FUEL:
method_s = "fuel";
break;
default:
method_s = "unknown";
}
lua_pushstring(L, method_s.c_str());
lua_setfield(L, -2, "method"); lua_setfield(L, -2, "method");
// Deprecated, only for compatibility's sake // Deprecated, only for compatibility's sake
lua_pushstring(L, method_s.c_str()); lua_pushstring(L, input.method.c_str());
lua_setfield(L, -2, "type"); lua_setfield(L, -2, "type");
lua_pushstring(L, output.item.c_str()); lua_pushstring(L, output.item.c_str());

View File

@ -41,8 +41,6 @@ private:
static bool readCraftRecipeShaped(lua_State *L, int index, static bool readCraftRecipeShaped(lua_State *L, int index,
int &width, std::vector<std::string> &recipe); int &width, std::vector<std::string> &recipe);
static struct EnumString es_CraftMethod[];
public: public:
static void Initialize(lua_State *L, int top); static void Initialize(lua_State *L, int top);
}; };