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)
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));
652 void cChunkDesc::VerifyHeightmap(
void)
HEIGHTTYPE GetMaxHeight(void) const
Returns the maximum height value in the heightmap.
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
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...
NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
cChunkDesc(cChunkCoords a_Coords)
bool m_bUseDefaultComposition
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.
BLOCKTYPE GetBlockType() const
void SetUseDefaultHeight(bool a_bUseDefaultHeight)
NIBBLETYPE GetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
unsigned char BLOCKTYPE
The datatype used by blockdata.
void GetShapeFromHeight(Shape &a_Shape) const
Sets the shape in a_Shape to match the heightmap stored currently in m_HeightMap. ...
eMergeStrategy
The per-block strategy to use when merging another block area into this object.
bool IsUsingDefaultBiomes(void) const
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type)
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
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.
cChunkDef::HeightMap m_HeightMap
static int MakeIndex(int x, int y, int z)
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...
EMCSBiome GetBiome(int a_RelX, int a_RelZ) const
int IntNoise3DInt(int a_X, int a_Y, int a_Z) const
void SetUseDefaultFinish(bool a_bUseDefaultFinish)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
bool IsUsingDefaultComposition(void) const
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, Vector3i a_RelPos)
void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
cChunkDef::BiomeMap m_BiomeMap
unsigned char HEIGHTTYPE
The type used by the heightmap.
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...
void UpdateHeightmap(void)
Updates the heightmap to match the current contents.
bool IsUsingDefaultFinish(void) const
void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height)
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, 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.
void CompressBlockMetas(cChunkDef::BlockNibbles &a_DestMetas)
Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byt...
cBlockEntities m_BlockEntities
void Clear(void)
Clears the data stored to reclaim memory.
void SetUseDefaultComposition(bool a_bUseDefaultComposition)
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 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.
cBlockEntity * GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ)
Returns the block entity at the specified coords.
static void SetBiome(BiomeMap &a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome)
void SetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
void GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ) const
HEIGHTTYPE GetMinHeight(void) const
Returns the minimum height value in the heightmap.
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...
bool IsUsingDefaultHeight(void) const
static void SetHeight(HeightMap &a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height)
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...
void SetChunkCoords(cChunkCoords a_Coords)
BLOCKTYPE * GetBlockTypes(void) const
Returns the internal pointer to the block types.
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID)
NIBBLETYPE * GetBlockMetas(void) const
void SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
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 SetUseDefaultBiomes(bool a_bUseDefaultBiomes)
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
static cBlockEntity * 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...
void SetHeightFromShape(const Shape &a_Shape)
Sets the heightmap to match the given shape data.
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)