Cuberite
A lightweight, fast and extensible game server for Minecraft
PalettedBlockArea.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 
5 
6 
7 #include <utility>
8 
10 #include "Cuboid.h"
11 
12 
13 
14 
15 
21 {
22 public:
23 
26  static PalettedBlockArea createFilled(Vector3i aSize, const AString & aBlockTypeName, const BlockState & aBlockState);
27 
29  const Vector3i & size() const { return mSize; }
30 
33  cCuboid whole() const;
34 
38  void setBlock(Vector3i aPos, const AString & aBlockTypeName, const BlockState & aBlockState);
39 
43  void setBlock(Vector3i aPos, UInt32 aPaletteIndex);
44 
47  UInt32 paletteIndex(const AString & aBlockTypeName, const BlockState & aBlockState);
48 
51  std::pair<UInt32, bool> maybePaletteIndex(const AString & aBlockTypeName, const BlockState & aBlockState) const;
52 
55  UInt32 blockPaletteIndex(Vector3i aPos) const;
56 
59  const std::pair<AString, BlockState> & block(Vector3i aPos) const;
60 
63  const std::pair<AString, BlockState> & paletteEntry(UInt32 aPaletteIndex) const;
64 
66  bool isPositionValid(Vector3i aPos) const;
67 
70  void fill(const AString & aBlockTypeName, const BlockState & aBlockState);
71 
77  void paste(const PalettedBlockArea & aSrc, const cCuboid & aSrcCuboid, Vector3i aDstOrigin = Vector3i());
78 
83  inline void paste(const PalettedBlockArea & aSrc, Vector3i aDstOrigin = Vector3i())
84  {
85  paste(aSrc, aSrc.whole(), aDstOrigin);
86  }
87 
90  void crop(const cCuboid & aArea);
91 
93  const BlockTypePalette & palette() { return mPalette; }
94 
95 
96 protected:
97 
100 
102  std::vector<UInt32> mBlocks;
103 
106 
107 
110 
113  UInt32 positionToIndex(Vector3i aPos) const;
114 };
unsigned int UInt32
Definition: Globals.h:157
std::string AString
Definition: StringUtils.h:11
Vector3< int > Vector3i
Definition: Vector3.h:487
Represents the state of a single block (previously known as "block meta").
Definition: BlockState.h:20
Holds a palette that maps between block type + state and numbers.
Definition: Cuboid.h:10
Represents an area of blocks that are represented using a palette.
void setBlock(Vector3i aPos, const AString &aBlockTypeName, const BlockState &aBlockState)
Sets a single block using its full blockspec.
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.
const std::pair< AString, BlockState > & block(Vector3i aPos) const
Returns the full blockspec of the block at the specified position.
void crop(const cCuboid &aArea)
Crops this PBA by the specified coords.
Vector3i mSize
The size (dimensions) of the area.
std::vector< UInt32 > mBlocks
The blocks contained in the area, stored as indices into mPalette.
cCuboid whole() const
Returns a cCuboid that encompasses the entire PBA.
void fill(const AString &aBlockTypeName, const BlockState &aBlockState)
Fills the entire PBA with a single block of the specified type.
BlockTypePalette mPalette
The palette used in the area.
const BlockTypePalette & palette()
Returns the (reqd-only) palette used internally by this object.
PalettedBlockArea()
Creates a new uninitialized instance (all sizes zero).
const Vector3i & size() const
Returns the actual size of the area in all 3 axes.
UInt32 paletteIndex(const AString &aBlockTypeName, const BlockState &aBlockState)
Returns the index into the palette that is used by the specified full blockspec.
UInt32 blockPaletteIndex(Vector3i aPos) const
Returns the index into the palette for the block at the specified pos.
bool isPositionValid(Vector3i aPos) const
Returns true if the specified position is within the size bounds of the area.
void paste(const PalettedBlockArea &aSrc, Vector3i aDstOrigin=Vector3i())
Pastes (copies verbatim) the entire src PBA into this PBA.
void paste(const PalettedBlockArea &aSrc, const cCuboid &aSrcCuboid, Vector3i aDstOrigin=Vector3i())
Pastes (copies verbatim) a cCuboid out of the src PBA into this PBA.
UInt32 positionToIndex(Vector3i aPos) const
Converts the position to index in mBlocks.
const std::pair< AString, BlockState > & paletteEntry(UInt32 aPaletteIndex) const
Returns the blockspec represented by the specified palette index.
static PalettedBlockArea createFilled(Vector3i aSize, const AString &aBlockTypeName, const BlockState &aBlockState)
Creates a new PBA of the specified size filled with the specified block.