2014-03-28 17:22:29 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2014-09-26 13:13:19 -04:00
|
|
|
#include "ChunkInterface.h"
|
2020-04-03 02:57:01 -04:00
|
|
|
#include "../BlockInfo.h"
|
2018-01-05 06:28:06 -05:00
|
|
|
#include "../Items/ItemHandler.h"
|
2014-03-28 17:22:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockBigFlowerHandler final :
|
2014-03-28 17:22:29 -04:00
|
|
|
public cBlockHandler
|
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockHandler;
|
2019-10-11 05:02:53 -04:00
|
|
|
|
2014-03-28 17:22:29 -04:00
|
|
|
public:
|
|
|
|
|
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
|
|
|
private:
|
2019-10-11 05:02:53 -04:00
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
virtual bool DoesIgnoreBuildCollision(const cWorld & a_World, const cItem & a_HeldItem, const Vector3i a_Position, NIBBLETYPE a_Meta, const eBlockFace a_ClickedBlockFace, const bool a_ClickedDirectly) const override
|
2017-03-22 06:04:32 -04:00
|
|
|
{
|
2017-07-07 10:37:53 -04:00
|
|
|
if (IsMetaTopPart(a_Meta))
|
|
|
|
{
|
|
|
|
BLOCKTYPE BottomType;
|
|
|
|
if (
|
2021-05-05 09:25:10 -04:00
|
|
|
(a_Position.y < 1) ||
|
|
|
|
!a_World.GetBlockTypeMeta(a_Position - Vector3i(0, 1, 0), BottomType, a_Meta) ||
|
2017-07-07 10:37:53 -04:00
|
|
|
(BottomType != E_BLOCK_BIG_FLOWER)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Can't find the flower meta so assume grass
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NIBBLETYPE FlowerMeta = a_Meta & 0x07;
|
|
|
|
return (
|
|
|
|
(FlowerMeta == E_META_BIG_FLOWER_DOUBLE_TALL_GRASS) ||
|
|
|
|
(FlowerMeta == E_META_BIG_FLOWER_LARGE_FERN)
|
|
|
|
);
|
2017-03-22 06:04:32 -04:00
|
|
|
}
|
|
|
|
|
2017-06-14 08:23:33 -04:00
|
|
|
|
2014-03-28 17:22:29 -04:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
2021-03-28 09:41:34 -04:00
|
|
|
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
|
2014-03-28 17:22:29 -04:00
|
|
|
{
|
2017-07-07 10:37:53 -04:00
|
|
|
if (IsMetaTopPart(a_BlockMeta))
|
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
return {}; // No drops from the top part
|
2017-07-07 10:37:53 -04:00
|
|
|
}
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
// With shears, drop self (even tall grass and fern):
|
|
|
|
if ((a_Tool != nullptr) && (a_Tool->m_ItemType == E_ITEM_SHEARS))
|
|
|
|
{
|
|
|
|
// Bit 0x08 specifies whether this is a top part or bottom; cut it off from the pickup:
|
|
|
|
return cItem(m_BlockType, 1, a_BlockMeta & 0x07);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tall grass drops seeds, large fern drops nothing, others drop self:
|
|
|
|
auto flowerType = a_BlockMeta & 0x07;
|
|
|
|
if (flowerType == E_META_BIG_FLOWER_DOUBLE_TALL_GRASS)
|
2014-03-28 17:22:29 -04:00
|
|
|
{
|
2020-09-28 08:41:49 -04:00
|
|
|
|
|
|
|
// Drop seeds, depending on bernoulli trial result:
|
|
|
|
if (GetRandomProvider().RandBool(0.875))
|
2017-06-19 12:11:24 -04:00
|
|
|
{
|
2020-09-28 08:41:49 -04:00
|
|
|
// 87.5% chance of dropping nothing:
|
|
|
|
return {};
|
2017-06-19 12:11:24 -04:00
|
|
|
}
|
2020-09-28 08:41:49 -04:00
|
|
|
|
|
|
|
// 12.5% chance of dropping some seeds.
|
|
|
|
const auto DropNum = FortuneDiscreteRandom(1, 1, 2 * ToolFortuneLevel(a_Tool));
|
|
|
|
return cItem(E_ITEM_SEEDS, DropNum);
|
2017-06-14 08:23:33 -04:00
|
|
|
}
|
2019-10-16 04:06:34 -04:00
|
|
|
else if (flowerType != E_META_BIG_FLOWER_LARGE_FERN)
|
2017-06-14 08:23:33 -04:00
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
return cItem(m_BlockType, 1, static_cast<short>(flowerType));
|
2014-03-28 17:22:29 -04:00
|
|
|
}
|
2020-09-28 08:41:49 -04:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
return {};
|
2014-03-28 17:22:29 -04:00
|
|
|
}
|
2014-03-28 18:14:58 -04:00
|
|
|
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-03-22 06:04:32 -04:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2014-03-28 18:14:58 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
static bool IsMetaTopPart(NIBBLETYPE a_Meta)
|
2017-01-21 08:15:45 -05:00
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
return ((a_Meta & 0x08) != 0);
|
2017-01-21 08:15:45 -05:00
|
|
|
}
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
|
2014-03-28 17:22:29 -04:00
|
|
|
{
|
2021-05-05 09:25:10 -04:00
|
|
|
// CanBeAt is also called on placement, so the top part can't check for the bottom part.
|
|
|
|
// Both parts can only that they're rooted in grass.
|
2017-01-21 08:15:45 -05:00
|
|
|
|
2021-05-05 09:25:10 -04:00
|
|
|
const auto RootPosition = a_Position.addedY(IsMetaTopPart(a_Meta) ? -2 : -1);
|
|
|
|
return (RootPosition.y >= 0) && IsBlockTypeOfDirt(a_Chunk.GetBlock(RootPosition));
|
2014-03-28 17:22:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-08 15:13:44 -04:00
|
|
|
virtual void OnBroken(
|
|
|
|
cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
|
|
|
|
const Vector3i a_BlockPos,
|
|
|
|
BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta,
|
|
|
|
const cEntity * a_Digger
|
|
|
|
) const override
|
2019-10-16 04:06:34 -04:00
|
|
|
{
|
2020-10-08 15:13:44 -04:00
|
|
|
UNUSED(a_Digger);
|
2019-10-16 04:06:34 -04:00
|
|
|
if ((a_OldBlockMeta & 0x8) != 0)
|
2014-03-28 17:22:29 -04:00
|
|
|
{
|
2014-03-28 17:24:54 -04:00
|
|
|
// Was upper part of flower
|
2019-10-16 04:06:34 -04:00
|
|
|
auto lowerPartPos = a_BlockPos - Vector3i(0, 1, 0);
|
|
|
|
if (a_ChunkInterface.GetBlock(lowerPartPos) == a_OldBlockType)
|
2014-03-28 17:22:29 -04:00
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
a_ChunkInterface.DropBlockAsPickups(lowerPartPos);
|
2014-03-28 17:22:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Was lower part
|
2019-10-16 04:06:34 -04:00
|
|
|
auto upperPartPos = a_BlockPos + Vector3i(0, 1, 0);
|
|
|
|
if (a_ChunkInterface.GetBlock(upperPartPos) == a_OldBlockType)
|
2014-03-28 17:22:29 -04:00
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
a_ChunkInterface.DropBlockAsPickups(upperPartPos);
|
2014-03-28 17:22:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-30 10:50:15 -04:00
|
|
|
|
2019-10-16 04:06:34 -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 7;
|
|
|
|
}
|
2014-03-28 17:22:29 -04:00
|
|
|
} ;
|