Added 1.16(.1) support (#1091)

*  Added 1.16(.1) support

* ♻️ Whoopsy..

* ♻️ Undo Terrain Handling update

* Revert "♻️ Undo Terrain Handling update"

This reverts commit eb891cc91f.

* Revert "Revert "♻️ Undo Terrain Handling update""

This reverts commit 2d2b1e95cb.

* Join Game and Respawn encoding/decoding & added ReadNextVarIntArray

* Remove VarIntArray because I cannot read wiki's correctly xD

* Attempt to fix indentation level

* Fix indentation level, 2

* Fix indentation level, 3

* Fix indentation level, 4

* Fix compilation errors

* Fix check

Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
This commit is contained in:
ORelio 2020-06-29 22:35:31 +02:00 committed by GitHub
commit 9568aef0c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 137 additions and 11 deletions

View file

@ -32,7 +32,7 @@ namespace MinecraftClient
public const string Version = MCHighestVersion;
public const string MCLowestVersion = "1.4.6";
public const string MCHighestVersion = "1.15.2";
public const string MCHighestVersion = "1.16.1";
public static readonly string BuildInfo = null;
private static Thread offlinePrompt = null;

View file

@ -38,6 +38,8 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC114Version = 477;
internal const int MC115Version = 573;
internal const int MC1152Version = 578;
internal const int MC116Version = 735;
internal const int MC1161Version = 736;
private int compression_treshold = 0;
private bool autocomplete_received = false;
@ -218,22 +220,51 @@ namespace MinecraftClient.Protocol.Handlers
int playerEntityID = dataTypes.ReadNextInt(packetData);
handler.OnReceivePlayerEntityID(playerEntityID);
handler.OnGamemodeUpdate(Guid.Empty, dataTypes.ReadNextByte(packetData));
if (protocolversion >= MC191Version)
if (protocolversion >= MC116Version)
{
dataTypes.ReadNextByte(packetData); // Previous Gamemode - 1.16 and above
int worldCount = dataTypes.ReadNextVarInt(packetData); // World Count - 1.16 and above
for (int i = 0; i < worldCount; i++)
dataTypes.ReadNextString(packetData); // World Names - 1.16 and above
dataTypes.ReadNextNbt(packetData); // Dimension Codec - 1.16 and above
}
//Current dimension - String identifier in 1.16, varInt below 1.16, byte below 1.9.1
if (protocolversion >= MC116Version)
{
// TODO handle dimensions for 1.16+, needed for terrain handling
dataTypes.ReadNextString(packetData);
this.currentDimension = 0;
}
else if (protocolversion >= MC191Version)
this.currentDimension = dataTypes.ReadNextInt(packetData);
else
this.currentDimension = (sbyte)dataTypes.ReadNextByte(packetData);
if (protocolversion < MC114Version)
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
if (protocolversion >= MC116Version)
dataTypes.ReadNextString(packetData); // World Name - 1.16 and above
if (protocolversion >= MC115Version)
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
dataTypes.ReadNextByte(packetData);
dataTypes.ReadNextString(packetData);
dataTypes.ReadNextByte(packetData); // Max Players
if (protocolversion < MC116Version)
dataTypes.ReadNextString(packetData); // Level Type - 1.15 and below
if (protocolversion >= MC114Version)
dataTypes.ReadNextVarInt(packetData); // View distance - 1.14 and above
if (protocolversion >= MC18Version)
dataTypes.ReadNextBool(packetData); // Reduced debug info - 1.8 and above
if (protocolversion >= MC115Version)
dataTypes.ReadNextBool(packetData); // Enable respawn screen - 1.15 and above
if (protocolversion >= MC116Version)
{
dataTypes.ReadNextBool(packetData); // Is Debug - 1.16 and above
dataTypes.ReadNextBool(packetData); // Is Flat - 1.16 and above
}
break;
case PacketIncomingType.ChatMessage:
string message = dataTypes.ReadNextString(packetData);
@ -249,13 +280,34 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnTextReceived(message, true);
break;
case PacketIncomingType.Respawn:
this.currentDimension = dataTypes.ReadNextInt(packetData);
if (protocolversion >= MC116Version)
{
// TODO handle dimensions for 1.16+, needed for terrain handling
dataTypes.ReadNextString(packetData);
this.currentDimension = 0;
}
else
{
// 1.15 and below
this.currentDimension = dataTypes.ReadNextInt(packetData);
}
if (protocolversion >= MC116Version)
dataTypes.ReadNextString(packetData); // World Name - 1.16 and above
if (protocolversion < MC114Version)
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
if (protocolversion >= MC115Version)
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
dataTypes.ReadNextByte(packetData);
dataTypes.ReadNextString(packetData);
dataTypes.ReadNextByte(packetData); // Gamemode
if (protocolversion >= MC116Version)
dataTypes.ReadNextByte(packetData); // Previous Game mode - 1.16 and above
if (protocolversion < MC116Version)
dataTypes.ReadNextString(packetData); // Level Type - 1.15 and below
if (protocolversion >= MC116Version)
{
dataTypes.ReadNextBool(packetData); // Is Debug - 1.16 and above
dataTypes.ReadNextBool(packetData); // Is Flat - 1.16 and above
dataTypes.ReadNextBool(packetData); // Copy metadata - 1.16 and above
}
handler.OnRespawn();
break;
case PacketIncomingType.PlayerPositionAndLook:
@ -1389,7 +1441,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendPlayerDigging(int status, Location location, Direction face)
{
try

View file

@ -288,7 +288,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4F: return PacketIncomingType.Title;
}
}
else // MC 1.15
else if (protocol <= Protocol18Handler.MC1152Version) // MC 1.15 to 1.15.2
{
switch (packetID)
{
@ -331,6 +331,48 @@ namespace MinecraftClient.Protocol.Handlers
case 0x27: return PacketIncomingType.MapData;
case 0x50: return PacketIncomingType.Title;
}
} else {
switch (packetID)
{
case 0x20: return PacketIncomingType.KeepAlive;
case 0x25: return PacketIncomingType.JoinGame;
case 0x0E: return PacketIncomingType.ChatMessage;
case 0x3A: return PacketIncomingType.Respawn;
case 0x35: return PacketIncomingType.PlayerPositionAndLook;
case 0x21: return PacketIncomingType.ChunkData;
case 0x0F: return PacketIncomingType.MultiBlockChange;
case 0x0B: return PacketIncomingType.BlockChange;
// MapChunkBulk does not exist since 1.9
case 0x1D: return PacketIncomingType.UnloadChunk;
case 0x33: return PacketIncomingType.PlayerListUpdate;
case 0x10: return PacketIncomingType.TabCompleteResult;
case 0x18: return PacketIncomingType.PluginMessage;
case 0x1A: return PacketIncomingType.KickPacket;
// NetworkCompressionTreshold does not exist since 1.9
case 0x39: return PacketIncomingType.ResourcePackSend;
case 0x13: return PacketIncomingType.CloseWindow;
case 0x2E: return PacketIncomingType.OpenWindow;
case 0x14: return PacketIncomingType.WindowItems;
case 0x16: return PacketIncomingType.SetSlot;
case 0x00: return PacketIncomingType.SpawnEntity;
case 0x02: return PacketIncomingType.SpawnLivingEntity;
case 0x04: return PacketIncomingType.SpawnPlayer;
case 0x37: return PacketIncomingType.DestroyEntities;
case 0x17: return PacketIncomingType.SetCooldown;
case 0x28: return PacketIncomingType.EntityPosition;
case 0x29: return PacketIncomingType.EntityPositionAndRotation;
case 0x58: return PacketIncomingType.EntityProperties;
case 0x56: return PacketIncomingType.EntityTeleport;
case 0x46: return PacketIncomingType.EntityVelocity;
case 0x47: return PacketIncomingType.EntityEquipment;
case 0x4E: return PacketIncomingType.TimeUpdate;
case 0x49: return PacketIncomingType.UpdateHealth;
case 0x48: return PacketIncomingType.SetExperience;
case 0x3F: return PacketIncomingType.HeldItemChange;
case 0x1C: return PacketIncomingType.Explosion;
case 0x26: return PacketIncomingType.MapData;
case 0x4F: return PacketIncomingType.Title;
}
}
return PacketIncomingType.UnknownPacket;
@ -485,7 +527,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x26;
}
}
else // MC 1.14 to 1.15
else if (protocol <= Protocol18Handler.MC1152Version) //MC 1.14 to 1.15.2
{
switch (packet)
{
@ -512,6 +554,33 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x29;
}
}
else
{
switch (packet)
{
case PacketOutgoingType.KeepAlive: return 0x10;
case PacketOutgoingType.ResourcePackStatus: return 0x20;
case PacketOutgoingType.ChatMessage: return 0x03;
case PacketOutgoingType.ClientStatus: return 0x04;
case PacketOutgoingType.ClientSettings: return 0x05;
case PacketOutgoingType.PluginMessage: return 0x0B;
case PacketOutgoingType.TabComplete: return 0x06;
case PacketOutgoingType.EntityAction: return 0x1C;
case PacketOutgoingType.PlayerPosition: return 0x12;
case PacketOutgoingType.PlayerPositionAndLook: return 0x13;
case PacketOutgoingType.TeleportConfirm: return 0x00;
case PacketOutgoingType.HeldItemChange: return 0x24;
case PacketOutgoingType.InteractEntity: return 0x0E;
case PacketOutgoingType.UseItem: return 0x2E;
case PacketOutgoingType.ClickWindow: return 0x09;
case PacketOutgoingType.CloseWindow: return 0x0A;
case PacketOutgoingType.PlayerBlockPlacement: return 0x2C;
case PacketOutgoingType.CreativeInventoryAction: return 0x27;
case PacketOutgoingType.Animation: return 0x2B;
case PacketOutgoingType.PlayerDigging: return 0x1B;
case PacketOutgoingType.UpdateSign: return 0x2A;
}
}
throw new System.ComponentModel.InvalidEnumArgumentException("Unknown PacketOutgoingType (protocol=" + protocol + ")", (int)packet, typeof(PacketOutgoingType));
}

View file

@ -116,7 +116,7 @@ namespace MinecraftClient.Protocol
int[] supportedVersions_Protocol16 = { 51, 60, 61, 72, 73, 74, 78 };
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};
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};
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1)
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo);
throw new NotSupportedException("The protocol version no." + ProtocolVersion + " is not supported.");
@ -223,6 +223,11 @@ namespace MinecraftClient.Protocol
return 575;
case "1.15.2":
return 578;
case "1.16":
case "1.16.0":
return 735;
case "1.16.1":
return 736;
default:
return 0;
}