Cuberite
A lightweight, fast and extensible game server for Minecraft
FurnaceEntity.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockEntityWithItems.h"
5 #include "../FurnaceRecipe.h"
6 
7 
8 
9 
10 
11 class cClientHandle;
12 
13 
14 
15 
16 
17 // tolua_begin
20 {
21  // tolua_end
22 
24 
25  // tolua_begin
26 
27 public:
28 
29  enum
30  {
31  fsInput = 0, // Input slot number
32  fsFuel = 1, // Fuel slot number
33  fsOutput = 2, // Output slot number
34 
37  };
38 
39  // tolua_end
40 
42  cFurnaceEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World);
43 
44  // cBlockEntity overrides:
45  virtual void CopyFrom(const cBlockEntity & a_Src) override;
46  virtual void OnRemoveFromWorld() override;
47  virtual void SendTo(cClientHandle & a_Client) override;
48  virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
49  virtual bool UsedBy(cPlayer * a_Player) override;
50 
54  bool ContinueCooking(void);
55 
56  // tolua_begin
57 
59  const cItem & GetInputSlot(void) const { return GetSlot(fsInput); }
60 
62  const cItem & GetFuelSlot(void) const { return GetSlot(fsFuel); }
63 
65  const cItem & GetOutputSlot(void) const { return GetSlot(fsOutput); }
66 
68  void SetInputSlot(const cItem & a_Item) { SetSlot(fsInput, a_Item); }
69 
71  void SetFuelSlot(const cItem & a_Item) { SetSlot(fsFuel, a_Item); }
72 
74  void SetOutputSlot(const cItem & a_Item) { SetSlot(fsOutput, a_Item); }
75 
77  int GetTimeCooked(void) const { return m_TimeCooked; }
78 
80  int GetCookTimeLeft(void) const { return m_NeedCookTime - m_TimeCooked; }
81 
83  int GetFuelBurnTimeLeft(void) const { return m_FuelBurnTime - m_TimeBurned; }
84 
86  bool HasFuelTimeLeft(void) const { return (GetFuelBurnTimeLeft() > 0); }
87 
89  int GetAndResetReward(void);
90 
91  // tolua_end
92 
93  void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned)
94  {
95  m_FuelBurnTime = a_FuelBurnTime;
96  m_TimeBurned = a_TimeBurned;
97  }
98 
99  void SetCookTimes(int a_NeedCookTime, int a_TimeCooked)
100  {
101  m_NeedCookTime = a_NeedCookTime;
102  m_TimeCooked = a_TimeCooked;
103  }
104 
105  void SetLoading(bool a_IsLoading)
106  {
107  m_IsLoading = a_IsLoading;
108  }
109 
110 
111 protected:
112 
115 
118 
121 
124 
127 
130 
133 
136 
139 
141  void BroadcastProgress(size_t a_ProgressbarID, short a_Value);
142 
144  void FinishOne();
145 
147  void BurnNewFuel(void);
148 
150  void UpdateInput(void);
151 
153  void UpdateFuel(void);
154 
156  void UpdateOutput(void);
157 
159  bool CanCookInputToOutput(void) const;
160 
162  void UpdateProgressBars(bool a_ForceUpdate = false);
163 
165  void SetIsCooking(bool a_IsCooking);
166 
167  // cItemGrid::cListener overrides:
168  virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
169 
170 } ; // 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 CanCookInputToOutput(void) const
Returns true if the input can be cooked into output and the item counts allow for another cooking ope...
const cItem & GetInputSlot(void) const
Returns the item in the input slot.
Definition: FurnaceEntity.h:59
int m_FuelBurnTime
Amount of ticks that the current fuel can burn (in total); zero if no fuel burning.
bool m_IsLoading
Is the block currently being loaded into the world?
void FinishOne()
One item finished cooking.
const cItem & GetFuelSlot(void) const
Returns the item in the fuel slot.
Definition: FurnaceEntity.h:62
const cFurnaceRecipe::cRecipe * m_CurrentRecipe
The recipe for the current input slot.
virtual void OnRemoveFromWorld() override
Called when the block entity object is removed from a world.
bool m_IsCooking
Set to true if the furnace is cooking an item.
void SetOutputSlot(const cItem &a_Item)
Sets the item in the output slot.
Definition: FurnaceEntity.h:74
int GetFuelBurnTimeLeft(void) const
Returns the time until the current fuel is depleted, in ticks.
Definition: FurnaceEntity.h:83
bool HasFuelTimeLeft(void) const
Returns true if there's time left before the current fuel is depleted.
Definition: FurnaceEntity.h:86
int GetTimeCooked(void) const
Returns the time that the current item has been cooking, in ticks.
Definition: FurnaceEntity.h:77
void UpdateOutput(void)
Called when the output slot changes.
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
void SetLoading(bool a_IsLoading)
int m_NeedCookTime
Amount of ticks needed to fully cook current 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.
int GetCookTimeLeft(void) const
Returns the time until the current item finishes cooking, in ticks.
Definition: FurnaceEntity.h:80
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
int m_TimeBurned
Amount of ticks that the current fuel has been burning.
cItem m_LastInput
The item that is being smelted.
cFurnaceEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Constructor used for normal operation.
void SetIsCooking(bool a_IsCooking)
Sets the m_IsCooking variable, updates the furnace block type based on the value.
void UpdateInput(void)
Updates the recipe, based on the current input.
const cItem & GetOutputSlot(void) const
Returns the item in the output slot.
Definition: FurnaceEntity.h:65
float m_RewardCounter
Running total of experience that can be picked up.
void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned)
Definition: FurnaceEntity.h:93
void SetCookTimes(int a_NeedCookTime, int a_TimeCooked)
Definition: FurnaceEntity.h:99
bool ContinueCooking(void)
Restarts cooking Used after the furnace is loaded from storage to set up the internal variables so th...
virtual void OnSlotChanged(cItemGrid *a_ItemGrid, int a_SlotNum) override
Called whenever a slot changes.
void BroadcastProgress(size_t a_ProgressbarID, short a_Value)
Sends the specified progressbar value to all clients of the window.
int m_TimeCooked
Amount of ticks that the current item has been cooking.
void UpdateFuel(void)
Called when the fuel slot changes or when the fuel is spent, burns another piece of fuel if appropria...
void BurnNewFuel(void)
Starts burning a new fuel, if possible.
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
void SetInputSlot(const cItem &a_Item)
Sets the item in the input slot.
Definition: FurnaceEntity.h:68
int GetAndResetReward(void)
Calculates, resets, and returns the experience reward in this furnace.
void SetFuelSlot(const cItem &a_Item)
Sets the item in the fuel slot.
Definition: FurnaceEntity.h:71
void UpdateProgressBars(bool a_ForceUpdate=false)
Broadcasts progressbar updates, if needed.
Definition: Chunk.h:36
Definition: Player.h:29
Definition: Item.h:37
Definition: World.h:53