Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockSideways.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 
6 
7 
8 
9 
14  public cBlockHandler
15 {
17 
18 public:
19 
21  super(a_BlockType)
22  {
23  }
24 
25 
26 
27 
28 
30  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
31  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
32  int a_CursorX, int a_CursorY, int a_CursorZ,
33  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
34  ) override
35  {
36  a_BlockType = m_BlockType;
37  NIBBLETYPE Meta = static_cast<NIBBLETYPE>(a_Player.GetEquippedItem().m_ItemDamage);
38  a_BlockMeta = BlockFaceToMetaData(a_BlockFace, Meta);
39  return true;
40  }
41 
42 
43 
44 
45 
46  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
47  {
48  // Reset the orientation part of meta, keep the sub-type part of meta
49  return cItem(m_BlockType, 1, a_BlockMeta & 0x03);
50  }
51 
52 
53 
54 
55 
56  inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_Meta)
57  {
58  switch (a_BlockFace)
59  {
60  case BLOCK_FACE_YM:
61  case BLOCK_FACE_YP:
62  {
63  return a_Meta; // Top or bottom, just return original
64  }
65 
66  case BLOCK_FACE_ZP:
67  case BLOCK_FACE_ZM:
68  {
69  return a_Meta | 0x8; // North or south
70  }
71 
72  case BLOCK_FACE_XP:
73  case BLOCK_FACE_XM:
74  {
75  return a_Meta | 0x4; // East or west
76  }
77 
78  case BLOCK_FACE_NONE:
79  {
80  ASSERT(!"Unhandled block face!");
81  return a_Meta | 0xC; // No idea, give a special meta
82  }
83  }
84  UNREACHABLE("Unsupported block face");
85  }
86 } ;
87 
88 
89 
90 
Handler for blocks that have 3 orientations (hay bale, log), specified by the upper 2 bits in meta...
Definition: BlockSideways.h:13
short m_ItemDamage
Definition: Item.h:211
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
const cItem & GetEquippedItem(void) const
Definition: Player.h:142
Definition: Player.h:27
cBlockHandler(BLOCKTYPE a_BlockType)
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity *a_BlockEntity, const cEntity *a_Digger, const cItem *a_Tool) override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
Definition: BlockSideways.h:46
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
cBlockSidewaysHandler(BLOCKTYPE a_BlockType)
Definition: BlockSideways.h:20
#define ASSERT(x)
Definition: Globals.h:335
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_Meta)
Definition: BlockSideways.h:56
Definition: Entity.h:73
Definition: Item.h:36
#define UNREACHABLE(x)
Use to mark code that should be impossible to reach.
Definition: Globals.h:344
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234
virtual bool GetPlacementBlockTypeMeta(cChunkInterface &a_ChunkInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) override
Called before a block is placed into a world.
Definition: BlockSideways.h:29