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

94 lines
2.2 KiB
C
Raw Normal View History

#pragma once
#include "BlockHandler.h"
#include "MetaRotator.h"
class cBlockTripwireHookHandler :
public cMetaRotator<cBlockHandler, 0x03, 0x02, 0x03, 0x00, 0x01>
{
public:
cBlockTripwireHookHandler(BLOCKTYPE a_BlockType)
: cMetaRotator<cBlockHandler, 0x03, 0x02, 0x03, 0x00, 0x01>(a_BlockType)
{
}
virtual bool GetPlacementBlockTypeMeta(
2017-07-31 16:17:52 -04:00
cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
int a_CursorX, int a_CursorY, int a_CursorZ,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
2014-08-19 16:14:37 -04:00
) override
{
a_BlockType = m_BlockType;
a_BlockMeta = DirectionToMetadata(a_BlockFace);
return true;
}
inline static NIBBLETYPE DirectionToMetadata(eBlockFace a_Direction)
{
switch (a_Direction)
{
case BLOCK_FACE_XM: return 0x1;
case BLOCK_FACE_XP: return 0x3;
case BLOCK_FACE_ZM: return 0x2;
case BLOCK_FACE_ZP: return 0x0;
2015-05-19 07:28:31 -04:00
case BLOCK_FACE_NONE:
case BLOCK_FACE_YM:
case BLOCK_FACE_YP:
{
ASSERT(!"Unhandled tripwire hook direction!");
return 0x0;
}
}
#if !defined(__clang__)
ASSERT(!"Unknown BLOCK_FACE");
return 0;
#endif
}
inline static eBlockFace MetadataToDirection(NIBBLETYPE a_Meta)
{
switch (a_Meta & 0x03)
{
case 0x1: return BLOCK_FACE_XM;
case 0x3: return BLOCK_FACE_XP;
case 0x2: return BLOCK_FACE_ZM;
case 0x0: return BLOCK_FACE_ZP;
default: ASSERT(!"Unhandled tripwire hook metadata!"); return BLOCK_FACE_NONE;
}
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
2014-08-19 16:14:37 -04:00
// Reset meta to zero
a_Pickups.push_back(cItem(E_BLOCK_TRIPWIRE_HOOK, 1, 0));
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
NIBBLETYPE Meta;
a_Chunk.UnboundedRelGetBlockMeta(a_RelX, a_RelY, a_RelZ, Meta);
AddFaceDirection(a_RelX, a_RelY, a_RelZ, MetadataToDirection(Meta), true);
2014-08-19 16:14:37 -04:00
BLOCKTYPE BlockIsOn;
a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
2014-08-19 16:14:37 -04:00
return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(BlockIsOn));
}
2015-06-30 10:50:15 -04:00
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);
return 0;
}
};