summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChunkMap.cpp5
-rw-r--r--src/Defines.h13
-rw-r--r--src/Entities/Entity.cpp5
-rw-r--r--src/Entities/Minecart.cpp16
-rw-r--r--src/Entities/Minecart.h11
-rw-r--r--src/Entities/Player.cpp5
-rw-r--r--src/Entities/SplashPotionEntity.cpp5
-rw-r--r--src/Generating/Trees.cpp8
-rw-r--r--src/Mobs/Monster.cpp6
-rw-r--r--src/World.cpp3
10 files changed, 16 insertions, 61 deletions
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index e91f77d27..49e9245d2 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1951,10 +1951,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
double FinalDamage = (((1 / AbsoluteEntityPos.x) + (1 / AbsoluteEntityPos.y) + (1 / AbsoluteEntityPos.z)) * 2) * m_ExplosionSize;
// Clip damage values
- if (FinalDamage > a_Entity->GetMaxHealth())
- FinalDamage = a_Entity->GetMaxHealth();
- else if (FinalDamage < 0)
- FinalDamage = 0;
+ FinalDamage = Clamp(FinalDamage, 0.0, (double)a_Entity->GetMaxHealth());
if (!a_Entity->IsTNT() && !a_Entity->IsFallingBlock()) // Don't apply damage to other TNT entities and falling blocks, they should be invincible
{
diff --git a/src/Defines.h b/src/Defines.h
index f57e63c7f..f7c8d0fc5 100644
--- a/src/Defines.h
+++ b/src/Defines.h
@@ -470,18 +470,7 @@ inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_B
{
int Y = a_BlockY;
AddFaceDirection(a_BlockX, Y, a_BlockZ, a_BlockFace, a_bInverse);
- if (Y < 0)
- {
- a_BlockY = 0;
- }
- else if (Y > 255)
- {
- a_BlockY = 255;
- }
- else
- {
- a_BlockY = (unsigned char)Y;
- }
+ a_BlockY = Clamp<unsigned char>(Y, 0, 255);
}
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/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)
} ;
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<short int>(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 056700629..13cbcb0fc 100644
--- a/src/Entities/SplashPotionEntity.cpp
+++ b/src/Entities/SplashPotionEntity.cpp
@@ -48,10 +48,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;
diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp
index b7a08999d..c40322630 100644
--- a/src/Generating/Trees.cpp
+++ b/src/Generating/Trees.cpp
@@ -10,13 +10,6 @@
-// DEBUG:
-int gTotalLargeJungleTrees = 0;
-int gOversizeLargeJungleTrees = 0;
-
-
-
-
typedef struct
{
@@ -113,6 +106,7 @@ inline void PushCoordBlocks(int a_BlockX, int a_Height, int a_BlockZ, sSetBlockV
+
inline void PushCornerBlocks(int a_BlockX, int a_Height, int a_BlockZ, int a_Seq, cNoise & a_Noise, int a_Chance, sSetBlockVector & a_Blocks, int a_CornersDist, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta)
{
for (size_t i = 0; i < ARRAYCOUNT(Corners); i++)
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index e6c82a448..8d612fbaa 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -414,11 +414,7 @@ void cMonster::HandleFalling()
int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
{
int PosY = POSY_TOINT;
-
- if (PosY < 0)
- PosY = 0;
- else if (PosY > cChunkDef::Height)
- PosY = cChunkDef::Height;
+ PosY = Clamp(PosY, 0, cChunkDef::Height);
if (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))))
{
diff --git a/src/World.cpp b/src/World.cpp
index 186842b20..c27fd462b 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -570,12 +570,13 @@ void cWorld::Start(void)
m_TNTShrapnelLevel = (eShrapnelLevel)Clamp(TNTShrapnelLevel, (int)slNone, (int)slAll);
// Load allowed mobs:
- const char * DefaultMonsters = "";
+ AString DefaultMonsters;
switch (m_Dimension)
{
case dimOverworld: DefaultMonsters = "bat, cavespider, chicken, cow, creeper, enderman, horse, mooshroom, ocelot, pig, sheep, silverfish, skeleton, slime, spider, squid, wolf, zombie"; break;
case dimNether: DefaultMonsters = "blaze, ghast, magmacube, skeleton, zombie, zombiepigman"; break;
case dimEnd: DefaultMonsters = "enderman"; break;
+ case dimNotSet: break;
}
m_bAnimals = IniFile.GetValueSetB("Monsters", "AnimalsOn", true);
AString AllMonsters = IniFile.GetValueSet("Monsters", "Types", DefaultMonsters);