From 307e7aaff5c454b703db4d536c40d5715d96032b Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Thu, 14 Sep 2017 09:48:57 +0100 Subject: Fix switch warnings (#4013) * Fix switch warnings * Fix a variety of -Wswitch and -Wswitch-enum warnings * Remove unneeded -Wno-error flags * Reorganise some eMonsterType switches * Alpha sort eMonsterType cases in WriteMobMetadata and in cNBTChunkSerializer::AddMonsterEntity * List all mob types in protocol 1.12 and NBTChunkSerializer * cStructGenTrees::GetNumTrees: remove switch default * cWSSAnvil::LoadOldMinecartFromNBT: Log unhandled minecart type --- src/Protocol/CMakeLists.txt | 8 ---- src/Protocol/Protocol_1_10.cpp | 68 +++++++++++++++-------------- src/Protocol/Protocol_1_11.cpp | 68 +++++++++++++++-------------- src/Protocol/Protocol_1_12.cpp | 98 ++++++++++++++++++++++++++++-------------- src/Protocol/Protocol_1_8.cpp | 34 ++++++++------- src/Protocol/Protocol_1_9.cpp | 69 +++++++++++++++-------------- 6 files changed, 189 insertions(+), 156 deletions(-) (limited to 'src/Protocol') diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index f4f266963..ff1a98e6b 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -32,14 +32,6 @@ SET (HDRS ProtocolRecognizer.h ) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set_source_files_properties(Protocol_1_9.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch") - set_source_files_properties(Protocol_1_8.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch") - set_source_files_properties(Protocol_1_10.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch") - set_source_files_properties(Protocol_1_11.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch") - set_source_files_properties(Protocol_1_12.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch") -endif() - if (NOT MSVC) add_library(Protocol ${SRCS} ${HDRS}) endif() diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index bb29c58ce..a16ad3143 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -707,6 +707,26 @@ void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtBat + case mtChicken: + { + auto & Chicken = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Chicken.IsBaby()); + break; + } // case mtChicken + + case mtCow: + { + auto & Cow = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Cow.IsBaby()); + break; + } // case mtCow + case mtCreeper: { auto & Creeper = reinterpret_cast(a_Mob); @@ -821,26 +841,6 @@ void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtOcelot - case mtCow: - { - auto & Cow = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Cow.IsBaby()); - break; - } // case mtCow - - case mtChicken: - { - auto & Chicken = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Chicken.IsBaby()); - break; - } // case mtChicken - case mtPig: { auto & Pig = reinterpret_cast(a_Mob); @@ -856,6 +856,19 @@ void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtPig + case mtRabbit: + { + auto & Rabbit = reinterpret_cast(a_Mob); + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Rabbit.IsBaby()); + + a_Pkt.WriteBEUInt8(RABBIT_TYPE); + a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); + a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); + break; + } // case mtRabbit + case mtSheep: { auto & Sheep = reinterpret_cast(a_Mob); @@ -876,19 +889,6 @@ void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtSheep - case mtRabbit: - { - auto & Rabbit = reinterpret_cast(a_Mob); - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Rabbit.IsBaby()); - - a_Pkt.WriteBEUInt8(RABBIT_TYPE); - a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); - break; - } // case mtRabbit - case mtSkeleton: { auto & Skeleton = reinterpret_cast(a_Mob); @@ -1003,5 +1003,7 @@ void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ a_Pkt.WriteBool(ZombiePigman.IsBaby()); break; } // case mtZombiePigman + + default: break; } // switch (a_Mob.GetType()) } diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index ba7742493..c0c8815e8 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -841,6 +841,26 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtBat + case mtChicken: + { + auto & Chicken = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Chicken.IsBaby()); + break; + } // case mtChicken + + case mtCow: + { + auto & Cow = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Cow.IsBaby()); + break; + } // case mtCow + case mtCreeper: { auto & Creeper = reinterpret_cast(a_Mob); @@ -978,26 +998,6 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtOcelot - case mtCow: - { - auto & Cow = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Cow.IsBaby()); - break; - } // case mtCow - - case mtChicken: - { - auto & Chicken = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Chicken.IsBaby()); - break; - } // case mtChicken - case mtPig: { auto & Pig = reinterpret_cast(a_Mob); @@ -1014,6 +1014,19 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtPig + case mtRabbit: + { + auto & Rabbit = reinterpret_cast(a_Mob); + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Rabbit.IsBaby()); + + a_Pkt.WriteBEUInt8(RABBIT_TYPE); + a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); + a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); + break; + } // case mtRabbit + case mtSheep: { auto & Sheep = reinterpret_cast(a_Mob); @@ -1034,19 +1047,6 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ break; } // case mtSheep - case mtRabbit: - { - auto & Rabbit = reinterpret_cast(a_Mob); - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Rabbit.IsBaby()); - - a_Pkt.WriteBEUInt8(RABBIT_TYPE); - a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); - break; - } // case mtRabbit - case mtSkeleton: { // XXX Skeletons are separate entities; all skeletons are currently treated as regular ones @@ -1165,6 +1165,8 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_ a_Pkt.WriteBool(ZombiePigman.IsBaby()); break; } // case mtZombiePigman + + default: break; } // switch (a_Mob.GetType()) } diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index 166078aef..627131576 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -654,6 +654,26 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo break; } // case mtBat + case mtChicken: + { + auto & Chicken = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Chicken.IsBaby()); + break; + } // case mtChicken + + case mtCow: + { + auto & Cow = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Cow.IsBaby()); + break; + } // case mtCow + case mtCreeper: { auto & Creeper = reinterpret_cast(a_Mob); @@ -791,26 +811,6 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo break; } // case mtOcelot - case mtCow: - { - auto & Cow = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Cow.IsBaby()); - break; - } // case mtCow - - case mtChicken: - { - auto & Chicken = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Chicken.IsBaby()); - break; - } // case mtChicken - case mtPig: { auto & Pig = reinterpret_cast(a_Mob); @@ -827,6 +827,19 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo break; } // case mtPig + case mtRabbit: + { + auto & Rabbit = reinterpret_cast(a_Mob); + a_Pkt.WriteBEUInt8(AGEABLE_BABY); + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Rabbit.IsBaby()); + + a_Pkt.WriteBEUInt8(RABBIT_TYPE); + a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); + a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); + break; + } // case mtRabbit + case mtSheep: { auto & Sheep = reinterpret_cast(a_Mob); @@ -847,19 +860,6 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo break; } // case mtSheep - case mtRabbit: - { - auto & Rabbit = reinterpret_cast(a_Mob); - a_Pkt.WriteBEUInt8(AGEABLE_BABY); - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Rabbit.IsBaby()); - - a_Pkt.WriteBEUInt8(RABBIT_TYPE); - a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); - break; - } // case mtRabbit - case mtSkeleton: { // XXX Skeletons are separate entities; all skeletons are currently treated as regular ones @@ -978,6 +978,38 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo a_Pkt.WriteBool(ZombiePigman.IsBaby()); break; } // case mtZombiePigman + + case mtBlaze: + case mtEnderDragon: + case mtGuardian: + case mtIronGolem: + case mtSnowGolem: + case mtSpider: + { + // TODO: Mobs with extra fields that aren't implemented + break; + } + + case mtMooshroom: + case mtCaveSpider: + { + // Not mentioned on http://wiki.vg/Entities + break; + } + + case mtGiant: + case mtSilverfish: + case mtSquid: + { + // Mobs with no extra fields + break; + } + + case mtInvalidType: + { + ASSERT(!"cProtocol_1_12::WriteMobMetadata: Recieved mob of invalid type"); + break; + } } // switch (a_Mob.GetType()) } diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index b6e5b5a38..c384f85b9 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -3414,6 +3414,22 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M break; } // case mtBat + case mtChicken: + { + auto & Chicken = reinterpret_cast(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Chicken.IsBaby() ? -1 : (Chicken.IsInLoveCooldown() ? 1 : 0)); + break; + } // case mtChicken + + case mtCow: + { + auto & Cow = reinterpret_cast(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Cow.IsBaby() ? -1 : (Cow.IsInLoveCooldown() ? 1 : 0)); + break; + } // case mtCow + case mtCreeper: { auto & Creeper = reinterpret_cast(a_Mob); @@ -3504,22 +3520,6 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M break; } // case mtOcelot - case mtCow: - { - auto & Cow = reinterpret_cast(a_Mob); - a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Cow.IsBaby() ? -1 : (Cow.IsInLoveCooldown() ? 1 : 0)); - break; - } // case mtCow - - case mtChicken: - { - auto & Chicken = reinterpret_cast(a_Mob); - a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEInt8(Chicken.IsBaby() ? -1 : (Chicken.IsInLoveCooldown() ? 1 : 0)); - break; - } // case mtChicken - case mtPig: { auto & Pig = reinterpret_cast(a_Mob); @@ -3650,6 +3650,8 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M a_Pkt.WriteBEInt8(ZombiePigman.IsBaby() ? 1 : -1); break; } // case mtZombiePigman + + default: break; } // switch (a_Mob.GetType()) } diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 90eedf91e..fcfc6674a 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -3434,6 +3434,7 @@ void cProtocol_1_9_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) case cEntityEffect::effInstantDamage: PotionID = "harming"; break; case cEntityEffect::effWaterBreathing: PotionID = "water_breathing"; break; case cEntityEffect::effInvisibility: PotionID = "invisibility"; break; + default: ASSERT(!"Unknown potion effect"); break; } if (cEntityEffect::GetPotionEffectIntensity(a_Item.m_ItemDamage) == 1) { @@ -3835,6 +3836,26 @@ void cProtocol_1_9_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M break; } // case mtBat + case mtChicken: + { + auto & Chicken = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(11); // Index 11: Is baby + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Chicken.IsBaby()); + break; + } // case mtChicken + + case mtCow: + { + auto & Cow = reinterpret_cast(a_Mob); + + a_Pkt.WriteBEUInt8(11); // Index 11: Is baby + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Cow.IsBaby()); + break; + } // case mtCow + case mtCreeper: { auto & Creeper = reinterpret_cast(a_Mob); @@ -3949,26 +3970,6 @@ void cProtocol_1_9_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M break; } // case mtOcelot - case mtCow: - { - auto & Cow = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(11); // Index 11: Is baby - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Cow.IsBaby()); - break; - } // case mtCow - - case mtChicken: - { - auto & Chicken = reinterpret_cast(a_Mob); - - a_Pkt.WriteBEUInt8(11); // Index 11: Is baby - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Chicken.IsBaby()); - break; - } // case mtChicken - case mtPig: { auto & Pig = reinterpret_cast(a_Mob); @@ -3984,6 +3985,19 @@ void cProtocol_1_9_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M break; } // case mtPig + case mtRabbit: + { + auto & Rabbit = reinterpret_cast(a_Mob); + a_Pkt.WriteBEUInt8(11); // Index 11: Is baby + a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); + a_Pkt.WriteBool(Rabbit.IsBaby()); + + a_Pkt.WriteBEUInt8(12); // Index 12: Type + a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); + a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); + break; + } // case mtRabbit + case mtSheep: { auto & Sheep = reinterpret_cast(a_Mob); @@ -4004,19 +4018,6 @@ void cProtocol_1_9_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M break; } // case mtSheep - case mtRabbit: - { - auto & Rabbit = reinterpret_cast(a_Mob); - a_Pkt.WriteBEUInt8(11); // Index 11: Is baby - a_Pkt.WriteBEUInt8(METADATA_TYPE_BOOL); - a_Pkt.WriteBool(Rabbit.IsBaby()); - - a_Pkt.WriteBEUInt8(12); // Index 12: Type - a_Pkt.WriteBEUInt8(METADATA_TYPE_VARINT); - a_Pkt.WriteVarInt32(static_cast(Rabbit.GetRabbitType())); - break; - } // case mtRabbit - case mtSkeleton: { auto & Skeleton = reinterpret_cast(a_Mob); @@ -4131,6 +4132,8 @@ void cProtocol_1_9_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M a_Pkt.WriteBool(ZombiePigman.IsBaby()); break; } // case mtZombiePigman + + default: break; } // switch (a_Mob.GetType()) } -- cgit v1.2.3