diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Blocks/BlockFluid.h | 81 | ||||
-rw-r--r-- | src/Blocks/BlockHandler.cpp | 12 | ||||
-rw-r--r-- | src/ByteBuffer.cpp | 4 | ||||
-rw-r--r-- | src/ByteBuffer.h | 2 | ||||
-rw-r--r-- | src/Chunk.cpp | 4 | ||||
-rw-r--r-- | src/World.cpp | 1 | ||||
-rw-r--r-- | src/World.h | 3 |
7 files changed, 97 insertions, 10 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; + } +} ; + + + + diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 7bb35efeb..4a6d49449 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -144,6 +144,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_INACTIVE_COMPARATOR: return new cBlockComparatorHandler (a_BlockType); case E_BLOCK_IRON_DOOR: return new cBlockDoorHandler (a_BlockType); case E_BLOCK_IRON_ORE: return new cBlockOreHandler (a_BlockType); + case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType); case E_BLOCK_JUKEBOX: return new cBlockEntityHandler (a_BlockType); case E_BLOCK_JUNGLE_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_LADDER: return new cBlockLadderHandler (a_BlockType); @@ -157,18 +158,17 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_MELON_STEM: return new cBlockStemsHandler (a_BlockType); case E_BLOCK_MYCELIUM: return new cBlockMyceliumHandler (a_BlockType); case E_BLOCK_NETHER_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); + case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType); case E_BLOCK_NOTE_BLOCK: return new cBlockNoteHandler (a_BlockType); case E_BLOCK_PISTON: return new cBlockPistonHandler (a_BlockType); case E_BLOCK_PISTON_EXTENSION: return new cBlockPistonHeadHandler ( ); case E_BLOCK_PLANKS: return new cBlockPlanksHandler (a_BlockType); - case E_BLOCK_NETHER_PORTAL: return new cBlockPortalHandler (a_BlockType); + case E_BLOCK_POTATOES: return new cBlockCropsHandler (a_BlockType); + case E_BLOCK_POWERED_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_PUMPKIN: return new cBlockPumpkinHandler (a_BlockType); - case E_BLOCK_JACK_O_LANTERN: return new cBlockPumpkinHandler (a_BlockType); case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType); case E_BLOCK_QUARTZ_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); - case E_BLOCK_POTATOES: return new cBlockCropsHandler (a_BlockType); - case E_BLOCK_POWERED_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE_GLOWING: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_REPEATER_OFF: return new cBlockRedstoneRepeaterHandler(a_BlockType); @@ -184,8 +184,8 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_SIGN_POST: return new cBlockSignHandler (a_BlockType); case E_BLOCK_SNOW: return new cBlockSnowHandler (a_BlockType); case E_BLOCK_SPRUCE_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); - case E_BLOCK_STATIONARY_LAVA: return new cBlockFluidHandler (a_BlockType); - case E_BLOCK_STATIONARY_WATER: return new cBlockFluidHandler (a_BlockType); + case E_BLOCK_STATIONARY_LAVA: return new cBlockLavaHandler (a_BlockType); + case E_BLOCK_STATIONARY_WATER: return new cBlockLavaHandler (a_BlockType); case E_BLOCK_STICKY_PISTON: return new cBlockPistonHandler (a_BlockType); case E_BLOCK_STONE: return new cBlockStoneHandler (a_BlockType); case E_BLOCK_STONE_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index a6be09ad3..29f3afbfc 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -26,7 +26,9 @@ (defined(_WIN32) && defined(__ARM__) && defined(_MSC_VER)) \ ) #define IS_LITTLE_ENDIAN -#elif defined (__ARMEB__) +#elif ( \ + defined (__ARMEB__) || defined(__sparc) \ +) #define IS_BIG_ENDIAN #else #error Cannot determine endianness of this platform diff --git a/src/ByteBuffer.h b/src/ByteBuffer.h index a9dd7f5ea..95c690203 100644 --- a/src/ByteBuffer.h +++ b/src/ByteBuffer.h @@ -123,7 +123,7 @@ protected: int m_BufferSize; // Total size of the ringbuffer #ifdef _DEBUG - unsigned long m_ThreadID; // Thread that is currently accessing the object, checked via cSingleThreadAccessChecker + volatile unsigned long m_ThreadID; // Thread that is currently accessing the object, checked via cSingleThreadAccessChecker #endif // _DEBUG int m_DataStart; // Where the data starts in the ringbuffer diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 45825a30f..5c9eb892b 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -641,7 +641,7 @@ void cChunk::TickBlock(int a_RelX, int a_RelY, int a_RelZ) } 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); + Handler->OnUpdate(*this, a_RelX, a_RelY, a_RelZ); } @@ -794,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(*this, m_BlockTickX + m_PosX * Width, m_BlockTickY, m_BlockTickZ + m_PosZ * Width); + Handler->OnUpdate(*this, m_BlockTickX, m_BlockTickY, m_BlockTickZ); } // for i - tickblocks } diff --git a/src/World.cpp b/src/World.cpp index bed5d6701..7982924ae 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -522,6 +522,7 @@ void cWorld::Start(void) m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false); m_bEnabledPVP = IniFile.GetValueSetB("PVP", "Enabled", true); m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", false); + m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true); m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode); diff --git a/src/World.h b/src/World.h index a6b61f2e2..ea0db53e6 100644 --- a/src/World.h +++ b/src/World.h @@ -129,6 +129,8 @@ public: bool IsPVPEnabled(void) const { return m_bEnabledPVP; } bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; } + bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; } + eDimension GetDimension(void) const { return m_Dimension; } /// Returns the world height at the specified coords; waits for the chunk to get loaded / generated @@ -654,6 +656,7 @@ private: eGameMode m_GameMode; bool m_bEnabledPVP; bool m_IsDeepSnowEnabled; + bool m_ShouldLavaSpawnFire; // The cRedstone class simulates redstone and needs access to m_RSList // friend class cRedstone; |