summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-06-30 15:12:56 +0200
committerHowaner <franzi.moos@googlemail.com>2014-06-30 15:12:56 +0200
commitaa753a92c092a4d35b2ff7d08259c3196abecf67 (patch)
treebfc61dbfbc957110217460cb89d7be612ee1f944 /src/Entities
parentUnnecessary return (diff)
downloadcuberite-aa753a92c092a4d35b2ff7d08259c3196abecf67.tar
cuberite-aa753a92c092a4d35b2ff7d08259c3196abecf67.tar.gz
cuberite-aa753a92c092a4d35b2ff7d08259c3196abecf67.tar.bz2
cuberite-aa753a92c092a4d35b2ff7d08259c3196abecf67.tar.lz
cuberite-aa753a92c092a4d35b2ff7d08259c3196abecf67.tar.xz
cuberite-aa753a92c092a4d35b2ff7d08259c3196abecf67.tar.zst
cuberite-aa753a92c092a4d35b2ff7d08259c3196abecf67.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Player.cpp50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index daf1ef2cc..ed18d2ab7 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -37,9 +37,9 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
: super(etPlayer, 0.6, 1.8)
, m_bVisible(true)
, m_FoodLevel(MAX_FOOD_LEVEL)
- , m_FoodSaturationLevel(5)
+ , m_FoodSaturationLevel(5.0)
, m_FoodTickTimer(0)
- , m_FoodExhaustionLevel(0)
+ , m_FoodExhaustionLevel(0.0)
, m_FoodPoisonedTicksRemaining(0)
, m_LastJumpHeight(0)
, m_LastGroundHeight(0)
@@ -521,7 +521,15 @@ void cPlayer::Heal(int a_Health)
void cPlayer::SetFoodLevel(int a_FoodLevel)
{
- m_FoodLevel = std::max(0, std::min(a_FoodLevel, (int)MAX_FOOD_LEVEL));
+ a_FoodLevel = std::max(0, std::min(a_FoodLevel, (int)MAX_FOOD_LEVEL));
+
+ if (cRoot::Get()->GetPluginManager()->CallHookPlayerFoodLevelChange(*this, a_FoodLevel))
+ {
+ m_FoodSaturationLevel = 5.0;
+ return;
+ }
+
+ m_FoodLevel = a_FoodLevel;
SendHealth();
}
@@ -571,11 +579,9 @@ bool cPlayer::Feed(int a_Food, double a_Saturation)
{
return false;
}
-
- m_FoodLevel = std::min(a_Food + m_FoodLevel, (int)MAX_FOOD_LEVEL);
- m_FoodSaturationLevel = std::min(m_FoodSaturationLevel + a_Saturation, (double)m_FoodLevel);
-
- SendHealth();
+
+ SetFoodSaturationLevel(m_FoodSaturationLevel + a_Saturation);
+ SetFoodLevel(m_FoodLevel + a_Food);
return true;
}
@@ -969,7 +975,7 @@ void cPlayer::Respawn(void)
// Reset food level:
m_FoodLevel = MAX_FOOD_LEVEL;
- m_FoodSaturationLevel = 5;
+ m_FoodSaturationLevel = 5.0;
// Reset Experience
m_CurrentXp = 0;
@@ -1895,16 +1901,13 @@ void cPlayer::TickBurning(cChunk & a_Chunk)
void cPlayer::HandleFood(void)
{
// Ref.: http://www.minecraftwiki.net/wiki/Hunger
-
+
if (IsGameModeCreative())
{
// Hunger is disabled for Creative
return;
}
-
- // Remember the food level before processing, for later comparison
- int LastFoodLevel = m_FoodLevel;
-
+
// Heal or damage, based on the food level, using the m_FoodTickTimer:
if ((m_FoodLevel > 17) || (m_FoodLevel <= 0))
{
@@ -1917,7 +1920,7 @@ void cPlayer::HandleFood(void)
{
// Regenerate health from food, incur 3 pts of food exhaustion:
Heal(1);
- m_FoodExhaustionLevel += 3;
+ m_FoodExhaustionLevel += 3.0;
}
else if ((m_FoodLevel <= 0) && (m_Health > 1))
{
@@ -1926,7 +1929,7 @@ void cPlayer::HandleFood(void)
}
}
}
-
+
// Apply food poisoning food exhaustion:
if (m_FoodPoisonedTicksRemaining > 0)
{
@@ -1939,24 +1942,19 @@ void cPlayer::HandleFood(void)
}
// Apply food exhaustion that has accumulated:
- if (m_FoodExhaustionLevel >= 4)
+ if (m_FoodExhaustionLevel >= 4.0)
{
- m_FoodExhaustionLevel -= 4;
+ m_FoodExhaustionLevel -= 4.0;
- if (m_FoodSaturationLevel >= 1)
+ if (m_FoodSaturationLevel >= 1.0)
{
- m_FoodSaturationLevel -= 1;
+ m_FoodSaturationLevel -= 1.0;
}
else
{
- m_FoodLevel = std::max(m_FoodLevel - 1, 0);
+ SetFoodLevel(m_FoodLevel - 1);
}
}
-
- if (m_FoodLevel != LastFoodLevel)
- {
- SendHealth();
- }
}