Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PalettedBlockArea Class Reference

Represents an area of blocks that are represented using a palette. More...

#include <PalettedBlockArea.h>

Collaboration diagram for PalettedBlockArea:
Collaboration graph
[legend]

Public Member Functions

const std::pair< AString, BlockState > & block (Vector3i aPos) const
 Returns the full blockspec of the block at the specified position. More...
 
UInt32 blockPaletteIndex (Vector3i aPos) const
 Returns the index into the palette for the block at the specified pos. More...
 
void crop (const cCuboid &aArea)
 Crops this PBA by the specified coords. More...
 
void fill (const AString &aBlockTypeName, const BlockState &aBlockState)
 Fills the entire PBA with a single block of the specified type. More...
 
bool isPositionValid (Vector3i aPos) const
 Returns true if the specified position is within the size bounds of the area. More...
 
std::pair< UInt32, bool > maybePaletteIndex (const AString &aBlockTypeName, const BlockState &aBlockState) const
 Returns the <index, true> into the palette that is used by the specified full blockspec. More...
 
const BlockTypePalettepalette ()
 Returns the (reqd-only) palette used internally by this object. More...
 
const std::pair< AString, BlockState > & paletteEntry (UInt32 aPaletteIndex) const
 Returns the blockspec represented by the specified palette index. More...
 
UInt32 paletteIndex (const AString &aBlockTypeName, const BlockState &aBlockState)
 Returns the index into the palette that is used by the specified full blockspec. More...
 
void paste (const PalettedBlockArea &aSrc, const cCuboid &aSrcCuboid, Vector3i aDstOrigin=Vector3i())
 Pastes (copies verbatim) a cCuboid out of the src PBA into this PBA. More...
 
void paste (const PalettedBlockArea &aSrc, Vector3i aDstOrigin=Vector3i())
 Pastes (copies verbatim) the entire src PBA into this PBA. More...
 
void setBlock (Vector3i aPos, const AString &aBlockTypeName, const BlockState &aBlockState)
 Sets a single block using its full blockspec. More...
 
void setBlock (Vector3i aPos, UInt32 aPaletteIndex)
 Sets a single block using an index to the palette (retrieved earlier by paletteIndex()). More...
 
const Vector3isize () const
 Returns the actual size of the area in all 3 axes. More...
 
cCuboid whole () const
 Returns a cCuboid that encompasses the entire PBA. More...
 

Static Public Member Functions

static PalettedBlockArea createFilled (Vector3i aSize, const AString &aBlockTypeName, const BlockState &aBlockState)
 Creates a new PBA of the specified size filled with the specified block. More...
 

Protected Member Functions

 PalettedBlockArea ()
 Creates a new uninitialized instance (all sizes zero). More...
 
UInt32 positionToIndex (Vector3i aPos) const
 Converts the position to index in mBlocks. More...
 

Protected Attributes

std::vector< UInt32mBlocks
 The blocks contained in the area, stored as indices into mPalette. More...
 
BlockTypePalette mPalette
 The palette used in the area. More...
 
Vector3i mSize
 The size (dimensions) of the area. More...
 

Detailed Description

Represents an area of blocks that are represented using a palette.

The object itself provides no thread safety, users of this class need to handle locking, if required. The PalettedBlockArea always contains Blocks and their associated BlockEntities, it may optionally contain Entities. There's no way to instantiate this class directly, you need to use either createFilled(), or read from cWorld.

Definition at line 20 of file PalettedBlockArea.h.

Constructor & Destructor Documentation

◆ PalettedBlockArea()

PalettedBlockArea::PalettedBlockArea ( )
protected

Creates a new uninitialized instance (all sizes zero).

Definition at line 8 of file PalettedBlockArea.cpp.

Member Function Documentation

◆ block()

const std::pair< AString, BlockState > & PalettedBlockArea::block ( Vector3i  aPos) const

Returns the full blockspec of the block at the specified position.

The position must be valid (ASSERTed).

Definition at line 99 of file PalettedBlockArea.cpp.

◆ blockPaletteIndex()

UInt32 PalettedBlockArea::blockPaletteIndex ( Vector3i  aPos) const

Returns the index into the palette for the block at the specified pos.

The position must be valid (ASSERTed).

Definition at line 89 of file PalettedBlockArea.cpp.

◆ createFilled()

PalettedBlockArea PalettedBlockArea::createFilled ( Vector3i  aSize,
const AString aBlockTypeName,
const BlockState aBlockState 
)
static

Creates a new PBA of the specified size filled with the specified block.

Throws if there is an error (memory allocation etc.)

Definition at line 17 of file PalettedBlockArea.cpp.

◆ crop()

void PalettedBlockArea::crop ( const cCuboid aArea)

Crops this PBA by the specified coords.

