Cuberite
A lightweight, fast and extensible game server for Minecraft
CraftingRecipes.h
Go to the documentation of this file.
1 
2 // CraftingRecipes.h
3 
4 // Interfaces to the cCraftingRecipes class representing the storage of crafting recipes
5 
6 
7 
8 
9 #pragma once
10 
11 #include "Item.h"
12 
13 
14 
15 
16 
17 // fwd: cPlayer.h
18 class cPlayer;
19 
20 
21 
22 
23 
24 class cCraftingGrid // tolua_export
25 { // tolua_export
26 public:
27  cCraftingGrid(const cCraftingGrid & a_Original);
28  cCraftingGrid(int a_Width, int a_Height); // tolua_export
29  cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height);
31 
32  // tolua_begin
33  int GetWidth (void) const {return m_Width; }
34  int GetHeight(void) const {return m_Height; }
35  cItem & GetItem (int x, int y) const;
36  void SetItem (int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth);
37  void SetItem (int x, int y, const cItem & a_Item);
38  void Clear (void);
39 
41  void ConsumeGrid(const cCraftingGrid & a_Grid);
42 
44  void Dump(void);
45 
46  // tolua_end
47 
48  cItem * GetItems(void) const {return m_Items; }
49 
51  void CopyToItems(cItem * a_Items) const;
52 
53 protected:
54 
55  int m_Width;
56  int m_Height;
58 } ; // tolua_export
59 
60 
61 
62 
63 
64 class cCraftingRecipe // tolua_export
65 { // tolua_export
66 public:
67  cCraftingRecipe(const cCraftingGrid & a_CraftingGrid);
68 
69  // tolua_begin
70  void Clear (void);
71  int GetIngredientsWidth (void) const {return m_Ingredients.GetWidth(); }
72  int GetIngredientsHeight(void) const {return m_Ingredients.GetHeight(); }
73  cItem & GetIngredient (int x, int y) const {return m_Ingredients.GetItem(x, y); }
74  const cItem & GetResult (void) const {return m_Result; }
75  void SetResult (ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth);
76  void SetResult (const cItem & a_Item)
77  {
78  m_Result = a_Item;
79  }
80 
81  void SetIngredient (int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
82  {
83  m_Ingredients.SetItem(x, y, a_ItemType, a_ItemCount, a_ItemHealth);
84  }
85 
86  void SetIngredient (int x, int y, const cItem & a_Item)
87  {
88  m_Ingredients.SetItem(x, y, a_Item);
89  }
90 
92  void ConsumeIngredients(cCraftingGrid & a_CraftingGrid);
93 
95  void Dump(void);
96  // tolua_end
97 
98 protected:
99 
100  cCraftingGrid m_Ingredients; // Adjusted to correspond to the input crafting grid!
102 } ; // tolua_export
103 
104 
105 
106 
107 
109 {
110 public:
111  static const int MAX_GRID_WIDTH = 3;
112  static const int MAX_GRID_HEIGHT = 3;
113 
114  cCraftingRecipes(void);
115  ~cCraftingRecipes();
116 
118  void GetRecipe(cPlayer & a_Player, cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe);
119 
120 protected:
121 
122  struct cRecipeSlot
123  {
125  int x, y; // 1..3, or -1 for "any"
126  } ;
127  typedef std::vector<cRecipeSlot> cRecipeSlots;
128 
131  struct cRecipe
132  {
133  cRecipeSlots m_Ingredients;
135 
136  // Size of the regular items in the recipe; "anywhere" items are excluded:
137  int m_Width;
138  int m_Height;
139  } ;
140  typedef std::vector<cRecipe *> cRecipes;
141 
142  cRecipes m_Recipes;
143 
144  void LoadRecipes(void);
145  void ClearRecipes(void);
146 
148  void AddRecipeLine(int a_LineNum, const AString & a_RecipeLine);
149 
151  bool ParseItem(const AString & a_String, cItem & a_Item);
152 
154  bool ParseIngredient(const AString & a_String, cRecipe * a_Recipe);
155 
157  void NormalizeIngredients(cRecipe * a_Recipe);
158 
160  cRecipe * FindRecipe(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight);
161 
163  cRecipe * FindRecipeCropped(const cItem * a_CraftingGrid, int a_GridWidth, int a_GridHeight, int a_GridStride);
164 
166  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);
167 
169  void HandleFireworks(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_OffsetX, int a_OffsetY);
170 
172  void HandleDyedLeather(const cItem * a_CraftingGrid, cCraftingRecipes::cRecipe * a_Recipe, int a_GridStride, int a_GridWidth, int a_GridHeight);
173 } ;
174 
175 
176 
177 
A single recipe, stored.
std::vector< cRecipeSlot > cRecipeSlots
void ConsumeGrid(const cCraftingGrid &a_Grid)
Removes items in a_Grid from m_Items[] (used by cCraftingRecipe::ConsumeIngredients()) ...
const cItem & GetResult(void) const
void SetIngredient(int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
cItem & GetIngredient(int x, int y) const
std::vector< cRecipe * > cRecipes
Definition: Player.h:27
cItem * GetItems(void) const
void SetIngredient(int x, int y, const cItem &a_Item)
int GetIngredientsHeight(void) const
void SetResult(const cItem &a_Item)
void SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
void CopyToItems(cItem *a_Items) const
Copies internal contents into the item array specified.
int GetHeight(void) const
cItem & GetItem(int x, int y) const
int GetWidth(void) const
std::string AString
Definition: StringUtils.h:13
ENUM_ITEM_ID
Definition: BlockID.h:293
cCraftingGrid(const cCraftingGrid &a_Original)
Definition: Item.h:36
int GetIngredientsWidth(void) const
void Dump(void)
Dumps the entire crafting grid using LOGD()
cCraftingGrid m_Ingredients