21 class cChunkDataCallback;
32 #define PREPARE_REL_AND_CHUNK(Position, OriginalChunk) cChunk * Chunk; Vector3i Rel; bool RelSuccess = (OriginalChunk).GetChunkAndRelByAbsolute(Position, &Chunk, Rel)
48 int a_ChunkX,
int a_ChunkZ,
100 void GetAllData(cChunkDataCallback & a_Callback)
const;
118 void Stay(
bool a_Stay =
true);
126 void Tick(std::chrono::milliseconds a_Dt);
143 FastSetBlock(a_RelPos.
x, a_RelPos.
y, a_RelPos.
z, a_BlockType, a_BlockMeta);
262 void PositionToWorldPosition(
int a_RelX,
int a_RelY,
int a_RelZ,
int & a_BlockX,
int & a_BlockY,
int & a_BlockZ);
288 SetMeta({ a_RelX, a_RelY, a_RelZ }, a_Meta);
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
unsigned char BLOCKTYPE
The datatype used by blockdata.
cCoordWithIntList cFireSimulatorChunkData
Stores individual fire blocks in the chunk; the int data is used as the time [msec] the fire takes to...
cCoordWithIntList cSandSimulatorChunkData
Per-chunk data for the simulator, specified individual chunks to simulate; Data is not used.
Represents two sets of coords, minimum and maximum for each direction.
bool GetChunkAndRelByAbsolute(const Vector3d &a_Position, cChunk **a_Chunk, Vector3i &a_Rel)
Convert absolute coordinates into relative coordinates.
cFireSimulatorChunkData & GetFireSimulatorData(void)
void AddBlockEntity(OwnedBlockEntity a_BlockEntity)
Takes ownership of a block entity, which MUST actually reside in this chunk.
NIBBLETYPE GetBlockLight(Vector3i a_RelPos) const
Get the level of artificial light illuminating the block (0 - 15)
void GetAllData(cChunkDataCallback &a_Callback) const
Gets all chunk data, calls the a_Callback's methods for each data type.
ePresence m_Presence
Holds the presence status of the chunk - if it is present, or in the loader / generator queue,...
void TickBlocks(void)
Ticks several random blocks in the chunk.
std::vector< OwnedEntity > m_Entities
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
bool ShouldBeTicked(void) const
Returns true if the chunk should be ticked in the tick-thread.
std::vector< cBlockEntity * > m_PendingSendBlockEntities
Block entities that have been touched and need to be sent to all clients.
void CheckBlocks()
Checks the block scheduled for checking in m_ToTickBlocks[].
EMCSBiome GetBiomeAt(int a_RelX, int a_RelZ) const
void SpawnMobs(cMobSpawner &a_MobSpawner)
Try to Spawn Monsters inside chunk.
void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle &a_Client)
unsigned m_AlwaysTicked
If greater than zero, the chunk is ticked even if it has no clients.
bool IsSlimeChunk() const
Returns true if slimes should spawn in the chunk.
bool UnboundedRelGetBlockMeta(Vector3i a_RelPos, NIBBLETYPE &a_BlockMeta) const
Same as GetBlockMeta(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap...
int GrowPlantAt(Vector3i a_RelPos, int a_NumStages=1)
Grows the plant at the specified position by at most a_NumStages.
bool UseBlockEntity(cPlayer *a_Player, int a_X, int a_Y, int a_Z)
Use block entity on coordinate.
void SetAllData(SetChunkData &&a_SetChunkData)
Sets all chunk data as either loaded from the storage or generated.
bool 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 en...
void SetLight(const cChunkDef::BlockNibbles &a_BlockLight, const cChunkDef::BlockNibbles &a_SkyLight)
cFluidSimulatorData * GetLavaSimulatorData(void) const
BLOCKTYPE GetBlock(Vector3i a_RelCoords) const
bool ForEachEntity(cEntityCallback a_Callback) const
Calls the callback for each entity; returns true if all entities processed, false if the callback abo...
ChunkLightData m_LightData
bool UnboundedRelGetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_BlockMeta) const
OBSOLETE, use the Vector3i-based overload.
void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
void MarkRegenerating(void)
Marks all clients attached to this chunk as wanting this chunk.
void WriteBlockArea(cBlockArea &a_Area, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
Writes the specified cBlockArea at the coords specified.
NIBBLETYPE GetMeta(Vector3i a_RelPos) const
void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
void AddEntity(OwnedEntity a_Entity)
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
void GetThreeRandomNumbers(int &a_X, int &a_Y, int &a_Z, int a_MaxX, int a_MaxY, int a_MaxZ)
NIBBLETYPE GetSkyLight(Vector3i a_RelPos) const
Get the level of sky light illuminating the block (0 - 15) independent of daytime.
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
cChunkCoords GetPos() const
bool HasClient(cClientHandle *a_Client)
Returns true if the specified client is present in this chunk.
int GetHeight(int a_X, int a_Z) const
cBlockEntity * GetBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ)
OBSOLETE, use the Vector3i-based overload instead.
void WakeUpSimulators(void)
Wakes up each simulator for its specific blocks; through all the blocks in the chunk.
void GetRandomBlockCoords(int &a_X, int &a_Y, int &a_Z)
bool IsWeatherSunnyAt(int a_RelX, int a_RelZ) const
Returns true if it is sunny at the specified location.
NIBBLETYPE GetTimeAlteredLight(NIBBLETYPE a_Skylight) const
Light alterations based on time.
void SetBlock(Vector3i a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
bool ForEachEntityInBox(const cBoundingBox &a_Box, cEntityCallback a_Callback) const
Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
bool CanUnload(void) const
cBlockEntity * GetBlockEntity(Vector3i a_AbsPos)
Returns the block entity at the specified (absolute) coords.
void SetPresence(ePresence a_Presence)
Sets the chunk's presence.
bool UnboundedRelGetBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_SkyLight) const
OBSOLETE, use the Vector3i-based overload.
bool IsLightValid(void) const
bool UnboundedRelSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
OBSOLETE, use the Vector3i-based overload.
void SetBiomeAt(int a_RelX, int a_RelZ, EMCSBiome a_Biome)
Sets the biome at the specified relative coords.
bool UnboundedRelSetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Same as SetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in ...
void MarkLoadFailed(void)
Queues the chunk for generating.
NIBBLETYPE GetSkyLightAltered(Vector3i a_RelPos) const
Get the level of sky light illuminating the block (0 - 15), taking daytime into a account.
std::vector< sSetBlockQueueItem > sSetBlockQueueVector
bool AddClient(cClientHandle *a_Client)
Adds a client to the chunk; returns true if added, false if already there.
bool UnboundedRelGetBlockSkyLight(Vector3i a_RelPos, NIBBLETYPE &a_SkyLight) const
Same as GetBlockSkyLight(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_Chun...
bool UnboundedRelGetBlockBlockLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_BlockLight) const
OBSOLETE, use the Vector3i-based overload.
cChunk * GetRelNeighborChunk(int a_RelX, int a_RelZ)
Returns the chunk into which the relatively-specified block belongs, by walking the neighbors.
void ApplyWeatherToTop(void)
Adds snow to the top of snowy biomes and hydrates farmland / fills cauldrons in rainy biomes.
bool UnboundedRelFastSetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Same as FastSetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap...
bool UnboundedRelGetBlockLights(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_BlockLight, NIBBLETYPE &a_SkyLight) const
OBSOLETE, use the Vector3i-based overload.
cFluidSimulatorData * m_WaterSimulatorData
ePresence
Represents the presence state of the chunk.
@ cpQueued
The chunk is not present, but is queued for loading / generation.
@ cpPresent
The chunk is present.
@ cpInvalid
The chunk is not present at all and is not queued in the loader / generator.
cFireSimulatorChunkData m_FireSimulatorData
NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const
void Stay(bool a_Stay=true)
Sets or resets the internal flag that prevents chunk from being unloaded.
void SetNextBlockToTick(const Vector3i a_RelPos)
Causes the specified block to be ticked on the next Tick() call.
void SendBlockTo(int a_RelX, int a_RelY, int a_RelZ, cClientHandle *a_Client)
cItems PickupsFromBlock(Vector3i a_RelPos, const cEntity *a_Digger, const cItem *a_Tool)
Returns the pickups that would be produced, if the specified block was dug up by a_Digger using a_Too...
NIBBLETYPE GetSkyLightAltered(int a_RelX, int a_RelY, int a_RelZ) const
NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const
bool CanUnloadAfterSaving(void) const
Returns true if the chunk could have been unloaded if it weren't dirty.
cChunk * GetNeighborChunk(int a_BlockX, int a_BlockZ)
Returns the chunk into which the specified block belongs, by walking the neighbors.
cChunkDef::HeightMap m_HeightMap
void TickBlock(const Vector3i a_RelPos)
Ticks a single block.
bool UnboundedRelGetBlock(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in ...
void FastSetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta)
bool IsQueued(void) const
Returns true iff the chunk is in the queue for loading / generating.
ChunkBlockData m_BlockData
cFluidSimulatorData * m_LavaSimulatorData
bool IsWeatherWetAt(int a_RelX, int a_RelZ) const
Returns true if it is raining or storming at the specified location, taking into account biomes.
const auto & GetAllClients(void) const
bool IsDirty(void) const
Returns true iff the chunk has changed since it was last saved.
bool IsValid(void) const
Returns true iff the chunk block data is valid (loaded / generated)
bool UnboundedRelGetBlockBlockLight(Vector3i a_RelPos, NIBBLETYPE &a_BlockLight) const
Same as GetBlockBlockLight(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_Ch...
cWorld * GetWorld(void) const
cSandSimulatorChunkData & GetSandSimulatorData(void)
cBlockEntity * GetBlockEntityRel(Vector3i a_RelPos)
Returns the block entity at the specified (relative) coords.
void GetBlockInfo(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_Meta, NIBBLETYPE &a_SkyLight, NIBBLETYPE &a_BlockLight) const
std::vector< cClientHandle * > m_LoadedByClient
void CollectMobCensus(cMobCensus &toFill)
Recence all mobs proximities to players in order to know what to do with them.
std::queue< Vector3i > m_BlocksToCheck
A queue of relative positions to call cBlockHandler::Check on.
cBlockEntities m_BlockEntities
bool UnboundedRelFastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
OBSOLETE, use the Vector3i-based overload.
bool UnboundedRelGetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType) const
OBSOLETE, use the Vector3i-based overload.
void MoveEntityToNewChunk(OwnedEntity a_Entity)
Called by Tick() when an entity moves out of this chunk into a neighbor; moves the entity and sends s...
cChunk(int a_ChunkX, int a_ChunkZ, cChunkMap *a_ChunkMap, cWorld *a_World)
void OnUnload()
Called when the chunkmap unloads unused chunks.
cSandSimulatorChunkData m_SandSimulatorData
bool ForEachBlockEntity(cBlockEntityCallback a_Callback)
Calls the callback for each block entity; returns true if all block entities processed,...
cFluidSimulatorData * GetWaterSimulatorData(void) const
bool UnboundedRelGetBlockLights(Vector3i a_RelPos, NIBBLETYPE &a_BlockLight, NIBBLETYPE &a_SkyLight) const
Queries both BlockLight and SkyLight, relative coords needn't be in this chunk (uses m_Neighbor-s or ...
cRedstoneSimulatorChunkData * GetRedstoneSimulatorData(void) const
unsigned m_StayCount
Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero,...
Vector3i m_BlockToTick
Relative coords of the block to tick first in the next Tick() call.
bool UnboundedRelGetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
OBSOLETE, use the Vector3i-based overload.
void SetMeta(Vector3i a_RelPos, NIBBLETYPE a_Meta)
void BroadcastPendingChanges(void)
Flushes the pending block (entity) queue, and clients' outgoing data buffers.
void Tick(std::chrono::milliseconds a_Dt)
cChunkDef::BiomeMap m_BiomeMap
sSetBlockVector m_PendingSendBlocks
Blocks that have changed and need to be sent to all clients.
cRedstoneSimulatorChunkData * m_RedstoneSimulatorData
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.
bool UnboundedRelGetBlockType(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType) const
Same as GetBlockType(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap...
void SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_MaxRelZ, EMCSBiome a_Biome)
Sets the biome in the specified relative coords area.
cChunk(const cChunk &Other)=delete
bool HasAnyClients(void) const
Returns true if theres any client in the chunk; false otherwise.
bool HasEntity(UInt32 a_EntityID) const
Vector3i PositionToWorldPosition(Vector3i a_RelPos)
bool HasPlayerEntities() const
Check m_Entities for cPlayer objects.
void GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
bool DoWithEntityByID(UInt32 a_EntityID, cEntityCallback a_Callback, bool &a_CallbackResult) const
Calls the callback if the entity with the specified ID is found, with the entity object as the callba...
void RemoveClient(cClientHandle *a_Client)
Removes the specified client from the chunk; ignored if client not in chunk.
sSetBlockQueueItem(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType)
NIBBLETYPE GetMeta(Vector3i a_Position) const
void SetMeta(Vector3i a_Position, NIBBLETYPE a_Meta)
BLOCKTYPE GetBlock(Vector3i a_Position) const
NIBBLETYPE GetSkyLight(Vector3i a_Position) const
NIBBLETYPE GetBlockLight(Vector3i a_Position) const
Wraps the chunk coords into a single structure.
static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords)
Converts relative block coordinates into absolute coordinates with a known chunk location.
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
This class bridges a vector of cItem for safe access via Lua.
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 ...
Contains the data for a loaded / generated chunk, ready to be set into a cWorld.
This is a base class for all fluid simulator data classes.
std::unordered_map< size_t, OwnedBlockEntity > cBlockEntities
std::unique_ptr< cBlockEntity > OwnedBlockEntity