Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockDeadBush.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 
6 
7 
8 
9 
10 class cBlockDeadBushHandler final :
11  public cBlockHandler
12 {
14 
15 public:
16 
17  using Super::Super;
18 
19 private:
20 
21  virtual bool DoesIgnoreBuildCollision(const cWorld & a_World, const cItem & a_HeldItem, const Vector3i a_Position, const NIBBLETYPE a_Meta, const eBlockFace a_ClickedBlockFace, const bool a_ClickedDirectly) const override
22  {
23  return true;
24  }
25 
26 
27 
28 
29 
30  virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
31  {
32  if (a_Position.y <= 0)
33  {
34  return false;
35  }
36 
37  BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_Position.addedY(-1));
38  switch (BelowBlock)
39  {
40  case E_BLOCK_CLAY:
43  case E_BLOCK_SAND:
44  {
45  return true;
46  }
47  default: return false;
48  }
49  }
50 
51 
52 
53 
54 
55  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
56  {
57  // If cutting down with shears, drop self:
58  if ((a_Tool != nullptr) && (a_Tool->m_ItemType == E_ITEM_SHEARS))
59  {
60  return cItem(m_BlockType, 1, a_BlockMeta);
61  }
62 
63  // Drop 0-3 sticks:
64  auto chance = GetRandomProvider().RandInt<char>(3);
65  if (chance > 0)
66  {
67  return cItem(E_ITEM_STICK, chance, 0);
68  }
69  return {};
70  }
71 
72 
73 
74 
75 
76  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
77  {
78  UNUSED(a_Meta);
79  return 0;
80  }
81 } ;
@ E_BLOCK_CLAY
Definition: BlockType.h:96
@ E_BLOCK_STAINED_CLAY
Definition: BlockType.h:177
@ E_BLOCK_HARDENED_CLAY
Definition: BlockType.h:191
@ E_BLOCK_SAND
Definition: BlockType.h:22
@ E_ITEM_STICK
Definition: BlockType.h:324
@ E_ITEM_SHEARS
Definition: BlockType.h:404
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
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 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: BlockDeadBush.h:55
virtual bool DoesIgnoreBuildCollision(const cWorld &a_World, const cItem &a_HeldItem, const Vector3i a_Position, const NIBBLETYPE a_Meta, const eBlockFace a_ClickedBlockFace, const bool a_ClickedDirectly) const override
Checks if the player can build "inside" this block.
Definition: BlockDeadBush.h:21
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: BlockDeadBush.h:76
virtual bool CanBeAt(const cChunk &a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
Checks if the block can stay at the specified relative coords in the chunk.
Definition: BlockDeadBush.h:30
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
const BLOCKTYPE m_BlockType
Definition: BlockHandler.h:205
Definition: Chunk.h:36
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:146
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
Definition: FastRandom.h:78
Definition: Item.h:37
short m_ItemType
Definition: Item.h:163
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
Definition: Vector3.h:314
T y
Definition: Vector3.h:17
Definition: World.h:53