From d3801c0296dd32f430a4074932bfabf27a8ade03 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 28 Jul 2013 11:30:54 +0200 Subject: Added cPlayer::IsGameModeXXX() and cWorld::IsGameModeXXX() functions. These are the preferred way of determining the gamemode, you should use those instead of doing manual comparisons to the gamemode value. --- source/Player.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index 83181dda6..5609807b0 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -505,7 +505,6 @@ void cPlayer::KilledBy(cEntity * a_Killer) void cPlayer::Respawn(void) { m_Health = GetMaxHealth(); - m_FoodLevel = 20; m_ClientHandle->SendRespawn(); @@ -538,6 +537,36 @@ Vector3d cPlayer::GetEyePosition(void) const +bool cPlayer::IsGameModeCreative(void) const +{ + return (m_GameMode == gmCreative) || // Either the player is explicitly in Creative + ((m_GameMode == gmNotSet) && m_World->IsGameModeCreative()); // or they inherit from the world and the world is Creative +} + + + + + +bool cPlayer::IsGameModeSurvival(void) const +{ + return (m_GameMode == gmSurvival) || // Either the player is explicitly in Survival + ((m_GameMode == gmNotSet) && m_World->IsGameModeSurvival()); // or they inherit from the world and the world is Survival +} + + + + + +bool cPlayer::IsGameModeAdventure(void) const +{ + return (m_GameMode == gmCreative) || // Either the player is explicitly in Adventure + ((m_GameMode == gmNotSet) && m_World->IsGameModeCreative()); // or they inherit from the world and the world is Adventure +} + + + + + void cPlayer::OpenWindow(cWindow * a_Window) { if (a_Window != m_CurrentWindow) @@ -1283,6 +1312,11 @@ void cPlayer::HandleFood(void) void cPlayer::ApplyFoodExhaustionFromMovement(cChunk & a_Chunk) { + if (IsGameModeCreative()) + { + return; + } + // Calculate the distance travelled, update the last pos: Vector3d Movement(GetPosition() - m_LastFoodPos); m_LastFoodPos = GetPosition(); -- cgit v1.2.3