8 #include "../Noise/Noise.h"
9 #include "../BlockEntities/BlockEntity.h"
10 #include "../Entities/Entity.h"
18 m_bUseDefaultBiomes(true),
19 m_bUseDefaultHeight(true),
20 m_bUseDefaultComposition(true),
21 m_bUseDefaultFinish(true)
161 if (a_Shape[y + x * 256 + z * 16 * 256] != 0)
182 for (
int y = 0; y <= height; y++)
184 a_Shape[y + x * 256 + z * 16 * 256] = 1;
189 a_Shape[y + x * 256 + z * 16 * 256] = 0;
283 if (a_MinRelX > a_MaxRelX)
285 std::swap(a_MinRelX, a_MaxRelX);
287 if (a_MinRelY > a_MaxRelY)
289 std::swap(a_MinRelY, a_MaxRelY);
291 if (a_MinRelZ > a_MaxRelZ)
293 std::swap(a_MinRelZ, a_MaxRelZ);
304 LOGWARNING(
"%s: MinRelX less than zero, adjusting to zero", __FUNCTION__);
309 LOGWARNING(
"%s: MinRelX more than chunk width, adjusting to chunk width", __FUNCTION__);
314 LOGWARNING(
"%s: MaxRelX less than zero, adjusting to zero", __FUNCTION__);
319 LOGWARNING(
"%s: MaxRelX more than chunk width, adjusting to chunk width", __FUNCTION__);
325 LOGWARNING(
"%s: MinRelY less than zero, adjusting to zero", __FUNCTION__);
330 LOGWARNING(
"%s: MinRelY more than chunk height, adjusting to chunk height", __FUNCTION__);
335 LOGWARNING(
"%s: MaxRelY less than zero, adjusting to zero", __FUNCTION__);
340 LOGWARNING(
"%s: MaxRelY more than chunk height, adjusting to chunk height", __FUNCTION__);
346 LOGWARNING(
"%s: MinRelZ less than zero, adjusting to zero", __FUNCTION__);
351 LOGWARNING(
"%s: MinRelZ more than chunk width, adjusting to chunk width", __FUNCTION__);
356 LOGWARNING(
"%s: MaxRelZ less than zero, adjusting to zero", __FUNCTION__);
361 LOGWARNING(
"%s: MaxRelZ more than chunk width, adjusting to chunk width", __FUNCTION__);
366 int SizeX = a_MaxRelX - a_MinRelX;
367 int SizeY = a_MaxRelY - a_MinRelY;
368 int SizeZ = a_MaxRelZ - a_MinRelZ;
375 for (
int y = 0; y < SizeY; y++)
377 int CDY = a_MinRelY + y;
378 for (
int z = 0; z < SizeZ; z++)
380 int CDZ = a_MinRelZ + z;
381 for (
int x = 0; x < SizeX; x++)
383 int CDX = a_MinRelX + x;
432 int a_MinX,
int a_MaxX,
433 int a_MinY,
int a_MaxY,
434 int a_MinZ,
int a_MaxZ,
438 int MinX = std::max(a_MinX, 0);
439 int MinY = std::max(a_MinY, 0);
440 int MinZ = std::max(a_MinZ, 0);
445 for (
int y = MinY; y <= MaxY; y++)
447 for (
int z = MinZ; z <= MaxZ; z++)
449 for (
int x = MinX; x <= MaxX; x++)
462 int a_MinX,
int a_MaxX,
463 int a_MinY,
int a_MaxY,
464 int a_MinZ,
int a_MaxZ,
469 int MinX = std::max(a_MinX, 0);
470 int MinY = std::max(a_MinY, 0);
471 int MinZ = std::max(a_MinZ, 0);
476 for (
int y = MinY; y <= MaxY; y++)
478 for (
int z = MinZ; z <= MaxZ; z++)
480 for (
int x = MinX; x <= MaxX; x++)
485 if ((
BlockType == a_SrcType) && (BlockMeta == a_SrcMeta))
499 int a_MinX,
int a_MaxX,
500 int a_MinY,
int a_MaxY,
501 int a_MinZ,
int a_MaxZ,
505 int MinX = std::max(a_MinX, 0);
506 int MinY = std::max(a_MinY, 0);
507 int MinZ = std::max(a_MinZ, 0);
512 for (
int y = MinY; y <= MaxY; y++)
514 for (
int z = MinZ; z <= MaxZ; z++)
516 for (
int x = MinX; x <= MaxX; x++)
538 int a_MinX,
int a_MaxX,
539 int a_MinY,
int a_MaxY,
540 int a_MinZ,
int a_MaxZ,
542 int a_RandomSeed,
int a_ChanceOutOf10k
545 cNoise Noise(a_RandomSeed);
546 int MinX = std::max(a_MinX, 0);
547 int MinY = std::max(a_MinY, 0);
548 int MinZ = std::max(a_MinZ, 0);
553 for (
int y = MinY; y <= MaxY; y++)
555 for (
int z = MinZ; z <= MaxZ; z++)
557 for (
int x = MinX; x <= MaxX; x++)
560 if (rnd <= a_ChanceOutOf10k)
605 return res.first->second.get();
640 for (
size_t i = 0; i <
ARRAYCOUNT(a_DestMetas); i++)
642 a_DestMetas[i] =
static_cast<NIBBLETYPE>(AreaMetas[2 * i] | (AreaMetas[2 * i + 1] << 4));
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
@ E_BLOCK_STATIONARY_WATER
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char HEIGHTTYPE
The type used by the heightmap.
unsigned char BLOCKTYPE
The datatype used by blockdata.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
void LOGWARNING(std::string_view a_Format, const Args &... args)
void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes=baTypes|baMetas|baBlockEntities)
Creates a new area of the specified size and contents.
void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
NIBBLETYPE * GetBlockMetas(void) const
bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
Clears the data stored and prepares a fresh new block area with the specified dimensions.
BLOCKTYPE * GetBlockTypes(void) const
Returns the internal pointer to the block types.
void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta=0, NIBBLETYPE a_BlockLight=0, NIBBLETYPE a_BlockSkyLight=0x0f)
Fills the entire block area with the specified data.
NIBBLETYPE GetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
eMergeStrategy
The per-block strategy to use when merging another block area into this object.
void Merge(const cBlockArea &a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy)
Merges another block area into this one, using the specified block combinating strategy This function...
void SetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
void Clear(void)
Clears the data stored to reclaim memory.
static OwnedBlockEntity CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World=nullptr)
Creates a new block entity for the specified block type at the specified absolute pos.
BLOCKTYPE GetBlockType() const
Wraps the chunk coords into a single structure.
static void SetHeight(HeightMap &a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height)
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, Vector3i a_RelPos)
static size_t MakeIndex(int x, int y, int z)
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
static void SetBiome(BiomeMap &a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome)
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type)
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ) const
void ReadBlockArea(cBlockArea &a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ)
Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas.
bool IsUsingDefaultHeight(void) const
EMCSBiome GetBiome(int a_RelX, int a_RelZ) const
cBlockEntity * GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ)
Returns the block entity at the specified coords.
void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
bool IsUsingDefaultBiomes(void) const
void RandomFillRelCuboid(int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, int a_MinZ, int a_MaxZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_RandomSeed, int a_ChanceOutOf10k)
Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of th...
void SetUseDefaultBiomes(bool a_bUseDefaultBiomes)
void SetUseDefaultHeight(bool a_bUseDefaultHeight)
void FillRelCuboid(int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, int a_MinZ, int a_MaxZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Fills the relative cuboid with specified block; allows cuboid out of range of this chunk.
void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height)
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
bool IsUsingDefaultFinish(void) const
void SetUseDefaultComposition(bool a_bUseDefaultComposition)
void SetChunkCoords(cChunkCoords a_Coords)
void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
void CompressBlockMetas(cChunkDef::BlockNibbles &a_DestMetas)
Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byt...
NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
cChunkDef::BiomeMap m_BiomeMap
void SetUseDefaultFinish(bool a_bUseDefaultFinish)
void FloorRelCuboid(int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, int a_MinZ, int a_MaxZ, BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta)
Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air,...
bool m_bUseDefaultComposition
void VerifyHeightmap(void)
Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column.
void ReplaceRelCuboid(int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, int a_MinZ, int a_MaxZ, BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta, BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta)
Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this...
cBlockEntities m_BlockEntities
HEIGHTTYPE GetMinHeight(void) const
Returns the minimum height value in the heightmap.
void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Returns the BlockType and BlockMeta at the specified coords.
void GetShapeFromHeight(Shape &a_Shape) const
Sets the shape in a_Shape to match the heightmap stored currently in m_HeightMap.
bool IsUsingDefaultComposition(void) const
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID)
void WriteBlockArea(const cBlockArea &a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy=cBlockArea::msOverwrite)
Writes the block area into the chunk, with its origin set at the specified relative coords.
cChunkDef::HeightMap m_HeightMap
void UpdateHeightmap(void)
Updates the heightmap to match the current contents.
void SetHeightFromShape(const Shape &a_Shape)
Sets the heightmap to match the given shape data.
HEIGHTTYPE GetMaxHeight(void) const
Returns the maximum height value in the heightmap.
cChunkDesc(cChunkCoords a_Coords)
int IntNoise3DInt(int a_X, int a_Y, int a_Z) const