2013-07-29 11:13:03 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 10:27:14 +00:00
|
|
|
class cBlockSnowHandler final :
|
2013-07-29 11:13:03 +00:00
|
|
|
public cBlockHandler
|
|
|
|
{
|
2020-04-21 20:19:22 +00:00
|
|
|
using Super = cBlockHandler;
|
|
|
|
|
2013-07-29 11:13:03 +00:00
|
|
|
public:
|
2020-04-21 20:19:22 +00:00
|
|
|
|
2020-09-20 13:50:52 +00:00
|
|
|
using Super::Super;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-09-12 21:26:13 +00:00
|
|
|
enum
|
|
|
|
{
|
2021-05-05 13:25:10 +00:00
|
|
|
FullBlockMeta = 7 // Meta value of a full-height snow block.
|
2017-09-12 21:26:13 +00:00
|
|
|
};
|
|
|
|
|
2020-04-21 20:19:22 +00:00
|
|
|
|
2021-05-05 13:25:10 +00:00
|
|
|
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
|
2013-07-29 11:13:03 +00:00
|
|
|
{
|
2021-05-05 13:25:10 +00:00
|
|
|
if (a_Meta == 0)
|
2013-11-30 00:31:21 +00:00
|
|
|
{
|
2021-05-05 13:25:10 +00:00
|
|
|
return true; // If at normal snowfall height (lowest), we ignore collision.
|
2013-11-30 00:31:21 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 13:25:10 +00:00
|
|
|
// Special case if a player is holding a (thin) snow block and its size can be increased:
|
|
|
|
if ((a_HeldItem.m_ItemType == E_BLOCK_SNOW) && (a_Meta < FullBlockMeta))
|
2013-11-30 00:31:21 +00:00
|
|
|
{
|
2021-05-05 13:25:10 +00:00
|
|
|
return !a_ClickedDirectly || (a_ClickedBlockFace == BLOCK_FACE_YP); // If clicked an adjacent block, or clicked YP directly, we ignore collision.
|
2013-11-30 00:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-07-29 11:13:03 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-28 13:41:34 +00:00
|
|
|
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
|
2013-07-29 11:13:03 +00:00
|
|
|
{
|
2021-05-05 13:25:10 +00:00
|
|
|
// No drop unless dug up with a shovel:
|
2019-10-16 08:06:34 +00:00
|
|
|
if ((a_Tool == nullptr) || !ItemCategory::IsShovel(a_Tool->m_ItemType))
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ToolHasSilkTouch(a_Tool))
|
|
|
|
{
|
|
|
|
return cItem(m_BlockType, 1, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Drop as many snowballs as there were "layers" of snow:
|
|
|
|
return cItem(E_ITEM_SNOWBALL, 1 + (a_BlockMeta & 0x07), 0);
|
|
|
|
}
|
2013-07-29 11:13:03 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 08:06:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-05 13:25:10 +00:00
|
|
|
virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
|
2013-07-29 11:13:03 +00:00
|
|
|
{
|
2021-05-05 13:25:10 +00:00
|
|
|
if (a_Position.y <= 0)
|
2013-11-30 11:45:23 +00:00
|
|
|
{
|
2020-04-21 20:19:22 +00:00
|
|
|
return false;
|
2013-11-30 11:45:23 +00:00
|
|
|
}
|
2021-05-05 13:25:10 +00:00
|
|
|
auto BelowPos = a_Position.addedY(-1);
|
2020-04-21 20:19:22 +00:00
|
|
|
auto BlockBelow = a_Chunk.GetBlock(BelowPos);
|
|
|
|
auto MetaBelow = a_Chunk.GetMeta(BelowPos);
|
|
|
|
return CanBeOn(BlockBelow, MetaBelow);
|
2013-07-29 11:13:03 +00:00
|
|
|
}
|
2016-02-05 21:45:45 +00:00
|
|
|
|
2020-04-21 20:19:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 13:50:52 +00:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
2015-06-30 14:50:15 +00:00
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 14;
|
|
|
|
}
|
2015-11-10 13:02:07 +00:00
|
|
|
|
2020-04-21 20:19:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 13:50:52 +00:00
|
|
|
virtual bool IsInsideBlock(const Vector3d a_RelPosition, const NIBBLETYPE a_BlockMeta) const override
|
2015-11-10 13:02:07 +00:00
|
|
|
{
|
2020-04-21 20:19:22 +00:00
|
|
|
return a_RelPosition.y < (cBlockInfo::GetBlockHeight(m_BlockType) * (a_BlockMeta & 0x07));
|
2017-09-12 21:26:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 20:19:22 +00:00
|
|
|
|
2017-09-12 21:26:13 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/** Returns true if snow can be placed on top of a block with the given type and meta. */
|
|
|
|
static bool CanBeOn(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
2021-05-05 13:25:10 +00:00
|
|
|
// If block below is snowable, or it is a thin snow block and is a full thin snow block, say yay:
|
2017-09-12 21:26:13 +00:00
|
|
|
return (
|
|
|
|
cBlockInfo::IsSnowable(a_BlockType) ||
|
|
|
|
(
|
|
|
|
(a_BlockType == E_BLOCK_SNOW) &&
|
|
|
|
(a_BlockMeta == FullBlockMeta)
|
|
|
|
)
|
|
|
|
);
|
2015-11-10 13:02:07 +00:00
|
|
|
}
|
2017-09-12 21:26:13 +00:00
|
|
|
|
2013-07-29 11:13:03 +00:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|