summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockComparator.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-09-20 15:50:52 +0200
committerGitHub <noreply@github.com>2020-09-20 15:50:52 +0200
commit68cced73afe546328cf94ed07c57deee47bfadec (patch)
tree88be88e3fd4a208b9849e526f1877caa44058ab5 /src/Blocks/BlockComparator.h
parentAdded armor and shulker box cleaning (#4875) (diff)
downloadcuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar
cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.gz
cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.bz2
cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.lz
cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.xz
cuberite-68cced73afe546328cf94ed07c57deee47bfadec.tar.zst
cuberite-68cced73afe546328cf94ed07c57deee47bfadec.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockComparator.h189
1 files changed, 84 insertions, 105 deletions
diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h
index ba939b41f..53edaca50 100644
--- a/src/Blocks/BlockComparator.h
+++ b/src/Blocks/BlockComparator.h
@@ -16,14 +16,90 @@ class cBlockComparatorHandler :
public:
- cBlockComparatorHandler(BLOCKTYPE a_BlockType):
- Super(a_BlockType)
+ using Super::Super;
+
+ inline static bool IsInSubtractionMode(NIBBLETYPE a_Meta)
{
+ return ((a_Meta & 0x4) == 0x4);
}
+ inline static Vector3i GetFrontCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta)
+ {
+ 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;
+ default:
+ {
+ LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
+ ASSERT(!"Unknown metadata while determining orientation of comparator!");
+ break;
+ }
+ }
+ return a_Position;
+ }
+ inline static Vector3i GetSideCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta, bool a_bInverse)
+ {
+ 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;
+ 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;
+ default:
+ {
+ LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
+ ASSERT(!"Unknown metadata while determining orientation of comparator!");
+ break;
+ }
+ }
+ }
+ return a_Position;
+ }
+
+ inline static Vector3i GetRearCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta)
+ {
+ 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;
+ default:
+ {
+ LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
+ ASSERT(!"Unknown metadata while determining orientation of comparator!");
+ break;
+ }
+ }
+
+ return a_Position;
+ }
+
+private:
virtual bool OnUse(
cChunkInterface & a_ChunkInterface,
@@ -32,7 +108,7 @@ public:
const Vector3i a_BlockPos,
eBlockFace a_BlockFace,
const Vector3i a_CursorPos
- ) override
+ ) const override
{
const auto Meta = a_ChunkInterface.GetBlockMeta(a_BlockPos);
@@ -54,7 +130,7 @@ public:
cPlayer & a_Player,
const Vector3i a_BlockPos,
eBlockFace a_BlockFace
- ) override
+ ) const override
{
UNUSED(a_ChunkInterface);
UNUSED(a_BlockFace);
@@ -67,7 +143,7 @@ public:
- virtual bool IsUseable(void) override
+ virtual bool IsUseable(void) const override
{
return true;
}
@@ -76,7 +152,7 @@ public:
- virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) override
+ virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const override
{
if (a_RelPos.y <= 0)
{
@@ -106,7 +182,7 @@ public:
- virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
+ virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override
{
return cItem(E_ITEM_COMPARATOR, 1, 0);
}
@@ -115,104 +191,7 @@ public:
- inline static bool IsInSubtractionMode(NIBBLETYPE a_Meta)
- {
- return ((a_Meta & 0x4) == 0x4);
- }
-
-
-
-
-
- inline static Vector3i GetSideCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta, bool a_bInverse)
- {
- 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;
- 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;
- default:
- {
- LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
- ASSERT(!"Unknown metadata while determining orientation of comparator!");
- break;
- }
- }
- }
-
- return a_Position;
- }
-
-
-
-
-
- inline static Vector3i GetRearCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta)
- {
- 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;
- default:
- {
- LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
- ASSERT(!"Unknown metadata while determining orientation of comparator!");
- break;
- }
- }
-
- return a_Position;
- }
-
-
-
-
-
- inline static Vector3i GetFrontCoordinate(Vector3i a_Position, NIBBLETYPE a_Meta)
- {
- 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;
- default:
- {
- LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
- ASSERT(!"Unknown metadata while determining orientation of comparator!");
- break;
- }
- }
-
- return a_Position;
- }
-
-
-
-
-
- virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
+ virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
{
UNUSED(a_Meta);
return 11;