Compare commits

...

1 Commits

Author SHA1 Message Date
Pascal Abresch 7eae352a13 Remove Craftmethods enum 2021-09-01 21:39:55 +02:00
5 changed files with 20 additions and 61 deletions

View File

@ -299,7 +299,7 @@ bool CraftInput::empty() const
std::string CraftInput::dump() const
{
std::ostringstream os(std::ios::binary);
os << "(method=" << ((int)method) << ", items="
os << "(method=" << (method) << ", items="
<< craftDumpMatrix(items, width) << ")";
return os.str();
}
@ -358,7 +358,7 @@ std::string CraftDefinitionShaped::getName() const
bool CraftDefinitionShaped::check(const CraftInput &input, IGameDef *gamedef) const
{
if (input.method != CRAFT_METHOD_NORMAL)
if (input.method != "normal")
return false;
// Get input item matrix
@ -429,7 +429,7 @@ CraftOutput CraftDefinitionShaped::getOutput(const CraftInput &input, IGameDef *
CraftInput CraftDefinitionShaped::getInput(const CraftOutput &output, IGameDef *gamedef) const
{
return CraftInput(CRAFT_METHOD_NORMAL,width,craftGetItems(recipe,gamedef));
return CraftInput("normal",width,craftGetItems(recipe,gamedef));
}
void CraftDefinitionShaped::decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements,
@ -494,7 +494,7 @@ std::string CraftDefinitionShapeless::getName() const
bool CraftDefinitionShapeless::check(const CraftInput &input, IGameDef *gamedef) const
{
if (input.method != CRAFT_METHOD_NORMAL)
if (input.method != "normal")
return false;
// Filter empty items out of input
@ -550,7 +550,7 @@ CraftOutput CraftDefinitionShapeless::getOutput(const CraftInput &input, IGameDe
CraftInput CraftDefinitionShapeless::getInput(const CraftOutput &output, IGameDef *gamedef) const
{
return CraftInput(CRAFT_METHOD_NORMAL, 0, craftGetItems(recipe, gamedef));
return CraftInput("normal", 0, craftGetItems(recipe, gamedef));
}
void CraftDefinitionShapeless::decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements,
@ -635,7 +635,7 @@ std::string CraftDefinitionToolRepair::getName() const
bool CraftDefinitionToolRepair::check(const CraftInput &input, IGameDef *gamedef) const
{
if (input.method != CRAFT_METHOD_NORMAL)
if (input.method != "normal")
return false;
ItemStack item1;
@ -674,7 +674,7 @@ CraftInput CraftDefinitionToolRepair::getInput(const CraftOutput &output, IGameD
{
std::vector<ItemStack> stack;
stack.emplace_back();
return CraftInput(CRAFT_METHOD_COOKING, additional_wear, stack);
return CraftInput("cooking", additional_wear, stack);
}
void CraftDefinitionToolRepair::decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements,
@ -714,7 +714,7 @@ std::string CraftDefinitionCooking::getName() const
bool CraftDefinitionCooking::check(const CraftInput &input, IGameDef *gamedef) const
{
if (input.method != CRAFT_METHOD_COOKING)
if (input.method != "cooking")
return false;
// Filter empty items out of input
@ -746,7 +746,7 @@ CraftInput CraftDefinitionCooking::getInput(const CraftOutput &output, IGameDef
{
std::vector<std::string> rec;
rec.push_back(recipe);
return CraftInput(CRAFT_METHOD_COOKING,cooktime,craftGetItems(rec,gamedef));
return CraftInput("cooking", cooktime, craftGetItems(rec,gamedef));
}
void CraftDefinitionCooking::decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements,
@ -816,7 +816,7 @@ std::string CraftDefinitionFuel::getName() const
bool CraftDefinitionFuel::check(const CraftInput &input, IGameDef *gamedef) const
{
if (input.method != CRAFT_METHOD_FUEL)
if (input.method != "fuel")
return false;
// Filter empty items out of input
@ -848,7 +848,7 @@ CraftInput CraftDefinitionFuel::getInput(const CraftOutput &output, IGameDef *ga
{
std::vector<std::string> rec;
rec.push_back(recipe);
return CraftInput(CRAFT_METHOD_COOKING,(int)burntime,craftGetItems(rec,gamedef));
return CraftInput("cooking", (int)burntime, craftGetItems(rec,gamedef));
}
void CraftDefinitionFuel::decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements,

View File

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

View File

@ -975,7 +975,7 @@ bool getCraftingResult(Inventory *inv, ItemStack &result,
// Mangle crafting grid to an another format
CraftInput ci;
ci.method = CRAFT_METHOD_NORMAL;
ci.method = "normal";
ci.width = clist->getWidth() ? clist->getWidth() : 3;
for (u16 i=0; i < clist->getSize(); i++)
ci.items.push_back(clist->getItem(i));

View File

@ -26,14 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.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
bool ModApiCraft::readCraftRecipeShaped(lua_State *L, int index,
int &width, std::vector<std::string> &recipe)
@ -305,7 +297,7 @@ int ModApiCraft::l_clear_craft(lua_State *L)
}
std::vector<std::string> recipe;
int width = 0;
CraftMethod method = CRAFT_METHOD_NORMAL;
std::string method = "normal";
/*
CraftDefinitionShaped
*/
@ -330,7 +322,7 @@ int ModApiCraft::l_clear_craft(lua_State *L)
CraftDefinitionCooking
*/
else if (type == "cooking") {
method = CRAFT_METHOD_COOKING;
method = "cooking";
std::string rec = getstringfield_default(L, table, "recipe", "");
if (rec.empty())
throw LuaError("Crafting definition (cooking)"
@ -341,7 +333,7 @@ int ModApiCraft::l_clear_craft(lua_State *L)
CraftDefinitionFuel
*/
else if (type == "fuel") {
method = CRAFT_METHOD_FUEL;
method = "fuel";
std::string rec = getstringfield_default(L, table, "recipe", "");
if (rec.empty())
throw LuaError("Crafting definition (fuel)"
@ -374,8 +366,6 @@ int ModApiCraft::l_get_craft_result(lua_State *L)
int input_i = 1;
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;
lua_getfield(L, input_i, "width");
if(lua_isnumber(L, -1))
@ -387,7 +377,7 @@ int ModApiCraft::l_get_craft_result(lua_State *L)
IGameDef *gdef = getServer(L);
ICraftDefManager *cdef = gdef->cdef();
CraftInput input(method, width, items);
CraftInput input("normal", width, items);
CraftOutput output;
std::vector<ItemStack> output_replacements;
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");
setintfield(L, -1, "width", input.width);
std::string method_s;
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_pushstring(L, input.method.c_str());
lua_setfield(L, -2, "method");
// 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_pushstring(L, output.item.c_str());

View File

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