Cuberite
A lightweight, fast and extensible game server for Minecraft
|
The crafting recipes are the configurations to build a result item out of a set of ingredient items. More...
#include <CraftingRecipes.h>
Classes | |
struct | cRecipe |
A single recipe, stored. More... | |
struct | cRecipeSlot |
Public Types | |
typedef std::vector< cRecipeSlot > | cRecipeSlots |
Public Member Functions | |
cCraftingRecipes (void) | |
std::vector< UInt32 > | FindNewRecipesForItem (const cItem &a_Item, const std::set< cItem, cItem::sItemCompare > &a_KnownItems) |
Find recipes and returns the RecipeIds which contain the new item and all ingredients are in the known items. More... | |
void | GetRecipe (cPlayer &a_Player, cCraftingGrid &a_CraftingGrid, cCraftingRecipe &a_Recipe) |
Returns the recipe for current crafting grid. More... | |
cRecipe * | GetRecipeById (UInt32 a_RecipeId) |
Returns the recipe by id. More... | |
const std::map< AString, UInt32 > & | GetRecipeNameMap () |
Gets a map of all recipes with name and recipe id. More... | |
~cCraftingRecipes () | |
Static Public Attributes | |
static const int | MAX_GRID_HEIGHT = 3 |
static const int | MAX_GRID_WIDTH = 3 |
Protected Types | |
typedef std::vector< cRecipe * > | cRecipes |
Protected Member Functions | |
void | AddRecipeLine (int a_LineNum, const AString &a_RecipeLine) |
Parses the recipe line and adds it into m_Recipes. More... | |
void | ClearRecipes (void) |
cRecipe * | FindRecipe (const cItem *a_CraftingGrid, int a_GridWidth, int a_GridHeight) |
Finds a recipe matching the crafting grid. More... | |
cRecipe * | FindRecipeCropped (const cItem *a_CraftingGrid, int a_GridWidth, int a_GridHeight, int a_GridStride) |
Same as FindRecipe, but the grid is guaranteed to be of minimal dimensions needed. More... | |
void | HandleDyedLeather (const cItem *a_CraftingGrid, cCraftingRecipes::cRecipe *a_Recipe, int a_GridStride, int a_GridWidth, int a_GridHeight) |
Searches for anything dye related for leather, calculates the appropriate color value, and sets the resulting value. More... | |
void | HandleFireworks (const cItem *a_CraftingGrid, cCraftingRecipes::cRecipe *a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY) |
Searches for anything firework related, and does the data setting if appropriate. More... | |
void | LoadRecipes (void) |
cRecipe * | MatchRecipe (const cItem *a_CraftingGrid, int a_GridWidth, int a_GridHeight, int a_GridStride, const cRecipe *a_Recipe, int a_OffsetX, int a_OffsetY) |
Checks if the grid matches the specified recipe, offset by the specified offsets. More... | |
void | NormalizeIngredients (cRecipe *a_Recipe) |
Moves the recipe to top-left corner, sets its MinWidth / MinHeight. More... | |
bool | ParseIngredient (const AString &a_String, cRecipe *a_Recipe) |
Parses one ingredient and adds it to the specified recipe. More... | |
bool | ParseItem (const AString &a_String, cItem &a_Item) |
Parses an item string in the format "<ItemType>[^<Damage>]", returns true if successful. More... | |
Protected Attributes | |
cRecipes | m_Recipes |
Private Member Functions | |
bool | IsNewCraftableRecipe (const cRecipe *a_Recipe, const cItem &a_NewItem, const std::set< cItem, cItem::sItemCompare > &a_KnownItems) |
Checks if all ingredients of the a_Recipe are within the a_KnownItems list and if the a_NewItem is part of the ingredients. More... | |
void | PopulateRecipeNameMap (void) |
Populates the RecipeNameMap. More... | |
Private Attributes | |
std::map< AString, UInt32 > | m_RecipeNameMap |
Mapping the minecraft recipe names to the internal cuberite recipe Ids. More... | |
The crafting recipes are the configurations to build a result item out of a set of ingredient items.
The recipes are configured in the crafting.txt
. When populating the crafting grid in game (inventory or crafting table), the items are compared to the ingredients to find a matching recipe and show and craft the result.
Each recipe is defined via the result, the ingredients and the minecraft recipe name.
To handle the crafting recipes internally efficient the vector index of the cRecipes
is used as RecipeId
.
Definition at line 117 of file CraftingRecipes.h.
|
protected |
Definition at line 160 of file CraftingRecipes.h.
typedef std::vector<cRecipeSlot> cCraftingRecipes::cRecipeSlots |
Definition at line 137 of file CraftingRecipes.h.
cCraftingRecipes::cCraftingRecipes | ( | void | ) |
Definition at line 266 of file CraftingRecipes.cpp.
cCraftingRecipes::~cCraftingRecipes | ( | ) |
Definition at line 276 of file CraftingRecipes.cpp.
|
protected |
Parses the recipe line and adds it into m_Recipes.
a_LineNum is used for diagnostic warnings only
Definition at line 451 of file CraftingRecipes.cpp.
|
protected |
Definition at line 438 of file CraftingRecipes.cpp.
std::vector< UInt32 > cCraftingRecipes::FindNewRecipesForItem | ( | const cItem & | a_Item, |
const std::set< cItem, cItem::sItemCompare > & | a_KnownItems | ||
) |
Find recipes and returns the RecipeIds which contain the new item and all ingredients are in the known items.
Definition at line 312 of file CraftingRecipes.cpp.
|
protected |
Finds a recipe matching the crafting grid.
Returns a newly allocated recipe (with all its coords set) or nullptr if not found. Caller must delete return value!
Definition at line 674 of file CraftingRecipes.cpp.
|
protected |
Same as FindRecipe, but the grid is guaranteed to be of minimal dimensions needed.
Definition at line 717 of file CraftingRecipes.cpp.
void cCraftingRecipes::GetRecipe | ( | cPlayer & | a_Player, |
cCraftingGrid & | a_CraftingGrid, | ||
cCraftingRecipe & | a_Recipe | ||
) |
Returns the recipe for current crafting grid.
Doesn't modify the grid. Clears a_Recipe if no recipe found.
Definition at line 351 of file CraftingRecipes.cpp.
cCraftingRecipes::cRecipe * cCraftingRecipes::GetRecipeById | ( | UInt32 | a_RecipeId | ) |
Returns the recipe by id.
Definition at line 342 of file CraftingRecipes.cpp.
Gets a map of all recipes with name and recipe id.
Definition at line 333 of file CraftingRecipes.cpp.
|
protected |
Searches for anything dye related for leather, calculates the appropriate color value, and sets the resulting value.
Definition at line 965 of file CraftingRecipes.cpp.
|
protected |
Searches for anything firework related, and does the data setting if appropriate.
Definition at line 884 of file CraftingRecipes.cpp.
|
private |
Checks if all ingredients of the a_Recipe are within the a_KnownItems list and if the a_NewItem is part of the ingredients.
This makes sure to only find 'newly discovered' recipes.
Definition at line 285 of file CraftingRecipes.cpp.
|
protected |
Definition at line 382 of file CraftingRecipes.cpp.
|
protected |
Checks if the grid matches the specified recipe, offset by the specified offsets.
Returns a matched cRecipe * if so, or nullptr if not matching. Caller must delete the return value!
Definition at line 747 of file CraftingRecipes.cpp.
|
protected |
Moves the recipe to top-left corner, sets its MinWidth / MinHeight.
Definition at line 633 of file CraftingRecipes.cpp.
Parses one ingredient and adds it to the specified recipe.
Returns true if successful.
Definition at line 557 of file CraftingRecipes.cpp.
Parses an item string in the format "<ItemType>[^<Damage>]", returns true if successful.
Definition at line 524 of file CraftingRecipes.cpp.
|
private |
Populates the RecipeNameMap.
Definition at line 423 of file CraftingRecipes.cpp.
Mapping the minecraft recipe names to the internal cuberite recipe Ids.
Definition at line 196 of file CraftingRecipes.h.
|
protected |
Definition at line 162 of file CraftingRecipes.h.
|
static |
Definition at line 121 of file CraftingRecipes.h.
|
static |
Definition at line 120 of file CraftingRecipes.h.