|
Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Go to the documentation of this file.
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);
cFluidSimulatorData * GetLavaSimulatorData(void) const
void GetRandomBlockCoords(int &a_X, int &a_Y, int &a_Z)
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...
void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta)
@ cpQueued
The chunk is not present, but is queued for loading / generation.
bool AddClient(cClientHandle *a_Client)
Adds a client to the chunk; returns true if added, false if already there.
std::vector< OwnedEntity > m_Entities
std::vector< sSetBlock > sSetBlockVector
bool UnboundedRelFastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
OBSOLETE, use the Vector3i-based overload.
bool ForEachEntity(cEntityCallback a_Callback) const
Calls the callback for each entity; returns true if all entities processed, false if the callback abo...
void AddEntity(OwnedEntity a_Entity)
void SetBiomeAt(int a_RelX, int a_RelZ, EMCSBiome a_Biome)
Sets the biome at the specified relative coords.
void BroadcastPendingChanges(void)
Flushes the pending block (entity) queue, and clients' outgoing data buffers.
NIBBLETYPE GetSkyLight(Vector3i a_Position) const
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.
cChunkDef::BiomeMap m_BiomeMap
bool GetChunkAndRelByAbsolute(const Vector3d &a_Position, cChunk **a_Chunk, Vector3i &a_Rel)
Convert absolute coordinates into relative coordinates.
bool UnboundedRelGetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_BlockMeta) const
OBSOLETE, use the Vector3i-based overload.
ePresence m_Presence
Holds the presence status of the chunk - if it is present, or in the loader / generator queue,...
bool UnboundedRelGetBlockLights(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_BlockLight, NIBBLETYPE &a_SkyLight) const
OBSOLETE, use the Vector3i-based overload.
bool CanUnloadAfterSaving(void) const
Returns true if the chunk could have been unloaded if it weren't dirty.
cFireSimulatorChunkData & GetFireSimulatorData(void)
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 ...
int GrowPlantAt(Vector3i a_RelPos, int a_NumStages=1)
Grows the plant at the specified position by at most a_NumStages.
std::vector< sSetBlockQueueItem > sSetBlockQueueVector
Represents two sets of coords, minimum and maximum for each direction.
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
cCoordWithIntList cFireSimulatorChunkData
Stores individual fire blocks in the chunk; the int data is used as the time [msec] the fire takes to...
std::unique_ptr< cEntity > OwnedEntity
void RemoveClient(cClientHandle *a_Client)
Removes the specified client from the chunk; ignored if client not in chunk.
bool UnboundedRelGetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType) const
OBSOLETE, use the Vector3i-based overload.
void Stay(bool a_Stay=true)
Sets or resets the internal flag that prevents chunk from being unloaded.
bool UnboundedRelGetBlockBlockLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_BlockLight) const
OBSOLETE, use the Vector3i-based overload.
cBlockEntity * GetBlockEntityRel(Vector3i a_RelPos)
Returns the block entity at the specified (relative) coords.
bool HasPlayerEntities() const
Check m_Entities for cPlayer objects.
cChunkCoords GetPos() const
This class is used to collect information, for each Mob, what is the distance of the closest player i...
void SetLight(const cChunkDef::BlockNibbles &a_BlockLight, const cChunkDef::BlockNibbles &a_SkyLight)
bool HasEntity(UInt32 a_EntityID) const
bool ForEachBlockEntity(cBlockEntityCallback a_Callback)
Calls the callback for each block entity; returns true if all block entities processed,...
bool HasClient(cClientHandle *a_Client)
Returns true if the specified client is present in this chunk.
cChunk(int a_ChunkX, int a_ChunkZ, cChunkMap *a_ChunkMap, cWorld *a_World)
void GetBlockInfo(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_Meta, NIBBLETYPE &a_SkyLight, NIBBLETYPE &a_BlockLight) const
std::queue< Vector3i > m_BlocksToCheck
A queue of relative positions to call cBlockHandler::Check on.
void SendBlockTo(int a_RelX, int a_RelY, int a_RelZ, cClientHandle *a_Client)
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...
void ApplyWeatherToTop(void)
Adds snow to the top of snowy biomes and hydrates farmland / fills cauldrons in rainy biomes.
bool UseBlockEntity(cPlayer *a_Player, int a_X, int a_Y, int a_Z)
Use block entity on coordinate.
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...
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...
std::vector< cBlockEntity * > m_PendingSendBlockEntities
Block entities that have been touched and need to be sent to all clients.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
cChunk * GetNeighborChunk(int a_BlockX, int a_BlockZ)
Returns the chunk into which the specified block belongs, by walking the neighbors.
NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const
ChunkLightData m_LightData
bool ShouldBeTicked(void) const
Returns true if the chunk should be ticked in the tick-thread.
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...
bool IsQueued(void) const
Returns true iff the chunk is in the queue for loading / generating.
@ cpInvalid
The chunk is not present at all and is not queued in the loader / generator.
NIBBLETYPE GetSkyLightAltered(Vector3i a_RelPos) const
Get the level of sky light illuminating the block (0 - 15), taking daytime into a account.
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 GetThreeRandomNumbers(int &a_X, int &a_Y, int &a_Z, int a_MaxX, int a_MaxY, int a_MaxZ)
void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
ePresence
Represents the presence state of the chunk.
NIBBLETYPE GetBlockLight(Vector3i a_Position) const
void WakeUpSimulators(void)
Wakes up each simulator for its specific blocks; through all the blocks in the chunk.
void OnUnload()
Called when the chunkmap unloads unused chunks.
unsigned m_AlwaysTicked
If greater than zero, the chunk is ticked even if it has no clients.
int GetHeight(int a_X, int a_Z) const
void MarkRegenerating(void)
Marks all clients attached to this chunk as wanting this chunk.
cFluidSimulatorData * GetWaterSimulatorData(void) const
void AddBlockEntity(OwnedBlockEntity a_BlockEntity)
Takes ownership of a block entity, which MUST actually reside in this chunk.
cCoordWithIntList cSandSimulatorChunkData
Per-chunk data for the simulator, specified individual chunks to simulate; Data is not used.
cRedstoneSimulatorChunkData * m_RedstoneSimulatorData
void SetMeta(Vector3i a_Position, NIBBLETYPE a_Meta)
cSandSimulatorChunkData & GetSandSimulatorData(void)
void CheckBlocks()
Checks the block scheduled for checking in m_ToTickBlocks[].
void SetAllData(SetChunkData &&a_SetChunkData)
Sets all chunk data as either loaded from the storage or generated.
BLOCKTYPE GetBlock(Vector3i a_Position) const
void SetBlock(Vector3i a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
BLOCKTYPE GetBlock(Vector3i a_RelCoords) 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 ...
NIBBLETYPE GetSkyLightAltered(int a_RelX, int a_RelY, int a_RelZ) const
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.
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...
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 GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
cRedstoneSimulatorChunkData * GetRedstoneSimulatorData(void) const
This is a base class for all fluid simulator data classes.
cFireSimulatorChunkData m_FireSimulatorData
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
cSandSimulatorChunkData m_SandSimulatorData
std::unique_ptr< cBlockEntity > OwnedBlockEntity
NIBBLETYPE GetTimeAlteredLight(NIBBLETYPE a_Skylight) const
Light alterations based on time.
std::unordered_map< size_t, OwnedBlockEntity > cBlockEntities
This class bridges a vector of cItem for safe access via Lua.
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
Vector3i PositionToWorldPosition(Vector3i a_RelPos)
unsigned char BLOCKTYPE
The datatype used by blockdata.
cFluidSimulatorData * m_WaterSimulatorData
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...
NIBBLETYPE GetBlockLight(Vector3i a_RelPos) const
Get the level of artificial light illuminating the block (0 - 15)
bool UnboundedRelGetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
OBSOLETE, use the Vector3i-based overload.
bool IsWeatherSunnyAt(int a_RelX, int a_RelZ) const
Returns true if it is sunny at the specified location.
std::vector< cClientHandle * > m_LoadedByClient
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...
cChunk * GetRelNeighborChunk(int a_RelX, int a_RelZ)
Returns the chunk into which the relatively-specified block belongs, by walking the neighbors.
NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const
ChunkBlockData m_BlockData
void MarkLoadFailed(void)
Queues the chunk for generating.
const auto & GetAllClients(void) const
bool HasAnyClients(void) const
Returns true if theres any client in the chunk; false otherwise.
bool CanUnload(void) const
void SetNextBlockToTick(const Vector3i a_RelPos)
Causes the specified block to be ticked on the next Tick() call.
sSetBlockQueueItem(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType)
bool UnboundedRelGetBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE &a_SkyLight) const
OBSOLETE, use the Vector3i-based overload.
sSetBlockVector m_PendingSendBlocks
Blocks that have changed and need to be sent to all clients.
NIBBLETYPE GetSkyLight(Vector3i a_RelPos) const
Get the level of sky light illuminating the block (0 - 15) independent of daytime.
void FastSetBlock(Vector3i a_RelPos, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
OwnedEntity RemoveEntity(cEntity &a_Entity)
Releases ownership of the given entity if it was found in this chunk.
cBlockEntities m_BlockEntities
This class is used to determine which monster can be spawned in which place it is essentially static ...
void SpawnMobs(cMobSpawner &a_MobSpawner)
Try to Spawn Monsters inside chunk.
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
Vector3i m_BlockToTick
Relative coords of the block to tick first in the next Tick() call.
NIBBLETYPE GetMeta(Vector3i a_Position) const
cChunkDef::HeightMap m_HeightMap
void SetPresence(ePresence a_Presence)
Sets the chunk's presence.
bool IsLightValid(void) const
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords)
Converts relative block coordinates into absolute coordinates with a known chunk location.
void TickBlocks(void)
Ticks several random blocks in the chunk.
@ cpPresent
The chunk is present.
EMCSBiome GetBiomeAt(int a_RelX, int a_RelZ) const
cBlockEntity * GetBlockEntity(Vector3i a_AbsPos)
Returns the block entity at the specified (absolute) coords.
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.
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
void SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle &a_Client)
NIBBLETYPE GetMeta(Vector3i a_RelPos) const
void GetAllData(cChunkDataCallback &a_Callback) const
Gets all chunk data, calls the a_Callback's methods for each data type.
void TickBlock(const Vector3i a_RelPos)
Ticks a single block.
unsigned m_StayCount
Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero,...
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
void SetAlwaysTicked(bool a_AlwaysTicked)
Increments (a_AlwaysTicked == true) or decrements (false) the m_AlwaysTicked counter.
void Tick(std::chrono::milliseconds a_Dt)
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)
cBlockEntity * GetBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ)
OBSOLETE, use the Vector3i-based overload instead.
bool UnboundedRelSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
OBSOLETE, use the Vector3i-based overload.
void CollectMobCensus(cMobCensus &toFill)
Recence all mobs proximities to players in order to know what to do with them.
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.
void SetMeta(Vector3i a_RelPos, NIBBLETYPE a_Meta)
cFluidSimulatorData * m_LavaSimulatorData
cWorld * GetWorld(void) const