summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2018-02-03 12:24:19 +0100
committerAlexander Harkness <me@bearbin.net>2020-04-10 01:50:45 +0200
commit8438def87e40e43fd66d38dbf8cc287cea7de29b (patch)
tree647b7674cca3df58507e5311e5578d14084bc691 /src/WorldStorage
parentRe-enable darwin download from easyinstall.sh script (diff)
downloadcuberite-8438def87e40e43fd66d38dbf8cc287cea7de29b.tar
cuberite-8438def87e40e43fd66d38dbf8cc287cea7de29b.tar.gz
cuberite-8438def87e40e43fd66d38dbf8cc287cea7de29b.tar.bz2
cuberite-8438def87e40e43fd66d38dbf8cc287cea7de29b.tar.lz
cuberite-8438def87e40e43fd66d38dbf8cc287cea7de29b.tar.xz
cuberite-8438def87e40e43fd66d38dbf8cc287cea7de29b.tar.zst
cuberite-8438def87e40e43fd66d38dbf8cc287cea7de29b.zip
Diffstat (limited to '')
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp19
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.cpp51
-rwxr-xr-xsrc/WorldStorage/WSSAnvil.h1
3 files changed, 60 insertions, 11 deletions
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index 3e8994786..138921264 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -738,10 +738,17 @@ public:
case mtVillager: EntityClass = "Villager"; break;
case mtWitch: EntityClass = "Witch"; break;
case mtWither: EntityClass = "WitherBoss"; break;
+<<<<<<< HEAD
case mtWitherSkeleton: EntityClass = "WitherSkeleton"; break;
case mtWolf: EntityClass = "Wolf"; break;
case mtZombie: EntityClass = "Zombie"; break;
case mtZombiePigman: EntityClass = "PigZombie"; break;
+=======
+ case mtWolf: EntityClass = "Wolf"; break;
+ case mtZombie: EntityClass = "Zombie"; break;
+ case mtZombiePigman: EntityClass = "PigZombie"; break;
+ case mtZombieVillager: EntityClass = "ZombieVillager"; break;
+>>>>>>> Add Zombie Villagers
default:
{
ASSERT(!"Unhandled monster type");
@@ -901,10 +908,7 @@ public:
}
case mtZombie:
{
- const cZombie *Zombie = static_cast<const cZombie *>(a_Monster);
- mWriter.AddByte("IsVillager", Zombie->IsVillagerZombie() ? 1 : 0);
- mWriter.AddByte("IsConverting", Zombie->IsConverting() ? 1 : 0);
- mWriter.AddInt ("Age", Zombie->GetAge());
+ mWriter.AddInt("Age", static_cast<const cZombie *>(a_Monster)->GetAge());
break;
}
case mtZombiePigman:
@@ -912,6 +916,13 @@ public:
mWriter.AddInt("Age", static_cast<const cZombiePigman *>(a_Monster)->GetAge());
break;
}
+ case mtZombieVillager:
+ {
+ const cZombieVillager *ZombieVillager = reinterpret_cast<const cZombieVillager *>(a_Monster);
+ mWriter.AddInt("Profession", ZombieVillager->GetProfession());
+ mWriter.AddInt("ConversionTime", ZombieVillager->ConversionTime());
+ mWriter.AddInt("Age", ZombieVillager->GetAge());
+ }
case mtBlaze:
case mtCaveSpider:
case mtChicken:
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 31934e181..9915e9eb7 100755
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -1568,6 +1568,8 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a
{ "minecraft:zombie", &cWSSAnvil::LoadZombieFromNBT },
{ "PigZombie", &cWSSAnvil::LoadPigZombieFromNBT },
{ "minecraft:zombie_pigman", &cWSSAnvil::LoadPigZombieFromNBT },
+ { "ZombieVillager", &cWSSAnvil::LoadZombieVillagerFromNBT },
+ { "minecraft:zombie_villager", &cWSSAnvil::LoadZombieVillagerFromNBT },
};
auto it = EntityTypeToFunction.find(AString(a_IDTag, a_IDTagLength));
@@ -2968,15 +2970,40 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N
void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
- int IsVillagerIdx = a_NBT.FindChildByName(a_TagIdx, "IsVillager");
- if (IsVillagerIdx < 0)
+ std::unique_ptr<cZombie> Monster = cpp14::make_unique<cZombie>();
+ if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
}
- bool IsVillagerZombie = ((a_NBT.GetByte(IsVillagerIdx) == 1) ? true : false);
+ if (!LoadMonsterBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
+ {
+ return;
+ }
+
+ int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
+ if (AgeableIdx > 0)
+ {
+ int Age;
+ switch (a_NBT.GetType(AgeableIdx))
+ {
+ case TAG_Byte: Age = static_cast<int>(a_NBT.GetByte(AgeableIdx)); break;
+ case TAG_Int: Age = a_NBT.GetInt(AgeableIdx); break;
+ default: Age = 0; break;
+ }
+ Monster->SetAge(Age);
+ }
+
+ a_Entities.emplace_back(std::move(Monster));
+}
+
+
+
- std::unique_ptr<cZombie> Monster = cpp14::make_unique<cZombie>(IsVillagerZombie);
+
+void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
+{
+ std::unique_ptr<cZombiePigman> Monster = cpp14::make_unique<cZombiePigman>();
if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
@@ -3007,9 +3034,17 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a
-void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
+void cWSSAnvil::LoadZombieVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx)
{
- std::unique_ptr<cZombiePigman> Monster = cpp14::make_unique<cZombiePigman>();
+ int ProfessionIdx = a_NBT.FindChildByName(a_TagIdx, "Profession");
+ if (ProfessionIdx < 0)
+ {
+ return;
+ }
+
+ cVillager::eVillagerType Profession = static_cast<cVillager::eVillagerType>(a_NBT.GetInt(ProfessionIdx));
+
+ std::unique_ptr<cZombieVillager> Monster = cpp14::make_unique<cZombieVillager>(Profession);
if (!LoadEntityBaseFromNBT(*Monster.get(), a_NBT, a_TagIdx))
{
return;
@@ -3020,6 +3055,8 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
return;
}
+ // TODO: Conversion time
+
int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age");
if (AgeableIdx > 0)
{
@@ -3028,7 +3065,7 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT
{
case TAG_Byte: Age = static_cast<int>(a_NBT.GetByte(AgeableIdx)); break;
case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break;
- default: Age = 0; break;
+ default: Age = 0; break;
}
Monster->SetAge(Age);
}
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index e6b3e5ee9..caee4ade2 100755
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -232,6 +232,7 @@ protected:
void LoadWolfFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadPigZombieFromNBT (cEntityList & a_Entities, const cParsedNBT & a_NBT, int a_TagIdx);
+ void LoadZombieVillagerFromNBT (cEntityList & a_Entities, 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, name is an empty string and uuid is nil. */