summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Bindings/ManualBindings.cpp6
-rw-r--r--src/BlockEntities/DispenserEntity.cpp35
-rw-r--r--src/BlockEntities/DispenserEntity.h5
-rw-r--r--src/BlockEntities/MobSpawnerEntity.cpp2
-rw-r--r--src/Blocks/WorldInterface.h12
-rw-r--r--src/Chunk.cpp4
-rw-r--r--src/Chunk.h4
-rw-r--r--src/ChunkMap.cpp14
-rw-r--r--src/ChunkMap.h67
-rw-r--r--src/Entities/Entity.cpp75
-rw-r--r--src/Entities/Entity.h13
-rw-r--r--src/Entities/Minecart.cpp11
-rw-r--r--src/Entities/ProjectileEntity.cpp2
-rw-r--r--src/Entities/ProjectileEntity.h12
-rw-r--r--src/Items/ItemPotion.h2
-rw-r--r--src/Items/ItemSpawnEgg.h2
-rw-r--r--src/Items/ItemThrowable.h4
-rw-r--r--src/MapManager.cpp2
-rw-r--r--src/MapManager.h11
-rw-r--r--src/UI/SlotArea.h17
-rw-r--r--src/World.cpp45
-rw-r--r--src/World.h48
22 files changed, 224 insertions, 169 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 035be55ae..05389f723 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -590,7 +590,7 @@ static int tolua_DoWith(lua_State* tolua_S)
template <
class Ty1,
class Ty2,
- bool (Ty1::*Func1)(int, cItemCallback<Ty2> &)
+ bool (Ty1::*Func1)(UInt32, cItemCallback<Ty2> &)
>
static int tolua_DoWithID(lua_State* tolua_S)
{
@@ -3867,6 +3867,10 @@ void ManualBindings::Bind(lua_State * tolua_S)
BindRankManager(tolua_S);
BindNetwork(tolua_S);
+ tolua_beginmodule(tolua_S, "cEntity");
+ tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID);
+ tolua_endmodule(tolua_S);
+
tolua_endmodule(tolua_S);
}
diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp
index 42a0476b6..a847f1b65 100644
--- a/src/BlockEntities/DispenserEntity.cpp
+++ b/src/BlockEntities/DispenserEntity.cpp
@@ -105,7 +105,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
{
double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
double MobZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
- if (m_World->SpawnMob(MobX, DispY, MobZ, static_cast<eMonsterType>(m_Contents.GetSlot(a_SlotNum).m_ItemDamage)) >= 0)
+ if (m_World->SpawnMob(MobX, DispY, MobZ, static_cast<eMonsterType>(m_Contents.GetSlot(a_SlotNum).m_ItemDamage)) != cEntity::INVALID_ID)
{
m_Contents.ChangeSlotCount(a_SlotNum, -1);
}
@@ -144,29 +144,37 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
case E_ITEM_FIRE_CHARGE:
{
- SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkFireCharge, GetShootVector(Meta) * 20);
- m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ if (SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkFireCharge, GetShootVector(Meta) * 20) != cEntity::INVALID_ID)
+ {
+ m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ }
break;
}
case E_ITEM_ARROW:
{
- SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkArrow, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0));
- m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ if (SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkArrow, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0)) != cEntity::INVALID_ID)
+ {
+ m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ }
break;
}
case E_ITEM_SNOWBALL:
{
- SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkSnowball, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0));
- m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ if (SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkSnowball, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0)) != cEntity::INVALID_ID)
+ {
+ m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ }
break;
}
case E_ITEM_EGG:
{
- SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkEgg, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0));
- m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ if (SpawnProjectileFromDispenser(BlockX, DispY, BlockZ, cProjectileEntity::pkEgg, GetShootVector(Meta) * 20 + Vector3d(0, 1, 0)) != cEntity::INVALID_ID)
+ {
+ m_Contents.ChangeSlotCount(a_SlotNum, -1);
+ }
break;
}
@@ -188,9 +196,14 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
-void cDispenserEntity::SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_ShootVector)
+UInt32 cDispenserEntity::SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_ShootVector)
{
- m_World->CreateProjectile(static_cast<double>(a_BlockX + 0.5), static_cast<double>(a_BlockY + 0.5), static_cast<double>(a_BlockZ + 0.5), a_Kind, nullptr, nullptr, &a_ShootVector);
+ return m_World->CreateProjectile(
+ static_cast<double>(a_BlockX + 0.5),
+ static_cast<double>(a_BlockY + 0.5),
+ static_cast<double>(a_BlockZ + 0.5),
+ a_Kind, nullptr, nullptr, &a_ShootVector
+ );
}
diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h
index 12e12942a..62072d43b 100644
--- a/src/BlockEntities/DispenserEntity.h
+++ b/src/BlockEntities/DispenserEntity.h
@@ -24,8 +24,9 @@ public:
// tolua_begin
- /** Spawns a projectile of the given kind in front of the dispenser with the specified speed. */
- void SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_Speed);
+ /** Spawns a projectile of the given kind in front of the dispenser with the specified speed.
+ Returns the UniqueID of the spawned projectile, or 0 on failure. */
+ UInt32 SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY, int a_BlockZ, cProjectileEntity::eKind a_Kind, const Vector3d & a_Speed);
/** Returns a unit vector in the cardinal direction of where the dispenser is facing. */
Vector3d GetShootVector(NIBBLETYPE a_Meta);
diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp
index 9b3f605f9..764d7af84 100644
--- a/src/BlockEntities/MobSpawnerEntity.cpp
+++ b/src/BlockEntities/MobSpawnerEntity.cpp
@@ -169,7 +169,7 @@ void cMobSpawnerEntity::SpawnEntity(void)
Monster->SetPosition(PosX, RelY, PosZ);
Monster->SetYaw(Random.NextFloat() * 360.0f);
- if (Chunk->GetWorld()->SpawnMobFinalize(Monster) != mtInvalidType)
+ if (Chunk->GetWorld()->SpawnMobFinalize(Monster) != cEntity::INVALID_ID)
{
EntitiesSpawned = true;
Chunk->BroadcastSoundParticleEffect(2004, (int)(PosX * 8.0), (int)(RelY * 8.0), (int)(PosZ * 8.0), 0);
diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h
index 106c314e7..44c118195 100644
--- a/src/Blocks/WorldInterface.h
+++ b/src/Blocks/WorldInterface.h
@@ -30,14 +30,16 @@ public:
/** Spawns item pickups for each item in the list. May compress pickups if too many entities: */
virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false) = 0;
- /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */
+ /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified. */
virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) = 0;
- /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
- virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) = 0;
+ /** Spawns a mob of the specified type.
+ Returns the mob's UniqueID if recognized and spawned, or cEntity::INVALID_ID on failure. */
+ virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) = 0;
- /** Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. */
- virtual int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) = 0;
+ /** Spawns an experience orb at the given location with the given reward.
+ Returns the UniqueID of the spawned experience orb, or cEntity::INVALID_ID on failure. */
+ virtual UInt32 SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) = 0;
/** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */
virtual bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback) = 0;
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 00ac1fdb1..b23b28d7b 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -1969,7 +1969,7 @@ void cChunk::RemoveEntity(cEntity * a_Entity)
-bool cChunk::HasEntity(int a_EntityID)
+bool cChunk::HasEntity(UInt32 a_EntityID)
{
for (cEntityList::const_iterator itr = m_Entities.begin(), end = m_Entities.end(); itr != end; ++itr)
{
@@ -2027,7 +2027,7 @@ bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_
-bool cChunk::DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult)
+bool cChunk::DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult)
{
// The entity list is locked by the parent chunkmap's CS
for (cEntityList::iterator itr = m_Entities.begin(), end = m_Entities.end(); itr != end; ++itr)
diff --git a/src/Chunk.h b/src/Chunk.h
index 1ce862371..4522f56e1 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -241,7 +241,7 @@ public:
void AddEntity(cEntity * a_Entity);
void RemoveEntity(cEntity * a_Entity);
- bool HasEntity(int a_EntityID);
+ bool HasEntity(UInt32 a_EntityID);
/** Calls the callback for each entity; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible
@@ -251,7 +251,7 @@ public:
bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Lua-accessible
/** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. */
- bool DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult); // Lua-accessible
+ bool DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult); // Lua-accessible
/** Calls the callback for each block entity; returns true if all block entities processed, false if the callback aborted by returning true */
bool ForEachBlockEntity(cBlockEntityCallback & a_Callback); // Lua-accessible
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index b9d4ed55b..87da86131 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -373,19 +373,19 @@ void cChunkMap::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, c
-void cChunkMap::BroadcastBlockBreakAnimation(int a_entityID, int a_blockX, int a_blockY, int a_blockZ, char a_stage, const cClientHandle * a_Exclude)
+void cChunkMap::BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ;
- cChunkDef::BlockToChunk(a_blockX, a_blockZ, ChunkX, ChunkZ);
+ cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == nullptr)
{
return;
}
// It's perfectly legal to broadcast packets even to invalid chunks!
- Chunk->BroadcastBlockBreakAnimation(a_entityID, a_blockX, a_blockY, a_blockZ, a_stage, a_Exclude);
+ Chunk->BroadcastBlockBreakAnimation(a_EntityID, a_BlockX, a_BlockY, a_BlockZ, a_Stage, a_Exclude);
}
@@ -1753,7 +1753,7 @@ void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
-bool cChunkMap::HasEntity(int a_UniqueID)
+bool cChunkMap::HasEntity(UInt32 a_UniqueID)
{
cCSLock Lock(m_CSLayers);
for (cChunkLayerList::const_iterator itr = m_Layers.begin(); itr != m_Layers.end(); ++itr)
@@ -2045,7 +2045,7 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
-bool cChunkMap::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback)
+bool cChunkMap::DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback & a_Callback)
{
cCSLock Lock(m_CSLayers);
bool res = false;
@@ -2996,7 +2996,7 @@ bool cChunkMap::cChunkLayer::ForEachEntity(cEntityCallback & a_Callback)
-bool cChunkMap::cChunkLayer::DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackReturn)
+bool cChunkMap::cChunkLayer::DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackReturn)
{
// Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found.
for (size_t i = 0; i < ARRAYCOUNT(m_Chunks); i++)
@@ -3016,7 +3016,7 @@ bool cChunkMap::cChunkLayer::DoWithEntityByID(int a_EntityID, cEntityCallback &
-bool cChunkMap::cChunkLayer::HasEntity(int a_EntityID)
+bool cChunkMap::cChunkLayer::HasEntity(UInt32 a_EntityID)
{
for (size_t i = 0; i < ARRAYCOUNT(m_Chunks); i++)
{
diff --git a/src/ChunkMap.h b/src/ChunkMap.h
index f08d02337..0fac79c84 100644
--- a/src/ChunkMap.h
+++ b/src/ChunkMap.h
@@ -71,7 +71,7 @@ public:
// (Please keep these alpha-sorted)
void BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle);
void BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = nullptr);
- void BroadcastBlockBreakAnimation(int a_entityID, int a_blockX, int a_blockY, int a_blockZ, char a_stage, const cClientHandle * a_Exclude = nullptr);
+ void BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = nullptr);
void BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude);
void BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = nullptr);
void BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude = nullptr);
@@ -217,7 +217,7 @@ public:
void AddEntityIfNotPresent(cEntity * a_Entity);
/** Returns true if the entity with specified ID is present in the chunks */
- bool HasEntity(int a_EntityID);
+ bool HasEntity(UInt32 a_EntityID);
/** Removes the entity from its appropriate chunk */
void RemoveEntity(cEntity * a_Entity);
@@ -236,61 +236,80 @@ public:
/** Destroys and returns a list of blocks destroyed in the explosion at the specified coordinates */
void DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, cVector3iArray & a_BlockAffected);
- /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found and callback returned false. */
- bool DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback); // Lua-accessible
+ /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param.
+ Returns true if entity found and callback returned false. */
+ bool DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback); // Lua-accessible
- /** Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true */
+ /** Calls the callback for each block entity in the specified chunk.
+ Returns true if all block entities processed, false if the callback aborted by returning true. */
bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback); // Lua-accessible
- /** Calls the callback for each chest in the specified chunk; returns true if all chests processed, false if the callback aborted by returning true */
+ /** Calls the callback for each chest in the specified chunk.
+ Returns true if all chests processed, false if the callback aborted by returning true. */
bool ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & a_Callback); // Lua-accessible
- /** Calls the callback for each dispenser in the specified chunk; returns true if all dispensers processed, false if the callback aborted by returning true */
+ /** Calls the callback for each dispenser in the specified chunk.
+ Returns true if all dispensers processed, false if the callback aborted by returning true. */
bool ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback & a_Callback);
- /** Calls the callback for each dropper in the specified chunk; returns true if all droppers processed, false if the callback aborted by returning true */
+ /** Calls the callback for each dropper in the specified chunk.
+ Returns true if all droppers processed, false if the callback aborted by returning true. */
bool ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback & a_Callback);
- /** Calls the callback for each dropspenser in the specified chunk; returns true if all dropspensers processed, false if the callback aborted by returning true */
+ /** Calls the callback for each dropspenser in the specified chunk.
+ Returns true if all dropspensers processed, false if the callback aborted by returning true. */
bool ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback & a_Callback);
- /** Calls the callback for each furnace in the specified chunk; returns true if all furnaces processed, false if the callback aborted by returning true */
+ /** Calls the callback for each furnace in the specified chunk.
+ Returns true if all furnaces processed, false if the callback aborted by returning true. */
bool ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */
+ /** Calls the callback for the block entity at the specified coords.
+ Returns false if there's no block entity at those coords, true if found. */
bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible
- /** Calls the callback for the beacon at the specified coords; returns false if there's no beacon at those coords, true if found */
+ /** Calls the callback for the beacon at the specified coords.
+ Returns false if there's no beacon at those coords, true if found. */
bool DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback); // Lua-acessible
- /** Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found */
+ /** Calls the callback for the chest at the specified coords.
+ Returns false if there's no chest at those coords, true if found. */
bool DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Lua-acessible
- /** Calls the callback for the dispenser at the specified coords; returns false if there's no dispenser at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the dispenser at the specified coords.
+ Returns false if there's no dispenser at those coords or callback returns true, returns true if found. */
bool DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDispenserCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the dropper at the specified coords; returns false if there's no dropper at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the dropper at the specified coords.
+ Returns false if there's no dropper at those coords or callback returns true, returns true if found. */
bool DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropperCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the dropspenser at the specified coords; returns false if there's no dropspenser at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the dropspenser at the specified coords.
+ Returns false if there's no dropspenser at those coords or callback returns true, returns true if found. */
bool DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the furnace at the specified coords; returns false if there's no furnace at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the furnace at the specified coords.
+ Returns false if there's no furnace at those coords or callback returns true, returns true if found. */
bool DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the noteblock at the specified coords; returns false if there's no noteblock at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the noteblock at the specified coords.
+ Returns false if there's no noteblock at those coords or callback returns true, returns true if found. */
bool DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNoteBlockCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the command block at the specified coords; returns false if there's no command block at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the command block at the specified coords.
+ Returns false if there's no command block at those coords or callback returns true, returns true if found. */
bool DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cCommandBlockCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the mob head block at the specified coords; returns false if there's no mob head block at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the mob head block at the specified coords.
+ Returns false if there's no mob head block at those coords or callback returns true, returns true if found. */
bool DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHeadCallback & a_Callback); // Lua-accessible
- /** Calls the callback for the flower pot at the specified coords; returns false if there's no flower pot at those coords or callback returns true, returns true if found */
+ /** Calls the callback for the flower pot at the specified coords.
+ Returns false if there's no flower pot at those coords or callback returns true, returns true if found. */
bool DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlowerPotCallback & a_Callback); // Lua-accessible
- /** Retrieves the test on the sign at the specified coords; returns false if there's no sign at those coords, true if found */
+ /** Retrieves the test on the sign at the specified coords.
+ Returns false if there's no sign at those coords, true if found. */
bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible
/** Touches the chunk, causing it to be loaded or generated */
@@ -423,10 +442,10 @@ private:
bool ForEachEntity(cEntityCallback & a_Callback); // Lua-accessible
/** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found. */
- bool DoWithEntityByID(int a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackReturn); // Lua-accessible
+ bool DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackReturn); // Lua-accessible
/** Returns true if there is an entity with the specified ID within this layer's chunks */
- bool HasEntity(int a_EntityID);
+ bool HasEntity(UInt32 a_EntityID);
protected:
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 1bc4690e1..329537c92 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -18,49 +18,50 @@
-int cEntity::m_EntityCount = 0;
+UInt32 cEntity::m_EntityCount = 0;
cCriticalSection cEntity::m_CSCount;
-cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height)
- : m_UniqueID(0)
- , m_Health(1)
- , m_MaxHealth(1)
- , m_AttachedTo(nullptr)
- , m_Attachee(nullptr)
- , m_bDirtyHead(true)
- , m_bDirtyOrientation(true)
- , m_bHasSentNoSpeed(true)
- , m_bOnGround(false)
- , m_Gravity(-9.81f)
- , m_LastPos(a_X, a_Y, a_Z)
- , m_IsInitialized(false)
- , m_WorldTravellingFrom(nullptr)
- , m_EntityType(a_EntityType)
- , m_World(nullptr)
- , m_IsFireproof(false)
- , m_TicksSinceLastBurnDamage(0)
- , m_TicksSinceLastLavaDamage(0)
- , m_TicksSinceLastFireDamage(0)
- , m_TicksLeftBurning(0)
- , m_TicksSinceLastVoidDamage(0)
- , m_IsSwimming(false)
- , m_IsSubmerged(false)
- , m_AirLevel(0)
- , m_AirTickTimer(0)
- , m_TicksAlive(0)
- , m_HeadYaw(0.0)
- , m_Rot(0.0, 0.0, 0.0)
- , m_Pos(a_X, a_Y, a_Z)
- , m_WaterSpeed(0, 0, 0)
- , m_Mass (0.001) // Default 1g
- , m_Width(a_Width)
- , m_Height(a_Height)
- , m_InvulnerableTicks(0)
-{
+cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height):
+ m_UniqueID(INVALID_ID), // Proper ID will be assigned later in the constructor code
+ m_Health(1),
+ m_MaxHealth(1),
+ m_AttachedTo(nullptr),
+ m_Attachee(nullptr),
+ m_bDirtyHead(true),
+ m_bDirtyOrientation(true),
+ m_bHasSentNoSpeed(true),
+ m_bOnGround(false),
+ m_Gravity(-9.81f),
+ m_LastPos(a_X, a_Y, a_Z),
+ m_IsInitialized(false),
+ m_WorldTravellingFrom(nullptr),
+ m_EntityType(a_EntityType),
+ m_World(nullptr),
+ m_IsFireproof(false),
+ m_TicksSinceLastBurnDamage(0),
+ m_TicksSinceLastLavaDamage(0),
+ m_TicksSinceLastFireDamage(0),
+ m_TicksLeftBurning(0),
+ m_TicksSinceLastVoidDamage(0),
+ m_IsSwimming(false),
+ m_IsSubmerged(false),
+ m_AirLevel(0),
+ m_AirTickTimer(0),
+ m_TicksAlive(0),
+ m_HeadYaw(0.0),
+ m_Rot(0.0, 0.0, 0.0),
+ m_Pos(a_X, a_Y, a_Z),
+ m_WaterSpeed(0, 0, 0),
+ m_Mass (0.001), // Default 1g
+ m_Width(a_Width),
+ m_Height(a_Height),
+ m_InvulnerableTicks(0)
+{
+ // Assign a proper ID:
cCSLock Lock(m_CSCount);
m_EntityCount++;
m_UniqueID = m_EntityCount;
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 809e974d2..9bb1837f1 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -142,6 +142,10 @@ public:
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
+
+ /** Special ID that is considered an "invalid value", signifying no entity. */
+ static const UInt32 INVALID_ID = 0; // Exported to Lua in ManualBindings.cpp, ToLua doesn't parse initialized constants.
+
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
virtual ~cEntity();
@@ -248,7 +252,7 @@ public:
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways);
void SteerVehicle(float a_Forward, float a_Sideways);
- inline int GetUniqueID(void) const { return m_UniqueID; }
+ inline UInt32 GetUniqueID(void) const { return m_UniqueID; }
inline bool IsDestroyed(void) const { return !m_IsInitialized; }
/// Schedules the entity for destroying; if a_ShouldBroadcast is set to true, broadcasts the DestroyEntity packet
@@ -464,12 +468,15 @@ public:
protected:
static cCriticalSection m_CSCount;
- static int m_EntityCount;
+ static UInt32 m_EntityCount;
/** Measured in meter/second (m/s) */
Vector3d m_Speed;
- int m_UniqueID;
+ /** The ID of the entity that is guaranteed to be unique within a single run of the server.
+ Always nonzero (a zero UniqueID (cEntity::INVALID_ID) is used for error reporting).
+ Note that the UniqueID is not persisted through storage. */
+ UInt32 m_UniqueID;
int m_Health;
int m_MaxHealth;
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index a32926838..ee10cf6b3 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -24,7 +24,7 @@ class cMinecartCollisionCallback :
public cEntityCallback
{
public:
- cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, int a_UniqueID, int a_AttacheeUniqueID) :
+ cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, UInt32 a_UniqueID, UInt32 a_AttacheeUniqueID) :
m_DoesInteserct(false),
m_CollidedEntityPos(0, 0, 0),
m_Pos(a_Pos),
@@ -77,8 +77,8 @@ protected:
Vector3d m_Pos;
double m_Height, m_Width;
- int m_UniqueID;
- int m_AttacheeUniqueID;
+ UInt32 m_UniqueID;
+ UInt32 m_AttacheeUniqueID;
};
@@ -824,7 +824,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
- cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == nullptr) ? -1 : m_Attachee->GetUniqueID()));
+ cMinecartCollisionCallback MinecartCollisionCallback(
+ GetPosition(), GetHeight(), GetWidth(), GetUniqueID(),
+ ((m_Attachee == nullptr) ? cEntity::INVALID_ID : m_Attachee->GetUniqueID())
+ );
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback);
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index 4f20bfae6..7af2186c1 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -221,7 +221,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a
super(etProjectile, a_X, a_Y, a_Z, a_Width, a_Height),
m_ProjectileKind(a_Kind),
m_CreatorData(
- ((a_Creator != nullptr) ? a_Creator->GetUniqueID() : -1),
+ ((a_Creator != nullptr) ? a_Creator->GetUniqueID() : cEntity::INVALID_ID),
((a_Creator != nullptr) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""),
((a_Creator != nullptr) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments())
),
diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h
index 93e442d8c..de460a8ad 100644
--- a/src/Entities/ProjectileEntity.h
+++ b/src/Entities/ProjectileEntity.h
@@ -69,7 +69,7 @@ public:
/** Returns the unique ID of the entity who created this projectile
May return an ID <0
*/
- int GetCreatorUniqueID(void) { return m_CreatorData.m_UniqueID; }
+ UInt32 GetCreatorUniqueID(void) { return m_CreatorData.m_UniqueID; }
/** Returns the name of the player that created the projectile
Will be empty for non-player creators
@@ -90,18 +90,17 @@ public:
protected:
/** A structure that stores the Entity ID and Playername of the projectile's creator
- Used to migitate invalid pointers caused by the creator being destroyed
- */
+ Used to migitate invalid pointers caused by the creator being destroyed. */
struct CreatorData
{
- CreatorData(int a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
+ CreatorData(UInt32 a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
m_UniqueID(a_UniqueID),
m_Name(a_Name),
m_Enchantments(a_Enchantments)
{
}
- const int m_UniqueID;
+ const UInt32 m_UniqueID;
AString m_Name;
cEnchantments m_Enchantments;
};
@@ -110,8 +109,7 @@ protected:
eKind m_ProjectileKind;
/** The structure for containing the entity ID and name who has created this projectile
- The ID and/or name may be nullptr (e.g. for dispensers/mobs)
- */
+ The ID and/or name may be nullptr (e.g. for dispensers/mobs). */
CreatorData m_CreatorData;
/** True if the projectile has hit the ground and is stuck there */
diff --git a/src/Items/ItemPotion.h b/src/Items/ItemPotion.h
index 398ef6805..798573846 100644
--- a/src/Items/ItemPotion.h
+++ b/src/Items/ItemPotion.h
@@ -39,7 +39,7 @@ public:
Vector3d Pos = a_Player->GetThrowStartPos();
Vector3d Speed = a_Player->GetLookVector() * 7;
- if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, cProjectileEntity::pkSplashPotion, a_Player, &a_Player->GetEquippedItem(), &Speed) < 0)
+ if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, cProjectileEntity::pkSplashPotion, a_Player, &a_Player->GetEquippedItem(), &Speed) == cEntity::INVALID_ID)
{
return false;
}
diff --git a/src/Items/ItemSpawnEgg.h b/src/Items/ItemSpawnEgg.h
index dee8a9057..a07e4ef49 100644
--- a/src/Items/ItemSpawnEgg.h
+++ b/src/Items/ItemSpawnEgg.h
@@ -36,7 +36,7 @@ public:
eMonsterType MonsterType = ItemDamageToMonsterType(a_Item.m_ItemDamage);
if (
(MonsterType != mtInvalidType) && // Valid monster type
- (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, MonsterType) >= 0)) // Spawning succeeded
+ (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, MonsterType) != cEntity::INVALID_ID)) // Spawning succeeded
{
if (!a_Player->IsGameModeCreative())
{
diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h
index c151c5d3a..cdcbdab3b 100644
--- a/src/Items/ItemThrowable.h
+++ b/src/Items/ItemThrowable.h
@@ -35,7 +35,7 @@ public:
cFastRandom Random;
a_World->BroadcastSoundEffect("random.bow", a_Player->GetPosX(), a_Player->GetPosY() - a_Player->GetHeight(), a_Player->GetPosZ(), 0.5f, 0.4f / (Random.NextFloat(1.0f) * 0.4f + 0.8f));
- if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, &a_Player->GetEquippedItem(), &Speed) < 0)
+ if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, &a_Player->GetEquippedItem(), &Speed) == cEntity::INVALID_ID)
{
return false;
}
@@ -135,7 +135,7 @@ public:
return false;
}
- if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, &a_Player->GetEquippedItem()) < 0)
+ if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, &a_Player->GetEquippedItem()) == 0)
{
return false;
}
diff --git a/src/MapManager.cpp b/src/MapManager.cpp
index 2a3ab192b..fc67bd901 100644
--- a/src/MapManager.cpp
+++ b/src/MapManager.cpp
@@ -22,7 +22,7 @@ cMapManager::cMapManager(cWorld * a_World)
-bool cMapManager::DoWithMap(int a_ID, cMapCallback & a_Callback)
+bool cMapManager::DoWithMap(UInt32 a_ID, cMapCallback & a_Callback)
{
cCSLock Lock(m_CS);
cMap * Map = GetMapData(a_ID);
diff --git a/src/MapManager.h b/src/MapManager.h
index 2cc6a7bce..1059773c3 100644
--- a/src/MapManager.h
+++ b/src/MapManager.h
@@ -32,8 +32,7 @@ public:
cMapManager(cWorld * a_World);
/** Returns the map with the specified ID, nullptr if out of range.
- WARNING: The returned map object is not thread safe.
- */
+ WARNING: The returned map object is not thread safe. */
cMap * GetMapData(unsigned int a_ID);
/** Creates a new map. Returns nullptr on error */
@@ -41,13 +40,11 @@ public:
/** Calls the callback for the map with the specified ID.
Returns true if the map was found and the callback called, false if map not found.
- Callback return value is ignored.
- */
- bool DoWithMap(int a_ID, cMapCallback & a_Callback); // Exported in ManualBindings.cpp
+ Callback return value is ignored. */
+ bool DoWithMap(UInt32 a_ID, cMapCallback & a_Callback); // Exported in ManualBindings.cpp
/** Calls the callback for each map.
- Returns true if all maps processed, false if the callback aborted by returning true.
- */
+ Returns true if all maps processed, false if the callback aborted by returning true. */
bool ForEachMap(cMapCallback & a_Callback);
size_t GetNumMaps(void) const; // tolua_export
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index e39d372c9..0e7ba2a50 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -248,28 +248,31 @@ public:
protected:
- /// Maps player's EntityID -> current recipe; not a std::map because cCraftingGrid needs proper constructor params
- typedef std::list<std::pair<int, cCraftingRecipe> > cRecipeMap;
+ /** Maps player's EntityID -> current recipe.
+ Not a std::map because cCraftingGrid needs proper constructor params. */
+ typedef std::list<std::pair<UInt32, cCraftingRecipe> > cRecipeMap;
int m_GridSize;
cRecipeMap m_Recipes;
- /// Handles a click in the result slot. Crafts using the current recipe, if possible
+ /** Handles a click in the result slot.
+ Crafts using the current recipe, if possible. */
void ClickedResult(cPlayer & a_Player);
- /// Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result.
+ /** Handles a shift-click in the result slot.
+ Crafts using the current recipe until it changes or no more space for result. */
void ShiftClickedResult(cPlayer & a_Player);
/** Handles a drop-click in the result slot. */
void DropClickedResult(cPlayer & a_Player);
- /// Updates the current recipe and result slot based on the ingredients currently in the crafting grid of the specified player
+ /** Updates the current recipe and result slot based on the ingredients currently in the crafting grid of the specified player. */
void UpdateRecipe(cPlayer & a_Player);
- /// Retrieves the recipe for the specified player from the map, or creates one if not found
+ /** Retrieves the recipe for the specified player from the map, or creates one if not found. */
cCraftingRecipe & GetRecipeForPlayer(cPlayer & a_Player);
- /// Called after an item has been crafted to handle statistics e.t.c.
+ /** Called after an item has been crafted to handle statistics e.t.c. */
void HandleCraftItem(const cItem & a_Result, cPlayer & a_Player);
} ;
diff --git a/src/World.cpp b/src/World.cpp
index 292ff9b94..d3058abc9 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -1920,7 +1920,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double
-int cWorld::SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta)
+UInt32 cWorld::SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta)
{
cFallingBlock * FallingBlock = new cFallingBlock(Vector3i(a_X, a_Y, a_Z), BlockType, BlockMeta);
FallingBlock->Initialize(*this);
@@ -1931,11 +1931,12 @@ int cWorld::SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NI
-int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward)
+UInt32 cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward)
{
if (a_Reward < 1)
{
- return -1;
+ LOGWARNING("%s: Attempting to create an experience orb with non-positive reward!", __FUNCTION__);
+ return cEntity::INVALID_ID;
}
cExpOrb * ExpOrb = new cExpOrb(a_X, a_Y, a_Z, a_Reward);
@@ -1947,7 +1948,7 @@ int cWorld::SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward)
-int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content, int a_BlockHeight)
+UInt32 cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content, int a_BlockHeight)
{
cMinecart * Minecart;
switch (a_MinecartType)
@@ -1959,7 +1960,7 @@ int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType
case E_ITEM_MINECART_WITH_HOPPER: Minecart = new cMinecartWithHopper (a_X, a_Y, a_Z); break;
default:
{
- return -1;
+ return cEntity::INVALID_ID;
}
} // switch (a_MinecartType)
Minecart->Initialize(*this);
@@ -1970,7 +1971,7 @@ int cWorld::SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType
-void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks, double a_InitialVelocityCoeff)
+UInt32 cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks, double a_InitialVelocityCoeff)
{
cTNTEntity * TNT = new cTNTEntity(a_X, a_Y, a_Z, a_FuseTicks);
TNT->Initialize(*this);
@@ -1979,6 +1980,7 @@ void cWorld::SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTicks,
a_InitialVelocityCoeff * 2,
a_InitialVelocityCoeff * (GetTickRandomNumber(2) - 1)
);
+ return TNT->GetUniqueID();
}
@@ -2069,7 +2071,7 @@ void cWorld::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char
-void cWorld::BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude)
+void cWorld::BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude)
{
m_ChunkMap->BroadcastBlockBreakAnimation(a_EntityID, a_BlockX, a_BlockY, a_BlockZ, a_Stage, a_Exclude);
}
@@ -2906,7 +2908,7 @@ bool cWorld::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_
-bool cWorld::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback)
+bool cWorld::DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback & a_Callback)
{
// First check the entities-to-add:
{
@@ -3215,7 +3217,7 @@ void cWorld::AddEntity(cEntity * a_Entity)
-bool cWorld::HasEntity(int a_UniqueID)
+bool cWorld::HasEntity(UInt32 a_UniqueID)
{
// Check if the entity is in the queue to be added to the world:
{
@@ -3332,15 +3334,16 @@ bool cWorld::IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ)
-int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType)
+UInt32 cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType)
{
cMonster * Monster = nullptr;
Monster = cMonster::NewMonsterFromType(a_MonsterType);
- if (Monster != nullptr)
+ if (Monster == nullptr)
{
- Monster->SetPosition(a_PosX, a_PosY, a_PosZ);
+ return cEntity::INVALID_ID;
}
+ Monster->SetPosition(a_PosX, a_PosY, a_PosZ);
return SpawnMobFinalize(Monster);
}
@@ -3348,13 +3351,9 @@ int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a
-int cWorld::SpawnMobFinalize(cMonster * a_Monster)
+UInt32 cWorld::SpawnMobFinalize(cMonster * a_Monster)
{
- // Invalid cMonster object. Bail out.
- if (!a_Monster)
- {
- return -1;
- }
+ ASSERT(a_Monster != nullptr);
// Give the mob full health.
a_Monster->SetHealth(a_Monster->GetMaxHealth());
@@ -3364,7 +3363,7 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster)
{
delete a_Monster;
a_Monster = nullptr;
- return -1;
+ return cEntity::INVALID_ID;
}
// Initialize the monster into the current world.
@@ -3372,7 +3371,7 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster)
{
delete a_Monster;
a_Monster = nullptr;
- return -1;
+ return cEntity::INVALID_ID;
}
cPluginManager::Get()->CallHookSpawnedMonster(*this, *a_Monster);
@@ -3384,18 +3383,18 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster)
-int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed)
+UInt32 cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed)
{
cProjectileEntity * Projectile = cProjectileEntity::Create(a_Kind, a_Creator, a_PosX, a_PosY, a_PosZ, a_Item, a_Speed);
if (Projectile == nullptr)
{
- return -1;
+ return cEntity::INVALID_ID;
}
if (!Projectile->Initialize(*this))
{
delete Projectile;
Projectile = nullptr;
- return -1;
+ return cEntity::INVALID_ID;
}
return Projectile->GetUniqueID();
}
diff --git a/src/World.h b/src/World.h
index 0decc8c6e..006798bab 100644
--- a/src/World.h
+++ b/src/World.h
@@ -215,7 +215,7 @@ public:
// (Please keep these alpha-sorted)
void BroadcastAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle);
void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = nullptr); // tolua_export
- void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = nullptr);
+ void BroadcastBlockBreakAnimation(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = nullptr);
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = nullptr); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude
// tolua_begin
@@ -335,7 +335,9 @@ public:
The entity is added lazily - this function only puts it in a queue that is then processed by the Tick thread. */
void AddEntity(cEntity * a_Entity);
- bool HasEntity(int a_UniqueID);
+ /** Returns true if an entity with the specified UniqueID exists in the world.
+ Note: Only loaded chunks are considered. */
+ bool HasEntity(UInt32 a_UniqueID);
/** Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true */
bool ForEachEntity(cEntityCallback & a_Callback); // Exported in ManualBindings.cpp
@@ -348,8 +350,9 @@ public:
If any chunk in the box is missing, ignores the entities in that chunk silently. */
bool ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp
- /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. Returns true if entity found and callback returned false. */
- bool DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp
+ /** Calls the callback if the entity with the specified ID is found, with the entity object as the callback param.
+ Returns true if entity found and callback returned false. */
+ bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback & a_Callback); // Exported in ManualBindings.cpp
/** Compares clients of two chunks, calls the callback accordingly */
void CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback);
@@ -476,20 +479,25 @@ public:
/** Spawns item pickups for each item in the list. May compress pickups if too many entities: */
virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false) override;
- /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */
+ /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified. */
virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) override;
- /** Spawns an falling block entity at the given position. It returns the UniqueID of the spawned falling block. */
- int SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta);
+ /** Spawns an falling block entity at the given position.
+ Returns the UniqueID of the spawned falling block, or cEntity::INVALID_ID on failure. */
+ UInt32 SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE BlockType, NIBBLETYPE BlockMeta);
- /** Spawns an minecart at the given coordinates. */
- int SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content = cItem(), int a_BlockHeight = 1);
+ /** Spawns an minecart at the given coordinates.
+ Returns the UniqueID of the spawned minecart, or cEntity::INVALID_ID on failure. */
+ UInt32 SpawnMinecart(double a_X, double a_Y, double a_Z, int a_MinecartType, const cItem & a_Content = cItem(), int a_BlockHeight = 1);
- /** Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. */
- virtual int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) override;
+ /** Spawns an experience orb at the given location with the given reward.
+ Returns the UniqueID of the spawned experience orb, or cEntity::INVALID_ID on failure. */
+ virtual UInt32 SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) override;
- /** Spawns a new primed TNT entity at the specified block coords and specified fuse duration. Initial velocity is given based on the relative coefficient provided */
- void SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1);
+ /** Spawns a new primed TNT entity at the specified block coords and specified fuse duration.
+ Initial velocity is given based on the relative coefficient provided.
+ Returns the UniqueID of the created entity, or cEntity::INVALID_ID on failure. */
+ UInt32 SpawnPrimedTNT(double a_X, double a_Y, double a_Z, int a_FuseTimeInSec = 80, double a_InitialVelocityCoeff = 1);
// tolua_end
@@ -796,14 +804,14 @@ public:
bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export
- /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */
- virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) override; // tolua_export
- int SpawnMobFinalize(cMonster* a_Monster);
+ /** Spawns a mob of the specified type. Returns the mob's UniqueID if recognized and spawned, cEntity::INVALID_ID otherwise */
+ virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) override; // tolua_export
+
+ UInt32 SpawnMobFinalize(cMonster * a_Monster);
- /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise
- Item parameter used currently for Fireworks to correctly set entity metadata based on item metadata
- */
- int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed = nullptr); // tolua_export
+ /** Creates a projectile of the specified type. Returns the projectile's UniqueID if successful, cEntity::INVALID_ID otherwise
+ Item parameter is currently used for Fireworks to correctly set entity metadata based on item metadata. */
+ UInt32 CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem * a_Item, const Vector3d * a_Speed = nullptr); // tolua_export
/** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */
int GetTickRandomNumber(int a_Range) { return (int)(m_TickRand.randInt(a_Range)); }