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 }
cClientHandle
Definition: ClientHandle.h:49
cUUID
Definition: UUID.h:10
cPlayer::GetUUID
const cUUID & GetUUID(void) const
Returns the UUID that has been read from the client, or nil if not available.
Definition: Player.cpp:2431
eMobHeadType
eMobHeadType
Definition: Defines.h:176
cMobHeadEntity::CopyFrom
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
Definition: MobHeadEntity.cpp:103
cMobHeadEntity::SendTo
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
Definition: MobHeadEntity.cpp:119
SKULL_ROTATION_NORTH
@ SKULL_ROTATION_NORTH
Definition: Defines.h:192
cEntity::GetWorld
cWorld * GetWorld(void) const
Definition: Entity.h:190
cMobHeadEntity::m_Rotation
eMobHeadRotation m_Rotation
Definition: MobHeadEntity.h:73
E_ITEM_HEAD
@ E_ITEM_HEAD
Definition: BlockType.h:443
World
Utilities to allow casting a cWorld to one of its interfaces without including World....
Definition: OpaqueWorld.h:12
cMobHeadEntity::m_OwnerName
AString m_OwnerName
Definition: MobHeadEntity.h:75
cMobHeadEntity::m_OwnerTexture
AString m_OwnerTexture
Definition: MobHeadEntity.h:77
Globals.h
cMobHeadEntity::UsedBy
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
Definition: MobHeadEntity.cpp:130
ASSERT
#define ASSERT(x)
Definition: Globals.h:273
cMobHeadEntity::m_OwnerUUID
cUUID m_OwnerUUID
Definition: MobHeadEntity.h:76
NIBBLETYPE
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
eMobHeadRotation
eMobHeadRotation
Definition: Defines.h:190
cClientHandle::GetPlayer
cPlayer * GetPlayer(void)
Definition: ClientHandle.h:78
cMobHeadEntity
Definition: MobHeadEntity.h:21
cWorld
Definition: World.h:47
SKULL_TYPE_PLAYER
@ SKULL_TYPE_PLAYER
Definition: Defines.h:181
cMobHeadEntity::m_Type
eMobHeadType m_Type
Definition: MobHeadEntity.h:72
cItem
Definition: Item.h:36
cMobHeadEntity::m_OwnerTextureSignature
AString m_OwnerTextureSignature
Definition: MobHeadEntity.h:78
cBlockEntity::m_BlockType
BLOCKTYPE m_BlockType
The blocktype representing this particular instance in the world.
Definition: BlockEntity.h:120
cMobHeadEntity::cMobHeadEntity
cMobHeadEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Creates a new mob head entity at the specified block coords.
Definition: MobHeadEntity.cpp:16
cMobHeadEntity::ConvertToPickups
virtual cItems ConvertToPickups() const override
Returns the contents of this block entity that it would drop if broken.
Definition: MobHeadEntity.cpp:94
cItems
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:213
SKULL_TYPE_SKELETON
@ SKULL_TYPE_SKELETON
Definition: Defines.h:178
BLOCKTYPE
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
cMobHeadEntity::SetType
void SetType(const eMobHeadType &a_SkullType)
Set the type of the mob head.
Definition: MobHeadEntity.cpp:28
E_BLOCK_HEAD
@ E_BLOCK_HEAD
Definition: BlockType.h:159
cPlayer::GetClientHandle
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276
m_Type
eMonsterType m_Type
Definition: Monster.cpp:35
cPlayer
Definition: Player.h:27
cBlockEntity::m_Pos
Vector3i m_Pos
Position in absolute block coordinates.
Definition: BlockEntity.h:113
UNUSED
#define UNUSED
Definition: Globals.h:72
cClientHandle::SendBlockChange
void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ClientHandle.cpp:2281
cBlockEntity::CopyFrom
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
cClientHandle::SendUpdateBlockEntity
void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity)
Definition: ClientHandle.cpp:3170
cClientHandle::GetProperties
const Json::Value & GetProperties(void) const
Definition: ClientHandle.h:88
AString
std::string AString
Definition: StringUtils.h:11
cPlayer::GetName
const AString & GetName(void) const
Definition: Player.cpp:1299
Vector3< int >
MobHeadEntity.h
cMobHeadEntity::SetRotation
void SetRotation(eMobHeadRotation a_Rotation)
Set the rotation of the mob head.
Definition: MobHeadEntity.cpp:42
cMobHeadEntity::SetOwner
void SetOwner(const cPlayer &a_Owner)
Set the player for mob heads with player type.
Definition: MobHeadEntity.cpp:51
cBlockEntity
Definition: BlockEntity.h:24
cBlockEntity::GetPos
Vector3i GetPos() const
Definition: BlockEntity.h:90