Files
cuberite-2a/src/BlockEntities/FurnaceEntity.h
T

173 lines
4.6 KiB
C++
Raw Normal View History

#pragma once
2013-06-16 20:24:07 +00:00
#include "BlockEntityWithItems.h"
#include "../FurnaceRecipe.h"
namespace Json
{
class Value;
}
class cClientHandle;
2012-08-11 11:51:32 +00:00
2013-12-16 22:02:28 +01:00
// tolua_begin
class cFurnaceEntity :
2014-02-12 22:01:22 +00:00
public cBlockEntityWithItems
{
2013-06-16 20:24:07 +00:00
typedef cBlockEntityWithItems super;
public:
2013-06-16 20:24:07 +00:00
enum
{
fsInput = 0, // Input slot number
fsFuel = 1, // Fuel slot number
fsOutput = 2, // Output slot number
ContentsWidth = 3,
ContentsHeight = 1,
};
// tolua_end
BLOCKENTITY_PROTODEF(cFurnaceEntity);
2014-10-03 21:32:41 +01:00
/** Constructor used for normal operation */
cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cWorld * a_World);
2013-06-16 20:24:07 +00:00
virtual ~cFurnaceEntity();
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void UsedBy(cPlayer * a_Player) override;
2014-10-03 21:32:41 +01:00
virtual void Destroy() override
{
m_IsDestroyed = true;
super::Destroy();
}
2014-10-03 21:32:41 +01:00
/** Restarts cooking
Used after the furnace is loaded from storage to set up the internal variables so that cooking continues, if it was active
Returns true if cooking */
bool ContinueCooking(void);
2013-06-16 20:24:07 +00:00
// tolua_begin
2014-10-03 21:32:41 +01:00
/** Returns the item in the input slot */
2013-06-16 20:24:07 +00:00
const cItem & GetInputSlot(void) const { return GetSlot(fsInput); }
2014-10-03 21:32:41 +01:00
/** Returns the item in the fuel slot */
2013-06-16 20:24:07 +00:00
const cItem & GetFuelSlot(void) const { return GetSlot(fsFuel); }
2014-10-03 21:32:41 +01:00
/** Returns the item in the output slot */
2013-06-16 20:24:07 +00:00
const cItem & GetOutputSlot(void) const { return GetSlot(fsOutput); }
2014-10-03 21:32:41 +01:00
/** Sets the item in the input slot */
2013-06-16 20:24:07 +00:00
void SetInputSlot(const cItem & a_Item) { SetSlot(fsInput, a_Item); }
2014-10-03 21:32:41 +01:00
/** Sets the item in the fuel slot */
2013-06-16 20:24:07 +00:00
void SetFuelSlot(const cItem & a_Item) { SetSlot(fsFuel, a_Item); }
2014-10-03 21:32:41 +01:00
/** Sets the item in the output slot */
2013-06-16 20:24:07 +00:00
void SetOutputSlot(const cItem & a_Item) { SetSlot(fsOutput, a_Item); }
2014-10-03 21:32:41 +01:00
/** Returns the time that the current item has been cooking, in ticks */
int GetTimeCooked(void) const { return m_TimeCooked; }
2013-06-16 20:24:07 +00:00
2014-10-03 21:32:41 +01:00
/** Returns the time until the current item finishes cooking, in ticks */
2013-06-16 20:24:07 +00:00
int GetCookTimeLeft(void) const { return m_NeedCookTime - m_TimeCooked; }
2014-10-03 21:32:41 +01:00
/** Returns the time until the current fuel is depleted, in ticks */
int GetFuelBurnTimeLeft(void) const { return m_FuelBurnTime - m_TimeBurned; }
2014-10-03 21:32:41 +01:00
/** Returns true if there's time left before the current fuel is depleted */
2013-06-16 20:24:07 +00:00
bool HasFuelTimeLeft(void) const { return (GetFuelBurnTimeLeft() > 0); }
2013-06-16 20:24:07 +00:00
// tolua_end
2014-10-03 21:32:41 +01:00
void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned)
{
m_FuelBurnTime = a_FuelBurnTime;
m_TimeBurned = a_TimeBurned;
}
void SetCookTimes(int a_NeedCookTime, int a_TimeCooked)
{
m_NeedCookTime = a_NeedCookTime;
m_TimeCooked = a_TimeCooked;
}
2013-06-16 20:24:07 +00:00
protected:
2014-10-03 21:32:41 +01:00
/** Block meta of the block currently represented by this entity */
NIBBLETYPE m_BlockMeta;
2014-10-03 21:32:41 +01:00
/** The recipe for the current input slot */
2014-08-31 19:00:36 +02:00
const cFurnaceRecipe::cRecipe * m_CurrentRecipe;
2013-06-16 20:24:07 +00:00
2014-10-03 21:32:41 +01:00
/** The item that is being smelted */
2013-06-16 20:24:07 +00:00
cItem m_LastInput;
2014-10-03 21:32:41 +01:00
/** Set to true when the furnace entity has been destroyed to prevent the block being set again */
bool m_IsDestroyed;
2013-06-16 20:24:07 +00:00
2014-10-03 21:32:41 +01:00
/** Set to true if the furnace is cooking an item */
bool m_IsCooking;
2012-09-20 13:25:54 +00:00
2014-10-03 21:32:41 +01:00
/** Amount of ticks needed to fully cook current item */
int m_NeedCookTime;
/** Amount of ticks that the current item has been cooking */
int m_TimeCooked;
/** Amount of ticks that the current fuel can burn (in total); zero if no fuel burning */
int m_FuelBurnTime;
/** Amount of ticks that the current fuel has been burning */
2014-10-21 22:00:31 +02:00
int m_TimeBurned;
2014-10-03 21:32:41 +01:00
/** Sends the specified progressbar value to all clients of the window */
void BroadcastProgress(short a_ProgressbarID, short a_Value);
2013-06-16 20:24:07 +00:00
2014-10-03 21:32:41 +01:00
/** One item finished cooking */
2014-02-24 11:29:59 -08:00
void FinishOne();
2013-06-16 20:24:07 +00:00
2014-10-03 21:32:41 +01:00
/** Starts burning a new fuel, if possible */
2013-06-16 20:24:07 +00:00
void BurnNewFuel(void);
2014-10-03 21:32:41 +01:00
/** Updates the recipe, based on the current input */
2013-06-16 20:24:07 +00:00
void UpdateInput(void);
2014-10-03 21:32:41 +01:00
/** Called when the fuel slot changes or when the fuel is spent, burns another piece of fuel if appropriate */
2013-06-16 20:24:07 +00:00
void UpdateFuel(void);
2014-10-03 21:32:41 +01:00
/** Called when the output slot changes */
2013-06-16 20:24:07 +00:00
void UpdateOutput(void);
2014-10-03 21:32:41 +01:00
/** Returns true if the input can be cooked into output and the item counts allow for another cooking operation */
2013-06-16 20:24:07 +00:00
bool CanCookInputToOutput(void) const;
2014-10-03 21:32:41 +01:00
/** Broadcasts progressbar updates, if needed */
void UpdateProgressBars(bool a_ForceUpdate = false);
2013-06-16 20:24:07 +00:00
2014-10-03 21:32:41 +01:00
/** Sets the m_IsCooking variable, updates the furnace block type based on the value */
void SetIsCooking(bool a_IsCooking);
2013-06-16 20:24:07 +00:00
// cItemGrid::cListener overrides:
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
} ; // tolua_export