diff options
author | Mattes D <github@xoft.cz> | 2014-03-03 20:52:08 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-03-03 20:52:08 +0100 |
commit | 71ae689eb71ce5ced58b19460a8d8137722ce357 (patch) | |
tree | acbb99403541d778513d4e2dcfd243a19c368bc9 /src/World.cpp | |
parent | Merge pull request #748 from xdot/master (diff) | |
parent | Add cancelling to WeatherChanging event. (diff) | |
download | cuberite-71ae689eb71ce5ced58b19460a8d8137722ce357.tar cuberite-71ae689eb71ce5ced58b19460a8d8137722ce357.tar.gz cuberite-71ae689eb71ce5ced58b19460a8d8137722ce357.tar.bz2 cuberite-71ae689eb71ce5ced58b19460a8d8137722ce357.tar.lz cuberite-71ae689eb71ce5ced58b19460a8d8137722ce357.tar.xz cuberite-71ae689eb71ce5ced58b19460a8d8137722ce357.tar.zst cuberite-71ae689eb71ce5ced58b19460a8d8137722ce357.zip |
Diffstat (limited to '')
-rw-r--r-- | src/World.cpp | 94 |
1 files changed, 81 insertions, 13 deletions
diff --git a/src/World.cpp b/src/World.cpp index 2dfa85d64..58d50d3a8 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -307,25 +307,52 @@ void cWorld::CastThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) +int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) +{ + switch (a_Weather) + { + case eWeather_Sunny: + { + return 14400 + (m_TickRand.randInt() % 4800); // 12 - 16 minutes + } + case eWeather_Rain: + { + return 9600 + (m_TickRand.randInt() % 7200); // 8 - 14 minutes + } + case eWeather_ThunderStorm: + { + return 2400 + (m_TickRand.randInt() % 4800); // 2 - 6 minutes + } + default: + { + LOGWARNING("Missing default weather interval for weather %d.", a_Weather); + return 1200; + } + } // switch (Weather) +} + + + + + void cWorld::SetWeather(eWeather a_NewWeather) { // Do the plugins agree? Do they want a different weather? - cRoot::Get()->GetPluginManager()->CallHookWeatherChanging(*this, a_NewWeather); + if (cRoot::Get()->GetPluginManager()->CallHookWeatherChanging(*this, a_NewWeather)) + { + m_WeatherInterval = GetDefaultWeatherInterval(m_Weather); + return; + } // Set new period for the selected weather: - switch (a_NewWeather) + m_WeatherInterval = GetDefaultWeatherInterval(a_NewWeather); + + // The weather can't be found: + if (m_WeatherInterval == 1200) { - case eWeather_Sunny: m_WeatherInterval = 14400 + (m_TickRand.randInt() % 4800); break; // 12 - 16 minutes - case eWeather_Rain: m_WeatherInterval = 9600 + (m_TickRand.randInt() % 7200); break; // 8 - 14 minutes - case eWeather_ThunderStorm: m_WeatherInterval = 2400 + (m_TickRand.randInt() % 4800); break; // 2 - 6 minutes - default: - { - LOGWARNING("Requested unknown weather %d, setting sunny for a minute instead.", a_NewWeather); - a_NewWeather = eWeather_Sunny; - m_WeatherInterval = 1200; - break; - } - } // switch (NewWeather) + return; + } + m_Weather = a_NewWeather; BroadcastWeather(m_Weather); @@ -2647,6 +2674,47 @@ bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, co +bool cWorld::IsTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + BLOCKTYPE Block; + NIBBLETYPE Meta; + GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, Meta); + if (Block != E_BLOCK_TRAPDOOR) + { + return false; + } + + return (Meta & 0x4) > 0; +} + + + + + +bool cWorld::SetTrapdoorOpen(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_Open) +{ + BLOCKTYPE Block; + NIBBLETYPE Meta; + GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, Block, Meta); + if (Block != E_BLOCK_TRAPDOOR) + { + return false; + } + + bool IsOpen = (Meta & 0x4) > 0; + if (a_Open != IsOpen) + { + SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta ^ 0x4); + BroadcastSoundParticleEffect(1003, a_BlockX, a_BlockY, a_BlockZ, 0); + return true; + } + return false; +} + + + + + void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ) { m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); |