Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
cChunkMap Class Reference

#include <ChunkMap.h>

Collaboration diagram for cChunkMap:
Collaboration graph
[legend]

Public Member Functions

bool AddChunkClient (int a_ChunkX, int a_ChunkZ, cClientHandle *a_Client)
 Adds client to a chunk, if not already present; returns true if added, false if present. More...
 
void AddEntity (OwnedEntity a_Entity)
 Adds the entity to its appropriate chunk, takes ownership of the entity pointer. More...
 
void AddPlayer (std::unique_ptr< cPlayer > a_Player)
 Adds the player to its appropriate chunk, takes ownership of the player pointer. More...
 
 cChunkMap (cWorld *a_World)
 
void ChunkLighted (int a_ChunkX, int a_ChunkZ, const cChunkDef::BlockNibbles &a_BlockLight, const cChunkDef::BlockNibbles &a_SkyLight)
 
void ChunkLoadFailed (int a_ChunkX, int a_ChunkZ)
 Marks the chunk as failed-to-load. More...
 
void ChunkValidated (void)
 
void CollectMobCensus (cMobCensus &a_ToFill)
 Make a Mob census, of all mobs, their family, their chunk and their distance to closest player. More...
 
void CollectPickupsByEntity (cEntity &a_Entity)
 Makes the specified entity collect all the pickups around them. More...
 
void CompareChunkClients (cChunk *a_Chunk1, cChunk *a_Chunk2, cClientDiffCallback &a_Callback)
 Compares clients of two chunks, calls the callback accordingly. More...
 
void CompareChunkClients (int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback &a_Callback)
 Compares clients of two chunks, calls the callback accordingly. More...
 
bool DigBlock (Vector3i a_BlockPos)
 Removes the block at the specified coords and wakes up simulators. More...
 
bool DoWithBlockEntityAt (Vector3i a_Position, cBlockEntityCallback a_Callback)
 Calls the callback for the block entity at the specified coords. More...
 
