2014-12-01 12:10:37 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
#include "../FastRandom.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockCocoaPodHandler final :
|
2014-12-01 12:10:37 -05:00
|
|
|
public cBlockHandler
|
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockHandler;
|
2019-10-11 05:02:53 -04:00
|
|
|
|
2014-12-01 12:10:37 -05:00
|
|
|
public:
|
2019-10-11 05:02:53 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2019-10-11 05:02:53 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
static NIBBLETYPE BlockFaceToMeta(eBlockFace a_BlockFace)
|
|
|
|
{
|
|
|
|
switch (a_BlockFace)
|
|
|
|
{
|
|
|
|
case BLOCK_FACE_ZM: return 0;
|
|
|
|
case BLOCK_FACE_XM: return 3;
|
|
|
|
case BLOCK_FACE_XP: return 1;
|
|
|
|
case BLOCK_FACE_ZP: return 2;
|
|
|
|
case BLOCK_FACE_NONE:
|
|
|
|
case BLOCK_FACE_YM:
|
|
|
|
case BLOCK_FACE_YP:
|
|
|
|
{
|
2021-02-20 11:24:13 -05:00
|
|
|
break;
|
2020-09-20 09:50:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE("Unsupported block face");
|
|
|
|
}
|
2019-10-11 05:02:53 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2019-10-11 05:02:53 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const override
|
2014-12-01 12:10:37 -05:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
// Check that we're attached to a jungle log block:
|
|
|
|
eBlockFace BlockFace = MetaToBlockFace(a_Chunk.GetMeta(a_RelPos));
|
|
|
|
auto LogPos = AddFaceDirection(a_RelPos, BlockFace, true);
|
2014-12-01 12:10:37 -05:00
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
2020-04-21 16:19:22 -04:00
|
|
|
a_Chunk.UnboundedRelGetBlock(LogPos, BlockType, BlockMeta);
|
|
|
|
return ((BlockType == E_BLOCK_LOG) && ((BlockMeta & 0x03) == E_META_LOG_JUNGLE));
|
2014-12-01 12:10:37 -05:00
|
|
|
}
|
|
|
|
|
2019-10-11 05:02:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
virtual void OnUpdate(
|
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cWorldInterface & a_WorldInterface,
|
|
|
|
cBlockPluginInterface & a_PluginInterface,
|
|
|
|
cChunk & a_Chunk,
|
|
|
|
const Vector3i a_RelPos
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2014-12-01 12:10:37 -05:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
if (GetRandomProvider().RandBool(0.20))
|
2014-12-01 12:10:37 -05:00
|
|
|
{
|
2020-04-17 05:36:37 -04:00
|
|
|
Grow(a_Chunk, a_RelPos);
|
2014-12-01 12:10:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-23 11:06:27 -04:00
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override
|
2014-12-01 12:10:37 -05:00
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
// If fully grown, give 3 items, otherwise just one:
|
|
|
|
auto growState = a_BlockMeta >> 2;
|
|
|
|
return cItem(E_ITEM_DYE, ((growState >= 2) ? 3 : 1), E_META_DYE_BROWN);
|
2014-12-01 12:10:37 -05:00
|
|
|
}
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual int Grow(cChunk & a_Chunk, Vector3i a_RelPos, int a_NumStages = 1) const override
|
2019-10-11 05:02:53 -04:00
|
|
|
{
|
|
|
|
auto meta = a_Chunk.GetMeta(a_RelPos);
|
|
|
|
auto typeMeta = meta & 0x03;
|
|
|
|
auto growState = meta >> 2;
|
|
|
|
|
2020-03-23 04:19:52 -04:00
|
|
|
if (growState >= 2)
|
2019-10-11 05:02:53 -04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2020-03-23 04:19:52 -04:00
|
|
|
auto newState = std::min(growState + a_NumStages, 2);
|
2019-10-11 05:02:53 -04:00
|
|
|
a_Chunk.SetMeta(a_RelPos, static_cast<NIBBLETYPE>(newState << 2 | typeMeta));
|
|
|
|
return newState - growState;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-12-01 12:10:37 -05:00
|
|
|
static eBlockFace MetaToBlockFace(NIBBLETYPE a_Meta)
|
|
|
|
{
|
2019-10-11 05:02:53 -04:00
|
|
|
switch (a_Meta & 0x03)
|
2014-12-01 12:10:37 -05:00
|
|
|
{
|
|
|
|
case 0: return BLOCK_FACE_ZM;
|
|
|
|
case 1: return BLOCK_FACE_XP;
|
|
|
|
case 2: return BLOCK_FACE_ZP;
|
|
|
|
case 3: return BLOCK_FACE_XM;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Bad meta");
|
|
|
|
return BLOCK_FACE_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 05:02:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
2015-06-30 10:50:15 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 34;
|
|
|
|
}
|
2014-12-01 12:10:37 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|