2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2019-10-16 04:06:34 -04:00
|
|
|
#include "Mixins.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockStairsHandler :
|
2019-10-16 04:06:34 -04:00
|
|
|
public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x02, 0x01, true>>
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x03, 0x00, 0x02, 0x01, true>>;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2020-04-21 16:19:22 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2020-04-21 16:19:22 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual bool GetPlacementBlockTypeMeta(
|
2020-04-21 16:19:22 -04:00
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cPlayer & a_Player,
|
|
|
|
const Vector3i a_PlacedBlockPos,
|
|
|
|
eBlockFace a_ClickedBlockFace,
|
|
|
|
const Vector3i a_CursorPos,
|
2013-07-29 07:13:03 -04:00
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-03-07 13:42:13 -05:00
|
|
|
UNUSED(a_ChunkInterface);
|
2020-04-21 16:19:22 -04:00
|
|
|
UNUSED(a_PlacedBlockPos);
|
|
|
|
UNUSED(a_CursorPos);
|
2013-07-29 07:13:03 -04:00
|
|
|
a_BlockType = m_BlockType;
|
2017-07-31 16:17:52 -04:00
|
|
|
a_BlockMeta = RotationToMetaData(a_Player.GetYaw());
|
2020-04-21 16:19:22 -04:00
|
|
|
switch (a_ClickedBlockFace)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
case BLOCK_FACE_TOP: break;
|
|
|
|
case BLOCK_FACE_BOTTOM: a_BlockMeta = a_BlockMeta | 0x4; break; // When placing onto a bottom face, always place an upside-down stairs block
|
|
|
|
case BLOCK_FACE_EAST:
|
|
|
|
case BLOCK_FACE_NORTH:
|
|
|
|
case BLOCK_FACE_SOUTH:
|
|
|
|
case BLOCK_FACE_WEST:
|
|
|
|
{
|
|
|
|
// When placing onto a sideways face, check cursor, if in top half, make it an upside-down stairs block
|
2020-04-21 16:19:22 -04:00
|
|
|
if (a_CursorPos.y > 8)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
a_BlockMeta |= 0x4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-04-01 08:55:46 -04:00
|
|
|
case BLOCK_FACE_NONE: return false;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-19 16:14:37 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
static NIBBLETYPE RotationToMetaData(double a_Rotation)
|
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
a_Rotation += 90 + 45; // So its not aligned with axis
|
2013-07-29 07:13:03 -04:00
|
|
|
if (a_Rotation > 360)
|
|
|
|
{
|
|
|
|
a_Rotation -= 360;
|
|
|
|
}
|
|
|
|
if ((a_Rotation >= 0) && (a_Rotation < 90))
|
|
|
|
{
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
else if ((a_Rotation >= 180) && (a_Rotation < 270))
|
|
|
|
{
|
|
|
|
return 0x1;
|
|
|
|
}
|
|
|
|
else if ((a_Rotation >= 90) && (a_Rotation < 180))
|
|
|
|
{
|
|
|
|
return 0x2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0x3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) const override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
// Toggle bit 3:
|
|
|
|
return (a_Meta & 0x0b) | ((~a_Meta) & 0x04);
|
|
|
|
}
|
2015-06-30 10:50:15 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
2015-06-30 10:50:15 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
switch (m_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_SANDSTONE_STAIRS:
|
|
|
|
case E_BLOCK_BIRCH_WOOD_STAIRS: return 2;
|
|
|
|
case E_BLOCK_QUARTZ_STAIRS: return 8;
|
|
|
|
case E_BLOCK_JUNGLE_WOOD_STAIRS:
|
|
|
|
case E_BLOCK_RED_SANDSTONE_STAIRS: return 10;
|
|
|
|
case E_BLOCK_COBBLESTONE_STAIRS:
|
|
|
|
case E_BLOCK_STONE_BRICK_STAIRS: return 11;
|
|
|
|
case E_BLOCK_OAK_WOOD_STAIRS: return 13;
|
|
|
|
case E_BLOCK_ACACIA_WOOD_STAIRS: return 15;
|
2017-02-14 05:13:55 -05:00
|
|
|
case E_BLOCK_PURPUR_STAIRS: return 16;
|
2015-06-30 10:50:15 -04:00
|
|
|
case E_BLOCK_DARK_OAK_WOOD_STAIRS: return 26;
|
|
|
|
case E_BLOCK_BRICK_STAIRS: return 28;
|
|
|
|
case E_BLOCK_NETHER_BRICK_STAIRS: return 35;
|
|
|
|
case E_BLOCK_SPRUCE_WOOD_STAIRS: return 34;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled blocktype in stairs handler!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 08:02:07 -05:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-10 08:02:07 -05:00
|
|
|
/** EXCEPTION a.k.a. why is this removed:
|
|
|
|
This collision-detection is actually more accurate than the client, but since the client itself
|
|
|
|
sends inaccurate / sparse data, it's easier to just err on the side of the client and keep the
|
|
|
|
two in sync by assuming that if a player hit ANY of the stair's bounding cube, it counts as the ground. */
|
|
|
|
#if 0
|
2020-04-21 16:19:22 -04:00
|
|
|
bool IsInsideBlock(Vector3d a_RelPosition, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta)
|
2015-11-10 08:02:07 -05:00
|
|
|
{
|
|
|
|
if (a_BlockMeta & 0x4) // upside down
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ((a_BlockMeta & 0x3) == 0) // tall side is east (+X)
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
return (a_RelPosition.y < ((a_RelPosition.x > 0.5) ? 1.0 : 0.5));
|
2015-11-10 08:02:07 -05:00
|
|
|
}
|
|
|
|
else if ((a_BlockMeta & 0x3) == 1) // tall side is west (-X)
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
return (a_RelPosition.y < ((a_RelPosition.x < 0.5) ? 1.0 : 0.5));
|
2015-11-10 08:02:07 -05:00
|
|
|
}
|
|
|
|
else if ((a_BlockMeta & 0x3) == 2) // tall side is south (+Z)
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
return (a_RelPosition.y < ((a_RelPosition.z > 0.5) ? 1.0 : 0.5));
|
2015-11-10 08:02:07 -05:00
|
|
|
}
|
|
|
|
else if ((a_BlockMeta & 0x3) == 3) // tall side is north (-Z)
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
return (a_RelPosition.y < ((a_RelPosition.z < 0.5) ? 1.0 : 0.5));
|
2015-11-10 08:02:07 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|