Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockCake.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "BlockHandler.h"
4 
5 
6 
7 
8 
9 class cBlockCakeHandler final :
10  public cBlockHandler
11 {
13 
14 public:
15 
16  using Super::Super;
17 
18 private:
19 
20  virtual bool OnUse(
21  cChunkInterface & a_ChunkInterface,
22  cWorldInterface & a_WorldInterface,
23  cPlayer & a_Player,
24  const Vector3i a_BlockPos,
25  eBlockFace a_BlockFace,
26  const Vector3i a_CursorPos
27  ) const override
28  {
29  NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockPos);
30 
31  if (!a_Player.Feed(2, 0.4))
32  {
33  return false;
34  }
35 
37  if (Meta >= 5)
38  {
39  a_ChunkInterface.DigBlock(a_WorldInterface, a_BlockPos, &a_Player);
40  }
41  else
42  {
43  a_ChunkInterface.SetBlockMeta(a_BlockPos, Meta + 1);
44  }
45  return true;
46  }
47 
48 
49 
50 
51 
52  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
53  {
54  // Give nothing
55  return {};
56  }
57 
58 
59 
60 
61 
62  virtual bool IsUseable(void) const override
63  {
64  return true;
65  }
66 
67  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
68  {
69  UNUSED(a_Meta);
70  return 14;
71  }
72 } ;
73 
74 
75 
76 
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
Byte ColourID
Definition: Globals.h:162
#define UNUSED
Definition: Globals.h:72
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockCake.h:67
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const override
Called when the user right clicks the block and the block is useable.
Definition: BlockCake.h:20
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem *const a_Tool) const override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
Definition: BlockCake.h:52
virtual bool IsUseable(void) const override
Called to check whether this block supports a rclk action.
Definition: BlockCake.h:62
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
bool DigBlock(cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, cEntity *a_Digger)
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData)
Sets the meta for the specified block, while keeping the blocktype.
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
Definition: Player.h:29
StatisticsManager & GetStatistics()
Return the associated statistic and achievement manager.
Definition: Player.h:237
bool Feed(int a_Food, double a_Saturation)
Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed,...
Definition: Player.cpp:423
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
std::unordered_map< CustomStatistic, StatValue > Custom