bool DoWithChunk (int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
 Calls the callback for the chunk specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback. More...
 
bool DoWithChunkAt (Vector3i a_BlockPos, cChunkCallback a_Callback)
 Calls the callback for the chunk at the block position specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback. More...
 
bool DoWithEntityByID (UInt32 a_EntityID, cEntityCallback a_Callback) const
 Calls the callback if the entity with the specified ID is found, with the entity object as the callback param. More...
 
void FastSetBlock (Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
 Sets the block at the specified coords to the specified value. More...
 
bool ForEachBlockEntityInChunk (int a_ChunkX, int a_ChunkZ, cBlockEntityCallback a_Callback)
 Calls the callback for each block entity in the specified chunk. More...
 
bool ForEachChunkInRect (int a_MinChunkX, int a_MaxChunkX, int a_MinChunkZ, int a_MaxChunkZ, cChunkDataCallback &a_Callback)
 Calls the callback for each chunk in the coords specified (all cords are inclusive). More...
 
bool ForEachEntity (cEntityCallback a_Callback) const
 Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true. More...
 
bool ForEachEntityInBox (const cBoundingBox &a_Box, cEntityCallback a_Callback)
 Calls the callback for each entity that has a nonempty intersection with the specified boundingbox. More...
 
bool ForEachEntityInChunk (int a_ChunkX, int a_ChunkZ, cEntityCallback a_Callback)
 Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true. More...
 
bool ForEachLoadedChunk (cFunctionRef< bool(int, int)> a_Callback) const
 Calls the callback for each loaded chunk. More...
 
void GenerateChunk (int a_ChunkX, int a_ChunkZ)
 Queues the chunk for generating. More...
 
EMCSBiome GetBiomeAt (int a_BlockX, int a_BlockZ) const
 Returns the biome at the specified coords. More...
 
BLOCKTYPE GetBlock (Vector3i a_BlockPos) const
 
NIBBLETYPE GetBlockBlockLight (Vector3i a_BlockPos) const
 
bool GetBlockInfo (Vector3i, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_Meta, NIBBLETYPE &a_SkyLight, NIBBLETYPE &a_BlockLight) const
 
NIBBLETYPE GetBlockMeta (Vector3i a_BlockPos) const
 
bool GetBlocks (sSetBlockVector &a_Blocks, bool a_ContinueOnFailure)
 Retrieves block types and metas of the specified blocks. More...
 
NIBBLETYPE GetBlockSkyLight (Vector3i a_BlockPos) const
 
bool GetBlockTypeMeta (Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
 
bool GetChunkData (cChunkCoords a_Coords, cChunkDataCallback &a_Callback) const
 Calls the callback with the chunk's data, if available (with ChunkCS locked). More...
 
void GetChunkStats (int &a_NumChunksValid, int &a_NumChunksDirty) const
 Returns the number of valid chunks and the number of dirty chunks. More...
 
cCriticalSectionGetCS (void) const
 Returns the CS for locking the chunkmap; only cWorld::cLock may use this function! More...
 
int GetHeight (int a_BlockX, int a_BlockZ)
 
size_t GetNumChunks (void) const
 
size_t GetNumUnusedDirtyChunks (void) const
 Returns the number of unused dirty chunks. More...
 
cWorldGetWorld (void) const
 
int GrowPlantAt (Vector3i a_BlockPos, int a_NumStages=1)
 Grows the plant at the specified position by at most a_NumStages. More...
 
bool HasChunkAnyClients (int a_ChunkX, int a_ChunkZ) const
 
bool HasEntity (UInt32 a_EntityID) const
 Returns true if the entity with specified ID is present in the chunks. More...
 
bool IsChunkLighted (int a_ChunkX, int a_ChunkZ)
 
bool IsChunkQueued (int a_ChunkX, int a_ChunkZ) const
 Returns true iff the chunk is in the loader / generator queue. More...
 
bool IsChunkValid (int a_ChunkX, int a_ChunkZ) const
 
bool IsWeatherSunnyAt (int a_BlockX, int a_BlockZ) const
 
bool IsWeatherWetAt (int a_BlockX, int a_BlockZ) const
 
bool IsWeatherWetAt (Vector3i a_Position) const
 
void MarkChunkDirty (int a_ChunkX, int a_ChunkZ)
 
void MarkChunkRegenerating (int a_ChunkX, int a_ChunkZ)
 Marks the chunk as being regenerated - all its clients want that chunk again (used by cWorld::RegenerateChunk()) More...
 
void MarkChunkSaved (int a_ChunkX, int a_ChunkZ)
 
void MarkChunkSaving (int a_ChunkX, int a_ChunkZ)
 
cItems PickupsFromBlock (Vector3i a_BlockPos, const cEntity *a_Digger, const cItem *a_Tool)
 Returns all the pickups that would result if the a_Digger dug up the block at a_BlockPos using a_Tool. More...
 
void PrepareChunk (int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallAfter={})
 Queues the chunk for preparing - making sure that it's generated and lit. More...
 
void RemoveChunkClient (int a_ChunkX, int a_ChunkZ, cClientHandle *a_Client)
 Removes the client from the chunk. More...
 
void RemoveClientFromChunks (cClientHandle *a_Client)
 Removes the client from all chunks it is present in. More...
 
OwnedEntity RemoveEntity (cEntity &a_Entity)
 Removes the entity from its appropriate chunk Returns an owning reference to the found entity. More...
 
void ReplaceTreeBlocks (const sSetBlockVector &a_Blocks)
 Special function used for growing trees, replaces only blocks that tree may overwrite. More...
 
void SaveAllChunks (void) const
 
void SendBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle &a_Client)
 Sends the block entity, if it is at the coords specified, to a_Client. More...
 
void SendBlockTo (int a_BlockX, int a_BlockY, int a_BlockZ, const cPlayer &a_Player)
 Sends the block at the specified coords to the specified player. More...
 
bool SetAreaBiome (int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome)
 Sets the biome at the area. More...
 
bool SetBiomeAt (int a_BlockX, int a_BlockZ, EMCSBiome a_Biome)
 Sets the biome at the specified coords. More...
 
void SetBlock (Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
 
void SetBlockMeta (Vector3i a_BlockPos, NIBBLETYPE a_BlockMeta)
 Sets the meta for the specified block, while keeping the blocktype. More...
 
void SetChunkAlwaysTicked (int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked)
 Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter for the specified chunk. More...
 
void SetChunkData (SetChunkData &&a_SetChunkData)
 Sets the chunk data as either loaded from the storage or generated. More...
 
void SetNextBlockToTick (const Vector3i a_BlockPos)
 Causes the specified block to be ticked on the next Tick() call. More...
 
void SpawnMobs (cMobSpawner &a_MobSpawner)
 Try to Spawn Monsters inside all Chunks. More...
 
void Tick (std::chrono::milliseconds a_Dt)
 
void TickBlock (const Vector3i a_BlockPos)
 Ticks a single block. More...
 
void TrackInDeadlockDetect (cDeadlockDetect &a_DeadlockDetect, const AString &a_WorldName)
 Adds this chunkmap's CS to the DeadlockDetect's tracked CSs. More...
 
bool TryGetHeight (int a_BlockX, int a_BlockZ, int &a_Height)
 
void UnloadUnusedChunks (void)
 
void UntrackInDeadlockDetect (cDeadlockDetect &a_DeadlockDetect)
 Removes this chunkmap's CS from the DeadlockDetect's tracked CSs. More...
 
bool UseBlockEntity (cPlayer *a_Player, int a_X, int a_Y, int a_Z)
 a_Player rclked block entity at the coords specified, handle it returns true if the use was successful, return false to use the block as a "normal" block More...
 
void WakeUpSimulators (int a_BlockX, int a_BlockY, int a_BlockZ)
 
void WakeUpSimulators (Vector3i a_Block)
 Wakes up simulators for the specified block. More...
 
bool WriteBlockArea (cBlockArea &a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
 Writes the block area into the specified coords. More...
 

Private Types

typedef std::list< cChunkStay * > cChunkStays
 

Private Member Functions

void AddChunkStay (cChunkStay &a_ChunkStay)
 Adds a new cChunkStay descendant to the internal list of ChunkStays; loads its chunks. More...
 
cChunkConstructChunk (int a_ChunkX, int a_ChunkZ)
 Returns or creates and returns a chunk pointer corresponding to the given chunk coordinates. More...
 
void DelChunkStay (cChunkStay &a_ChunkStay)
 Removes the specified cChunkStay descendant from the internal list of ChunkStays. More...
 
cChunkFindChunk (int a_ChunkX, int a_ChunkZ)
 Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked. More...
 
const cChunkFindChunk (int a_ChunkX, int a_ChunkZ) const
 Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked. More...
 
cChunkGetChunk (int a_ChunkX, int a_ChunkZ)
 Constructs a chunk and queues it for loading / generating if not valid, returning it. More...
 

Private Attributes

std::map< cChunkCoords, cChunkm_Chunks
 A map of chunk coordinates to chunks. More...
 
cChunkStays m_ChunkStays
 The cChunkStay descendants that are currently enabled in this chunkmap. More...
 
cCriticalSection m_CSChunks
 
cEvent m_evtChunkValid
 
cWorldm_World
 

Friends

class cChunk
 
class cChunkStay
 

Detailed Description

Definition at line 37 of file ChunkMap.h.

Member Typedef Documentation

◆ cChunkStays

typedef std::list<cChunkStay *> cChunkMap::cChunkStays
private

Definition at line 295 of file ChunkMap.h.

Constructor & Destructor Documentation

◆ cChunkMap()

cChunkMap::cChunkMap ( cWorld a_World)

Definition at line 30 of file ChunkMap.cpp.

Member Function Documentation

◆ AddChunkClient()

bool cChunkMap::AddChunkClient ( int  a_ChunkX,
int  a_ChunkZ,
cClientHandle a_Client 
)

Adds client to a chunk, if not already present; returns true if added, false if present.

Definition at line 873 of file ChunkMap.cpp.

◆ AddChunkStay()

void cChunkMap::AddChunkStay ( cChunkStay a_ChunkStay)
private

Adds a new cChunkStay descendant to the internal list of ChunkStays; loads its chunks.

To be used only by cChunkStay; others should use cChunkStay::Enable() instead

Definition at line 1495 of file ChunkMap.cpp.

◆ AddEntity()

void cChunkMap::AddEntity ( OwnedEntity  a_Entity)

Adds the entity to its appropriate chunk, takes ownership of the entity pointer.

Definition at line 908 of file ChunkMap.cpp.

◆ AddPlayer()

void cChunkMap::AddPlayer ( std::unique_ptr< cPlayer a_Player)

Adds the player to its appropriate chunk, takes ownership of the player pointer.

Definition at line 935 of file ChunkMap.cpp.

◆ ChunkLighted()

void cChunkMap::ChunkLighted ( int  a_ChunkX,
int  a_ChunkZ,
const cChunkDef::BlockNibbles a_BlockLight,
const cChunkDef::BlockNibbles a_SkyLight 
)

Definition at line 251 of file ChunkMap.cpp.

◆ ChunkLoadFailed()

void cChunkMap::ChunkLoadFailed ( int  a_ChunkX,
int  a_ChunkZ 
)

Marks the chunk as failed-to-load.

Definition at line 1129 of file ChunkMap.cpp.

◆ ChunkValidated()

void cChunkMap::ChunkValidated ( void  )

Definition at line 1458 of file ChunkMap.cpp.

◆ CollectMobCensus()

void cChunkMap::CollectMobCensus ( cMobCensus a_ToFill)

Make a Mob census, of all mobs, their family, their chunk and their distance to closest player.

Definition at line 1307 of file ChunkMap.cpp.

◆ CollectPickupsByEntity()

void cChunkMap::CollectPickupsByEntity ( cEntity a_Entity)

Makes the specified entity collect all the pickups around them.

Definition at line 442 of file ChunkMap.cpp.

◆ CompareChunkClients() [1/2]

void cChunkMap::CompareChunkClients ( cChunk a_Chunk1,
cChunk a_Chunk2,
cClientDiffCallback a_Callback 
)

Compares clients of two chunks, calls the callback accordingly.

Definition at line 843 of file ChunkMap.cpp.

◆ CompareChunkClients() [2/2]

void cChunkMap::CompareChunkClients ( int  a_ChunkX1,
int  a_ChunkZ1,
int  a_ChunkX2,
int  a_ChunkZ2,
cClientDiffCallback a_Callback 
)

Compares clients of two chunks, calls the callback accordingly.

Definition at line 822 of file ChunkMap.cpp.

◆ ConstructChunk()

cChunk & cChunkMap::ConstructChunk ( int  a_ChunkX,
int  a_ChunkZ 
)
private

Returns or creates and returns a chunk pointer corresponding to the given chunk coordinates.

Emplaces this chunk in the chunk map.

Definition at line 39 of file ChunkMap.cpp.

◆ DelChunkStay()

void cChunkMap::DelChunkStay ( cChunkStay a_ChunkStay)
private

Removes the specified cChunkStay descendant from the internal list of ChunkStays.

To be used only by cChunkStay; others should use cChunkStay::Disable() instead

Definition at line 1526 of file ChunkMap.cpp.

◆ DigBlock()

bool cChunkMap::DigBlock ( Vector3i  a_BlockPos)

Removes the block at the specified coords and wakes up simulators.

Returns false if the chunk is not loaded (and the block is not dug). Returns true if successful.

Definition at line 765 of file ChunkMap.cpp.

◆ DoWithBlockEntityAt()

bool cChunkMap::DoWithBlockEntityAt ( Vector3i  a_Position,
cBlockEntityCallback  a_Callback 
)

Calls the callback for the block entity at the specified coords.

Returns false if there's no block entity at those coords, and whatever the callback returns if found.

Definition at line 1079 of file ChunkMap.cpp.

◆ DoWithChunk()

bool cChunkMap::DoWithChunk ( int  a_ChunkX,
int  a_ChunkZ,
cChunkCallback  a_Callback 
)

Calls the callback for the chunk specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback.

Definition at line 128 of file ChunkMap.cpp.

◆ DoWithChunkAt()

bool cChunkMap::DoWithChunkAt ( Vector3i  a_BlockPos,
cChunkCallback  a_Callback 
)

Calls the callback for the chunk at the block position specified, with ChunkMapCS locked; returns false if the chunk doesn't exist, otherwise returns the same value as the callback.

Definition at line 143 of file ChunkMap.cpp.

◆ DoWithEntityByID()

bool cChunkMap::DoWithEntityByID ( UInt32  a_EntityID,
cEntityCallback  a_Callback 
) const

Calls the callback if the entity with the specified ID is found, with the entity object as the callback param.

Returns true if entity found and callback returned false.

Definition at line 1046 of file ChunkMap.cpp.

◆ FastSetBlock()

void cChunkMap::FastSetBlock ( Vector3i  a_BlockPos,
BLOCKTYPE  a_BlockType,
NIBBLETYPE  a_BlockMeta 
)

Sets the block at the specified coords to the specified value.

The replacement doesn't trigger block updates, nor wake up simulators. The replaced blocks aren't checked for block entities (block entity is leaked if it exists at this block). If the chunk is invalid, the operation is ignored silently.

Definition at line 425 of file ChunkMap.cpp.

◆ FindChunk() [1/2]

cChunk * cChunkMap::FindChunk ( int  a_ChunkX,
int  a_ChunkZ 
)
private

Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked.

To be called only from cChunkMap.

Definition at line 69 of file ChunkMap.cpp.

◆ FindChunk() [2/2]

const cChunk * cChunkMap::FindChunk ( int  a_ChunkX,
int  a_ChunkZ 
) const
private

Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSChunks is locked.

To be called only from cChunkMap.

Definition at line 81 of file ChunkMap.cpp.

◆ ForEachBlockEntityInChunk()

bool cChunkMap::ForEachBlockEntityInChunk ( int  a_ChunkX,
int  a_ChunkZ,
cBlockEntityCallback  a_Callback 
)

Calls the callback for each block entity in the specified chunk.

Returns true if all block entities processed, false if the callback aborted by returning true.

Definition at line 1064 of file ChunkMap.cpp.

◆ ForEachChunkInRect()

bool cChunkMap::ForEachChunkInRect ( int  a_MinChunkX,
int  a_MaxChunkX,
int  a_MinChunkZ,
int  a_MaxChunkZ,
cChunkDataCallback &  a_Callback 
)

Calls the callback for each chunk in the coords specified (all cords are inclusive).

Returns true if all chunks have been processed successfully

Definition at line 1167 of file ChunkMap.cpp.

◆ ForEachEntity()

bool cChunkMap::ForEachEntity ( cEntityCallback  a_Callback) const

Calls the callback for each entity in the entire world; returns true if all entities processed, false if the callback aborted by returning true.

Definition at line 982 of file ChunkMap.cpp.

◆ ForEachEntityInBox()

bool cChunkMap::ForEachEntityInBox ( const cBoundingBox a_Box,
cEntityCallback  a_Callback 
)

Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.

Returns true if all entities processed, false if the callback aborted by returning true. If any chunk in the box is missing, ignores the entities in that chunk silently.

Definition at line 1014 of file ChunkMap.cpp.

◆ ForEachEntityInChunk()

bool cChunkMap::ForEachEntityInChunk ( int  a_ChunkX,
int  a_ChunkZ,
cEntityCallback  a_Callback 
)

Calls the callback for each entity in the specified chunk; returns true if all entities processed, false if the callback aborted by returning true.

Definition at line 999 of file ChunkMap.cpp.

◆ ForEachLoadedChunk()

bool cChunkMap::ForEachLoadedChunk ( cFunctionRef< bool(int, int)>  a_Callback) const

Calls the callback for each loaded chunk.

Returns true if all chunks have been processed successfully

Definition at line 1196 of file ChunkMap.cpp.

◆ GenerateChunk()

void cChunkMap::GenerateChunk ( int  a_ChunkX,
int  a_ChunkZ 
)

Queues the chunk for generating.

First attempts to load the chunk from the storage. If that fails, queues the chunk for generating.

Definition at line 1119 of file ChunkMap.cpp.

◆ GetBiomeAt()

EMCSBiome cChunkMap::GetBiomeAt ( int  a_BlockX,
int  a_BlockZ 
) const

Returns the biome at the specified coords.

Reads the biome from the chunk, if loaded, invalid otherwise.

Definition at line 660 of file ChunkMap.cpp.

◆ GetBlock()

BLOCKTYPE cChunkMap::GetBlock ( Vector3i  a_BlockPos) const

Definition at line 475 of file ChunkMap.cpp.

◆ GetBlockBlockLight()

NIBBLETYPE cChunkMap::GetBlockBlockLight ( Vector3i  a_BlockPos) const

Definition at line 532 of file ChunkMap.cpp.

◆ GetBlockInfo()

bool cChunkMap::GetBlockInfo ( Vector3i  a_BlockPos,
BLOCKTYPE a_BlockType,
NIBBLETYPE a_Meta,
NIBBLETYPE a_SkyLight,
NIBBLETYPE a_BlockLight 
) const

Definition at line 605 of file ChunkMap.cpp.

◆ GetBlockMeta()

NIBBLETYPE cChunkMap::GetBlockMeta ( Vector3i  a_BlockPos) const

Definition at line 494 of file ChunkMap.cpp.

◆ GetBlocks()

bool cChunkMap::GetBlocks ( sSetBlockVector a_Blocks,
bool  a_ContinueOnFailure 
)

Retrieves block types and metas of the specified blocks.

If a chunk is not loaded, doesn't modify the block and consults a_ContinueOnFailure whether to process the rest of the array. Returns true if all blocks were read, false if any one failed.

Definition at line 735 of file ChunkMap.cpp.

◆ GetBlockSkyLight()

NIBBLETYPE cChunkMap::GetBlockSkyLight ( Vector3i  a_BlockPos) const

Definition at line 513 of file ChunkMap.cpp.

◆ GetBlockTypeMeta()

bool cChunkMap::GetBlockTypeMeta ( Vector3i  a_BlockPos,
BLOCKTYPE a_BlockType,
NIBBLETYPE a_BlockMeta 
) const

Definition at line 586 of file ChunkMap.cpp.

◆ GetChunk()

cChunk & cChunkMap::GetChunk ( int  a_ChunkX,
int  a_ChunkZ 
)
private

Constructs a chunk and queues it for loading / generating if not valid, returning it.

Definition at line 52 of file ChunkMap.cpp.

◆ GetChunkData()

bool cChunkMap::GetChunkData ( cChunkCoords  a_Coords,
cChunkDataCallback &  a_Callback 
) const

Calls the callback with the chunk's data, if available (with ChunkCS locked).

Returns true if the chunk was reported successfully, false if not (chunk not present or callback failed).

Definition at line 271 of file ChunkMap.cpp.

◆ GetChunkStats()

void cChunkMap::GetChunkStats ( int &  a_NumChunksValid,
int &  a_NumChunksDirty 
) const

Returns the number of valid chunks and the number of dirty chunks.

Definition at line 1254 of file ChunkMap.cpp.

◆ GetCS()

cCriticalSection& cChunkMap::GetCS ( void  ) const
inline

Returns the CS for locking the chunkmap; only cWorld::cLock may use this function!

Definition at line 272 of file ChunkMap.h.

◆ GetHeight()

int cChunkMap::GetHeight ( int  a_BlockX,
int  a_BlockZ 
)

Definition at line 383 of file ChunkMap.cpp.

◆ GetNumChunks()

size_t cChunkMap::GetNumChunks ( void  ) const

Definition at line 1430 of file ChunkMap.cpp.

◆ GetNumUnusedDirtyChunks()

size_t cChunkMap::GetNumUnusedDirtyChunks ( void  ) const

Returns the number of unused dirty chunks.

Those are chunks that we can save and then unload

Definition at line 1440 of file ChunkMap.cpp.

◆ GetWorld()

cWorld* cChunkMap::GetWorld ( void  ) const
inline

Definition at line 262 of file ChunkMap.h.

◆ GrowPlantAt()

int cChunkMap::GrowPlantAt ( Vector3i  a_BlockPos,
int  a_NumStages = 1 
)

Grows the plant at the specified position by at most a_NumStages.

The block's Grow handler is invoked. Returns the number of stages the plant has grown, 0 if not a plant.

Definition at line 1273 of file ChunkMap.cpp.

◆ HasChunkAnyClients()

bool cChunkMap::HasChunkAnyClients ( int  a_ChunkX,
int  a_ChunkZ 
) const

Definition at line 372 of file ChunkMap.cpp.

◆ HasEntity()

bool cChunkMap::HasEntity ( UInt32  a_EntityID) const

Returns true if the entity with specified ID is present in the chunks.

Definition at line 947 of file ChunkMap.cpp.

◆ IsChunkLighted()

bool cChunkMap::IsChunkLighted ( int  a_ChunkX,
int  a_ChunkZ 
)

Definition at line 1151 of file ChunkMap.cpp.

◆ IsChunkQueued()

bool cChunkMap::IsChunkQueued ( int  a_ChunkX,
int  a_ChunkZ 
) const

Returns true iff the chunk is in the loader / generator queue.

Definition at line 293 of file ChunkMap.cpp.

◆ IsChunkValid()

bool cChunkMap::IsChunkValid ( int  a_ChunkX,
int  a_ChunkZ 
) const

Definition at line 361 of file ChunkMap.cpp.

◆ IsWeatherSunnyAt()

bool cChunkMap::IsWeatherSunnyAt ( int  a_BlockX,
int  a_BlockZ 
) const

Definition at line 304 of file ChunkMap.cpp.

◆ IsWeatherWetAt() [1/2]

bool cChunkMap::IsWeatherWetAt ( int  a_BlockX,
int  a_BlockZ 
) const

Definition at line 323 of file ChunkMap.cpp.

◆ IsWeatherWetAt() [2/2]

bool cChunkMap::IsWeatherWetAt ( Vector3i  a_Position) const

Definition at line 342 of file ChunkMap.cpp.

◆ MarkChunkDirty()

void cChunkMap::MarkChunkDirty ( int  a_ChunkX,
int  a_ChunkZ 
)

Definition at line 170 of file ChunkMap.cpp.

◆ MarkChunkRegenerating()

void cChunkMap::MarkChunkRegenerating ( int  a_ChunkX,
int  a_ChunkZ 
)

Marks the chunk as being regenerated - all its clients want that chunk again (used by cWorld::RegenerateChunk())

Definition at line 1141 of file ChunkMap.cpp.

◆ MarkChunkSaved()

void cChunkMap::MarkChunkSaved ( int  a_ChunkX,
int  a_ChunkZ 
)

Definition at line 200 of file ChunkMap.cpp.

◆ MarkChunkSaving()

void cChunkMap::MarkChunkSaving ( int  a_ChunkX,
int  a_ChunkZ 
)

Definition at line 185 of file ChunkMap.cpp.

◆ PickupsFromBlock()

cItems cChunkMap::PickupsFromBlock ( Vector3i  a_BlockPos,
const cEntity a_Digger,
const cItem a_Tool 
)

Returns all the pickups that would result if the a_Digger dug up the block at a_BlockPos using a_Tool.

a_Digger is usually a player, but can be nullptr for natural causes. a_Tool is an optional item used to dig up the block, used by the handlers (empty hand vs shears produce different pickups from leaves). An empty hand is assumed if a_Tool is nullptr. Returns an empty cItems object if the chunk is not present.

Definition at line 787 of file ChunkMap.cpp.

◆ PrepareChunk()

void cChunkMap::PrepareChunk ( int  a_ChunkX,
int  a_ChunkZ,
std::unique_ptr< cChunkCoordCallback a_CallAfter = {} 
)

Queues the chunk for preparing - making sure that it's generated and lit.

The specified chunk is queued to be loaded or generated, and lit if needed. The specified callback is called after the chunk has been prepared. If there's no preparation to do, only the callback is called. It is legal to call without the callback.

Definition at line 1096 of file ChunkMap.cpp.

◆ RemoveChunkClient()

void cChunkMap::RemoveChunkClient ( int  a_ChunkX,
int  a_ChunkZ,
cClientHandle a_Client 
)

Removes the client from the chunk.

Definition at line 883 of file ChunkMap.cpp.

◆ RemoveClientFromChunks()

void cChunkMap::RemoveClientFromChunks ( cClientHandle a_Client)

Removes the client from all chunks it is present in.

Definition at line 895 of file ChunkMap.cpp.

◆ RemoveEntity()

OwnedEntity cChunkMap::RemoveEntity ( cEntity a_Entity)

Removes the entity from its appropriate chunk Returns an owning reference to the found entity.

Definition at line 964 of file ChunkMap.cpp.

◆ ReplaceTreeBlocks()

void cChunkMap::ReplaceTreeBlocks ( const sSetBlockVector a_Blocks)

Special function used for growing trees, replaces only blocks that tree may overwrite.

Definition at line 625 of file ChunkMap.cpp.

◆ SaveAllChunks()

void cChunkMap::SaveAllChunks ( void  ) const

Definition at line 1414 of file ChunkMap.cpp.

◆ SendBlockEntity()

void cChunkMap::SendBlockEntity ( int  a_BlockX,
int  a_BlockY,
int  a_BlockZ,
cClientHandle a_Client 
)

Sends the block entity, if it is at the coords specified, to a_Client.

Definition at line 93 of file ChunkMap.cpp.

◆ SendBlockTo()

void cChunkMap::SendBlockTo ( int  a_BlockX,
int  a_BlockY,
int  a_BlockZ,
const cPlayer a_Player 
)

Sends the block at the specified coords to the specified player.

Uses a blockchange packet to send the block. If the relevant chunk isn't loaded, doesn't do anything.

Definition at line 805 of file ChunkMap.cpp.

◆ SetAreaBiome()

bool cChunkMap::SetAreaBiome ( int  a_MinX,
int  a_MaxX,
int  a_MinZ,
int  a_MaxZ,
EMCSBiome  a_Biome 
)

Sets the biome at the area.

Returns true if successful, false if any subarea failed (chunk not loaded). (Re)sends the chunks to their relevant clients if successful.

Definition at line 697 of file ChunkMap.cpp.

◆ SetBiomeAt()

bool cChunkMap::SetBiomeAt ( int  a_BlockX,
int  a_BlockZ,
EMCSBiome  a_Biome 
)

Sets the biome at the specified coords.

Returns true if successful, false if not (chunk not loaded). Doesn't resend the chunk to clients.

Definition at line 678 of file ChunkMap.cpp.

◆ SetBlock()

void cChunkMap::SetBlock ( Vector3i  a_BlockPos,
BLOCKTYPE  a_BlockType,
NIBBLETYPE  a_BlockMeta 
)

Definition at line 569 of file ChunkMap.cpp.

◆ SetBlockMeta()

void cChunkMap::SetBlockMeta ( Vector3i  a_BlockPos,
NIBBLETYPE  a_BlockMeta 
)

Sets the meta for the specified block, while keeping the blocktype.

Ignored if the chunk is invalid.

Definition at line 551 of file ChunkMap.cpp.

◆ SetChunkAlwaysTicked()

void cChunkMap::SetChunkAlwaysTicked ( int  a_ChunkX,
int  a_ChunkZ,
bool  a_AlwaysTicked 
)

Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter for the specified chunk.

If the m_AlwaysTicked counter is greater than zero, the chunk is ticked in the tick-thread regardless of whether it has any clients or not. This function allows nesting and task-concurrency (multiple separate tasks can request ticking and as long as at least one requests is active the chunk will be ticked).

Definition at line 1467 of file ChunkMap.cpp.

◆ SetChunkData()

void cChunkMap::SetChunkData ( SetChunkData &&  a_SetChunkData)

Sets the chunk data as either loaded from the storage or generated.

BlockLight and BlockSkyLight are optional, if not present, chunk will be marked as unlighted. If MarkDirty is set, the chunk is set as dirty (used after generating) Modifies the BlockEntity list in a_SetChunkData - moves the block entities into the chunk.

Definition at line 215 of file ChunkMap.cpp.

◆ SetNextBlockToTick()

void cChunkMap::SetNextBlockToTick ( const Vector3i  a_BlockPos)

Causes the specified block to be ticked on the next Tick() call.

Plugins can use this via the cWorld:SetNextBlockToTick() API. Only one block coord per chunk may be set, a second call overwrites the first call

Definition at line 1290 of file ChunkMap.cpp.

◆ SpawnMobs()

void cChunkMap::SpawnMobs ( cMobSpawner a_MobSpawner)

Try to Spawn Monsters inside all Chunks.

Definition at line 1326 of file ChunkMap.cpp.

◆ Tick()

void cChunkMap::Tick ( std::chrono::milliseconds  a_Dt)

Definition at line 1343 of file ChunkMap.cpp.

◆ TickBlock()

void cChunkMap::TickBlock ( const Vector3i  a_BlockPos)

Ticks a single block.

Used by cWorld::TickQueuedBlocks() to tick the queued blocks

Definition at line 1367 of file ChunkMap.cpp.

◆ TrackInDeadlockDetect()

void cChunkMap::TrackInDeadlockDetect ( cDeadlockDetect a_DeadlockDetect,
const AString a_WorldName 
)

Adds this chunkmap's CS to the DeadlockDetect's tracked CSs.

Definition at line 1477 of file ChunkMap.cpp.

◆ TryGetHeight()

bool cChunkMap::TryGetHeight ( int  a_BlockX,
int  a_BlockZ,
int &  a_Height 
)

Definition at line 406 of file ChunkMap.cpp.

◆ UnloadUnusedChunks()

void cChunkMap::UnloadUnusedChunks ( void  )

Definition at line 1384 of file ChunkMap.cpp.

◆ UntrackInDeadlockDetect()

void cChunkMap::UntrackInDeadlockDetect ( cDeadlockDetect a_DeadlockDetect)

Removes this chunkmap's CS from the DeadlockDetect's tracked CSs.

Definition at line 1486 of file ChunkMap.cpp.

◆ UseBlockEntity()

bool cChunkMap::UseBlockEntity ( cPlayer a_Player,
int  a_X,
int  a_Y,
int  a_Z 
)

a_Player rclked block entity at the coords specified, handle it returns true if the use was successful, return false to use the block as a "normal" block

Definition at line 110 of file ChunkMap.cpp.

◆ WakeUpSimulators() [1/2]

void cChunkMap::WakeUpSimulators ( int  a_BlockX,
int  a_BlockY,
int  a_BlockZ 
)
inline

Definition at line 60 of file ChunkMap.h.

◆ WakeUpSimulators() [2/2]

void cChunkMap::WakeUpSimulators ( Vector3i  a_Block)

Wakes up simulators for the specified block.

Definition at line 153 of file ChunkMap.cpp.

◆ WriteBlockArea()

bool cChunkMap::WriteBlockArea ( cBlockArea a_Area,
int  a_MinBlockX,
int  a_MinBlockY,
int  a_MinBlockZ,
int  a_DataTypes 
)

Writes the block area into the specified coords.

Returns true if all chunks have been processed. Prefer cBlockArea::Write() instead.

Definition at line 1216 of file ChunkMap.cpp.

Friends And Related Function Documentation

◆ cChunk

friend class cChunk
friend

Definition at line 290 of file ChunkMap.h.

◆ cChunkStay

friend class cChunkStay
friend

Definition at line 293 of file ChunkMap.h.

Member Data Documentation

◆ m_Chunks

std::map<cChunkCoords, cChunk> cChunkMap::m_Chunks
private

A map of chunk coordinates to chunks.

Uses a map (as opposed to unordered_map) because sorted maps are apparently faster.

Definition at line 301 of file ChunkMap.h.

◆ m_ChunkStays

cChunkStays cChunkMap::m_ChunkStays
private

The cChunkStay descendants that are currently enabled in this chunkmap.

Definition at line 308 of file ChunkMap.h.

◆ m_CSChunks

cCriticalSection cChunkMap::m_CSChunks
mutableprivate

Definition at line 297 of file ChunkMap.h.

◆ m_evtChunkValid

cEvent cChunkMap::m_evtChunkValid
private

Definition at line 303 of file ChunkMap.h.

◆ m_World

cWorld* cChunkMap::m_World
private

Definition at line 305 of file ChunkMap.h.


The documentation for this class was generated from the following files: