From 6a1984112146a14c96f43e9cdf758f5104d6d2a3 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Wed, 12 Jul 2017 12:42:02 +0200 Subject: Added basic ocelot behavior (#3829) --- src/WorldStorage/NBTChunkSerializer.cpp | 13 +++++++++- src/WorldStorage/WSSAnvil.cpp | 45 +++++++++++++++++++++++++-------- src/WorldStorage/WSSAnvil.h | 6 +++-- 3 files changed, 51 insertions(+), 13 deletions(-) (limited to 'src/WorldStorage') 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(a_Monster)->GetAge()); + const auto *Ocelot = reinterpret_cast(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(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 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(); } // 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(); } } 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(); } } - 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 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); -- cgit v1.2.3