2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
#include "../World.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockLadderHandler :
|
2014-03-25 17:26:13 -04:00
|
|
|
public cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04>
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
cBlockLadderHandler(BLOCKTYPE a_BlockType)
|
2014-03-25 17:26:13 -04:00
|
|
|
: cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04>(a_BlockType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
2014-02-01 08:06:32 -05:00
|
|
|
cChunkInterface & a_ChunkInterface, cPlayer * a_Player,
|
2014-02-04 13:59:05 -05:00
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
|
2013-07-29 07:13:03 -04:00
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
|
|
|
) override
|
|
|
|
{
|
2014-01-31 18:17:41 -05:00
|
|
|
if (!LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-01-31 18:17:41 -05:00
|
|
|
a_BlockFace = FindSuitableBlockFace(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
if (a_BlockFace == BLOCK_FACE_BOTTOM)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a_BlockType = m_BlockType;
|
|
|
|
a_BlockMeta = DirectionToMetaData(a_BlockFace);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction) // tolua_export
|
2013-07-29 07:13:03 -04:00
|
|
|
{ // tolua_export
|
|
|
|
switch (a_Direction)
|
|
|
|
{
|
2014-02-04 13:59:05 -05:00
|
|
|
case BLOCK_FACE_ZM: return 0x2;
|
|
|
|
case BLOCK_FACE_ZP: return 0x3;
|
|
|
|
case BLOCK_FACE_XM: return 0x4;
|
|
|
|
case BLOCK_FACE_XP: return 0x5;
|
2013-07-29 07:13:03 -04:00
|
|
|
default: return 0x2;
|
|
|
|
}
|
|
|
|
} // tolua_export
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export
|
2013-07-29 07:13:03 -04:00
|
|
|
{ // tolua_export
|
|
|
|
switch (a_MetaData)
|
|
|
|
{
|
2014-02-04 13:59:05 -05:00
|
|
|
case 0x2: return BLOCK_FACE_ZM;
|
|
|
|
case 0x3: return BLOCK_FACE_ZP;
|
|
|
|
case 0x4: return BLOCK_FACE_XM;
|
|
|
|
case 0x5: return BLOCK_FACE_XP;
|
|
|
|
default: return BLOCK_FACE_ZM;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
} // tolua_export
|
|
|
|
|
|
|
|
|
|
|
|
/// Finds a suitable Direction for the Ladder. Returns BLOCK_FACE_BOTTOM on failure
|
2014-02-04 13:59:05 -05:00
|
|
|
static eBlockFace FindSuitableBlockFace(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-04 13:59:05 -05:00
|
|
|
for (int FaceInt = BLOCK_FACE_ZM; FaceInt <= BLOCK_FACE_XP; FaceInt++)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-04 13:59:05 -05:00
|
|
|
eBlockFace Face = static_cast<eBlockFace>(FaceInt);
|
2014-01-31 18:17:41 -05:00
|
|
|
if (LadderCanBePlacedAt(a_ChunkInterface, a_BlockX, a_BlockY, a_BlockZ, Face))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return Face;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BLOCK_FACE_BOTTOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
static bool LadderCanBePlacedAt(cChunkInterface & a_ChunkInterface, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
if ((a_BlockFace == BLOCK_FACE_BOTTOM) || (a_BlockFace == BLOCK_FACE_TOP))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true);
|
|
|
|
|
2014-03-01 14:34:19 -05:00
|
|
|
return cBlockInfo::IsSolid(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ));
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface,int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
// TODO: Use AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison
|
2014-02-04 13:59:05 -05:00
|
|
|
eBlockFace BlockFace = MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
|
2013-07-29 07:13:03 -04:00
|
|
|
int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
|
|
|
|
int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
|
2014-01-31 18:17:41 -05:00
|
|
|
return LadderCanBePlacedAt(a_ChunkInterface, BlockX, a_RelY, BlockZ, BlockFace);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual const char * GetStepSound(void) override
|
|
|
|
{
|
|
|
|
return "step.wood";
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|