Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockLadder.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "Mixins.h"
6 
7 
8 
9 
10 
12  public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04> >
13 {
15 
16 public:
17 
19  super(a_BlockType)
20  {
21  }
22 
23 
24 
25 
26 
28  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
29  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
30  int a_CursorX, int a_CursorY, int a_CursorZ,
31  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
32  ) override
33  {
34  if (!LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace))
35  {
36  a_BlockFace = FindSuitableBlockFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
37 
38  if (a_BlockFace == BLOCK_FACE_BOTTOM)
39  {
40  return false;
41  }
42  }
43 
44  a_BlockType = m_BlockType;
45  a_BlockMeta = DirectionToMetaData(a_BlockFace);
46  return true;
47  }
48 
49 
50 
51 
52 
54  {
55  switch (a_Direction)
56  {
57  case BLOCK_FACE_ZM: return 0x2;
58  case BLOCK_FACE_ZP: return 0x3;
59  case BLOCK_FACE_XM: return 0x4;
60  case BLOCK_FACE_XP: return 0x5;
61  case BLOCK_FACE_NONE:
62  case BLOCK_FACE_YM:
63  case BLOCK_FACE_YP:
64  {
65  return 0x2;
66  }
67  }
68  UNREACHABLE("Unsupported block face");
69  }
70 
71 
72 
73 
74 
76  {
77  switch (a_MetaData)
78  {
79  case 0x2: return BLOCK_FACE_ZM;
80  case 0x3: return BLOCK_FACE_ZP;
81  case 0x4: return BLOCK_FACE_XM;
82  case 0x5: return BLOCK_FACE_XP;
83  default: return BLOCK_FACE_ZM;
84  }
85  }
86 
87 
88 
89 
90 
92  static eBlockFace FindSuitableBlockFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
93  {
94  for (int FaceInt = BLOCK_FACE_ZM; FaceInt <= BLOCK_FACE_XP; FaceInt++)
95  {
96  eBlockFace Face = static_cast<eBlockFace>(FaceInt);
97  if (LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, Face))
98  {
99  return Face;
100  }
101  }
102  return BLOCK_FACE_BOTTOM;
103  }
104 
105 
106 
107 
108 
109  static bool LadderCanBePlacedAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
110  {
111  if ((a_BlockFace == BLOCK_FACE_BOTTOM) || (a_BlockFace == BLOCK_FACE_TOP))
112  {
113  return false;
114  }
115 
116  AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true);
117 
118  return cBlockInfo::IsSolid(a_ChunkInterface.GetBlock({a_BlockX, a_BlockY, a_BlockZ}));
119  }
120 
121 
122 
123 
124 
125  virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
126  {
127  // TODO: Use AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison
128  eBlockFace BlockFace = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
129  int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
130  int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
131  return LadderCanBePlacedAt(a_ChunkInterface, BlockX, a_RelY, BlockZ, BlockFace);
132  }
133 
134 
135 
136 
137 
138  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
139  {
140  UNUSED(a_Meta);
141  return 0;
142  }
143 } ;
144 
145 
146 
147 
cBlockLadderHandler(BLOCKTYPE a_BlockType)
Definition: BlockLadder.h:18
virtual bool CanBeAt(cChunkInterface &a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk &a_Chunk) override
Checks if the block can stay at the specified relative coords in the chunk.
Definition: BlockLadder.h:125
static bool IsSolid(BLOCKTYPE a_Type)
Definition: BlockInfo.h:48
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
static const int Width
Definition: ChunkDef.h:134
Definition: Player.h:27
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData)
Definition: BlockLadder.h:75
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
Definition: Chunk.h:49
static eBlockFace FindSuitableBlockFace(cChunkInterface &a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
Finds a suitable Direction for the Ladder.
Definition: BlockLadder.h:92
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse=false)
Definition: Defines.h:859
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:380
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockLadder.h:138
int GetPosX(void) const
Definition: Chunk.h:150
static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction)
Definition: BlockLadder.h:53
#define UNUSED
Definition: Globals.h:152
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
BLOCKTYPE GetBlock(Vector3i a_Pos)
Byte ColourID
Definition: Globals.h:118
int GetPosZ(void) const
Definition: Chunk.h:151
static bool LadderCanBePlacedAt(cChunkInterface &a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
Definition: BlockLadder.h:109
Mixin to clear the block&#39;s meta value when converting to a pickup.
Definition: Mixins.h:55
virtual bool GetPlacementBlockTypeMeta(cChunkInterface &a_ChunkInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) override
Called before a block is placed into a world.
Definition: BlockLadder.h:27
#define UNREACHABLE(x)
Use to mark code that should be impossible to reach.
Definition: Globals.h:344