Cuberite
A lightweight, fast and extensible game server for Minecraft
MobHeadEntity.cpp
Go to the documentation of this file.
1 
2 // MobHeadEntity.cpp
3 
4 // Implements the cMobHeadEntity class representing a single skull / head in the world
5 
6 #include "Globals.h"
7 #include "MobHeadEntity.h"
8 #include "json/json.h"
9 #include "../Entities/Player.h"
10 #include "../ClientHandle.h"
11 
12 
13 
14 
15 
16 cMobHeadEntity::cMobHeadEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World):
17  super(a_BlockType, a_BlockMeta, a_Pos, a_World),
19  m_Rotation(SKULL_ROTATION_NORTH)
20 {
21  ASSERT(a_BlockType == E_BLOCK_HEAD);
22 }
23 
24 
25 
26 
27 
29 {
30  super::CopyFrom(a_Src);
31  auto & src = static_cast<const cMobHeadEntity &>(a_Src);
32  m_OwnerName = src.m_OwnerName;
33  m_OwnerTexture = src.m_OwnerTexture;
34  m_OwnerTextureSignature = src.m_OwnerTextureSignature;
35  m_OwnerUUID = src.m_OwnerUUID;
36  m_Rotation = src.m_Rotation;
37  m_Type = src.m_Type;
38 }
39 
40 
41 
42 
43 
45 {
46  UNUSED(a_Player);
47  return true;
48 }
49 
50 
51 
52 
53 
55 {
56  if ((!m_OwnerName.empty()) && (a_Type != SKULL_TYPE_PLAYER))
57  {
59  m_OwnerUUID = cUUID{};
60  }
61  m_Type = a_Type;
63 }
64 
65 
66 
67 
68 
70 {
71  m_Rotation = a_Rotation;
73 }
74 
75 
76 
77 
78 
79 void cMobHeadEntity::SetOwner(const cPlayer & a_Owner)
80 {
82  {
83  return;
84  }
85 
86  m_OwnerName = a_Owner.GetName();
87  m_OwnerUUID = a_Owner.GetUUID();
88 
89  const Json::Value & Properties = a_Owner.GetClientHandle()->GetProperties();
90  for (auto & Node : Properties)
91  {
92  if (Node.get("name", "").asString() == "textures")
93  {
94  m_OwnerTexture = Node.get("value", "").asString();
95  m_OwnerTextureSignature = Node.get("signature", "").asString();
96  break;
97  }
98  }
99 
101 }
102 
103 
104 
105 
106 
107 void cMobHeadEntity::SetOwner(const cUUID & a_OwnerUUID, const AString & a_OwnerName, const AString & a_OwnerTexture, const AString & a_OwnerTextureSignature)
108 {
109  if (m_Type != SKULL_TYPE_PLAYER)
110  {
111  return;
112  }
113 
114  m_OwnerUUID = a_OwnerUUID;
115  m_OwnerName = a_OwnerName;
116  m_OwnerTexture = a_OwnerTexture;
117  m_OwnerTextureSignature = a_OwnerTextureSignature;
119 }
120 
121 
122 
123 
124 
126 {
127  cWorld * World = a_Client.GetPlayer()->GetWorld();
129  a_Client.SendUpdateBlockEntity(*this);
130 }
131 
132 
133 
134 
cMobHeadEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Creates a new mob head entity at the specified block coords.
T x
Definition: Vector3.h:17
void SetOwner(const cPlayer &a_Owner)
Set the player for mob heads with player type.
const Json::Value & GetProperties(void) const
Definition: ClientHandle.h:85
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
eMobHeadType m_Type
Definition: MobHeadEntity.h:79
Definition: Player.h:27
eMobHeadRotation
Definition: Defines.h:182
BLOCKTYPE m_BlockType
The blocktype representing this particular instance in the world.
Definition: BlockEntity.h:149
void SetType(const eMobHeadType &a_SkullType)
Set the type of the mob head.
const AString & GetName(void) const
Definition: Player.h:277
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
void SetRotation(eMobHeadRotation a_Rotation)
Set the rotation of the mob head.
T y
Definition: Vector3.h:17
NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos)
Returns the block meta at the specified position.
Definition: World.h:431
cWorld * m_World
Definition: BlockEntity.h:155
T z
Definition: Vector3.h:17
Definition: UUID.h:10
Utilities to allow casting a cWorld to one of its interfaces without including World.h.
Definition: OpaqueWorld.h:12
virtual void BroadcastBlockEntity(Vector3i a_BlockPos, const cClientHandle *a_Exclude=nullptr) override
If there is a block entity at the specified coods, sends it to all clients except a_Exclude...
Vector3i GetPos() const
Definition: BlockEntity.h:104
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
Definition: World.h:65
cPlayer * GetPlayer(void)
Definition: ClientHandle.h:75
void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
eMobHeadType
Definition: Defines.h:168
#define ASSERT(x)
Definition: Globals.h:335
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
Vector3i m_Pos
Position in absolute block coordinates.
Definition: BlockEntity.h:142
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
virtual void CopyFrom(const cBlockEntity &a_Src)
Copies all properties of a_Src into this entity, except for its m_World and location.
#define UNUSED
Definition: Globals.h:152
std::string AString
Definition: StringUtils.h:13
AString m_OwnerName
Definition: MobHeadEntity.h:82
eMonsterType m_Type
Definition: Monster.cpp:33
const cUUID & GetUUID(void) const
Returns the UUID that has been read from the client, or nil if not available.
Definition: Player.h:521
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
AString m_OwnerTextureSignature
Definition: MobHeadEntity.h:85
AString m_OwnerTexture
Definition: MobHeadEntity.h:84
eMobHeadRotation m_Rotation
Definition: MobHeadEntity.h:80
cWorld * GetWorld(void) const
Definition: Entity.h:201
cClientHandle * GetClientHandle(void) const
Returns the raw client handle associated with the player.
Definition: Player.h:254