From 041bfd5860cd8ef51db42eb6fb4b50b45549feba Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 19 Jul 2014 01:40:29 -0700 Subject: Fixed clamping issues --- src/Entities/Entity.cpp | 5 +---- src/Entities/Player.cpp | 5 +---- src/Entities/SplashPotionEntity.cpp | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 61b28ec70..f9331ede8 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -327,10 +327,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) // TODO: Apply damage to armor - if (m_Health < 0) - { - m_Health = 0; - } + m_Health = std::max(m_Health, 0); if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL)) // Knockback for only players and mobs { diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ea11926b8..7376441b4 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -382,10 +382,7 @@ short cPlayer::DeltaExperience(short a_Xp_delta) m_CurrentXp += a_Xp_delta; // Make sure they didn't subtract too much - if (m_CurrentXp < 0) - { - m_CurrentXp = 0; - } + m_CurrentXp = std::max(m_CurrentXp, 0); // Update total for score calculation if (a_Xp_delta > 0) diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp index 3efb1f25d..ccadf9c8e 100644 --- a/src/Entities/SplashPotionEntity.cpp +++ b/src/Entities/SplashPotionEntity.cpp @@ -44,10 +44,7 @@ public: // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash. // TODO: better equation double Reduction = -0.25 * SplashDistance + 1.0; - if (Reduction < 0) - { - Reduction = 0; - } + Reduction = std::max(Reduction, 0.0); ((cPawn *) a_Entity)->AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction); return false; -- cgit v1.2.3 From 7c861f98a2933e125f100f239d0ae5e977d1a719 Mon Sep 17 00:00:00 2001 From: archshift Date: Sat, 19 Jul 2014 02:55:36 -0700 Subject: Minecart: slimmed down SpawnOn by keeping subtype in the payload enum --- src/Entities/Minecart.cpp | 16 +--------------- src/Entities/Minecart.h | 11 ++++++----- 2 files changed, 7 insertions(+), 20 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 03850c8a7..d4eadc5d5 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -103,21 +103,7 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) { - char SubType = 0; - switch (m_Payload) - { - case mpNone: SubType = 0; break; - case mpChest: SubType = 1; break; - case mpFurnace: SubType = 2; break; - case mpTNT: SubType = 3; break; - case mpHopper: SubType = 5; break; - default: - { - ASSERT(!"Unknown payload, cannot spawn on client"); - return; - } - } - a_ClientHandle.SendSpawnVehicle(*this, 10, SubType); // 10 = Minecarts, SubType = What type of Minecart + a_ClientHandle.SendSpawnVehicle(*this, 10, (char)m_Payload); // 10 = Minecarts a_ClientHandle.SendEntityMetadata(*this); } diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index 798f844ce..c585cfab0 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -23,13 +23,14 @@ class cMinecart : public: CLASS_PROTODEF(cMinecart); + /** Minecart payload, values correspond to packet subtype */ enum ePayload { - mpNone, // Empty minecart, ridable by player or mobs - mpChest, // Minecart-with-chest, can store a grid of 3*8 items - mpFurnace, // Minecart-with-furnace, can be powered - mpTNT, // Minecart-with-TNT, can be blown up with activator rail - mpHopper, // Minecart-with-hopper, can be hopper + mpNone = 0, // Empty minecart, ridable by player or mobs + mpChest = 1, // Minecart-with-chest, can store a grid of 3*8 items + mpFurnace = 2, // Minecart-with-furnace, can be powered + mpTNT = 3, // Minecart-with-TNT, can be blown up with activator rail + mpHopper = 5, // Minecart-with-hopper, can be hopper // TODO: Spawner minecarts, (and possibly any block in a minecart with NBT editing) } ; -- cgit v1.2.3