Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemLever.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 
6 
7 
8 
9 
10 class cItemLeverHandler final :
11  public cItemHandler
12 {
14 
15 public:
16 
17  using Super::Super;
18 
19 private:
20 
23  {
24  // Determine lever direction:
25  switch (a_BlockFace)
26  {
27  case BLOCK_FACE_YP: return 0x6;
28  case BLOCK_FACE_XP: return 0x1;
29  case BLOCK_FACE_XM: return 0x2;
30  case BLOCK_FACE_ZP: return 0x3;
31  case BLOCK_FACE_ZM: return 0x4;
32  case BLOCK_FACE_YM: return 0x0;
33  case BLOCK_FACE_NONE: break;
34  }
35  UNREACHABLE("Unsupported block face");
36  }
37 
38 
39  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
40  {
41  return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), BlockFaceToMetaData(a_ClickedBlockFace));
42  }
43 };
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
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
@ BLOCK_FACE_NONE
Definition: Defines.h:39
#define UNREACHABLE(x)
Definition: Globals.h:288
Definition: Player.h:29
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_ItemType
Definition: Item.h:163
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: ItemLever.h:39
static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace)
Converts the block face of the neighbor to which the lever is attached to the lever block's meta.
Definition: ItemLever.h:22