Implement entity types (#1001)

Implement palette generation and investigate palette changes between
versions. Turns out 1.13- has legacy IDs, 1.14 switches to entity
palette and 1.15 refreshes the whole palette just to insert Bee.

Also refactor entity handling code here and there.
This commit is contained in:
ORelio 2020-05-24 18:21:22 +02:00
parent 5b0b0c9cc3
commit bd85c46663
27 changed files with 1113 additions and 259 deletions

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Mapping.EntityPalettes
{
public abstract class EntityPalette
{
/// <summary>
/// Get mapping dictionary. Must be overriden with proper implementation.
/// </summary>
/// <returns>Palette dictionary</returns>
protected abstract Dictionary<int, EntityType> GetDict();
/// <summary>
/// Get mapping dictionary for pre-1.13. May be overriden with proper implementation.
/// </summary>
/// <returns>Palette dictionary for non-living entities (pre-1.13)</returns>
protected virtual Dictionary<int, EntityType> GetDictNonLiving()
{
return null;
}
/// <summary>
/// Get entity type from type ID
/// </summary>
/// <param name="id">Entity type ID</param>
/// <returns>EntityType corresponding to the specified ID</returns>
public EntityType FromId(int id, bool living)
{
Dictionary<int, EntityType> entityTypes = GetDict();
Dictionary<int, EntityType> entityTypesNonLiving = GetDictNonLiving();
if (entityTypesNonLiving != null && !living)
{
//Pre-1.13 non-living entities have a different set of IDs (entityTypesNonLiving != null)
if (entityTypesNonLiving.ContainsKey(id))
return entityTypesNonLiving[id];
}
else
{
//Post-1.13 entities have the same set of IDs regardless of living status
if (entityTypes.ContainsKey(id))
return entityTypes[id];
}
throw new System.IO.InvalidDataException("Unknown Entity ID " + id + ". Is Entity Palette up to date for this Minecraft version?");
}
}
}

View file

@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
namespace MinecraftClient.Mapping.EntityPalettes
{
/// <summary>
/// Defines mappings for pre-1.14 entitiy IDs
/// Pre-1.14 Minecraft has 2 set of ids: One for non-living objects and one for living mobs
/// Post-1.14 Minecraft has only one set of ids for all types of entities
/// </summary>
public class EntityPalette113 : EntityPalette
{
private static Dictionary<int, EntityType> mappingsObjects = new Dictionary<int, EntityType>()
{
// https://wiki.vg/Entity_metadata#Objects
{ 1, EntityType.Boat },
{ 2, EntityType.Item },
{ 3, EntityType.AreaEffectCloud },
{ 10, EntityType.Minecart },
{ 50, EntityType.Tnt },
{ 51, EntityType.EndCrystal },
{ 60, EntityType.Arrow },
{ 61, EntityType.Snowball },
{ 62, EntityType.Egg },
{ 63, EntityType.Fireball },
{ 64, EntityType.SmallFireball },
{ 65, EntityType.EnderPearl },
{ 66, EntityType.WitherSkull },
{ 67, EntityType.ShulkerBullet },
{ 68, EntityType.LlamaSpit },
{ 70, EntityType.FallingBlock },
{ 71, EntityType.ItemFrame },
{ 72, EntityType.EyeOfEnder },
{ 73, EntityType.Potion },
{ 75, EntityType.ExperienceBottle },
{ 76, EntityType.FireworkRocket },
{ 77, EntityType.LeashKnot },
{ 78, EntityType.ArmorStand },
{ 79, EntityType.EvokerFangs },
{ 90, EntityType.FishingBobber },
{ 91, EntityType.SpectralArrow },
{ 93, EntityType.DragonFireball },
{ 94, EntityType.Trident },
};
private static Dictionary<int, EntityType> mappingsMobs = new Dictionary<int, EntityType>()
{
// https://wiki.vg/Entity_metadata#Mobs
{ 0, EntityType.AreaEffectCloud },
{ 1, EntityType.ArmorStand },
{ 2, EntityType.Arrow },
{ 3, EntityType.Bat },
{ 4, EntityType.Blaze },
{ 5, EntityType.Boat },
{ 6, EntityType.CaveSpider },
{ 7, EntityType.Chicken },
{ 8, EntityType.Cod },
{ 9, EntityType.Cow },
{ 10, EntityType.Creeper },
{ 11, EntityType.Donkey },
{ 12, EntityType.Dolphin },
{ 13, EntityType.DragonFireball },
{ 14, EntityType.Drowned },
{ 15, EntityType.ElderGuardian },
{ 16, EntityType.EndCrystal },
{ 17, EntityType.EnderDragon },
{ 18, EntityType.Enderman },
{ 19, EntityType.Endermite },
{ 20, EntityType.EvokerFangs },
{ 21, EntityType.Evoker },
{ 22, EntityType.ExperienceBottle },
{ 23, EntityType.EyeOfEnder },
{ 24, EntityType.FallingBlock },
{ 25, EntityType.FireworkRocket },
{ 26, EntityType.Ghast },
{ 27, EntityType.Giant },
{ 28, EntityType.Guardian },
{ 29, EntityType.Horse },
{ 30, EntityType.Husk },
{ 31, EntityType.Illusioner },
{ 32, EntityType.Item },
{ 33, EntityType.ItemFrame },
{ 34, EntityType.Fireball },
{ 35, EntityType.LeashKnot },
{ 36, EntityType.Llama },
{ 37, EntityType.LlamaSpit },
{ 38, EntityType.MagmaCube },
{ 39, EntityType.Minecart },
{ 40, EntityType.ChestMinecart },
{ 41, EntityType.CommandBlockMinecart },
{ 42, EntityType.FurnaceMinecart },
{ 43, EntityType.HopperMinecart },
{ 44, EntityType.SpawnerMinecart },
{ 45, EntityType.TntMinecart },
{ 46, EntityType.Mule },
{ 47, EntityType.Mooshroom },
{ 48, EntityType.Ocelot },
{ 49, EntityType.Painting },
{ 50, EntityType.Parrot },
{ 51, EntityType.Pig },
{ 52, EntityType.Pufferfish },
{ 53, EntityType.ZombiePigman },
{ 54, EntityType.PolarBear },
{ 55, EntityType.Tnt },
{ 56, EntityType.Rabbit },
{ 57, EntityType.Salmon },
{ 58, EntityType.Sheep },
{ 59, EntityType.Shulker },
{ 60, EntityType.ShulkerBullet },
{ 61, EntityType.Silverfish },
{ 62, EntityType.Skeleton },
{ 63, EntityType.SkeletonHorse },
{ 64, EntityType.Slime },
{ 65, EntityType.SmallFireball },
{ 66, EntityType.SnowGolem },
{ 67, EntityType.Snowball },
{ 68, EntityType.SpectralArrow },
{ 69, EntityType.Spider },
{ 70, EntityType.Squid },
{ 71, EntityType.Stray },
{ 72, EntityType.TropicalFish },
{ 73, EntityType.Turtle },
{ 74, EntityType.Egg },
{ 75, EntityType.EnderPearl },
{ 76, EntityType.ExperienceBottle },
{ 77, EntityType.Potion },
{ 78, EntityType.Vex },
{ 79, EntityType.Villager },
{ 80, EntityType.IronGolem },
{ 81, EntityType.Vindicator },
{ 82, EntityType.Witch },
{ 83, EntityType.Wither },
{ 84, EntityType.WitherSkeleton },
{ 85, EntityType.WitherSkull },
{ 86, EntityType.Wolf },
{ 87, EntityType.Zombie },
{ 88, EntityType.ZombieHorse },
{ 89, EntityType.ZombieVillager },
{ 90, EntityType.Phantom },
{ 91, EntityType.LightningBolt },
{ 92, EntityType.Player },
{ 93, EntityType.FishingBobber },
{ 94, EntityType.Trident },
};
protected override Dictionary<int, EntityType> GetDict()
{
return mappingsMobs;
}
protected override Dictionary<int, EntityType> GetDictNonLiving()
{
return mappingsObjects;
}
}
}

View file

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
namespace MinecraftClient.Mapping.EntityPalettes
{
/// <summary>
/// Defines mappings for Minecraft 1.14.
/// Automatically generated using EntityPaletteGenerator.cs
/// </summary>
public class EntityPalette114 : EntityPalette
{
private static Dictionary<int, EntityType> mappings = new Dictionary<int, EntityType>();
static EntityPalette114()
{
mappings[0] = EntityType.AreaEffectCloud;
mappings[1] = EntityType.ArmorStand;
mappings[2] = EntityType.Arrow;
mappings[3] = EntityType.Bat;
mappings[4] = EntityType.Blaze;
mappings[5] = EntityType.Boat;
mappings[6] = EntityType.Cat;
mappings[7] = EntityType.CaveSpider;
mappings[8] = EntityType.Chicken;
mappings[9] = EntityType.Cod;
mappings[10] = EntityType.Cow;
mappings[11] = EntityType.Creeper;
mappings[12] = EntityType.Donkey;
mappings[13] = EntityType.Dolphin;
mappings[14] = EntityType.DragonFireball;
mappings[15] = EntityType.Drowned;
mappings[16] = EntityType.ElderGuardian;
mappings[17] = EntityType.EndCrystal;
mappings[18] = EntityType.EnderDragon;
mappings[19] = EntityType.Enderman;
mappings[20] = EntityType.Endermite;
mappings[21] = EntityType.EvokerFangs;
mappings[22] = EntityType.Evoker;
mappings[23] = EntityType.ExperienceOrb;
mappings[24] = EntityType.EyeOfEnder;
mappings[25] = EntityType.FallingBlock;
mappings[26] = EntityType.FireworkRocket;
mappings[27] = EntityType.Fox;
mappings[28] = EntityType.Ghast;
mappings[29] = EntityType.Giant;
mappings[30] = EntityType.Guardian;
mappings[31] = EntityType.Horse;
mappings[32] = EntityType.Husk;
mappings[33] = EntityType.Illusioner;
mappings[34] = EntityType.Item;
mappings[35] = EntityType.ItemFrame;
mappings[36] = EntityType.Fireball;
mappings[37] = EntityType.LeashKnot;
mappings[38] = EntityType.Llama;
mappings[39] = EntityType.LlamaSpit;
mappings[40] = EntityType.MagmaCube;
mappings[41] = EntityType.Minecart;
mappings[42] = EntityType.ChestMinecart;
mappings[43] = EntityType.CommandBlockMinecart;
mappings[44] = EntityType.FurnaceMinecart;
mappings[45] = EntityType.HopperMinecart;
mappings[46] = EntityType.SpawnerMinecart;
mappings[47] = EntityType.TntMinecart;
mappings[48] = EntityType.Mule;
mappings[49] = EntityType.Mooshroom;
mappings[50] = EntityType.Ocelot;
mappings[51] = EntityType.Painting;
mappings[52] = EntityType.Panda;
mappings[53] = EntityType.Parrot;
mappings[54] = EntityType.Pig;
mappings[55] = EntityType.Pufferfish;
mappings[56] = EntityType.ZombiePigman;
mappings[57] = EntityType.PolarBear;
mappings[58] = EntityType.Tnt;
mappings[59] = EntityType.Rabbit;
mappings[60] = EntityType.Salmon;
mappings[61] = EntityType.Sheep;
mappings[62] = EntityType.Shulker;
mappings[63] = EntityType.ShulkerBullet;
mappings[64] = EntityType.Silverfish;
mappings[65] = EntityType.Skeleton;
mappings[66] = EntityType.SkeletonHorse;
mappings[67] = EntityType.Slime;
mappings[68] = EntityType.SmallFireball;
mappings[69] = EntityType.SnowGolem;
mappings[70] = EntityType.Snowball;
mappings[71] = EntityType.SpectralArrow;
mappings[72] = EntityType.Spider;
mappings[73] = EntityType.Squid;
mappings[74] = EntityType.Stray;
mappings[75] = EntityType.TraderLlama;
mappings[76] = EntityType.TropicalFish;
mappings[77] = EntityType.Turtle;
mappings[78] = EntityType.Egg;
mappings[79] = EntityType.EnderPearl;
mappings[80] = EntityType.ExperienceBottle;
mappings[81] = EntityType.Potion;
mappings[82] = EntityType.Trident;
mappings[83] = EntityType.Vex;
mappings[84] = EntityType.Villager;
mappings[85] = EntityType.IronGolem;
mappings[86] = EntityType.Vindicator;
mappings[87] = EntityType.Pillager;
mappings[88] = EntityType.WanderingTrader;
mappings[89] = EntityType.Witch;
mappings[90] = EntityType.Wither;
mappings[91] = EntityType.WitherSkeleton;
mappings[92] = EntityType.WitherSkull;
mappings[93] = EntityType.Wolf;
mappings[94] = EntityType.Zombie;
mappings[95] = EntityType.ZombieHorse;
mappings[96] = EntityType.ZombieVillager;
mappings[97] = EntityType.Phantom;
mappings[98] = EntityType.Ravager;
mappings[99] = EntityType.LightningBolt;
mappings[100] = EntityType.Player;
mappings[101] = EntityType.FishingBobber;
}
protected override Dictionary<int, EntityType> GetDict()
{
return mappings;
}
}
}

View file

@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
namespace MinecraftClient.Mapping.EntityPalettes
{
/// <summary>
/// Defines mappings for Minecraft 1.15.
/// Automatically generated using EntityPaletteGenerator.cs
/// </summary>
public class EntityPalette115 : EntityPalette
{
private static Dictionary<int, EntityType> mappings = new Dictionary<int, EntityType>();
static EntityPalette115()
{
mappings[0] = EntityType.AreaEffectCloud;
mappings[1] = EntityType.ArmorStand;
mappings[2] = EntityType.Arrow;
mappings[3] = EntityType.Bat;
mappings[4] = EntityType.Bee;
mappings[5] = EntityType.Blaze;
mappings[6] = EntityType.Boat;
mappings[7] = EntityType.Cat;
mappings[8] = EntityType.CaveSpider;
mappings[9] = EntityType.Chicken;
mappings[10] = EntityType.Cod;
mappings[11] = EntityType.Cow;
mappings[12] = EntityType.Creeper;
mappings[13] = EntityType.Donkey;
mappings[14] = EntityType.Dolphin;
mappings[15] = EntityType.DragonFireball;
mappings[16] = EntityType.Drowned;
mappings[17] = EntityType.ElderGuardian;
mappings[18] = EntityType.EndCrystal;
mappings[19] = EntityType.EnderDragon;
mappings[20] = EntityType.Enderman;
mappings[21] = EntityType.Endermite;
mappings[22] = EntityType.EvokerFangs;
mappings[23] = EntityType.Evoker;
mappings[24] = EntityType.ExperienceOrb;
mappings[25] = EntityType.EyeOfEnder;
mappings[26] = EntityType.FallingBlock;
mappings[27] = EntityType.FireworkRocket;
mappings[28] = EntityType.Fox;
mappings[29] = EntityType.Ghast;
mappings[30] = EntityType.Giant;
mappings[31] = EntityType.Guardian;
mappings[32] = EntityType.Horse;
mappings[33] = EntityType.Husk;
mappings[34] = EntityType.Illusioner;
mappings[35] = EntityType.Item;
mappings[36] = EntityType.ItemFrame;
mappings[37] = EntityType.Fireball;
mappings[38] = EntityType.LeashKnot;
mappings[39] = EntityType.Llama;
mappings[40] = EntityType.LlamaSpit;
mappings[41] = EntityType.MagmaCube;
mappings[42] = EntityType.Minecart;
mappings[43] = EntityType.ChestMinecart;
mappings[44] = EntityType.CommandBlockMinecart;
mappings[45] = EntityType.FurnaceMinecart;
mappings[46] = EntityType.HopperMinecart;
mappings[47] = EntityType.SpawnerMinecart;
mappings[48] = EntityType.TntMinecart;
mappings[49] = EntityType.Mule;
mappings[50] = EntityType.Mooshroom;
mappings[51] = EntityType.Ocelot;
mappings[52] = EntityType.Painting;
mappings[53] = EntityType.Panda;
mappings[54] = EntityType.Parrot;
mappings[55] = EntityType.Pig;
mappings[56] = EntityType.Pufferfish;
mappings[57] = EntityType.ZombiePigman;
mappings[58] = EntityType.PolarBear;
mappings[59] = EntityType.Tnt;
mappings[60] = EntityType.Rabbit;
mappings[61] = EntityType.Salmon;
mappings[62] = EntityType.Sheep;
mappings[63] = EntityType.Shulker;
mappings[64] = EntityType.ShulkerBullet;
mappings[65] = EntityType.Silverfish;
mappings[66] = EntityType.Skeleton;
mappings[67] = EntityType.SkeletonHorse;
mappings[68] = EntityType.Slime;
mappings[69] = EntityType.SmallFireball;
mappings[70] = EntityType.SnowGolem;
mappings[71] = EntityType.Snowball;
mappings[72] = EntityType.SpectralArrow;
mappings[73] = EntityType.Spider;
mappings[74] = EntityType.Squid;
mappings[75] = EntityType.Stray;
mappings[76] = EntityType.TraderLlama;
mappings[77] = EntityType.TropicalFish;
mappings[78] = EntityType.Turtle;
mappings[79] = EntityType.Egg;
mappings[80] = EntityType.EnderPearl;
mappings[81] = EntityType.ExperienceBottle;
mappings[82] = EntityType.Potion;
mappings[83] = EntityType.Trident;
mappings[84] = EntityType.Vex;
mappings[85] = EntityType.Villager;
mappings[86] = EntityType.IronGolem;
mappings[87] = EntityType.Vindicator;
mappings[88] = EntityType.Pillager;
mappings[89] = EntityType.WanderingTrader;
mappings[90] = EntityType.Witch;
mappings[91] = EntityType.Wither;
mappings[92] = EntityType.WitherSkeleton;
mappings[93] = EntityType.WitherSkull;
mappings[94] = EntityType.Wolf;
mappings[95] = EntityType.Zombie;
mappings[96] = EntityType.ZombieHorse;
mappings[97] = EntityType.ZombieVillager;
mappings[98] = EntityType.Phantom;
mappings[99] = EntityType.Ravager;
mappings[100] = EntityType.LightningBolt;
mappings[101] = EntityType.Player;
mappings[102] = EntityType.FishingBobber;
}
protected override Dictionary<int, EntityType> GetDict()
{
return mappings;
}
}
}

View file

@ -0,0 +1,20 @@
using MinecraftClient.Protocol;
namespace MinecraftClient.Mapping.EntityPalettes
{
/// <summary>
/// Generator for MCC ItemType enumeration
/// </summary>
public static class EntityPaletteGenerator
{
/// <summary>
/// Generate EntityType.cs from Minecraft registries.json
/// </summary>
/// <param name="registriesJsonFile">path to registries.json</param>
/// <remarks>java -cp minecraft_server.jar net.minecraft.data.Main --reports</remarks>
public static void GenerateEntityTypes(string registriesJsonFile)
{
DataTypeGenerator.GenerateEnumWithPalette(registriesJsonFile, "minecraft:entity_type", "EntityType", "MinecraftClient.Mapping", "EntityPalette", "MinecraftClient.Mapping.EntityPalettes");
}
}
}

View file

@ -0,0 +1,108 @@
namespace MinecraftClient.Mapping
{
public enum EntityType115
{
AreaEffectCloud = 0,
ArmorStand = 1,
Arrow = 2,
Bat = 3,
Blaze = 4,
Boat = 5,
Cat = 6,
CaveSpider = 7,
Chicken = 8,
Cod = 9,
Cow = 10,
Creeper = 11,
Donkey = 12,
Dolphin = 13,
DragonFireball = 14,
Drowned = 15,
ElderGuardian = 16,
EndCrystal = 17,
EnderDragon = 18,
Enderman = 19,
Endermite = 20,
EvokerFangs = 21,
Evoker = 22,
ExperienceOrb = 23,
EyeOfEnder = 24,
FallingBlock = 25,
FireworkRocket = 26,
Fox = 27,
Ghast = 28,
Giant = 29,
Guardian = 30,
Horse = 31,
Husk = 32,
Illusioner = 33,
Item = 34,
ItemFrame = 35,
Fireball = 36,
LeashKnot = 37,
Llama = 38,
LlamaSpit = 39,
MagmaCube = 40,
Minecart = 41,
ChestMinecart = 42,
CommandBlockMinecart = 43,
FurnaceMinecart = 44,
HopperMinecart = 45,
SpawnerMinecart = 46,
TntMinecart = 47,
Mule = 48,
Mooshroom = 49,
Ocelot = 50,
Painting = 51,
Panda = 52,
Parrot = 53,
Pig = 54,
Pufferfish = 55,
ZombiePigman = 56,
PolarBear = 57,
Tnt = 58,
Rabbit = 59,
Salmon = 60,
Sheep = 61,
Shulker = 62,
ShulkerBullet = 63,
Silverfish = 64,
Skeleton = 65,
SkeletonHorse = 66,
Slime = 67,
SmallFireball = 68,
SnowGolem = 69,
Snowball = 70,
SpectralArrow = 71,
Spider = 72,
Squid = 73,
Stray = 74,
TraderLlama = 75,
TropicalFish = 76,
Turtle = 77,
Egg = 78,
EnderPearl = 79,
ExperienceBottle = 80,
Potion = 81,
Trident = 82,
Vex = 83,
Villager = 84,
IronGolem = 85,
Vindicator = 86,
Pillager = 87,
WanderingTrader = 88,
Witch = 89,
Wither = 90,
WitherSkeleton = 91,
WitherSkull = 92,
Wolf = 93,
Zombie = 94,
ZombieHorse = 95,
ZombieVillager = 96,
Phantom = 97,
Ravager = 98,
LightningBolt = 99,
Player = 100,
FishingBobber = 101,
}
}

View file

@ -0,0 +1,109 @@
namespace MinecraftClient.Mapping
{
public enum EntityType114
{
AreaEffectCloud = 0,
ArmorStand = 1,
Arrow = 2,
Bat = 3,
Bee = 4,
Blaze = 5,
Boat = 6,
Cat = 7,
CaveSpider = 8,
Chicken = 9,
Cod = 10,
Cow = 11,
Creeper = 12,
Donkey = 13,
Dolphin = 14,
DragonFireball = 15,
Drowned = 16,
ElderGuardian = 17,
EndCrystal = 18,
EnderDragon = 19,
Enderman = 20,
Endermite = 21,
EvokerFangs = 22,
Evoker = 23,
ExperienceOrb = 24,
EyeOfEnder = 25,
FallingBlock = 26,
FireworkRocket = 27,
Fox = 28,
Ghast = 29,
Giant = 30,
Guardian = 31,
Horse = 32,
Husk = 33,
Illusioner = 34,
Item = 35,
ItemFrame = 36,
Fireball = 37,
LeashKnot = 38,
Llama = 39,
LlamaSpit = 40,
MagmaCube = 41,
Minecart = 42,
ChestMinecart = 43,
CommandBlockMinecart = 44,
FurnaceMinecart = 45,
HopperMinecart = 46,
SpawnerMinecart = 47,
TntMinecart = 48,
Mule = 49,
Mooshroom = 50,
Ocelot = 51,
Painting = 52,
Panda = 53,
Parrot = 54,
Pig = 55,
Pufferfish = 56,
ZombiePigman = 57,
PolarBear = 58,
Tnt = 59,
Rabbit = 60,
Salmon = 61,
Sheep = 62,
Shulker = 63,
ShulkerBullet = 64,
Silverfish = 65,
Skeleton = 66,
SkeletonHorse = 67,
Slime = 68,
SmallFireball = 69,
SnowGolem = 70,
Snowball = 71,
SpectralArrow = 72,
Spider = 73,
Squid = 74,
Stray = 75,
TraderLlama = 76,
TropicalFish = 77,
Turtle = 78,
Egg = 79,
EnderPearl = 80,
ExperienceBottle = 81,
Potion = 82,
Trident = 83,
Vex = 84,
Villager = 85,
IronGolem = 86,
Vindicator = 87,
Pillager = 88,
WanderingTrader = 89,
Witch = 90,
Wither = 91,
WitherSkeleton = 92,
WitherSkull = 93,
Wolf = 94,
Zombie = 95,
ZombieHorse = 96,
ZombieVillager = 97,
Phantom = 98,
Ravager = 99,
LightningBolt = 100,
Player = 101,
FishingBobber = 102,
}
}