diff options
Diffstat (limited to 'src/Blocks/BlockDirt.h')
-rw-r--r-- | src/Blocks/BlockDirt.h | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 0d4f73212..727c5d295 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -10,13 +10,17 @@ -/** Handler used for all types of dirt and grass */ +/** Handler used for all types of dirt and grassblock. +TODO: Split the Grassblock handler away from this class. */ class cBlockDirtHandler : public cBlockHandler { + using super = cBlockHandler; + public: - cBlockDirtHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + + cBlockDirtHandler(BLOCKTYPE a_BlockType): + super(a_BlockType) { } @@ -91,37 +95,41 @@ public: // Y Coord out of range continue; } - int BlockX = a_RelX + OfsX; - int BlockY = a_RelY + OfsY; - int BlockZ = a_RelZ + OfsZ; - cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(BlockX, BlockZ); - if (Chunk == nullptr) + Vector3i pos(a_RelX + OfsX, a_RelY + OfsY, a_RelZ + OfsZ); + auto chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(pos); + if (chunk == nullptr) { // Unloaded chunk continue; } - Chunk->GetBlockTypeMeta(BlockX, BlockY, BlockZ, DestBlock, DestMeta); + chunk->GetBlockTypeMeta(pos, DestBlock, DestMeta); if ((DestBlock != E_BLOCK_DIRT) || (DestMeta != E_META_DIRT_NORMAL)) { // Not a regular dirt block continue; } - BLOCKTYPE above = Chunk->GetBlock(BlockX, BlockY + 1, BlockZ); - NIBBLETYPE light = std::max(Chunk->GetBlockLight(BlockX, BlockY + 1, BlockZ), Chunk->GetTimeAlteredLight(Chunk->GetSkyLight(BlockX, BlockY + 1, BlockZ))); + auto abovePos = pos.addedY(1); + BLOCKTYPE above = chunk->GetBlock(abovePos); + NIBBLETYPE light = std::max(chunk->GetBlockLight(abovePos), chunk->GetTimeAlteredLight(chunk->GetSkyLight(abovePos))); if ((light > 4) && cBlockInfo::IsTransparent(above) && (!IsBlockLava(above)) && (!IsBlockWaterOrIce(above)) ) { - if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread(*Chunk->GetWorld(), Chunk->GetPosX() * cChunkDef::Width + BlockX, BlockY, Chunk->GetPosZ() * cChunkDef::Width + BlockZ, ssGrassSpread)) + auto absPos = chunk->RelativeToAbsolute(pos); + if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread(*chunk->GetWorld(), absPos.x, absPos.y, absPos.z, ssGrassSpread)) { - Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0); + chunk->FastSetBlock(pos, E_BLOCK_GRASS, 0); } } } // for i - repeat twice } + + + + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override { UNUSED(a_Meta); |