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 6c46fc3ba4.
* Remove comment related to `data[key] = value`
Comment is not needed anymore as the value is set or overwritten automatically (no catch)
This commit is contained in:
ReinforceZwei 2020-08-17 17:43:10 +08:00 committed by GitHub
parent 236e077e44
commit 08db87e5f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -497,10 +497,10 @@ namespace MinecraftClient.Protocol.Handlers
public Dictionary<int, object> ReadNextMetadata(Queue<byte> cache) public Dictionary<int, object> ReadNextMetadata(Queue<byte> cache)
{ {
Dictionary<int, object> data = new Dictionary<int, object>(); Dictionary<int, object> data = new Dictionary<int, object>();
byte Key = ReadNextByte(cache); byte key = ReadNextByte(cache);
while (Key != 0xff) 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. // 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 // Increase type ID by 1 if
@ -508,80 +508,80 @@ namespace MinecraftClient.Protocol.Handlers
// - type ID larger than 4 // - type ID larger than 4
if (protocolversion < Protocol18Handler.MC113Version) if (protocolversion < Protocol18Handler.MC113Version)
{ {
if (Type > 4) if (type > 4)
{ {
Type += 1; type += 1;
} }
} }
// Value's data type is depended on Type // 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 // This is backward compatible since new type is appended to the end
// Version upgrade note // Version upgrade note
// - Check type ID got shifted or not // - Check type ID got shifted or not
// - Add new type if any // - Add new type if any
switch (Type) switch (type)
{ {
case 0: // byte case 0: // byte
Value = ReadNextByte(cache); value = ReadNextByte(cache);
break; break;
case 1: // VarInt case 1: // VarInt
Value = ReadNextVarInt(cache); value = ReadNextVarInt(cache);
break; break;
case 2: // Float case 2: // Float
Value = ReadNextFloat(cache); value = ReadNextFloat(cache);
break; break;
case 3: // String case 3: // String
Value = ReadNextString(cache); value = ReadNextString(cache);
break; break;
case 4: // Chat case 4: // Chat
Value = ReadNextString(cache); value = ReadNextString(cache);
break; break;
case 5: // Optional Chat case 5: // Optional Chat
if (ReadNextBool(cache)) if (ReadNextBool(cache))
{ {
Value = ReadNextString(cache); value = ReadNextString(cache);
} }
break; break;
case 6: // Slot case 6: // Slot
Value = ReadNextItemSlot(cache); value = ReadNextItemSlot(cache);
break; break;
case 7: // Boolean case 7: // Boolean
Value = ReadNextBool(cache); value = ReadNextBool(cache);
break; break;
case 8: // Rotation (3x floats) case 8: // Rotation (3x floats)
List<float> t = new List<float>(); List<float> t = new List<float>();
t.Add(ReadNextFloat(cache)); t.Add(ReadNextFloat(cache));
t.Add(ReadNextFloat(cache)); t.Add(ReadNextFloat(cache));
t.Add(ReadNextFloat(cache)); t.Add(ReadNextFloat(cache));
Value = t; value = t;
break; break;
case 9: // Position case 9: // Position
Value = ReadNextLocation(cache); value = ReadNextLocation(cache);
break; break;
case 10: // Optional Position case 10: // Optional Position
if (ReadNextBool(cache)) if (ReadNextBool(cache))
{ {
Value = ReadNextLocation(cache); value = ReadNextLocation(cache);
} }
break; break;
case 11: // Direction (VarInt) case 11: // Direction (VarInt)
Value = ReadNextVarInt(cache); value = ReadNextVarInt(cache);
break; break;
case 12: // Optional UUID case 12: // Optional UUID
if (ReadNextBool(cache)) if (ReadNextBool(cache))
{ {
Value = ReadNextUUID(cache); value = ReadNextUUID(cache);
} }
break; break;
case 13: // Optional BlockID (VarInt) case 13: // Optional BlockID (VarInt)
if (ReadNextBool(cache)) if (ReadNextBool(cache))
{ {
Value = ReadNextVarInt(cache); value = ReadNextVarInt(cache);
} }
break; break;
case 14: // NBT case 14: // NBT
Value = ReadNextNbt(cache); value = ReadNextNbt(cache);
break; break;
case 15: // Particle case 15: // Particle
// Currecutly not handled. Reading data only // 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)); d.Add(ReadNextVarInt(cache));
d.Add(ReadNextVarInt(cache)); d.Add(ReadNextVarInt(cache));
Value = d; value = d;
break; break;
case 17: // Optional VarInt case 17: // Optional VarInt
if (ReadNextBool(cache)) if (ReadNextBool(cache))
{ {
Value = ReadNextVarInt(cache); value = ReadNextVarInt(cache);
} }
break; break;
case 18: // Pose case 18: // Pose
Value = ReadNextVarInt(cache); value = ReadNextVarInt(cache);
break; break;
default: 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); data[key] = value;
Key = ReadNextByte(cache); key = ReadNextByte(cache);
} }
return data; return data;
} }