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 
26 
28  Byte GetProtocolFacing() const { return m_Facing; }
29 
31  static bool IsValidSupportBlock(BLOCKTYPE a_BlockType); // tolua_export
32 
34  void SetFacing(eBlockFace a_Facing) { m_Facing = cHangingEntity::BlockFaceToProtocolFace(a_Facing); } // tolua_export
35 
37  void SetProtocolFacing(Byte a_Facing)
38  {
39  ASSERT(a_Facing <= 3);
40  m_Facing = a_Facing;
41  }
42 
43 protected:
44 
46 
47  virtual void KilledBy(TakeDamageInfo & a_TDI) override;
48  virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
49  virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
50 
52  inline static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace)
53  {
54  // 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
55  switch (a_ProtocolFace)
56  {
57  case 0: return BLOCK_FACE_ZP;
58  case 2: return BLOCK_FACE_ZM;
59  case 1: return BLOCK_FACE_XM;
60  case 3: return BLOCK_FACE_XP;
61  default:
62  {
63  LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_ProtocolFace);
64  ASSERT(!"Tried to convert a bad facing!");
65 
67  }
68  }
69  }
70 
71 
73  inline static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace)
74  {
75  // 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
76  switch (a_BlockFace)
77  {
78  case BLOCK_FACE_ZP: return 0;
79  case BLOCK_FACE_ZM: return 2;
80  case BLOCK_FACE_XM: return 1;
81  case BLOCK_FACE_XP: return 3;
82  case BLOCK_FACE_YP:
83  case BLOCK_FACE_YM:
84  case BLOCK_FACE_NONE:
85  {
86  // Uncomment when entities are initialised with their real data, instead of dummy values:
87  // LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_BlockFace);
88  // ASSERT(!"Tried to convert a bad facing!");
89 
91  }
92  }
93  UNREACHABLE("Unsupported block face");
94  }
95 }; // tolua_export
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
@ BLOCK_FACE_XP
Definition: Defines.h:41
@ BLOCK_FACE_YP
Definition: Defines.h:43
@ BLOCK_FACE_YM
Definition: Defines.h:42
@ BLOCK_FACE_ZM
Definition: Defines.h:44
@ BLOCK_FACE_ZP
Definition: Defines.h:45
@ BLOCK_FACE_XM
Definition: Defines.h:40
@ BLOCK_FACE_NONE
Definition: Defines.h:39
#define CLASS_PROTODEF(classname)
Definition: Entity.h:13
#define UNREACHABLE(x)
Definition: Globals.h:288
#define ASSERT(x)
Definition: Globals.h:276
unsigned char Byte
Definition: Globals.h:161
void LOGINFO(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:61
Definition: Chunk.h:36
Definition: Entity.h:76
cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height)
Definition: Entity.cpp:37
eEntityType
Definition: Entity.h:89
static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace)
Converts protocol hanging item facing to eBlockFace values.
Definition: HangingEntity.h:52
void SetFacing(eBlockFace a_Facing)
Set the direction in which the entity is facing.
Definition: HangingEntity.h:34
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
Byte GetProtocolFacing() const
Returns the direction in which the entity is facing.
Definition: HangingEntity.h:28
void SetProtocolFacing(Byte a_Facing)
Set the direction in which the entity is facing.
Definition: HangingEntity.h:37
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...
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
static bool IsValidSupportBlock(BLOCKTYPE a_BlockType)
Returns if the given block can support hanging entity placements.
cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, Vector3d a_Pos)
static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace)
Converts eBlockFace values to protocol hanging item faces.
Definition: HangingEntity.h:73
eBlockFace GetFacing() const
Returns the direction in which the entity is facing.
Definition: HangingEntity.h:25