Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockGravel.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 
6 
7 
8 
9 
10 class cBlockGravelHandler final :
11  public cBlockHandler
12 {
13 public:
14 
16 
17 private:
18 
19  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
20  {
21  if (ToolHasSilkTouch(a_Tool))
22  {
23  return cItem(E_BLOCK_GRAVEL);
24  }
25 
26  // Denominator of probability from wiki, don't let it go below 1.
27  const auto Denominator = std::max(10 - 3 * ToolFortuneLevel(a_Tool), 1);
28  if (GetRandomProvider().RandBool(1.0 / Denominator))
29  {
30  return cItem(E_ITEM_FLINT);
31  }
32 
33  return cItem(E_BLOCK_GRAVEL);
34  }
35 
36 
37 
38 
39 
40  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
41  {
42  UNUSED(a_Meta);
43  return 11;
44  }
45 } ;
46 
47 
48 
49 
@ E_BLOCK_GRAVEL
Definition: BlockType.h:23
@ E_ITEM_FLINT
Definition: BlockType.h:362
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
MTRand & GetRandomProvider()
Returns the current thread's random number source.
Definition: FastRandom.cpp:12
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: BlockGravel.h:40
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: BlockGravel.h:19
static unsigned char ToolFortuneLevel(const cItem *a_Tool)
Returns the fortune level of a tool, if it is a valid tool.
static bool ToolHasSilkTouch(const cItem *a_Tool)
Returns true if the specified tool is valid and has a non-zero silk-touch enchantment.
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215