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 "BlockInfo.h"
6 #include "Mixins.h"
7 
8 
9 
10 
11 
12 class cBlockLadderHandler final :
13  public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04> >
14 {
16 
17 public:
18 
19  using Super::Super;
20 
21 
23  static bool CanBePlacedOn(const BLOCKTYPE a_BlockType, const eBlockFace a_BlockFace)
24  {
25  if (
26  (a_BlockFace == BLOCK_FACE_NONE) ||
27  (a_BlockFace == BLOCK_FACE_BOTTOM) ||
28  (a_BlockFace == BLOCK_FACE_TOP)
29  )
30  {
31  return false;
32  }
33 
34  return cBlockInfo::FullyOccupiesVoxel(a_BlockType);
35  }
36 
37 private:
38 
41  {
42  switch (a_MetaData)
43  {
44  case 0x2: return BLOCK_FACE_ZM;
45  case 0x3: return BLOCK_FACE_ZP;
46  case 0x4: return BLOCK_FACE_XM;
47  case 0x5: return BLOCK_FACE_XP;
48  default: return BLOCK_FACE_ZM;
49  }
50  }
51 
52 
53 
54 
55 
56  virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
57  {
58  auto Face = MetaDataToBlockFace(a_Meta);
59  auto NeighborRelPos = AddFaceDirection(a_Position, Face, true);
60  BLOCKTYPE NeighborBlockType;
61  a_Chunk.UnboundedRelGetBlockType(NeighborRelPos, NeighborBlockType);
62  return CanBePlacedOn(NeighborBlockType, Face);
63  }
64 
65 
66 
67 
68 
69  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
70  {
71  UNUSED(a_Meta);
72  return 0;
73  }
74 } ;
75 
76 
77 
78 
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse)
Modifies the specified coords so that they point to the block adjacent to the one specified through i...
Definition: Defines.cpp:378
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
@ BLOCK_FACE_XP
Definition: Defines.h:41
@ BLOCK_FACE_TOP
Definition: Defines.h:49
@ BLOCK_FACE_ZM
Definition: Defines.h:44
@ BLOCK_FACE_BOTTOM
Definition: Defines.h:48
@ BLOCK_FACE_ZP
Definition: Defines.h:45
@ BLOCK_FACE_XM
Definition: Defines.h:40
@ BLOCK_FACE_NONE
Definition: Defines.h:39
Byte ColourID
Definition: Globals.h:162
#define UNUSED
Definition: Globals.h:72
static bool FullyOccupiesVoxel(BLOCKTYPE Block)
Does this block fully occupy its voxel - is it a 'full' block?
Definition: BlockInfo.cpp:606
static eBlockFace MetaDataToBlockFace(NIBBLETYPE a_MetaData)
Converts the ladder block's meta to the block face of the neighbor to which the ladder is attached.
Definition: BlockLadder.h:40
virtual bool CanBeAt(const cChunk &a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
Definition: BlockLadder.h:56
static bool CanBePlacedOn(const BLOCKTYPE a_BlockType, const eBlockFace a_BlockFace)
Returns true if the ladder will be supported by the block through the given blockface.
Definition: BlockLadder.h:23
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Definition: BlockLadder.h:69
Mixin to clear the block's meta value when converting to a pickup.
Definition: Mixins.h:31
Definition: Chunk.h:36
bool UnboundedRelGetBlockType(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType) const
Same as GetBlockType(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap...
Definition: Chunk.cpp:1029