Fully Implemented 1.20

This commit is contained in:
Anon 2023-06-08 19:27:28 +02:00
parent b21f40593e
commit ae7ce35cc8
14 changed files with 3313 additions and 209 deletions

View file

@ -111,11 +111,11 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
{ 0x66, PacketTypesIn.NBTQueryResponse }, // (Wiki name: Tab Query)
{ 0x67, PacketTypesIn.CollectItem }, // (Wiki name: Take Item Entity)
{ 0x68, PacketTypesIn.EntityTeleport }, // (Wiki name: Teleport Entity)
{ 0x69, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements)
{ 0x69, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements) (Unused)
{ 0x6A, PacketTypesIn.EntityProperties }, // (Wiki name: Update Attributes)
{ 0x6B, PacketTypesIn.FeatureFlags }, // Added in 1.19.3 (Not yet clear what is the purpose of this packet)
{ 0x6C, PacketTypesIn.EntityEffect }, // Changed in 1.19 (Added "Has Factor Data" and "Factor Codec" fields) (Wiki name: Entity Effect)
{ 0x6D, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes)
{ 0x6D, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes) (Unused)
{ 0x6E, PacketTypesIn.Tags }, // (Wiki name: Update Tags)
};

View file

@ -46,40 +46,26 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns></returns>
public PacketTypePalette GetTypeHandler(int protocol)
{
PacketTypePalette p;
if (protocol > Protocol18Handler.MC_1_19_4_Version)
throw new NotImplementedException(Translations.exception_palette_packet);
if (protocol <= Protocol18Handler.MC_1_8_Version)
p = new PacketPalette17();
else if (protocol <= Protocol18Handler.MC_1_11_2_Version)
p = new PacketPalette110();
else if (protocol <= Protocol18Handler.MC_1_12_Version)
p = new PacketPalette112();
else if (protocol <= Protocol18Handler.MC_1_12_2_Version)
p = new PacketPalette1122();
else if (protocol < Protocol18Handler.MC_1_14_Version)
p = new PacketPalette113();
else if (protocol < Protocol18Handler.MC_1_15_Version)
p = new PacketPalette114();
else if (protocol <= Protocol18Handler.MC_1_15_2_Version)
p = new PacketPalette115();
else if (protocol <= Protocol18Handler.MC_1_16_1_Version)
p = new PacketPalette116();
else if (protocol <= Protocol18Handler.MC_1_16_5_Version)
p = new PacketPalette1162();
else if (protocol <= Protocol18Handler.MC_1_17_1_Version)
p = new PacketPalette117();
else if (protocol <= Protocol18Handler.MC_1_18_2_Version)
p = new PacketPalette118();
else if (protocol <= Protocol18Handler.MC_1_19_Version)
p = new PacketPalette119();
else if (protocol <= Protocol18Handler.MC_1_19_2_Version)
p = new PacketPalette1192();
else if (protocol <= Protocol18Handler.MC_1_19_3_Version)
p = new PacketPalette1193();
else
p = new PacketPalette1194();
PacketTypePalette p = protocol switch
{
> Protocol18Handler.MC_1_20_Version => throw new NotImplementedException(Translations
.exception_palette_packet),
<= Protocol18Handler.MC_1_8_Version => new PacketPalette17(),
<= Protocol18Handler.MC_1_11_2_Version => new PacketPalette110(),
<= Protocol18Handler.MC_1_12_Version => new PacketPalette112(),
<= Protocol18Handler.MC_1_12_2_Version => new PacketPalette1122(),
< Protocol18Handler.MC_1_14_Version => new PacketPalette113(),
< Protocol18Handler.MC_1_15_Version => new PacketPalette114(),
<= Protocol18Handler.MC_1_15_2_Version => new PacketPalette115(),
<= Protocol18Handler.MC_1_16_1_Version => new PacketPalette116(),
<= Protocol18Handler.MC_1_16_5_Version => new PacketPalette1162(),
<= Protocol18Handler.MC_1_17_1_Version => new PacketPalette117(),
<= Protocol18Handler.MC_1_18_2_Version => new PacketPalette118(),
<= Protocol18Handler.MC_1_19_Version => new PacketPalette119(),
<= Protocol18Handler.MC_1_19_2_Version => new PacketPalette1192(),
<= Protocol18Handler.MC_1_19_3_Version => new PacketPalette1193(),
_ => new PacketPalette1194()
};
p.SetForgeEnabled(forgeEnabled);
return p;

View file

@ -711,7 +711,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (SocketException) { return false; }
}
public bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4)
public bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4, bool isFrontText = true)
{
return false; //Currently not implemented
}

