Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
cCraftingRecipes Class Reference

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< cRecipeSlotcRecipeSlots
 

Public Member Functions

 cCraftingRecipes (void)
 
std::vector< UInt32FindNewRecipesForItem (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...
 
cRecipeGetRecipeById (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)
 
cRecipeFindRecipe (const cItem *a_CraftingGrid, int a_GridWidth, int a_GridHeight)
 Finds a recipe matching the crafting grid. More...
 
cRecipeFindRecipeCropped (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)
 
cRecipeMatchRecipe (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, UInt32m_RecipeNameMap
 Mapping the minecraft recipe names to the internal cuberite recipe Ids. More...
 

Detailed Description

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.

Member Typedef Documentation

◆ cRecipes

typedef std::vector<cRecipe *> cCraftingRecipes::cRecipes
protected

Definition at line 160 of file CraftingRecipes.h.

◆ cRecipeSlots

Definition at line 137 of file CraftingRecipes.h.

Constructor & Destructor Documentation

◆ cCraftingRecipes()

cCraftingRecipes::cCraftingRecipes ( void  )

Definition at line 266 of file CraftingRecipes.cpp.

◆ ~cCraftingRecipes()

cCraftingRecipes::~cCraftingRecipes ( )

Definition at line 276 of file CraftingRecipes.cpp.

Member Function Documentation

◆ AddRecipeLine()

void cCraftingRecipes::AddRecipeLine ( int  a_LineNum,
const AString a_RecipeLine 
)
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.

◆ ClearRecipes()

void cCraftingRecipes::ClearRecipes ( void  )
protected

Definition at line 438 of file CraftingRecipes.cpp.

◆ FindNewRecipesForItem()

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.

◆ FindRecipe()

cCraftingRecipes::cRecipe * cCraftingRecipes::FindRecipe ( const cItem a_CraftingGrid,
int  a_GridWidth,
int  a_GridHeight 
)
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.

◆ FindRecipeCropped()

cCraftingRecipes::cRecipe * cCraftingRecipes::FindRecipeCropped ( const cItem a_CraftingGrid,
int  a_GridWidth,
int  a_GridHeight,
int  a_GridStride 
)
protected

Same as FindRecipe, but the grid is guaranteed to be of minimal dimensions needed.

Definition at line 717 of file CraftingRecipes.cpp.

◆ GetRecipe()

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.

◆ GetRecipeById()

cCraftingRecipes::cRecipe * cCraftingRecipes::GetRecipeById ( UInt32  a_RecipeId)

Returns the recipe by id.

Definition at line 342 of file CraftingRecipes.cpp.

◆ GetRecipeNameMap()

const std::map< AString, UInt32 > & cCraftingRecipes::GetRecipeNameMap ( )

Gets a map of all recipes with name and recipe id.

Definition at line 333 of file CraftingRecipes.cpp.

◆ HandleDyedLeather()

void cCraftingRecipes::HandleDyedLeather ( const cItem a_CraftingGrid,
cCraftingRecipes::cRecipe a_Recipe,
int  a_GridStride,
int  a_GridWidth,
int  a_GridHeight 
)
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.

◆ HandleFireworks()

void cCraftingRecipes::HandleFireworks ( const cItem a_CraftingGrid,
cCraftingRecipes::cRecipe a_Recipe,
int  a_GridStride,
int  a_OffsetX,
int  a_OffsetY 
)
protected

Searches for anything firework related, and does the data setting if appropriate.

Definition at line 884 of file CraftingRecipes.cpp.

◆ IsNewCraftableRecipe()

bool cCraftingRecipes::IsNewCraftableRecipe ( const cRecipe a_Recipe,
const cItem a_NewItem,
const std::set< cItem, cItem::sItemCompare > &  a_KnownItems 
)
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.

◆ LoadRecipes()

void cCraftingRecipes::LoadRecipes ( void  )
protected

Definition at line 382 of file CraftingRecipes.cpp.

◆ MatchRecipe()

cCraftingRecipes::cRecipe * cCraftingRecipes::MatchRecipe ( const cItem a_CraftingGrid,
int  a_GridWidth,
int  a_GridHeight,
int  a_GridStride,
const cRecipe a_Recipe,
int  a_OffsetX,
int  a_OffsetY 
)
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.

◆ NormalizeIngredients()

void cCraftingRecipes::NormalizeIngredients ( cCraftingRecipes::cRecipe a_Recipe)
protected

Moves the recipe to top-left corner, sets its MinWidth / MinHeight.

Definition at line 633 of file CraftingRecipes.cpp.

◆ ParseIngredient()

bool cCraftingRecipes::ParseIngredient ( const AString a_String,
cRecipe a_Recipe 
)
protected

Parses one ingredient and adds it to the specified recipe.

Returns true if successful.

Definition at line 557 of file CraftingRecipes.cpp.

◆ ParseItem()

bool cCraftingRecipes::ParseItem ( const AString a_String,
cItem a_Item 
)
protected

Parses an item string in the format "<ItemType>[^<Damage>]", returns true if successful.

Definition at line 524 of file CraftingRecipes.cpp.

◆ PopulateRecipeNameMap()

void cCraftingRecipes::PopulateRecipeNameMap ( void  )
private

Populates the RecipeNameMap.

Definition at line 423 of file CraftingRecipes.cpp.

Member Data Documentation

◆ m_RecipeNameMap

std::map<AString, UInt32> cCraftingRecipes::m_RecipeNameMap
private

Mapping the minecraft recipe names to the internal cuberite recipe Ids.

Definition at line 196 of file CraftingRecipes.h.

◆ m_Recipes

cRecipes cCraftingRecipes::m_Recipes
protected

Definition at line 162 of file CraftingRecipes.h.

◆ MAX_GRID_HEIGHT

const int cCraftingRecipes::MAX_GRID_HEIGHT = 3
static

Definition at line 121 of file CraftingRecipes.h.

◆ MAX_GRID_WIDTH

const int cCraftingRecipes::MAX_GRID_WIDTH = 3
static

Definition at line 120 of file CraftingRecipes.h.


The documentation for this class was generated from the following files: