summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp142
-rw-r--r--src/Entities/Player.cpp26
-rw-r--r--src/Entities/Player.h3
3 files changed, 70 insertions, 101 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index da578013d..a274e6780 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -543,10 +543,7 @@ void cEntity::KilledBy(TakeDamageInfo & a_TDI)
void cEntity::Heal(int a_HitPoints)
{
m_Health += a_HitPoints;
- if (m_Health > m_MaxHealth)
- {
- m_Health = m_MaxHealth;
- }
+ m_Health = std::min(m_Health, m_MaxHealth);
}
@@ -555,7 +552,7 @@ void cEntity::Heal(int a_HitPoints)
void cEntity::SetHealth(int a_Health)
{
- m_Health = std::max(0, std::min(m_MaxHealth, a_Health));
+ m_Health = Clamp(a_Health, 0, m_MaxHealth);
}
@@ -1068,42 +1065,38 @@ bool cEntity::DetectPortal()
}
m_PortalCooldownData.m_TicksDelayed = 0;
- switch (GetWorld()->GetDimension())
+ if (GetWorld()->GetDimension() == dimNether)
{
- case dimNether:
+ if (GetWorld()->GetLinkedOverworldName().empty())
{
- if (GetWorld()->GetLinkedOverworldName().empty())
- {
- return false;
- }
-
- m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
-
- if (IsPlayer())
- {
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimOverworld); // Send a respawn packet before world is loaded/generated so the client isn't left in limbo
- }
-
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
+ return false;
}
- case dimOverworld:
+
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
+
+ if (IsPlayer())
{
- if (GetWorld()->GetNetherWorldName().empty())
- {
- return false;
- }
-
- m_PortalCooldownData.m_ShouldPreventTeleportation = true;
-
- if (IsPlayer())
- {
- ((cPlayer *)this)->AwardAchievement(achEnterPortal);
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimNether);
- }
-
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()), false);
+ ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimOverworld); // Send a respawn packet before world is loaded/generated so the client isn't left in limbo
}
- default: return false;
+
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
+ }
+ else
+ {
+ if (GetWorld()->GetNetherWorldName().empty())
+ {
+ return false;
+ }
+
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
+
+ if (IsPlayer())
+ {
+ ((cPlayer *)this)->AwardAchievement(achEnterPortal);
+ ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimNether);
+ }
+
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()), false);
}
}
case E_BLOCK_END_PORTAL:
@@ -1113,45 +1106,43 @@ bool cEntity::DetectPortal()
return false;
}
- switch (GetWorld()->GetDimension())
+ if (GetWorld()->GetDimension() == dimEnd)
{
- case dimEnd:
+
+ if (GetWorld()->GetLinkedOverworldName().empty())
{
- if (GetWorld()->GetLinkedOverworldName().empty())
- {
- return false;
- }
-
- m_PortalCooldownData.m_ShouldPreventTeleportation = true;
+ return false;
+ }
- if (IsPlayer())
- {
- cPlayer * Player = (cPlayer *)this;
- Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z);
- Player->GetClientHandle()->SendRespawn(dimOverworld);
- }
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
- }
- case dimOverworld:
+ if (IsPlayer())
{
- if (GetWorld()->GetEndWorldName().empty())
- {
- return false;
- }
+ cPlayer * Player = (cPlayer *)this;
+ Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z);
+ Player->GetClientHandle()->SendRespawn(dimOverworld);
+ }
- m_PortalCooldownData.m_ShouldPreventTeleportation = true;
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
+ }
+ else
+ {
+ if (GetWorld()->GetEndWorldName().empty())
+ {
+ return false;
+ }
- if (IsPlayer())
- {
- ((cPlayer *)this)->AwardAchievement(achEnterTheEnd);
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimEnd);
- }
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
- return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName(), dimEnd, GetWorld()->GetName()), false);
+ if (IsPlayer())
+ {
+ ((cPlayer *)this)->AwardAchievement(achEnterTheEnd);
+ ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimEnd);
}
- default: return false;
+
+ return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName(), dimEnd, GetWorld()->GetName()), false);
}
+
}
default: break;
}
@@ -1270,10 +1261,10 @@ void cEntity::HandleAir(void)
SetSpeedY(1); // Float in the water
}
- // Either reduce air level or damage player
- if (m_AirLevel < 1)
+ if (m_AirLevel <= 0)
{
- if (m_AirTickTimer < 1)
+ // Runs the air tick timer to check whether the player should be damaged
+ if (m_AirTickTimer <= 0)
{
// Damage player
TakeDamage(dtDrowning, NULL, 1, 1, 0);
@@ -1558,17 +1549,10 @@ void cEntity::SetHeight(double a_Height)
void cEntity::SetMass(double a_Mass)
{
- if (a_Mass > 0)
- {
- m_Mass = a_Mass;
- }
- else
- {
- // Make sure that mass is not zero. 1g is the default because we
- // have to choose a number. It's perfectly legal to have a mass
- // less than 1g as long as is NOT equal or less than zero.
- m_Mass = 0.001;
- }
+ // Make sure that mass is not zero. 1g is the default because we
+ // have to choose a number. It's perfectly legal to have a mass
+ // less than 1g as long as is NOT equal or less than zero.
+ m_Mass = std::max(a_Mass, 0.001);
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index ca3b1f367..d1d7349a6 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -527,7 +527,7 @@ void cPlayer::SetFoodLevel(int a_FoodLevel)
void cPlayer::SetFoodSaturationLevel(double a_FoodSaturationLevel)
{
- m_FoodSaturationLevel = std::max(0.0, std::min(a_FoodSaturationLevel, (double)m_FoodLevel));
+ m_FoodSaturationLevel = Clamp(a_FoodSaturationLevel, 0.0, (double) m_FoodLevel);
}
@@ -545,7 +545,7 @@ void cPlayer::SetFoodTickTimer(int a_FoodTickTimer)
void cPlayer::SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
{
- m_FoodExhaustionLevel = std::max(0.0, std::min(a_FoodExhaustionLevel, 40.0));
+ m_FoodExhaustionLevel = Clamp(a_FoodExhaustionLevel, 0.0, 40.0);
}
@@ -580,15 +580,6 @@ void cPlayer::AddFoodExhaustion(double a_Exhaustion)
-void cPlayer::FoodPoison(int a_NumTicks)
-{
- AddEntityEffect(cEntityEffect::effHunger, a_NumTicks, 0, 1);
-}
-
-
-
-
-
void cPlayer::StartEating(void)
{
// Set the timer:
@@ -709,16 +700,13 @@ double cPlayer::GetMaxSpeed(void) const
{
return m_FlyingMaxSpeed;
}
+ else if (m_IsSprinting)
+ {
+ return m_SprintingMaxSpeed;
+ }
else
{
- if (m_IsSprinting)
- {
- return m_SprintingMaxSpeed;
- }
- else
- {
- return m_NormalMaxSpeed;
- }
+ return m_NormalMaxSpeed;
}
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 917e87a89..e3203d6d1 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -286,9 +286,6 @@ public:
/** Adds the specified exhaustion to m_FoodExhaustion. Expects only positive values. */
void AddFoodExhaustion(double a_Exhaustion);
- /** Starts the food poisoning for the specified amount of ticks */
- void FoodPoison(int a_NumTicks);
-
/** Returns true if the player is currently in the process of eating the currently equipped item */
bool IsEating(void) const { return (m_EatingFinishTick >= 0); }