diff options
author | madmaxoft <github@xoft.cz> | 2013-07-28 19:15:03 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-07-28 19:15:03 +0200 |
commit | 4746d2251c6204118e710c818d78b89c356a7427 (patch) | |
tree | 2573e0b5e70b04aebc35d5da034c8449ff696f3d /source/Player.cpp | |
parent | ProtoProxy now properly waits for both sides to establish encryption (diff) | |
download | cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.gz cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.bz2 cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.lz cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.xz cuberite-4746d2251c6204118e710c818d78b89c356a7427.tar.zst cuberite-4746d2251c6204118e710c818d78b89c356a7427.zip |
Diffstat (limited to 'source/Player.cpp')
-rw-r--r-- | source/Player.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/source/Player.cpp b/source/Player.cpp index 2aa041ff4..c177b8cf4 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -20,6 +20,7 @@ #include "OSSupport/Timer.h"
#include "MersenneTwister.h"
#include "Chunk.h"
+#include "Items/ItemHandler.h"
#include "Vector3d.h"
#include "Vector3f.h"
@@ -58,6 +59,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) , m_SprintingMaxSpeed(0.13)
, m_IsCrouched(false)
, m_IsSprinting(false)
+ , m_EatingFinishTick(-1)
{
LOGD("Created a player object for \"%s\" @ \"%s\" at %p, ID %d",
a_PlayerName.c_str(), a_Client->GetIPString().c_str(),
@@ -189,6 +191,11 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) {
m_World->CollectPickupsByPlayer(this);
+ if ((m_EatingFinishTick >= 0) && (m_EatingFinishTick <= m_World->GetWorldAge()))
+ {
+ FinishEating();
+ }
+
HandleFood();
}
@@ -349,6 +356,57 @@ void cPlayer::FoodPoison(int a_NumTicks) +void cPlayer::StartEating(void)
+{
+ // Set the timer:
+ m_EatingFinishTick = m_World->GetWorldAge() + EATING_TICKS;
+
+ // Send the packets:
+ m_World->BroadcastPlayerAnimation(*this, 5);
+ m_World->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
+void cPlayer::FinishEating(void)
+{
+ // Reset the timer:
+ m_EatingFinishTick = -1;
+
+ // Send the packets:
+ m_ClientHandle->SendEntityStatus(*this, ENTITY_STATUS_EATING_ACCEPTED);
+ m_World->BroadcastPlayerAnimation(*this, 0);
+ m_World->BroadcastEntityMetadata(*this);
+
+ // consume the item:
+ cItem Item(GetEquippedItem());
+ Item.m_ItemCount = 1;
+ cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Item.m_ItemType);
+ if (!ItemHandler->EatItem(this, &Item))
+ {
+ return;
+ }
+ ItemHandler->OnFoodEaten(m_World, this, &Item);
+ GetInventory().RemoveOneEquippedItem();
+}
+
+
+
+
+
+void cPlayer::AbortEating(void)
+{
+ m_EatingFinishTick = -1;
+ m_World->BroadcastPlayerAnimation(*this, 0);
+ m_World->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
void cPlayer::SendHealth(void)
{
if (m_ClientHandle != NULL)
|