Cuberite
A lightweight, fast and extensible game server for Minecraft
HangingEntity.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "Entity.h"
5 
6 
7 
8 
9 
10 // tolua_begin
12  public cEntity
13 {
14  // tolua_end
15 
16  using super = cEntity;
17 
18 public: // tolua_export
19 
21 
22  cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, Vector3d a_Pos);
23 
24  // tolua_begin
25 
28 
30  void SetFacing(eBlockFace a_Facing)
31  {
33  }
34 
35  // tolua_end
36 
38  Byte GetProtocolFacing() const { return m_Facing; }
39 
41  void SetProtocolFacing(Byte a_Facing)
42  {
43  ASSERT(a_Facing <= 3);
44  m_Facing = a_Facing;
45  }
46 
47 protected:
48 
50 
51 
52  virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
53  virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override
54  {
55  UNUSED(a_Dt);
56  UNUSED(a_Chunk);
57  }
58 
59 
61  inline static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace)
62  {
63  // 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
64  switch (a_ProtocolFace)
65  {
66  case 0: return BLOCK_FACE_ZP;
67  case 2: return BLOCK_FACE_ZM;
68  case 1: return BLOCK_FACE_XM;
69  case 3: return BLOCK_FACE_XP;
70  default:
71  {
72  LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_ProtocolFace);
73  ASSERT(!"Tried to convert a bad facing!");
74 
76  }
77  }
78  }
79 
80 
82  inline static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace)
83  {
84  // 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
85  switch (a_BlockFace)
86  {
87  case BLOCK_FACE_ZP: return 0;
88  case BLOCK_FACE_ZM: return 2;
89  case BLOCK_FACE_XM: return 1;
90  case BLOCK_FACE_XP: return 3;
91  case BLOCK_FACE_YP:
92  case BLOCK_FACE_YM:
93  case BLOCK_FACE_NONE:
94  {
95  // Uncomment when entities are initialised with their real data, instead of dummy values:
96  // LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_BlockFace);
97  // ASSERT(!"Tried to convert a bad facing!");
98 
100  }
101  }
102  UNREACHABLE("Unsupported block face");
103  }
104 }; // tolua_export
105 
106 
107 
108 
Byte GetProtocolFacing() const
Returns the direction in which the entity is facing.
Definition: HangingEntity.h:38
static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace)
Converts eBlockFace values to protocol hanging item faces.
Definition: HangingEntity.h:82
virtual void SpawnOn(cClientHandle &a_ClientHandle) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
void SetFacing(eBlockFace a_Facing)
Set the direction in which the entity is facing.
Definition: HangingEntity.h:30
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: HangingEntity.h:53
Definition: Chunk.h:49
static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace)
Converts protocol hanging item facing to eBlockFace values.
Definition: HangingEntity.h:61
void LOGINFO(const char *a_Format, fmt::ArgList a_ArgList)
Definition: Logger.cpp:165
#define ASSERT(x)
Definition: Globals.h:335
eBlockFace GetFacing() const
Returns the direction in which the entity is facing.
Definition: HangingEntity.h:27
#define UNUSED
Definition: Globals.h:152
eEntityType
Definition: Entity.h:77
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
Definition: Entity.h:73
cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, double a_Height)
Definition: Entity.cpp:35
void SetProtocolFacing(Byte a_Facing)
Set the direction in which the entity is facing.
Definition: HangingEntity.h:41
#define CLASS_PROTODEF(classname)
Definition: Entity.h:11
unsigned char Byte
Definition: Globals.h:117
#define UNREACHABLE(x)
Use to mark code that should be impossible to reach.
Definition: Globals.h:344