View file

@ -66,6 +66,7 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC_1_19_2_Version = 760;
internal const int MC_1_19_3_Version = 761;
internal const int MC_1_19_4_Version = 762;
internal const int MC_1_20_Version = 763;
private int compression_treshold = 0;
private int autocomplete_transaction_id = 0;
@ -113,97 +114,79 @@ namespace MinecraftClient.Protocol.Handlers
randomGen = RandomNumberGenerator.Create();
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_19_4_Version)
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_Version)
{
log.Error("§c" + Translations.extra_terrainandmovement_disabled);
handler.SetTerrainEnabled(false);
}
if (handler.GetInventoryEnabled() &&
(protocolVersion < MC_1_9_Version || protocolVersion > MC_1_19_4_Version))
protocolVersion is < MC_1_9_Version or > MC_1_20_Version)
{
log.Error("§c" + Translations.extra_inventory_disabled);
handler.SetInventoryEnabled(false);
}
if (handler.GetEntityHandlingEnabled() &&
(protocolVersion < MC_1_8_Version || protocolVersion > MC_1_19_4_Version))
protocolVersion is < MC_1_8_Version or > MC_1_20_Version)
{
log.Error("§c" + Translations.extra_entity_disabled);
handler.SetEntityHandlingEnabled(false);
}
// Block palette
if (protocolVersion > MC_1_19_4_Version && handler.GetTerrainEnabled())
throw new NotImplementedException(Translations.exception_palette_block);
Block.Palette = protocolVersion switch
{
// Block palette
> MC_1_20_Version when handler.GetTerrainEnabled() =>
throw new NotImplementedException(Translations.exception_palette_block),
MC_1_20_Version => new Palette120(),
MC_1_19_4_Version => new Palette1194(),
MC_1_19_3_Version => new Palette1193(),
>= MC_1_19_Version => new Palette119(),
>= MC_1_17_Version => new Palette117(),
>= MC_1_16_Version => new Palette116(),
>= MC_1_15_Version => new Palette115(),
>= MC_1_14_Version => new Palette114(),
>= MC_1_13_Version => new Palette113(),
_ => new Palette112()
};
if (protocolVersion >= MC_1_19_4_Version)
Block.Palette = new Palette1194();
else if (protocolVersion >= MC_1_19_3_Version)
Block.Palette = new Palette1193();
else if (protocolVersion >= MC_1_19_Version)
Block.Palette = new Palette119();
else if (protocolVersion >= MC_1_17_Version)
Block.Palette = new Palette117();
else if (protocolVersion >= MC_1_16_Version)
Block.Palette = new Palette116();
else if (protocolVersion >= MC_1_15_Version)
Block.Palette = new Palette115();
else if (protocolVersion >= MC_1_14_Version)
Block.Palette = new Palette114();
else if (protocolVersion >= MC_1_13_Version)
Block.Palette = new Palette113();
else
Block.Palette = new Palette112();
// Entity palette
if (protocolVersion > MC_1_19_4_Version && handler.GetEntityHandlingEnabled())
throw new NotImplementedException(Translations.exception_palette_entity);
if (protocolVersion >= MC_1_19_4_Version)
entityPalette = new EntityPalette1194();
else if (protocolVersion >= MC_1_19_3_Version)
entityPalette = new EntityPalette1193();
else if (protocolVersion >= MC_1_19_Version)
entityPalette = new EntityPalette119();
else if (protocolVersion >= MC_1_17_Version)
entityPalette = new EntityPalette117();
else if (protocolVersion >= MC_1_16_2_Version)
entityPalette = new EntityPalette1162();
else if (protocolVersion >= MC_1_16_Version)
entityPalette = new EntityPalette1161();
else if (protocolVersion >= MC_1_15_Version)
entityPalette = new EntityPalette115();
else if (protocolVersion >= MC_1_14_Version)
entityPalette = new EntityPalette114();
else if (protocolVersion >= MC_1_13_Version)
entityPalette = new EntityPalette113();
else if (protocolVersion >= MC_1_12_Version)
entityPalette = new EntityPalette112();
else entityPalette = new EntityPalette18();
entityPalette = protocolVersion switch
{
// Entity palette
> MC_1_20_Version when handler.GetEntityHandlingEnabled() =>
throw new NotImplementedException(Translations.exception_palette_entity),
MC_1_20_Version => new EntityPalette120(),
MC_1_19_4_Version => new EntityPalette1194(),
MC_1_19_3_Version => new EntityPalette1193(),
>= MC_1_19_Version => new EntityPalette119(),
>= MC_1_17_Version => new EntityPalette117(),
>= MC_1_16_2_Version => new EntityPalette1162(),
>= MC_1_16_Version => new EntityPalette1161(),
>= MC_1_15_Version => new EntityPalette115(),
>= MC_1_14_Version => new EntityPalette114(),
>= MC_1_13_Version => new EntityPalette113(),
>= MC_1_12_Version => new EntityPalette112(),
_ => new EntityPalette18()
};
entityMetadataPalette = EntityMetadataPalette.GetPalette(protocolVersion);
// Item palette
if (protocolVersion > MC_1_19_4_Version && handler.GetInventoryEnabled())
throw new NotImplementedException(Translations.exception_palette_item);
if (protocolVersion >= MC_1_19_4_Version)
itemPalette = new ItemPalette1194();
else if (protocolVersion >= MC_1_19_3_Version)
itemPalette = new ItemPalette1193();
else if (protocolVersion >= MC_1_19_Version)
itemPalette = new ItemPalette119();
else if (protocolVersion >= MC_1_18_1_Version)
itemPalette = new ItemPalette118();
else if (protocolVersion >= MC_1_17_Version)
itemPalette = new ItemPalette117();
else if (protocolVersion >= MC_1_16_2_Version)
itemPalette = new ItemPalette1162();
else if (protocolVersion >= MC_1_16_1_Version)
itemPalette = new ItemPalette1161();
else
itemPalette = new ItemPalette115();
itemPalette = protocolVersion switch
{
// Item palette
> MC_1_20_Version when handler.GetInventoryEnabled() =>
throw new NotImplementedException(Translations.exception_palette_item),
MC_1_20_Version => new ItemPalette120(),
MC_1_19_4_Version => new ItemPalette1194(),
MC_1_19_3_Version => new ItemPalette1193(),
>= MC_1_19_Version => new ItemPalette119(),
>= MC_1_18_1_Version => new ItemPalette118(),
>= MC_1_17_Version => new ItemPalette117(),
>= MC_1_16_2_Version => new ItemPalette1162(),
>= MC_1_16_1_Version => new ItemPalette1161(),
_ => new ItemPalette115()
};
// MessageType
// You can find it in https://wiki.vg/Protocol#Player_Chat_Message or /net/minecraft/network/message/MessageType.java
@ -522,7 +505,10 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.ReadNextLocation(packetData); // Death location
}
}
if (protocolVersion >= MC_1_20_Version)
dataTypes.ReadNextVarInt(packetData); // Portal Cooldown - 1.20 and above
break;
case PacketTypesIn.SpawnPainting: // Just skip, no need for this
return true;
@ -880,7 +866,7 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.SkipNextVarInt(packetData);
handler.OnPlayerKilled(
dataTypes.ReadNextInt(packetData),
protocolVersion >= MC_1_20_Version ? -1 : dataTypes.ReadNextInt(packetData),
ChatParser.ParseText(dataTypes.ReadNextString(packetData))
);
@ -1009,6 +995,9 @@ namespace MinecraftClient.Protocol.Handlers
}
}
if (protocolVersion >= MC_1_20_Version)
dataTypes.ReadNextVarInt(packetData); // Portal Cooldown
handler.OnRespawn();
break;
case PacketTypesIn.PlayerPositionAndLook:
@ -1103,6 +1092,7 @@ namespace MinecraftClient.Protocol.Handlers
Interlocked.Decrement(ref handler.GetWorld().chunkLoadNotCompleted);
// Block Entity data: ignored
// Trust edges: ignored (Removed in 1.20)
// Light data: ignored
}
else
@ -1359,7 +1349,10 @@ namespace MinecraftClient.Protocol.Handlers
int sectionX = (int)(chunkSection >> 42);
int sectionY = (int)((chunkSection << 44) >> 44);
int sectionZ = (int)((chunkSection << 22) >> 42);
dataTypes.ReadNextBool(packetData); // Useless boolean (Related to light update)
if(protocolVersion < MC_1_20_Version)
dataTypes.ReadNextBool(packetData); // Useless boolean (Related to light update)
int blocksSize = dataTypes.ReadNextVarInt(packetData);
for (int i = 0; i < blocksSize; i++)
{
@ -2188,22 +2181,23 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.ReadNextMetadata(packetData, itemPalette, entityMetadataPalette);
// Also make a palette for field? Will be a lot of work
int healthField; // See https://wiki.vg/Entity_metadata#Living_Entity
if (protocolVersion > MC_1_19_4_Version)
throw new NotImplementedException(Translations.exception_palette_healthfield);
else if (protocolVersion >= MC_1_17_Version) // 1.17 and above
healthField = 9;
else if (protocolVersion >= MC_1_14_Version) // 1.14 and above
healthField = 8;
else if (protocolVersion >= MC_1_10_Version) // 1.10 and above
healthField = 7;
else if (protocolVersion >= MC_1_8_Version) // 1.8 and above
healthField = 6;
else
throw new NotImplementedException(Translations.exception_palette_healthfield);
int healthField = protocolVersion switch
{
> MC_1_20_Version => throw new NotImplementedException(Translations
.exception_palette_healthfield),
// 1.17 and above
>= MC_1_17_Version => 9,
// 1.14 and above
>= MC_1_14_Version => 8,
// 1.10 and above
>= MC_1_10_Version => 7,
// 1.8 and above
>= MC_1_8_Version => 6,
_ => throw new NotImplementedException(Translations.exception_palette_healthfield)
};
if (metadata.TryGetValue(healthField, out object? healthObj) && healthObj != null &&
healthObj.GetType() == typeof(float))
if (metadata.TryGetValue(healthField, out var healthObj) && healthObj != null &&
healthObj is float)
handler.OnEntityHealth(EntityID, (float)healthObj);
handler.OnEntityMetadata(EntityID, metadata);
@ -2343,6 +2337,17 @@ namespace MinecraftClient.Protocol.Handlers
}
break;
case PacketTypesIn.OpenSignEditor:
var signLocation = dataTypes.ReadNextLocation(packetData);
var isFrontText = true;
if (protocolVersion >= MC_1_20_Version)
isFrontText = dataTypes.ReadNextBool(packetData);
// TODO: Use
break;
default:
return false; //Ignored packet
}
@ -3950,7 +3955,7 @@ namespace MinecraftClient.Protocol.Handlers
}
}
public bool SendUpdateSign(Location sign, string line1, string line2, string line3, string line4)
public bool SendUpdateSign(Location sign, string line1, string line2, string line3, string line4, bool isFrontText = true)
{
try
{
@ -3965,6 +3970,8 @@ namespace MinecraftClient.Protocol.Handlers
List<byte> packet = new();
packet.AddRange(dataTypes.GetLocation(sign));
if(protocolVersion >= MC_1_20_Version)
packet.AddRange(dataTypes.GetBool((isFrontText)));
packet.AddRange(dataTypes.GetString(line1));
packet.AddRange(dataTypes.GetString(line2));
packet.AddRange(dataTypes.GetString(line3));

View file

@ -220,7 +220,7 @@ namespace MinecraftClient.Protocol
/// <param name="location">Location</param>
/// <param name="face">Block face</param>
/// <param name="sequenceId">Sequence ID (use for synchronization)</param>
/// <returns>True if packet was succcessfully sent</returns>
/// <returns>True if packet was successfully sent</returns>
bool SendPlayerDigging(int status, Location location, Direction face, int sequenceId);
/// <summary>
@ -231,8 +231,9 @@ namespace MinecraftClient.Protocol
/// <param name="line2">New line 2</param>
/// <param name="line3">New line 3</param>
/// <param name="line4">New line 4</param>
/// <returns>True if packet was succcessfully sent</returns>
bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4);
/// <param name="isFrontText">Are we editing the front or the back of the sign. 1.20 +</param>
/// <returns>True if packet was successfully sent</returns>
bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4, bool isFrontText = true);
/// <summary>
/// Update command block

