From a58e97563046f36956a9356780ea348a67258fc1 Mon Sep 17 00:00:00 2001 From: Dusan Milutinovic Date: Mon, 27 Jul 2020 12:43:32 +0200 Subject: [PATCH] Updated the protocol for 1.16/1.16.1. Fixed Auto Attack (Added a new field (sneaking) to the Interact Entity event (Only 1.16 and above)). Added Entity Pallete for 1.16/1.16.1. --- .../EntityPalettes/EntityPalette116.cs | 126 ++++++++++++++++++ MinecraftClient/Mapping/EntityType.cs | 40 +++--- MinecraftClient/MinecraftClient.csproj | 1 + .../Protocol/Handlers/DataTypes.cs | 12 ++ .../Protocol/Handlers/Protocol18.cs | 19 ++- .../Handlers/Protocol18PacketTypes.cs | 8 +- 6 files changed, 173 insertions(+), 33 deletions(-) create mode 100644 MinecraftClient/Mapping/EntityPalettes/EntityPalette116.cs diff --git a/MinecraftClient/Mapping/EntityPalettes/EntityPalette116.cs b/MinecraftClient/Mapping/EntityPalettes/EntityPalette116.cs new file mode 100644 index 00000000..b1b6c036 --- /dev/null +++ b/MinecraftClient/Mapping/EntityPalettes/EntityPalette116.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; + +namespace MinecraftClient.Mapping.EntityPalettes +{ + public class EntityPalette116 : EntityPalette + { + private static Dictionary mappings = new Dictionary(); + + static EntityPalette116() + { + 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.Dolphin; + mappings[14] = EntityType.Donkey; + 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.Evoker; + mappings[23] = EntityType.EvokerFangs; + 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.Hoglin; + mappings[33] = EntityType.Horse; + mappings[34] = EntityType.Husk; + mappings[35] = EntityType.Illusioner; + mappings[36] = EntityType.IronGolem; + mappings[37] = EntityType.Item; + mappings[38] = EntityType.ItemFrame; + mappings[39] = EntityType.Fireball; + mappings[40] = EntityType.LeashKnot; + mappings[41] = EntityType.LightningBolt; + mappings[42] = EntityType.Llama; + mappings[43] = EntityType.LlamaSpit; + mappings[44] = EntityType.MagmaCube; + mappings[45] = EntityType.Minecart; + mappings[46] = EntityType.ChestMinecart; + mappings[47] = EntityType.CommandBlockMinecart; + mappings[48] = EntityType.FurnaceMinecart; + mappings[49] = EntityType.HopperMinecart; + mappings[50] = EntityType.SpawnerMinecart; + mappings[51] = EntityType.TntMinecart; + mappings[52] = EntityType.Mule; + mappings[53] = EntityType.Mooshroom; + mappings[54] = EntityType.Ocelot; + mappings[55] = EntityType.Painting; + mappings[56] = EntityType.Panda; + mappings[57] = EntityType.Parrot; + mappings[58] = EntityType.Phantom; + mappings[59] = EntityType.Pig; + mappings[60] = EntityType.Piglin; + mappings[61] = EntityType.Pillager; + mappings[62] = EntityType.PolarBear; + mappings[63] = EntityType.Tnt; + mappings[64] = EntityType.Pufferfish; + mappings[65] = EntityType.Rabbit; + mappings[66] = EntityType.Ravager; + mappings[67] = EntityType.Salmon; + mappings[68] = EntityType.Sheep; + mappings[69] = EntityType.Shulker; + mappings[70] = EntityType.ShulkerBullet; + mappings[71] = EntityType.Silverfish; + mappings[72] = EntityType.Skeleton; + mappings[73] = EntityType.SkeletonHorse; + mappings[74] = EntityType.Slime; + mappings[75] = EntityType.SmallFireball; + mappings[76] = EntityType.SnowGolem; + mappings[77] = EntityType.Snowball; + mappings[78] = EntityType.SpectralArrow; + mappings[79] = EntityType.Spider; + mappings[80] = EntityType.Squid; + mappings[81] = EntityType.Stray; + mappings[82] = EntityType.Strider; + mappings[83] = EntityType.Egg; + mappings[84] = EntityType.EnderPearl; + mappings[85] = EntityType.ExperienceBottle; + mappings[86] = EntityType.Potion; + mappings[87] = EntityType.Trident; + mappings[88] = EntityType.TraderLlama; + mappings[89] = EntityType.TropicalFish; + mappings[90] = EntityType.Turtle; + mappings[91] = EntityType.Vex; + mappings[92] = EntityType.Villager; + mappings[93] = EntityType.Vindicator; + mappings[94] = EntityType.WanderingTrader; + mappings[95] = EntityType.Witch; + mappings[96] = EntityType.Wither; + mappings[97] = EntityType.WitherSkeleton; + mappings[98] = EntityType.WitherSkull; + mappings[99] = EntityType.Wolf; + mappings[100] = EntityType.Zoglin; + mappings[101] = EntityType.Zombie; + mappings[102] = EntityType.ZombieHorse; + mappings[103] = EntityType.ZombieVillager; + mappings[104] = EntityType.ZombiePigman; + mappings[105] = EntityType.Player; + mappings[106] = EntityType.FishingBobber; + } + + protected override Dictionary GetDict() + { + return mappings; + } + } +} diff --git a/MinecraftClient/Mapping/EntityType.cs b/MinecraftClient/Mapping/EntityType.cs index 09a7f69c..1d67c67d 100644 --- a/MinecraftClient/Mapping/EntityType.cs +++ b/MinecraftClient/Mapping/EntityType.cs @@ -1,17 +1,5 @@ namespace MinecraftClient.Mapping { - /// - /// Represents Minecraft Entity Types - /// - /// - /// Generated from registries.json using EntityPaletteGenerator.cs. - /// Typical steps to handle new entity IDs for newer Minecraft versions: - /// 1. Generate registries.json using data reporting on Vanilla Minecraft (https://wiki.vg/Data_Generators) - /// 2. Generate temporary EntityTypeXXX.cs and EntityPaletteXXX.cs using EntityPaletteGenerator.cs - /// 3. Perform a diff with existing versions, add missing entries in EntityType.cs and EntityTypeExtensions.cs - /// 4. If existing entity IDs were not randomized by Mojang, simply add missing entries to the latest existing EntityPaletteXXX.cs - /// 5. If existing entity IDs were randomized, add a new palette as EntityPaletteXXX.cs into the codebase (worst case) - /// public enum EntityType { AreaEffectCloud, @@ -27,8 +15,8 @@ namespace MinecraftClient.Mapping Cod, Cow, Creeper, - Donkey, Dolphin, + Donkey, DragonFireball, Drowned, ElderGuardian, @@ -36,8 +24,8 @@ namespace MinecraftClient.Mapping EnderDragon, Enderman, Endermite, - EvokerFangs, Evoker, + EvokerFangs, ExperienceOrb, EyeOfEnder, FallingBlock, @@ -46,13 +34,16 @@ namespace MinecraftClient.Mapping Ghast, Giant, Guardian, + Hoglin, Horse, Husk, Illusioner, + IronGolem, Item, ItemFrame, Fireball, LeashKnot, + LightningBolt, Llama, LlamaSpit, MagmaCube, @@ -69,12 +60,15 @@ namespace MinecraftClient.Mapping Painting, Panda, Parrot, + Phantom, Pig, - Pufferfish, - ZombiePigman, + Piglin, + Pillager, PolarBear, Tnt, + Pufferfish, Rabbit, + Ravager, Salmon, Sheep, Shulker, @@ -90,31 +84,29 @@ namespace MinecraftClient.Mapping Spider, Squid, Stray, - TraderLlama, - TropicalFish, - Turtle, + Strider, Egg, EnderPearl, ExperienceBottle, Potion, Trident, + TraderLlama, + TropicalFish, + Turtle, Vex, Villager, - IronGolem, Vindicator, - Pillager, WanderingTrader, Witch, Wither, WitherSkeleton, WitherSkull, Wolf, + Zoglin, Zombie, ZombieHorse, ZombieVillager, - Phantom, - Ravager, - LightningBolt, + ZombiePigman, Player, FishingBobber, } diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj index 6c76edee..2b114481 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -133,6 +133,7 @@ + diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 5a077073..6aed193e 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -671,6 +671,18 @@ namespace MinecraftClient.Protocol.Handlers return bytes.ToArray(); } + /// + /// Build an boolean for sending over the network + /// + /// Boolean to encode + /// Byte array for this boolean + public byte[] GetVarBool(bool paramBool) + { + List bytes = new List(); + bytes.Add((byte)Convert.ToByte(paramBool)); + return bytes.ToArray(); + } + /// /// Get byte array representing a long integer /// diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index e7a1901c..1343e088 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -84,7 +84,7 @@ namespace MinecraftClient.Protocol.Handlers handler.SetInventoryEnabled(false); } - if (handler.GetEntityHandlingEnabled() && (protocolversion <= MC1122Version || protocolversion > MC1152Version)) + if (handler.GetEntityHandlingEnabled() && (protocolversion <= MC1122Version || protocolversion > MC1161Version)) { ConsoleIO.WriteLineFormatted("ยง8Entities are currently not handled for that MC version."); handler.SetEntityHandlingEnabled(false); @@ -104,11 +104,13 @@ namespace MinecraftClient.Protocol.Handlers if (protocolversion >= MC114Version) { - if (protocolversion > MC1152Version && handler.GetEntityHandlingEnabled()) + if (protocolversion > MC1161Version && handler.GetEntityHandlingEnabled()) throw new NotImplementedException("Please update entity types handling for this Minecraft version. See EntityType.cs"); - if (protocolversion >= MC115Version) - entityPalette = new EntityPalette115(); - else entityPalette = new EntityPalette114(); + if (protocolversion < MC115Version) + entityPalette = new EntityPalette114(); + if (protocolversion > MC115Version) + entityPalette = new EntityPalette116(); + else entityPalette = new EntityPalette115(); } else entityPalette = new EntityPalette113(); } @@ -1436,6 +1438,13 @@ namespace MinecraftClient.Protocol.Handlers List fields = new List(); fields.AddRange(dataTypes.GetVarInt(EntityID)); fields.AddRange(dataTypes.GetVarInt(type)); + + // Is player Sneaking (Only 1.16 and above) + // Currently hardcoded to false + // TODO: Update to reflect the real player state + if (protocolversion >= MC116Version) + fields.AddRange(dataTypes.GetVarBool(false)); + SendPacket(PacketOutgoingType.InteractEntity, fields); return true; } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs index e3705bc0..a5b43e22 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs @@ -385,9 +385,9 @@ namespace MinecraftClient.Protocol.Handlers case 0x29: return PacketIncomingType.EntityPositionAndRotation; case 0x58: return PacketIncomingType.EntityProperties; case 0x56: return PacketIncomingType.EntityTeleport; - case 0x46: return PacketIncomingType.EntityVelocity; + case 0x46: return PacketIncomingType.EntityVelocity; // This is maybe entity moving, not sure case 0x47: return PacketIncomingType.EntityEquipment; - case 0x5A: return PacketIncomingType.EntityEffect; + case 0x59: return PacketIncomingType.EntityEffect; case 0x4E: return PacketIncomingType.TimeUpdate; case 0x49: return PacketIncomingType.UpdateHealth; case 0x48: return PacketIncomingType.SetExperience; @@ -605,12 +605,12 @@ namespace MinecraftClient.Protocol.Handlers case PacketOutgoingType.UseItem: return 0x2E; case PacketOutgoingType.ClickWindow: return 0x09; case PacketOutgoingType.CloseWindow: return 0x0A; - case PacketOutgoingType.PlayerBlockPlacement: return 0x2C; + case PacketOutgoingType.PlayerBlockPlacement: return 0x2D; case PacketOutgoingType.CreativeInventoryAction: return 0x27; case PacketOutgoingType.Animation: return 0x2B; case PacketOutgoingType.PlayerDigging: return 0x1B; case PacketOutgoingType.UpdateSign: return 0x2A; - case PacketOutgoingType.UpdateCommandBlock: return 0x24; + case PacketOutgoingType.UpdateCommandBlock: return 0x25; } }