Implement slime chunks. (#5484)

* Implement slime chunks.

* add cWorld::IsSlimeChunk

* add documentation for cWorld::IsSlimeChunk
This commit is contained in:
Michal Havlíček 2023-04-08 00:11:10 +02:00 committed by GitHub
parent dcad86e776
commit 669392d44a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 2 deletions

View File

@ -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 =

View File

@ -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);
}

View File

@ -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:

View File

@ -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) &&

View File

@ -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
}

View File

@ -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: