diff --git a/Server/Plugins/APIDump/Classes/World.lua b/Server/Plugins/APIDump/Classes/World.lua index ab12c89cf..841c93cd0 100644 --- a/Server/Plugins/APIDump/Classes/World.lua +++ b/Server/Plugins/APIDump/Classes/World.lua @@ -2315,6 +2315,27 @@ function OnAllChunksAvailable() All return values from the callbacks are i }, Notes = "Returns whether or not saving chunk data is enabled. If disabled, the world will keep dirty chunks in memory forever, and will simply regenerate non-dirty chunks that are unloaded.", }, + IsSlimeChunk = + { + Params = + { + { + Name = "ChunkX", + Type = "number", + }, + { + Name = "ChunkZ", + Type = "number", + }, + }, + Returns = + { + { + Type = "boolean", + }, + }, + Notes = "Returns whether slimes can spawn in the chunk.", + }, IsTrapdoorOpen = { Params = diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 0b700ef00..aea9ee7ec 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1996,3 +1996,12 @@ NIBBLETYPE cChunk::GetTimeAlteredLight(NIBBLETYPE a_Skylight) const // Because NIBBLETYPE is unsigned, we clamp it to 0 .. 15 by checking for values above 15 return (a_Skylight < 16)? a_Skylight : 0; } + + + + + +bool cChunk::IsSlimeChunk() const +{ + return m_World->IsSlimeChunk(m_PosX, m_PosZ); +} diff --git a/src/Chunk.h b/src/Chunk.h index 8f21a062c..1e2ea0ec6 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -468,6 +468,8 @@ public: return cChunkDef::RelativeToAbsolute(a_RelBlockPosition, {m_PosX, m_PosZ}); } + /** Returns true if slimes should spawn in the chunk. */ + bool IsSlimeChunk() const; private: diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index e42783abf..9fd35b643 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -236,7 +236,10 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, Vector3i a_RelPos, eMonsterType (!cBlockInfo::IsTransparent(BlockBelow)) || (a_DisableSolidBelowCheck)) && ( - (a_RelPos.y <= 40) || + ( + (a_RelPos.y <= 40) && + a_Chunk->IsSlimeChunk() + ) || ( (a_Biome == biSwampland) && (a_RelPos.y >= 50) && diff --git a/src/World.cpp b/src/World.cpp index f4b2c0fda..ee18a3725 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3245,3 +3245,13 @@ void cWorld::cChunkGeneratorCallbacks::CallHookChunkGenerated (cChunkDesc & a_Ch *m_World, a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ(), &a_ChunkDesc );*/ } + + + + + +bool cWorld::IsSlimeChunk(int a_ChunkX, int a_ChunkZ) const +{ + cNoise Noise(GetSeed()); + return (Noise.IntNoise2DInt(a_ChunkX, a_ChunkZ) / 8) % 10 == 0; // 10% chance +} diff --git a/src/World.h b/src/World.h index b1503e118..ac5d64477 100644 --- a/src/World.h +++ b/src/World.h @@ -859,7 +859,7 @@ public: virtual bool IsWeatherWetAtXYZ(Vector3i a_Position) override; /** Returns the seed of the world. */ - int GetSeed(void) { return m_Generator.GetSeed(); } + int GetSeed(void) const { return m_Generator.GetSeed(); } // tolua_end @@ -908,6 +908,8 @@ public: as at least one requests is active the chunk will be ticked). */ void SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked = true); // tolua_export + /** Returns true if slimes should spawn in the chunk. */ + bool IsSlimeChunk(int a_ChunkX, int a_ChunkZ) const; // tolua_export private: class cTickThread: