1
0

Adding new monster types to enum and saving/loading for easier future implementation (#4941)

* added new monster types to enum
added string <-> enum conversion in namespace serializer
added loading functions
added to saving

* renamed zombie pigman to zombified piglins in enum

Co-authored-by: 12xx12 <12xx12100@gmail.com>
Co-authored-by: Tiger Wang <ziwei.tiger@outlook.com>
This commit is contained in:
12xx12
2020-11-23 00:41:13 +01:00
committed by GitHub
parent a0afd13233
commit e35519ec8a
18 changed files with 1716 additions and 462 deletions

View File

@@ -1388,9 +1388,17 @@ void cProtocol_1_8_0::SendSpawnMob(const cMonster & a_Mob)
{
ASSERT(m_State == 3); // In game mode?
const auto MobType = GetProtocolMobType(a_Mob.GetMobType());
// If the type is not valid in this protocol bail out:
if (MobType == 0)
{
return;
}
cPacketizer Pkt(*this, pktSpawnMob);
Pkt.WriteVarInt32(a_Mob.GetUniqueID());
Pkt.WriteBEUInt8(static_cast<Byte>(GetProtocolMobType(a_Mob.GetMobType())));
Pkt.WriteBEUInt8(static_cast<Byte>(MobType));
Vector3d LastSentPos = a_Mob.GetLastSentPosition();
Pkt.WriteFPInt(LastSentPos.x);
Pkt.WriteFPInt(LastSentPos.y);
@@ -1876,7 +1884,7 @@ int cProtocol_1_8_0::GetParticleID(const AString & a_ParticleName)
UInt32 cProtocol_1_8_0::GetProtocolMobType(eMonsterType a_MobType)
UInt32 cProtocol_1_8_0::GetProtocolMobType(const eMonsterType a_MobType)
{
switch (a_MobType)
{
@@ -1890,6 +1898,7 @@ UInt32 cProtocol_1_8_0::GetProtocolMobType(eMonsterType a_MobType)
case mtCreeper: return 50;
case mtEnderDragon: return 63;
case mtEnderman: return 58;
case mtEndermite: return 67;
case mtGhast: return 56;
case mtGiant: return 53;
case mtGuardian: return 68;
@@ -1915,8 +1924,18 @@ UInt32 cProtocol_1_8_0::GetProtocolMobType(eMonsterType a_MobType)
case mtZombie: return 54;
case mtZombiePigman: return 57;
case mtZombieVillager: return 27;
// Mobs that get replaced with another because they were added later
case mtCat: return GetProtocolMobType(mtOcelot);
case mtDonkey: return GetProtocolMobType(mtHorse);
case mtMule: return GetProtocolMobType(mtHorse);
case mtSkeletonHorse: return GetProtocolMobType(mtHorse);
case mtZombieHorse: return GetProtocolMobType(mtHorse);
case mtStray: return GetProtocolMobType(mtSkeleton);
case mtHusk: return GetProtocolMobType(mtZombie);
default: return 0;
}
UNREACHABLE("Unsupported mob type");
}
@@ -3792,6 +3811,14 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M
break;
} // case mtSlime
case mtSkeleton:
case mtStray:
{
a_Pkt.WriteBEUInt8(0x0d);
a_Pkt.WriteBEUInt8(0); // Is normal skeleton
break;
}
case mtVillager:
{
auto & Villager = static_cast<const cVillager &>(a_Mob);
@@ -3857,6 +3884,7 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M
break;
} // case mtWolf
case mtHusk:
case mtZombie:
{
auto & Zombie = static_cast<const cZombie &>(a_Mob);
@@ -3889,7 +3917,46 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M
break;
} // case mtZombieVillager
default: break;
case mtBlaze:
case mtElderGuardian:
case mtGuardian:
{
// TODO: Mobs with extra fields that aren't implemented
break;
}
case mtCat:
case mtEndermite:
case mtDonkey:
case mtMule:
case mtSkeletonHorse:
case mtZombieHorse:
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
UNREACHABLE("cProtocol_1_8::WriteMobMetadata: received unimplemented type");
break;
}
case mtCaveSpider:
case mtEnderDragon:
case mtGiant:
case mtIronGolem:
case mtMooshroom:
case mtSilverfish:
case mtSnowGolem:
case mtSpider:
case mtSquid:
{
// Allowed mobs without additional metadata
break;
}
case mtInvalidType:
{
break;
}
default: UNREACHABLE("cProtocol_1_8::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}