2014-03-15 02:45:25 +01:00
#pragma once
#include "Entity.h"
// tolua_begin
class cHangingEntity :
public cEntity
{
2019-09-29 14:59:24 +02:00
// tolua_end
2014-03-15 02:45:25 +01:00
2020-04-13 18:38:06 +02:00
using Super = cEntity ;
2014-03-15 02:45:25 +01:00
2019-09-29 14:59:24 +02:00
public : // tolua_export
2014-10-21 22:02:30 +02:00
2014-07-22 15:36:13 -07:00
CLASS_PROTODEF ( cHangingEntity )
2014-03-15 02:45:25 +01:00
2019-09-29 14:59:24 +02:00
cHangingEntity ( eEntityType a_EntityType , eBlockFace a_BlockFace , Vector3d a_Pos );
2016-02-05 23:45:45 +02:00
2014-10-21 22:02:30 +02:00
// tolua_begin
/** Returns the direction in which the entity is facing. */
2015-03-13 22:29:27 +00:00
eBlockFace GetFacing () const { return cHangingEntity :: ProtocolFaceToBlockFace ( m_Facing ); }
2014-10-21 22:02:30 +02:00
/** Set the direction in which the entity is facing. */
2015-04-19 21:34:56 +02:00
void SetFacing ( eBlockFace a_Facing )
{
m_Facing = cHangingEntity :: BlockFaceToProtocolFace ( a_Facing );
}
2014-10-21 22:02:30 +02:00
// tolua_end
2014-03-15 02:45:25 +01:00
2015-03-13 22:29:27 +00:00
/** 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 )
{
2015-04-19 21:34:56 +02:00
ASSERT ( a_Facing <= 3 );
2015-03-13 22:29:27 +00:00
m_Facing = a_Facing ;
}
2015-03-13 23:05:06 +00:00
protected :
2014-03-15 02:45:25 +01:00
2015-06-02 12:51:43 +02:00
Byte m_Facing ;
2014-03-15 02:45:25 +01:00
virtual void SpawnOn ( cClientHandle & a_ClientHandle ) override ;
2015-03-13 23:05:06 +00:00
virtual void Tick ( std :: chrono :: milliseconds a_Dt , cChunk & a_Chunk ) override
{
UNUSED ( a_Dt );
UNUSED ( a_Chunk );
}
2014-03-15 02:45:25 +01:00
2015-06-02 12:51:43 +02:00
2015-03-13 22:29:27 +00:00
/** Converts protocol hanging item facing to eBlockFace values */
inline static eBlockFace ProtocolFaceToBlockFace ( Byte a_ProtocolFace )
{
// 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 )
{
2018-02-04 23:07:12 +00:00
case 0 : return BLOCK_FACE_ZP ;
case 2 : return BLOCK_FACE_ZM ;
case 1 : return BLOCK_FACE_XM ;
case 3 : return BLOCK_FACE_XP ;
2015-03-13 22:29:27 +00:00
default :
{
LOGINFO ( "Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP." , a_ProtocolFace );
ASSERT ( ! "Tried to convert a bad facing!" );
2018-02-04 23:07:12 +00:00
return cHangingEntity :: ProtocolFaceToBlockFace ( 3 );
2015-03-13 22:29:27 +00:00
}
}
}
2015-06-02 12:51:43 +02:00
2015-03-13 22:29:27 +00:00
/** Converts eBlockFace values to protocol hanging item faces */
inline static Byte BlockFaceToProtocolFace ( eBlockFace a_BlockFace )
{
// 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 )
{
2018-02-04 23:07:12 +00:00
case BLOCK_FACE_ZP : return 0 ;
case BLOCK_FACE_ZM : return 2 ;
case BLOCK_FACE_XM : return 1 ;
case BLOCK_FACE_XP : return 3 ;
2015-05-19 19:32:10 +01:00
case BLOCK_FACE_YP :
case BLOCK_FACE_YM :
case BLOCK_FACE_NONE :
2015-03-13 22:29:27 +00:00
{
2015-03-13 23:22:09 +00:00
// Uncomment when entities are initialised with their real data, instead of dummy values:
2015-03-13 23:05:06 +00:00
// LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_BlockFace);
// ASSERT(!"Tried to convert a bad facing!");
2015-03-13 22:29:27 +00:00
2018-02-04 23:07:12 +00:00
return cHangingEntity :: BlockFaceToProtocolFace ( BLOCK_FACE_XP );
2015-03-13 22:29:27 +00:00
}
}
2018-02-04 23:07:12 +00:00
UNREACHABLE ( "Unsupported block face" );
2015-03-13 22:29:27 +00:00
}
2014-03-15 02:45:25 +01:00
}; // tolua_export