Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockFenceGate.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 
12  public cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x02, 0x03, 0x00, 0x01>>
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20 private:
21 
22  virtual bool OnUse(
23  cChunkInterface & a_ChunkInterface,
24  cWorldInterface & a_WorldInterface,
25  cPlayer & a_Player,
26  const Vector3i a_BlockPos,
27  eBlockFace a_BlockFace,
28  const Vector3i a_CursorPos
29  ) const override
30  {
31  NIBBLETYPE OldMetaData = a_ChunkInterface.GetBlockMeta(a_BlockPos);
32  NIBBLETYPE NewMetaData = YawToMetaData(a_Player.GetYaw());
33  OldMetaData ^= 4; // Toggle the gate
34 
35  if ((OldMetaData & 1) == (NewMetaData & 1))
36  {
37  // Standing in front of the gate - apply new direction
38  a_ChunkInterface.SetBlockMeta(a_BlockPos, (OldMetaData & 4) | (NewMetaData & 3));
39  }
40  else
41  {
42  // Standing aside - use last direction
43  a_ChunkInterface.SetBlockMeta(a_BlockPos, OldMetaData);
44  }
46  return true;
47  }
48 
49 
50 
51 
52 
53  virtual void OnCancelRightClick(
54  cChunkInterface & a_ChunkInterface,
55  cWorldInterface & a_WorldInterface,
56  cPlayer & a_Player,
57  const Vector3i a_BlockPos,
58  eBlockFace a_BlockFace
59  ) const override
60  {
61  a_WorldInterface.SendBlockTo(a_BlockPos, a_Player);
62  }
63 
64 
65 
66 
67 
68  virtual bool IsUseable(void) const override
69  {
70  return true;
71  }
72 
73 
74 
75 
76 
77  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
78  {
79  UNUSED(a_Meta);
80  switch (m_BlockType)
81  {
82  case E_BLOCK_OAK_FENCE_GATE: return 13;
83  case E_BLOCK_SPRUCE_FENCE_GATE: return 34;
84  case E_BLOCK_BIRCH_FENCE_GATE: return 2;
85  case E_BLOCK_JUNGLE_FENCE_GATE: return 10;
86  case E_BLOCK_DARK_OAK_FENCE_GATE: return 26;
87  case E_BLOCK_ACACIA_FENCE_GATE: return 15;
88  default:
89  {
90  ASSERT(!"Unhandled blocktype in fence gate handler!");
91  return 0;
92  }
93  }
94  }
95 } ;
96 
97 
98 
99 
@ E_BLOCK_BIRCH_FENCE_GATE
Definition: BlockType.h:203
@ E_BLOCK_ACACIA_FENCE_GATE
Definition: BlockType.h:206
@ E_BLOCK_OAK_FENCE_GATE
Definition: BlockType.h:122
@ E_BLOCK_SPRUCE_FENCE_GATE
Definition: BlockType.h:202
@ E_BLOCK_DARK_OAK_FENCE_GATE
Definition: BlockType.h:205
@ E_BLOCK_JUNGLE_FENCE_GATE
Definition: BlockType.h:204
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
@ 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 IsUseable(void) const override
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
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
virtual void OnCancelRightClick(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const override
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
static NIBBLETYPE YawToMetaData(double a_Rotation)
Converts the rotation value as returned by cPlayer::GetYaw() to the appropriate metadata value for a ...
Definition: Mixins.h:172
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.
double GetYaw(void) const
Definition: Entity.h:198
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override