From 08db87e5f690d03b5f01e63a834a86be29051c9b Mon Sep 17 00:00:00 2001 From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com> Date: Mon, 17 Aug 2020 17:43:10 +0800 Subject: [PATCH] Fix 1.16 entity metadata and equipment (#1211) * Fix 1.16 Entity Equipment * Fix #1209 Rename variable to meet naming rule * Remove key checking * Revert "Fix 1.16 Entity Equipment" This reverts commit 6c46fc3ba41b2df153f2cc910927290590416daa. * Remove comment related to `data[key] = value` Comment is not needed anymore as the value is set or overwritten automatically (no catch) --- .../Protocol/Handlers/DataTypes.cs | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index df66bc61..5666c07f 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -497,10 +497,10 @@ namespace MinecraftClient.Protocol.Handlers public Dictionary ReadNextMetadata(Queue cache) { Dictionary data = new Dictionary(); - byte Key = ReadNextByte(cache); - while (Key != 0xff) + byte key = ReadNextByte(cache); + while (key != 0xff) { - int Type = ReadNextVarInt(cache); + int type = ReadNextVarInt(cache); // starting from 1.13, Optional Chat is inserted as number 5 in 1.13 and IDs after 5 got shifted. // Increase type ID by 1 if @@ -508,80 +508,80 @@ namespace MinecraftClient.Protocol.Handlers // - type ID larger than 4 if (protocolversion < Protocol18Handler.MC113Version) { - if (Type > 4) + if (type > 4) { - Type += 1; + type += 1; } } // Value's data type is depended on Type - object Value = null; + object value = null; // This is backward compatible since new type is appended to the end // Version upgrade note // - Check type ID got shifted or not // - Add new type if any - switch (Type) + switch (type) { case 0: // byte - Value = ReadNextByte(cache); + value = ReadNextByte(cache); break; case 1: // VarInt - Value = ReadNextVarInt(cache); + value = ReadNextVarInt(cache); break; case 2: // Float - Value = ReadNextFloat(cache); + value = ReadNextFloat(cache); break; case 3: // String - Value = ReadNextString(cache); + value = ReadNextString(cache); break; case 4: // Chat - Value = ReadNextString(cache); + value = ReadNextString(cache); break; case 5: // Optional Chat if (ReadNextBool(cache)) { - Value = ReadNextString(cache); + value = ReadNextString(cache); } break; case 6: // Slot - Value = ReadNextItemSlot(cache); + value = ReadNextItemSlot(cache); break; case 7: // Boolean - Value = ReadNextBool(cache); + value = ReadNextBool(cache); break; case 8: // Rotation (3x floats) List t = new List(); t.Add(ReadNextFloat(cache)); t.Add(ReadNextFloat(cache)); t.Add(ReadNextFloat(cache)); - Value = t; + value = t; break; case 9: // Position - Value = ReadNextLocation(cache); + value = ReadNextLocation(cache); break; case 10: // Optional Position if (ReadNextBool(cache)) { - Value = ReadNextLocation(cache); + value = ReadNextLocation(cache); } break; case 11: // Direction (VarInt) - Value = ReadNextVarInt(cache); + value = ReadNextVarInt(cache); break; case 12: // Optional UUID if (ReadNextBool(cache)) { - Value = ReadNextUUID(cache); + value = ReadNextUUID(cache); } break; case 13: // Optional BlockID (VarInt) if (ReadNextBool(cache)) { - Value = ReadNextVarInt(cache); + value = ReadNextVarInt(cache); } break; case 14: // NBT - Value = ReadNextNbt(cache); + value = ReadNextNbt(cache); break; case 15: // Particle // Currecutly not handled. Reading data only @@ -610,22 +610,22 @@ namespace MinecraftClient.Protocol.Handlers d.Add(ReadNextVarInt(cache)); d.Add(ReadNextVarInt(cache)); d.Add(ReadNextVarInt(cache)); - Value = d; + value = d; break; case 17: // Optional VarInt if (ReadNextBool(cache)) { - Value = ReadNextVarInt(cache); + value = ReadNextVarInt(cache); } break; case 18: // Pose - Value = ReadNextVarInt(cache); + value = ReadNextVarInt(cache); break; default: - throw new System.IO.InvalidDataException("Unknown Metadata Type ID " + Type + ". Is this up to date for new MC Version?"); + throw new System.IO.InvalidDataException("Unknown Metadata Type ID " + type + ". Is this up to date for new MC Version?"); } - data.Add(Key, Value); - Key = ReadNextByte(cache); + data[key] = value; + key = ReadNextByte(cache); } return data; }