diff options
author | Samuel Barney <samjbarney@gmail.com> | 2013-12-05 15:32:19 +0100 |
---|---|---|
committer | Samuel Barney <samjbarney@gmail.com> | 2013-12-05 15:32:19 +0100 |
commit | 8acfe21503f4b4fdccd03d0927ec8a11cd6457ec (patch) | |
tree | 1ea90086621fc11d433cd94ccd635d54c5a4380a /src/Blocks/BlockFluid.h | |
parent | Made suggested changes (diff) | |
parent | ProtoProxy: Fixed metadata parsing. (diff) | |
download | cuberite-8acfe21503f4b4fdccd03d0927ec8a11cd6457ec.tar cuberite-8acfe21503f4b4fdccd03d0927ec8a11cd6457ec.tar.gz cuberite-8acfe21503f4b4fdccd03d0927ec8a11cd6457ec.tar.bz2 cuberite-8acfe21503f4b4fdccd03d0927ec8a11cd6457ec.tar.lz cuberite-8acfe21503f4b4fdccd03d0927ec8a11cd6457ec.tar.xz cuberite-8acfe21503f4b4fdccd03d0927ec8a11cd6457ec.tar.zst cuberite-8acfe21503f4b4fdccd03d0927ec8a11cd6457ec.zip |
Diffstat (limited to 'src/Blocks/BlockFluid.h')
-rw-r--r-- | src/Blocks/BlockFluid.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 0db2f60c4..bce5064bc 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -54,3 +54,84 @@ public: + +class cBlockLavaHandler : + public cBlockFluidHandler +{ + typedef cBlockFluidHandler super; +public: + + cBlockLavaHandler(BLOCKTYPE a_BlockType) : + super(a_BlockType) + { + } + + + /// Called to tick the block + virtual void OnUpdate(cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) 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); + } + } + } + + + /// 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) + { + // Pick a 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 + + // Check if it's fuel: + BLOCKTYPE BlockType; + if ( + !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || + !cFireSimulator::IsFuel(BlockType) + ) + { + return false; + } + + // Try to set it on fire: + static struct + { + int x, y, z; + } CrossCoords[] = + { + {-1, 0, 0}, + { 1, 0, 0}, + { 0, -1, 0}, + { 0, 1, 0}, + { 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++) + { + if ( + a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, 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); + return true; + } + } // for i - CrossCoords[] + return false; + } +} ; + + + + |