Cuberite
A lightweight, fast and extensible game server for Minecraft
BrewingstandEntity.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockEntityWithItems.h"
5 #include "../BrewingRecipes.h"
6 #include "../Root.h"
7 
8 
9 
10 
11 
12 class cClientHandle;
13 
14 
15 
16 
17 
18 // tolua_begin
21 {
22  // tolua_end
23 
25 
26  // tolua_begin
27 
28 public:
29 
30  enum
31  {
32  bsLeftBottle = 0, // Left bottle slot number
33  bsMiddleBottle = 1, // Middle bottle slot number
34  bsRightBottle = 2, // Right bottle slot number
35  bsIngredient = 3, // Top ingredient slot number
36  bsFuel = 4, // Top left fuel slot number
37 
40  };
41 
42  // tolua_end
43 
45  cBrewingstandEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World);
46 
47  // cBlockEntity overrides:
48  virtual void CopyFrom(const cBlockEntity & a_Src) override;
49  virtual void OnRemoveFromWorld() override;
50  virtual void SendTo(cClientHandle & a_Client) override;
51  virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
52  virtual bool UsedBy(cPlayer * a_Player) override;
53 
54  // tolua_begin
55 
57  short GetBrewingTimeLeft(void) const { return m_NeedBrewingTime - m_TimeBrewed; }
58 
60  short GetTimeBrewed(void) { return m_TimeBrewed; }
61 
63  short GetRemainingFuel(void) { return m_RemainingFuel; }
64 
66  const cItem & GetLeftBottleSlot(void) const { return GetSlot(bsLeftBottle); }
67 
69  const cItem & GetMiddleBottleSlot(void) const { return GetSlot(bsMiddleBottle); }
70 
72  const cItem & GetRightBottleSlot(void) const { return GetSlot(bsRightBottle); }
73 
75  const cItem & GetIndgredientSlot(void) const { return GetSlot(bsIngredient); }
76 
78  const cItem & GetFuelSlot(void) const { return GetSlot(bsFuel); }
79 
81  const cItem & GetResultItem(size_t a_SlotNumber) { return m_Results[a_SlotNumber]; }
82 
84  void SetLeftBottleSlot(const cItem & a_Item) { SetSlot(bsLeftBottle, a_Item); }
85 
87  void SetMiddleBottleSlot(const cItem & a_Item) { SetSlot(bsMiddleBottle, a_Item); }
88 
90  void SetRightBottleSlot(const cItem & a_Item) { SetSlot(bsRightBottle, a_Item); }
91 
93  void SetIngredientSlot(const cItem & a_Item) { SetSlot(bsIngredient, a_Item); }
94 
96  void SetFuelSlot(const cItem & a_Item) { SetSlot(bsFuel, a_Item); }
97 
98  // tolua_end
99 
101  void SetTimeBrewed(short a_TimeBrewed) { m_TimeBrewed = a_TimeBrewed; }
102 
104  void SetRemainingFuel(short a_RemainingFuel) { m_RemainingFuel = a_RemainingFuel; }
105 
107  void ContinueBrewing(void);
108 
110  void LoadRecipes(void);
111 
112 protected:
113 
116 
118  const short m_NeedBrewingTime = 400;
119 
121  std::array<const cBrewingRecipes::cRecipe *, 3> m_CurrentBrewingRecipes = {};
122 
124  std::array<cItem, 3> m_Results;
125 
128 
131 
133  void BroadcastProgress(size_t a_ProgressbarID, short a_Value);
134 
135  // /** Broadcasts progressbar updates, if needed */
136  void UpdateProgressBars(bool a_ForceUpdate = false);
137 
138  // cItemGrid::cListener overrides:
139  virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
140 } ; // tolua_export
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
const cItem & GetSlot(int a_SlotNum) const
cBlockEntityWithItems(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, int a_ItemGridWidth, int a_ItemGridHeight, cWorld *a_World)
void SetSlot(int a_SlotNum, const cItem &a_Item)
bool m_IsBrewing
Set to true if the brewing stand is brewing an item.
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking.
short m_RemainingFuel
The remaining fuel for the brewing stand.
short GetTimeBrewed(void)
Returns the time that the current items has been brewing, in ticks.
void SetLeftBottleSlot(const cItem &a_Item)
Sets the item in the left bottle slot
virtual void OnSlotChanged(cItemGrid *a_ItemGrid, int a_SlotNum) override
Called whenever a slot changes.
void SetIngredientSlot(const cItem &a_Item)
Sets the item in the ingredient slot
const cItem & GetIndgredientSlot(void) const
Returns the item in the ingredient slot
void ContinueBrewing(void)
Starts the brewing proccess.
void SetRightBottleSlot(const cItem &a_Item)
Sets the item in the right bottle slot
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
short GetBrewingTimeLeft(void) const
Returns the time until the current items finishes brewing, in ticks.
void LoadRecipes(void)
Gets the recipes.
void SetFuelSlot(const cItem &a_Item)
Sets the item in the fuel slot
virtual void OnRemoveFromWorld() override
Called when the block entity object is removed from a world.
const cItem & GetLeftBottleSlot(void) const
Returns the item in the left bottle slot
short GetRemainingFuel(void)
Returns the remaining fuel that is left.
void SetMiddleBottleSlot(const cItem &a_Item)
Sets the item in the middle bottle slot
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
std::array< const cBrewingRecipes::cRecipe *, 3 > m_CurrentBrewingRecipes
Store the current brewing recipes.
const cItem & GetFuelSlot(void) const
Returns the item in the fuel slot.
void BroadcastProgress(size_t a_ProgressbarID, short a_Value)
Sends the specified progressbar value to all clients of the window.
void SetTimeBrewed(short a_TimeBrewed)
Sets the current brewing time.
const cItem & GetMiddleBottleSlot(void) const
Returns the item in the middle bottle slot
const cItem & GetResultItem(size_t a_SlotNumber)
Get the expected result item for the given slot number.
void UpdateProgressBars(bool a_ForceUpdate=false)
const cItem & GetRightBottleSlot(void) const
Returns the item in the right bottle slot
std::array< cItem, 3 > m_Results
Result items for the bottle inputs.
const short m_NeedBrewingTime
Brewing time is 400 ticks.
void SetRemainingFuel(short a_RemainingFuel)
Sets the remaining fuel.
cBrewingstandEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Constructor used for normal operation.
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
short m_TimeBrewed
Amount of ticks that the current item has been brewed.
Definition: Chunk.h:36
Definition: Player.h:29
Definition: Item.h:37
Definition: World.h:53