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