Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemQuartz.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 
6 
7 
8 
9 
10 class cItemQuartzHandler final:
11  public cItemHandler
12 {
14 
15 public:
16 
17  using Super::Super;
18 
19 private:
20 
23  {
24  switch (a_BlockFace)
25  {
26  case BLOCK_FACE_YM:
27  case BLOCK_FACE_YP:
28  {
29  return E_META_QUARTZ_PILLAR; // Top or bottom.
30  }
31 
32  case BLOCK_FACE_ZP:
33  case BLOCK_FACE_ZM:
34  {
35  return 0x4; // North or south.
36  }
37 
38  case BLOCK_FACE_XP:
39  case BLOCK_FACE_XM:
40  {
41  return 0x3; // East or west.
42  }
43  default: UNREACHABLE("Unsupported block face");
44  }
45  }
46 
47 
48  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
49  {
50  const auto Meta = static_cast<NIBBLETYPE>(a_Player.GetEquippedItem().m_ItemDamage);
51 
52  // Pillar block needs additional direction in the metadata:
53  if (Meta == E_META_QUARTZ_PILLAR)
54  {
55  return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_QUARTZ_BLOCK, BlockFaceToMetaData(a_ClickedBlockFace));
56  }
57 
58  return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_QUARTZ_BLOCK, Meta);
59  }
60 };
@ E_META_QUARTZ_PILLAR
Definition: BlockType.h:778
@ E_BLOCK_QUARTZ_BLOCK
Definition: BlockType.h:172
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_YP
Definition: Defines.h:43
@ BLOCK_FACE_YM
Definition: Defines.h:42
@ BLOCK_FACE_ZM
Definition: Defines.h:44
@ BLOCK_FACE_ZP
Definition: Defines.h:45
@ BLOCK_FACE_XM
Definition: Defines.h:40
#define UNREACHABLE(x)
Definition: Globals.h:288
Definition: Player.h:29
const cItem & GetEquippedItem(void) const
Definition: Player.h:162
bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Attempts to place the block in the world with a call to PlaceBlocks.
Definition: Player.cpp:2440
Definition: Item.h:37
short m_ItemDamage
Definition: Item.h:165
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
virtual bool CommitPlacement(cPlayer &a_Player, const cItem &a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
Performs the actual placement of this placeable item.
Definition: ItemQuartz.h:48
static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace)
Converts the block face of the pillar block's "base" to the block's metadata.
Definition: ItemQuartz.h:22