2012-10-01 17:08:15 -04:00
|
|
|
|
2012-07-15 16:36:34 -04:00
|
|
|
#pragma once
|
2012-10-01 17:08:15 -04:00
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "BlockHandler.h"
|
|
|
|
#include "../World.h"
|
|
|
|
#include "../Ladder.h"
|
2012-07-15 16:36:34 -04:00
|
|
|
|
2012-10-01 17:08:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockLadderHandler :
|
|
|
|
public cBlockHandler
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
|
|
|
public:
|
2012-10-03 04:52:11 -04:00
|
|
|
cBlockLadderHandler(BLOCKTYPE a_BlockType)
|
|
|
|
: cBlockHandler(a_BlockType)
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-01 17:08:15 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
|
|
|
cWorld * a_World, cPlayer * a_Player,
|
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace,
|
|
|
|
int a_CursorX, int a_CursorY, int a_CursorZ,
|
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
|
|
|
) override
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!LadderCanBePlacedAt(a_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace))
|
2012-10-23 14:13:37 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
a_BlockFace = FindSuitableBlockFace(a_World, a_BlockX, a_BlockY, a_BlockZ);
|
2012-10-23 14:13:37 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (a_BlockFace == BLOCK_FACE_BOTTOM)
|
2012-10-23 14:13:37 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
return false;
|
2012-10-23 14:13:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
a_BlockType = m_BlockType;
|
|
|
|
a_BlockMeta = cLadder::DirectionToMetaData(a_BlockFace);
|
|
|
|
return true;
|
2012-07-15 16:36:34 -04:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
2012-10-23 14:13:37 -04:00
|
|
|
/// Finds a suitable Direction for the Ladder. Returns BLOCK_FACE_BOTTOM on failure
|
2013-01-11 23:46:01 -05:00
|
|
|
static char FindSuitableBlockFace(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ)
|
2012-10-23 14:13:37 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
for (int Face = 2; Face <= 5; Face++)
|
2012-10-23 14:13:37 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
if (LadderCanBePlacedAt(a_World, a_BlockX, a_BlockY, a_BlockZ, Face))
|
2012-10-23 14:13:37 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
return Face;
|
2012-10-23 14:13:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return BLOCK_FACE_BOTTOM;
|
|
|
|
}
|
|
|
|
|
2012-10-01 17:08:15 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
static bool LadderCanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
if ((a_BlockFace == BLOCK_FACE_BOTTOM) || (a_BlockFace == BLOCK_FACE_TOP))
|
2012-10-23 14:13:37 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true);
|
2012-10-23 14:13:37 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
return g_BlockIsSolid[a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ)];
|
2012-10-23 14:13:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-15 16:18:11 -04:00
|
|
|
virtual bool CanBeAt(int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
2012-10-23 14:13:37 -04:00
|
|
|
{
|
2013-03-15 16:18:11 -04:00
|
|
|
// TODO: Use cTorch::AdjustCoordsByMeta(), then cChunk::UnboundedRelGetBlock() and finally some comparison
|
|
|
|
char BlockFace = cLadder::MetaDataToDirection(a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
|
|
|
|
int BlockX = a_RelX + a_Chunk.GetPosX() * cChunkDef::Width;
|
|
|
|
int BlockZ = a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width;
|
|
|
|
return LadderCanBePlacedAt(a_Chunk.GetWorld(), BlockX, a_RelY, BlockZ, BlockFace);
|
2012-07-16 09:30:33 -04:00
|
|
|
}
|
2012-09-11 08:01:34 -04:00
|
|
|
|
|
|
|
|
2012-10-01 17:08:15 -04:00
|
|
|
virtual const char * GetStepSound(void) override
|
2012-09-11 08:01:34 -04:00
|
|
|
{
|
|
|
|
return "step.wood";
|
|
|
|
}
|
2012-10-01 17:08:15 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|