Files
cuberite-2a/src/Blocks/BlockRedstoneRepeater.h
T

157 lines
3.3 KiB
C++
Raw Normal View History

2013-07-29 12:13:03 +01:00
#pragma once
#include "BlockHandler.h"
#include "Mixins.h"
2014-09-26 18:13:19 +01:00
#include "ChunkInterface.h"
2014-10-19 15:01:01 +02:00
#include "BlockSlab.h"
#include "../Chunk.h"
2013-07-29 12:13:03 +01:00
class cBlockRedstoneRepeaterHandler final :
public cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>
2013-07-29 12:13:03 +01:00
{
2020-04-13 18:38:06 +02:00
using Super = cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>;
2013-07-29 12:13:03 +01:00
public:
using Super::Super;
inline static Vector3i GetFrontCoordinateOffset(NIBBLETYPE a_Meta)
2013-11-29 22:25:07 +00:00
{
return -GetRearCoordinateOffset(a_Meta);
2013-11-29 22:25:07 +00:00
}
inline static Vector3i GetLeftCoordinateOffset(NIBBLETYPE a_Meta)
{
switch (a_Meta & E_META_REDSTONE_REPEATER_FACING_MASK) // We only want the direction (bottom) bits
{
case E_META_REDSTONE_REPEATER_FACING_ZM: return { -1, 0, 0 };
case E_META_REDSTONE_REPEATER_FACING_XP: return { 0, 0, -1 };
case E_META_REDSTONE_REPEATER_FACING_ZP: return { 1, 0, 0 };
case E_META_REDSTONE_REPEATER_FACING_XM: return { 0, 0, 1 };
2020-04-21 22:19:22 +02:00
default:
{
LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
ASSERT(!"Unknown metadata while determining orientation of repeater!");
return { 0, 0, 0 };
}
}
}
2020-04-21 22:19:22 +02:00
inline static Vector3i GetRearCoordinateOffset(NIBBLETYPE a_Meta)
{
switch (a_Meta & E_META_REDSTONE_REPEATER_FACING_MASK) // We only want the direction (bottom) bits
{
case E_META_REDSTONE_REPEATER_FACING_ZM: return { 0, 0, 1 };
case E_META_REDSTONE_REPEATER_FACING_XP: return { -1, 0, 0 };
case E_META_REDSTONE_REPEATER_FACING_ZP: return { 0, 0, -1 };
case E_META_REDSTONE_REPEATER_FACING_XM: return { 1, 0, 0 };
default:
{
LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
ASSERT(!"Unknown metadata while determining orientation of repeater!");
return { 0, 0, 0 };
}
}
}
2020-04-21 22:19:22 +02:00
private:
2020-04-21 22:19:22 +02:00
virtual bool OnUse(
cChunkInterface & a_ChunkInterface,
cWorldInterface & a_WorldInterface,
cPlayer & a_Player,
const Vector3i a_BlockPos,
eBlockFace a_BlockFace,
const Vector3i a_CursorPos
) const override
2013-11-29 22:25:07 +00:00
{
2020-04-21 22:19:22 +02:00
// Increment the delay setting:
a_ChunkInterface.SetBlockMeta(a_BlockPos, ((a_ChunkInterface.GetBlockMeta(a_BlockPos) + 0x04) & 0x0f));
return true;
2013-11-29 22:25:07 +00:00
}
2013-07-29 12:13:03 +01:00
2020-04-21 22:19:22 +02:00
virtual void OnCancelRightClick(
cChunkInterface & a_ChunkInterface,
cWorldInterface & a_WorldInterface,
cPlayer & a_Player,
const Vector3i a_BlockPos,
eBlockFace a_BlockFace
) const override
{
2014-03-05 19:33:43 +01:00
UNUSED(a_ChunkInterface);
2020-04-21 22:19:22 +02:00
a_WorldInterface.SendBlockTo(a_BlockPos, a_Player);
}
2020-04-21 22:19:22 +02:00
virtual bool IsUseable(void) const override
2013-07-29 12:13:03 +01:00
{
return true;
}
2016-02-05 23:45:45 +02:00
2020-04-21 22:19:22 +02:00
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const override
2013-07-29 12:13:03 +01:00
{
2020-04-21 22:19:22 +02:00
if (a_RelPos.y <= 0)
2014-10-19 15:01:01 +02:00
{
return false;
}
BLOCKTYPE BelowBlock;
NIBBLETYPE BelowBlockMeta;
2020-04-21 22:19:22 +02:00
a_Chunk.GetBlockTypeMeta(a_RelPos.addedY(-1), BelowBlock, BelowBlockMeta);
2014-10-19 15:01:01 +02:00
if (cBlockInfo::FullyOccupiesVoxel(BelowBlock))
{
return true;
}
else if (cBlockSlabHandler::IsAnySlabType(BelowBlock))
{
// Check if the slab is turned up side down
if ((BelowBlockMeta & 0x08) == 0x08)
{
return true;
}
}
return false;
2013-07-29 12:13:03 +01:00
}
2013-09-18 00:01:20 +01:00
2020-04-21 22:19:22 +02:00
2020-09-23 16:06:27 +01:00
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override
2020-03-23 22:07:08 +02:00
{
return cItem(E_ITEM_REDSTONE_REPEATER, 1, 0);
}
2020-04-21 22:19:22 +02:00
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
2015-06-30 15:50:15 +01:00
{
UNUSED(a_Meta);
return 11;
}
2013-07-29 12:13:03 +01:00
} ;