1
0
cuberite-2a/src/Blocks/BlockNetherWart.h

61 lines
1.6 KiB
C
Raw Normal View History

2013-12-18 17:33:18 +00:00
#pragma once
#include "BlockPlant.h"
#include "../FastRandom.h"
2013-12-18 17:33:18 +00:00
class cBlockNetherWartHandler :
public cBlockPlant
2013-12-18 17:33:18 +00:00
{
typedef cBlockPlant Super;
2013-12-18 17:33:18 +00:00
public:
cBlockNetherWartHandler(BLOCKTYPE a_BlockType)
: Super(a_BlockType, false)
2013-12-18 17:33:18 +00:00
{
}
2015-12-13 13:49:44 +00:00
2013-12-18 17:33:18 +00:00
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override
{
2017-06-13 19:35:30 +00:00
auto & rand = GetRandomProvider();
2013-12-18 17:33:18 +00:00
if (a_Meta == 0x3)
2013-12-18 17:33:18 +00:00
{
// Fully grown, drop the entire produce:
2017-06-13 19:35:30 +00:00
a_Pickups.emplace_back(E_ITEM_NETHER_WART, 1 + (rand.RandInt<char>(2) + rand.RandInt<char>(2)) / 2, 0);
2013-12-18 17:33:18 +00:00
}
else
{
a_Pickups.push_back(cItem(E_ITEM_NETHER_WART));
}
}
2014-02-02 14:49:37 +00:00
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
2013-12-18 17:33:18 +00:00
{
NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ);
if ((Meta < 3) && (CanGrow(a_Chunk, a_RelX, a_RelY, a_RelZ) == paGrowth))
2013-12-18 17:33:18 +00:00
{
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_NETHER_WART, ++Meta);
}
2015-12-13 13:49:44 +00:00
else if (Meta > 3) // In older versions of cuberite, there was a bug which made wart grow too much. This check fixes previously saved buggy warts.
{
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_NETHER_WART, 3);
}
2013-12-18 17:33:18 +00:00
}
2014-02-01 13:06:32 +00:00
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
2013-12-18 17:33:18 +00:00
{
// Needs to be placed on top of a Soulsand block:
2013-12-18 17:33:18 +00:00
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_SOULSAND));
}
2015-06-30 14:50:15 +00:00
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);
return 35;
}
} ;