Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemStairs.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "Blocks/BlockStairs.h"
6 
7 
8 
9 
10 
11 class cItemStairsHandler final :
12  public cItemHandler
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20 private:
21 
22  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
23  {
25 
26  switch (a_ClickedBlockFace)
27  {
28  case BLOCK_FACE_TOP: break;
29  case BLOCK_FACE_BOTTOM: Meta |= 0x4; break; // When placing onto a bottom face, always place an upside-down stairs block.
30  case BLOCK_FACE_EAST:
31  case BLOCK_FACE_NORTH:
32  case BLOCK_FACE_SOUTH:
33  case BLOCK_FACE_WEST:
34  {
35  // When placing onto a sideways face, check cursor, if in top half, make it an upside-down stairs block:
36  if (a_CursorPosition.y > 8)
37  {
38  Meta |= 0x4;
39  }
40  break;
41  }
42  default: UNREACHABLE("Unhandled block face");
43  }
44 
45  return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), Meta);
46  }
47 };
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_EAST
Definition: Defines.h:53
@ BLOCK_FACE_SOUTH
Definition: Defines.h:51
@ BLOCK_FACE_TOP
Definition: Defines.h:49
@ BLOCK_FACE_WEST
Definition: Defines.h:52
@ BLOCK_FACE_BOTTOM
Definition: Defines.h:48
@ BLOCK_FACE_NORTH
Definition: Defines.h:50
#define UNREACHABLE(x)
Definition: Globals.h:288
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
double GetYaw(void) const
Definition: Entity.h:198
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: ItemStairs.h:22
T y
Definition: Vector3.h:17