diff options
Diffstat (limited to 'src/Blocks/BlockFluid.h')
-rw-r--r-- | src/Blocks/BlockFluid.h | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 36f363a92..e856dba38 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -80,6 +80,10 @@ public: return 0; } + + + + virtual bool CanSustainPlant(BLOCKTYPE a_Plant) override { return ( @@ -109,33 +113,47 @@ public: { } - /** Called to tick the block */ - virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override + + + + + virtual void OnUpdate( + cChunkInterface & a_ChunkInterface, + cWorldInterface & a_WorldInterface, + cBlockPluginInterface & a_PluginInterface, + cChunk & a_Chunk, + const Vector3i a_RelPos + ) override { if (a_Chunk.GetWorld()->ShouldLavaSpawnFire()) { // Try to start up to 5 fires: for (int i = 0; i < 5; i++) { - TryStartFireNear(a_RelX, a_RelY, a_RelZ, a_Chunk); + TryStartFireNear(a_RelPos, a_Chunk); } } } + + + + /** Tries to start a fire near the lava at given coords. Returns true if fire started. */ - static bool TryStartFireNear(int a_RelX, int a_RelY, int a_RelZ, cChunk & a_Chunk) + static bool TryStartFireNear(const Vector3i a_RelPos, cChunk & a_Chunk) { - // Pick a block next to this lava block: + // Pick a random block next to this lava block: int rnd = a_Chunk.GetWorld()->GetTickRandomNumber(cChunkDef::NumBlocks * 8) / 7; int x = (rnd % 3) - 1; // -1 .. 1 int y = ((rnd / 4) % 4) - 1; // -1 .. 2 int z = ((rnd / 16) % 3) - 1; // -1 .. 1 + auto Pos = a_RelPos + Vector3i(x, y, z); // Check if it's fuel: BLOCKTYPE BlockType; if ( - ((a_RelY + y < 0) || (a_RelY + y >= cChunkDef::Height)) || - !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || + !cChunkDef::IsValidHeight(Pos.y) || + !a_Chunk.UnboundedRelGetBlockType(Pos, BlockType) || !cFireSimulator::IsFuel(BlockType) ) { @@ -143,10 +161,7 @@ public: } // Try to set it on fire: - static struct - { - int x, y, z; - } CrossCoords[] = + static Vector3i CrossCoords[] = { {-1, 0, 0}, { 1, 0, 0}, @@ -155,31 +170,37 @@ public: { 0, 0, -1}, { 0, 0, 1}, } ; - int RelX = a_RelX + x; - int RelY = a_RelY + y; - int RelZ = a_RelZ + z; for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++) { + auto NeighborPos = Pos + CrossCoords[i]; if ( - ((RelY + CrossCoords[i].y >= 0) && (RelY + CrossCoords[i].y < cChunkDef::Height)) && - a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, BlockType) && + cChunkDef::IsValidHeight(NeighborPos.y) && + a_Chunk.UnboundedRelGetBlockType(NeighborPos, BlockType) && (BlockType == E_BLOCK_AIR) ) { - // This is an air block next to a fuel next to lava, light it up: - a_Chunk.UnboundedRelSetBlock(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, E_BLOCK_FIRE, 0); + // This is an air block next to a fuel next to lava, light the fuel block up: + a_Chunk.UnboundedRelSetBlock(NeighborPos, E_BLOCK_FIRE, 0); return true; } } // for i - CrossCoords[] return false; } + + + + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override { UNUSED(a_Meta); return 4; } + + + + virtual bool CanSustainPlant(BLOCKTYPE a_Plant) override { return false; |