1
0
cuberite-2a/src/Blocks/BlockComparator.h

156 lines
3.9 KiB
C
Raw Normal View History

#pragma once
#include "BlockHandler.h"
#include "BlockRedstoneRepeater.h"
#include "Mixins.h"
class cBlockComparatorHandler :
public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03, true>>
{
using super = cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03, true>>;
public:
cBlockComparatorHandler(BLOCKTYPE a_BlockType):
super(a_BlockType)
{
}
2016-02-05 21:45:45 +00:00
2017-07-31 20:17:52 +00:00
virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ});
Meta ^= 0x04; // Toggle 3rd (addition / subtraction) bit with XOR
2014-02-01 13:06:32 +00:00
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta);
return true;
}
2017-07-31 20:17:52 +00:00
virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
{
2014-03-05 18:33:43 +00:00
UNUSED(a_ChunkInterface);
2017-07-31 20:17:52 +00:00
a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
}
virtual bool IsUseable(void) override
{
return true;
}
2016-02-05 21:45:45 +00:00
2014-02-01 13:06:32 +00:00
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR));
}
virtual bool GetPlacementBlockTypeMeta(
2017-07-31 20:17:52 +00:00
cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
int a_CursorX, int a_CursorY, int a_CursorZ,
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override
{
a_BlockType = m_BlockType;
2017-07-31 20:17:52 +00:00
a_BlockMeta = cBlockRedstoneRepeaterHandler::RepeaterRotationToMetaData(a_Player.GetYaw());
return true;
}
2015-02-08 16:35:10 +00:00
inline static bool IsInSubtractionMode(NIBBLETYPE a_Meta)
{
return ((a_Meta & 0x4) == 0x4);
}
inline static bool IsOn(NIBBLETYPE a_Meta)
{
return ((a_Meta & 0x8) == 0x8);
}
inline static Vector3i GetSideCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta, bool a_bInverse)
2015-02-08 16:35:10 +00:00
{
if (!a_bInverse)
{
switch (a_Meta)
{
case 0x0: a_Position.x++; break;
case 0x1: a_Position.z--; break;
case 0x2: a_Position.x--; break;
case 0x3: a_Position.z++; break;
2015-02-08 16:35:10 +00:00
default:
{
LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
ASSERT(!"Unknown metadata while determining orientation of comparator!");
break;
}
}
}
else
{
switch (a_Meta)
{
case 0x0: a_Position.x--; break;
case 0x1: a_Position.z++; break;
case 0x2: a_Position.x++; break;
case 0x3: a_Position.z--; break;
2015-02-08 16:35:10 +00:00
default:
{
LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
ASSERT(!"Unknown metadata while determining orientation of comparator!");
break;
}
}
}
return a_Position;
2015-02-08 16:35:10 +00:00
}
inline static Vector3i GetRearCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta)
2015-02-08 16:35:10 +00:00
{
switch (a_Meta)
{
case 0x0: a_Position.z++; break;
case 0x1: a_Position.x--; break;
case 0x2: a_Position.z--; break;
case 0x3: a_Position.x++; break;
2015-02-08 16:35:10 +00:00
default:
{
LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
ASSERT(!"Unknown metadata while determining orientation of comparator!");
break;
}
}
return a_Position;
2015-02-08 16:35:10 +00:00
}
inline static Vector3i GetFrontCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta)
2015-02-08 16:35:10 +00:00
{
switch (a_Meta)
{
case 0x0: a_Position.z--; break;
case 0x1: a_Position.x++; break;
case 0x2: a_Position.z++; break;
case 0x3: a_Position.x--; break;
2015-02-08 16:35:10 +00:00
default:
{
LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
ASSERT(!"Unknown metadata while determining orientation of comparator!");
break;
}
}
return a_Position;
2015-02-08 16:35:10 +00:00
}
2015-06-30 14:50:15 +00:00
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);
return 11;
}
} ;