1
0

Fully implemented leashes (#3798)

This commit is contained in:
Pablo Beltrán
2017-08-21 10:46:41 +02:00
committed by Mattes D
parent f81e6f6b6d
commit b18f6637b6
42 changed files with 1022 additions and 21 deletions

View File

@@ -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<Byte>(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<cTNTEntity *> (a_Entity)); break;
case cEntity::etExpOrb: AddExpOrbEntity (reinterpret_cast<cExpOrb *> (a_Entity)); break;
case cEntity::etItemFrame: AddItemFrameEntity (reinterpret_cast<cItemFrame *> (a_Entity)); break;
case cEntity::etLeashKnot: AddLeashKnotEntity (reinterpret_cast<cLeashKnot *> (a_Entity)); break;
case cEntity::etPainting: AddPaintingEntity (reinterpret_cast<cPainting *> (a_Entity)); break;
case cEntity::etPlayer: return; // Players aren't saved into the world
case cEntity::etFloater: return; // Floaters aren't saved either