diff options
author | Michal Havlíček <80639037+havel06@users.noreply.github.com> | 2023-04-08 00:11:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-08 00:11:10 +0200 |
commit | 669392d44a0f74e83b2702fa64d4f8bfb2ec643c (patch) | |
tree | 2c80eca6e9504c6475b00e5fd72b18d308d06e0f | |
parent | refactor: removed m_MojangAPI from RankManager (#5483) (diff) | |
download | cuberite-669392d44a0f74e83b2702fa64d4f8bfb2ec643c.tar cuberite-669392d44a0f74e83b2702fa64d4f8bfb2ec643c.tar.gz cuberite-669392d44a0f74e83b2702fa64d4f8bfb2ec643c.tar.bz2 cuberite-669392d44a0f74e83b2702fa64d4f8bfb2ec643c.tar.lz cuberite-669392d44a0f74e83b2702fa64d4f8bfb2ec643c.tar.xz cuberite-669392d44a0f74e83b2702fa64d4f8bfb2ec643c.tar.zst cuberite-669392d44a0f74e83b2702fa64d4f8bfb2ec643c.zip |
-rw-r--r-- | Server/Plugins/APIDump/Classes/World.lua | 21 | ||||
-rw-r--r-- | src/Chunk.cpp | 9 | ||||
-rw-r--r-- | src/Chunk.h | 2 | ||||
-rw-r--r-- | src/MobSpawner.cpp | 5 | ||||
-rw-r--r-- | src/World.cpp | 10 | ||||
-rw-r--r-- | src/World.h | 4 |
6 files changed, 49 insertions, 2 deletions
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()</pre> 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 c9bd1dbcf..a693e08e6 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1980,3 +1980,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 176f111ed..6d8dc91db 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -452,6 +452,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 3fcb20f99..d5ed79fc4 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -220,7 +220,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 133458a8c..67ae6623b 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3229,3 +3229,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 b6511edf5..352bc19f3 100644 --- a/src/World.h +++ b/src/World.h @@ -843,7 +843,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 @@ -892,6 +892,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: |