Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemSideways.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "Blocks/BlockSideways.h"
6 
7 
8 
9 
10 
14 class cItemSidewaysHandler final :
15  public cItemHandler
16 {
18 
19 public:
20 
21  using Super::Super;
22 
23 private:
24 
26  {
27  switch (a_BlockFace)
28  {
29  case BLOCK_FACE_YM:
30  case BLOCK_FACE_YP:
31  {
32  return a_Meta; // Top or bottom, just return original.
33  }
34  case BLOCK_FACE_ZP:
35  case BLOCK_FACE_ZM:
36  {
37  return a_Meta | 0x8; // North or south.
38  }
39  case BLOCK_FACE_XP:
40  case BLOCK_FACE_XM:
41  {
42  return a_Meta | 0x4; // East or west.
43  }
44  default: UNREACHABLE("Unsupported block face");
45  }
46  }
47 
48 
49  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
50  {
51  return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), BlockFaceToMetaData(a_ClickedBlockFace, static_cast<NIBBLETYPE>(a_HeldItem.m_ItemDamage)));
52  }
53 };
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
#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
short m_ItemDamage
Definition: Item.h:165
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
Handler for blocks that have 3 orientations (hay bale, log), specified by the upper 2 bits in meta.
Definition: ItemSideways.h:16
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: ItemSideways.h:49
static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_Meta)
Definition: ItemSideways.h:25