Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockDropSpenser.h
Go to the documentation of this file.
1 
2 // BlockDropSpenser.h
3 
4 // Declares the cBlockDropSpenserHandler class representing the BlockHandler for Dropper and Dispenser blocks
5 
6 #pragma once
7 
8 #include "../Blocks/BlockPiston.h"
9 #include "../BlockEntities/DropSpenserEntity.h"
10 #include "Mixins.h"
11 
12 
13 
14 
15 
17  public cMetaRotator<cBlockEntityHandler, 0x07, 0x02, 0x05, 0x03, 0x04>
18 {
20 
21 public:
22 
24  super(a_BlockType)
25  {
26  }
27 
28 
29 
30 
31 
33  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
34  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
35  int a_CursorX, int a_CursorY, int a_CursorZ,
36  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
37  ) override
38  {
39  a_BlockType = m_BlockType;
40 
41  // FIXME: Do not use cPiston class for dispenser placement!
42  a_BlockMeta = cBlockPistonHandler::RotationPitchToMetaData(a_Player.GetYaw(), a_Player.GetPitch());
43  return true;
44  }
45 
46 
47 
48 
49 
50  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
51  {
52  cItems res(cItem(m_BlockType, 1));
53  if (a_BlockEntity != nullptr)
54  {
55  auto be = static_cast<cDropSpenserEntity *>(a_BlockEntity);
56  res.AddItemGrid(be->GetContents());
57  }
58  return res;
59  }
60 
61 
62 
63 
64 
65  virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
66  {
67  // Bit 0x08 is a flag. Lowest three bits are position.
68  NIBBLETYPE OtherMeta = a_Meta & 0x08;
69  // Mirrors defined by a table. (Source, minecraft.gamepedia.com)
70  switch (a_Meta & 0x07)
71  {
72  case 0x00: return 0x01 + OtherMeta; // Down -> Up
73  case 0x01: return 0x00 + OtherMeta; // Up -> Down
74  }
75  // Not Facing Up or Down; No change.
76  return a_Meta;
77  }
78 
79 
80 
81 
82 
83  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
84  {
85  UNUSED(a_Meta);
86  return 11;
87  }
88 } ;
89 
90 
91 
92 
static NIBBLETYPE RotationPitchToMetaData(double a_Rotation, double a_Pitch)
Definition: BlockPiston.h:41
double GetPitch(void) const
Definition: Entity.h:210
cBlockDropSpenserHandler(BLOCKTYPE a_BlockType)
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
Definition: Player.h:27
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
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.
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...
Mixin for rotations and reflections following the standard pattern of "apply mask, then use a switch".
Definition: Mixins.h:84
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) override
Mirros a given block meta around the XZ plane.
#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
Definition: Entity.h:73
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: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234
void AddItemGrid(const cItemGrid &a_ItemGrid)
Adds a copy of all items in a_ItemGrid.
Definition: Item.cpp:727