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

74 lines
1.4 KiB
C
Raw Normal View History

#pragma once
2014-07-18 11:04:01 -04:00
#include "BlockHandler.h"
#include "../Entities/Player.h"
#include "Chunk.h"
class cBlockWallSignHandler :
2014-07-18 11:04:01 -04:00
public cBlockHandler
{
2014-07-18 11:04:01 -04:00
typedef cBlockHandler super;
public:
cBlockWallSignHandler(BLOCKTYPE a_BlockType) :
super(a_BlockType)
{
}
2014-07-18 11:04:01 -04:00
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
a_Pickups.push_back(cItem(E_ITEM_SIGN, 1, 0));
}
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
int BlockX = (a_Chunk.GetPosX() * cChunkDef::Width) + a_RelX;
int BlockZ = (a_Chunk.GetPosZ() * cChunkDef::Width) + a_RelZ;
GetBlockCoordsBehindTheSign(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ), BlockX, BlockZ);
2014-08-04 16:22:08 -04:00
BLOCKTYPE Type = a_ChunkInterface.GetBlock(BlockX, a_RelY, BlockZ);
2014-08-04 16:22:08 -04:00
return ((Type == E_BLOCK_WALLSIGN) || (Type == E_BLOCK_SIGN_POST) || cBlockInfo::IsSolid(Type));
}
static void GetBlockCoordsBehindTheSign(NIBBLETYPE a_BlockMeta, int & a_BlockX, int & a_BlockZ)
{
switch (a_BlockMeta)
{
case 2: a_BlockZ++; break;
case 3: a_BlockZ--; break;
case 4: a_BlockX++; break;
case 5: a_BlockX--; break;
default: break;
}
}
static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction)
{
switch (a_Direction)
{
case 0x2: return 0x2;
case 0x3: return 0x3;
case 0x4: return 0x4;
case 0x5: return 0x5;
default:
{
break;
}
}
return 0x2;
}
} ;