diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f49175922..ef8794e53 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -28,39 +28,40 @@ static const struct eMonsterType m_Type; const char * m_lcName; const char * m_VanillaName; + const char * m_VanillaNameNBT; } g_MobTypeNames[] = { - {mtBat, "bat", "Bat"}, - {mtBlaze, "blaze", "Blaze"}, - {mtCaveSpider, "cavespider", "CaveSpider"}, - {mtChicken, "chicken", "Chicken"}, - {mtCow, "cow", "Cow"}, - {mtCreeper, "creeper", "Creeper"}, - {mtEnderman, "enderman", "Enderman"}, - {mtEnderDragon, "enderdragon", "EnderDragon"}, - {mtGhast, "ghast", "Ghast"}, - {mtGiant, "giant", "Giant"}, - {mtGuardian, "guardian", "Guardian"}, - {mtHorse, "horse", "EntityHorse"}, - {mtIronGolem, "irongolem", "VillagerGolem"}, - {mtMagmaCube, "magmacube", "LavaSlime"}, - {mtMooshroom, "mooshroom", "MushroomCow"}, - {mtOcelot, "ocelot", "Ozelot"}, - {mtPig, "pig", "Pig"}, - {mtRabbit, "rabbit", "Rabbit"}, - {mtSheep, "sheep", "Sheep"}, - {mtSilverfish, "silverfish", "Silverfish"}, - {mtSkeleton, "skeleton", "Skeleton"}, - {mtSlime, "slime", "Slime"}, - {mtSnowGolem, "snowgolem", "SnowMan"}, - {mtSpider, "spider", "Spider"}, - {mtSquid, "squid", "Squid"}, - {mtVillager, "villager", "Villager"}, - {mtWitch, "witch", "Witch"}, - {mtWither, "wither", "WitherBoss"}, - {mtWolf, "wolf", "Wolf"}, - {mtZombie, "zombie", "Zombie"}, - {mtZombiePigman, "zombiepigman", "PigZombie"}, + {mtBat, "bat", "Bat", "bat"}, + {mtBlaze, "blaze", "Blaze", "blaze"}, + {mtCaveSpider, "cavespider", "CaveSpider", "cave_spider"}, + {mtChicken, "chicken", "Chicken", "chicken"}, + {mtCow, "cow", "Cow", "cow"}, + {mtCreeper, "creeper", "Creeper", "creeper"}, + {mtEnderman, "enderman", "Enderman", "enderman"}, + {mtEnderDragon, "enderdragon", "EnderDragon", "ender_dragon"}, + {mtGhast, "ghast", "Ghast", "ghast"}, + {mtGiant, "giant", "Giant", "giant"}, + {mtGuardian, "guardian", "Guardian", "guardian"}, + {mtHorse, "horse", "EntityHorse", "horse"}, + {mtIronGolem, "irongolem", "VillagerGolem", "iron_golem"}, + {mtMagmaCube, "magmacube", "LavaSlime", "magma_cube"}, + {mtMooshroom, "mooshroom", "MushroomCow", "mooshroom"}, + {mtOcelot, "ocelot", "Ozelot", "ocelot"}, + {mtPig, "pig", "Pig", "pig"}, + {mtRabbit, "rabbit", "Rabbit", "rabbit"}, + {mtSheep, "sheep", "Sheep", "sheep"}, + {mtSilverfish, "silverfish", "Silverfish", "silverfish"}, + {mtSkeleton, "skeleton", "Skeleton", "skeleton"}, + {mtSlime, "slime", "Slime", "slime"}, + {mtSnowGolem, "snowgolem", "SnowMan", "snow_golem"}, + {mtSpider, "spider", "Spider", "spider"}, + {mtSquid, "squid", "Squid", "squid"}, + {mtVillager, "villager", "Villager", "villager"}, + {mtWitch, "witch", "Witch", "witch"}, + {mtWither, "wither", "WitherBoss", "wither"}, + {mtWolf, "wolf", "Wolf", "wolf"}, + {mtZombie, "zombie", "Zombie", "zombie"}, + {mtZombiePigman, "zombiepigman", "PigZombie", "zombie_pigman"}, } ; @@ -826,6 +827,25 @@ AString cMonster::MobTypeToVanillaName(eMonsterType a_MobType) +AString cMonster::MobTypeToVanillaNBT(eMonsterType a_MobType) +{ + // Mob types aren't sorted, so we need to search linearly: + for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) + { + if (g_MobTypeNames[i].m_Type == a_MobType) + { + return g_MobTypeNames[i].m_VanillaNameNBT; + } + } + + // Not found: + return ""; +} + + + + + eMonsterType cMonster::StringToMobType(const AString & a_Name) { AString lcName = StrToLower(a_Name); @@ -848,6 +868,15 @@ eMonsterType cMonster::StringToMobType(const AString & a_Name) } } + // Search in NBT name + for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) + { + if (strcmp(StrToLower(g_MobTypeNames[i].m_VanillaNameNBT).c_str(), lcName.c_str()) == 0) + { + return g_MobTypeNames[i].m_Type; + } + } + // Not found: return mtInvalidType; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index cb1e73942..a4d256578 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -160,6 +160,9 @@ public: // tolua_end + /** Translates the MobType enum to the vanilla nbt name */ + static AString MobTypeToVanillaNBT(eMonsterType a_MobType); + /** Sets the target that this mob will chase. Pass a nullptr to unset. */ void SetTarget (cPawn * a_NewTarget); diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 2a6c924b0..e489b3903 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -2995,9 +2995,11 @@ void cProtocol_1_9_0::ParseItemMetadata(cItem & a_Item, const AString & a_Metada { if ((NBT.GetType(entitytag) == TAG_String) && (NBT.GetName(entitytag) == "id")) { - eMonsterType MonsterType = cMonster::StringToMobType(NBT.GetString(entitytag)); - // No special method here to convert to the numeric damage value; just cast to the given ID + AString NBTName = NBT.GetString(entitytag); + ReplaceString(NBTName, "minecraft:", ""); + eMonsterType MonsterType = cMonster::StringToMobType(NBTName); a_Item.m_ItemDamage = static_cast(MonsterType); + } } } @@ -3395,7 +3397,7 @@ void cProtocol_1_9_0::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) if (MonsterType != eMonsterType::mtInvalidType) { Writer.BeginCompound("EntityTag"); - Writer.AddString("id", cMonster::MobTypeToVanillaName(MonsterType)); + Writer.AddString("id", "minecraft:" + cMonster::MobTypeToVanillaNBT(MonsterType)); Writer.EndCompound(); } }