From b18f6637b6c58db20353cd3e77584b646ab36b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Beltr=C3=A1n?= Date: Mon, 21 Aug 2017 10:46:41 +0200 Subject: Fully implemented leashes (#3798) --- src/WorldStorage/NBTChunkSerializer.cpp | 38 +++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/WorldStorage/NBTChunkSerializer.cpp') diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 480558fa3..62f981eb4 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -37,6 +37,7 @@ #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" #include "../Entities/ItemFrame.h" +#include "../Entities/LeashKnot.h" #include "../Entities/Painting.h" #include "../Mobs/IncludeAllMonsters.h" @@ -574,6 +575,33 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.AddByte("CanPickUpLoot", (a_Monster->CanPickUpLoot())? 1 : 0); m_Writer.AddString("CustomName", a_Monster->GetCustomName()); m_Writer.AddByte("CustomNameVisible", static_cast(a_Monster->IsCustomNameAlwaysVisible())); + + // Mob was leashed + if (a_Monster->IsLeashed() || (a_Monster->GetLeashToPos() != nullptr)) + { + m_Writer.AddByte("Leashed", 1); + + const Vector3d * LeashedToPos = nullptr; + + if (a_Monster->GetLeashToPos() != nullptr) + { + LeashedToPos = a_Monster->GetLeashToPos(); + } + else if (a_Monster->GetLeashedTo()->IsLeashKnot()) + { + LeashedToPos = & a_Monster->GetLeashedTo()->GetPosition(); + } + + if (LeashedToPos != nullptr) + { + m_Writer.BeginCompound("Leash"); + m_Writer.AddDouble("X", LeashedToPos->x); + m_Writer.AddDouble("Y", LeashedToPos->y); + m_Writer.AddDouble("Z", LeashedToPos->z); + m_Writer.EndCompound(); + } + } + switch (a_Monster->GetMobType()) { case mtBat: @@ -850,8 +878,13 @@ void cNBTChunkSerializer::AddItemFrameEntity(cItemFrame * a_ItemFrame) m_Writer.EndCompound(); } - - +void cNBTChunkSerializer::AddLeashKnotEntity(cLeashKnot * a_LeashKnot) +{ + m_Writer.BeginCompound(""); + AddBasicEntity(a_LeashKnot, "LeashKnot"); + AddHangingEntity(a_LeashKnot); + m_Writer.EndCompound(); +} void cNBTChunkSerializer::AddPaintingEntity(cPainting * a_Painting) @@ -965,6 +998,7 @@ void cNBTChunkSerializer::Entity(cEntity * a_Entity) case cEntity::etTNT: AddTNTEntity (reinterpret_cast (a_Entity)); break; case cEntity::etExpOrb: AddExpOrbEntity (reinterpret_cast (a_Entity)); break; case cEntity::etItemFrame: AddItemFrameEntity (reinterpret_cast (a_Entity)); break; + case cEntity::etLeashKnot: AddLeashKnotEntity (reinterpret_cast (a_Entity)); break; case cEntity::etPainting: AddPaintingEntity (reinterpret_cast (a_Entity)); break; case cEntity::etPlayer: return; // Players aren't saved into the world case cEntity::etFloater: return; // Floaters aren't saved either -- cgit v1.2.3