2017-09-02 03:45:06 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// BlockArea.cpp
|
|
|
|
|
2016-08-04 11:29:14 -04:00
|
|
|
// NOTE: compile.sh checks for this file in order to determine if this is the Cuberite folder.
|
|
|
|
// Please modify compile.sh if you want to rename or remove this file.
|
|
|
|
// This file was chosen arbitrarily and it's a good enough indicator we're in the Cuberite folder.
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Implements the cBlockArea object representing an area of block data that can be queried from cWorld and then accessed again without further queries
|
|
|
|
// The object also supports writing the blockdata back into cWorld, even into other coords
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "BlockArea.h"
|
|
|
|
#include "OSSupport/GZipFile.h"
|
|
|
|
#include "Blocks/BlockHandler.h"
|
2014-05-21 14:58:48 -04:00
|
|
|
#include "ChunkData.h"
|
2017-06-24 05:58:06 -04:00
|
|
|
#include "BlockEntities/BlockEntity.h"
|
2019-10-16 04:06:34 -04:00
|
|
|
#include "Item.h"
|
2020-04-03 02:57:01 -04:00
|
|
|
#include "BlockInfo.h"
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-28 16:30:07 -04:00
|
|
|
// Disable MSVC warnings: "conditional expression is constant"
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4127)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-28 13:31:07 -04:00
|
|
|
|
|
|
|
typedef void (CombinatorFunc)(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta);
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Merges two blocktypes and blockmetas of the specified sizes and offsets using the specified combinator function
|
|
|
|
This wild construct allows us to pass a function argument and still have it inlined by the compiler. */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetasValid, CombinatorFunc Combinator>
|
2014-04-28 13:31:07 -04:00
|
|
|
void InternalMergeBlocks(
|
2013-07-29 07:13:03 -04:00
|
|
|
BLOCKTYPE * a_DstTypes, const BLOCKTYPE * a_SrcTypes,
|
2014-07-17 10:33:09 -04:00
|
|
|
NIBBLETYPE * a_DstMetas, const NIBBLETYPE * a_SrcMetas,
|
2013-07-29 07:13:03 -04:00
|
|
|
int a_SizeX, int a_SizeY, int a_SizeZ,
|
|
|
|
int a_SrcOffX, int a_SrcOffY, int a_SrcOffZ,
|
|
|
|
int a_DstOffX, int a_DstOffY, int a_DstOffZ,
|
|
|
|
int a_SrcSizeX, int a_SrcSizeY, int a_SrcSizeZ,
|
2014-04-28 13:31:07 -04:00
|
|
|
int a_DstSizeX, int a_DstSizeY, int a_DstSizeZ
|
2013-07-29 07:13:03 -04:00
|
|
|
)
|
|
|
|
{
|
2013-12-22 08:55:06 -05:00
|
|
|
UNUSED(a_SrcSizeY);
|
|
|
|
UNUSED(a_DstSizeY);
|
2013-07-29 07:13:03 -04:00
|
|
|
for (int y = 0; y < a_SizeY; y++)
|
|
|
|
{
|
|
|
|
int SrcBaseY = (y + a_SrcOffY) * a_SrcSizeX * a_SrcSizeZ;
|
|
|
|
int DstBaseY = (y + a_DstOffY) * a_DstSizeX * a_DstSizeZ;
|
|
|
|
for (int z = 0; z < a_SizeZ; z++)
|
|
|
|
{
|
|
|
|
int SrcBaseZ = SrcBaseY + (z + a_SrcOffZ) * a_SrcSizeX;
|
|
|
|
int DstBaseZ = DstBaseY + (z + a_DstOffZ) * a_DstSizeX;
|
|
|
|
int SrcIdx = SrcBaseZ + a_SrcOffX;
|
|
|
|
int DstIdx = DstBaseZ + a_DstOffX;
|
|
|
|
for (int x = 0; x < a_SizeX; x++)
|
|
|
|
{
|
2014-04-28 13:31:07 -04:00
|
|
|
if (MetasValid)
|
|
|
|
{
|
|
|
|
Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], a_DstMetas[DstIdx], a_SrcMetas[SrcIdx]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-12 18:51:42 -04:00
|
|
|
NIBBLETYPE FakeDestMeta = 0;
|
2015-05-24 07:56:56 -04:00
|
|
|
Combinator(a_DstTypes[DstIdx], a_SrcTypes[SrcIdx], FakeDestMeta, static_cast<NIBBLETYPE>(0));
|
2014-04-28 13:31:07 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
++DstIdx;
|
|
|
|
++SrcIdx;
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Combinator used for cBlockArea::msOverwrite merging */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetaValid>
|
2014-04-28 14:07:06 -04:00
|
|
|
void MergeCombinatorOverwrite(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
a_DstType = a_SrcType;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = a_SrcMeta;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Combinator used for cBlockArea::msFillAir merging */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetaValid>
|
2014-04-28 14:07:06 -04:00
|
|
|
void MergeCombinatorFillAir(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
if (a_DstType == E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
a_DstType = a_SrcType;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = a_SrcMeta;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
// "else" is the default, already in place
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Combinator used for cBlockArea::msImprint merging */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetaValid>
|
2014-04-28 14:07:06 -04:00
|
|
|
void MergeCombinatorImprint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
if (a_SrcType != E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
a_DstType = a_SrcType;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = a_SrcMeta;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
// "else" is the default, already in place
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Combinator used for cBlockArea::msLake merging */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetaValid>
|
2014-04-28 14:07:06 -04:00
|
|
|
void MergeCombinatorLake(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
// Sponge is the NOP block
|
|
|
|
if (a_SrcType == E_BLOCK_SPONGE)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
// Air is always hollowed out
|
2013-07-29 07:13:03 -04:00
|
|
|
if (a_SrcType == E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
a_DstType = E_BLOCK_AIR;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = 0;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Water and lava are never overwritten
|
|
|
|
switch (a_DstType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_WATER:
|
|
|
|
case E_BLOCK_STATIONARY_WATER:
|
|
|
|
case E_BLOCK_LAVA:
|
|
|
|
case E_BLOCK_STATIONARY_LAVA:
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Water and lava always overwrite
|
|
|
|
switch (a_SrcType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_WATER:
|
|
|
|
case E_BLOCK_STATIONARY_WATER:
|
|
|
|
case E_BLOCK_LAVA:
|
|
|
|
case E_BLOCK_STATIONARY_LAVA:
|
|
|
|
{
|
|
|
|
a_DstType = a_SrcType;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = a_SrcMeta;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (a_SrcType == E_BLOCK_STONE)
|
|
|
|
{
|
|
|
|
switch (a_DstType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_DIRT:
|
|
|
|
case E_BLOCK_GRASS:
|
|
|
|
case E_BLOCK_MYCELIUM:
|
|
|
|
{
|
|
|
|
a_DstType = E_BLOCK_STONE;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = 0;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Everything else is left as it is
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-28 13:03:37 -04:00
|
|
|
/** Combinator used for cBlockArea::msSpongePrint merging */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetaValid>
|
2014-04-28 14:07:06 -04:00
|
|
|
void MergeCombinatorSpongePrint(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
2014-03-28 13:03:37 -04:00
|
|
|
{
|
|
|
|
// Sponge overwrites nothing, everything else overwrites anything
|
|
|
|
if (a_SrcType != E_BLOCK_SPONGE)
|
|
|
|
{
|
|
|
|
a_DstType = a_SrcType;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = a_SrcMeta;
|
|
|
|
}
|
2014-03-28 13:03:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-31 13:47:18 -04:00
|
|
|
/** Combinator used for cBlockArea::msDifference merging */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetaValid>
|
2014-04-28 14:07:06 -04:00
|
|
|
void MergeCombinatorDifference(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
2014-03-31 13:47:18 -04:00
|
|
|
{
|
2014-04-28 13:31:07 -04:00
|
|
|
if ((a_DstType == a_SrcType) && (!MetaValid || (a_DstMeta == a_SrcMeta)))
|
2014-03-31 13:47:18 -04:00
|
|
|
{
|
|
|
|
a_DstType = E_BLOCK_AIR;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = 0;
|
|
|
|
}
|
2014-03-31 13:47:18 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_DstType = a_SrcType;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = a_SrcMeta;
|
|
|
|
}
|
2014-03-31 13:47:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 09:45:48 -04:00
|
|
|
/** Combinator used for cBlockArea::msSimpleCompare merging */
|
|
|
|
template <bool MetaValid>
|
|
|
|
void MergeCombinatorSimpleCompare(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
|
|
|
{
|
|
|
|
if ((a_DstType == a_SrcType) && (!MetaValid || (a_DstMeta == a_SrcMeta)))
|
|
|
|
{
|
|
|
|
// The blocktypes are the same, and the blockmetas are not present or are the same
|
|
|
|
a_DstType = E_BLOCK_AIR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The blocktypes or blockmetas differ
|
|
|
|
a_DstType = E_BLOCK_STONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-01 14:50:10 -04:00
|
|
|
/** Combinator used for cBlockArea::msMask merging */
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetaValid>
|
2014-04-28 14:07:06 -04:00
|
|
|
void MergeCombinatorMask(BLOCKTYPE & a_DstType, BLOCKTYPE a_SrcType, NIBBLETYPE & a_DstMeta, NIBBLETYPE a_SrcMeta)
|
2014-04-01 14:50:10 -04:00
|
|
|
{
|
|
|
|
// If the blocks are the same, keep the dest; otherwise replace with air
|
2014-04-28 13:31:07 -04:00
|
|
|
if ((a_SrcType != a_DstType) || !MetaValid || (a_SrcMeta != a_DstMeta))
|
2014-04-01 14:50:10 -04:00
|
|
|
{
|
|
|
|
a_DstType = E_BLOCK_AIR;
|
2014-04-28 14:00:43 -04:00
|
|
|
if (MetaValid)
|
|
|
|
{
|
|
|
|
a_DstMeta = 0;
|
|
|
|
}
|
2014-04-01 14:50:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 16:30:07 -04:00
|
|
|
// Re-enable previously disabled MSVC warnings
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2014-04-01 14:50:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-07-29 07:13:03 -04:00
|
|
|
// cBlockArea:
|
|
|
|
|
2017-09-06 13:40:04 -04:00
|
|
|
cBlockArea::cBlockArea(void) = default;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
bool cBlockArea::IsValidDataTypeCombination(int a_DataTypes)
|
|
|
|
{
|
|
|
|
// BlockEntities require that BlockTypes be present, too
|
|
|
|
if ((a_DataTypes & baBlockEntities) != 0)
|
|
|
|
{
|
|
|
|
if ((a_DataTypes & baTypes) == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// All other combinations are considered valid
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::Clear(void)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockTypes.reset();
|
|
|
|
m_BlockMetas.reset();
|
|
|
|
m_BlockLight.reset();
|
|
|
|
m_BlockSkyLight.reset();
|
2017-06-24 05:58:06 -04:00
|
|
|
m_BlockEntities.reset();
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Origin.Set(0, 0, 0);
|
|
|
|
m_Size.Set(0, 0, 0);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
|
|
|
|
{
|
2017-06-24 05:58:06 -04:00
|
|
|
ASSERT(a_SizeX > 0);
|
|
|
|
ASSERT(a_SizeY > 0);
|
|
|
|
ASSERT(a_SizeZ > 0);
|
|
|
|
ASSERT(IsValidDataTypeCombination(a_DataTypes));
|
2015-06-30 08:08:21 -04:00
|
|
|
|
|
|
|
// Warn if the height is too much, but proceed with the creation:
|
|
|
|
if (a_SizeY > cChunkDef::Height)
|
|
|
|
{
|
|
|
|
LOGWARNING("Creating a cBlockArea with height larger than world height (%d). Continuing, but the area may misbehave.", a_SizeY);
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
Clear();
|
2017-09-07 04:40:58 -04:00
|
|
|
SetSize(a_SizeX, a_SizeY, a_SizeZ, a_DataTypes);
|
|
|
|
Fill(a_DataTypes, E_BLOCK_AIR);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-25 17:05:45 -04:00
|
|
|
void cBlockArea::Create(const Vector3i & a_Size, int a_DataTypes)
|
|
|
|
{
|
|
|
|
Create(a_Size.x, a_Size.y, a_Size.z, a_DataTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-12 02:46:14 -04:00
|
|
|
void cBlockArea::SetWEOffset(int a_OffsetX, int a_OffsetY, int a_OffsetZ)
|
2014-03-10 12:07:46 -04:00
|
|
|
{
|
2014-03-11 13:23:21 -04:00
|
|
|
m_WEOffset.Set(a_OffsetX, a_OffsetY, a_OffsetZ);
|
2014-03-10 12:07:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-12 02:46:14 -04:00
|
|
|
void cBlockArea::SetWEOffset(const Vector3i & a_Offset)
|
2014-03-10 12:07:46 -04:00
|
|
|
{
|
2014-03-11 13:23:21 -04:00
|
|
|
m_WEOffset.Set(a_Offset.x, a_Offset.y, a_Offset.z);
|
2014-03-10 12:07:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Origin.Set(a_OriginX, a_OriginY, a_OriginZ);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-24 17:17:12 -05:00
|
|
|
void cBlockArea::SetOrigin(const Vector3i & a_Origin)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Origin.Set(a_Origin.x, a_Origin.y, a_Origin.z);
|
2014-02-24 17:17:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
bool cBlockArea::IsValidRelCoords(int a_RelX, int a_RelY, int a_RelZ) const
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(a_RelX >= 0) && (a_RelX < m_Size.x) &&
|
|
|
|
(a_RelY >= 0) && (a_RelY < m_Size.y) &&
|
|
|
|
(a_RelZ >= 0) && (a_RelZ < m_Size.z)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBlockArea::IsValidRelCoords(const Vector3i & a_RelCoords) const
|
|
|
|
{
|
|
|
|
return IsValidRelCoords(a_RelCoords.x, a_RelCoords.y, a_RelCoords.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBlockArea::IsValidCoords(int a_BlockX, int a_BlockY, int a_BlockZ) const
|
|
|
|
{
|
|
|
|
return IsValidRelCoords(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBlockArea::IsValidCoords(const Vector3i & a_Coords) const
|
|
|
|
{
|
|
|
|
return IsValidRelCoords(a_Coords - m_Origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 10:00:38 -05:00
|
|
|
bool cBlockArea::Read(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-06-24 05:58:06 -04:00
|
|
|
ASSERT(IsValidDataTypeCombination(a_DataTypes));
|
|
|
|
ASSERT(cChunkDef::IsValidHeight(a_MinBlockY));
|
|
|
|
ASSERT(cChunkDef::IsValidHeight(a_MaxBlockY));
|
|
|
|
ASSERT(a_MinBlockX <= a_MaxBlockX);
|
2017-06-25 05:07:16 -04:00
|
|
|
ASSERT(a_MinBlockY <= a_MaxBlockY);
|
2017-06-24 05:58:06 -04:00
|
|
|
ASSERT(a_MinBlockZ <= a_MaxBlockZ);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Include the Max coords:
|
|
|
|
a_MaxBlockX += 1;
|
|
|
|
a_MaxBlockY += 1;
|
|
|
|
a_MaxBlockZ += 1;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Allocate the needed memory:
|
|
|
|
Clear();
|
|
|
|
if (!SetSize(a_MaxBlockX - a_MinBlockX, a_MaxBlockY - a_MinBlockY, a_MaxBlockZ - a_MinBlockZ, a_DataTypes))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Origin.Set(a_MinBlockX, a_MinBlockY, a_MinBlockZ);
|
2013-07-29 07:13:03 -04:00
|
|
|
cChunkReader Reader(*this);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Convert block coords to chunks coords:
|
|
|
|
int MinChunkX, MaxChunkX;
|
|
|
|
int MinChunkZ, MaxChunkZ;
|
|
|
|
cChunkDef::AbsoluteToRelative(a_MinBlockX, a_MinBlockY, a_MinBlockZ, MinChunkX, MinChunkZ);
|
|
|
|
cChunkDef::AbsoluteToRelative(a_MaxBlockX, a_MaxBlockY, a_MaxBlockZ, MaxChunkX, MaxChunkZ);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// Query block data:
|
2017-02-05 10:00:38 -05:00
|
|
|
if (!a_ForEachChunkProvider.ForEachChunkInRect(MinChunkX, MaxChunkX, MinChunkZ, MaxChunkZ, Reader))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 10:00:38 -05:00
|
|
|
bool cBlockArea::Read(cForEachChunkProvider & a_ForEachChunkProvider, const cCuboid & a_Bounds, int a_DataTypes)
|
2014-02-24 17:17:12 -05:00
|
|
|
{
|
|
|
|
return Read(
|
|
|
|
a_ForEachChunkProvider,
|
|
|
|
a_Bounds.p1.x, a_Bounds.p2.x,
|
|
|
|
a_Bounds.p1.y, a_Bounds.p2.y,
|
|
|
|
a_Bounds.p1.z, a_Bounds.p2.z,
|
|
|
|
a_DataTypes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 10:00:38 -05:00
|
|
|
bool cBlockArea::Read(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_Point1, const Vector3i & a_Point2, int a_DataTypes)
|
2014-02-24 17:17:12 -05:00
|
|
|
{
|
|
|
|
return Read(
|
|
|
|
a_ForEachChunkProvider,
|
|
|
|
a_Point1.x, a_Point2.x,
|
|
|
|
a_Point1.y, a_Point2.y,
|
|
|
|
a_Point1.z, a_Point2.z,
|
|
|
|
a_DataTypes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 10:00:38 -05:00
|
|
|
bool cBlockArea::Write(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
ASSERT((a_DataTypes & GetDataTypes()) == a_DataTypes); // Are you requesting only the data that I have?
|
2017-06-24 05:58:06 -04:00
|
|
|
ASSERT(cChunkDef::IsValidHeight(a_MinBlockY));
|
|
|
|
ASSERT(cChunkDef::IsValidHeight(a_MinBlockY + m_Size.y - 1));
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2017-02-05 10:00:38 -05:00
|
|
|
return a_ForEachChunkProvider.WriteBlockArea(*this, a_MinBlockX, a_MinBlockY, a_MinBlockZ, a_DataTypes);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 10:00:38 -05:00
|
|
|
bool cBlockArea::Write(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes)
|
2014-02-24 17:17:12 -05:00
|
|
|
{
|
|
|
|
return Write(
|
|
|
|
a_ForEachChunkProvider,
|
|
|
|
a_MinCoords.x, a_MinCoords.y, a_MinCoords.z,
|
|
|
|
a_DataTypes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::CopyTo(cBlockArea & a_Into) const
|
|
|
|
{
|
|
|
|
if (&a_Into == this)
|
|
|
|
{
|
|
|
|
LOGWARNING("Trying to copy a cBlockArea into self, ignoring.");
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
a_Into.Clear();
|
2014-03-25 16:59:25 -04:00
|
|
|
a_Into.SetSize(m_Size.x, m_Size.y, m_Size.z, GetDataTypes());
|
|
|
|
a_Into.m_Origin = m_Origin;
|
2014-04-28 13:31:07 -04:00
|
|
|
size_t BlockCount = GetBlockCount();
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
memcpy(a_Into.GetBlockTypes(), GetBlockTypes(), BlockCount * sizeof(BLOCKTYPE));
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
memcpy(a_Into.GetBlockMetas(), GetBlockMetas(), BlockCount * sizeof(NIBBLETYPE));
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockLights())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
memcpy(a_Into.GetBlockLight(), GetBlockLight(), BlockCount * sizeof(NIBBLETYPE));
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockSkyLights())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
memcpy(a_Into.GetBlockSkyLight(), GetBlockSkyLight(), BlockCount * sizeof(NIBBLETYPE));
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
2020-04-03 17:23:38 -04:00
|
|
|
a_Into.m_BlockEntities->clear();
|
2017-06-24 05:58:06 -04:00
|
|
|
for (const auto & keyPair: *m_BlockEntities)
|
|
|
|
{
|
|
|
|
const auto & pos = keyPair.second->GetPos();
|
2020-04-03 17:23:38 -04:00
|
|
|
a_Into.m_BlockEntities->emplace(keyPair.first, keyPair.second->Clone(pos));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::CopyFrom(const cBlockArea & a_From)
|
|
|
|
{
|
|
|
|
a_From.CopyTo(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::DumpToRawFile(const AString & a_FileName)
|
|
|
|
{
|
|
|
|
cFile f;
|
|
|
|
if (!f.Open(a_FileName, cFile::fmWrite))
|
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: Cannot open file \"%s\" for raw dump", a_FileName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
2016-08-24 15:45:03 -04:00
|
|
|
UInt32 SizeX = ntohl(static_cast<UInt32>(m_Size.x));
|
|
|
|
UInt32 SizeY = ntohl(static_cast<UInt32>(m_Size.y));
|
|
|
|
UInt32 SizeZ = ntohl(static_cast<UInt32>(m_Size.z));
|
2013-07-29 07:13:03 -04:00
|
|
|
f.Write(&SizeX, 4);
|
|
|
|
f.Write(&SizeY, 4);
|
|
|
|
f.Write(&SizeZ, 4);
|
2015-05-24 07:56:56 -04:00
|
|
|
unsigned char DataTypes = static_cast<unsigned char>(GetDataTypes());
|
2013-07-29 07:13:03 -04:00
|
|
|
f.Write(&DataTypes, 1);
|
2014-04-28 13:31:07 -04:00
|
|
|
size_t NumBlocks = GetBlockCount();
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
f.Write(GetBlockTypes(), NumBlocks * sizeof(BLOCKTYPE));
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
f.Write(GetBlockMetas(), NumBlocks);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockLights())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
f.Write(GetBlockLight(), NumBlocks);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockSkyLights())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
f.Write(GetBlockSkyLight(), NumBlocks);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
|
|
|
|
{
|
|
|
|
if (
|
2014-03-25 16:59:25 -04:00
|
|
|
(a_AddMinX + a_SubMaxX >= m_Size.x) ||
|
|
|
|
(a_AddMinY + a_SubMaxY >= m_Size.y) ||
|
|
|
|
(a_AddMinZ + a_SubMaxZ >= m_Size.z)
|
2013-07-29 07:13:03 -04:00
|
|
|
)
|
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea:Crop called with more croping than the dimensions: %d x %d x %d with cropping %d, %d and %d",
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Size.x, m_Size.y, m_Size.z,
|
2013-07-29 07:13:03 -04:00
|
|
|
a_AddMinX + a_SubMaxX, a_AddMinY + a_SubMaxY, a_AddMinZ + a_SubMaxZ
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
|
|
|
CropBlockTypes(a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
|
|
|
|
}
|
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
|
|
|
CropNibbles(m_BlockMetas, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
|
|
|
|
}
|
|
|
|
if (HasBlockLights())
|
|
|
|
{
|
|
|
|
CropNibbles(m_BlockLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
|
|
|
|
}
|
|
|
|
if (HasBlockSkyLights())
|
|
|
|
{
|
|
|
|
CropNibbles(m_BlockSkyLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
|
|
|
|
}
|
2017-06-24 14:25:23 -04:00
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
2020-04-03 17:23:38 -04:00
|
|
|
const Vector3i AddMin{ a_AddMinX, a_AddMinY, a_AddMinZ };
|
|
|
|
const cCuboid CropBox{ AddMin, m_Size - Vector3i{a_SubMaxX, a_SubMaxY, a_SubMaxZ} };
|
2017-06-24 05:58:06 -04:00
|
|
|
|
2017-06-24 14:25:23 -04:00
|
|
|
// Move and crop block Entities:
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
2017-06-24 14:25:23 -04:00
|
|
|
auto & be = keyPair.second;
|
2020-04-03 17:23:38 -04:00
|
|
|
auto Pos = be->GetPos();
|
|
|
|
if (CropBox.IsInside(Pos))
|
2017-06-24 14:25:23 -04:00
|
|
|
{
|
|
|
|
// The block entity is within the new coords, recalculate its coords to match the new area:
|
2020-04-03 17:23:38 -04:00
|
|
|
Pos -= AddMin;
|
|
|
|
be->SetPos(Pos);
|
|
|
|
m_BlockEntities->emplace(MakeIndex(Pos.x, Pos.y, Pos.z), std::move(be));
|
2017-06-24 14:25:23 -04:00
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Origin.Move(a_AddMinX, a_AddMinY, a_AddMinZ);
|
|
|
|
m_Size.x -= a_AddMinX + a_SubMaxX;
|
|
|
|
m_Size.y -= a_AddMinY + a_SubMaxY;
|
|
|
|
m_Size.z -= a_AddMinZ + a_SubMaxZ;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
|
|
|
|
{
|
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
|
|
|
ExpandBlockTypes(a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
|
|
|
|
}
|
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
|
|
|
ExpandNibbles(m_BlockMetas, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
|
|
|
|
}
|
|
|
|
if (HasBlockLights())
|
|
|
|
{
|
|
|
|
ExpandNibbles(m_BlockLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
|
|
|
|
}
|
|
|
|
if (HasBlockSkyLights())
|
|
|
|
{
|
|
|
|
ExpandNibbles(m_BlockSkyLight, a_SubMinX, a_AddMaxX, a_SubMinY, a_AddMaxY, a_SubMinZ, a_AddMaxZ);
|
|
|
|
}
|
2017-06-24 14:25:23 -04:00
|
|
|
if (HasBlockEntities())
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
2017-06-24 14:25:23 -04:00
|
|
|
// Move block entities:
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 14:25:23 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto posX = be->GetPosX() + a_SubMinX;
|
|
|
|
auto posY = be->GetPosY() + a_SubMinY;
|
|
|
|
auto posZ = be->GetPosZ() + a_SubMinZ;
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({posX, posY, posZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(MakeIndex(posX, posY, posZ), std::move(be));
|
2017-06-24 14:25:23 -04:00
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Origin.Move(-a_SubMinX, -a_SubMinY, -a_SubMinZ);
|
|
|
|
m_Size.x += a_SubMinX + a_AddMaxX;
|
|
|
|
m_Size.y += a_SubMinY + a_AddMaxY;
|
|
|
|
m_Size.z += a_SubMinZ + a_AddMaxZ;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy)
|
|
|
|
{
|
|
|
|
|
|
|
|
const NIBBLETYPE * SrcMetas = a_Src.GetBlockMetas();
|
2017-09-06 13:40:04 -04:00
|
|
|
NIBBLETYPE * DstMetas = GetBlockMetas();
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
bool IsDummyMetas = ((SrcMetas == nullptr) || (DstMetas == nullptr));
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (IsDummyMetas)
|
|
|
|
{
|
2014-05-05 14:33:21 -04:00
|
|
|
MergeByStrategy<false>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2014-04-28 13:31:07 -04:00
|
|
|
else
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-05-05 14:33:21 -04:00
|
|
|
MergeByStrategy<true>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-24 17:17:12 -05:00
|
|
|
void cBlockArea::Merge(const cBlockArea & a_Src, const Vector3i & a_RelMinCoords, eMergeStrategy a_Strategy)
|
|
|
|
{
|
|
|
|
Merge(a_Src, a_RelMinCoords.x, a_RelMinCoords.y, a_RelMinCoords.z, a_Strategy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight)
|
|
|
|
{
|
|
|
|
if ((a_DataTypes & GetDataTypes()) != a_DataTypes)
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: requested datatypes that are not present in the BlockArea object, trimming those away (req 0x%x, stor 0x%x)",
|
|
|
|
__FUNCTION__, a_DataTypes, GetDataTypes()
|
|
|
|
);
|
|
|
|
a_DataTypes = a_DataTypes & GetDataTypes();
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-05-08 14:16:35 -04:00
|
|
|
size_t BlockCount = GetBlockCount();
|
2013-07-29 07:13:03 -04:00
|
|
|
if ((a_DataTypes & baTypes) != 0)
|
|
|
|
{
|
2014-05-08 14:16:35 -04:00
|
|
|
for (size_t i = 0; i < BlockCount; i++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
m_BlockTypes[i] = a_BlockType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baMetas) != 0)
|
|
|
|
{
|
2014-05-08 14:16:35 -04:00
|
|
|
for (size_t i = 0; i < BlockCount; i++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
m_BlockMetas[i] = a_BlockMeta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baLight) != 0)
|
|
|
|
{
|
2014-05-08 14:16:35 -04:00
|
|
|
for (size_t i = 0; i < BlockCount; i++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
m_BlockLight[i] = a_BlockLight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baSkyLight) != 0)
|
|
|
|
{
|
2014-05-08 14:16:35 -04:00
|
|
|
for (size_t i = 0; i < BlockCount; i++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
m_BlockSkyLight[i] = a_BlockSkyLight;
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// If the area contains block entities, remove those not matching and replace with whatever block entity block was filled
|
|
|
|
if (HasBlockEntities() && ((a_DataTypes & baTypes) != 0))
|
|
|
|
{
|
2017-09-23 12:47:46 -04:00
|
|
|
if (cBlockEntity::IsBlockEntityBlockType(a_BlockType))
|
|
|
|
{
|
|
|
|
RescanBlockEntities();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->clear();
|
2017-09-23 12:47:46 -04:00
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 10:33:09 -04:00
|
|
|
void cBlockArea::FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ,
|
2013-07-29 07:13:03 -04:00
|
|
|
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
|
|
|
|
NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if ((a_DataTypes & GetDataTypes()) != a_DataTypes)
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: requested datatypes that are not present in the BlockArea object, trimming those away (req 0x%x, stor 0x%x)",
|
|
|
|
__FUNCTION__, a_DataTypes, GetDataTypes()
|
|
|
|
);
|
|
|
|
a_DataTypes = a_DataTypes & GetDataTypes();
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if ((a_DataTypes & baTypes) != 0)
|
|
|
|
{
|
|
|
|
for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++)
|
|
|
|
{
|
|
|
|
m_BlockTypes[MakeIndex(x, y, z)] = a_BlockType;
|
|
|
|
} // for x, z, y
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baMetas) != 0)
|
|
|
|
{
|
|
|
|
for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++)
|
|
|
|
{
|
|
|
|
m_BlockMetas[MakeIndex(x, y, z)] = a_BlockMeta;
|
|
|
|
} // for x, z, y
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baLight) != 0)
|
|
|
|
{
|
|
|
|
for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++)
|
|
|
|
{
|
|
|
|
m_BlockLight[MakeIndex(x, y, z)] = a_BlockLight;
|
|
|
|
} // for x, z, y
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baSkyLight) != 0)
|
|
|
|
{
|
|
|
|
for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++)
|
|
|
|
{
|
|
|
|
m_BlockSkyLight[MakeIndex(x, y, z)] = a_BlockSkyLight;
|
|
|
|
} // for x, z, y
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// If the area contains block entities, remove those in the affected cuboid and replace with whatever block entity block was filled:
|
|
|
|
if (HasBlockEntities() && ((a_DataTypes & baTypes) != 0))
|
|
|
|
{
|
2017-09-23 12:47:46 -04:00
|
|
|
if (cBlockEntity::IsBlockEntityBlockType(a_BlockType))
|
|
|
|
{
|
|
|
|
RescanBlockEntities();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->clear();
|
2017-09-23 12:47:46 -04:00
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-24 17:17:12 -05:00
|
|
|
void cBlockArea::FillRelCuboid(const cCuboid & a_RelCuboid,
|
|
|
|
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
|
|
|
|
NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
|
|
|
|
)
|
|
|
|
{
|
|
|
|
FillRelCuboid(
|
|
|
|
a_RelCuboid.p1.x, a_RelCuboid.p2.x,
|
|
|
|
a_RelCuboid.p1.y, a_RelCuboid.p2.y,
|
|
|
|
a_RelCuboid.p1.z, a_RelCuboid.p2.z,
|
|
|
|
a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::RelLine(int a_RelX1, int a_RelY1, int a_RelZ1, int a_RelX2, int a_RelY2, int a_RelZ2,
|
|
|
|
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
|
|
|
|
NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Bresenham-3D algorithm for drawing lines:
|
|
|
|
int dx = abs(a_RelX2 - a_RelX1);
|
|
|
|
int dy = abs(a_RelY2 - a_RelY1);
|
|
|
|
int dz = abs(a_RelZ2 - a_RelZ1);
|
|
|
|
int sx = (a_RelX1 < a_RelX2) ? 1 : -1;
|
|
|
|
int sy = (a_RelY1 < a_RelY2) ? 1 : -1;
|
|
|
|
int sz = (a_RelZ1 < a_RelZ2) ? 1 : -1;
|
|
|
|
|
|
|
|
if (dx >= std::max(dy, dz)) // x dominant
|
|
|
|
{
|
|
|
|
int yd = dy - dx / 2;
|
|
|
|
int zd = dz - dx / 2;
|
|
|
|
|
2014-01-07 08:24:25 -05:00
|
|
|
for (;;)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
RelSetData(a_RelX1, a_RelY1, a_RelZ1, a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight);
|
|
|
|
|
|
|
|
if (a_RelX1 == a_RelX2)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yd >= 0) // move along y
|
|
|
|
{
|
|
|
|
a_RelY1 += sy;
|
|
|
|
yd -= dx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zd >= 0) // move along z
|
|
|
|
{
|
|
|
|
a_RelZ1 += sz;
|
|
|
|
zd -= dx;
|
|
|
|
}
|
|
|
|
|
|
|
|
// move along x
|
|
|
|
a_RelX1 += sx;
|
|
|
|
yd += dy;
|
|
|
|
zd += dz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dy >= std::max(dx, dz)) // y dominant
|
|
|
|
{
|
|
|
|
int xd = dx - dy / 2;
|
|
|
|
int zd = dz - dy / 2;
|
|
|
|
|
2014-01-07 08:24:25 -05:00
|
|
|
for (;;)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
RelSetData(a_RelX1, a_RelY1, a_RelZ1, a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight);
|
|
|
|
|
|
|
|
if (a_RelY1 == a_RelY2)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xd >= 0) // move along x
|
|
|
|
{
|
|
|
|
a_RelX1 += sx;
|
|
|
|
xd -= dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zd >= 0) // move along z
|
|
|
|
{
|
|
|
|
a_RelZ1 += sz;
|
|
|
|
zd -= dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// move along y
|
|
|
|
a_RelY1 += sy;
|
|
|
|
xd += dx;
|
|
|
|
zd += dz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// z dominant
|
|
|
|
ASSERT(dz >= std::max(dx, dy));
|
|
|
|
int xd = dx - dz / 2;
|
|
|
|
int yd = dy - dz / 2;
|
|
|
|
|
2014-01-07 08:24:25 -05:00
|
|
|
for (;;)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
RelSetData(a_RelX1, a_RelY1, a_RelZ1, a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight);
|
|
|
|
|
|
|
|
if (a_RelZ1 == a_RelZ2)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xd >= 0) // move along x
|
|
|
|
{
|
|
|
|
a_RelX1 += sx;
|
|
|
|
xd -= dz;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yd >= 0) // move along y
|
|
|
|
{
|
|
|
|
a_RelY1 += sy;
|
|
|
|
yd -= dz;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// move along z
|
|
|
|
a_RelZ1 += sz;
|
|
|
|
xd += dx;
|
|
|
|
yd += dy;
|
|
|
|
}
|
|
|
|
} // if (which dimension is dominant)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-24 17:17:12 -05:00
|
|
|
void cBlockArea::RelLine(const Vector3i & a_Point1, const Vector3i & a_Point2,
|
|
|
|
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
|
|
|
|
NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
|
|
|
|
)
|
|
|
|
{
|
|
|
|
RelLine(
|
|
|
|
a_Point1.x, a_Point1.y, a_Point1.z,
|
|
|
|
a_Point2.x, a_Point2.y, a_Point2.z,
|
|
|
|
a_DataTypes, a_BlockType, a_BlockMeta, a_BlockLight, a_BlockSkyLight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::RotateCCW(void)
|
|
|
|
{
|
|
|
|
if (!HasBlockTypes())
|
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: Cannot rotate blockmeta without blocktypes!");
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (!HasBlockMetas())
|
|
|
|
{
|
|
|
|
// There are no blockmetas to rotate, just use the NoMeta function
|
|
|
|
RotateCCWNoMeta();
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
|
2017-09-06 13:40:04 -04:00
|
|
|
BLOCKARRAY NewTypes{ new BLOCKTYPE[GetBlockCount()] };
|
|
|
|
NIBBLEARRAY NewMetas{ new NIBBLETYPE[GetBlockCount()] };
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewZ = m_Size.x - x - 1;
|
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
int NewX = z;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto NewIdx = MakeIndexForSize({ NewX, y, NewZ }, { m_Size.z, m_Size.y, m_Size.x });
|
|
|
|
auto OldIdx = MakeIndex(x, y, z);
|
2013-07-29 07:13:03 -04:00
|
|
|
NewTypes[NewIdx] = m_BlockTypes[OldIdx];
|
2020-09-20 09:50:52 -04:00
|
|
|
NewMetas[NewIdx] = cBlockHandler::For(m_BlockTypes[OldIdx]).MetaRotateCCW(m_BlockMetas[OldIdx]);
|
2013-07-29 07:13:03 -04:00
|
|
|
} // for y
|
|
|
|
} // for z
|
|
|
|
} // for x
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockTypes = std::move(NewTypes);
|
|
|
|
m_BlockMetas = std::move(NewMetas);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
// Rotate the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = be->GetPosZ();
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = m_Size.x - be->GetPosX() - 1;
|
|
|
|
auto newIdx = newX + newZ * m_Size.z + newY * m_Size.x * m_Size.z;
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:59:25 -04:00
|
|
|
std::swap(m_Size.x, m_Size.z);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::RotateCW(void)
|
|
|
|
{
|
|
|
|
if (!HasBlockTypes())
|
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: Cannot rotate blockmeta without blocktypes!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasBlockMetas())
|
|
|
|
{
|
|
|
|
// There are no blockmetas to rotate, just use the NoMeta function
|
|
|
|
RotateCWNoMeta();
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// We are guaranteed that both blocktypes and blockmetas exist; rotate both at the same time:
|
2017-09-06 13:40:04 -04:00
|
|
|
BLOCKARRAY NewTypes{ new BLOCKTYPE[GetBlockCount()] };
|
|
|
|
NIBBLEARRAY NewMetas{ new NIBBLETYPE[GetBlockCount()] };
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
int NewZ = x;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewX = m_Size.z - z - 1;
|
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto NewIdx = MakeIndexForSize({ NewX, y, NewZ }, { m_Size.z, m_Size.y, m_Size.x });
|
|
|
|
auto OldIdx = MakeIndex(x, y, z);
|
2013-07-29 07:13:03 -04:00
|
|
|
NewTypes[NewIdx] = m_BlockTypes[OldIdx];
|
2020-09-20 09:50:52 -04:00
|
|
|
NewMetas[NewIdx] = cBlockHandler::For(m_BlockTypes[OldIdx]).MetaRotateCW(m_BlockMetas[OldIdx]);
|
2013-07-29 07:13:03 -04:00
|
|
|
} // for y
|
|
|
|
} // for z
|
|
|
|
} // for x
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockTypes = std::move(NewTypes);
|
|
|
|
m_BlockMetas = std::move(NewMetas);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
// Rotate the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = m_Size.z - be->GetPosZ() - 1;
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = be->GetPosX();
|
|
|
|
auto newIdx = newX + newZ * m_Size.z + newY * m_Size.x * m_Size.z;
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:59:25 -04:00
|
|
|
std::swap(m_Size.x, m_Size.z);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::MirrorXY(void)
|
|
|
|
{
|
|
|
|
if (!HasBlockTypes())
|
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: Cannot mirror meta without blocktypes!");
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (!HasBlockMetas())
|
|
|
|
{
|
|
|
|
// There are no blockmetas to mirror, just use the NoMeta function
|
|
|
|
MirrorXYNoMeta();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
|
2014-03-25 16:59:25 -04:00
|
|
|
int HalfZ = m_Size.z / 2;
|
|
|
|
int MaxZ = m_Size.z - 1;
|
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2018-06-25 12:31:05 -04:00
|
|
|
for (int z = 0; z < HalfZ; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto Idx1 = MakeIndex(x, y, z);
|
|
|
|
auto Idx2 = MakeIndex(x, y, MaxZ - z);
|
2013-07-29 07:13:03 -04:00
|
|
|
std::swap(m_BlockTypes[Idx1], m_BlockTypes[Idx2]);
|
2020-09-20 09:50:52 -04:00
|
|
|
NIBBLETYPE Meta1 = cBlockHandler::For(m_BlockTypes[Idx2]).MetaMirrorXY(m_BlockMetas[Idx1]);
|
|
|
|
NIBBLETYPE Meta2 = cBlockHandler::For(m_BlockTypes[Idx1]).MetaMirrorXY(m_BlockMetas[Idx2]);
|
2013-07-29 07:13:03 -04:00
|
|
|
m_BlockMetas[Idx1] = Meta2;
|
|
|
|
m_BlockMetas[Idx2] = Meta1;
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Mirror the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = be->GetPosX();
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = MaxZ - be->GetPosZ();
|
|
|
|
auto newIdx = MakeIndex(newX, newY, newZ);
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::MirrorXZ(void)
|
|
|
|
{
|
|
|
|
if (!HasBlockTypes())
|
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: Cannot mirror meta without blocktypes!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasBlockMetas())
|
|
|
|
{
|
|
|
|
// There are no blockmetas to mirror, just use the NoMeta function
|
|
|
|
MirrorXZNoMeta();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
|
2014-03-25 16:59:25 -04:00
|
|
|
int HalfY = m_Size.y / 2;
|
|
|
|
int MaxY = m_Size.y - 1;
|
2018-06-25 12:31:05 -04:00
|
|
|
for (int y = 0; y < HalfY; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto Idx1 = MakeIndex(x, y, z);
|
|
|
|
auto Idx2 = MakeIndex(x, MaxY - y, z);
|
2013-07-29 07:13:03 -04:00
|
|
|
std::swap(m_BlockTypes[Idx1], m_BlockTypes[Idx2]);
|
2020-09-20 09:50:52 -04:00
|
|
|
NIBBLETYPE Meta1 = cBlockHandler::For(m_BlockTypes[Idx2]).MetaMirrorXZ(m_BlockMetas[Idx1]);
|
|
|
|
NIBBLETYPE Meta2 = cBlockHandler::For(m_BlockTypes[Idx1]).MetaMirrorXZ(m_BlockMetas[Idx2]);
|
2013-07-29 07:13:03 -04:00
|
|
|
m_BlockMetas[Idx1] = Meta2;
|
|
|
|
m_BlockMetas[Idx2] = Meta1;
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Mirror the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = be->GetPosX();
|
|
|
|
auto newY = MaxY - be->GetPosY();
|
|
|
|
auto newZ = be->GetPosZ();
|
|
|
|
auto newIdx = MakeIndex(newX, newY, newZ);
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::MirrorYZ(void)
|
|
|
|
{
|
|
|
|
if (!HasBlockTypes())
|
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: Cannot mirror meta without blocktypes!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HasBlockMetas())
|
|
|
|
{
|
|
|
|
// There are no blockmetas to mirror, just use the NoMeta function
|
|
|
|
MirrorYZNoMeta();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
|
2014-03-25 16:59:25 -04:00
|
|
|
int HalfX = m_Size.x / 2;
|
|
|
|
int MaxX = m_Size.x - 1;
|
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2018-06-25 12:31:05 -04:00
|
|
|
for (int x = 0; x < HalfX; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto Idx1 = MakeIndex(x, y, z);
|
|
|
|
auto Idx2 = MakeIndex(MaxX - x, y, z);
|
2013-07-29 07:13:03 -04:00
|
|
|
std::swap(m_BlockTypes[Idx1], m_BlockTypes[Idx2]);
|
2020-09-20 09:50:52 -04:00
|
|
|
NIBBLETYPE Meta1 = cBlockHandler::For(m_BlockTypes[Idx2]).MetaMirrorYZ(m_BlockMetas[Idx1]);
|
|
|
|
NIBBLETYPE Meta2 = cBlockHandler::For(m_BlockTypes[Idx1]).MetaMirrorYZ(m_BlockMetas[Idx2]);
|
2013-07-29 07:13:03 -04:00
|
|
|
m_BlockMetas[Idx1] = Meta2;
|
|
|
|
m_BlockMetas[Idx2] = Meta1;
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Mirror the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = MaxX - be->GetPosX();
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = be->GetPosZ();
|
|
|
|
auto newIdx = MakeIndex(newX, newY, newZ);
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::RotateCCWNoMeta(void)
|
|
|
|
{
|
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
BLOCKARRAY NewTypes{ new BLOCKTYPE[GetBlockCount()] };
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewZ = m_Size.x - x - 1;
|
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
int NewX = z;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
NewTypes[MakeIndexForSize({ NewX, y, NewZ }, { m_Size.z, m_Size.y, m_Size.x })] = m_BlockTypes[MakeIndex(x, y, z)];
|
2013-07-29 07:13:03 -04:00
|
|
|
} // for y
|
|
|
|
} // for z
|
|
|
|
} // for x
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockTypes = std::move(NewTypes);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
NIBBLEARRAY NewMetas{ new NIBBLETYPE[GetBlockCount()] };
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewZ = m_Size.x - x - 1;
|
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
int NewX = z;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
NewMetas[MakeIndexForSize({ NewX, y, NewZ }, { m_Size.z, m_Size.y, m_Size.x })] = m_BlockMetas[MakeIndex(x, y, z)];
|
2013-07-29 07:13:03 -04:00
|
|
|
} // for y
|
|
|
|
} // for z
|
|
|
|
} // for x
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockMetas = std::move(NewMetas);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Rotate the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = be->GetPosZ();
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = m_Size.x - be->GetPosX() - 1;
|
|
|
|
auto newIdx = newX + newZ * m_Size.z + newY * m_Size.x * m_Size.z;
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:59:25 -04:00
|
|
|
std::swap(m_Size.x, m_Size.z);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::RotateCWNoMeta(void)
|
|
|
|
{
|
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
BLOCKARRAY NewTypes{ new BLOCKTYPE[GetBlockCount()] };
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewX = m_Size.z - z - 1;
|
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
int NewZ = x;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
NewTypes[MakeIndexForSize({ NewX, y, NewZ }, { m_Size.z, m_Size.y, m_Size.x })] = m_BlockTypes[MakeIndex(x, y, z)];
|
2013-07-29 07:13:03 -04:00
|
|
|
} // for y
|
|
|
|
} // for x
|
|
|
|
} // for z
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockTypes = std::move(NewTypes);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
NIBBLEARRAY NewMetas{ new NIBBLETYPE[GetBlockCount()] };
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewX = m_Size.z - z - 1;
|
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
int NewZ = x;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
NewMetas[MakeIndexForSize({ NewX, y, NewZ }, { m_Size.z, m_Size.y, m_Size.x })] = m_BlockMetas[MakeIndex(x, y, z)];
|
2013-07-29 07:13:03 -04:00
|
|
|
} // for y
|
|
|
|
} // for x
|
|
|
|
} // for z
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockMetas = std::move(NewMetas);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Rotate the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = m_Size.z - be->GetPosZ() - 1;
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = be->GetPosX();
|
|
|
|
auto newIdx = newX + newZ * m_Size.z + newY * m_Size.x * m_Size.z;
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:59:25 -04:00
|
|
|
std::swap(m_Size.x, m_Size.z);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::MirrorXYNoMeta(void)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int HalfZ = m_Size.z / 2;
|
|
|
|
int MaxZ = m_Size.z - 1;
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
for (int z = 0; z < HalfZ; z++)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, y, MaxZ - z)]);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
} // if (HasBlockTypes)
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
for (int z = 0; z < HalfZ; z++)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, y, MaxZ - z)]);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
} // if (HasBlockMetas)
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Mirror the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = be->GetPosX();
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = MaxZ - be->GetPosZ();
|
|
|
|
auto newIdx = MakeIndex(newX, newY, newZ);
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::MirrorXZNoMeta(void)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int HalfY = m_Size.y / 2;
|
|
|
|
int MaxY = m_Size.y - 1;
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
|
|
|
for (int y = 0; y < HalfY; y++)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(x, MaxY - y, z)]);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
} // if (HasBlockTypes)
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
|
|
|
for (int y = 0; y < HalfY; y++)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(x, MaxY - y, z)]);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
} // if (HasBlockMetas)
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Mirror the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = be->GetPosX();
|
|
|
|
auto newY = MaxY - be->GetPosY();
|
|
|
|
auto newZ = be->GetPosZ();
|
|
|
|
auto newIdx = MakeIndex(newX, newY, newZ);
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::MirrorYZNoMeta(void)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int HalfX = m_Size.x / 2;
|
|
|
|
int MaxX = m_Size.x - 1;
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockTypes())
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
for (int x = 0; x < HalfX; x++)
|
|
|
|
{
|
|
|
|
std::swap(m_BlockTypes[MakeIndex(x, y, z)], m_BlockTypes[MakeIndex(MaxX - x, y, z)]);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
} // if (HasBlockTypes)
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
if (HasBlockMetas())
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
for (int x = 0; x < HalfX; x++)
|
|
|
|
{
|
|
|
|
std::swap(m_BlockMetas[MakeIndex(x, y, z)], m_BlockMetas[MakeIndex(MaxX - x, y, z)]);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
} // if (HasBlockMetas)
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Mirror the BlockEntities:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
2020-04-03 17:23:38 -04:00
|
|
|
for (auto & keyPair: oldBE)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
auto & be = keyPair.second;
|
|
|
|
auto newX = MaxX - be->GetPosX();
|
|
|
|
auto newY = be->GetPosY();
|
|
|
|
auto newZ = be->GetPosZ();
|
|
|
|
auto newIdx = MakeIndex(newX, newY, newZ);
|
2019-09-29 08:59:24 -04:00
|
|
|
be->SetPos({newX, newY, newZ});
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(newIdx, std::move(be));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
|
|
|
|
{
|
2017-06-24 05:58:06 -04:00
|
|
|
ASSERT(m_BlockTypes != nullptr);
|
|
|
|
auto idx = MakeIndex(a_RelX, a_RelY, a_RelZ);
|
|
|
|
m_BlockTypes[idx] = a_BlockType;
|
|
|
|
|
|
|
|
// Update the block entities, if appropriate:
|
|
|
|
if (HasBlockEntities())
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2019-09-27 11:51:44 -04:00
|
|
|
auto itr = m_BlockEntities->find(idx);
|
2017-06-24 05:58:06 -04:00
|
|
|
if (itr != m_BlockEntities->end())
|
|
|
|
{
|
|
|
|
if (itr->second->GetBlockType() == a_BlockType)
|
|
|
|
{
|
|
|
|
// The block entity is for the same block type, keep the current one
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_BlockEntities->erase(itr);
|
|
|
|
}
|
|
|
|
if (cBlockEntity::IsBlockEntityBlockType(a_BlockType))
|
|
|
|
{
|
|
|
|
NIBBLETYPE meta = HasBlockMetas() ? m_BlockMetas[idx] : 0;
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(idx, cBlockEntity::CreateByBlockType(a_BlockType, meta, {a_RelX, a_RelY, a_RelZ}));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
SetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
SetRelNibble(a_RelX, a_RelY, a_RelZ, a_BlockMeta, GetBlockMetas());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
SetNibble(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta, GetBlockMetas());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetRelBlockLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockLight)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
SetRelNibble(a_RelX, a_RelY, a_RelZ, a_BlockLight, GetBlockLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockLight)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
SetNibble(a_BlockX, a_BlockY, a_BlockZ, a_BlockLight, GetBlockLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockSkyLight)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
SetRelNibble(a_RelX, a_RelY, a_RelZ, a_BlockSkyLight, GetBlockSkyLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_BlockSkyLight)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
SetNibble(a_BlockX, a_BlockY, a_BlockZ, a_BlockSkyLight, GetBlockSkyLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BLOCKTYPE cBlockArea::GetRelBlockType(int a_RelX, int a_RelY, int a_RelZ) const
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockTypes == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: BlockTypes have not been read!");
|
|
|
|
return E_BLOCK_AIR;
|
|
|
|
}
|
|
|
|
return m_BlockTypes[MakeIndex(a_RelX, a_RelY, a_RelZ)];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BLOCKTYPE cBlockArea::GetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ) const
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
return GetRelBlockType(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetRelBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
return GetRelNibble(a_RelX, a_RelY, a_RelZ, GetBlockMetas());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ) const
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
return GetNibble(a_BlockX, a_BlockY, a_BlockZ, GetBlockMetas());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetRelBlockLight(int a_RelX, int a_RelY, int a_RelZ) const
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
return GetRelNibble(a_RelX, a_RelY, a_RelZ, GetBlockLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ) const
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
return GetNibble(a_BlockX, a_BlockY, a_BlockZ, GetBlockLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetRelBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ) const
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
return GetRelNibble(a_RelX, a_RelY, a_RelZ, GetBlockSkyLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ) const
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
return GetNibble(a_BlockX, a_BlockY, a_BlockZ, GetBlockSkyLight());
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
SetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto idx = MakeIndex(a_RelX, a_RelY, a_RelZ);
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockTypes == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("%s: BlockTypes not available but requested to be written to.", __FUNCTION__);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_BlockTypes[idx] = a_BlockType;
|
|
|
|
}
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockMetas == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("%s: BlockMetas not available but requested to be written to.", __FUNCTION__);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_BlockMetas[idx] = a_BlockMeta;
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Update the block entities, if appropriate:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
2019-09-27 11:51:44 -04:00
|
|
|
auto itr = m_BlockEntities->find(idx);
|
2017-06-24 05:58:06 -04:00
|
|
|
if (itr != m_BlockEntities->end())
|
|
|
|
{
|
|
|
|
if (itr->second->GetBlockType() == a_BlockType)
|
|
|
|
{
|
|
|
|
// The block entity is for the same block type, keep the current one
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_BlockEntities->erase(itr);
|
|
|
|
}
|
|
|
|
if (cBlockEntity::IsBlockEntityBlockType(a_BlockType))
|
|
|
|
{
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(idx, cBlockEntity::CreateByBlockType(a_BlockType, a_BlockMeta, {a_RelX, a_RelY, a_RelZ}));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
return GetRelBlockTypeMeta(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_BlockType, a_BlockMeta);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::GetRelBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const
|
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto idx = MakeIndex(a_RelX, a_RelY, a_RelZ);
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockTypes == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: BlockTypes have not been read!");
|
|
|
|
a_BlockType = E_BLOCK_AIR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_BlockType = m_BlockTypes[idx];
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockMetas == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: BlockMetas have not been read!");
|
|
|
|
a_BlockMeta = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_BlockMeta = m_BlockMetas[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-22 13:56:56 -04:00
|
|
|
cCuboid cBlockArea::GetBounds(void) const
|
|
|
|
{
|
|
|
|
return cCuboid(
|
2017-08-17 09:48:38 -04:00
|
|
|
m_Origin,
|
|
|
|
m_Origin + m_Size - Vector3i(1, 1, 1)
|
2017-07-22 13:56:56 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-30 17:16:33 -04:00
|
|
|
size_t cBlockArea::CountNonAirBlocks(void) const
|
|
|
|
{
|
|
|
|
// Check if blocktypes are valid:
|
|
|
|
if (m_BlockTypes == nullptr)
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: BlockTypes have not been read!", __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count the blocks:
|
|
|
|
size_t res = 0;
|
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
|
|
|
{
|
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
|
|
|
{
|
|
|
|
if (m_BlockTypes[MakeIndex(x, y, z)] != E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
++res;
|
|
|
|
}
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-08 15:52:13 -04:00
|
|
|
size_t cBlockArea::CountSpecificBlocks(BLOCKTYPE a_BlockType) const
|
|
|
|
{
|
|
|
|
// If blocktypes are not valid, log a warning and return zero occurences:
|
|
|
|
if (m_BlockTypes == nullptr)
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: BlockTypes not available!", __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count the blocks:
|
|
|
|
size_t num = GetBlockCount();
|
|
|
|
size_t res = 0;
|
|
|
|
for (size_t i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if (m_BlockTypes[i] == a_BlockType)
|
|
|
|
{
|
|
|
|
res++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t cBlockArea::CountSpecificBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) const
|
|
|
|
{
|
|
|
|
// If blocktypes are not valid, log a warning and return zero occurences:
|
|
|
|
if (m_BlockTypes == nullptr)
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: BlockTypes not available!", __FUNCTION__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If blockmetas are not valid, log a warning and count only blocktypes:
|
|
|
|
if (m_BlockMetas == nullptr)
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: BlockMetas not available, comparing blocktypes only!", __FUNCTION__);
|
|
|
|
return CountSpecificBlocks(a_BlockType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count the blocks:
|
|
|
|
size_t num = GetBlockCount();
|
|
|
|
size_t res = 0;
|
|
|
|
for (size_t i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if ((m_BlockTypes[i] == a_BlockType) && (m_BlockMetas[i] == a_BlockMeta))
|
|
|
|
{
|
|
|
|
res++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 09:14:22 -04:00
|
|
|
void cBlockArea::GetNonAirCropRelCoords(int & a_MinRelX, int & a_MinRelY, int & a_MinRelZ, int & a_MaxRelX, int & a_MaxRelY, int & a_MaxRelZ, BLOCKTYPE a_IgnoreBlockType)
|
|
|
|
{
|
|
|
|
// Check if blocktypes are valid:
|
|
|
|
if (m_BlockTypes == nullptr)
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: BlockTypes have not been read!", __FUNCTION__);
|
|
|
|
a_MinRelX = 1;
|
|
|
|
a_MaxRelX = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk all the blocks and find the min and max coords for the non-ignored ones:
|
|
|
|
int MaxX = 0, MinX = m_Size.x - 1;
|
|
|
|
int MaxY = 0, MinY = m_Size.y - 1;
|
|
|
|
int MaxZ = 0, MinZ = m_Size.z - 1;
|
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
|
|
|
{
|
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
|
|
|
{
|
|
|
|
if (m_BlockTypes[MakeIndex(x, y, z)] == a_IgnoreBlockType)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// The block is not ignored, update any coords that need updating:
|
|
|
|
if (x < MinX)
|
|
|
|
{
|
|
|
|
MinX = x;
|
|
|
|
}
|
|
|
|
if (x > MaxX)
|
|
|
|
{
|
|
|
|
MaxX = x;
|
|
|
|
}
|
|
|
|
if (y < MinY)
|
|
|
|
{
|
|
|
|
MinY = y;
|
|
|
|
}
|
|
|
|
if (y > MaxY)
|
|
|
|
{
|
|
|
|
MaxY = y;
|
|
|
|
}
|
|
|
|
if (z < MinZ)
|
|
|
|
{
|
|
|
|
MinZ = z;
|
|
|
|
}
|
|
|
|
if (z > MaxZ)
|
|
|
|
{
|
|
|
|
MaxZ = z;
|
|
|
|
}
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
|
|
|
|
// Assign to the output:
|
|
|
|
a_MinRelX = MinX;
|
|
|
|
a_MinRelY = MinY;
|
|
|
|
a_MinRelZ = MinZ;
|
|
|
|
a_MaxRelX = MaxX;
|
|
|
|
a_MaxRelY = MaxY;
|
|
|
|
a_MaxRelZ = MaxZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
int cBlockArea::GetDataTypes(void) const
|
|
|
|
{
|
|
|
|
int res = 0;
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockTypes != nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
res |= baTypes;
|
|
|
|
}
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockMetas != nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
res |= baMetas;
|
|
|
|
}
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockLight != nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
res |= baLight;
|
|
|
|
}
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_BlockSkyLight != nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
res |= baSkyLight;
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
if (m_BlockEntities != nullptr)
|
|
|
|
{
|
|
|
|
res |= baBlockEntities;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
|
|
|
|
{
|
2017-06-24 05:58:06 -04:00
|
|
|
ASSERT(IsValidDataTypeCombination(a_DataTypes));
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-09-06 13:40:04 -04:00
|
|
|
BLOCKARRAY NewBlocks;
|
|
|
|
NIBBLEARRAY NewMetas;
|
|
|
|
NIBBLEARRAY NewLight;
|
|
|
|
NIBBLEARRAY NewSkyLight;
|
|
|
|
cBlockEntitiesPtr NewBlockEntities;
|
|
|
|
|
|
|
|
// Try to allocate the new storage
|
2017-06-24 05:58:06 -04:00
|
|
|
if ((a_DataTypes & baTypes) != 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-05-09 11:51:54 -04:00
|
|
|
NewBlocks.reset(new BLOCKTYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
2017-09-06 13:40:04 -04:00
|
|
|
if (NewBlocks == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
if ((a_DataTypes & baMetas) != 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-05-09 11:51:54 -04:00
|
|
|
NewMetas.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
2017-09-06 13:40:04 -04:00
|
|
|
if (NewMetas == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
if ((a_DataTypes & baLight) != 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-05-09 11:51:54 -04:00
|
|
|
NewLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
2017-09-06 13:40:04 -04:00
|
|
|
if (NewLight == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
if ((a_DataTypes & baSkyLight) != 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-05-09 11:51:54 -04:00
|
|
|
NewSkyLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
2017-09-06 13:40:04 -04:00
|
|
|
if (NewSkyLight == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
if ((a_DataTypes & baBlockEntities) != 0)
|
|
|
|
{
|
2017-09-06 13:40:04 -04:00
|
|
|
NewBlockEntities.reset(new cBlockEntities);
|
|
|
|
if (NewBlockEntities == nullptr)
|
|
|
|
{
|
2017-06-24 05:58:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-09-06 13:40:04 -04:00
|
|
|
|
|
|
|
// Commit changes
|
|
|
|
m_BlockTypes = std::move(NewBlocks);
|
|
|
|
m_BlockMetas = std::move(NewMetas);
|
|
|
|
m_BlockLight = std::move(NewLight);
|
|
|
|
m_BlockSkyLight = std::move(NewSkyLight);
|
|
|
|
m_BlockEntities = std::move(NewBlockEntities);
|
2014-03-25 16:59:25 -04:00
|
|
|
m_Size.Set(a_SizeX, a_SizeY, a_SizeZ);
|
2013-07-29 07:13:03 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-07 04:40:58 -04:00
|
|
|
size_t cBlockArea::MakeIndexForSize(Vector3i a_RelPos, Vector3i a_Size)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
ASSERT(a_RelPos.x >= 0);
|
|
|
|
ASSERT(a_RelPos.x < a_Size.x);
|
|
|
|
ASSERT(a_RelPos.y >= 0);
|
|
|
|
ASSERT(a_RelPos.y < a_Size.y);
|
|
|
|
ASSERT(a_RelPos.z >= 0);
|
|
|
|
ASSERT(a_RelPos.z < a_Size.z);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-09-07 04:40:58 -04:00
|
|
|
return static_cast<size_t>(a_RelPos.x + a_RelPos.z * a_Size.x + a_RelPos.y * a_Size.x * a_Size.z);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
bool cBlockArea::DoWithBlockEntityRelAt(int a_RelX, int a_RelY, int a_RelZ, cBlockEntityCallback a_Callback)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
ASSERT(IsValidRelCoords(a_RelX, a_RelY, a_RelZ));
|
|
|
|
if (!HasBlockEntities())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-27 11:51:44 -04:00
|
|
|
auto idx = MakeIndex(a_RelX, a_RelY, a_RelZ);
|
2017-06-24 05:58:06 -04:00
|
|
|
auto itr = m_BlockEntities->find(idx);
|
|
|
|
if (itr == m_BlockEntities->end())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-11 17:20:49 -04:00
|
|
|
return a_Callback(*itr->second);
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
bool cBlockArea::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback a_Callback)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
return DoWithBlockEntityRelAt(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
bool cBlockArea::ForEachBlockEntity(cBlockEntityCallback a_Callback)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
if (!HasBlockEntities())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (auto & keyPair: *m_BlockEntities)
|
|
|
|
{
|
2017-09-11 17:20:49 -04:00
|
|
|
if (a_Callback(*keyPair.second))
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::SetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (a_Array == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: datatype has not been read!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
a_Array[MakeIndex(a_RelX, a_RelY, a_RelZ)] = a_Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::SetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Value, NIBBLETYPE * a_Array)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
SetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Value, a_Array);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE * a_Array) const
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (a_Array == nullptr)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("cBlockArea: datatype has not been read!");
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
return a_Array[MakeIndex(a_RelX, a_RelY, a_RelZ)];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NIBBLETYPE cBlockArea::GetNibble(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
return GetRelNibble(a_BlockX - m_Origin.x, a_BlockY - m_Origin.y, a_BlockZ - m_Origin.z, a_Array);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
void cBlockArea::CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2017-06-24 05:58:06 -04:00
|
|
|
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
|
|
|
|
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
|
|
|
|
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
|
2020-05-09 11:51:54 -04:00
|
|
|
BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
|
2017-09-07 04:40:58 -04:00
|
|
|
size_t idx = 0;
|
2017-06-24 05:58:06 -04:00
|
|
|
for (int y = 0; y < NewSizeY; y++)
|
|
|
|
{
|
|
|
|
for (int z = 0; z < NewSizeZ; z++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < NewSizeX; x++)
|
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto OldIndex = MakeIndex(x + a_AddMinX, y + a_AddMinY, z + a_AddMinZ);
|
2017-06-24 05:58:06 -04:00
|
|
|
NewBlockTypes[idx++] = m_BlockTypes[OldIndex];
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockTypes = std::move(NewBlockTypes);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
|
|
|
|
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
|
|
|
|
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
|
2020-05-09 11:51:54 -04:00
|
|
|
NIBBLEARRAY NewNibbles{ new NIBBLETYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
|
2017-09-07 04:40:58 -04:00
|
|
|
size_t idx = 0;
|
2013-07-29 07:13:03 -04:00
|
|
|
for (int y = 0; y < NewSizeY; y++)
|
|
|
|
{
|
|
|
|
for (int z = 0; z < NewSizeZ; z++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < NewSizeX; x++)
|
|
|
|
{
|
|
|
|
NewNibbles[idx++] = a_Array[MakeIndex(x + a_AddMinX, y + a_AddMinY, z + a_AddMinZ)];
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
2017-09-06 13:40:04 -04:00
|
|
|
a_Array = std::move(NewNibbles);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::ExpandBlockTypes(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX;
|
|
|
|
int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY;
|
|
|
|
int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ;
|
2015-05-24 07:56:56 -04:00
|
|
|
size_t BlockCount = static_cast<size_t>(NewSizeX * NewSizeY * NewSizeZ);
|
2017-09-06 13:40:04 -04:00
|
|
|
BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[BlockCount] };
|
|
|
|
memset(NewBlockTypes.get(), 0, BlockCount * sizeof(BLOCKTYPE));
|
2017-09-07 04:40:58 -04:00
|
|
|
size_t OldIndex = 0;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z;
|
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x;
|
2017-09-07 04:40:58 -04:00
|
|
|
auto idx = static_cast<size_t>(IndexBaseZ + a_SubMinX);
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
NewBlockTypes[idx++] = m_BlockTypes[OldIndex++];
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
2017-09-06 13:40:04 -04:00
|
|
|
m_BlockTypes = std::move(NewBlockTypes);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::ExpandNibbles(NIBBLEARRAY & a_Array, int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
|
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int NewSizeX = m_Size.x + a_SubMinX + a_AddMaxX;
|
|
|
|
int NewSizeY = m_Size.y + a_SubMinY + a_AddMaxY;
|
|
|
|
int NewSizeZ = m_Size.z + a_SubMinZ + a_AddMaxZ;
|
2015-05-24 07:56:56 -04:00
|
|
|
size_t BlockCount = static_cast<size_t>(NewSizeX * NewSizeY * NewSizeZ);
|
2017-09-06 13:40:04 -04:00
|
|
|
NIBBLEARRAY NewNibbles{ new NIBBLETYPE[BlockCount] };
|
|
|
|
memset(NewNibbles.get(), 0, BlockCount * sizeof(NIBBLETYPE));
|
2017-09-07 04:40:58 -04:00
|
|
|
size_t OldIndex = 0;
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int y = 0; y < m_Size.y; y++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int IndexBaseY = (y + a_SubMinY) * m_Size.x * m_Size.z;
|
|
|
|
for (int z = 0; z < m_Size.z; z++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-25 16:59:25 -04:00
|
|
|
int IndexBaseZ = IndexBaseY + (z + a_SubMinZ) * m_Size.x;
|
2017-09-07 04:40:58 -04:00
|
|
|
auto idx = static_cast<size_t>(IndexBaseZ + a_SubMinX);
|
2014-03-25 16:59:25 -04:00
|
|
|
for (int x = 0; x < m_Size.x; x++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
NewNibbles[idx++] = a_Array[OldIndex++];
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
2017-09-06 13:40:04 -04:00
|
|
|
a_Array = std::move(NewNibbles);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-25 16:59:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
void cBlockArea::RelSetData(
|
|
|
|
int a_RelX, int a_RelY, int a_RelZ,
|
|
|
|
int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
|
|
|
|
NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
|
|
|
|
)
|
|
|
|
{
|
2017-06-24 05:58:06 -04:00
|
|
|
if (!IsValidCoords(a_RelX, a_RelY, a_RelZ))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-07 04:40:58 -04:00
|
|
|
auto Index = MakeIndex(a_RelX, a_RelY, a_RelZ);
|
2013-07-29 07:13:03 -04:00
|
|
|
if ((a_DataTypes & baTypes) != 0)
|
|
|
|
{
|
|
|
|
m_BlockTypes[Index] = a_BlockType;
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baMetas) != 0)
|
|
|
|
{
|
|
|
|
m_BlockMetas[Index] = a_BlockMeta;
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baLight) != 0)
|
|
|
|
{
|
|
|
|
m_BlockLight[Index] = a_BlockLight;
|
|
|
|
}
|
|
|
|
if ((a_DataTypes & baSkyLight) != 0)
|
|
|
|
{
|
|
|
|
m_BlockSkyLight[Index] = a_BlockSkyLight;
|
|
|
|
}
|
2017-06-24 05:58:06 -04:00
|
|
|
|
|
|
|
// Update the block entities, if appropriate:
|
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
2019-09-27 11:51:44 -04:00
|
|
|
auto itr = m_BlockEntities->find(Index);
|
2017-06-24 05:58:06 -04:00
|
|
|
if (itr != m_BlockEntities->end())
|
|
|
|
{
|
|
|
|
if (itr->second->GetBlockType() == a_BlockType)
|
|
|
|
{
|
|
|
|
// The block entity is for the same block type, keep the current one
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// The block entity is for a different block type, remove it:
|
|
|
|
m_BlockEntities->erase(itr);
|
|
|
|
}
|
|
|
|
if (cBlockEntity::IsBlockEntityBlockType(a_BlockType))
|
|
|
|
{
|
|
|
|
// The block type should have a block entity attached to it, create an empty one:
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(Index, cBlockEntity::CreateByBlockType(a_BlockType, a_BlockMeta, {a_RelX, a_RelY, a_RelZ}));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 09:45:48 -04:00
|
|
|
|
|
|
|
|
2014-08-28 09:58:48 -04:00
|
|
|
template <bool MetasValid>
|
2014-04-28 13:31:07 -04:00
|
|
|
void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy, const NIBBLETYPE * SrcMetas, NIBBLETYPE * DstMetas)
|
|
|
|
{
|
2015-04-29 09:45:48 -04:00
|
|
|
// Block types are compulsory, block metas are optional
|
2014-04-28 13:31:07 -04:00
|
|
|
if (!HasBlockTypes() || !a_Src.HasBlockTypes())
|
|
|
|
{
|
|
|
|
LOGWARNING("%s: cannot merge because one of the areas doesn't have blocktypes.", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-28 13:31:07 -04:00
|
|
|
// Dst is *this, Src is a_Src
|
|
|
|
int SrcOffX = std::max(0, -a_RelX); // Offset in Src where to start reading
|
|
|
|
int DstOffX = std::max(0, a_RelX); // Offset in Dst where to start writing
|
|
|
|
int SizeX = std::min(a_Src.GetSizeX() - SrcOffX, GetSizeX() - DstOffX); // How many blocks to copy
|
|
|
|
|
|
|
|
int SrcOffY = std::max(0, -a_RelY); // Offset in Src where to start reading
|
|
|
|
int DstOffY = std::max(0, a_RelY); // Offset in Dst where to start writing
|
|
|
|
int SizeY = std::min(a_Src.GetSizeY() - SrcOffY, GetSizeY() - DstOffY); // How many blocks to copy
|
|
|
|
|
|
|
|
int SrcOffZ = std::max(0, -a_RelZ); // Offset in Src where to start reading
|
|
|
|
int DstOffZ = std::max(0, a_RelZ); // Offset in Dst where to start writing
|
|
|
|
int SizeZ = std::min(a_Src.GetSizeZ() - SrcOffZ, GetSizeZ() - DstOffZ); // How many blocks to copy
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2018-02-04 18:07:12 -05:00
|
|
|
[&]
|
|
|
|
{
|
|
|
|
switch (a_Strategy)
|
|
|
|
{
|
|
|
|
case cBlockArea::msOverwrite:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorOverwrite<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msOverwrite
|
|
|
|
|
|
|
|
case cBlockArea::msFillAir:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorFillAir<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msFillAir
|
|
|
|
|
|
|
|
case cBlockArea::msImprint:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorImprint<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msImprint
|
|
|
|
|
|
|
|
case cBlockArea::msLake:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorLake<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msLake
|
|
|
|
|
|
|
|
case cBlockArea::msSpongePrint:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorSpongePrint<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msSpongePrint
|
|
|
|
|
|
|
|
case cBlockArea::msDifference:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorDifference<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msDifference
|
|
|
|
|
|
|
|
case cBlockArea::msSimpleCompare:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorSimpleCompare<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msSimpleCompare
|
|
|
|
|
|
|
|
case cBlockArea::msMask:
|
|
|
|
{
|
|
|
|
InternalMergeBlocks<MetasValid, MergeCombinatorMask<MetasValid> >(
|
|
|
|
GetBlockTypes(), a_Src.GetBlockTypes(),
|
|
|
|
DstMetas, SrcMetas,
|
|
|
|
SizeX, SizeY, SizeZ,
|
|
|
|
SrcOffX, SrcOffY, SrcOffZ,
|
|
|
|
DstOffX, DstOffY, DstOffZ,
|
|
|
|
a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(),
|
|
|
|
m_Size.x, m_Size.y, m_Size.z
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} // case msMask
|
|
|
|
} // switch (a_Strategy)
|
|
|
|
UNREACHABLE("Unsupported block area merge strategy");
|
|
|
|
}();
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
if (HasBlockEntities())
|
|
|
|
{
|
|
|
|
if (a_Src.HasBlockEntities())
|
|
|
|
{
|
|
|
|
MergeBlockEntities(a_RelX, a_RelY, a_RelZ, a_Src);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RescanBlockEntities();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::MergeBlockEntities(int a_RelX, int a_RelY, int a_RelZ, const cBlockArea & a_Src)
|
|
|
|
{
|
|
|
|
// Only supported with both BlockEntities and BlockTypes (caller should check):
|
|
|
|
ASSERT(HasBlockTypes());
|
|
|
|
ASSERT(HasBlockEntities());
|
|
|
|
ASSERT(a_Src.HasBlockTypes());
|
|
|
|
ASSERT(a_Src.HasBlockEntities());
|
|
|
|
|
|
|
|
// Remove block entities that no longer match the block at their coords:
|
|
|
|
RemoveNonMatchingBlockEntities();
|
|
|
|
|
|
|
|
// Clone BEs from a_Src wherever a BE is missing:
|
|
|
|
for (int y = 0; y < m_Size.y; ++y) for (int z = 0; z < m_Size.z; ++z) for (int x = 0; x < m_Size.x; ++x)
|
|
|
|
{
|
|
|
|
auto idx = MakeIndex(x, y, z);
|
|
|
|
auto type = m_BlockTypes[idx];
|
|
|
|
if (!cBlockEntity::IsBlockEntityBlockType(type))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This block should have a block entity, check that there is one:
|
2019-09-27 11:51:44 -04:00
|
|
|
auto itr = m_BlockEntities->find(idx);
|
2017-06-24 05:58:06 -04:00
|
|
|
if (itr != m_BlockEntities->end())
|
|
|
|
{
|
|
|
|
// There is one already
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy a BE from a_Src, if it exists there:
|
|
|
|
auto srcX = x + a_RelX;
|
|
|
|
auto srcY = y + a_RelY;
|
|
|
|
auto srcZ = z + a_RelZ;
|
|
|
|
if (a_Src.IsValidRelCoords(srcX, srcY, srcZ))
|
|
|
|
{
|
|
|
|
auto srcIdx = a_Src.MakeIndex(srcX, srcY, srcZ);
|
2019-09-27 11:51:44 -04:00
|
|
|
auto itrSrc = a_Src.m_BlockEntities->find(srcIdx);
|
2017-07-21 22:10:39 -04:00
|
|
|
if (itrSrc != a_Src.m_BlockEntities->end())
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(idx, itrSrc->second->Clone({x, y, z}));
|
2017-06-24 05:58:06 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// No BE found in a_Src, insert a new empty one:
|
|
|
|
NIBBLETYPE meta = HasBlockMetas() ? m_BlockMetas[idx] : 0;
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(idx, cBlockEntity::CreateByBlockType(type, meta, {x, y, z}));
|
2017-06-24 05:58:06 -04:00
|
|
|
} // for x, z, y
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::RescanBlockEntities(void)
|
|
|
|
{
|
|
|
|
// Only supported with both BlockEntities and BlockTypes
|
|
|
|
if (!HasBlockEntities() || !HasBlockTypes())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove block entities that no longer match the block at their coords:
|
|
|
|
RemoveNonMatchingBlockEntities();
|
|
|
|
|
|
|
|
// Add block entities for all block types that should have a BE assigned to them:
|
|
|
|
for (int y = 0; y < m_Size.y; ++y) for (int z = 0; z < m_Size.z; ++z) for (int x = 0; x < m_Size.x; ++x)
|
|
|
|
{
|
|
|
|
auto idx = MakeIndex(x, y, z);
|
|
|
|
auto type = m_BlockTypes[idx];
|
|
|
|
if (!cBlockEntity::IsBlockEntityBlockType(type))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// This block should have a block entity, check that there is one:
|
2019-09-27 11:51:44 -04:00
|
|
|
auto itr = m_BlockEntities->find(idx);
|
2017-06-24 05:58:06 -04:00
|
|
|
if (itr != m_BlockEntities->end())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Create a new BE for this block:
|
|
|
|
NIBBLETYPE meta = HasBlockMetas() ? m_BlockMetas[idx] : 0;
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->emplace(idx, cBlockEntity::CreateByBlockType(type, meta, {x, y, z}));
|
2017-06-24 05:58:06 -04:00
|
|
|
} // for x, z, y
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::RemoveNonMatchingBlockEntities(void)
|
|
|
|
{
|
|
|
|
// Only supported with both BlockEntities and BlockTypes:
|
|
|
|
ASSERT(HasBlockTypes());
|
|
|
|
ASSERT(HasBlockEntities());
|
|
|
|
|
|
|
|
cBlockEntities oldBE;
|
|
|
|
std::swap(oldBE, *m_BlockEntities);
|
|
|
|
for (auto & keyPair: oldBE)
|
|
|
|
{
|
2017-09-07 04:40:58 -04:00
|
|
|
auto type = m_BlockTypes[static_cast<size_t>(keyPair.first)];
|
2017-06-24 05:58:06 -04:00
|
|
|
if (type == keyPair.second->GetBlockType())
|
|
|
|
{
|
2020-04-03 17:23:38 -04:00
|
|
|
m_BlockEntities->insert(std::move(keyPair));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
cBlockEntity * cBlockArea::GetBlockEntityRel(Vector3i a_RelPos)
|
|
|
|
{
|
|
|
|
if (!HasBlockEntities())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto itr = m_BlockEntities->find(MakeIndex(a_RelPos));
|
2020-04-03 17:23:38 -04:00
|
|
|
return (itr == m_BlockEntities->end()) ? nullptr : itr->second.get();
|
2017-09-06 13:40:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cBlockArea::cChunkReader:
|
|
|
|
|
|
|
|
cBlockArea::cChunkReader::cChunkReader(cBlockArea & a_Area) :
|
|
|
|
m_Area(a_Area),
|
2017-07-10 05:10:06 -04:00
|
|
|
m_AreaBounds(cCuboid(a_Area.GetOrigin(), a_Area.GetOrigin() + a_Area.GetSize() - Vector3i(1, 1, 1))),
|
2017-06-24 05:58:06 -04:00
|
|
|
m_Origin(a_Area.m_Origin.x, a_Area.m_Origin.y, a_Area.m_Origin.z),
|
|
|
|
m_CurrentChunkX(0),
|
|
|
|
m_CurrentChunkZ(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBlockArea::cChunkReader::CopyNibbles(NIBBLETYPE * a_AreaDst, const NIBBLETYPE * a_ChunkSrc)
|
|
|
|
{
|
|
|
|
int SizeY = m_Area.m_Size.y;
|
|
|
|
int MinY = m_Origin.y;
|
|
|
|
|
|
|
|
// SizeX, SizeZ are the dmensions of the block data to copy from the current chunk (size of the geometric union)
|
|
|
|
// OffX, OffZ are the offsets of the current chunk data from the area origin
|
|
|
|
// BaseX, BaseZ are the offsets of the area data within the current chunk from the chunk borders
|
|
|
|
int SizeX = cChunkDef::Width;
|
|
|
|
int SizeZ = cChunkDef::Width;
|
|
|
|
int OffX, OffZ;
|
|
|
|
int BaseX, BaseZ;
|
|
|
|
OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x;
|
|
|
|
if (OffX < 0)
|
|
|
|
{
|
|
|
|
BaseX = -OffX;
|
|
|
|
SizeX += OffX; // SizeX is decreased, OffX is negative
|
|
|
|
OffX = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BaseX = 0;
|
|
|
|
}
|
|
|
|
OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z;
|
|
|
|
if (OffZ < 0)
|
|
|
|
{
|
|
|
|
BaseZ = -OffZ;
|
|
|
|
SizeZ += OffZ; // SizeZ is decreased, OffZ is negative
|
|
|
|
OffZ = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BaseZ = 0;
|
|
|
|
}
|
|
|
|
// If the chunk extends beyond the area in the X or Z axis, cut off the Size:
|
|
|
|
if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x)
|
|
|
|
{
|
|
|
|
SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x);
|
|
|
|
}
|
|
|
|
if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z)
|
|
|
|
{
|
|
|
|
SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = 0; y < SizeY; y++)
|
|
|
|
{
|
|
|
|
int ChunkY = MinY + y;
|
|
|
|
int AreaY = y;
|
|
|
|
for (int z = 0; z < SizeZ; z++)
|
|
|
|
{
|
|
|
|
int ChunkZ = BaseZ + z;
|
|
|
|
int AreaZ = OffZ + z;
|
|
|
|
for (int x = 0; x < SizeX; x++)
|
|
|
|
{
|
|
|
|
int ChunkX = BaseX + x;
|
|
|
|
int AreaX = OffX + x;
|
|
|
|
a_AreaDst[m_Area.MakeIndex(AreaX, AreaY, AreaZ)] = cChunkDef::GetNibble(a_ChunkSrc, ChunkX, ChunkY, ChunkZ);
|
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBlockArea::cChunkReader::Coords(int a_ChunkX, int a_ChunkZ)
|
|
|
|
{
|
|
|
|
m_CurrentChunkX = a_ChunkX;
|
|
|
|
m_CurrentChunkZ = a_ChunkZ;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-05 08:03:55 -05:00
|
|
|
void cBlockArea::cChunkReader::ChunkData(const ChunkBlockData & a_BlockData, const ChunkLightData & a_LightData)
|
2017-06-24 05:58:06 -04:00
|
|
|
{
|
|
|
|
int SizeY = m_Area.m_Size.y;
|
|
|
|
int MinY = m_Origin.y;
|
|
|
|
|
|
|
|
// SizeX, SizeZ are the dimensions of the block data to copy from the current chunk (size of the geometric union)
|
|
|
|
// OffX, OffZ are the offsets of the current chunk data from the area origin
|
|
|
|
// BaseX, BaseZ are the offsets of the area data within the current chunk from the chunk borders
|
|
|
|
int SizeX = cChunkDef::Width;
|
|
|
|
int SizeZ = cChunkDef::Width;
|
|
|
|
int OffX, OffZ;
|
|
|
|
int BaseX, BaseZ;
|
|
|
|
OffX = m_CurrentChunkX * cChunkDef::Width - m_Origin.x;
|
|
|
|
if (OffX < 0)
|
|
|
|
{
|
|
|
|
BaseX = -OffX;
|
|
|
|
SizeX += OffX; // SizeX is decreased, OffX is negative
|
|
|
|
OffX = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BaseX = 0;
|
|
|
|
}
|
|
|
|
OffZ = m_CurrentChunkZ * cChunkDef::Width - m_Origin.z;
|
|
|
|
if (OffZ < 0)
|
|
|
|
{
|
|
|
|
BaseZ = -OffZ;
|
|
|
|
SizeZ += OffZ; // SizeZ is decreased, OffZ is negative
|
|
|
|
OffZ = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BaseZ = 0;
|
|
|
|
}
|
|
|
|
// If the chunk extends beyond the area in the X or Z axis, cut off the Size:
|
|
|
|
if ((m_CurrentChunkX + 1) * cChunkDef::Width > m_Origin.x + m_Area.m_Size.x)
|
|
|
|
{
|
|
|
|
SizeX -= (m_CurrentChunkX + 1) * cChunkDef::Width - (m_Origin.x + m_Area.m_Size.x);
|
|
|
|
}
|
|
|
|
if ((m_CurrentChunkZ + 1) * cChunkDef::Width > m_Origin.z + m_Area.m_Size.z)
|
|
|
|
{
|
|
|
|
SizeZ -= (m_CurrentChunkZ + 1) * cChunkDef::Width - (m_Origin.z + m_Area.m_Size.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the blocktypes:
|
|
|
|
if (m_Area.m_BlockTypes != nullptr)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < SizeY; y++)
|
|
|
|
{
|
|
|
|
int InChunkY = MinY + y;
|
|
|
|
int AreaY = y;
|
|
|
|
for (int z = 0; z < SizeZ; z++)
|
|
|
|
{
|
|
|
|
int InChunkZ = BaseZ + z;
|
|
|
|
int AreaZ = OffZ + z;
|
|
|
|
for (int x = 0; x < SizeX; x++)
|
|
|
|
{
|
|
|
|
int InChunkX = BaseX + x;
|
|
|
|
int AreaX = OffX + x;
|
2021-03-05 08:03:55 -05:00
|
|
|
m_Area.m_BlockTypes[m_Area.MakeIndex(AreaX, AreaY, AreaZ)] = a_BlockData.GetBlock({ InChunkX, InChunkY, InChunkZ });
|
2017-06-24 05:58:06 -04:00
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the block metas:
|
|
|
|
if (m_Area.m_BlockMetas != nullptr)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < SizeY; y++)
|
|
|
|
{
|
|
|
|
int InChunkY = MinY + y;
|
|
|
|
int AreaY = y;
|
|
|
|
for (int z = 0; z < SizeZ; z++)
|
|
|
|
{
|
|
|
|
int InChunkZ = BaseZ + z;
|
|
|
|
int AreaZ = OffZ + z;
|
|
|
|
for (int x = 0; x < SizeX; x++)
|
|
|
|
{
|
|
|
|
int InChunkX = BaseX + x;
|
|
|
|
int AreaX = OffX + x;
|
2021-03-05 08:03:55 -05:00
|
|
|
m_Area.m_BlockMetas[m_Area.MakeIndex(AreaX, AreaY, AreaZ)] = a_BlockData.GetMeta({ InChunkX, InChunkY, InChunkZ });
|
2017-06-24 05:58:06 -04:00
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the blocklight:
|
|
|
|
if (m_Area.m_BlockLight != nullptr)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < SizeY; y++)
|
|
|
|
{
|
|
|
|
int InChunkY = MinY + y;
|
|
|
|
int AreaY = y;
|
|
|
|
for (int z = 0; z < SizeZ; z++)
|
|
|
|
{
|
|
|
|
int InChunkZ = BaseZ + z;
|
|
|
|
int AreaZ = OffZ + z;
|
|
|
|
for (int x = 0; x < SizeX; x++)
|
|
|
|
{
|
|
|
|
int InChunkX = BaseX + x;
|
|
|
|
int AreaX = OffX + x;
|
2021-03-05 08:03:55 -05:00
|
|
|
m_Area.m_BlockLight[m_Area.MakeIndex(AreaX, AreaY, AreaZ)] = a_LightData.GetBlockLight({ InChunkX, InChunkY, InChunkZ });
|
2017-06-24 05:58:06 -04:00
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the skylight:
|
|
|
|
if (m_Area.m_BlockSkyLight != nullptr)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < SizeY; y++)
|
|
|
|
{
|
|
|
|
int InChunkY = MinY + y;
|
|
|
|
int AreaY = y;
|
|
|
|
for (int z = 0; z < SizeZ; z++)
|
|
|
|
{
|
|
|
|
int InChunkZ = BaseZ + z;
|
|
|
|
int AreaZ = OffZ + z;
|
|
|
|
for (int x = 0; x < SizeX; x++)
|
|
|
|
{
|
|
|
|
int InChunkX = BaseX + x;
|
|
|
|
int AreaX = OffX + x;
|
2021-03-05 08:03:55 -05:00
|
|
|
m_Area.m_BlockSkyLight[m_Area.MakeIndex(AreaX, AreaY, AreaZ)] = a_LightData.GetSkyLight({ InChunkX, InChunkY, InChunkZ });
|
2017-06-24 05:58:06 -04:00
|
|
|
} // for x
|
|
|
|
} // for z
|
|
|
|
} // for y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-26 17:24:36 -04:00
|
|
|
|
2017-06-24 05:58:06 -04:00
|
|
|
void cBlockArea::cChunkReader::BlockEntity(cBlockEntity * a_BlockEntity)
|
|
|
|
{
|
|
|
|
if (!m_Area.HasBlockEntities())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!m_AreaBounds.IsInside(a_BlockEntity->GetPos()))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-09-29 08:59:24 -04:00
|
|
|
auto areaPos = a_BlockEntity->GetPos() - m_Area.m_Origin;
|
|
|
|
auto Idx = m_Area.MakeIndex(areaPos);
|
2020-04-03 17:23:38 -04:00
|
|
|
m_Area.m_BlockEntities->emplace(Idx, a_BlockEntity->Clone(areaPos));
|
2017-06-24 05:58:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|