return str_starts_with(rec_name, std::string("group:"));
}
+static bool hasGroupItem(const std::vector<std::string> &recipe)
+{
+ for (const auto &item : recipe) {
+ if (isGroupRecipeStr(item))
+ return true;
+ }
+ return false;
+}
+
inline u64 getHashForString(const std::string &recipe_str)
{
/*errorstream << "Hashing craft string \"" << recipe_str << '"';*/
CraftDefinitionShaped
*/
+CraftDefinitionShaped::CraftDefinitionShaped(
+ const std::string &output_,
+ unsigned int width_,
+ const std::vector<std::string> &recipe_,
+ const CraftReplacements &replacements_):
+ output(output_), width(width_), recipe(recipe_), replacements(replacements_)
+{
+ if (hasGroupItem(recipe))
+ priority = SHAPED_AND_GROUPS;
+ else
+ priority = SHAPED;
+}
+
std::string CraftDefinitionShaped::getName() const
{
return "shaped";
hash_inited = true;
recipe_names = craftGetItemNames(recipe, gamedef);
- bool has_group = false;
- for (const auto &recipe_name : recipe_names) {
- if (isGroupRecipeStr(recipe_name)) {
- has_group = true;
- break;
- }
- }
- if (has_group) {
+ if (hasGroupItem(recipe_names))
hash_type = CRAFT_HASH_TYPE_COUNT;
- priority = SHAPED_AND_GROUPS;
- } else {
+ else
hash_type = CRAFT_HASH_TYPE_ITEM_NAMES;
- priority = SHAPED;
- }
}
std::string CraftDefinitionShaped::dump() const
CraftDefinitionShapeless
*/
+CraftDefinitionShapeless::CraftDefinitionShapeless(
+ const std::string &output_,
+ const std::vector<std::string> &recipe_,
+ const CraftReplacements &replacements_):
+ output(output_), recipe(recipe_), replacements(replacements_)
+{
+ if (hasGroupItem(recipe))
+ priority = SHAPELESS_AND_GROUPS;
+ else
+ priority = SHAPELESS;
+}
+
std::string CraftDefinitionShapeless::getName() const
{
return "shapeless";
recipe_names = craftGetItemNames(recipe, gamedef);
std::sort(recipe_names.begin(), recipe_names.end());
- bool has_group = false;
- for (const auto &recipe_name : recipe_names) {
- if (isGroupRecipeStr(recipe_name)) {
- has_group = true;
- break;
- }
- }
- if (has_group) {
+ if (hasGroupItem(recipe_names))
hash_type = CRAFT_HASH_TYPE_COUNT;
- priority = SHAPELESS_AND_GROUPS;
- } else {
+ else
hash_type = CRAFT_HASH_TYPE_ITEM_NAMES;
- priority = SHAPELESS;
- }
}
std::string CraftDefinitionShapeless::dump() const
CraftDefinitionToolRepair
*/
+CraftDefinitionToolRepair::CraftDefinitionToolRepair(float additional_wear_):
+ additional_wear(additional_wear_)
+{
+ priority = TOOLREPAIR;
+}
+
static ItemStack craftToolRepair(
const ItemStack &item1,
const ItemStack &item2,
CraftDefinitionCooking
*/
+CraftDefinitionCooking::CraftDefinitionCooking(
+ const std::string &output_,
+ const std::string &recipe_,
+ float cooktime_,
+ const CraftReplacements &replacements_):
+ output(output_), recipe(recipe_), cooktime(cooktime_), replacements(replacements_)
+{
+ if (isGroupRecipeStr(recipe))
+ priority = SHAPELESS_AND_GROUPS;
+ else
+ priority = SHAPELESS;
+}
+
std::string CraftDefinitionCooking::getName() const
{
return "cooking";
hash_inited = true;
recipe_name = craftGetItemName(recipe, gamedef);
- if (isGroupRecipeStr(recipe_name)) {
+ if (isGroupRecipeStr(recipe_name))
hash_type = CRAFT_HASH_TYPE_COUNT;
- priority = SHAPELESS_AND_GROUPS;
- } else {
+ else
hash_type = CRAFT_HASH_TYPE_ITEM_NAMES;
- priority = SHAPELESS;
- }
}
std::string CraftDefinitionCooking::dump() const
CraftDefinitionFuel
*/
+CraftDefinitionFuel::CraftDefinitionFuel(
+ const std::string &recipe_,
+ float burntime_,
+ const CraftReplacements &replacements_):
+ recipe(recipe_), burntime(burntime_), replacements(replacements_)
+{
+ if (isGroupRecipeStr(recipe_name))
+ priority = SHAPELESS_AND_GROUPS;
+ else
+ priority = SHAPELESS;
+}
+
std::string CraftDefinitionFuel::getName() const
{
return "fuel";
hash_inited = true;
recipe_name = craftGetItemName(recipe, gamedef);
- if (isGroupRecipeStr(recipe_name)) {
+ if (isGroupRecipeStr(recipe_name))
hash_type = CRAFT_HASH_TYPE_COUNT;
- priority = SHAPELESS_AND_GROUPS;
- } else {
+ else
hash_type = CRAFT_HASH_TYPE_ITEM_NAMES;
- priority = SHAPELESS;
- }
}
std::string CraftDefinitionFuel::dump() const
{
public:
CraftDefinitionShaped() = delete;
-
CraftDefinitionShaped(
- const std::string &output_,
- unsigned int width_,
- const std::vector<std::string> &recipe_,
- const CraftReplacements &replacements_):
- output(output_), width(width_), recipe(recipe_),
- replacements(replacements_)
- {}
+ const std::string &output_,
+ unsigned int width_,
+ const std::vector<std::string> &recipe_,
+ const CraftReplacements &replacements_);
+
virtual ~CraftDefinitionShaped() = default;
virtual std::string getName() const;
public:
CraftDefinitionShapeless() = delete;
CraftDefinitionShapeless(
- const std::string &output_,
- const std::vector<std::string> &recipe_,
- const CraftReplacements &replacements_):
- output(output_), recipe(recipe_), replacements(replacements_)
- {}
+ const std::string &output_,
+ const std::vector<std::string> &recipe_,
+ const CraftReplacements &replacements_);
+
virtual ~CraftDefinitionShapeless() = default;
virtual std::string getName() const;
{
public:
CraftDefinitionToolRepair() = delete;
- CraftDefinitionToolRepair(float additional_wear_):
- additional_wear(additional_wear_)
- {}
+ CraftDefinitionToolRepair(float additional_wear_);
+
virtual ~CraftDefinitionToolRepair() = default;
virtual std::string getName() const;
virtual void initHash(IGameDef *gamedef)
{
hash_type = CRAFT_HASH_TYPE_COUNT;
- priority = TOOLREPAIR;
}
virtual std::string dump() const;
public:
CraftDefinitionCooking() = delete;
CraftDefinitionCooking(
- const std::string &output_,
- const std::string &recipe_,
- float cooktime_,
- const CraftReplacements &replacements_):
- output(output_), recipe(recipe_), cooktime(cooktime_), replacements(replacements_)
- {}
+ const std::string &output_,
+ const std::string &recipe_,
+ float cooktime_,
+ const CraftReplacements &replacements_);
+
virtual ~CraftDefinitionCooking() = default;
virtual std::string getName() const;
{
public:
CraftDefinitionFuel() = delete;
- CraftDefinitionFuel(const std::string &recipe_,
- float burntime_,
- const CraftReplacements &replacements_):
- recipe(recipe_), burntime(burntime_), replacements(replacements_)
- {}
+ CraftDefinitionFuel(
+ const std::string &recipe_,
+ float burntime_,
+ const CraftReplacements &replacements_);
+
virtual ~CraftDefinitionFuel() = default;
virtual std::string getName() const;