Botcraft 1.21.4
Loading...
Searching...
No Matches
Botcraft::World Class Reference

#include <World.hpp>

Inheritance diagram for Botcraft::World:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Message, AllMessages >

Public Member Functions

 World (const bool is_shared_)
 
 ~World ()
 
bool IsLoaded (const Position &pos) const
 Check if a position is in a loaded chunk.
 
bool IsShared () const
 is_shared getter
 
int GetHeight () const
 Get height of the current dimension.
 
int GetMinY () const
 Get min_y of the current dimension.
 
bool IsInUltraWarmDimension () const
 Check if current dimension is Ultrawarm.
 
bool HasChunkBeenModified (const int x, const int z)
 Check if a chunk modification flag is set.
 
std::optional< ChunkResetChunkModificationState (const int x, const int z)
 Reset a chunk modification state.
 
void LoadChunk (const int x, const int z, const std::string &dim, const std::thread::id &loader_id=std::this_thread::get_id())
 Add a chunk at given coordinates.
 
void UnloadChunk (const int x, const int z, const std::thread::id &loader_id=std::this_thread::get_id())
 Remove a chunk at given coordinates.
 
void UnloadAllChunks (const std::thread::id &loader_id=std::this_thread::get_id())
 Remove all chunks from memory.
 
void SetBlock (const Position &pos, const BlockstateId id)
 Set block at given pos.
 
const BlockstateGetBlock (const Position &pos) const
 Get the blockstate at a given position.
 
std::vector< const Blockstate * > GetBlocks (const std::vector< Position > &pos) const
 Get blockstates for a set of positions.
 
std::vector< AABBGetColliders (const AABB &aabb, const Vector3< double > &movement=Vector3< double >(0.0)) const
 Get all colliders that could collide with a given AABB.
 
Vector3< double > GetFlow (const Position &pos)
 Get the flow of fluid at a given position.
 
Utilities::ScopeLockedWrapper< const std::unordered_map< std::pair< int, int >, Chunk >, std::shared_mutex, std::shared_lock > GetChunks () const
 Get a read-only locked version of all the loaded chunks.
 
void SetBiome (const int x, const int y, const int z, const int biome)
 Set biome of given block.
 
const BiomeGetBiome (const Position &pos) const
 Get the biome at a given position.
 
void SetSkyLight (const Position &pos, const unsigned char skylight)
 Set sky light value.
 
void SetBlockLight (const Position &pos, const unsigned char blocklight)
 Set block light value.
 
unsigned char GetSkyLight (const Position &pos) const
 Get sky light value.
 
unsigned char GetBlockLight (const Position &pos) const
 Get block light value.
 
void SetBlockEntityData (const Position &pos, const ProtocolCraft::NBT::Value &data)
 Set block entity data at pos.
 
ProtocolCraft::NBT::Value GetBlockEntityData (const Position &pos) const
 Get the block entity data at a given position.
 
std::string GetDimension (const int x, const int z) const
 Get dimension of chunk at given coordinates.
 
std::string GetCurrentDimension () const
 Get current world dimension.
 
void SetCurrentDimension (const std::string &dimension)
 Set current world dimension.
 
void SetDimensionHeight (const std::string &dimension, const int height)
 Set total height for given dimension.
 
void SetDimensionMinY (const std::string &dimension, const int min_y)
 Set min block for given dimension.
 
void SetDimensionUltrawarm (const std::string &dimension, const bool ultrawarm)
 Set ultrawarm bool for given dimension.
 
const BlockstateRaycast (const Vector3< double > &origin, const Vector3< double > &direction, const float max_radius, Position &out_pos, Position &out_normal)
 Perform a raycast in the voxel world and return position, normal and blockstate which are hit.
 
int GetNextWorldInteractionSequenceId ()
 Get a unique id used for server interactions.
 
bool IsFree (const AABB &aabb, const bool fluid_collide) const
 Check if an AABB collides in the world.
 
