summaryrefslogtreecommitdiffstats
path: root/src/Entities/HangingEntity.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2015-03-13 23:29:27 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2015-03-13 23:29:27 +0100
commite15e30a030c6013d3ae631188ad8a790c627e9aa (patch)
treef496fad34db9572e03fd3a8ea655d812b013610d /src/Entities/HangingEntity.h
parentMerge pull request #1809 from flx5/master (diff)
downloadcuberite-e15e30a030c6013d3ae631188ad8a790c627e9aa.tar
cuberite-e15e30a030c6013d3ae631188ad8a790c627e9aa.tar.gz
cuberite-e15e30a030c6013d3ae631188ad8a790c627e9aa.tar.bz2
cuberite-e15e30a030c6013d3ae631188ad8a790c627e9aa.tar.lz
cuberite-e15e30a030c6013d3ae631188ad8a790c627e9aa.tar.xz
cuberite-e15e30a030c6013d3ae631188ad8a790c627e9aa.tar.zst
cuberite-e15e30a030c6013d3ae631188ad8a790c627e9aa.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/HangingEntity.h75
1 files changed, 62 insertions, 13 deletions
diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h
index d1ef79a68..de93a73fe 100644
--- a/src/Entities/HangingEntity.h
+++ b/src/Entities/HangingEntity.h
@@ -24,28 +24,77 @@ public:
// tolua_begin
/** Returns the direction in which the entity is facing. */
- eBlockFace GetFacing() const { return m_Facing; }
-
+ eBlockFace GetFacing() const { return cHangingEntity::ProtocolFaceToBlockFace(m_Facing); }
+
/** Set the direction in which the entity is facing. */
- void SetFacing(eBlockFace a_Facing);
-
- /** Returns the X coord of the block in which the entity resides. */
- int GetBlockX() const { return POSX_TOINT; }
-
- /** Returns the Y coord of the block in which the entity resides. */
- int GetBlockY() const { return POSY_TOINT; }
-
- /** Returns the Z coord of the block in which the entity resides. */
- int GetBlockZ() const { return POSZ_TOINT; }
+ void SetFacing(eBlockFace a_Facing) { m_Facing = cHangingEntity::BlockFaceToProtocolFace(a_Facing); }
// tolua_end
+ /** Returns the direction in which the entity is facing. */
+ Byte GetProtocolFacing() const { return m_Facing; }
+
+ /** Set the direction in which the entity is facing. */
+ void SetProtocolFacing(Byte a_Facing)
+ {
+ ASSERT((a_Facing <= 3) && (a_Facing >= 0));
+ m_Facing = a_Facing;
+ }
+
private:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override {}
- eBlockFace m_Facing;
+ /** Converts protocol hanging item facing to eBlockFace values */
+ inline static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace)
+ {
+ eBlockFace Dir;
+
+ // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
+ switch (a_ProtocolFace)
+ {
+ case 0: Dir = BLOCK_FACE_ZP; break;
+ case 2: Dir = BLOCK_FACE_ZM; break;
+ case 1: Dir = BLOCK_FACE_XM; break;
+ case 3: Dir = BLOCK_FACE_XP; break;
+ default:
+ {
+ LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_ProtocolFace);
+ ASSERT(!"Tried to convert a bad facing!");
+
+ Dir = cHangingEntity::ProtocolFaceToBlockFace(3);
+ }
+ }
+
+ return Dir;
+ }
+
+ /** Converts eBlockFace values to protocol hanging item faces */
+ inline static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace)
+ {
+ Byte Dir;
+
+ // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
+ switch (a_BlockFace)
+ {
+ case BLOCK_FACE_ZP: Dir = 0; break;
+ case BLOCK_FACE_ZM: Dir = 2; break;
+ case BLOCK_FACE_XM: Dir = 1; break;
+ case BLOCK_FACE_XP: Dir = 3; break;
+ default:
+ {
+ LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_BlockFace);
+ // Uncomment when entities are initialised with their real data, instead of dummy values: ASSERT(!"Tried to convert a bad facing!");
+
+ Dir = cHangingEntity::BlockFaceToProtocolFace(BLOCK_FACE_XP);
+ }
+ }
+
+ return Dir;
+ }
+
+ Byte m_Facing;
}; // tolua_export