summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2017-07-12 12:42:02 +0200
committerLukas Pioch <lukas@zgow.de>2017-07-12 12:42:02 +0200
commit6a1984112146a14c96f43e9cdf758f5104d6d2a3 (patch)
tree373b218beaad1ddfe76e29eb1a6370c6bc0e4624 /src/WorldStorage
parentLua plugin cColor (#3833) (diff)
downloadcuberite-6a1984112146a14c96f43e9cdf758f5104d6d2a3.tar
cuberite-6a1984112146a14c96f43e9cdf758f5104d6d2a3.tar.gz
cuberite-6a1984112146a14c96f43e9cdf758f5104d6d2a3.tar.bz2
cuberite-6a1984112146a14c96f43e9cdf758f5104d6d2a3.tar.lz
cuberite-6a1984112146a14c96f43e9cdf758f5104d6d2a3.tar.xz
cuberite-6a1984112146a14c96f43e9cdf758f5104d6d2a3.tar.zst
cuberite-6a1984112146a14c96f43e9cdf758f5104d6d2a3.zip
Diffstat (limited to 'src/WorldStorage')
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp13
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.cpp45
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.h6
3 files changed, 51 insertions, 13 deletions
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index d61e61879..ecc7a550a 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -670,7 +670,18 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
}
case mtOcelot:
{
- m_Writer.AddInt("Age", reinterpret_cast<const cOcelot *>(a_Monster)->GetAge());
+ const auto *Ocelot = reinterpret_cast<const cOcelot *>(a_Monster);
+ if (!Ocelot->GetOwnerName().empty())
+ {
+ m_Writer.AddString("Owner", Ocelot->GetOwnerName());
+ }
+ if (!Ocelot->GetOwnerUUID().empty())
+ {
+ m_Writer.AddString("OwnerUUID", Ocelot->GetOwnerUUID());
+ }
+ m_Writer.AddByte("Sitting", Ocelot->IsSitting() ? 1 : 0);
+ m_Writer.AddInt ("CatType", Ocelot->GetOcelotType());
+ m_Writer.AddInt ("Age", Ocelot->GetAge());
break;
}
case mtPig:
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 8b8a0482e..3715548e7 100755
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -2496,6 +2496,27 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a
return;
}
+ auto OwnerInfo = LoadEntityOwner(a_NBT, a_TagIdx);
+ if (!OwnerInfo.first.empty() && !OwnerInfo.second.empty())
+ {
+ Monster->SetOwner(OwnerInfo.first, OwnerInfo.second);
+ Monster->SetIsTame(true);
+ }
+
+ int TypeIdx = a_NBT.FindChildByName(a_TagIdx, "CatType");
+ if (TypeIdx > 0)
+ {
+ int Type = a_NBT.GetInt(TypeIdx);
+ Monster->SetCatType(static_cast<cOcelot::eCatType>(Type));
+ }
+
+ int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting");
+ if ((SittingIdx > 0) && (a_NBT.GetType(SittingIdx) == TAG_Byte))
+ {
+ bool Sitting = ((a_NBT.GetByte(SittingIdx) == 1) ? true : false);
+ Monster->SetIsSitting(Sitting);
+ }
+
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
if (AgeableIdx > 0)
{
@@ -2876,7 +2897,12 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
return;
}
- LoadWolfOwner(*Monster.get(), a_NBT, a_TagIdx);
+ auto OwnerInfo = LoadEntityOwner(a_NBT, a_TagIdx);
+ if (!OwnerInfo.first.empty() && !OwnerInfo.second.empty())
+ {
+ Monster->SetOwner(OwnerInfo.first, OwnerInfo.second);
+ Monster->SetIsTame(true);
+ }
int SittingIdx = a_NBT.FindChildByName(a_TagIdx, "Sitting");
if ((SittingIdx > 0) && (a_NBT.GetType(SittingIdx) == TAG_Byte))
@@ -3009,7 +3035,7 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
-void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_TagIdx)
+std::pair<AString, AString> cWSSAnvil::LoadEntityOwner(const cParsedNBT & a_NBT, int a_TagIdx)
{
// Load the owner information. OwnerUUID or Owner may be specified, possibly both:
AString OwnerUUID, OwnerName;
@@ -3026,19 +3052,19 @@ void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_Ta
if (OwnerName.empty() && OwnerUUID.empty())
{
// There is no owner, bail out:
- return;
+ return std::pair<AString, AString>();
}
// Convert name to UUID, if needed:
if (OwnerUUID.empty())
{
- // This wolf has only playername stored (pre-1.7.6), look up the UUID
+ // This entity 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;
+ // Not a known player, un-tame the entity by bailing out
+ return std::pair<AString, AString>();
}
}
else
@@ -3054,13 +3080,12 @@ void cWSSAnvil::LoadWolfOwner(cWolf & a_Wolf, const cParsedNBT & a_NBT, int a_Ta
OwnerName = cRoot::Get()->GetMojangAPI().GetPlayerNameFromUUID(OwnerUUID);
if (OwnerName.empty())
{
- // Not a known player, un-tame the wolf by bailing out
- return;
+ // Not a known player, un-tame the entity by bailing out
+ return std::pair<AString, AString>();
}
}
- a_Wolf.SetOwner(OwnerName, OwnerUUID);
- a_Wolf.SetIsTame(true);
+ return std::make_pair(OwnerName, OwnerUUID);
}
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index 12acbbcff..4d37aa244 100755
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -22,6 +22,7 @@ class cItemGrid;
class cProjectileEntity;
class cHangingEntity;
class cWolf;
+class cOcelot;
@@ -230,8 +231,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 the owner name and UUID from the entity at the specified NBT tag.
+ Returns a pair of {name, uuid}. If the entity is not owned, both are empty strings. */
+ std::pair<AString, AString> LoadEntityOwner(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);