std::optional< PositionGetSupportingBlockPos (const AABB &aabb) const
 Get the block position supporting an aabb.
 

Protected Member Functions

virtual void Handle (ProtocolCraft::ClientboundLoginPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundRespawnPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundBlockUpdatePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSectionBlocksUpdatePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundForgetLevelChunkPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundLevelChunkWithLightPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundLightUpdatePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundBlockEntityDataPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundChunksBiomesPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundRegistryDataPacket &msg) override
 

Private Member Functions

void LoadChunkImpl (const int x, const int z, const std::string &dim, const std::thread::id &loader_id)
 
void UnloadChunkImpl (const int x, const int z, const std::thread::id &loader_id)
 
void SetBlockImpl (const Position &pos, const BlockstateId id)
 
const BlockstateGetBlockImpl (const Position &pos) const
 
void SetCurrentDimensionImpl (const std::string &dimension)
 
int GetHeightImpl () const
 
int GetMinYImpl () const
 
void SetBiomeImpl (const int x, const int y, const int z, const int biome)
 
void UpdateChunk (const int chunk_x, const int chunk_z, const Position &pos)
 Progagate chunk update at pos to neighbouring chunks.
 
void UpdateChunk (const int chunk_x, const int chunk_z)
 Progagate whole chunk update to neighbouring chunks.
 
ChunkGetChunk (const int x, const int z)
 Get a pointer to a chunk.
 
void LoadDataInChunk (const int x, const int z, const std::vector< unsigned char > &data)
 
void LoadBlockEntityDataInChunk (const int x, const int z, const std::vector< ProtocolCraft::BlockEntityInfo > &block_entities)
 
void UpdateChunkLight (const int x, const int z, const std::string &dim, const std::vector< unsigned long long int > &light_mask, const std::vector< unsigned long long int > &empty_light_mask, const std::vector< std::vector< char > > &data, const bool sky)
 
size_t GetDimIndex (const std::string &dim)
 

Private Attributes

std::unordered_map< std::pair< int, int >, Chunkterrain
 
std::shared_mutex world_mutex
 
const bool is_shared
 
std::string current_dimension
 
std::unordered_map< std::string, size_t > dimension_index_map
 
std::unordered_map< size_t, std::string > index_dimension_map
 
std::atomic< int > world_interaction_sequence_id
 
std::unordered_map< std::string, unsigned int > dimension_height
 Height of the chunks in a given dimension.
 
std::unordered_map< std::string, int > dimension_min_y
 Height of the lowest block in a given dimension.
 
std::unordered_map< std::string, bool > dimension_ultrawarm
 

Detailed Description

Definition at line 36 of file World.hpp.

Constructor & Destructor Documentation

◆ World()

Botcraft::World::World ( const bool  is_shared_)
Parameters
is_shared_If true, this world can be shared by multiple bot instances (assuming they all are and stay in the same dimension)

Definition at line 9 of file World.cpp.

References current_dimension, and world_interaction_sequence_id.

◆ ~World()

Botcraft::World::~World ( )

Definition at line 22 of file World.cpp.

Member Function Documentation

◆ GetBiome()

const Biome * Botcraft::World::GetBiome ( const Position pos) const

Get the biome at a given position.

Thread-safe

Parameters
posBlock position
Returns
A pointer to the biome, nullptr if not loaded

Definition at line 287 of file World.cpp.

References Botcraft::CHUNK_WIDTH, terrain, world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ GetBlock()

const Blockstate * Botcraft::World::GetBlock ( const Position pos) const

Get the blockstate at a given position.

Thread-safe

Parameters
posPosition of the block
Returns
A const pointer to the blockstate at position, nullptr if not loaded

Definition at line 142 of file World.cpp.

References GetBlockImpl(), and world_mutex.

Referenced by Raycast().

◆ GetBlockEntityData()

ProtocolCraft::NBT::Value Botcraft::World::GetBlockEntityData ( const Position pos) const

Get the block entity data at a given position.

Thread-safe

