summaryrefslogtreecommitdiffstats
path: root/source/cPlayer.cpp
diff options
context:
space:
mode:
authormtilden@gmail.com <mtilden@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-29 16:31:48 +0100
committermtilden@gmail.com <mtilden@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-29 16:31:48 +0100
commitd7adbba59d2372234a616b87f8b3b5a03888ddbc (patch)
treeee465a22205a21de84b57b931a15942382acc9a0 /source/cPlayer.cpp
parentM$ BS... (diff)
downloadcuberite-d7adbba59d2372234a616b87f8b3b5a03888ddbc.tar
cuberite-d7adbba59d2372234a616b87f8b3b5a03888ddbc.tar.gz
cuberite-d7adbba59d2372234a616b87f8b3b5a03888ddbc.tar.bz2
cuberite-d7adbba59d2372234a616b87f8b3b5a03888ddbc.tar.lz
cuberite-d7adbba59d2372234a616b87f8b3b5a03888ddbc.tar.xz
cuberite-d7adbba59d2372234a616b87f8b3b5a03888ddbc.tar.zst
cuberite-d7adbba59d2372234a616b87f8b3b5a03888ddbc.zip
Diffstat (limited to '')
-rw-r--r--source/cPlayer.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index 820b11f8b..baba0174a 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -81,6 +81,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName)
{
m_EntityType = E_PLAYER;
SetMaxHealth(20);
+ SetMaxFoodLevel(125);
m_Inventory = new cInventory( this );
cTimer t1;
m_LastPlayerListTime = t1.GetNowTime();
@@ -290,6 +291,22 @@ void cPlayer::Heal( int a_Health )
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
+ Health.m_Food = GetFood();
+ Health.m_Saturation = GetFoodSaturation();
+ m_ClientHandle->Send( Health );
+ }
+}
+
+void cPlayer::Feed( short a_Food )
+{
+ if( m_FoodLevel < GetMaxFoodLevel() )
+ {
+ m_FoodLevel = MIN(a_Food + m_FoodLevel, GetMaxFoodLevel());
+
+ cPacket_UpdateHealth Health;
+ Health.m_Health = m_Health;
+ Health.m_Food = GetFood();
+ Health.m_Saturation = GetFoodSaturation();
m_ClientHandle->Send( Health );
}
}
@@ -301,6 +318,8 @@ void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator )
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
+ Health.m_Food = GetFood();
+ Health.m_Saturation = GetFoodSaturation();
//TODO: Causes problems sometimes O.o (E.G. Disconnecting when attacked)
if(m_ClientHandle != 0)
m_ClientHandle->Send( Health );
@@ -772,6 +791,7 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor
}
m_Health = (short)root.get("health", 0 ).asInt();
+ m_FoodLevel = (short)root.get("food", 0 ).asInt();
m_Inventory->LoadFromJson(root["inventory"]);
m_pState->LoadedWorldName = root.get("world", "world").asString();
@@ -804,6 +824,7 @@ bool cPlayer::SaveToDisk()
root["rotation"] = JSON_PlayerRotation;
root["inventory"] = JSON_Inventory;
root["health"] = m_Health;
+ root["food"] = m_FoodLevel;
root["world"] = GetWorld()->GetName();
Json::StyledWriter writer;