summaryrefslogtreecommitdiffstats
path: root/src/Defines.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2022-07-16 13:04:14 +0200
committerGitHub <noreply@github.com>2022-07-16 13:04:14 +0200
commit64a24a4c79ace77ff111f0b555ff1d9d942bf56e (patch)
tree9ab668e5ac829c7b09e7e9f457de2c0b73a8d903 /src/Defines.cpp
parentItemHandler: Fix torch handler not being called (#5433) (diff)
downloadcuberite-64a24a4c79ace77ff111f0b555ff1d9d942bf56e.tar
cuberite-64a24a4c79ace77ff111f0b555ff1d9d942bf56e.tar.gz
cuberite-64a24a4c79ace77ff111f0b555ff1d9d942bf56e.tar.bz2
cuberite-64a24a4c79ace77ff111f0b555ff1d9d942bf56e.tar.lz
cuberite-64a24a4c79ace77ff111f0b555ff1d9d942bf56e.tar.xz
cuberite-64a24a4c79ace77ff111f0b555ff1d9d942bf56e.tar.zst
cuberite-64a24a4c79ace77ff111f0b555ff1d9d942bf56e.zip
Diffstat (limited to 'src/Defines.cpp')
-rw-r--r--src/Defines.cpp60
1 files changed, 26 insertions, 34 deletions
diff --git a/src/Defines.cpp b/src/Defines.cpp
index aa5e46995..e00e9f7e6 100644
--- a/src/Defines.cpp
+++ b/src/Defines.cpp
@@ -377,42 +377,34 @@ eDamageType StringToDamageType(const AString & a_DamageTypeString)
void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse)
{
- if (!a_bInverse)
- {
- switch (a_BlockFace)
- {
- case BLOCK_FACE_YP: a_BlockY++; break;
- case BLOCK_FACE_YM: a_BlockY--; break;
- case BLOCK_FACE_ZM: a_BlockZ--; break;
- case BLOCK_FACE_ZP: a_BlockZ++; break;
- case BLOCK_FACE_XP: a_BlockX++; break;
- case BLOCK_FACE_XM: a_BlockX--; break;
- case BLOCK_FACE_NONE:
- {
- LOGWARNING("%s: Unknown face: %d", __FUNCTION__, a_BlockFace);
- ASSERT(!"AddFaceDirection(): Unknown face");
- break;
- }
- }
- }
- else
+ LOGWARNING("AddFaceDirection with X/Y/Z parameters is deprecated, use the vector version");
+
+ const auto Offset = AddFaceDirection({ a_BlockX, a_BlockY, a_BlockZ }, a_BlockFace, a_bInverse);
+ a_BlockX = Offset.x;
+ a_BlockY = Offset.y;
+ a_BlockZ = Offset.z;
+}
+
+
+
+
+
+Vector3i AddFaceDirection(const Vector3i a_Position, const eBlockFace a_BlockFace, const bool a_InvertDirection)
+{
+ const int Offset = a_InvertDirection ? -1 : 1;
+
+ switch (a_BlockFace)
{
- switch (a_BlockFace)
- {
- case BLOCK_FACE_YP: a_BlockY--; break;
- case BLOCK_FACE_YM: a_BlockY++; break;
- case BLOCK_FACE_ZM: a_BlockZ++; break;
- case BLOCK_FACE_ZP: a_BlockZ--; break;
- case BLOCK_FACE_XP: a_BlockX--; break;
- case BLOCK_FACE_XM: a_BlockX++; break;
- case BLOCK_FACE_NONE:
- {
- LOGWARNING("%s: Unknown inv face: %d", __FUNCTION__, a_BlockFace);
- ASSERT(!"AddFaceDirection(): Unknown face");
- break;
- }
- }
+ case BLOCK_FACE_YP: return a_Position.addedY(+Offset);
+ case BLOCK_FACE_YM: return a_Position.addedY(-Offset);
+ case BLOCK_FACE_ZM: return a_Position.addedZ(-Offset);
+ case BLOCK_FACE_ZP: return a_Position.addedZ(+Offset);
+ case BLOCK_FACE_XP: return a_Position.addedX(+Offset);
+ case BLOCK_FACE_XM: return a_Position.addedX(-Offset);
+ case BLOCK_FACE_NONE: break;
}
+
+ UNREACHABLE("Unsupported block face");
}