Parameters
posPosition of the block entity
Returns
Copy of the data at pos

Definition at line 403 of file World.cpp.

References Botcraft::CHUNK_WIDTH, terrain, world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ GetBlockImpl()

◆ GetBlockLight()

unsigned char Botcraft::World::GetBlockLight ( const Position pos) const

Get block light value.

Thread-safe

Parameters
posBlock position
Returns
Block light value at pos, 0 if not loaded

Definition at line 358 of file World.cpp.

References Botcraft::CHUNK_WIDTH, terrain, world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ GetBlocks()

std::vector< const Blockstate * > Botcraft::World::GetBlocks ( const std::vector< Position > &  pos) const

Get blockstates for a set of positions.

More efficient than calling multiple times GetBlock. Thread-safe

Parameters
posPositions of the blocks
Returns
A vector of const pointer to the blockstate at each position, nullptr if not loaded

Definition at line 148 of file World.cpp.

References GetBlockImpl(), and world_mutex.

◆ GetChunk()

Chunk * Botcraft::World::GetChunk ( const int  x,
const int  z 
)
private

Get a pointer to a chunk.

Not thread-safe

Parameters
xChunk X
zChunk Z
Returns
Pointer to the chunk, or nullptr if not loaded

Definition at line 1255 of file World.cpp.

References terrain.

Referenced by UpdateChunk(), and UpdateChunk().

◆ GetChunks()

Utilities::ScopeLockedWrapper< const std::unordered_map< std::pair< int, int >, Chunk >, std::shared_mutex, std::shared_lock > Botcraft::World::GetChunks ( ) const

Get a read-only locked version of all the loaded chunks.

Returns
Basically an object you can use as a std::unordered_map<std::pair<int, int>, Chunk>*. ALL WORLD UPDATE WILL BE BLOCKED WHILE THIS OBJECT IS ALIVE, make sure it goes out of scope as soon as you don't need it.

Definition at line 266 of file World.cpp.

References terrain, and world_mutex.

◆ GetColliders()

std::vector< AABB > Botcraft::World::GetColliders ( const AABB aabb,
const Vector3< double > &  movement = Vector3<double>(0.0) 
) const

Get all colliders that could collide with a given AABB.

Thread-safe

Parameters
aabbAABB of the blocks to search for
movementOptional movement vector that will be added to the AABB
Returns
A vector of solid colliders

Definition at line 160 of file World.cpp.

References Botcraft::Vector3< T >::Abs(), GetBlockImpl(), Botcraft::AABB::GetCenter(), Botcraft::Blockstate::GetCollidersAtPos(), Botcraft::AABB::GetHalfSize(), Botcraft::AABB::GetMax(), Botcraft::AABB::GetMin(), Botcraft::Blockstate::IsSolid(), world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ GetCurrentDimension()

std::string Botcraft::World::GetCurrentDimension ( ) const

Get current world dimension.

Thread-safe

Returns
Current world dimension

Definition at line 448 of file World.cpp.

◆ GetDimension()

std::string Botcraft::World::GetDimension ( const int  x,
const int  z 
) const

Get dimension of chunk at given coordinates.

Thread-safe

Parameters
xX chunk coordinate
zZ chunk coordinate
Returns
Dimension of the chunk, empty if chunk is not loaded

Definition at line 428 of file World.cpp.

◆ GetDimIndex()

size_t Botcraft::World::GetDimIndex ( const std::string &  dim)
private

Definition at line 1429 of file World.cpp.

References dimension_index_map, and index_dimension_map.

Referenced by LoadChunkImpl().

◆ GetFlow()

◆ GetHeight()

int Botcraft::World::GetHeight ( ) const

Get height of the current dimension.

Returns
256 for versions prior to 1.18, current dimension height otherwise

Definition at line 42 of file World.cpp.

References GetHeightImpl(), and world_mutex.

◆ GetHeightImpl()

int Botcraft::World::GetHeightImpl ( ) const
private

Definition at line 1108 of file World.cpp.

