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  if ((!m_OwnerName.empty()) && (a_Type != SKULL_TYPE_PLAYER))
31  {
33  m_OwnerUUID = cUUID{};
34  }
35  m_Type = a_Type;
36 }
37 
38 
39 
40 
41 
43 {
44  m_Rotation = a_Rotation;
45 }
46 
47 
48 
49 
50 
51 void cMobHeadEntity::SetOwner(const cPlayer & a_Owner)
52 {
54  {
55  return;
56  }
57 
58  m_OwnerName = a_Owner.GetName();
59  m_OwnerUUID = a_Owner.GetUUID();
60 
61  const Json::Value & Properties = a_Owner.GetClientHandle()->GetProperties();
62  for (auto & Node : Properties)
63  {
64  if (Node.get("name", "").asString() == "textures")
65  {
66  m_OwnerTexture = Node.get("value", "").asString();
67  m_OwnerTextureSignature = Node.get("signature", "").asString();
68  break;
69  }
70  }
71 }
72 
73 
74 
75 
76 
77 void cMobHeadEntity::SetOwner(const cUUID & a_OwnerUUID, const AString & a_OwnerName, const AString & a_OwnerTexture, const AString & a_OwnerTextureSignature)
78 {
80  {
81  return;
82  }
83 
84  m_OwnerUUID = a_OwnerUUID;
85  m_OwnerName = a_OwnerName;
86  m_OwnerTexture = a_OwnerTexture;
87  m_OwnerTextureSignature = a_OwnerTextureSignature;
88 }
89 
90 
91 
92 
93 
95 {
96  return cItem(E_ITEM_HEAD, 1, static_cast<short>(m_Type));
97 }
98 
99 
100 
101 
102 
104 {
105  Super::CopyFrom(a_Src);
106  auto & src = static_cast<const cMobHeadEntity &>(a_Src);
107  m_OwnerName = src.m_OwnerName;
108  m_OwnerTexture = src.m_OwnerTexture;
109  m_OwnerTextureSignature = src.m_OwnerTextureSignature;
110  m_OwnerUUID = src.m_OwnerUUID;
111  m_Rotation = src.m_Rotation;
112  m_Type = src.m_Type;
113 }
114 
115 
116 
117 
118 
120 {
121  cWorld * World = a_Client.GetPlayer()->GetWorld();
122  a_Client.SendBlockChange(m_Pos, m_BlockType, World->GetBlockMeta(GetPos()));
123  a_Client.SendUpdateBlockEntity(*this);
124 }
125 
126 
127 
128 
129 
131 {
132  UNUSED(a_Player);
133  return false;
134 }
@ E_BLOCK_HEAD
Definition: BlockType.h:159
@ E_ITEM_HEAD
Definition: BlockType.h:443
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eMobHeadRotation
Definition: Defines.h:191
@ SKULL_ROTATION_NORTH
Definition: Defines.h:192
eMobHeadType
Definition: Defines.h:177
@ SKULL_TYPE_PLAYER
Definition: Defines.h:181
@ SKULL_TYPE_SKELETON
Definition: Defines.h:178
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
eMonsterType m_Type
Definition: Monster.cpp:35
std::string AString
Definition: StringUtils.h:11
Utilities to allow casting a cWorld to one of its interfaces without including World....
Definition: OpaqueWorld.h:13
BLOCKTYPE m_BlockType
The blocktype representing this particular instance in the world.
Definition: BlockEntity.h:120
Vector3i GetPos() const
Definition: BlockEntity.h:90
Vector3i m_Pos
Position in absolute block coordinates.
Definition: BlockEntity.h:113
virtual void CopyFrom(const cBlockEntity &a_Src)
Copies all properties of a_Src into this entity, except for its m_World and location.
Definition: BlockEntity.cpp:66
AString m_OwnerTextureSignature
Definition: MobHeadEntity.h:78
void SetRotation(eMobHeadRotation a_Rotation)
Set the rotation of the mob head.
eMobHeadRotation m_Rotation
Definition: MobHeadEntity.h:73
cMobHeadEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Creates a new mob head entity at the specified block coords.
virtual cItems ConvertToPickups() const override
Returns the contents of this block entity that it would drop if broken.
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 bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
void SetOwner(const cPlayer &a_Owner)
Set the player for mob heads with player type.
void SetType(const eMobHeadType &a_SkullType)
Set the type of the mob head.
AString m_OwnerTexture
Definition: MobHeadEntity.h:77
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
eMobHeadType m_Type
Definition: MobHeadEntity.h:72
AString m_OwnerName
Definition: MobHeadEntity.h:75
void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
cPlayer * GetPlayer(void)
Definition: ClientHandle.h:78
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
const Json::Value & GetProperties(void) const
Definition: ClientHandle.h:88
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276
const AString & GetName(void) const
Definition: Player.cpp:1299
const cUUID & GetUUID(void) const
Returns the UUID that has been read from the client, or nil if not available.
Definition: Player.cpp:2431
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
Definition: UUID.h:11
Definition: World.h:53