Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockTrapdoor.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "Mixins.h"
6 #include "../EffectID.h"
7 
8 
9 
10 
11 class cBlockTrapdoorHandler final :
12  public cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x01, 0x02, 0x00, 0x03, false>>
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20 private:
21 
22  virtual bool IsUseable(void) const override
23  {
24  return true;
25  }
26 
27 
28 
29 
30 
31  virtual bool OnUse(
32  cChunkInterface & a_ChunkInterface,
33  cWorldInterface & a_WorldInterface,
34  cPlayer & a_Player,
35  const Vector3i a_BlockPos,
36  eBlockFace a_BlockFace,
37  const Vector3i a_CursorPos
38  ) const override
39  {
40  if (m_BlockType == E_BLOCK_IRON_TRAPDOOR)
41  {
42  // Iron doors can only be toggled by redstone, not by right-clicking
43  return false;
44  }
45 
46  // Flip the ON bit on / off using the XOR bitwise operation
47  NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockPos) ^ 0x04);
48  a_ChunkInterface.SetBlockMeta(a_BlockPos, Meta);
50 
51  return true;
52  }
53 
54 
55 
56 
57 
58  virtual void OnCancelRightClick(
59  cChunkInterface & a_ChunkInterface,
60  cWorldInterface & a_WorldInterface,
61  cPlayer & a_Player,
62  const Vector3i a_BlockPos,
63  eBlockFace a_BlockFace
64  ) const override
65  {
66  UNUSED(a_ChunkInterface);
67  a_WorldInterface.SendBlockTo(a_BlockPos, a_Player);
68  }
69 
70 
71 
72 
73 
75  {
76  switch (a_Meta & 0x3)
77  {
78  case 0x0: return BLOCK_FACE_ZM;
79  case 0x1: return BLOCK_FACE_ZP;
80  case 0x2: return BLOCK_FACE_XM;
81  case 0x3: return BLOCK_FACE_XP;
82  default:
83  {
84  ASSERT(!"Unhandled block meta!");
85  return BLOCK_FACE_NONE;
86  }
87  }
88  }
89 
90 
91 
92 
93 
94  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
95  {
96  UNUSED(a_Meta);
97  switch (m_BlockType)
98  {
99  case E_BLOCK_TRAPDOOR: return 13;
100  case E_BLOCK_IRON_TRAPDOOR: return 6;
101  default:
102  {
103  ASSERT(!"Unhandled blocktype in trapdoor handler!");
104  return 0;
105  }
106  }
107  }
108 };
109 
110 
111 
112 
@ E_BLOCK_TRAPDOOR
Definition: BlockType.h:111
@ E_BLOCK_IRON_TRAPDOOR
Definition: BlockType.h:186
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
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_ZM
Definition: Defines.h:44
@ BLOCK_FACE_ZP
Definition: Defines.h:45
@ BLOCK_FACE_XM
Definition: Defines.h:40
@ BLOCK_FACE_NONE
Definition: Defines.h:39
@ SFX_RANDOM_FENCE_GATE_OPEN
Byte ColourID
Definition: Globals.h:162
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const override
Definition: BlockTrapdoor.h:31
static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta)
Definition: BlockTrapdoor.h:74
virtual bool IsUseable(void) const override
Definition: BlockTrapdoor.h:22
virtual void OnCancelRightClick(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const override
Definition: BlockTrapdoor.h:58
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Definition: BlockTrapdoor.h:94
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr)=0
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData)
Sets the meta for the specified block, while keeping the blocktype.
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
Mixin to clear the block's meta value when converting to a pickup.
Definition: Mixins.h:31
cMetaRotator< Base, BitMask, North, East, South, West, AssertIfNotMatched > Super
Definition: Mixins.h:163
virtual cBroadcastInterface & GetBroadcastManager()=0
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, const cPlayer &a_Player)=0
Sends the block on those coords to the player.
Definition: Player.h:29
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276