aArea is first cropped to the size of this PBA (so it's only possible to shrink a PBA, not enlarge).

Definition at line 219 of file PalettedBlockArea.cpp.

◆ fill()

void PalettedBlockArea::fill ( const AString aBlockTypeName,
const BlockState aBlockState 
)

Fills the entire PBA with a single block of the specified type.

The palette is reset to one containing only the single block.

Definition at line 129 of file PalettedBlockArea.cpp.

◆ isPositionValid()

bool PalettedBlockArea::isPositionValid ( Vector3i  aPos) const

Returns true if the specified position is within the size bounds of the area.

Definition at line 117 of file PalettedBlockArea.cpp.

◆ maybePaletteIndex()

std::pair< UInt32, bool > PalettedBlockArea::maybePaletteIndex ( const AString aBlockTypeName,
const BlockState aBlockState 
) const

Returns the <index, true> into the palette that is used by the specified full blockspec.

Returns <undefined, false> if blockspec not in palette.

Definition at line 80 of file PalettedBlockArea.cpp.

◆ palette()

const BlockTypePalette& PalettedBlockArea::palette ( )
inline

Returns the (reqd-only) palette used internally by this object.

Definition at line 93 of file PalettedBlockArea.h.

◆ paletteEntry()

const std::pair< AString, BlockState > & PalettedBlockArea::paletteEntry ( UInt32  aPaletteIndex) const

Returns the blockspec represented by the specified palette index.

The index must be valid (ASSERTed).

Definition at line 108 of file PalettedBlockArea.cpp.

◆ paletteIndex()

UInt32 PalettedBlockArea::paletteIndex ( const AString aBlockTypeName,
const BlockState aBlockState 
)

Returns the index into the palette that is used by the specified full blockspec.

Adds the blockspec to palette if not already there.

Definition at line 71 of file PalettedBlockArea.cpp.

◆ paste() [1/2]

void PalettedBlockArea::paste ( const PalettedBlockArea aSrc,
const cCuboid aSrcCuboid,
Vector3i  aDstOrigin = Vector3i() 
)

Pastes (copies verbatim) a cCuboid out of the src PBA into this PBA.

aSrcCuboid is the coord range in aSrc that will be copied (min-coord is inclusive, max-coord is exclusive). aDstOrigin is the coord relative to this PBA where the lowest coords of the copied area will be put. aDstOrigin can be outside of this PBA's coord range (only part of the src is copied). Automatically crops aSrcCuboid so that the copied part is entirely inside this PBA's coord range.

Definition at line 141 of file PalettedBlockArea.cpp.

◆ paste() [2/2]

void PalettedBlockArea::paste ( const PalettedBlockArea aSrc,
Vector3i  aDstOrigin = Vector3i() 
)
inline

Pastes (copies verbatim) the entire src PBA into this PBA.

aDstOrigin is the coord relative to this PBA where the lowest coords of the copied area will be put. aDstOrigin can be outside of this PBA's coord range (only part of the src is copied). Gracefully handles situations where the copied src PBA goes outside of this PBA's coord range.

Definition at line 83 of file PalettedBlockArea.h.

◆ positionToIndex()

UInt32 PalettedBlockArea::positionToIndex ( Vector3i  aPos) const
protected

Converts the position to index in mBlocks.

This may be removed later on when optimizing the RAM usage of this class by compressing low-palette-count PBAs.

Definition at line 257 of file PalettedBlockArea.cpp.

◆ setBlock() [1/2]

void PalettedBlockArea::setBlock ( Vector3i  aPos,
const AString aBlockTypeName,
const BlockState aBlockState 
)

Sets a single block using its full blockspec.

The position must be valid (ASSERTed). If the block is not already in palette, it is added.

Definition at line 49 of file PalettedBlockArea.cpp.

◆ setBlock() [2/2]

void PalettedBlockArea::setBlock ( Vector3i  aPos,
UInt32  aPaletteIndex 
)

Sets a single block using an index to the palette (retrieved earlier by paletteIndex()).

The position must be valid (ASSERTed). The palette index must be valid (ASSERTed).

Definition at line 58 of file PalettedBlockArea.cpp.

◆ size()

const Vector3i& PalettedBlockArea::size ( ) const
inline

Returns the actual size of the area in all 3 axes.

Definition at line 29 of file PalettedBlockArea.h.

◆ whole()

cCuboid PalettedBlockArea::whole ( ) const

Returns a cCuboid that encompasses the entire PBA.

Technically, {0, 0, 0} to mSize.

Definition at line 40 of file PalettedBlockArea.cpp.

Member Data Documentation

◆ mBlocks

std::vector<UInt32> PalettedBlockArea::mBlocks
protected

The blocks contained in the area, stored as indices into mPalette.

Definition at line 102 of file PalettedBlockArea.h.

◆ mPalette

BlockTypePalette PalettedBlockArea::mPalette
protected

The palette used in the area.

Definition at line 99 of file PalettedBlockArea.h.

◆ mSize

Vector3i PalettedBlockArea::mSize
protected

The size (dimensions) of the area.

Definition at line 105 of file PalettedBlockArea.h.


The documentation for this class was generated from the following files: