update to newest version

This commit is contained in:
ReinforceZwei 2020-03-22 14:08:25 +08:00 committed by ORelio
parent 31dac18c85
commit fa51d9632d
3 changed files with 28 additions and 8 deletions

View file

@ -324,16 +324,18 @@ namespace MinecraftClient.Protocol.Handlers
/// </summary>
private Dictionary<string, object> ReadNextNbt(List<byte> cache, bool root)
{
Dictionary<string, object> NbtData = new Dictionary<string, object>();
if (root)
{
if (cache[0] == 0) // TAG_End
return NbtData;
if (cache[0] != 10) // TAG_Compound
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
ReadNextByte(cache); // Tag type (TAG_Compound)
ReadData(ReadNextUShort(cache), cache); // NBT root name
}
Dictionary<string, object> NbtData = new Dictionary<string, object>();
while (true)
{
int fieldType = ReadNextByte(cache);
@ -445,7 +447,7 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion < Protocol18Handler.MC18Version)
{
byte[] length = BitConverter.GetBytes((short)array.Length);
Array.Reverse(length);
Array.Reverse(length); //Endianness
return ConcatBytes(length, array);
}
else return ConcatBytes(GetVarInt(array.Length), array);
@ -464,7 +466,7 @@ namespace MinecraftClient.Protocol.Handlers
}
/// <summary>
/// Get a byte array representing the given location encoded as an unsigned short
/// Get a byte array representing the given location encoded as an unsigned long
/// </summary>
/// <remarks>
/// A modulo will be applied if the location is outside the following ranges:
@ -475,11 +477,14 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>Location representation as ulong</returns>
public byte[] GetLocation(Location location)
{
byte[] locationBytes;
if (protocolversion >= Protocol18Handler.MC114Version)
{
return BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Z) & 0x3FFFFFF) << 12) | (((ulong)location.Y) & 0xFFF));
locationBytes = BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Z) & 0x3FFFFFF) << 12) | (((ulong)location.Y) & 0xFFF));
}
else return BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Y) & 0xFFF) << 26) | (((ulong)location.Z) & 0x3FFFFFF));
else locationBytes = BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Y) & 0xFFF) << 26) | (((ulong)location.Z) & 0x3FFFFFF));
Array.Reverse(locationBytes); //Endianness
return locationBytes;
}
/// <summary>