From 48f84cc3e9204d8481aab32a3c51da5f29fd4306 Mon Sep 17 00:00:00 2001 From: Julian Laubstein Date: Mon, 24 Aug 2015 23:05:15 +0200 Subject: [PATCH] changed mob age from char to int --- src/Mobs/Monster.h | 6 +- src/Protocol/Protocol18x.cpp | 17 ++--- src/WorldStorage/NBTChunkSerializer.cpp | 20 +++--- src/WorldStorage/WSSAnvil.cpp | 90 ++++++++++++++++++++----- 4 files changed, 92 insertions(+), 41 deletions(-) diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 22280110c..963ac9148 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -117,8 +117,8 @@ public: // tolua_begin bool IsBaby (void) const { return m_Age < 0; } - char GetAge (void) const { return m_Age; } - void SetAge(char a_Age) { m_Age = a_Age; } + int GetAge (void) const { return m_Age; } + void SetAge(int a_Age) { m_Age = a_Age; } // tolua_end @@ -279,7 +279,7 @@ protected: bool m_BurnsInDaylight; double m_RelativeWalkSpeed; - char m_Age; + int m_Age; /** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops */ void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0); diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 428e24f7c..15dd085be 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -3361,9 +3361,8 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEInt32(Appearance); a_Pkt.WriteBEUInt8(0x56); // Int at index 22 a_Pkt.WriteBEInt32(Horse.GetHorseArmour()); - a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Horse.GetAge()); + a_Pkt.WriteBEInt8(Horse.IsBaby() ? -1 : 0); break; } // case mtHorse @@ -3379,7 +3378,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) { auto & Ocelot = reinterpret_cast(a_Mob); a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Ocelot.GetAge()); + a_Pkt.WriteBEInt8(Ocelot.IsBaby() ? -1 : 0); break; } // case mtOcelot @@ -3387,7 +3386,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) { auto & Pig = reinterpret_cast(a_Mob); a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Pig.GetAge()); + a_Pkt.WriteBEInt8(Pig.IsBaby() ? -1 : 0); a_Pkt.WriteBEUInt8(0x10); a_Pkt.WriteBEUInt8(Pig.IsSaddled() ? 1 : 0); break; @@ -3397,7 +3396,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) { auto & Sheep = reinterpret_cast(a_Mob); a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Sheep.GetAge()); + a_Pkt.WriteBEInt8(Sheep.IsBaby() ? -1 : 0); a_Pkt.WriteBEUInt8(0x10); Byte SheepMetadata = 0; @@ -3415,9 +3414,8 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) auto & Rabbit = reinterpret_cast(a_Mob); a_Pkt.WriteBEUInt8(0x12); a_Pkt.WriteBEUInt8(Rabbit.GetRabbitTypeAsNumber()); - a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Rabbit.GetAge()); + a_Pkt.WriteBEInt8(Rabbit.IsBaby() ? -1 : 0); break; } // case mtRabbit @@ -3443,7 +3441,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(0x50); a_Pkt.WriteBEInt32(Villager.GetVilType()); a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Villager.GetAge()); + a_Pkt.WriteBEInt8(Villager.IsBaby() ? -1 : 0); break; } // case mtVillager @@ -3490,9 +3488,8 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Wolf.IsBegging() ? 1 : 0); a_Pkt.WriteBEUInt8(0x14); a_Pkt.WriteBEUInt8(static_cast(Wolf.GetCollarColor())); - a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Wolf.GetAge()); + a_Pkt.WriteBEInt8(Wolf.IsBaby() ? -1 : 0); break; } // case mtWolf diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 607a9c182..855fcea09 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -572,7 +572,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.AddInt ("Style", Horse->GetHorseStyle()); m_Writer.AddInt ("ArmorType", Horse->GetHorseArmour()); m_Writer.AddByte("Saddle", Horse->IsSaddled()? 1 : 0); - m_Writer.AddByte("Age", static_cast(Horse->GetAge())); + m_Writer.AddInt ("Age", Horse->GetAge()); break; } case mtMagmaCube: @@ -585,7 +585,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) const cSheep *Sheep = reinterpret_cast(a_Monster); m_Writer.AddByte("Sheared", Sheep->IsSheared()? 1 : 0); m_Writer.AddByte("Color", static_cast(Sheep->GetFurColor())); - m_Writer.AddByte("Age", static_cast(Sheep->GetAge())); + m_Writer.AddInt ("Age", Sheep->GetAge()); break; } case mtSlime: @@ -602,7 +602,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) { const cVillager *Villager = reinterpret_cast(a_Monster); m_Writer.AddInt("Profession", Villager->GetVilType()); - m_Writer.AddByte("Age", static_cast(Villager->GetAge())); + m_Writer.AddInt("Age", Villager->GetAge()); break; } case mtWither: @@ -624,7 +624,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) m_Writer.AddByte("Sitting", Wolf->IsSitting() ? 1 : 0); m_Writer.AddByte("Angry", Wolf->IsAngry() ? 1 : 0); m_Writer.AddByte("CollarColor", static_cast(Wolf->GetCollarColor())); - m_Writer.AddByte("Age", static_cast(Wolf->GetAge())); + m_Writer.AddInt ("Age", Wolf->GetAge()); break; } case mtZombie: @@ -632,30 +632,30 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) const cZombie *Zombie = reinterpret_cast(a_Monster); m_Writer.AddByte("IsVillager", Zombie->IsVillagerZombie() ? 1 : 0); m_Writer.AddByte("IsConverting", Zombie->IsConverting() ? 1 : 0); - m_Writer.AddByte("Age", static_cast(Zombie->GetAge())); + m_Writer.AddInt ("Age", Zombie->GetAge()); break; } case mtZombiePigman: { - m_Writer.AddByte("Age", static_cast(reinterpret_cast(a_Monster)->GetAge())); + m_Writer.AddInt("Age", reinterpret_cast(a_Monster)->GetAge()); break; } case mtOcelot: { - m_Writer.AddByte("Age", static_cast(reinterpret_cast(a_Monster)->GetAge())); + m_Writer.AddInt("Age", reinterpret_cast(a_Monster)->GetAge()); break; } case mtPig: { - m_Writer.AddByte("Age", static_cast(reinterpret_cast(a_Monster)->GetAge())); + m_Writer.AddInt("Age", reinterpret_cast(a_Monster)->GetAge()); break; } case mtRabbit: { const cRabbit *Rabbit = reinterpret_cast(a_Monster); - m_Writer.AddInt("RabbitType", Rabbit->GetRabbitTypeAsNumber()); + m_Writer.AddInt("RabbitType", Rabbit->GetRabbitTypeAsNumber()); m_Writer.AddInt("MoreCarrotTicks", Rabbit->GetMoreCarrotTicks()); - m_Writer.AddByte("Age", static_cast(Rabbit->GetAge())); + m_Writer.AddInt("Age", Rabbit->GetAge()); break; } case mtInvalidType: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 38ca1cdd9..5138717a7 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -2344,8 +2344,14 @@ void cWSSAnvil::LoadHorseFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release()); @@ -2440,8 +2446,14 @@ void cWSSAnvil::LoadOcelotFromNBT(cEntityList & a_Entities, const cParsedNBT & a int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release()); @@ -2467,8 +2479,14 @@ void cWSSAnvil::LoadPigFromNBT(cEntityList & a_Entities, const cParsedNBT & a_NB int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release()); @@ -2505,8 +2523,14 @@ void cWSSAnvil::LoadRabbitFromNBT(cEntityList & a_Entities, const cParsedNBT & a int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release()); @@ -2545,8 +2569,14 @@ void cWSSAnvil::LoadSheepFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release()); @@ -2717,8 +2747,14 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } @@ -2825,8 +2861,14 @@ void cWSSAnvil::LoadWolfFromNBT(cEntityList & a_Entities, const cParsedNBT & a_N int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release()); @@ -2860,8 +2902,14 @@ void cWSSAnvil::LoadZombieFromNBT(cEntityList & a_Entities, const cParsedNBT & a int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release()); @@ -2887,8 +2935,14 @@ void cWSSAnvil::LoadPigZombieFromNBT(cEntityList & a_Entities, const cParsedNBT int AgeableIdx = a_NBT.FindChildByName(a_TagIdx, "Age"); if (AgeableIdx > 0) { - Byte Age = a_NBT.GetByte(AgeableIdx); - Monster->SetAge(static_cast(Age)); + int Age; + switch (a_NBT.GetType(AgeableIdx)) + { + case TAG_Byte: Age = static_cast(a_NBT.GetByte(AgeableIdx)); break; + case TAG_Int: Age = a_NBT.GetInt (AgeableIdx); break; + default: Age = 0; break; + } + Monster->SetAge(Age); } a_Entities.push_back(Monster.release());