43 { a_ChunkX, a_ChunkZ },
44 a_ChunkX, a_ChunkZ,
this,
m_World
57 if (!Chunk.IsValid() && !Chunk.IsQueued())
73 const auto Chunk =
m_Chunks.find({ a_ChunkX, a_ChunkZ });
74 return (Chunk ==
m_Chunks.end()) ? nullptr : &Chunk->second;
85 const auto Chunk =
m_Chunks.find({ a_ChunkX, a_ChunkZ });
86 return (Chunk ==
m_Chunks.end()) ? nullptr : &Chunk->second;
98 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
99 if ((Chunk ==
nullptr) || !Chunk->IsValid())
103 Chunk->SendBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Client);
116 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
117 if ((Chunk ==
nullptr) || !Chunk->IsValid())
121 return Chunk->UseBlockEntity(a_Player, a_BlockX, a_BlockY, a_BlockZ);
131 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
132 if ((Chunk ==
nullptr) || !Chunk->IsValid())
136 return a_Callback(*Chunk);
146 return DoWithChunk(Position.m_ChunkX, Position.m_ChunkZ, a_Callback);
157 const auto Chunk =
FindChunk(Position.m_ChunkX, Position.m_ChunkZ);
158 if ((Chunk ==
nullptr) || !Chunk->IsValid())
173 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
174 if ((Chunk ==
nullptr) || !Chunk->IsValid())
188 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
189 if ((Chunk ==
nullptr) || !Chunk->IsValid())
203 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
204 if ((Chunk ==
nullptr) || !Chunk->IsValid())
217 const int ChunkX = a_SetChunkData.Chunk.m_ChunkX;
218 const int ChunkZ = a_SetChunkData.Chunk.m_ChunkZ;
221 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
223 Chunk->SetAllData(std::move(a_SetChunkData));
229 if ((*itr)->ChunkAvailable(ChunkX, ChunkZ))
232 ToBeDisabled.push_back(*itr);
237 for (cChunkStays::iterator itr = ToBeDisabled.begin(), end = ToBeDisabled.end(); itr != end; ++itr)
252 int a_ChunkX,
int a_ChunkZ,
258 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
259 if (Chunk ==
nullptr)
264 Chunk->SetLight(a_BlockLight, a_SkyLight);
280 if ((Chunk ==
nullptr) || !Chunk->IsValid())
285 Chunk->GetAllData(a_Callback);
296 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
297 return (Chunk !=
nullptr) && Chunk->IsQueued();
306 int ChunkX, ChunkZ, BlockY = 0;
310 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
311 if ((Chunk ==
nullptr) || !Chunk->IsValid())
316 return Chunk->IsWeatherSunnyAt(a_BlockX, a_BlockZ);
325 int ChunkX, ChunkZ, BlockY = 0;
329 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
330 if ((Chunk ==
nullptr) || !Chunk->IsValid())
335 return Chunk->IsWeatherWetAt(a_BlockX, a_BlockZ);
348 const auto Chunk =
FindChunk(ChunkPosition.m_ChunkX, ChunkPosition.m_ChunkZ);
349 if ((Chunk ==
nullptr) || !Chunk->IsValid())
354 return Chunk->IsWeatherWetAt(Position);
364 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
365 return (Chunk !=
nullptr) && Chunk->IsValid();
375 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
376 return (Chunk !=
nullptr) && Chunk->HasAnyClients();
388 int ChunkX, ChunkZ, BlockY = 0;
390 auto & Chunk =
GetChunk(ChunkX, ChunkZ);
393 return Chunk.GetHeight(a_BlockX, a_BlockZ);
410 int ChunkX, ChunkZ, BlockY = 0;
412 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
413 if ((Chunk ==
nullptr) || !Chunk->IsValid())
417 a_Height = Chunk->GetHeight(a_BlockX, a_BlockZ);
431 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
432 if ((Chunk !=
nullptr) && Chunk->IsValid())
434 Chunk->FastSetBlock(relPos, a_BlockType, a_BlockMeta);
447 BoundingBox.
Expand(1, 0.5, 1);
459 static_cast<cPickup &>(Entity).CollectedBy(a_Entity);
463 static_cast<cProjectileEntity &>(Entity).CollectedBy(static_cast<cPlayer&>(a_Entity));
482 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
483 if ((Chunk !=
nullptr) && Chunk->IsValid())
485 return Chunk->GetBlock(relPos);
501 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
502 if ((Chunk !=
nullptr) && Chunk->IsValid())
504 return Chunk->GetMeta(relPos);
520 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
521 if ((Chunk !=
nullptr) && Chunk->IsValid())
523 return Chunk->GetSkyLight(relPos);
539 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
540 if ((Chunk !=
nullptr) && Chunk->IsValid())
542 return Chunk->GetBlockLight(relPos);
558 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
559 if ((Chunk !=
nullptr) && Chunk->IsValid())
561 Chunk->SetMeta(relPos, a_BlockMeta);
575 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
576 if ((Chunk !=
nullptr) && Chunk->IsValid())
578 Chunk->SetBlock(relPos, a_BlockType, a_BlockMeta);
592 const auto Chunk =
FindChunk(chunkCoord.m_ChunkX, chunkCoord.m_ChunkZ);
593 if ((Chunk !=
nullptr) && Chunk->IsValid())
595 Chunk->GetBlockTypeMeta(relPos, a_BlockType, a_BlockMeta);
612 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
613 if ((Chunk !=
nullptr) && Chunk->IsValid())
615 Chunk->GetBlockInfo(relPos, a_BlockType, a_Meta, a_SkyLight, a_BlockLight);
628 for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
630 const auto Chunk =
FindChunk(itr->m_ChunkX, itr->m_ChunkZ);
631 if ((Chunk ==
nullptr) || !Chunk->IsValid())
635 Vector3i relPos(itr->m_RelX, itr->m_RelY, itr->m_RelZ);
636 switch (Chunk->GetBlock(relPos))
640 Chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta);
648 Chunk->SetBlock(relPos, itr->m_BlockType, itr->m_BlockMeta);
662 int ChunkX, ChunkZ, X = a_BlockX, Y = 0, Z = a_BlockZ;
666 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
667 if ((Chunk !=
nullptr) && Chunk->IsValid())
669 return Chunk->GetBiomeAt(X, Z);
680 int ChunkX, ChunkZ, X = a_BlockX, Y = 0, Z = a_BlockZ;
684 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
685 if ((Chunk !=
nullptr) && Chunk->IsValid())
687 Chunk->SetBiomeAt(X, Z, a_Biome);
701 int MinChunkX, MinChunkZ, MinX = a_MinX, MinZ = a_MinZ;
702 int MaxChunkX, MaxChunkZ, MaxX = a_MaxX, MaxZ = a_MaxZ;
709 for (
int x = MinChunkX; x <= MaxChunkX; x++)
711 int MinRelX = (x == MinChunkX) ? MinX : 0;
713 for (
int z = MinChunkZ; z <= MaxChunkZ; z++)
715 int MinRelZ = (z == MinChunkZ) ? MinZ : 0;
718 if ((Chunk !=
nullptr) && Chunk->IsValid())
720 Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome);
739 for (sSetBlockVector::iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
741 const auto Chunk =
FindChunk(itr->m_ChunkX, itr->m_ChunkZ);
742 if ((Chunk ==
nullptr) || !Chunk->IsValid())
744 if (!a_ContinueOnFailure)
755 itr->m_BlockType = Chunk->GetBlock(itr->m_RelX, itr->m_RelY, itr->m_RelZ);
756 itr->m_BlockMeta = Chunk->GetMeta(itr->m_RelX, itr->m_RelY, itr->m_RelZ);
772 const auto Chunk =
FindChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ);
773 if ((Chunk ==
nullptr) || !Chunk->IsValid())
793 const auto Chunk =
FindChunk(chunkCoords.m_ChunkX, chunkCoords.m_ChunkZ);
794 if ((Chunk ==
nullptr) || !Chunk->IsValid())
798 return Chunk->PickupsFromBlock(relPos, a_Digger, a_Tool);
811 const auto Chunk =
FindChunk(ChunkX, ChunkZ);
812 if ((Chunk !=
nullptr) && (Chunk->IsValid()))
825 const auto Chunk1 =
FindChunk(a_ChunkX1, a_ChunkZ1);
826 if (Chunk1 ==
nullptr)
830 const auto Chunk2 =
FindChunk(a_ChunkX2, a_ChunkZ2);
831 if (Chunk2 ==
nullptr)
849 for (
auto * Client : Clients1)
851 bool Found = (std::find(Clients2.begin(), Clients2.end(), Client) != Clients2.end());
859 for (
auto * Client : Clients2)
861 bool Found = (std::find(Clients1.begin(), Clients1.end(), Client) != Clients1.end());
864 a_Callback.
Added(Client);
886 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
888 Chunk->RemoveClient(a_Client);
900 Chunk.second.RemoveClient(a_Client);
911 if (
FindChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ()) ==
nullptr)
913 LOGWARNING(
"%s: Entity at %p (%s, ID %d) spawning in a non-existent chunk.",
914 __FUNCTION__,
static_cast<void *
>(a_Entity.get()), a_Entity->GetClass(), a_Entity->GetUniqueID()
918 const auto EntityPtr = a_Entity.get();
921 auto & Chunk =
ConstructChunk(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
922 Chunk.AddEntity(std::move(a_Entity));
924 EntityPtr->OnAddToWorld(*
m_World);
925 ASSERT(!EntityPtr->IsTicking());
926 EntityPtr->SetIsTicking(
true);
938 auto & Chunk =
ConstructChunk(a_Player->GetChunkX(), a_Player->GetChunkZ());
939 ASSERT(!Chunk.HasEntity(a_Player->GetUniqueID()));
940 Chunk.AddEntity(std::move(a_Player));
952 if (Chunk.second.IsValid() && Chunk.second.HasEntity(a_UniqueID))
969 if (Chunk ==
nullptr)
987 if (Chunk.second.IsValid() && !Chunk.second.ForEachEntity(a_Callback))
1002 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
1003 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1007 return Chunk->ForEachEntity(a_Callback);
1024 for (
int z = MinChunkZ; z <= MaxChunkZ; z++)
1026 for (
int x = MinChunkX; x <= MaxChunkX; x++)
1029 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1033 if (!Chunk->ForEachEntityInBox(a_Box, a_Callback))
1050 for (
const auto & Chunk :
m_Chunks)
1052 if (Chunk.second.IsValid() && Chunk.second.DoWithEntityByID(a_UniqueID, a_Callback, res))
1067 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
1068 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1072 return Chunk->ForEachBlockEntity(a_Callback);
1084 const auto Chunk =
FindChunk(ChunkPosition.m_ChunkX, ChunkPosition.m_ChunkZ);
1085 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1089 return Chunk->DoWithBlockEntityAt(Relative, a_Callback);
1099 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
1102 if ((Chunk ==
nullptr) || !Chunk->IsValid() || !Chunk->IsLightValid())
1109 if (a_Callback !=
nullptr)
1111 a_Callback->Call({a_ChunkX, a_ChunkZ},
true);
1132 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
1133 ASSERT(Chunk !=
nullptr);
1134 Chunk->MarkLoadFailed();
1154 const auto Chunk =
FindChunk(a_ChunkX, a_ChunkZ);
1155 if (Chunk ==
nullptr)
1160 return Chunk->IsLightValid();
1171 for (
int z = a_MinChunkZ; z <= a_MaxChunkZ; z++)
1173 for (
int x = a_MinChunkX; x <= a_MaxChunkX; x++)
1176 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1182 if (!a_Callback.Coords(x, z))
1186 Chunk->GetAllData(a_Callback);
1199 for (
const auto & Chunk :
m_Chunks)
1201 if (Chunk.second.IsValid())
1203 if (a_Callback(Chunk.first.m_ChunkX, Chunk.first.m_ChunkZ))
1219 int MinChunkX, MaxChunkX;
1220 int MinChunkZ, MaxChunkZ;
1221 int MinBlockX = a_MinBlockX;
1222 int MinBlockY = a_MinBlockY;
1223 int MinBlockZ = a_MinBlockZ;
1224 int MaxBlockX = a_MinBlockX + a_Area.
GetSizeX();
1225 int MaxBlockY = a_MinBlockY + a_Area.
GetSizeY();
1226 int MaxBlockZ = a_MinBlockZ + a_Area.
GetSizeZ();
1233 for (
int z = MinChunkZ; z <= MaxChunkZ; z++)
1235 for (
int x = MinChunkX; x <= MaxChunkX; x++)
1238 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1244 Chunk->WriteBlockArea(a_Area, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
1256 a_NumChunksValid = 0;
1257 a_NumChunksDirty = 0;
1259 for (
const auto & Chunk :
m_Chunks)
1262 if (Chunk.second.IsDirty())
1278 const auto Chunk =
FindChunk(chunkPos.m_ChunkX, chunkPos.m_ChunkZ);
1279 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1283 return Chunk->GrowPlantAt(relPos, a_NumStages);
1296 const auto Chunk =
FindChunk(ChunkPos.m_ChunkX, ChunkPos.m_ChunkZ);
1297 if (Chunk !=
nullptr)
1299 Chunk->SetNextBlockToTick(RelPos);
1315 if (Chunk.second.IsValid() && Chunk.second.HasAnyClients())
1317 Chunk.second.CollectMobCensus(a_ToFill);
1332 if (Chunk.second.IsValid() && Chunk.second.HasAnyClients())
1334 Chunk.second.SpawnMobs(a_MobSpawner);
1350 if (Chunk.second.ShouldBeTicked())
1352 Chunk.second.Tick(a_Dt);
1359 Chunk.second.BroadcastPendingChanges();
1372 const auto Chunk =
FindChunk(ChunkPos.m_ChunkX, ChunkPos.m_ChunkZ);
1373 if ((Chunk ==
nullptr) || !Chunk->IsValid())
1377 Chunk->TickBlock(RelPos);
1390 itr->second.CanUnload() &&
1398 itr->second.OnUnload();
1417 for (
const auto & Chunk :
m_Chunks)
1419 if (Chunk.second.IsValid() && Chunk.second.IsDirty())
1444 for (
const auto & Chunk :
m_Chunks)
1446 if (Chunk.second.IsValid() && Chunk.second.CanUnloadAfterSaving())
1505 for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr)
1507 auto & Chunk =
GetChunk(itr->m_ChunkX, itr->m_ChunkZ);
1509 if (Chunk.IsValid())
1531 bool HasFound =
false;
1534 if (*itr == &a_ChunkStay)
1544 ASSERT(!
"Removing a cChunkStay that hasn't been added!");
1550 for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr)
1552 const auto Chunk =
FindChunk(itr->m_ChunkX, itr->m_ChunkZ);
1553 ASSERT(Chunk !=
nullptr);
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
std::vector< sSetBlock > sSetBlockVector
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
std::unique_ptr< cEntity > OwnedEntity
std::vector< cChunkCoords > cChunkCoordsVector
unsigned char BLOCKTYPE
The datatype used by blockdata.
#define CASE_TREE_OVERWRITTEN_BLOCKS
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
void LOGWARNING(std::string_view a_Format, const Args &... args)
bool CallHookSpawnedEntity(cWorld &a_World, cEntity &a_Entity)
bool CallHookChunkAvailable(cWorld &a_World, int a_ChunkX, int a_ChunkZ)
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
bool CallHookChunkUnloaded(cWorld &a_World, int a_ChunkX, int a_ChunkZ)
bool CallHookChunkUnloading(cWorld &a_World, int a_ChunkX, int a_ChunkZ)
Represents two sets of coords, minimum and maximum for each direction.
double GetMinZ(void) const
double GetMaxX(void) const
double GetMinX(void) const
void Expand(double a_ExpandX, double a_ExpandY, double a_ExpandZ)
Expands the bounding box by the specified amount in each direction (so the box becomes larger by 2 * ...
double GetMaxZ(void) const
void MarkRegenerating(void)
Marks all clients attached to this chunk as wanting this chunk.
bool AddClient(cClientHandle *a_Client)
Adds a client to the chunk; returns true if added, false if already there.
@ cpQueued
The chunk is not present, but is queued for loading / generation.
const auto & GetAllClients(void) const
OwnedEntity RemoveEntity(cEntity &a_Entity)
Releases ownership of the given entity if it was found in this chunk.
void SetAlwaysTicked(bool a_AlwaysTicked)
Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter.
Wraps the chunk coords into a single structure.
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
Interface class used for comparing clients of two chunks.
virtual void Removed(cClientHandle *a_Client)=0
Called for clients that are in Chunk1 and not in Chunk2,.
virtual void Added(cClientHandle *a_Client)=0
Called for clients that are in Chunk2 and not in Chunk1.
bool SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome)
Sets the biome at the specified coords.
bool ForEachLoadedChunk(cFunctionRef< bool(int, int)> a_Callback) const
Calls the callback for each loaded chunk.
BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
void UntrackInDeadlockDetect(cDeadlockDetect &a_DeadlockDetect)
Removes this chunkmap's CS from the DeadlockDetect's tracked CSs.
cChunk & GetChunk(int a_ChunkX, int a_ChunkZ)
Constructs a chunk and queues it for loading / generating if not valid, returning it.
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.
void SpawnMobs(cMobSpawner &a_MobSpawner)
Try to Spawn Monsters inside all Chunks.
bool SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMCSBiome a_Biome)
Sets the biome at the area.
void ChunkValidated(void)
void SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked)
Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter for the specifie...
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.
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'...
NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) const
NIBBLETYPE GetBlockSkyLight(Vector3i a_BlockPos) const
void MarkChunkSaving(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::Regener...
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...
void SaveAllChunks(void) const
bool IsChunkValid(int a_ChunkX, int a_ChunkZ) const
bool IsChunkLighted(int a_ChunkX, int a_ChunkZ)
std::map< cChunkCoords, cChunk > m_Chunks
A map of chunk coordinates to chunks.
void SetChunkData(SetChunkData &&a_SetChunkData)
Sets the chunk data as either loaded from the storage or generated.
void RemoveClientFromChunks(cClientHandle *a_Client)
Removes the client from all chunks it is present in.
void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
Marks the chunk as failed-to-load.
NIBBLETYPE GetBlockBlockLight(Vector3i a_BlockPos) const
void GenerateChunk(int a_ChunkX, int a_ChunkZ)
Queues the chunk for generating.
void GetChunkStats(int &a_NumChunksValid, int &a_NumChunksDirty) const
Returns the number of valid chunks and the number of dirty chunks.
void RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle *a_Client)
Removes the client from the chunk.
void AddChunkStay(cChunkStay &a_ChunkStay)
Adds a new cChunkStay descendant to the internal list of ChunkStays; loads its chunks.
void AddEntity(OwnedEntity a_Entity)
Adds the entity to its appropriate chunk, takes ownership of the entity pointer.
void SetNextBlockToTick(const Vector3i a_BlockPos)
Causes the specified block to be ticked on the next Tick() call.
void MarkChunkDirty(int a_ChunkX, int a_ChunkZ)
bool GetBlockInfo(Vector3i, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_Meta, NIBBLETYPE &a_SkyLight, NIBBLETYPE &a_BlockLight) const
cChunk * FindChunk(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.
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 successfu...
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_BlockMeta)
Sets the meta for the specified block, while keeping the blocktype.
void TickBlock(const Vector3i a_BlockPos)
Ticks a single block.
void ReplaceTreeBlocks(const sSetBlockVector &a_Blocks)
Special function used for growing trees, replaces only blocks that tree may overwrite.
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.
void FastSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
cWorld * GetWorld(void) const
bool ForEachEntity(cEntityCallback a_Callback) const
Calls the callback for each entity in the entire world; returns true if all entities processed,...
bool ForEachEntityInBox(const cBoundingBox &a_Box, cEntityCallback a_Callback)
Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
bool DoWithBlockEntityAt(Vector3i a_Position, cBlockEntityCallback a_Callback)
Calls the callback for the block entity at the specified coords.
void DelChunkStay(cChunkStay &a_ChunkStay)
Removes the specified cChunkStay descendant from the internal list of ChunkStays.
OwnedEntity RemoveEntity(cEntity &a_Entity)
Removes the entity from its appropriate chunk Returns an owning reference to the found entity.
void TrackInDeadlockDetect(cDeadlockDetect &a_DeadlockDetect, const AString &a_WorldName)
Adds this chunkmap's CS to the DeadlockDetect's tracked CSs.
void CollectPickupsByEntity(cEntity &a_Entity)
Makes the specified entity collect all the pickups around them.
bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) const
void MarkChunkSaved(int a_ChunkX, int a_ChunkZ)
void WakeUpSimulators(Vector3i a_Block)
Wakes up simulators for the specified block.
bool GetBlocks(sSetBlockVector &a_Blocks, bool a_ContinueOnFailure)
Retrieves block types and metas of the specified blocks.
bool IsChunkQueued(int a_ChunkX, int a_ChunkZ) const
Returns true iff the chunk is in the loader / generator queue.
bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback a_Callback)
Calls the callback for each block entity in the specified chunk.
bool HasEntity(UInt32 a_EntityID) const
Returns true if the entity with specified ID is present in the chunks.
bool DigBlock(Vector3i a_BlockPos)
Removes the block at the specified coords and wakes up simulators.
std::list< cChunkStay * > cChunkStays
bool TryGetHeight(int a_BlockX, int a_BlockZ, int &a_Height)
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.
void Tick(std::chrono::milliseconds a_Dt)
cChunkStays m_ChunkStays
The cChunkStay descendants that are currently enabled in this chunkmap.
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,...
EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ) const
Returns the biome at the specified coords.
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
void UnloadUnusedChunks(void)
int GrowPlantAt(Vector3i a_BlockPos, int a_NumStages=1)
Grows the plant at the specified position by at most a_NumStages.
int GetHeight(int a_BlockX, int a_BlockZ)
bool DoWithChunkAt(Vector3i a_BlockPos, cChunkCallback a_Callback)
Calls the callback for the chunk at the block position specified, with ChunkMapCS locked; returns fal...
void CollectMobCensus(cMobCensus &a_ToFill)
Make a Mob census, of all mobs, their family, their chunk and their distance to closest player.
cCriticalSection m_CSChunks
size_t GetNumChunks(void) const
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).
size_t GetNumUnusedDirtyChunks(void) const
Returns the number of unused dirty chunks.
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.
bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) const
cChunk & ConstructChunk(int a_ChunkX, int a_ChunkZ)
Returns or creates and returns a chunk pointer corresponding to the given chunk coordinates.
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 callba...
bool HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) const
void ChunkLighted(int a_ChunkX, int a_ChunkZ, const cChunkDef::BlockNibbles &a_BlockLight, const cChunkDef::BlockNibbles &a_SkyLight)
bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback &a_Callback) const
Calls the callback with the chunk's data, if available (with ChunkCS locked).
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.
void AddPlayer(std::unique_ptr< cPlayer > a_Player)
Adds the player to its appropriate chunk, takes ownership of the player pointer.
cChunkMap(cWorld *a_World)
Makes chunks stay loaded until this object is cleared or destroyed Works by setting internal flags in...
virtual void Disable(void)
Disables the ChunkStay, the chunks are released and the ChunkStay object can be edited with Add() and...
bool ChunkAvailable(int a_ChunkX, int a_ChunkZ)
Called by cChunkMap when a chunk is available, checks m_NumLoaded and triggers the appropriate callba...
virtual void OnDisabled(void)=0
Called by the ChunkMap when the ChunkStay is disabled.
const cChunkCoordsVector & GetChunks(void) const
Returns all the chunks that should be kept.
void UntrackCriticalSection(cCriticalSection &a_CS)
Removes the CS from the tracking.
void TrackCriticalSection(cCriticalSection &a_CS, const AString &a_Name)
Adds the critical section for tracking.
bool IsProjectile(void) const
bool IsPlayer(void) const
cBoundingBox GetBoundingBox() const
bool IsPickup(void) const
cChunk * GetParentChunk()
Returns the chunk responsible for ticking this entity.
cClientHandle * GetClientHandle(void) const
This class bridges a vector of cItem for safe access via Lua.
void QueueChunk(int a_ChunkX, int a_ChunkZ, std::unique_ptr< cChunkCoordCallback > a_CallbackAfter)
Queues the entire chunk for lighting.
This class is used to collect information, for each Mob, what is the distance of the closest player i...
This class is used to determine which monster can be spawned in which place it is essentially static ...
bool IsLockedByCurrentThread(void)
Returns true if the CS is currently locked by the thread calling this function.
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
Temporary RAII unlock for a cCSLock.
void Wait(void)
Waits until the event has been set.
void Set(void)
Sets the event - releases one thread that has been waiting in Wait().
Contains the data for a loaded / generated chunk, ready to be set into a cWorld.
void WakeUp(cChunk &a_Chunk, Vector3i a_Position)
bool IsWeatherSunny(void) const
Returns true if the current weather is sunny.
cLightingThread & GetLightingThread(void)
cWorldStorage & GetStorage(void)
bool IsWeatherWet(void) const
Returns true if the world currently has any precipitation - rain, storm or snow.
cSimulatorManager * GetSimulatorManager(void)
void QueueLoadChunk(int a_ChunkX, int a_ChunkZ)
Queues a chunk to be loaded, asynchronously.
void QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
Queues a chunk to be saved, asynchronously.