diff options
Diffstat (limited to '')
-rw-r--r-- | src/BlockEntities/FurnaceEntity.cpp | 19 | ||||
-rw-r--r-- | src/BlockEntities/FurnaceEntity.h | 6 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index 1f7f6e023..96a17782a 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -32,6 +32,7 @@ cFurnaceEntity::cFurnaceEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, in m_TimeCooked(0), m_FuelBurnTime(0), m_TimeBurned(0), + m_RewardCounter(0), m_IsLoading(false) { m_Contents.AddListener(*this); @@ -173,6 +174,23 @@ bool cFurnaceEntity::ContinueCooking(void) +int cFurnaceEntity::GetAndResetReward(void) +{ + int Reward = FloorC(m_RewardCounter); + float Remainder = m_RewardCounter - static_cast<float>(Reward); + // Remainder is used as the percent chance of getting an extra xp point + if (GetRandomProvider().RandBool(Remainder)) + { + Reward++; + } + m_RewardCounter = 0.0; + return Reward; +} + + + + + void cFurnaceEntity::BroadcastProgress(short a_ProgressbarID, short a_Value) { cWindow * Window = GetWindow(); @@ -189,6 +207,7 @@ void cFurnaceEntity::BroadcastProgress(short a_ProgressbarID, short a_Value) void cFurnaceEntity::FinishOne() { m_TimeCooked = 0; + m_RewardCounter += m_CurrentRecipe->Reward; if (m_Contents.GetSlot(fsOutput).IsEmpty()) { diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index 7b189be85..b1166c3bf 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -84,6 +84,9 @@ public: /** Returns true if there's time left before the current fuel is depleted */ bool HasFuelTimeLeft(void) const { return (GetFuelBurnTimeLeft() > 0); } + /** Calculates, resets, and returns the experience reward in this furnace */ + int GetAndResetReward(void); + // tolua_end void SetBurnTimes(int a_FuelBurnTime, int a_TimeBurned) @@ -130,6 +133,9 @@ protected: /** Amount of ticks that the current fuel has been burning */ int m_TimeBurned; + /** Running total of experience that can be picked up */ + float m_RewardCounter; + /** Is the block currently being loaded into the world? */ bool m_IsLoading; |