summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-11-30 15:58:27 +0100
committermadmaxoft <github@xoft.cz>2013-11-30 15:58:27 +0100
commitc70c2fa42fa9336958e7b66a8813d075963f3463 (patch)
tree52ef965eb191c81aca95fd56146d10478496d645
parentAdded IsBiomeNoDownfall() function. (diff)
downloadcuberite-c70c2fa42fa9336958e7b66a8813d075963f3463.tar
cuberite-c70c2fa42fa9336958e7b66a8813d075963f3463.tar.gz
cuberite-c70c2fa42fa9336958e7b66a8813d075963f3463.tar.bz2
cuberite-c70c2fa42fa9336958e7b66a8813d075963f3463.tar.lz
cuberite-c70c2fa42fa9336958e7b66a8813d075963f3463.tar.xz
cuberite-c70c2fa42fa9336958e7b66a8813d075963f3463.tar.zst
cuberite-c70c2fa42fa9336958e7b66a8813d075963f3463.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockCactus.h4
-rw-r--r--src/Blocks/BlockCrops.h12
-rw-r--r--src/Blocks/BlockDirt.h32
-rw-r--r--src/Blocks/BlockFarmland.h23
-rw-r--r--src/Blocks/BlockHandler.cpp2
-rw-r--r--src/Blocks/BlockHandler.h7
-rw-r--r--src/Blocks/BlockLeaves.h25
-rw-r--r--src/Blocks/BlockSapling.h10
-rw-r--r--src/Blocks/BlockStems.h10
-rw-r--r--src/Blocks/BlockSugarcane.h4
-rw-r--r--src/Chunk.cpp19
-rw-r--r--src/Chunk.h6
-rw-r--r--src/ChunkMap.cpp19
-rw-r--r--src/ChunkMap.h3
-rw-r--r--src/World.cpp4
15 files changed, 117 insertions, 63 deletions
diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h
index 4147ad473..7a9088178 100644
--- a/src/Blocks/BlockCactus.h
+++ b/src/Blocks/BlockCactus.h
@@ -65,9 +65,9 @@ public:
}
- void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
- a_World->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, 1);
+ a_Chunk.GetWorld()->GrowCactus(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1);
}
diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h
index 9dd65aae2..9c4964e02 100644
--- a/src/Blocks/BlockCrops.h
+++ b/src/Blocks/BlockCrops.h
@@ -75,11 +75,11 @@ public:
}
- void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
- NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- NIBBLETYPE Light = a_World->GetBlockBlockLight(a_BlockX, a_BlockY, a_BlockZ);
- NIBBLETYPE SkyLight = a_World->GetBlockSkyLight(a_BlockX, a_BlockY, a_BlockZ);
+ NIBBLETYPE Meta = a_Chunk.GetMeta (a_RelX, a_RelY, a_RelZ);
+ NIBBLETYPE Light = a_Chunk.GetBlockLight(a_RelX, a_RelY, a_RelZ);
+ NIBBLETYPE SkyLight = a_Chunk.GetSkyLight (a_RelX, a_RelY, a_RelZ);
if (SkyLight > Light)
{
@@ -88,11 +88,11 @@ public:
if ((Meta < 7) && (Light > 8))
{
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_CROPS, ++Meta);
+ a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_CROPS, ++Meta);
}
else if (Light < 9)
{
- a_World->DigBlock(a_BlockX, a_BlockY, a_BlockZ);
+ a_Chunk.GetWorld()->DigBlock(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width);
}
}
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h
index a98199977..a83dab1fd 100644
--- a/src/Blocks/BlockDirt.h
+++ b/src/Blocks/BlockDirt.h
@@ -26,7 +26,7 @@ public:
}
- virtual void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
if (m_BlockType != E_BLOCK_GRASS)
{
@@ -34,18 +34,18 @@ public:
}
// Grass becomes dirt if there is something on top of it:
- if (a_BlockY < cChunkDef::Height - 1)
+ if (a_RelY < cChunkDef::Height - 1)
{
- BLOCKTYPE Above = a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ);
+ BLOCKTYPE Above = a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ);
if ((!g_BlockTransparent[Above] && !g_BlockOneHitDig[Above]) || IsBlockWater(Above))
{
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DIRT, 0);
+ a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, E_META_DIRT_NORMAL);
return;
}
}
// Grass spreads to adjacent dirt blocks:
- MTRand rand;
+ MTRand rand; // TODO: Replace with cFastRandom
for (int i = 0; i < 2; i++) // Pick two blocks to grow to
{
int OfsX = rand.randInt(2) - 1; // [-1 .. 1]
@@ -54,25 +54,33 @@ public:
BLOCKTYPE DestBlock;
NIBBLETYPE DestMeta;
- if ((a_BlockY + OfsY < 0) || (a_BlockY + OfsY >= cChunkDef::Height - 1))
+ if ((a_RelY + OfsY < 0) || (a_RelY + OfsY >= cChunkDef::Height - 1))
{
// Y Coord out of range
continue;
}
- bool IsValid = a_World->GetBlockTypeMeta(a_BlockX + OfsX, a_BlockY + OfsY, a_BlockZ + OfsZ, DestBlock, DestMeta);
- if (!IsValid || (DestBlock != E_BLOCK_DIRT) || (DestMeta != E_META_DIRT_NORMAL))
+ int BlockX = a_RelX + OfsX;
+ int BlockY = a_RelY + OfsY;
+ int BlockZ = a_RelZ + OfsZ;
+ cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(BlockX, BlockZ);
+ if (Chunk == NULL)
{
- // Not a regular dirt block, or in an unloaded chunk
+ // Unloaded chunk
+ continue;
+ }
+ Chunk->GetBlockTypeMeta(BlockX, BlockY, BlockZ, DestBlock, DestMeta);
+ if ((DestBlock != E_BLOCK_DIRT) || (DestMeta != E_META_DIRT_NORMAL))
+ {
+ // Not a regular dirt block
continue;
}
BLOCKTYPE AboveDest;
NIBBLETYPE AboveMeta;
- IsValid = a_World->GetBlockTypeMeta(a_BlockX + OfsX, a_BlockY + OfsY + 1, a_BlockZ + OfsZ, AboveDest, AboveMeta);
- ASSERT(IsValid); // WTF - how did we get the DestBlock if AboveBlock is not valid?
+ Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta);
if ((g_BlockOneHitDig[AboveDest] || g_BlockTransparent[AboveDest]) && !IsBlockWater(AboveDest))
{
- a_World->FastSetBlock(a_BlockX + OfsX, a_BlockY + OfsY, a_BlockZ + OfsZ, E_BLOCK_GRASS, 0);
+ Chunk->FastSetBlock(a_RelX + OfsX, a_RelY + OfsY, a_RelZ + OfsZ, E_BLOCK_GRASS, 0);
}
} // for i - repeat twice
}
diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h
index 7bc71f7f3..a69d9b775 100644
--- a/src/Blocks/BlockFarmland.h
+++ b/src/Blocks/BlockFarmland.h
@@ -28,12 +28,12 @@ public:
}
- virtual void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
bool Found = false;
- int Biome = a_World->GetBiomeAt(a_BlockX, a_BlockZ);
- if (a_World->IsWeatherWet() && (Biome != biDesert) && (Biome != biDesertHills))
+ EMCSBiome Biome = a_Chunk.GetBiomeAt(a_RelX, a_RelZ);
+ if (a_Chunk.GetWorld()->IsWeatherWet() && !IsBiomeNoDownfall(Biome))
{
// Rain hydrates farmland, too, except in Desert biomes.
Found = true;
@@ -42,10 +42,13 @@ public:
{
// Search for water in a close proximity:
// Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles
+ // TODO: Rewrite this to use the chunk and its neighbors directly
cBlockArea Area;
- if (!Area.Read(a_World, a_BlockX - 4, a_BlockX + 4, a_BlockY, a_BlockY + 1, a_BlockZ - 4, a_BlockZ + 4))
+ int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
+ int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
+ if (!Area.Read(a_Chunk.GetWorld(), BlockX - 4, BlockX + 4, a_RelY, a_RelY + 1, BlockZ - 4, BlockZ + 4))
{
- // Too close to the world edge, cannot check surroudnings; don't tick at all
+ // Too close to the world edge, cannot check surroundings; don't tick at all
return;
}
@@ -64,14 +67,14 @@ public:
} // for i - BlockTypes[]
}
- NIBBLETYPE BlockMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ NIBBLETYPE BlockMeta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
if (Found)
{
// Water was found, hydrate the block until hydration reaches 7:
if (BlockMeta < 7)
{
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, ++BlockMeta);
+ a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, ++BlockMeta);
}
return;
}
@@ -79,12 +82,12 @@ public:
// Water wasn't found, de-hydrate block:
if (BlockMeta > 0)
{
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_FARMLAND, --BlockMeta);
+ a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_FARMLAND, --BlockMeta);
return;
}
// Farmland too dry. If nothing is growing on top, turn back to dirt:
- switch (a_World->GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))
+ switch (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ))
{
case E_BLOCK_CROPS:
case E_BLOCK_MELON_STEM:
@@ -95,7 +98,7 @@ public:
}
default:
{
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DIRT, 0);
+ a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, 0);
break;
}
}
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index cd07b3021..3448cf8a1 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -252,7 +252,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta(
-void cBlockHandler::OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
+void cBlockHandler::OnUpdate(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ)
{
}
diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h
index 81d9f240c..80dccd8c7 100644
--- a/src/Blocks/BlockHandler.h
+++ b/src/Blocks/BlockHandler.h
@@ -22,8 +22,9 @@ class cBlockHandler
public:
cBlockHandler(BLOCKTYPE a_BlockType);
- /// Called when the block gets ticked either by a random tick or by a queued tick
- virtual void OnUpdate(cWorld *a_World, int a_BlockX, int a_BlockY, int a_BlockZ);
+ /// Called when the block gets ticked either by a random tick or by a queued tick.
+ /// Note that the coords are chunk-relative!
+ virtual void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ);
/** Called before a block is placed into a world.
The handler should return true to allow placement, false to refuse.
@@ -66,7 +67,7 @@ public:
/// Called if the user right clicks the block and the block is useable
virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
- /// Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents
+ /// <summary>Called when the item is mined to convert it into pickups. Pickups may specify multiple items. Appends items to a_Pickups, preserves its original contents</summary>
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta);
/// Handles the dropping of a block based on what ConvertToDrops() returns. This will not destroy the block. a_Digger is the entity causing the drop; it may be NULL
diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h
index 6e015b8fa..539d12a49 100644
--- a/src/Blocks/BlockLeaves.h
+++ b/src/Blocks/BlockLeaves.h
@@ -77,9 +77,9 @@ public:
}
- virtual void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
- NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
if ((Meta & 0x04) != 0)
{
// Player-placed leaves, don't decay
@@ -93,12 +93,14 @@ public:
}
// Get the data around the leaves:
+ int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
+ int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
cBlockArea Area;
if (!Area.Read(
- a_World,
- a_BlockX - LEAVES_CHECK_DISTANCE, a_BlockX + LEAVES_CHECK_DISTANCE,
- a_BlockY - LEAVES_CHECK_DISTANCE, a_BlockY + LEAVES_CHECK_DISTANCE,
- a_BlockZ - LEAVES_CHECK_DISTANCE, a_BlockZ + LEAVES_CHECK_DISTANCE,
+ a_Chunk.GetWorld(),
+ BlockX - LEAVES_CHECK_DISTANCE, BlockX + LEAVES_CHECK_DISTANCE,
+ a_RelY - LEAVES_CHECK_DISTANCE, a_RelY + LEAVES_CHECK_DISTANCE,
+ BlockZ - LEAVES_CHECK_DISTANCE, BlockZ + LEAVES_CHECK_DISTANCE,
cBlockArea::baTypes)
)
{
@@ -106,17 +108,16 @@ public:
return;
}
- if (HasNearLog(Area, a_BlockX, a_BlockY, a_BlockZ))
+ if (HasNearLog(Area, BlockX, a_RelY, BlockZ))
{
// Wood found, the leaves stay; mark them as checked:
- a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x8);
+ a_Chunk.SetMeta(a_RelX, a_RelY, a_RelZ, Meta | 0x8);
return;
}
- // Decay the leaves:
- DropBlock(a_World, NULL, a_BlockX, a_BlockY, a_BlockZ);
- a_World->DigBlock(a_BlockX, a_BlockY, a_BlockZ);
-
+ // Decay the leaves:
+ DropBlock(a_Chunk.GetWorld(), NULL, BlockX, a_RelY, BlockZ);
+ a_Chunk.GetWorld()->DigBlock(BlockX, a_RelY, BlockZ);
}
diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h
index fff2fa88b..0dcae1f93 100644
--- a/src/Blocks/BlockSapling.h
+++ b/src/Blocks/BlockSapling.h
@@ -31,17 +31,19 @@ public:
}
- void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
- NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
if ((Meta & 0x08) != 0)
{
- a_World->GrowTree(a_BlockX, a_BlockY, a_BlockZ);
+ int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
+ int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
+ a_Chunk.GetWorld()->GrowTree(BlockX, a_RelY, BlockZ);
}
else
{
- a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x08);
+ a_Chunk.SetMeta(a_RelX, a_RelY, a_RelZ, Meta | 0x08);
}
}
diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h
index ce02d9cb8..e17f2ea3d 100644
--- a/src/Blocks/BlockStems.h
+++ b/src/Blocks/BlockStems.h
@@ -25,18 +25,20 @@ public:
}
- void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
- NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
+ NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
if (Meta >= 7)
{
// Grow the produce:
- a_World->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, m_BlockType);
+ int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
+ int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
+ a_Chunk.GetWorld()->GrowMelonPumpkin(BlockX, a_RelY, a_RelZ, m_BlockType);
}
else
{
// Grow the stem:
- a_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, Meta + 1);
+ a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, Meta + 1);
}
}
diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h
index 28a60df80..02d7a2fe4 100644
--- a/src/Blocks/BlockSugarcane.h
+++ b/src/Blocks/BlockSugarcane.h
@@ -73,9 +73,9 @@ public:
}
- void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
+ void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
{
- a_World->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, 1);
+ a_Chunk.GetWorld()->GrowSugarcane(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width, 1);
}
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index b3b24e339..45825a30f 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -631,6 +631,23 @@ void cChunk::Tick(float a_Dt)
+void cChunk::TickBlock(int a_RelX, int a_RelY, int a_RelZ)
+{
+ unsigned Index = MakeIndex(a_RelX, a_RelY, a_RelZ);
+ if (Index == INDEX_OUT_OF_RANGE)
+ {
+ // An assert has already been made in MakeIndex()
+ return;
+ }
+ cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]);
+ ASSERT(Handler != NULL); // Happenned on server restart, FS #243
+ Handler->OnUpdate(*this, a_RelX + m_PosX * Width, a_RelY, a_RelZ + m_PosZ * Width);
+}
+
+
+
+
+
void cChunk::MoveEntityToNewChunk(cEntity * a_Entity)
{
cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width);
@@ -777,7 +794,7 @@ void cChunk::TickBlocks(void)
unsigned int Index = MakeIndexNoCheck(m_BlockTickX, m_BlockTickY, m_BlockTickZ);
cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]);
ASSERT(Handler != NULL); // Happenned on server restart, FS #243
- Handler->OnUpdate(m_World, m_BlockTickX + m_PosX * Width, m_BlockTickY, m_BlockTickZ + m_PosZ * Width);
+ Handler->OnUpdate(*this, m_BlockTickX + m_PosX * Width, m_BlockTickY, m_BlockTickZ + m_PosZ * Width);
} // for i - tickblocks
}
diff --git a/src/Chunk.h b/src/Chunk.h
index 895b407a3..f13eb9a03 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -134,6 +134,9 @@ public:
void SpawnMobs(cMobSpawner& a_MobSpawner);
void Tick(float a_Dt);
+
+ /// Ticks a single block. Used by cWorld::TickQueuedBlocks() to tick the queued blocks
+ void TickBlock(int a_RelX, int a_RelY, int a_RelZ);
int GetPosX(void) const { return m_PosX; }
int GetPosY(void) const { return m_PosY; }
@@ -457,9 +460,6 @@ private:
/// Grows a melon or a pumpkin next to the block specified (assumed to be the stem)
void GrowMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, MTRand & a_Random);
- /// Checks if a leaves block at the specified coords has a log up to 4 blocks away connected by other leaves blocks (false if no log)
- bool HasNearLog(cBlockArea & a_Area, int a_BlockX, int a_BlockY, int a_BlockZ);
-
/// Called by Tick() when an entity moves out of this chunk into a neighbor; moves the entity and sends spawn / despawn packet to clients
void MoveEntityToNewChunk(cEntity * a_Entity);
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 692f97ddf..a6caa5ef7 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -2244,7 +2244,24 @@ void cChunkMap::Tick(float a_Dt)
-void cChunkMap::UnloadUnusedChunks()
+void cChunkMap::TickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ cCSLock Lock(m_CSLayers);
+ int ChunkX, ChunkZ;
+ cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
+ cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
+ if ((Chunk == NULL) || !Chunk->IsValid())
+ {
+ return;
+ }
+ Chunk->TickBlock(a_BlockX, a_BlockY, a_BlockZ);
+}
+
+
+
+
+
+void cChunkMap::UnloadUnusedChunks(void)
{
cCSLock Lock(m_CSLayers);
for (cChunkLayerList::iterator itr = m_Layers.begin(); itr != m_Layers.end(); ++itr)
diff --git a/src/ChunkMap.h b/src/ChunkMap.h
index 2a1d78ff8..b3fe25393 100644
--- a/src/ChunkMap.h
+++ b/src/ChunkMap.h
@@ -282,6 +282,9 @@ public:
void SpawnMobs(cMobSpawner& a_MobSpawner);
void Tick(float a_Dt);
+
+ /// Ticks a single block. Used by cWorld::TickQueuedBlocks() to tick the queued blocks
+ void TickBlock(int a_BlockX, int a_BlockY, int a_BlockZ);
void UnloadUnusedChunks(void);
void SaveAllChunks(void);
diff --git a/src/World.cpp b/src/World.cpp
index 4f315d2af..bed5d6701 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2596,12 +2596,12 @@ void cWorld::TickQueuedBlocks(void)
for (std::vector<BlockTickQueueItem *>::iterator itr = m_BlockTickQueueCopy.begin(); itr != m_BlockTickQueueCopy.end(); itr++)
{
- BlockTickQueueItem *Block = (*itr);
+ BlockTickQueueItem * Block = (*itr);
Block->TicksToWait -= 1;
if (Block->TicksToWait <= 0)
{
// TODO: Handle the case when the chunk is already unloaded
- BlockHandler(GetBlock(Block->X, Block->Y, Block->Z))->OnUpdate(this, Block->X, Block->Y, Block->Z);
+ m_ChunkMap->TickBlock(Block->X, Block->Y, Block->Z);
delete Block; // We don't have to remove it from the vector, this will happen automatically on the next tick
}
else