Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockTripwireHook.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "BlockHandler.h"
4 #include "Mixins.h"
5 
6 
7 
8 
9 
11  public cMetaRotator<cClearMetaOnDrop<cBlockHandler>, 0x03, 0x02, 0x03, 0x00, 0x01>
12 {
13  using super = cMetaRotator<cClearMetaOnDrop<cBlockHandler>, 0x03, 0x02, 0x03, 0x00, 0x01>;
14 
15 public:
16 
18  super(a_BlockType)
19  {
20  }
21 
22 
23 
24 
25 
27  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
28  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
29  int a_CursorX, int a_CursorY, int a_CursorZ,
30  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
31  ) override
32  {
33  a_BlockType = m_BlockType;
34  a_BlockMeta = DirectionToMetadata(a_BlockFace);
35 
36  return true;
37  }
38 
39 
40 
41 
42 
43  inline static NIBBLETYPE DirectionToMetadata(eBlockFace a_Direction)
44  {
45  switch (a_Direction)
46  {
47  case BLOCK_FACE_XM: return 0x1;
48  case BLOCK_FACE_XP: return 0x3;
49  case BLOCK_FACE_ZM: return 0x2;
50  case BLOCK_FACE_ZP: return 0x0;
51  case BLOCK_FACE_NONE:
52  case BLOCK_FACE_YM:
53  case BLOCK_FACE_YP:
54  {
55  ASSERT(!"Unhandled tripwire hook direction!");
56  return 0x0;
57  }
58  }
59  UNREACHABLE("Unsupported block face");
60  }
61 
62 
63 
64 
65 
67  {
68  switch (a_Meta & 0x03)
69  {
70  case 0x1: return BLOCK_FACE_XM;
71  case 0x3: return BLOCK_FACE_XP;
72  case 0x2: return BLOCK_FACE_ZM;
73  case 0x0: return BLOCK_FACE_ZP;
74  default: ASSERT(!"Unhandled tripwire hook metadata!"); return BLOCK_FACE_NONE;
75  }
76  }
77 
78 
79 
80 
81 
82  virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
83  {
84  NIBBLETYPE Meta;
85  a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta);
86 
87  AddFaceDirection(a_RelX, a_RelY, a_RelZ, MetadataToDirection(Meta), true);
88  BLOCKTYPE BlockIsOn;
89  a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
90 
91  return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn));
92  }
93 
94 
95 
96 
97 
98  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
99  {
100  UNUSED(a_Meta);
101  return 0;
102  }
103 };
104 
105 
106 
107 
static eBlockFace MetadataToDirection(NIBBLETYPE a_Meta)
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
bool UnboundedRelGetBlockType(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType) const
Same as GetBlockType(), but relative coords needn&#39;t be in this chunk (uses m_Neighbor-s or m_ChunkMap...
Definition: Chunk.cpp:1018
Definition: Player.h:27
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
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...
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.
cBlockTripwireHookHandler(BLOCKTYPE a_BlockType)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
Definition: Chunk.h:49
bool UnboundedRelGetBlockMeta(Vector3i a_RelPos, NIBBLETYPE &a_BlockMeta) const
Same as GetBlockMeta(), but relative coords needn&#39;t be in this chunk (uses m_Neighbor-s or m_ChunkMap...
Definition: Chunk.cpp:1039
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse=false)
Definition: Defines.h:859
Mixin for rotations and reflections following the standard pattern of "apply mask, then use a switch".
Definition: Mixins.h:84
#define ASSERT(x)
Definition: Globals.h:335
static NIBBLETYPE DirectionToMetadata(eBlockFace a_Direction)
#define UNUSED
Definition: Globals.h:152
static bool FullyOccupiesVoxel(BLOCKTYPE a_Type)
Definition: BlockInfo.h:50
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
Byte ColourID
Definition: Globals.h:118
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.
#define UNREACHABLE(x)
Use to mark code that should be impossible to reach.
Definition: Globals.h:344