summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockDirt.h
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 /src/Blocks/BlockDirt.h
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/BlockDirt.h32
1 files changed, 20 insertions, 12 deletions
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
}