Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockStairs.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "Mixins.h"
6 
7 
8 
9 
11  public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x02, 0x01, true>>
12 {
14 
15 public:
16 
18  super(a_BlockType)
19  {
20 
21  }
22 
24  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
25  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
26  int a_CursorX, int a_CursorY, int a_CursorZ,
27  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
28  ) override
29  {
30  UNUSED(a_ChunkInterface);
31  UNUSED(a_BlockX);
32  UNUSED(a_BlockY);
33  UNUSED(a_BlockZ);
34  UNUSED(a_CursorX);
35  UNUSED(a_CursorZ);
36  a_BlockType = m_BlockType;
37  a_BlockMeta = RotationToMetaData(a_Player.GetYaw());
38  switch (a_BlockFace)
39  {
40  case BLOCK_FACE_TOP: break;
41  case BLOCK_FACE_BOTTOM: a_BlockMeta = a_BlockMeta | 0x4; break; // When placing onto a bottom face, always place an upside-down stairs block
42  case BLOCK_FACE_EAST:
43  case BLOCK_FACE_NORTH:
44  case BLOCK_FACE_SOUTH:
45  case BLOCK_FACE_WEST:
46  {
47  // When placing onto a sideways face, check cursor, if in top half, make it an upside-down stairs block
48  if (a_CursorY > 8)
49  {
50  a_BlockMeta |= 0x4;
51  }
52  break;
53  }
54  case BLOCK_FACE_NONE: return false;
55  }
56  return true;
57  }
58 
59  static NIBBLETYPE RotationToMetaData(double a_Rotation)
60  {
61  a_Rotation += 90 + 45; // So its not aligned with axis
62  if (a_Rotation > 360)
63  {
64  a_Rotation -= 360;
65  }
66  if ((a_Rotation >= 0) && (a_Rotation < 90))
67  {
68  return 0x0;
69  }
70  else if ((a_Rotation >= 180) && (a_Rotation < 270))
71  {
72  return 0x1;
73  }
74  else if ((a_Rotation >= 90) && (a_Rotation < 180))
75  {
76  return 0x2;
77  }
78  else
79  {
80  return 0x3;
81  }
82  }
83 
84  virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
85  {
86  // Toggle bit 3:
87  return (a_Meta & 0x0b) | ((~a_Meta) & 0x04);
88  }
89 
90  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
91  {
92  UNUSED(a_Meta);
93  switch (m_BlockType)
94  {
96  case E_BLOCK_BIRCH_WOOD_STAIRS: return 2;
97  case E_BLOCK_QUARTZ_STAIRS: return 8;
99  case E_BLOCK_RED_SANDSTONE_STAIRS: return 10;
101  case E_BLOCK_STONE_BRICK_STAIRS: return 11;
102  case E_BLOCK_OAK_WOOD_STAIRS: return 13;
103  case E_BLOCK_ACACIA_WOOD_STAIRS: return 15;
104  case E_BLOCK_PURPUR_STAIRS: return 16;
105  case E_BLOCK_DARK_OAK_WOOD_STAIRS: return 26;
106  case E_BLOCK_BRICK_STAIRS: return 28;
107  case E_BLOCK_NETHER_BRICK_STAIRS: return 35;
108  case E_BLOCK_SPRUCE_WOOD_STAIRS: return 34;
109  default:
110  {
111  ASSERT(!"Unhandled blocktype in stairs handler!");
112  return 0;
113  }
114  }
115  }
116 
121  #if 0
122  bool IsInsideBlock(const Vector3d & a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta)
123  {
124  if (a_BlockMeta & 0x4) // upside down
125  {
126  return true;
127  }
128  else if ((a_BlockMeta & 0x3) == 0) // tall side is east (+X)
129  {
130  return a_Position.y < ((a_Position.x > 0.5) ? 1.0 : 0.5);
131  }
132  else if ((a_BlockMeta & 0x3) == 1) // tall side is west (-X)
133  {
134  return a_Position.y < ((a_Position.x < 0.5) ? 1.0 : 0.5);
135  }
136  else if ((a_BlockMeta & 0x3) == 2) // tall side is south (+Z)
137  {
138  return a_Position.y < ((a_Position.z > 0.5) ? 1.0 : 0.5);
139  }
140  else if ((a_BlockMeta & 0x3) == 3) // tall side is north (-Z)
141  {
142  return a_Position.y < ((a_Position.z < 0.5) ? 1.0 : 0.5);
143  }
144  return false;
145  }
146  #endif
147 
148 } ;
149 
150 
151 
152 
T x
Definition: Vector3.h:17
cBlockStairsHandler(BLOCKTYPE a_BlockType)
Definition: BlockStairs.h:17
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
Definition: Player.h:27
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
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: BlockStairs.h:23
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
static NIBBLETYPE RotationToMetaData(double a_Rotation)
Definition: BlockStairs.h:59
T y
Definition: Vector3.h:17
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockStairs.h:90
T z
Definition: Vector3.h:17
#define ASSERT(x)
Definition: Globals.h:335
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
Mirros a given block meta around the XZ plane.
Definition: BlockStairs.h:84
#define UNUSED
Definition: Globals.h:152
double GetYaw(void) const
Definition: Entity.h:209
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
Byte ColourID
Definition: Globals.h:118
Mixin to clear the block&#39;s meta value when converting to a pickup.
Definition: Mixins.h:55
virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta)
Tests if a_Position is inside the block where a_Position is relative to the origin of the block Note ...