References current_dimension, and dimension_height.

Referenced by GetHeight(), and UpdateChunkLight().

◆ GetMinY()

int Botcraft::World::GetMinY ( ) const

Get min_y of the current dimension.

Returns
0 for versions prior to 1.18, current dimension min_y otherwise

Definition at line 52 of file World.cpp.

References GetMinYImpl(), and world_mutex.

◆ GetMinYImpl()

int Botcraft::World::GetMinYImpl ( ) const
private

Definition at line 1117 of file World.cpp.

References current_dimension, and dimension_min_y.

Referenced by GetMinY(), and UpdateChunkLight().

◆ GetNextWorldInteractionSequenceId()

int Botcraft::World::GetNextWorldInteractionSequenceId ( )

Get a unique id used for server interactions.

Thread-safe

Returns
Unique id

Definition at line 607 of file World.cpp.

References world_interaction_sequence_id.

◆ GetSkyLight()

unsigned char Botcraft::World::GetSkyLight ( const Position pos) const

Get sky light value.

Thread-safe

Parameters
posBlock position
Returns
Sky light value at pos, 0 if not loaded or in dimension with no sky light

Definition at line 341 of file World.cpp.

References Botcraft::CHUNK_WIDTH, terrain, world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ GetSupportingBlockPos()

std::optional< Position > Botcraft::World::GetSupportingBlockPos ( const AABB aabb) const

◆ Handle() [1/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundBlockEntityDataPacket msg)
overrideprotectedvirtual

Definition at line 911 of file World.cpp.

References SetBlockEntityData().

◆ Handle() [2/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundBlockUpdatePacket msg)
overrideprotectedvirtual

Definition at line 762 of file World.cpp.

References SetBlockImpl(), and world_mutex.

◆ Handle() [3/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundChunksBiomesPacket msg)
overrideprotectedvirtual

Definition at line 917 of file World.cpp.

References LOG_WARNING, terrain, and world_mutex.

◆ Handle() [4/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundForgetLevelChunkPacket msg)
overrideprotectedvirtual

Definition at line 819 of file World.cpp.

References UnloadChunk().

◆ Handle() [5/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundLevelChunkWithLightPacket msg)
overrideprotectedvirtual

◆ Handle() [6/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundLightUpdatePacket msg)
overrideprotectedvirtual

Definition at line 889 of file World.cpp.

References current_dimension, terrain, UpdateChunkLight(), and world_mutex.

◆ Handle() [7/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundLoginPacket msg)
overrideprotectedvirtual

◆ Handle() [8/10]

◆ Handle() [9/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundRespawnPacket msg)
overrideprotectedvirtual

◆ Handle() [10/10]

void Botcraft::World::Handle ( ProtocolCraft::ClientboundSectionBlocksUpdatePacket msg)
overrideprotectedvirtual

◆ HasChunkBeenModified()

bool Botcraft::World::HasChunkBeenModified ( const int  x,
const int  z 
)

Check if a chunk modification flag is set.

Thread-safe

Parameters
xChunk X coordinate
zChunk Z coordinate
Returns
True if chunk flag is set, false otherwise

Definition at line 72 of file World.cpp.

References terrain, and world_mutex.

◆ IsFree()

bool Botcraft::World::IsFree ( const AABB aabb,
const bool  fluid_collide 
) const

Check if an AABB collides in the world.

Parameters
aabbAABB to check against the world
fluid_collideif true, will count fluids as collision
Returns
True if collision false otherwise

Definition at line 613 of file World.cpp.

References Botcraft::AABB::Collide(), GetBlockImpl(), Botcraft::Blockstate::GetCollidersAtPos(), Botcraft::AABB::GetMax(), Botcraft::AABB::GetMin(), Botcraft::Blockstate::IsFluid(), Botcraft::Blockstate::IsSolid(), world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ IsInUltraWarmDimension()

bool Botcraft::World::IsInUltraWarmDimension ( ) const

