7#include <unordered_map>
20 struct hash<pair<int, int>>
25 size_t value = hasher(p.first);
26 value ^= hasher(p.second) + 0x9e3779b9 + (value << 6) + (value >> 2);
42 World(
const bool is_shared_);
79#if PROTOCOL_VERSION < 719
85 void LoadChunk(
const int x,
const int z,
const Dimension dim,
const std::thread::id& loader_id = std::this_thread::get_id());
92 void LoadChunk(
const int x,
const int z,
const std::string& dim,
const std::thread::id& loader_id = std::this_thread::get_id());
98 void UnloadChunk(
const int x,
const int z,
const std::thread::id& loader_id = std::this_thread::get_id());
102 void UnloadAllChunks(
const std::thread::id& loader_id = std::this_thread::get_id());
118 std::vector<const Blockstate*>
GetBlocks(
const std::vector<Position>& pos)
const;
137#if PROTOCOL_VERSION < 358
142 void SetBiome(
const int x,
const int z,
const unsigned char biome);
143#elif PROTOCOL_VERSION < 552
148 void SetBiome(
const int x,
const int z,
const int biome);
155 void SetBiome(
const int x,
const int y,
const int z,
const int biome);
190#if PROTOCOL_VERSION < 719
201 std::string
GetDimension(
const int x,
const int z)
const;
204#if PROTOCOL_VERSION < 719
214#if PROTOCOL_VERSION < 719
224#if PROTOCOL_VERSION > 756
234#if PROTOCOL_VERSION > 718
251#if PROTOCOL_VERSION > 758
261 bool IsFree(
const AABB& aabb,
const bool fluid_collide)
const;
274#if PROTOCOL_VERSION < 757
275 virtual void Handle(ProtocolCraft::ClientboundLevelChunkPacket& msg)
override;
279#if PROTOCOL_VERSION > 404
283#if PROTOCOL_VERSION > 761
286#if PROTOCOL_VERSION > 763
291#if PROTOCOL_VERSION < 719
292 void LoadChunkImpl(
const int x,
const int z,
const Dimension dim,
const std::thread::id& loader_id);
294 void LoadChunkImpl(
const int x,
const int z,
const std::string& dim,
const std::thread::id& loader_id);
296 void UnloadChunkImpl(
const int x,
const int z,
const std::thread::id& loader_id);
301#if PROTOCOL_VERSION < 719
310#if PROTOCOL_VERSION < 358
311 void SetBiomeImpl(
const int x,
const int z,
const unsigned char biome);
312#elif PROTOCOL_VERSION < 552
313 void SetBiomeImpl(
const int x,
const int z,
const int biome);
315 void SetBiomeImpl(
const int x,
const int y,
const int z,
const int biome);
327 void UpdateChunk(
const int chunk_x,
const int chunk_z);
335#if PROTOCOL_VERSION < 552
336 void LoadDataInChunk(
const int x,
const int z,
const std::vector<unsigned char>& data,
337 const int primary_bit_mask,
const bool ground_up_continuous);
338#elif PROTOCOL_VERSION < 755
339 void LoadDataInChunk(
const int x,
const int z,
const std::vector<unsigned char>& data,
340 const int primary_bit_mask);
341#elif PROTOCOL_VERSION < 757
342 void LoadDataInChunk(
const int x,
const int z,
const std::vector<unsigned char>& data,
343 const std::vector<unsigned long long int>& primary_bit_mask);
345 void LoadDataInChunk(
const int x,
const int z,
const std::vector<unsigned char>& data);
348#if PROTOCOL_VERSION < 757
354#if PROTOCOL_VERSION > 551 && PROTOCOL_VERSION < 757
355 void LoadBiomesInChunk(
const int x,
const int z,
const std::vector<int>& biomes);
358#if PROTOCOL_VERSION > 404 && PROTOCOL_VERSION < 719
359 void UpdateChunkLight(
const int x,
const int z,
const Dimension dim,
const int light_mask,
const int empty_light_mask,
const std::vector<std::vector<char> >& data,
const bool sky);
360#elif PROTOCOL_VERSION > 718 && PROTOCOL_VERSION < 755
361 void UpdateChunkLight(
const int x,
const int z,
const std::string& dim,
const int light_mask,
const int empty_light_mask,
const std::vector<std::vector<char> >& data,
const bool sky);
362#elif PROTOCOL_VERSION > 754
364 const std::vector<unsigned long long int>& light_mask,
const std::vector<unsigned long long int>& empty_light_mask,
365 const std::vector<std::vector<char> >& data,
const bool sky);
368#if PROTOCOL_VERSION < 719
378#if PROTOCOL_VERSION > 404 && PROTOCOL_VERSION < 757
383#if PROTOCOL_VERSION < 719
393#if PROTOCOL_VERSION > 758
397#if PROTOCOL_VERSION > 756
403#if PROTOCOL_VERSION > 718
Mutex protected reference, will be locked until destroyed.
void SetBlockEntityData(const Position &pos, const ProtocolCraft::NBT::Value &data)
Set block entity data at pos.
Vector3< double > GetFlow(const Position &pos)
Get the flow of fluid at a given position.
void UnloadChunkImpl(const int x, const int z, const std::thread::id &loader_id)
void SetSkyLight(const Position &pos, const unsigned char skylight)
Set sky light value.
std::unordered_map< std::pair< int, int >, Chunk > terrain
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.
unsigned char GetBlockLight(const Position &pos) const
Get block light value.
const Blockstate * GetBlock(const Position &pos) const
Get the blockstate at a given position.
bool IsFree(const AABB &aabb, const bool fluid_collide) const
Check if an AABB collides in the world.
std::optional< Chunk > ResetChunkModificationState(const int x, const int z)
Reset a chunk modification state.
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.
void LoadDataInChunk(const int x, const int z, const std::vector< unsigned char > &data)
void SetCurrentDimensionImpl(const std::string &dimension)
Chunk * GetChunk(const int x, const int z)
Get a pointer to a chunk.
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)
int GetNextWorldInteractionSequenceId()
Get a unique id used for server interactions.
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.
std::unordered_map< std::string, size_t > dimension_index_map
std::string current_dimension
std::unordered_map< size_t, std::string > index_dimension_map
bool HasChunkBeenModified(const int x, const int z)
Check if a chunk modification flag is set.
bool IsInUltraWarmDimension() const
Check if current dimension is Ultrawarm.
void UpdateChunk(const int chunk_x, const int chunk_z, const Position &pos)
Progagate chunk update at pos to neighbouring chunks.
void SetDimensionHeight(const std::string &dimension, const int height)
Set total height for given dimension.
int GetHeight() const
Get height of the current dimension.
std::unordered_map< std::string, unsigned int > dimension_height
Height of the chunks in a given dimension.
const Biome * GetBiome(const Position &pos) const
Get the biome at a given position.
const Blockstate * GetBlockImpl(const Position &pos) const
void SetCurrentDimension(const std::string &dimension)
Set current world dimension.
void SetBlock(const Position &pos, const BlockstateId id)
Set block at given pos.
void SetBlockImpl(const Position &pos, const BlockstateId id)
bool IsLoaded(const Position &pos) const
Check if a position is in a loaded chunk.
ProtocolCraft::NBT::Value GetBlockEntityData(const Position &pos) const
Get the block entity data at a given position.
std::atomic< int > world_interaction_sequence_id
void UnloadAllChunks(const std::thread::id &loader_id=std::this_thread::get_id())
Remove all chunks from memory.
int GetHeightImpl() const
virtual void Handle(ProtocolCraft::ClientboundLoginPacket &msg) override
void SetBiomeImpl(const int x, const int y, const int z, const int biome)
std::vector< AABB > GetColliders(const AABB &aabb, const Vector3< double > &movement=Vector3< double >(0.0)) const
Get all colliders that could collide with a given AABB.
void SetBlockLight(const Position &pos, const unsigned char blocklight)
Set block light value.
std::unordered_map< std::string, bool > dimension_ultrawarm
std::unordered_map< std::string, int > dimension_min_y
Height of the lowest block in a given dimension.
const Blockstate * 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.
void SetBiome(const int x, const int y, const int z, const int biome)
Set biome of given block.
void LoadBlockEntityDataInChunk(const int x, const int z, const std::vector< ProtocolCraft::BlockEntityInfo > &block_entities)
unsigned char GetSkyLight(const Position &pos) const
Get sky light value.
size_t GetDimIndex(const std::string &dim)
bool IsShared() const
is_shared getter
std::optional< Position > GetSupportingBlockPos(const AABB &aabb) const
Get the block position supporting an aabb.
void LoadChunkImpl(const int x, const int z, const std::string &dim, const std::thread::id &loader_id)
int GetMinY() const
Get min_y of the current dimension.
std::shared_mutex world_mutex
std::vector< const Blockstate * > GetBlocks(const std::vector< Position > &pos) const
Get blockstates for a set of positions.
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.
std::string GetCurrentDimension() const
Get current world dimension.
std::string GetDimension(const int x, const int z) const
Get dimension of chunk at given coordinates.
unsigned int BlockstateId
size_t operator()(const pair< int, int > &p) const