summaryrefslogtreecommitdiffstats
path: root/src/Defines.cpp
diff options
context:
space:
mode:
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");
}