Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockTallGrass.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "ChunkInterface.h"
6 
7 
8 
9 
10 
13  public cBlockHandler
14 {
16 
17 public:
18 
20  super(a_BlockType)
21  {
22  }
23 
24 
25 
26 
27 
28  virtual bool DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) override
29  {
30  return true;
31  }
32 
33 
34 
35 
36 
37  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
38  {
39  // If using shears, drop self:
40  if ((a_Tool != nullptr) && (a_Tool->m_ItemType == E_ITEM_SHEARS))
41  {
42  return cItem(m_BlockType, 1, a_BlockMeta);
43  }
44 
45  // Drop seeds, sometimes:
46  if (GetRandomProvider().RandBool(0.125))
47  {
48  return cItem(E_ITEM_SEEDS);
49  }
50  return {};
51  }
52 
53 
54 
55 
56 
57  virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
58  {
59  if (a_RelY <= 0)
60  {
61  return false;
62  }
63 
64  BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
65  return IsBlockTypeOfDirt(BelowBlock);
66  }
67 
68 
69 
70 
71 
73  virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) override
74  {
75  if (a_RelPos.y > (cChunkDef::Height - 2))
76  {
77  return 0;
78  }
79  auto blockMeta = a_Chunk.GetMeta(a_RelPos);
80  NIBBLETYPE largeFlowerMeta;
81  switch (blockMeta)
82  {
83  case E_META_TALL_GRASS_GRASS: largeFlowerMeta = E_META_BIG_FLOWER_DOUBLE_TALL_GRASS; break;
84  case E_META_TALL_GRASS_FERN: largeFlowerMeta = E_META_BIG_FLOWER_LARGE_FERN; break;
85  default: return 0;
86  }
87  a_Chunk.SetBlock(a_RelPos, E_BLOCK_BIG_FLOWER, largeFlowerMeta);
89  return 1;
90  }
91 
92 
93 
94 
95 
96  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
97  {
98  UNUSED(a_Meta);
99  return 7;
100  }
101 } ;
102 
103 
104 
105 
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.
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
MTRand & GetRandomProvider()
Returns the current thread&#39;s random number source.
Definition: FastRandom.cpp:20
Definition: Player.h:27
cBlockHandler(BLOCKTYPE a_BlockType)
void SetBlock(Vector3i a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: Chunk.cpp:1313
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
Definition: Chunk.h:49
T y
Definition: Vector3.h:17
static const int Height
Definition: ChunkDef.h:135
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:299
virtual int Grow(cChunk &a_Chunk, Vector3i a_RelPos, int a_NumStages=1) override
Growing a tall grass produces a big flower (2-block high fern or double-tall grass).
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:380
cBlockTallGrassHandler(BLOCKTYPE a_BlockType)
Handles the grass that is 1 block tall.
#define UNUSED
Definition: Globals.h:152
virtual bool CanBeAt(cChunkInterface &a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk &a_Chunk) override
Checks if the block can stay at the specified relative coords in the chunk.
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:177
Byte ColourID
Definition: Globals.h:118
bool IsBlockTypeOfDirt(BLOCKTYPE a_BlockType)
Definition: Defines.h:511
Definition: Entity.h:73
short m_ItemType
Definition: Item.h:209
Definition: Item.h:36
virtual bool DoesIgnoreBuildCollision(cChunkInterface &a_ChunkInterface, Vector3i a_Pos, cPlayer &a_Player, NIBBLETYPE a_Meta) override
Checks if the player can build "inside" this block.
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234
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...