From 7915c4ca7cf4a7afaa86e62757d23364ead4c69e Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 2 Aug 2014 21:44:02 -0700 Subject: Entity.cpp: On portal check, use if-else for current dimension If current dimension corresponds with the portal (nether portal in the nether) send to the overworld, else send to the portal dimension. No need to switch on the dimension and exclude potential others. --- src/Entities/Entity.cpp | 114 +++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 60 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index da578013d..c2727e6a1 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1068,42 +1068,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()) + { + ((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); + } + else + { + if (GetWorld()->GetNetherWorldName().empty()) + { + return false; + } + + m_PortalCooldownData.m_ShouldPreventTeleportation = true; + + 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)->AwardAchievement(achEnterPortal); + ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimNether); } - default: return false; + + return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()), false); } } case E_BLOCK_END_PORTAL: @@ -1113,45 +1109,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; } -- cgit v1.2.3 From 3ffec92e7930c0b4bb14073f23a9d12313bd6cbc Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 2 Aug 2014 22:27:27 -0700 Subject: Removed unused cPlayer::FoodPoison function --- src/Entities/Player.cpp | 9 --------- src/Entities/Player.h | 3 --- 2 files changed, 12 deletions(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ca3b1f367..d3d5a61d4 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -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: 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); } -- cgit v1.2.3 From 9ecce2366e81ae66c77312220e378ff2f1b02a24 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 2 Aug 2014 22:35:29 -0700 Subject: Code reduction and clarity fixes --- src/Entities/Entity.cpp | 28 +++++++++------------------- src/Entities/Player.cpp | 17 +++++++---------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c2727e6a1..042e3b868 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); } @@ -1264,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) + // Either reduce air level or damage player + if (m_AirTickTimer <= 0) { // Damage player TakeDamage(dtDrowning, NULL, 1, 1, 0); @@ -1552,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 d3d5a61d4..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); } @@ -700,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; } } -- cgit v1.2.3 From e461df00302939cd767ae0c6a31ce22fc94e977c Mon Sep 17 00:00:00 2001 From: archshift Date: Sun, 3 Aug 2014 02:20:48 -0700 Subject: Entity.cpp: Air timer comment fix --- src/Entities/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 042e3b868..a274e6780 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1263,7 +1263,7 @@ void cEntity::HandleAir(void) if (m_AirLevel <= 0) { - // Either reduce air level or damage player + // Runs the air tick timer to check whether the player should be damaged if (m_AirTickTimer <= 0) { // Damage player -- cgit v1.2.3