summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-08-03 22:03:48 +0200
committermadmaxoft <github@xoft.cz>2014-08-03 22:04:52 +0200
commit3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3 (patch)
tree1af0928bd5e51e38c459aca0e60c8ae4f1ea21fe /src/WorldStorage
parentDebuggers: Added a Name-from-UUID cMojangAPI test. (diff)
downloadcuberite-3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3.tar
cuberite-3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3.tar.gz
cuberite-3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3.tar.bz2
cuberite-3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3.tar.lz
cuberite-3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3.tar.xz
cuberite-3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3.tar.zst
cuberite-3136fc6246a6e0c3ab19eb3dddb1badc7c427ee3.zip
Diffstat (limited to 'src/WorldStorage')
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp10
-rw-r--r--src/WorldStorage/WSSAnvil.cpp69
-rw-r--r--src/WorldStorage/WSSAnvil.h4
3 files changed, 69 insertions, 14 deletions
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 601cd8833..ecda9b8fd 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -569,10 +569,12 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
}
case cMonster::mtWolf:
{
- m_Writer.AddString("Owner", ((const cWolf *)a_Monster)->GetOwner());
- m_Writer.AddByte("Sitting", (((const cWolf *)a_Monster)->IsSitting() ? 1 : 0));
- m_Writer.AddByte("Angry", (((const cWolf *)a_Monster)->IsAngry() ? 1 : 0));
- m_Writer.AddInt("CollarColor", ((const cWolf *)a_Monster)->GetCollarColor());
+ const cWolf & Wolf = *((cWolf *)a_Monster);
+ m_Writer.AddString("Owner", Wolf.GetOwnerName());
+ m_Writer.AddString("OwnerUUID", Wolf.GetOwnerUUID());
+ m_Writer.AddByte("Sitting", Wolf.IsSitting() ? 1 : 0);
+ m_Writer.AddByte("Angry", Wolf.IsAngry() ? 1 : 0);
+ m_Writer.AddInt("CollarColor", Wolf.GetCollarColor());
break;
}
case cMonster::mtZombie:
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index d3a156ee1..434f1e21f 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -15,6 +15,7 @@
#include "../ItemGrid.h"
#include "../StringCompression.h"
#include "../SetChunkData.h"
+#include "../Root.h"
#include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/ChestEntity.h"
@@ -49,6 +50,8 @@
#include "../Entities/HangingEntity.h"
#include "../Entities/ItemFrame.h"
+#include "../Protocol/MojangAPI.h"
+
@@ -2411,16 +2414,9 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
{
return;
}
- int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
- if (OwnerIdx > 0)
- {
- AString OwnerName = a_NBT.GetString(OwnerIdx);
- if (OwnerName != "")
- {
- Monster->SetOwner(OwnerName);
- Monster->SetIsTame(true);
- }
- }
+
+ LoadWolfOwner(*Monster.get(), a_NBT, a_TagIdx);
+
int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting");
if (SittingIdx > 0)
{
@@ -2492,6 +2488,59 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
+void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ // Load the owner information. OwnerUUID or Owner may be specified, possibly both:
+ AString OwnerUUID, OwnerName;
+ int OwnerUUIDIdx = a_NBT.FindChildByName(a_TagIdx, "OwnerUUID");
+ if (OwnerUUIDIdx > 0)
+ {
+ OwnerUUID = cMojangAPI::MakeUUIDShort(a_NBT.GetString(OwnerUUIDIdx));
+ }
+ int OwnerIdx = a_NBT.FindChildByName(a_TagIdx, "Owner");
+ if (OwnerIdx > 0)
+ {
+ OwnerName = a_NBT.GetString(OwnerIdx);
+ }
+ if (OwnerName.empty() && OwnerUUID.empty())
+ {
+ // There is no owner, bail out:
+ return;
+ }
+
+ // Convert name to UUID, if needed:
+ if (OwnerUUID.empty())
+ {
+ // This wolf has only playername stored (pre-1.7.6), look up the UUID
+ // The lookup is blocking, but we're running in a separate thread, so it's ok
+ OwnerUUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(OwnerName);
+ if (OwnerUUID.empty())
+ {
+ // Not a known player, un-tame the wolf by bailing out
+ return;
+ }
+ }
+
+ // Convert UUID to name, if needed:
+ if (OwnerName.empty())
+ {
+ // The lookup is blocking, but we're running in a separate thread, so it's ok
+ OwnerName = cRoot::Get()->GetMojangAPI().GetPlayerNameFromUUID(OwnerUUID);
+ if (OwnerName.empty())
+ {
+ // Not a known player, un-tame the wolf by bailing out
+ return;
+ }
+ }
+
+ a_Wolf.SetOwner(OwnerName, OwnerUUID);
+ a_Wolf.SetIsTame(true);
+}
+
+
+
+
+
bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx)
{
double Pos[3];
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index f8eeb8247..a41268f4c 100644
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -21,6 +21,7 @@ class cItemGrid;
class cProjectileEntity;
class cHangingEntity;
+class cWolf;
@@ -201,6 +202,9 @@ protected:
void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ /** Loads the wolf's owner information from the NBT into the specified wolf entity. */
+ void LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_TagIdx);
+
/// Loads entity common data from the NBT compound; returns true if successful
bool LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx);