2013-11-29 17:27:08 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2019-10-16 04:06:34 -04:00
|
|
|
#include "Mixins.h"
|
2015-11-23 18:39:19 -05:00
|
|
|
#include "../EffectID.h"
|
2013-11-29 17:27:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockTrapdoorHandler :
|
2020-09-21 10:41:31 -04:00
|
|
|
public cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x01, 0x02, 0x00, 0x03, false>>
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
2020-09-21 10:41:31 -04:00
|
|
|
using Super = cClearMetaOnDrop<cYawRotator<cBlockHandler, 0x03, 0x01, 0x02, 0x00, 0x03, false>>;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-11-29 17:27:08 -05:00
|
|
|
public:
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual bool IsUseable(void) const override
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
virtual bool OnUse(
|
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cWorldInterface & a_WorldInterface,
|
|
|
|
cPlayer & a_Player,
|
|
|
|
const Vector3i a_BlockPos,
|
|
|
|
eBlockFace a_BlockFace,
|
|
|
|
const Vector3i a_CursorPos
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
2014-09-30 14:04:49 -04:00
|
|
|
if (m_BlockType == E_BLOCK_IRON_TRAPDOOR)
|
|
|
|
{
|
2014-09-30 14:59:59 -04:00
|
|
|
// Iron doors can only be toggled by redstone, not by right-clicking
|
2015-12-01 17:12:44 -05:00
|
|
|
return false;
|
2014-09-30 14:04:49 -04:00
|
|
|
}
|
|
|
|
|
2015-05-09 03:25:09 -04:00
|
|
|
// Flip the ON bit on / off using the XOR bitwise operation
|
2020-04-21 16:19:22 -04:00
|
|
|
NIBBLETYPE Meta = (a_ChunkInterface.GetBlockMeta(a_BlockPos) ^ 0x04);
|
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, Meta);
|
|
|
|
a_WorldInterface.GetBroadcastManager().BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_FENCE_GATE_OPEN, a_BlockPos, 0, a_Player.GetClientHandle());
|
2015-12-01 17:12:44 -05:00
|
|
|
|
|
|
|
return true;
|
2013-11-29 17:27:08 -05:00
|
|
|
}
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnCancelRightClick(
|
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cWorldInterface & a_WorldInterface,
|
|
|
|
cPlayer & a_Player,
|
|
|
|
const Vector3i a_BlockPos,
|
|
|
|
eBlockFace a_BlockFace
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2014-03-05 09:10:20 -05:00
|
|
|
{
|
2014-03-05 13:33:43 -05:00
|
|
|
UNUSED(a_ChunkInterface);
|
2020-04-21 16:19:22 -04:00
|
|
|
a_WorldInterface.SendBlockTo(a_BlockPos, a_Player);
|
2014-03-05 09:10:20 -05:00
|
|
|
}
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-29 17:27:08 -05: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-11-29 17:27:08 -05:00
|
|
|
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
2020-09-21 10:41:31 -04:00
|
|
|
if (a_ClickedBlockFace == BLOCK_FACE_YP)
|
|
|
|
{
|
|
|
|
// Trapdoor is placed on top of a block.
|
|
|
|
// Engage yaw rotation to determine hinge direction:
|
|
|
|
return Super::GetPlacementBlockTypeMeta(a_ChunkInterface, a_Player, a_PlacedBlockPos, a_ClickedBlockFace, a_CursorPos, a_BlockType, a_BlockMeta);
|
|
|
|
}
|
|
|
|
else if (a_ClickedBlockFace == BLOCK_FACE_YM)
|
|
|
|
{
|
|
|
|
// Trapdoor is placed on bottom of a block.
|
|
|
|
// Engage yaw rotation to determine hinge direction:
|
|
|
|
if (!Super::GetPlacementBlockTypeMeta(a_ChunkInterface, a_Player, a_PlacedBlockPos, a_ClickedBlockFace, a_CursorPos, a_BlockType, a_BlockMeta))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle 'Move up half-block' bit on:
|
|
|
|
a_BlockMeta |= 0x8;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Placement on block sides; hinge direction is determined by which side was clicked:
|
2013-11-29 17:27:08 -05:00
|
|
|
a_BlockType = m_BlockType;
|
2020-04-21 16:19:22 -04:00
|
|
|
a_BlockMeta = BlockFaceToMetaData(a_ClickedBlockFace);
|
2013-11-29 17:27:08 -05:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
if (a_CursorPos.y > 7)
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
2020-09-21 10:41:31 -04:00
|
|
|
// Trapdoor is placed on a higher half of a vertical block.
|
|
|
|
// Toggle 'Move up half-block' bit on:
|
2013-11-29 17:27:08 -05:00
|
|
|
a_BlockMeta |= 0x8;
|
|
|
|
}
|
2020-09-21 10:41:31 -04:00
|
|
|
|
2013-11-29 17:27:08 -05:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-02 06:51:43 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
inline static NIBBLETYPE BlockFaceToMetaData(eBlockFace a_BlockFace)
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
|
|
|
switch (a_BlockFace)
|
|
|
|
{
|
|
|
|
case BLOCK_FACE_ZP: return 0x1;
|
|
|
|
case BLOCK_FACE_ZM: return 0x0;
|
|
|
|
case BLOCK_FACE_XP: return 0x3;
|
|
|
|
case BLOCK_FACE_XM: return 0x2;
|
2020-09-21 10:41:31 -04:00
|
|
|
default:
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled block face!");
|
2014-02-04 18:07:22 -05:00
|
|
|
return 0;
|
2013-11-29 17:27:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta)
|
2013-11-29 17:27:08 -05:00
|
|
|
{
|
|
|
|
switch (a_Meta & 0x3)
|
|
|
|
{
|
|
|
|
case 0x0: return BLOCK_FACE_ZM;
|
|
|
|
case 0x1: return BLOCK_FACE_ZP;
|
|
|
|
case 0x2: return BLOCK_FACE_XM;
|
|
|
|
case 0x3: return BLOCK_FACE_XP;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled block meta!");
|
2014-02-08 19:57:22 -05:00
|
|
|
return BLOCK_FACE_NONE;
|
2013-11-29 17:27:08 -05: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_TRAPDOOR: return 13;
|
|
|
|
case E_BLOCK_IRON_TRAPDOOR: return 6;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled blocktype in trapdoor handler!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-29 17:27:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|