virtual bool clearCraftRecipesByInput(CraftMethod craft_method, unsigned int craft_grid_width, const std::vector<std::string> &recipe, IGameDef *gamedef) { bool all_empty = true; for (const auto &i : recipe) { if (!i.empty()) { all_empty = false; break; } } if (all_empty) return false; CraftInput input(craft_method, craft_grid_width, craftGetItems(recipe, gamedef)); // Recipes are not yet hashed at this point std::vector<CraftDefinition*> &unhashed_inputs_vec = m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0]; std::vector<CraftDefinition*> new_vec_by_input; bool got_hit = false; for (std::vector<CraftDefinition*>::size_type i = unhashed_inputs_vec.size(); i > 0; i--) { CraftDefinition *def = unhashed_inputs_vec[i - 1]; /* If the input doesn't match the recipe definition, this recipe definition later will be added back in source map. */ if (!def->check(input, gamedef)) { new_vec_by_input.push_back(def); continue; } CraftOutput output = def->getOutput(input, gamedef); got_hit = true; auto vec_iter = m_output_craft_definitions.find(output.item); if (vec_iter == m_output_craft_definitions.end()) continue; std::vector<CraftDefinition*> &vec = vec_iter->second; std::vector<CraftDefinition*> new_vec_by_output; /* We will preallocate necessary memory addresses, so we don't need to reallocate them later. This would save us some performance. */ new_vec_by_output.reserve(vec.size()); for (auto &vec_i : vec) { /* If pointers from map by input and output are not same, we will add 'CraftDefinition*' to a new vector. */ if (def != vec_i) { /* Adding dereferenced iterator value (which are 'CraftDefinition' reference) to a new vector. */ new_vec_by_output.push_back(vec_i); } } // Swaps assigned to current key value with new vector for output map. m_output_craft_definitions[output.item].swap(new_vec_by_output); } if (got_hit) // Swaps value with new vector for input map. m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0].swap(new_vec_by_input); return got_hit; }
CraftInput CraftDefinitionFuel::getInput(const CraftOutput &output, IGameDef *gamedef) const { std::vector<std::string> rec; rec.push_back(recipe); return CraftInput(CRAFT_METHOD_COOKING,(int)burntime,craftGetItems(rec,gamedef)); }
CraftInput CraftDefinitionShapeless::getInput(const CraftOutput &output, IGameDef *gamedef) const { return CraftInput(CRAFT_METHOD_NORMAL,0,craftGetItems(recipe,gamedef)); }