Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockNetherWart.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockPlant.h"
5 #include "../FastRandom.h"
6 
7 
8 
9 
10 
12  public cBlockPlant<false>
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20 private:
21 
22  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
23  {
24  if (a_BlockMeta == 0x03)
25  {
26  // Fully grown, drop the entire produce:
27  const auto DropNum = FortuneDiscreteRandom(2, 4, ToolFortuneLevel(a_Tool));
28  return cItem(E_ITEM_NETHER_WART, DropNum);
29  }
30 
31  return cItem(E_ITEM_NETHER_WART);
32  }
33 
34 
35 
36 
37 
38  virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) const override
39  {
40  auto oldMeta = a_Chunk.GetMeta(a_RelPos);
41  auto meta = std::min(oldMeta + a_NumStages, 3);
42  if ((oldMeta < 3) && (CanGrow(a_Chunk, a_RelPos) == paGrowth))
43  {
44  a_Chunk.SetBlock(a_RelPos, m_BlockType, static_cast<NIBBLETYPE>(meta));
45  return meta - oldMeta;
46  }
47 
48  // In older versions of cuberite, there was a bug which made wart grow too much. This check fixes previously saved buggy warts.
49  if (oldMeta > 3)
50  {
51  a_Chunk.FastSetBlock(a_RelPos, m_BlockType, 3);
52  }
53  return 0;
54  }
55 
56 
57 
58 
59 
60  virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
61  {
62  // Needs to be placed on top of a Soulsand block:
63  return (a_Position.y > 0) && (a_Chunk.GetBlock(a_Position.addedY(-1)) == E_BLOCK_SOULSAND);
64  }
65 
66 
67 
68 
69 
70  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
71  {
72  UNUSED(a_Meta);
73  return 35;
74  }
75 } ;
@ E_BLOCK_SOULSAND
Definition: BlockType.h:103
@ E_ITEM_NETHER_WART
Definition: BlockType.h:417
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
Byte ColourID
Definition: Globals.h:162
#define UNUSED
Definition: Globals.h:72
static unsigned char ToolFortuneLevel(const cItem *a_Tool)
Returns the fortune level of a tool, if it is a valid tool.
static char FortuneDiscreteRandom(char a_MinDrop, char a_DefaultMax, unsigned char a_BonusMax, char a_DropCap=25)
Returns a random number of drops taking into account fortune.
const BLOCKTYPE m_BlockType
Definition: BlockHandler.h:205
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.
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.
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...
virtual int Grow(cChunk &a_Chunk, Vector3i a_RelPos, int a_NumStages=1) const override
Grows this block, if it supports growing, by the specified amount of stages (at most).
Base class for plants that use light values to decide whether to grow or not.
Definition: BlockPlant.h:14
virtual PlantAction CanGrow(cChunk &a_Chunk, Vector3i a_RelPos) const
Checks whether a plant can grow grow, based on what is returned from cBlockPlant::HasEnoughLight and ...
Definition: BlockPlant.h:81
cBlockHandler Super
Definition: BlockPlant.h:15
Definition: Chunk.h:36
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:279
void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
Definition: Chunk.cpp:1296
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:146
void SetBlock(Vector3i a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: Chunk.cpp:1263
Definition: Item.h:37
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