2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
#include "../World.h"
|
2014-07-14 15:26:36 -04:00
|
|
|
#include "ClearMetaOnDrop.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockLadderHandler :
|
2014-07-14 15:26:36 -04:00
|
|
|
public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04> >
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-07-17 16:59:02 -04:00
|
|
|
typedef cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x07, 0x02, 0x05, 0x03, 0x04> > super;
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
|
|
|
cBlockLadderHandler(BLOCKTYPE a_BlockType)
|
2014-07-15 07:27:36 -04:00
|
|
|
: super(a_BlockType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-07-17 16:59:02 -04:00
|
|
|
}
|
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-07-17 16:59:02 -04: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-07-14 16:57:44 -04:00
|
|
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
a_Pickups.Add(m_BlockType, 1, 0); // Reset meta
|
2014-07-14 16:57:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction)
|
|
|
|
{
|
2013-07-29 07:13:03 -04:00
|
|
|
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;
|
2014-07-14 16:57:44 -04:00
|
|
|
default: return 0x2;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2014-07-14 16:57:44 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
2014-07-14 16:57:44 -04:00
|
|
|
static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData)
|
|
|
|
{
|
2013-07-29 07:13:03 -04:00
|
|
|
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
|
|
|
}
|
2014-07-14 16:57:44 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
2014-07-14 16:57:44 -04:00
|
|
|
/** 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";
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|