2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
/** Handler for blocks that have 3 orientations (hay bale, log), specified by the upper 2 bits in meta.
|
|
|
|
Handles setting the correct orientation on placement.
|
|
|
|
Additionally supports the metadata specifying block sub-type in its lower 2 bits. */
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockSidewaysHandler final :
|
2019-10-16 04:06:34 -04:00
|
|
|
public cBlockHandler
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockHandler;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-09-17 15:59:36 -04:00
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
2020-04-21 16:19:22 -04:00
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cPlayer & a_Player,
|
|
|
|
const Vector3i a_PlacedBlockPos,
|
|
|
|
eBlockFace a_ClickedBlockFace,
|
|
|
|
const Vector3i a_CursorPos,
|
2013-09-17 15:59:36 -04:00
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2013-09-17 15:59:36 -04:00
|
|
|
{
|
|
|
|
a_BlockType = m_BlockType;
|
2017-07-31 16:17:52 -04:00
|
|
|
NIBBLETYPE Meta = static_cast<NIBBLETYPE>(a_Player.GetEquippedItem().m_ItemDamage);
|
2020-04-21 16:19:22 -04:00
|
|
|
a_BlockMeta = BlockFaceToMetaData(a_ClickedBlockFace, Meta);
|
2013-09-17 15:59:36 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-24 14:52:35 -04: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-03-24 14:52:35 -04:00
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
// Reset the orientation part of meta, keep the sub-type part of meta
|
|
|
|
return cItem(m_BlockType, 1, a_BlockMeta & 0x03);
|
2014-03-24 14:52:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-14 16:57:44 -04:00
|
|
|
inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace, NIBBLETYPE a_Meta)
|
2013-09-17 15:59:36 -04:00
|
|
|
{
|
|
|
|
switch (a_BlockFace)
|
|
|
|
{
|
|
|
|
case BLOCK_FACE_YM:
|
|
|
|
case BLOCK_FACE_YP:
|
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
return a_Meta; // Top or bottom, just return original
|
2013-09-17 15:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
case BLOCK_FACE_ZP:
|
|
|
|
case BLOCK_FACE_ZM:
|
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
return a_Meta | 0x8; // North or south
|
2013-09-17 15:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
case BLOCK_FACE_XP:
|
|
|
|
case BLOCK_FACE_XM:
|
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
return a_Meta | 0x4; // East or west
|
2013-09-17 15:59:36 -04:00
|
|
|
}
|
|
|
|
|
2015-05-19 07:28:31 -04:00
|
|
|
case BLOCK_FACE_NONE:
|
2013-09-17 15:59:36 -04:00
|
|
|
{
|
2021-02-20 11:24:13 -05:00
|
|
|
break;
|
2013-09-17 15:59:36 -04:00
|
|
|
}
|
|
|
|
}
|
2018-02-04 18:07:12 -05:00
|
|
|
UNREACHABLE("Unsupported block face");
|
2013-09-17 15:59:36 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|