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/WSSAnvil.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'src/WorldStorage/WSSAnvil.cpp') diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 77d1e46b8..7aa3eb0cd 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -50,10 +50,12 @@ #include "../Entities/ExpOrb.h" #include "../Entities/HangingEntity.h" #include "../Entities/ItemFrame.h" +#include "../Entities/LeashKnot.h" #include "../Entities/Painting.h" #include "../Protocol/MojangAPI.h" #include "Server.h" +#include "BoundingBox.h" @@ -1540,6 +1542,8 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { "minecraft:xp_orb", &cWSSAnvil::LoadExpOrbFromNBT }, { "ItemFrame", &cWSSAnvil::LoadItemFrameFromNBT }, { "minecraft:item_frame", &cWSSAnvil::LoadItemFrameFromNBT }, + { "LeashKnot", &cWSSAnvil::LoadLeashKnotFromNBT }, + { "minecraft:leash_knot", &cWSSAnvil::LoadLeashKnotFromNBT }, { "Arrow", &cWSSAnvil::LoadArrowFromNBT }, { "minecraft:arrow", &cWSSAnvil::LoadArrowFromNBT }, { "SplashPotion", &cWSSAnvil::LoadSplashPotionFromNBT }, @@ -1958,6 +1962,24 @@ void cWSSAnvil::LoadItemFrameFromNBT(cEntityList & a_Entities, const cParsedNBT +void cWSSAnvil::LoadLeashKnotFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + auto LeashKnot = cpp14::make_unique(BLOCK_FACE_NONE, 0.0, 0.0, 0.0); + + if (!LoadEntityBaseFromNBT(*LeashKnot.get(), a_NBT, a_TagIdx)) + { + return; + } + + LoadHangingFromNBT(*LeashKnot.get(), a_NBT, a_TagIdx); + + a_Entities.emplace_back(std::move(LeashKnot)); +} + + + + + void cWSSAnvil::LoadPaintingFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { // Load painting name: @@ -3182,6 +3204,13 @@ bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & a_Monster.SetCustomNameAlwaysVisible(CustomNameVisible); } + // Leashed to a knot + int LeashedIdx = a_NBT.FindChildByName(a_TagIdx, "Leashed"); + if ((LeashedIdx >= 0) && a_NBT.GetByte(LeashedIdx)) + { + LoadLeashToPosition(a_Monster, a_NBT, a_TagIdx); + } + return true; } @@ -3189,6 +3218,54 @@ bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT & +void cWSSAnvil::LoadLeashToPosition(cMonster & a_Monster, const cParsedNBT & a_NBT, int a_TagIdx) +{ + int LeashIdx = a_NBT.FindChildByName(a_TagIdx, "Leash"); + if (LeashIdx < 0) + { + return; + } + + double PosX = 0.0, PosY = 0.0, PosZ = 0.0; + bool KnotPosPresent = true; + int LeashDataLine = a_NBT.FindChildByName(LeashIdx, "X"); + if (LeashDataLine >= 0) + { + PosX = a_NBT.GetDouble(LeashDataLine); + } + else + { + KnotPosPresent = false; + } + LeashDataLine = a_NBT.FindChildByName(LeashIdx, "Y"); + if (LeashDataLine >= 0) + { + PosY = a_NBT.GetDouble(LeashDataLine); + } + else + { + KnotPosPresent = false; + } + LeashDataLine = a_NBT.FindChildByName(LeashIdx, "Z"); + if (LeashDataLine >= 0) + { + PosZ = a_NBT.GetDouble(LeashDataLine); + } + else + { + KnotPosPresent = false; + } + if (KnotPosPresent) + { + // Set leash pos for the mob + a_Monster.SetLeashToPos(new Vector3d(PosX, PosY, PosZ)); + } +} + + + + + bool cWSSAnvil::LoadProjectileBaseFromNBT(cProjectileEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { if (!LoadEntityBaseFromNBT(a_Entity, a_NBT, a_TagIdx)) -- cgit v1.2.3