1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#pragma once
#include "BlockHandler.h"
#include "ChunkInterface.h"
/** Handles the grass that is 1 block tall */
class cBlockTallGrassHandler final : public cBlockHandler
{
using Super = cBlockHandler;
public:
using Super::Super;
private:
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
{
return true;
}
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
{
// If using shears, drop self:
if ((a_Tool != nullptr) && (a_Tool->m_ItemType == E_ITEM_SHEARS))
{
return cItem(m_BlockType, 1, a_BlockMeta);
}
// Drop seeds, depending on bernoulli trial result:
if (GetRandomProvider().RandBool(0.875)) // 87.5% chance of dropping nothing
{
return {};
}
// 12.5% chance of dropping 0 or more seeds.
const auto DropNum = FortuneDiscreteRandom(1, 1, 2 * ToolFortuneLevel(a_Tool));
return cItem(E_ITEM_SEEDS, DropNum);
}
virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
{
if (a_Position.y <= 0)
{
return false;
}
BLOCKTYPE BelowBlock = a_Chunk.GetBlock(a_Position.addedY(-1));
return IsBlockTypeOfDirt(BelowBlock);
}
/** Growing a tall grass produces a big flower (2-block high fern or double-tall grass). */
virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) const override
{
if (a_RelPos.y > (cChunkDef::Height - 2))
{
return 0;
}
auto blockMeta = a_Chunk.GetMeta(a_RelPos);
NIBBLETYPE largeFlowerMeta;
switch (blockMeta)
{
case E_META_TALL_GRASS_GRASS: largeFlowerMeta = E_META_BIG_FLOWER_DOUBLE_TALL_GRASS; break;
case E_META_TALL_GRASS_FERN: largeFlowerMeta = E_META_BIG_FLOWER_LARGE_FERN; break;
default: return 0;
}
a_Chunk.SetBlock(a_RelPos, E_BLOCK_BIG_FLOWER, largeFlowerMeta);
a_Chunk.SetBlock(a_RelPos.addedY(1), E_BLOCK_BIG_FLOWER, E_META_BIG_FLOWER_TOP);
return 1;
}
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
{
UNUSED(a_Meta);
return 7;
}
};
|