Check if current dimension is Ultrawarm.

Returns
True if ultrawarm, false otherwise

Definition at line 62 of file World.cpp.

References current_dimension, dimension_ultrawarm, and world_mutex.

◆ IsLoaded()

bool Botcraft::World::IsLoaded ( const Position pos) const

Check if a position is in a loaded chunk.

Thread-safe

Parameters
posBlock position
Returns
True if the chunk is loaded, false otherwise

Definition at line 27 of file World.cpp.

References Botcraft::CHUNK_WIDTH, terrain, world_mutex, Botcraft::Vector3< T >::x, and Botcraft::Vector3< T >::z.

◆ IsShared()

bool Botcraft::World::IsShared ( ) const

is_shared getter

Returns
True if world is a shared one, false otherwise

Definition at line 37 of file World.cpp.

References is_shared.

◆ LoadBlockEntityDataInChunk()

void Botcraft::World::LoadBlockEntityDataInChunk ( const int  x,
const int  z,
const std::vector< ProtocolCraft::BlockEntityInfo > &  block_entities 
)
private

Definition at line 1297 of file World.cpp.

References terrain.

Referenced by Handle().

◆ LoadChunk()

void Botcraft::World::LoadChunk ( const int  x,
const int  z,
const std::string &  dim,
const std::thread::id &  loader_id = std::this_thread::get_id() 
)

Add a chunk at given coordinates.

If already exists in another dimension, will be erased first. Thread-safe

Parameters
xX chunk coordinate
zZ chunk coordinate
dimDimension in which the chunk is added
loader_idId of the loader of this chunk (used for shared worlds), default: current thread id

Definition at line 106 of file World.cpp.

◆ LoadChunkImpl()

void Botcraft::World::LoadChunkImpl ( const int  x,
const int  z,
const std::string &  dim,
const std::thread::id &  loader_id 
)
private

Definition at line 977 of file World.cpp.

References dimension_height, dimension_min_y, GetDimIndex(), is_shared, LOG_WARNING, terrain, and UnloadChunkImpl().

Referenced by Handle().

◆ LoadDataInChunk()

void Botcraft::World::LoadDataInChunk ( const int  x,
const int  z,
const std::vector< unsigned char > &  data 
)
private

Definition at line 1275 of file World.cpp.

References Botcraft::Chunk::LoadChunkData(), terrain, and UpdateChunk().

Referenced by Handle().

◆ Raycast()

const Blockstate * Botcraft::World::Raycast ( const Vector3< double > &  origin,
const Vector3< double > &  direction,
const float  max_radius,
Position out_pos,
Position out_normal 
)

Perform a raycast in the voxel world and return position, normal and blockstate which are hit.

Thread-safe

Parameters
originorigin the origin of the ray
directiondirection the direction of the ray
max_radiusmax_radius maximum distance of the search, must be > 0
out_posout_pos the position of the block hit
out_normalout_normal the normal of the face hit
Returns
a pointer to the blockstate of the hit cube (nullptr if not hit)

Definition at line 487 of file World.cpp.

References GetBlock(), Botcraft::Blockstate::GetCollidersAtPos(), Botcraft::Blockstate::IsAir(), Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ ResetChunkModificationState()

std::optional< Chunk > Botcraft::World::ResetChunkModificationState ( const int  x,
const int  z 
)

Reset a chunk modification state.

Thread-safe

Parameters
xChunk X coordinate
zChunk Z coordinate
Returns
A copy of the chunk, or nothing if chunk is not loaded

Definition at line 87 of file World.cpp.

References terrain, and world_mutex.

◆ SetBiome()

void Botcraft::World::SetBiome ( const int  x,
const int  y,
const int  z,
const int  biome 
)

Set biome of given block.

Does nothing if not loaded. Thread-safe

Parameters
xX coordinate
yY coordinate
zZ coordinate
biomeId of the desired biome

Definition at line 276 of file World.cpp.

◆ SetBiomeImpl()

