summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-07-28 11:30:54 +0200
committermadmaxoft <github@xoft.cz>2013-07-28 11:30:54 +0200
commitd3801c0296dd32f430a4074932bfabf27a8ade03 (patch)
tree529694175b56e5eac589277298796a095ef55560 /source
parentUpdated Core to the latest version. (diff)
downloadcuberite-d3801c0296dd32f430a4074932bfabf27a8ade03.tar
cuberite-d3801c0296dd32f430a4074932bfabf27a8ade03.tar.gz
cuberite-d3801c0296dd32f430a4074932bfabf27a8ade03.tar.bz2
cuberite-d3801c0296dd32f430a4074932bfabf27a8ade03.tar.lz
cuberite-d3801c0296dd32f430a4074932bfabf27a8ade03.tar.xz
cuberite-d3801c0296dd32f430a4074932bfabf27a8ade03.tar.zst
cuberite-d3801c0296dd32f430a4074932bfabf27a8ade03.zip
Diffstat (limited to '')
-rw-r--r--source/Player.cpp36
-rw-r--r--source/Player.h13
-rw-r--r--source/World.h11
3 files changed, 58 insertions, 2 deletions
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();
diff --git a/source/Player.h b/source/Player.h
index fed222157..69b0c3df1 100644
--- a/source/Player.h
+++ b/source/Player.h
@@ -73,7 +73,18 @@ public:
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override;
- eGameMode GetGameMode(void) const { return m_GameMode; } // tolua_export
+ /// Returns the current gamemode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable
+ eGameMode GetGameMode(void) const { return m_GameMode; } // tolua_export
+
+ /// Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world
+ bool IsGameModeCreative(void) const;
+
+ /// Returns true if the player is in Survival mode, either explicitly, or by inheriting from current world
+ bool IsGameModeSurvival(void) const;
+
+ /// Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world
+ bool IsGameModeAdventure(void) const;
+
std::string GetIP() { return m_IP; } // tolua_export
float GetLastBlockActionTime() { return m_LastBlockActionTime; } // tolua_export
int GetLastBlockActionCnt() { return m_LastBlockActionCnt; } // tolua_export
diff --git a/source/World.h b/source/World.h
index 5da7218e2..e67b06789 100644
--- a/source/World.h
+++ b/source/World.h
@@ -106,7 +106,18 @@ public:
SetTimeOfDay(a_TimeOfDay);
}
+ /// Returns the current game mode. Partly OBSOLETE, you should use IsGameModeXXX() functions wherever applicable
eGameMode GetGameMode(void) const { return m_GameMode; }
+
+ /// Returns true if the world is in Creative mode
+ bool IsGameModeCreative(void) const { return (m_GameMode == gmCreative); }
+
+ /// Returns true if the world is in Survival mode
+ bool IsGameModeSurvival(void) const { return (m_GameMode == gmSurvival); }
+
+ /// Returns true if the world is in Adventure mode
+ bool IsGameModeAdventure(void) const { return (m_GameMode == gmAdventure); }
+
bool IsPVPEnabled(void) const { return m_bEnabledPVP; }
bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; }