From 28898f710b191abb610f31085d6ae076511cc89c Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Mar 2014 00:32:49 +0100 Subject: Add ExpOrb saving. --- src/WorldStorage/WSSAnvil.cpp | 96 +++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 26 deletions(-) (limited to 'src/WorldStorage/WSSAnvil.cpp') diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index b52b74932..c180f715f 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -37,6 +37,7 @@ #include "../Entities/Pickup.h" #include "../Entities/ProjectileEntity.h" #include "../Entities/TNTEntity.h" +#include "../Entities/ExpOrb.h" @@ -1092,6 +1093,14 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadPickupFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } + else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0) + { + LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } + else if (strncmp(a_IDTag, "XPOrb", a_IDTagLength) == 0) + { + LoadExpOrbFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + } else if (strncmp(a_IDTag, "Arrow", a_IDTagLength) == 0) { LoadArrowFromNBT(a_Entities, a_NBT, a_EntityTagIdx); @@ -1232,10 +1241,6 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a { LoadPigZombieFromNBT(a_Entities, a_NBT, a_EntityTagIdx); } - else if (strncmp(a_IDTag, "PrimedTnt", a_IDTagLength) == 0) - { - LoadTNTFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - } // TODO: other entities } @@ -1393,6 +1398,9 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } + + // TODO: Add health and age + a_Entities.push_back(Pickup.release()); } @@ -1400,6 +1408,64 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a +void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + std::auto_ptr TNT(new cTNTEntity(0.0, 0.0, 0.0, 0)); + if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx)) + { + return; + } + + // Load Fuse Ticks: + int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse"); + if (FuseTicks > 0) + { + TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks)); + } + + a_Entities.push_back(TNT.release()); +} + + + + + +void cWSSAnvil::LoadExpOrbFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) +{ + std::auto_ptr ExpOrb(new cExpOrb(0.0, 0.0, 0.0, 0)); + if (!LoadEntityBaseFromNBT(*ExpOrb.get(), a_NBT, a_TagIdx)) + { + return; + } + + // Load Health: + int Health = a_NBT.FindChildByName(a_TagIdx, "Health"); + if (Health > 0) + { + ExpOrb->SetHealth((int) (a_NBT.GetShort(Health) & 0xFF)); + } + + // Load Age: + int Age = a_NBT.FindChildByName(a_TagIdx, "Age"); + if (Age > 0) + { + ExpOrb->SetAge(a_NBT.GetShort(Age)); + } + + // Load Reward (Value): + int Reward = a_NBT.FindChildByName(a_TagIdx, "Value"); + if (Reward > 0) + { + ExpOrb->SetReward(a_NBT.GetShort(Reward)); + } + + a_Entities.push_back(ExpOrb.release()); +} + + + + + void cWSSAnvil::LoadArrowFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) { std::auto_ptr Arrow(new cArrowEntity(NULL, 0, 0, 0, Vector3d(0, 0, 0))); @@ -2172,28 +2238,6 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT -void cWSSAnvil::LoadTNTFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx) -{ - std::auto_ptr TNT(new cTNTEntity(0.0, 0.0, 0.0, 0)); - if (!LoadEntityBaseFromNBT(*TNT.get(), a_NBT, a_TagIdx)) - { - return; - } - - // Load Fuse Ticks: - int FuseTicks = a_NBT.FindChildByName(a_TagIdx, "Fuse"); - if (FuseTicks > 0) - { - TNT->SetFuseTicks((int) a_NBT.GetByte(FuseTicks)); - } - - a_Entities.push_back(TNT.release()); -} - - - - - bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_NBT, int a_TagIdx) { double Pos[3]; -- cgit v1.2.3