summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2014-08-03 15:32:45 +0200
committerSTRWarrior <niels.breuker@hotmail.nl>2014-08-03 15:32:45 +0200
commita24e960a894384a6161e71ddb0032707ab6bfdc0 (patch)
tree0700958027fbd2031c0bd54e369f5a02fbbda2a2 /src/Entities/Entity.cpp
parentVillageGen: Fixed a typo in comment (diff)
parentEntity.cpp: Air timer comment fix (diff)
downloadcuberite-a24e960a894384a6161e71ddb0032707ab6bfdc0.tar
cuberite-a24e960a894384a6161e71ddb0032707ab6bfdc0.tar.gz
cuberite-a24e960a894384a6161e71ddb0032707ab6bfdc0.tar.bz2
cuberite-a24e960a894384a6161e71ddb0032707ab6bfdc0.tar.lz
cuberite-a24e960a894384a6161e71ddb0032707ab6bfdc0.tar.xz
cuberite-a24e960a894384a6161e71ddb0032707ab6bfdc0.tar.zst
cuberite-a24e960a894384a6161e71ddb0032707ab6bfdc0.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp142
1 files changed, 63 insertions, 79 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);
}