Cuberite
A lightweight, fast and extensible game server for Minecraft
PrefabStructure.cpp
Go to the documentation of this file.
1 
2 // PrefabStructure.cpp
3 
4 // Implements the cPrefabStructure class representing a cGridStructGen::cStructure descendant based on placed cPrefab instances
5 
6 #include "Globals.h"
7 #include "PrefabStructure.h"
8 #include "Prefab.h"
9 
10 
11 
12 
13 
15  int a_GridX, int a_GridZ,
16  int a_OriginX, int a_OriginZ,
17  cPlacedPieces && a_Pieces,
18  cTerrainHeightGen & a_HeightGen
19 ):
20  Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
21  m_Pieces(std::move(a_Pieces)),
22  m_HeightGen(a_HeightGen)
23 {
24 }
25 
26 
27 
28 
29 
31 {
32  // Iterate over all items
33  // Each intersecting prefab is placed on ground, if requested, then drawn
34  for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
35  {
36  const cPrefab & Prefab = static_cast<const cPrefab &>((*itr)->GetPiece());
37  if (Prefab.ShouldMoveToGround() && !(*itr)->HasBeenMovedToGround())
38  {
39  PlacePieceOnGround(**itr);
40  }
41  Prefab.Draw(a_Chunk, itr->get());
42  } // for itr - m_PlacedPieces[]
43 }
44 
45 
46 
47 
48 
50 {
51  cPiece::cConnector FirstConnector = a_Piece.GetRotatedConnector(0);
52  int ChunkX, ChunkZ;
53  int BlockX = FirstConnector.m_Pos.x;
54  int BlockZ = FirstConnector.m_Pos.z;
55  int BlockY;
56  cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
57  cChunkDef::HeightMap HeightMap;
58  m_HeightGen.GenHeightMap({ChunkX, ChunkZ}, HeightMap);
59  int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
60  a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
61 }
std::vector< cPlacedPiecePtr > cPlacedPieces
Definition: PiecePool.h:370
Definition: FastNBT.h:132
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
Definition: ChunkDef.h:147
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
Definition: ChunkDef.h:132
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
Definition: ChunkDef.h:303
The interface that is used to query terrain height from the shape generator.
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap &a_HeightMap)=0
Retrieves the heightmap for the specified chunk.
Represents a single structure that occupies the grid point.
Definition: GridStructGen.h:50
Vector3i m_Pos
Position relative to the piece.
Definition: PiecePool.h:50
Represents a single piece that has been placed to specific coords in the world.
Definition: PiecePool.h:328
void MoveToGroundBy(int a_OffsetY)
Moves the placed piece Y-wise by the specified offset.
Definition: PiecePool.cpp:504
cPiece::cConnector GetRotatedConnector(size_t a_Index) const
Returns the connector at the specified index, rotated in the actual placement.
Definition: PiecePool.cpp:484
Definition: Prefab.h:33
bool ShouldMoveToGround(void) const
Returns whether the prefab should be moved Y-wise to ground before drawing, rather than staying at th...
Definition: Prefab.h:139
void Draw(cChunkDesc &a_Dest, const cPlacedPiece *a_Placement) const
Draws the prefab into the specified chunk, according to the placement stored in the PlacedPiece.
Definition: Prefab.cpp:133
void PlacePieceOnGround(cPlacedPiece &a_Piece)
Adjusts the Y coord of the given piece so that the piece is on the ground.
virtual void DrawIntoChunk(cChunkDesc &a_Chunk) override
Draws self into the specified chunk.
cPlacedPieces m_Pieces
The pieces placed by the generator.
cPrefabStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, cPlacedPieces &&a_Pieces, cTerrainHeightGen &a_HeightGen)
cTerrainHeightGen & m_HeightGen
The height generator used when adjusting pieces onto the ground.
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17