View file

@ -134,7 +134,7 @@ namespace MinecraftClient.Protocol
if (Array.IndexOf(supportedVersions_Protocol16, ProtocolVersion) > -1)
return new Protocol16Handler(Client, ProtocolVersion, Handler);
int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762 };
int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763 };
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1)
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo);
@ -317,6 +317,8 @@ namespace MinecraftClient.Protocol
return 761;
case "1.19.4":
return 762;
case "1.20":
return 763;
default:
return 0;
}
@ -325,7 +327,7 @@ namespace MinecraftClient.Protocol
{
try
{
return Int32.Parse(MCVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
return int.Parse(MCVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
}
catch
{
@ -342,61 +344,62 @@ namespace MinecraftClient.Protocol
/// <returns>The 1.X.X version number, or 0.0 if could not determine protocol version</returns>
public static string ProtocolVersion2MCVer(int protocol)
{
switch (protocol)
return protocol switch
{
case 22: return "1.0";
case 23: return "1.1";
case 28: return "1.2.3";
case 29: return "1.2.5";
case 39: return "1.3.2";
22 => "1.0",
23 => "1.1",
28 => "1.2.3",
29 => "1.2.5",
39 => "1.3.2",
// case 47: return "1.4.2";
case 48: return "1.4.3";
case 49: return "1.4.5";
case 51: return "1.4.6";
case 60: return "1.5.1";
case 62: return "1.5.2";
case 72: return "1.6";
case 73: return "1.6.1";
case 3: return "1.7.1";
case 4: return "1.7.2";
case 5: return "1.7.6";
case 47: return "1.8";
case 107: return "1.9";
case 108: return "1.9.1";
case 109: return "1.9.2";
case 110: return "1.9.3";
case 210: return "1.10";
case 315: return "1.11";
case 316: return "1.11.1";
case 335: return "1.12";
case 338: return "1.12.1";
case 340: return "1.12.2";
case 393: return "1.13";
case 401: return "1.13.1";
case 404: return "1.13.2";
case 477: return "1.14";
case 480: return "1.14.1";
case 485: return "1.14.2";
case 490: return "1.14.3";
case 498: return "1.14.4";
case 573: return "1.15";
case 575: return "1.15.1";
case 578: return "1.15.2";
case 735: return "1.16";
case 736: return "1.16.1";
case 751: return "1.16.2";
case 753: return "1.16.3";
case 754: return "1.16.5";
case 755: return "1.17";
case 756: return "1.17.1";
case 757: return "1.18.1";
case 758: return "1.18.2";
case 759: return "1.19";
case 760: return "1.19.2";
case 761: return "1.19.3";
case 762: return "1.19.4";
default: return "0.0";
}
48 => "1.4.3",
49 => "1.4.5",
51 => "1.4.6",
60 => "1.5.1",
62 => "1.5.2",
72 => "1.6",
73 => "1.6.1",
3 => "1.7.1",
4 => "1.7.2",
5 => "1.7.6",
47 => "1.8",
107 => "1.9",
108 => "1.9.1",
109 => "1.9.2",
110 => "1.9.3",
210 => "1.10",
315 => "1.11",
316 => "1.11.1",
335 => "1.12",
338 => "1.12.1",
340 => "1.12.2",
393 => "1.13",
401 => "1.13.1",
404 => "1.13.2",
477 => "1.14",
480 => "1.14.1",
485 => "1.14.2",
490 => "1.14.3",
498 => "1.14.4",
573 => "1.15",
575 => "1.15.1",
578 => "1.15.2",
735 => "1.16",
736 => "1.16.1",
751 => "1.16.2",
753 => "1.16.3",
754 => "1.16.5",
755 => "1.17",
756 => "1.17.1",
757 => "1.18.1",
758 => "1.18.2",
759 => "1.19",
760 => "1.19.2",
761 => "1.19.3",
762 => "1.19.4",
763 => "1.20",
_ => "0.0"
};
}
/// <summary>