void Botcraft::World::SetBiomeImpl ( const int  x,
const int  y,
const int  z,
const int  biome 
)
private

Definition at line 1131 of file World.cpp.

References Botcraft::CHUNK_WIDTH, and terrain.

◆ SetBlock()

void Botcraft::World::SetBlock ( const Position pos,
const BlockstateId  id 
)

Set block at given pos.

Does nothing if pos is not loaded. Thread-safe

Parameters
posPosition of the block to set
idId of the desired block

Definition at line 136 of file World.cpp.

References SetBlockImpl(), and world_mutex.

◆ SetBlockEntityData()

void Botcraft::World::SetBlockEntityData ( const Position pos,
const ProtocolCraft::NBT::Value data 
)

Set block entity data at pos.

Thread-safe

Parameters
posPosition of the block entity
dataData to set

Definition at line 375 of file World.cpp.

References Botcraft::CHUNK_WIDTH, ProtocolCraft::NBT::Value::HasData(), terrain, world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

Referenced by Handle().

◆ SetBlockImpl()

void Botcraft::World::SetBlockImpl ( const Position pos,
const BlockstateId  id 
)
private

◆ SetBlockLight()

void Botcraft::World::SetBlockLight ( const Position pos,
const unsigned char  blocklight 
)

Set block light value.

Thread-safe

Parameters
posBlock position
blocklightDesired block light value

Definition at line 325 of file World.cpp.

References Botcraft::CHUNK_WIDTH, terrain, world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ SetCurrentDimension()

void Botcraft::World::SetCurrentDimension ( const std::string &  dimension)

Set current world dimension.

Thread-safe

Parameters
dimensionDimension to set

Definition at line 458 of file World.cpp.

◆ SetCurrentDimensionImpl()

void Botcraft::World::SetCurrentDimensionImpl ( const std::string &  dimension)
private

Definition at line 1099 of file World.cpp.

References current_dimension.

Referenced by Handle(), and Handle().

◆ SetDimensionHeight()

void Botcraft::World::SetDimensionHeight ( const std::string &  dimension,
const int  height 
)

Set total height for given dimension.

Thread-safe

Parameters
dimensionDimension to set height for
heightTotal height of dimension

Definition at line 466 of file World.cpp.

References dimension_height, and world_mutex.

◆ SetDimensionMinY()

void Botcraft::World::SetDimensionMinY ( const std::string &  dimension,
const int  min_y 
)

Set min block for given dimension.

Thread-safe

Parameters
dimensionDimension to set min_y for
min_yMin block of dimension

Definition at line 472 of file World.cpp.

References dimension_min_y, and world_mutex.

◆ SetDimensionUltrawarm()

void Botcraft::World::SetDimensionUltrawarm ( const std::string &  dimension,
const bool  ultrawarm 
)

Set ultrawarm bool for given dimension.

Thread-safe

Parameters
dimensionDimension to set ultrawarm for
ultrawarmWhether the dimension is ultrawam (no water, lava flows faster etc...)

Definition at line 480 of file World.cpp.

References dimension_ultrawarm, and world_mutex.

◆ SetSkyLight()

void Botcraft::World::SetSkyLight ( const Position pos,
const unsigned char  skylight 
)

Set sky light value.

Thread-safe

Parameters
posBlock position
skylightDesired sky light value

Definition at line 309 of file World.cpp.

References Botcraft::CHUNK_WIDTH, terrain, world_mutex, Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

◆ UnloadAllChunks()

void Botcraft::World::UnloadAllChunks ( const std::thread::id &  loader_id = std::this_thread::get_id())

Remove all chunks from memory.

Parameters
loader_idId of the loader of this chunk (used for shared worlds), default: current thread id

Definition at line 119 of file World.cpp.

References terrain, and world_mutex.

Referenced by Handle().

◆ UnloadChunk()

void Botcraft::World::UnloadChunk ( const int  x,
const int  z,
const std::thread::id &  loader_id = std::this_thread::get_id() 
)

