summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/PluginManager.cpp8
-rw-r--r--src/ClientHandle.cpp3
-rw-r--r--src/Entities/Entity.h28
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Generating/CompoGen.cpp2
-rw-r--r--src/Generating/FinishGen.h4
-rw-r--r--src/World.cpp6
-rw-r--r--src/World.h5
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp1
-rw-r--r--src/WorldStorage/WSSAnvil.cpp7
10 files changed, 30 insertions, 36 deletions
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 088b92a6d..3560b8660 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -476,11 +476,9 @@ bool cPluginManager::CallHookDisconnect(cClientHandle & a_Client, const AString
bool cPluginManager::CallHookEntityAddEffect(cEntity & a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier)
{
- HookMap::iterator Plugins = m_Hooks.find(HOOK_ENTITY_ADD_EFFECT);
- if (Plugins == m_Hooks.end())
- {
- return false;
- }
+ FIND_HOOK(HOOK_ENTITY_ADD_EFFECT);
+ VERIFY_HOOK;
+
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnEntityAddEffect(a_Entity, a_EffectType, a_EffectDurationTicks, a_EffectIntensity, a_DistanceModifier))
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index aaed483e2..b390bf2d6 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -120,8 +120,7 @@ cClientHandle::~cClientHandle()
}
if (World != NULL)
{
- m_Player->SetWorldTravellingFrom(NULL); // Make sure that the player entity is actually removed
- World->RemovePlayer(m_Player); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
+ World->RemovePlayer(m_Player, true); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
m_Player->Destroy();
}
delete m_Player;
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index e66194ca2..b9c280b6b 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -128,20 +128,20 @@ public:
esFireworkExploding = 17,
} ;
- enum
- {
- FIRE_TICKS_PER_DAMAGE = 10, ///< How many ticks to wait between damaging an entity when it stands in fire
- FIRE_DAMAGE = 1, ///< How much damage to deal when standing in fire
- LAVA_TICKS_PER_DAMAGE = 10, ///< How many ticks to wait between damaging an entity when it stands in lava
- LAVA_DAMAGE = 5, ///< How much damage to deal when standing in lava
- BURN_TICKS_PER_DAMAGE = 20, ///< How many ticks to wait between damaging an entity when it is burning
- BURN_DAMAGE = 1, ///< How much damage to deal when the entity is burning
- BURN_TICKS = 200, ///< How long to keep an entity burning after it has stood in lava / fire
- MAX_AIR_LEVEL = 300, ///< Maximum air an entity can have
- DROWNING_TICKS = 20, ///< Number of ticks per heart of damage
- VOID_BOUNDARY = -46, ///< At what position Y to begin applying void damage
- FALL_DAMAGE_HEIGHT = 4 ///< At what position Y fall damage is applied
- } ;
+ static const int FIRE_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in fire
+ static const int FIRE_DAMAGE = 1; ///< Damage to deal when standing in fire
+ static const int LAVA_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in lava
+ static const int LAVA_DAMAGE = 5; ///< Damage to deal when standing in lava
+ static const int BURN_TICKS_PER_DAMAGE = 20; ///< Ticks to wait between damaging an entity when it is burning
+ static const int BURN_DAMAGE = 1; ///< Damage to deal when the entity is burning
+
+ static const int BURN_TICKS = 200; ///< Ticks to keep an entity burning after it has stood in lava / fire
+
+ static const int MAX_AIR_LEVEL = 300; ///< Maximum air an entity can have
+ static const int DROWNING_TICKS = 20; ///< Number of ticks per heart of damage
+
+ static const int VOID_BOUNDARY = -46; ///< Y position to begin applying void damage
+ static const int FALL_DAMAGE_HEIGHT = 4; ///< Y difference after which fall damage is applied
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
virtual ~cEntity();
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index ffdcca2ec..cf3322968 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1627,7 +1627,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
// Remove player from the old world
SetWorldTravellingFrom(GetWorld()); // cChunk handles entity removal
- GetWorld()->RemovePlayer(this);
+ GetWorld()->RemovePlayer(this, false);
// Queue adding player to the new world, including all the necessary adjustments to the object
a_World->AddPlayer(this);
diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp
index 912d74248..178673e32 100644
--- a/src/Generating/CompoGen.cpp
+++ b/src/Generating/CompoGen.cpp
@@ -638,7 +638,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc)
CeilingDisguise = -CeilingDisguise;
}
- int CeilingDisguiseHeight = Height - 2 - CeilingDisguise * 3;
+ int CeilingDisguiseHeight = Height - 2 - (int)CeilingDisguise * 3;
for (int y = Height - 1; y > CeilingDisguiseHeight; y--)
{
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index ed32768b3..50a0fd2e7 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -163,7 +163,7 @@ public:
m_Amount(a_Amount)
{
// Initialize all the block types.
- for (int idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
+ for (size_t idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
{
m_IsAllowedBelow[idx] = false;
}
@@ -175,7 +175,7 @@ public:
}
// Initialize all the biome types.
- for (int idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
+ for (size_t idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
{
m_IsBiomeAllowed[idx] = false;
}
diff --git a/src/World.cpp b/src/World.cpp
index 0b0f7870b..84c0f2b93 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2465,10 +2465,12 @@ void cWorld::AddPlayer(cPlayer * a_Player)
-void cWorld::RemovePlayer(cPlayer * a_Player)
+void cWorld::RemovePlayer(cPlayer * a_Player, bool a_RemoveFromChunk)
{
- if (!a_Player->IsWorldTravellingFrom(this))
+ if (a_RemoveFromChunk)
{
+ // To prevent iterator invalidations when an entity goes through a portal and calls this function whilst being ticked by cChunk
+ // we should not change cChunk's entity list if asked not to
m_ChunkMap->RemoveEntity(a_Player);
}
{
diff --git a/src/World.h b/src/World.h
index 4bf5a9d64..6649c4163 100644
--- a/src/World.h
+++ b/src/World.h
@@ -281,8 +281,9 @@ public:
/** Removes the player from the world.
Removes the player from the addition queue, too, if appropriate.
- If the player has a ClientHandle, the ClientHandle is removed from all chunks in the world and will not be ticked by this world anymore. */
- void RemovePlayer(cPlayer * a_Player);
+ If the player has a ClientHandle, the ClientHandle is removed from all chunks in the world and will not be ticked by this world anymore.
+ @param a_RemoveFromChunk determines if the entity should be removed from its chunk as well. Should be false when ticking from cChunk. */
+ void RemovePlayer(cPlayer * a_Player, bool a_RemoveFromChunk);
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
virtual bool ForEachPlayer(cPlayerListCallback & a_Callback) override; // >> EXPORTED IN MANUALBINDINGS <<
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index b7a3d40ce..4857da1b6 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -486,7 +486,6 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
m_Writer.AddFloat("", a_Monster->GetDropChanceBoots());
m_Writer.EndList();
m_Writer.AddByte("CanPickUpLoot", (char)a_Monster->CanPickUpLoot());
- m_Writer.AddShort("Health", (short)a_Monster->GetHealth());
switch (a_Monster->GetMobType())
{
case cMonster::mtBat:
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 6134e2c0a..71ff3ef99 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -2475,10 +2475,7 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N
// Load health:
int Health = a_NBT.FindChildByName(a_TagIdx, "Health");
- if (Health > 0)
- {
- a_Entity.SetHealth(a_NBT.GetShort(Health));
- }
+ a_Entity.SetHealth(Health > 0 ? a_NBT.GetShort(Health) : a_Entity.GetMaxHealth());
return true;
}
@@ -2507,8 +2504,6 @@ bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT &
a_Monster.SetCanPickUpLoot(CanPickUpLoot);
}
- int HealthTag = a_NBT.FindChildByName(a_TagIdx, "Health");
- a_Monster.SetHealth(HealthTag > 0 ? a_NBT.GetShort(HealthTag) : a_Monster.GetMaxHealth());
return true;
}