Implemented 1.20.2 fully, needs more testing

This commit is contained in:
Anon 2023-11-17 18:21:57 +01:00
parent 4f957cee7e
commit 93112d2c02
3 changed files with 2662 additions and 2532 deletions

View file

@ -786,7 +786,7 @@ namespace MinecraftClient.ChatBots
{
var playerInventory = GetPlayerInventory();
if (playerInventory.Items.TryGetValue(GetCurrentSlot() - 36, out Item value) && value.Type == itemType)
if (playerInventory.Items.TryGetValue(GetCurrentSlot() - 36, out var value) && value.Type == itemType)
return true; // Already selected
// Search the full inventory

View file

@ -521,7 +521,8 @@ namespace MinecraftClient.Protocol.Handlers
// Data
data = protocolversion >= Protocol18Handler.MC_1_19_Version
? ReadNextVarInt(cache) : ReadNextInt(cache);
? ReadNextVarInt(cache)
: ReadNextInt(cache);
}
// In 1.8 those 3 fields for Velocity are optional
@ -541,7 +542,8 @@ namespace MinecraftClient.Protocol.Handlers
ReadNextShort(cache);
}
return new Entity(entityID, entityType, new Location(entityX, entityY, entityZ), entityYaw, entityPitch, data);
return new Entity(entityID, entityType, new Location(entityX, entityY, entityZ), entityYaw, entityPitch,
data);
}
/// <summary>
@ -563,12 +565,15 @@ namespace MinecraftClient.Protocol.Handlers
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
ReadNextByte(cache); // Tag type (TAG_Compound)
if (protocolversion < Protocol18Handler.MC_1_20_2_Version)
{
// NBT root name
string rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache));
var rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache));
if (!String.IsNullOrEmpty(rootName))
if (!string.IsNullOrEmpty(rootName))
nbtData[""] = rootName;
}
}
while (true)
{
@ -646,7 +651,8 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
/// <exception cref="System.IO.InvalidDataException"></exception>
public Dictionary<int, object?> ReadNextMetadata(Queue<byte> cache, ItemPalette itemPalette, EntityMetadataPalette metadataPalette)
public Dictionary<int, object?> ReadNextMetadata(Queue<byte> cache, ItemPalette itemPalette,
EntityMetadataPalette metadataPalette)
{
Dictionary<int, object?> data = new();
byte key = ReadNextByte(cache);
@ -668,7 +674,8 @@ namespace MinecraftClient.Protocol.Handlers
}
catch (KeyNotFoundException)
{
throw new System.IO.InvalidDataException("Unknown Metadata Type ID " + typeId + ". Is this up to date for new MC Version?");
throw new System.IO.InvalidDataException("Unknown Metadata Type ID " + typeId +
". Is this up to date for new MC Version?");
}
if (protocolversion <= Protocol18Handler.MC_1_8_Version)
@ -737,6 +744,7 @@ namespace MinecraftClient.Protocol.Handlers
{
value = ReadNextLocation(cache);
}
break;
case EntityMetaDataType.Direction: // Direction (VarInt)
value = ReadNextVarInt(cache);
@ -746,6 +754,7 @@ namespace MinecraftClient.Protocol.Handlers
{
value = ReadNextUUID(cache);
}
break;
case EntityMetaDataType.BlockId: // BlockID (VarInt)
value = ReadNextVarInt(cache);
@ -773,6 +782,7 @@ namespace MinecraftClient.Protocol.Handlers
{
value = ReadNextVarInt(cache);
}
break;
case EntityMetaDataType.Pose: // Pose
value = ReadNextVarInt(cache);
@ -795,6 +805,7 @@ namespace MinecraftClient.Protocol.Handlers
// Dimension and blockPos, currently not in use
value = new Tuple<string, Location>(ReadNextString(cache), ReadNextLocation(cache));
}
break;
case EntityMetaDataType.PaintingVariant: // Painting Variant
value = ReadNextVarInt(cache);
@ -824,6 +835,7 @@ namespace MinecraftClient.Protocol.Handlers
data[key] = value;
key = ReadNextByte(cache);
}
return data;
}
@ -856,7 +868,8 @@ namespace MinecraftClient.Protocol.Handlers
case 3:
if (protocolversion < Protocol18Handler.MC_1_17_Version
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt(cache); // Block State (minecraft:block before 1.18, minecraft:block_marker after 1.18)
ReadNextVarInt(
cache); // Block State (minecraft:block before 1.18, minecraft:block_marker after 1.18)
break;
case 4:
if (protocolversion == Protocol18Handler.MC_1_17_Version
@ -870,31 +883,37 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 14:
// 1.15 - 1.16.5 and 1.18 - 1.19.4
if ((protocolversion >= Protocol18Handler.MC_1_15_Version && protocolversion < Protocol18Handler.MC_1_17_Version)
if ((protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
break;
case 15:
if (protocolversion == Protocol18Handler.MC_1_17_Version || protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
else
{
if (protocolversion > Protocol18Handler.MC_1_17_1_Version)
ReadDustParticleColorTransition(cache);
}
break;
case 16:
if (protocolversion == Protocol18Handler.MC_1_17_Version || protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
ReadDustParticleColorTransition(cache);
break;
case 23:
// 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version && protocolversion < Protocol18Handler.MC_1_17_Version)
if (protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 24:
// 1.18 - 1.19.2 onwards
if (protocolversion > Protocol18Handler.MC_1_17_1_Version && protocolversion < Protocol18Handler.MC_1_19_3_Version)
if (protocolversion > Protocol18Handler.MC_1_17_1_Version &&
protocolversion < Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 25:
@ -915,22 +934,26 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 32:
// 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version && protocolversion < Protocol18Handler.MC_1_17_Version)
if (protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
case 36:
// 1.17 - 1.17.1
if (protocolversion == Protocol18Handler.MC_1_17_Version || protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
{
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
}
else if (protocolversion > Protocol18Handler.MC_1_17_1_Version && protocolversion < Protocol18Handler.MC_1_19_3_Version)
else if (protocolversion > Protocol18Handler.MC_1_17_1_Version &&
protocolversion < Protocol18Handler.MC_1_19_3_Version)
{
// minecraft:vibration
ReadNextLocation(cache); // Origin (Starting Position)
ReadNextLocation(cache); // Desitination (Ending Position)
ReadNextVarInt(cache); // Ticks
}
break;
case 37:
// minecraft:vibration
@ -945,6 +968,7 @@ namespace MinecraftClient.Protocol.Handlers
ReadNextDouble(cache); // Destination Z
ReadNextInt(cache); // Ticks
}
break;
case 39:
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version)
@ -966,6 +990,7 @@ namespace MinecraftClient.Protocol.Handlers
ReadNextVarInt(cache);
}
break;
}
}
@ -1186,7 +1211,8 @@ namespace MinecraftClient.Protocol.Handlers
}
else
{
throw new System.IO.InvalidDataException("GetNbt: Cannot encode data type " + obj.GetType().Name + " into NBT!");
throw new System.IO.InvalidDataException("GetNbt: Cannot encode data type " + obj.GetType().Name +
" into NBT!");
}
}

File diff suppressed because it is too large Load diff