summaryrefslogtreecommitdiffstats
path: root/source/cFurnaceEntity.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-20 15:25:54 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-20 15:25:54 +0200
commitbc466f07a454271d4845a7e8c7f0822541c5afbd (patch)
treec8455a2af322bbd847b6b4ea74256b78aa834c4c /source/cFurnaceEntity.cpp
parentProtoProxy: moar packets! (can now sustain parsing while connected to vanilla server, most of the times) (diff)
downloadcuberite-bc466f07a454271d4845a7e8c7f0822541c5afbd.tar
cuberite-bc466f07a454271d4845a7e8c7f0822541c5afbd.tar.gz
cuberite-bc466f07a454271d4845a7e8c7f0822541c5afbd.tar.bz2
cuberite-bc466f07a454271d4845a7e8c7f0822541c5afbd.tar.lz
cuberite-bc466f07a454271d4845a7e8c7f0822541c5afbd.tar.xz
cuberite-bc466f07a454271d4845a7e8c7f0822541c5afbd.tar.zst
cuberite-bc466f07a454271d4845a7e8c7f0822541c5afbd.zip
Diffstat (limited to 'source/cFurnaceEntity.cpp')
-rw-r--r--source/cFurnaceEntity.cpp79
1 files changed, 50 insertions, 29 deletions
diff --git a/source/cFurnaceEntity.cpp b/source/cFurnaceEntity.cpp
index 5f0840913..0f51f4ade 100644
--- a/source/cFurnaceEntity.cpp
+++ b/source/cFurnaceEntity.cpp
@@ -4,7 +4,7 @@
#include "cFurnaceEntity.h"
#include "BlockID.h"
#include "cItem.h"
-#include "cFurnaceWindow.h"
+#include "UI/cWindow.h"
#include "cPlayer.h"
#include "cWorld.h"
#include "cClientHandle.h"
@@ -18,6 +18,17 @@
+
+enum
+{
+ PROGRESSBAR_SMELTING = 0,
+ PROGRESSBAR_FUEL = 1,
+} ;
+
+
+
+
+
cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
: cBlockEntity( E_BLOCK_FURNACE, a_X, a_Y, a_Z, a_World )
, m_Items( new cItem[3] )
@@ -72,24 +83,20 @@ void cFurnaceEntity::Destroy()
-void cFurnaceEntity::UsedBy( cPlayer * a_Player )
+void cFurnaceEntity::UsedBy(cPlayer * a_Player)
{
LOG("Used a furnace");
- if( !GetWindow() )
+ if (GetWindow() == NULL)
{
- cWindow* Window = new cFurnaceWindow( this );
- Window->SetSlots( m_Items, 3 );
- Window->SetWindowTitle("UberFurnace");
- OpenWindow( Window );
+ OpenWindow(new cFurnaceWindow(m_PosX, m_PosY, m_PosZ, this));
}
- if( GetWindow() )
+ if (GetWindow() != NULL)
{
- if( a_Player->GetWindow() != GetWindow() )
+ if (a_Player->GetWindow() != GetWindow())
{
- a_Player->OpenWindow( GetWindow() );
-
- GetWindow()->SendWholeWindow( a_Player->GetClientHandle() );
+ a_Player->OpenWindow(GetWindow());
+ GetWindow()->SendWholeWindow(*a_Player->GetClientHandle());
}
}
}
@@ -109,12 +116,19 @@ bool cFurnaceEntity::Tick( float a_Dt )
if (m_BurnTime <= 0)
{
+ if (m_TimeCooked > 0)
+ {
+ // We have just finished smelting, reset the progress bar:
+ BroadcastProgress(PROGRESSBAR_SMELTING, 0);
+ m_TimeCooked = 0;
+ }
// There is no fuel and no flame, no need to tick at all
return false;
}
// DEBUG: LOGD("Furnace: Left: %0.1f Burned: %0.1f Burn time: %0.1f", m_CookTime - m_TimeCooked, m_TimeBurned, m_BurnTime );
+ short SmeltingProgress = 0;
if ((m_CookingItem != NULL) && ((m_TimeBurned < m_BurnTime) || (m_TimeCooked + a_Dt >= m_CookTime)))
{
if (m_CookingItem->IsEqual(m_Items[2]) || m_Items[2].IsEmpty())
@@ -140,16 +154,12 @@ bool cFurnaceEntity::Tick( float a_Dt )
m_TimeCooked -= m_CookTime;
StartCooking();
}
- cWindow * Window = GetWindow();
- if (Window != NULL)
- {
- short Value = (short)( m_TimeCooked * (180.f / m_CookTime));
- if (Value > 180) Value = 180;
- if (Value < 0) Value = 0;
- Window->BroadcastInventoryProgress(0, Value);
- }
+ SmeltingProgress = (short)( m_TimeCooked * (180.f / m_CookTime));
+ if (SmeltingProgress > 180) SmeltingProgress = 180;
+ if (SmeltingProgress < 0) SmeltingProgress = 0;
}
}
+ BroadcastProgress(PROGRESSBAR_SMELTING, SmeltingProgress);
m_TimeBurned += a_Dt;
@@ -163,17 +173,15 @@ bool cFurnaceEntity::Tick( float a_Dt )
Window->BroadcastWholeWindow();
}
}
- if (Window != NULL)
+ short Value = 0;
+ if (m_BurnTime > 0.f)
{
- short Value = 0;
- if (m_BurnTime > 0.f)
- {
- Value = 250 - (short)( m_TimeBurned * (250.f / m_BurnTime));
- if (Value > 250) Value = 250;
- if (Value < 0) Value = 0;
- }
- Window->BroadcastInventoryProgress(1, Value);
+ Value = 250 - (short)( m_TimeBurned * (250.f / m_BurnTime));
+ if (Value > 250) Value = 250;
+ if (Value < 0) Value = 0;
}
+ BroadcastProgress(PROGRESSBAR_FUEL, Value);
+
return ((m_CookingItem != NULL) || (m_TimeBurned < m_BurnTime)) && (m_BurnTime > 0.0); // Keep on ticking, if there's more to cook, or if it's cooking
}
@@ -396,3 +404,16 @@ void cFurnaceEntity::SendTo(cClientHandle & a_Client)
+
+void cFurnaceEntity::BroadcastProgress(int a_ProgressbarID, short a_Value)
+{
+ cWindow * Window = GetWindow();
+ if (Window != NULL)
+ {
+ Window->BroadcastInventoryProgress(a_ProgressbarID, a_Value);
+ }
+}
+
+
+
+