Remove a chunk at given coordinates.

Thread-safe

Parameters
xX chunk coordinate
zZ chunk coordinate
loader_idId of the loader of this chunk (used for shared worlds), default: current thread id

Definition at line 113 of file World.cpp.

References UnloadChunkImpl(), and world_mutex.

Referenced by Handle().

◆ UnloadChunkImpl()

void Botcraft::World::UnloadChunkImpl ( const int  x,
const int  z,
const std::thread::id &  loader_id 
)
private

Definition at line 1020 of file World.cpp.

References terrain, and UpdateChunk().

Referenced by LoadChunkImpl(), and UnloadChunk().

◆ UpdateChunk() [1/2]

void Botcraft::World::UpdateChunk ( const int  chunk_x,
const int  chunk_z 
)
private

Progagate whole chunk update to neighbouring chunks.

Parameters
chunk_xChunk X
chunk_zChunk Z

Definition at line 1213 of file World.cpp.

References Botcraft::East, GetChunk(), Botcraft::North, Botcraft::South, Botcraft::Chunk::UpdateNeighbour(), and Botcraft::West.

◆ UpdateChunk() [2/2]

void Botcraft::World::UpdateChunk ( const int  chunk_x,
const int  chunk_z,
const Position pos 
)
private

Progagate chunk update at pos to neighbouring chunks.

Parameters
chunk_xChunk X
chunk_zChunk Z
posWorld coordinates of updated block

Definition at line 1149 of file World.cpp.

References Botcraft::CHUNK_WIDTH, Botcraft::Chunk::GetBlock(), GetChunk(), LOG_WARNING, Botcraft::Chunk::SetBlock(), Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

Referenced by LoadDataInChunk(), SetBlockImpl(), and UnloadChunkImpl().

◆ UpdateChunkLight()

void Botcraft::World::UpdateChunkLight ( const int  x,
const int  z,
const std::string &  dim,
const std::vector< unsigned long long int > &  light_mask,
const std::vector< unsigned long long int > &  empty_light_mask,
const std::vector< std::vector< char > > &  data,
const bool  sky 
)
private

Member Data Documentation

◆ current_dimension

std::string Botcraft::World::current_dimension
private

◆ dimension_height

std::unordered_map<std::string, unsigned int> Botcraft::World::dimension_height
private

Height of the chunks in a given dimension.

Definition at line 399 of file World.hpp.

Referenced by GetHeightImpl(), Handle(), Handle(), Handle(), LoadChunkImpl(), and SetDimensionHeight().

◆ dimension_index_map

std::unordered_map<std::string, size_t> Botcraft::World::dimension_index_map
private

Definition at line 389 of file World.hpp.

Referenced by GetDimIndex(), and Handle().

◆ dimension_min_y

std::unordered_map<std::string, int> Botcraft::World::dimension_min_y
private

Height of the lowest block in a given dimension.

Definition at line 401 of file World.hpp.

Referenced by GetMinYImpl(), Handle(), Handle(), Handle(), LoadChunkImpl(), and SetDimensionMinY().

◆ dimension_ultrawarm

std::unordered_map<std::string, bool> Botcraft::World::dimension_ultrawarm
private

Definition at line 404 of file World.hpp.

Referenced by Handle(), Handle(), Handle(), IsInUltraWarmDimension(), and SetDimensionUltrawarm().

◆ index_dimension_map

std::unordered_map<size_t, std::string> Botcraft::World::index_dimension_map
private

Definition at line 390 of file World.hpp.

Referenced by GetDimIndex(), and Handle().

◆ is_shared

const bool Botcraft::World::is_shared
private

Definition at line 382 of file World.hpp.

Referenced by IsShared(), and LoadChunkImpl().

◆ terrain

◆ world_interaction_sequence_id

std::atomic<int> Botcraft::World::world_interaction_sequence_id
private

Definition at line 394 of file World.hpp.

Referenced by GetNextWorldInteractionSequenceId(), and World().

◆ world_mutex


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