diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/PacketMapper.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/PacketMapper.java new file mode 100644 index 0000000000..b3138e05d4 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/PacketMapper.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2018-2023 Velocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.velocitypowered.proxy.protocol; + +import com.velocitypowered.api.network.ProtocolVersion; +import org.jspecify.annotations.Nullable; + +interface PacketMapper { + default void readWrite(final int id, final ProtocolVersion from) { + this.readWrite(id, from, null); + } + + void readWrite(final int id, final ProtocolVersion from, final @Nullable ProtocolVersion to); + + default void writeOnly(final int id, final ProtocolVersion from) { + this.writeOnly(id, from, null); + } + + void writeOnly(final int id, final ProtocolVersion from, final @Nullable ProtocolVersion to); +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/PacketMapping.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/PacketMapping.java new file mode 100644 index 0000000000..9073c2f097 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/PacketMapping.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2018-2023 Velocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.velocitypowered.proxy.protocol; + +import com.velocitypowered.api.network.ProtocolVersion; +import org.jspecify.annotations.Nullable; + +/** + * Packet mapping. + */ +public record PacketMapping( + int id, + ProtocolVersion from, + @Nullable ProtocolVersion to, + boolean writeOnly +) { +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java index 41d444a36b..ddae837ada 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -36,7 +36,6 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_20_2; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_20_3; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_20_5; -import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_21; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_7_2; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9; @@ -53,8 +52,6 @@ import com.velocitypowered.proxy.protocol.packet.BossBarPacket; import com.velocitypowered.proxy.protocol.packet.BundleDelimiterPacket; import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket; -import com.velocitypowered.proxy.protocol.packet.ClientboundCookieRequestPacket; -import com.velocitypowered.proxy.protocol.packet.ClientboundStoreCookiePacket; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket; import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket; import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket; @@ -76,7 +73,6 @@ import com.velocitypowered.proxy.protocol.packet.ServerDataPacket; import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket; import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket; -import com.velocitypowered.proxy.protocol.packet.ServerboundCookieResponsePacket; import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket; import com.velocitypowered.proxy.protocol.packet.StatusPingPacket; import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket; @@ -95,8 +91,6 @@ import com.velocitypowered.proxy.protocol.packet.chat.session.SessionPlayerCommandPacket; import com.velocitypowered.proxy.protocol.packet.chat.session.UnsignedPlayerCommandPacket; import com.velocitypowered.proxy.protocol.packet.config.ActiveFeaturesPacket; -import com.velocitypowered.proxy.protocol.packet.config.ClientboundCustomReportDetailsPacket; -import com.velocitypowered.proxy.protocol.packet.config.ClientboundServerLinksPacket; import com.velocitypowered.proxy.protocol.packet.config.FinishedUpdatePacket; import com.velocitypowered.proxy.protocol.packet.config.KnownPacksPacket; import com.velocitypowered.proxy.protocol.packet.config.RegistrySyncPacket; @@ -108,16 +102,17 @@ import com.velocitypowered.proxy.protocol.packet.title.TitleSubtitlePacket; import com.velocitypowered.proxy.protocol.packet.title.TitleTextPacket; import com.velocitypowered.proxy.protocol.packet.title.TitleTimesPacket; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import java.util.ArrayList; import java.util.Collections; import java.util.EnumMap; import java.util.EnumSet; +import java.util.List; import java.util.Map; -import java.util.Objects; +import java.util.function.Consumer; import java.util.function.Supplier; import org.checkerframework.checker.nullness.qual.Nullable; @@ -128,111 +123,112 @@ public enum StateRegistry { HANDSHAKE { { - serverbound.register(HandshakePacket.class, HandshakePacket::new, - map(0x00, MINECRAFT_1_7_2, false)); + serverbound(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_7_2); + }); } }, STATUS { { - serverbound.register( - StatusRequestPacket.class, () -> StatusRequestPacket.INSTANCE, - map(0x00, MINECRAFT_1_7_2, false)); - serverbound.register(StatusPingPacket.class, StatusPingPacket::new, - map(0x01, MINECRAFT_1_7_2, false)); - - clientbound.register( - StatusResponsePacket.class, StatusResponsePacket::new, - map(0x00, MINECRAFT_1_7_2, false)); - clientbound.register(StatusPingPacket.class, StatusPingPacket::new, - map(0x01, MINECRAFT_1_7_2, false)); + serverbound(StatusRequestPacket.class, () -> StatusRequestPacket.INSTANCE, m -> { + m.readWrite(0x00, MINECRAFT_1_7_2); + }); + serverbound(StatusPingPacket.class, StatusPingPacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_7_2); + }); + + clientbound(StatusResponsePacket.class, StatusResponsePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_7_2); + }); + clientbound(StatusPingPacket.class, StatusPingPacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_7_2); + }); } }, CONFIG { { - serverbound.register( - ClientSettingsPacket.class, ClientSettingsPacket::new, - map(0x00, MINECRAFT_1_20_2, false)); - serverbound.register( - ServerboundCookieResponsePacket.class, ServerboundCookieResponsePacket::new, - map(0x01, MINECRAFT_1_20_5, false)); - serverbound.register( - PluginMessagePacket.class, PluginMessagePacket::new, - map(0x01, MINECRAFT_1_20_2, false), - map(0x02, MINECRAFT_1_20_5, false)); - serverbound.register( - FinishedUpdatePacket.class, () -> FinishedUpdatePacket.INSTANCE, - map(0x02, MINECRAFT_1_20_2, false), - map(0x03, MINECRAFT_1_20_5, false)); - serverbound.register(KeepAlivePacket.class, KeepAlivePacket::new, - map(0x03, MINECRAFT_1_20_2, false), - map(0x04, MINECRAFT_1_20_5, false)); - serverbound.register( - PingIdentifyPacket.class, PingIdentifyPacket::new, - map(0x04, MINECRAFT_1_20_2, false), - map(0x05, MINECRAFT_1_20_5, false)); - serverbound.register( - ResourcePackResponsePacket.class, - ResourcePackResponsePacket::new, - map(0x05, MINECRAFT_1_20_2, false), - map(0x06, MINECRAFT_1_20_5, false)); - serverbound.register( - KnownPacksPacket.class, - KnownPacksPacket::new, - map(0x07, MINECRAFT_1_20_5, false)); - - clientbound.register( - ClientboundCookieRequestPacket.class, ClientboundCookieRequestPacket::new, - map(0x00, MINECRAFT_1_20_5, false)); - clientbound.register( - PluginMessagePacket.class, PluginMessagePacket::new, - map(0x00, MINECRAFT_1_20_2, false), - map(0x01, MINECRAFT_1_20_5, false)); - clientbound.register( - DisconnectPacket.class, () -> new DisconnectPacket(this), - map(0x01, MINECRAFT_1_20_2, false), - map(0x02, MINECRAFT_1_20_5, false)); - clientbound.register( - FinishedUpdatePacket.class, () -> FinishedUpdatePacket.INSTANCE, - map(0x02, MINECRAFT_1_20_2, false), - map(0x03, MINECRAFT_1_20_5, false)); - clientbound.register(KeepAlivePacket.class, KeepAlivePacket::new, - map(0x03, MINECRAFT_1_20_2, false), - map(0x04, MINECRAFT_1_20_5, false)); - clientbound.register( - PingIdentifyPacket.class, PingIdentifyPacket::new, - map(0x04, MINECRAFT_1_20_2, false), - map(0x05, MINECRAFT_1_20_5, false)); - clientbound.register( - RegistrySyncPacket.class, RegistrySyncPacket::new, - map(0x05, MINECRAFT_1_20_2, false), - map(0x07, MINECRAFT_1_20_5, false)); - clientbound.register( - RemoveResourcePackPacket.class, RemoveResourcePackPacket::new, - map(0x06, MINECRAFT_1_20_3, false), - map(0x08, MINECRAFT_1_20_5, false)); - clientbound.register(ResourcePackRequestPacket.class, ResourcePackRequestPacket::new, - map(0x06, MINECRAFT_1_20_2, false), - map(0x07, MINECRAFT_1_20_3, false), - map(0x09, MINECRAFT_1_20_5, false)); - clientbound.register( - ClientboundStoreCookiePacket.class, ClientboundStoreCookiePacket::new, - map(0x0A, MINECRAFT_1_20_5, false)); - clientbound.register(TransferPacket.class, TransferPacket::new, - map(0x0B, MINECRAFT_1_20_5, false)); - clientbound.register(ActiveFeaturesPacket.class, ActiveFeaturesPacket::new, - map(0x07, MINECRAFT_1_20_2, false), - map(0x08, MINECRAFT_1_20_3, false), - map(0x0C, MINECRAFT_1_20_5, false)); - clientbound.register(TagsUpdatePacket.class, TagsUpdatePacket::new, - map(0x08, MINECRAFT_1_20_2, false), - map(0x09, MINECRAFT_1_20_3, false), - map(0x0D, MINECRAFT_1_20_5, false)); - clientbound.register(KnownPacksPacket.class, KnownPacksPacket::new, - map(0x0E, MINECRAFT_1_20_5, false)); - clientbound.register(ClientboundCustomReportDetailsPacket.class, ClientboundCustomReportDetailsPacket::new, - map(0x0F, MINECRAFT_1_21, false)); - clientbound.register(ClientboundServerLinksPacket.class, ClientboundServerLinksPacket::new, - map(0x10, MINECRAFT_1_21, false)); + serverbound(ClientSettingsPacket.class, ClientSettingsPacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_20_2); + }); + serverbound(ServerboundCookieResponsePacket.class, ServerboundCookieResponsePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_20_5); + }); + serverbound(PluginMessagePacket.class, PluginMessagePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_20_2); + m.readWrite(0x02, MINECRAFT_1_20_5); + }); + serverbound(FinishedUpdatePacket.class, () -> FinishedUpdatePacket.INSTANCE, m -> { + m.readWrite(0x02, MINECRAFT_1_20_2); + m.readWrite(0x03, MINECRAFT_1_20_5); + }); + serverbound(KeepAlivePacket.class, KeepAlivePacket::new, m -> { + m.readWrite(0x03, MINECRAFT_1_20_2); + m.readWrite(0x04, MINECRAFT_1_20_5); + }); + serverbound(PingIdentifyPacket.class, PingIdentifyPacket::new, m -> { + m.readWrite(0x04, MINECRAFT_1_20_2); + m.readWrite(0x05, MINECRAFT_1_20_5); + }); + serverbound(ResourcePackResponsePacket.class, ResourcePackResponsePacket::new, m -> { + m.readWrite(0x05, MINECRAFT_1_20_2); + m.readWrite(0x06, MINECRAFT_1_20_5); + }); + serverbound(KnownPacksPacket.class, KnownPacksPacket::new, m -> { + m.readWrite(0x07, MINECRAFT_1_20_5); + }); + + clientbound(ClientboundCookieRequestPacket.class, ClientboundCookieRequestPacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_20_5); + }); + clientbound(PluginMessagePacket.class, PluginMessagePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_20_2); + m.readWrite(0x01, MINECRAFT_1_20_5); + }); + clientbound(DisconnectPacket.class, () -> new DisconnectPacket(this), m -> { + m.readWrite(0x01, MINECRAFT_1_20_2); + m.readWrite(0x02, MINECRAFT_1_20_5); + }); + clientbound(FinishedUpdatePacket.class, () -> FinishedUpdatePacket.INSTANCE, m -> { + m.readWrite(0x02, MINECRAFT_1_20_2); + m.readWrite(0x03, MINECRAFT_1_20_5); + }); + clientbound(KeepAlivePacket.class, KeepAlivePacket::new, m -> { + m.readWrite(0x03, MINECRAFT_1_20_2); + m.readWrite(0x04, MINECRAFT_1_20_5); + }); + clientbound(PingIdentifyPacket.class, PingIdentifyPacket::new, m -> { + m.readWrite(0x04, MINECRAFT_1_20_2); + m.readWrite(0x05, MINECRAFT_1_20_5); + }); + clientbound(RegistrySyncPacket.class, RegistrySyncPacket::new, m -> { + m.readWrite(0x05, MINECRAFT_1_20_2); + m.readWrite(0x07, MINECRAFT_1_20_5); + }); + clientbound(RemoveResourcePackPacket.class, RemoveResourcePackPacket::new, m -> { + m.readWrite(0x06, MINECRAFT_1_20_3); + m.readWrite(0x08, MINECRAFT_1_20_5); + }); + clientbound(ResourcePackRequestPacket.class, ResourcePackRequestPacket::new, m -> { + m.readWrite(0x06, MINECRAFT_1_20_2); + m.readWrite(0x07, MINECRAFT_1_20_3); + m.readWrite(0x09, MINECRAFT_1_20_5); + }); + clientbound(TransferPacket.class, TransferPacket::new, m -> { + m.readWrite(0x0B, MINECRAFT_1_20_5); + }); + clientbound(ActiveFeaturesPacket.class, ActiveFeaturesPacket::new, m -> { + m.readWrite(0x07, MINECRAFT_1_20_2); + m.readWrite(0x08, MINECRAFT_1_20_3); + m.readWrite(0x0C, MINECRAFT_1_20_5); + }); + clientbound(TagsUpdatePacket.class, TagsUpdatePacket::new, m -> { + m.readWrite(0x08, MINECRAFT_1_20_2); + m.readWrite(0x09, MINECRAFT_1_20_3); + m.readWrite(0x0D, MINECRAFT_1_20_5); + }); + clientbound(KnownPacksPacket.class, KnownPacksPacket::new, m -> { + m.readWrite(0x0E, MINECRAFT_1_20_5); + }); } }, PLAY { @@ -240,475 +236,431 @@ public enum StateRegistry { serverbound.fallback = false; clientbound.fallback = false; - serverbound.register(TabCompleteRequestPacket.class, TabCompleteRequestPacket::new, - map(0x14, MINECRAFT_1_7_2, false), - map(0x01, MINECRAFT_1_9, false), - map(0x02, MINECRAFT_1_12, false), - map(0x01, MINECRAFT_1_12_1, false), - map(0x05, MINECRAFT_1_13, false), - map(0x06, MINECRAFT_1_14, false), - map(0x08, MINECRAFT_1_19, false), - map(0x09, MINECRAFT_1_19_1, false), - map(0x08, MINECRAFT_1_19_3, false), - map(0x09, MINECRAFT_1_19_4, false), - map(0x0A, MINECRAFT_1_20_2, false), - map(0x0B, MINECRAFT_1_20_5, false)); - serverbound.register( - LegacyChatPacket.class, - LegacyChatPacket::new, - map(0x01, MINECRAFT_1_7_2, false), - map(0x02, MINECRAFT_1_9, false), - map(0x03, MINECRAFT_1_12, false), - map(0x02, MINECRAFT_1_12_1, false), - map(0x03, MINECRAFT_1_14, MINECRAFT_1_18_2, false)); - serverbound.register( - ChatAcknowledgementPacket.class, - ChatAcknowledgementPacket::new, - map(0x03, MINECRAFT_1_19_3, false)); - serverbound.register(KeyedPlayerCommandPacket.class, KeyedPlayerCommandPacket::new, - map(0x03, MINECRAFT_1_19, false), - map(0x04, MINECRAFT_1_19_1, MINECRAFT_1_19_1, false)); - serverbound.register(KeyedPlayerChatPacket.class, KeyedPlayerChatPacket::new, - map(0x04, MINECRAFT_1_19, false), - map(0x05, MINECRAFT_1_19_1, MINECRAFT_1_19_1, false)); - serverbound.register(SessionPlayerCommandPacket.class, SessionPlayerCommandPacket::new, - map(0x04, MINECRAFT_1_19_3, false), - map(0x05, MINECRAFT_1_20_5, false)); - serverbound.register(UnsignedPlayerCommandPacket.class, UnsignedPlayerCommandPacket::new, - map(0x04, MINECRAFT_1_20_5, false)); - serverbound.register( - SessionPlayerChatPacket.class, - SessionPlayerChatPacket::new, - map(0x05, MINECRAFT_1_19_3, false), - map(0x06, MINECRAFT_1_20_5, false)); - serverbound.register( - ClientSettingsPacket.class, - ClientSettingsPacket::new, - map(0x15, MINECRAFT_1_7_2, false), - map(0x04, MINECRAFT_1_9, false), - map(0x05, MINECRAFT_1_12, false), - map(0x04, MINECRAFT_1_12_1, false), - map(0x05, MINECRAFT_1_14, false), - map(0x07, MINECRAFT_1_19, false), - map(0x08, MINECRAFT_1_19_1, false), - map(0x07, MINECRAFT_1_19_3, false), - map(0x08, MINECRAFT_1_19_4, false), - map(0x09, MINECRAFT_1_20_2, false), - map(0x0A, MINECRAFT_1_20_5, false)); - serverbound.register( - ServerboundCookieResponsePacket.class, ServerboundCookieResponsePacket::new, - map(0x11, MINECRAFT_1_20_5, false)); - serverbound.register( - PluginMessagePacket.class, - PluginMessagePacket::new, - map(0x17, MINECRAFT_1_7_2, false), - map(0x09, MINECRAFT_1_9, false), - map(0x0A, MINECRAFT_1_12, false), - map(0x09, MINECRAFT_1_12_1, false), - map(0x0A, MINECRAFT_1_13, false), - map(0x0B, MINECRAFT_1_14, false), - map(0x0A, MINECRAFT_1_17, false), - map(0x0C, MINECRAFT_1_19, false), - map(0x0D, MINECRAFT_1_19_1, false), - map(0x0C, MINECRAFT_1_19_3, false), - map(0x0D, MINECRAFT_1_19_4, false), - map(0x0F, MINECRAFT_1_20_2, false), - map(0x10, MINECRAFT_1_20_3, false), - map(0x12, MINECRAFT_1_20_5, false)); - serverbound.register( - KeepAlivePacket.class, - KeepAlivePacket::new, - map(0x00, MINECRAFT_1_7_2, false), - map(0x0B, MINECRAFT_1_9, false), - map(0x0C, MINECRAFT_1_12, false), - map(0x0B, MINECRAFT_1_12_1, false), - map(0x0E, MINECRAFT_1_13, false), - map(0x0F, MINECRAFT_1_14, false), - map(0x10, MINECRAFT_1_16, false), - map(0x0F, MINECRAFT_1_17, false), - map(0x11, MINECRAFT_1_19, false), - map(0x12, MINECRAFT_1_19_1, false), - map(0x11, MINECRAFT_1_19_3, false), - map(0x12, MINECRAFT_1_19_4, false), - map(0x14, MINECRAFT_1_20_2, false), - map(0x15, MINECRAFT_1_20_3, false), - map(0x18, MINECRAFT_1_20_5, false)); - serverbound.register( - ResourcePackResponsePacket.class, - ResourcePackResponsePacket::new, - map(0x19, MINECRAFT_1_8, false), - map(0x16, MINECRAFT_1_9, false), - map(0x18, MINECRAFT_1_12, false), - map(0x1D, MINECRAFT_1_13, false), - map(0x1F, MINECRAFT_1_14, false), - map(0x20, MINECRAFT_1_16, false), - map(0x21, MINECRAFT_1_16_2, false), - map(0x23, MINECRAFT_1_19, false), - map(0x24, MINECRAFT_1_19_1, false), - map(0x27, MINECRAFT_1_20_2, false), - map(0x28, MINECRAFT_1_20_3, false), - map(0x2B, MINECRAFT_1_20_5, false)); - serverbound.register( - FinishedUpdatePacket.class, () -> FinishedUpdatePacket.INSTANCE, - map(0x0B, MINECRAFT_1_20_2, false), - map(0x0C, MINECRAFT_1_20_5, false)); - - clientbound.register( - BossBarPacket.class, - BossBarPacket::new, - map(0x0C, MINECRAFT_1_9, false), - map(0x0D, MINECRAFT_1_15, false), - map(0x0C, MINECRAFT_1_16, false), - map(0x0D, MINECRAFT_1_17, false), - map(0x0A, MINECRAFT_1_19, false), - map(0x0B, MINECRAFT_1_19_4, false), - map(0x0A, MINECRAFT_1_20_2, false)); - clientbound.register( - LegacyChatPacket.class, - LegacyChatPacket::new, - map(0x02, MINECRAFT_1_7_2, true), - map(0x0F, MINECRAFT_1_9, true), - map(0x0E, MINECRAFT_1_13, true), - map(0x0F, MINECRAFT_1_15, true), - map(0x0E, MINECRAFT_1_16, true), - map(0x0F, MINECRAFT_1_17, MINECRAFT_1_18_2, true)); - clientbound.register(TabCompleteResponsePacket.class, TabCompleteResponsePacket::new, - map(0x3A, MINECRAFT_1_7_2, false), - map(0x0E, MINECRAFT_1_9, false), - map(0x10, MINECRAFT_1_13, false), - map(0x11, MINECRAFT_1_15, false), - map(0x10, MINECRAFT_1_16, false), - map(0x0F, MINECRAFT_1_16_2, false), - map(0x11, MINECRAFT_1_17, false), - map(0x0E, MINECRAFT_1_19, false), - map(0x0D, MINECRAFT_1_19_3, false), - map(0x0F, MINECRAFT_1_19_4, false), - map(0x10, MINECRAFT_1_20_2, false)); - clientbound.register( - AvailableCommandsPacket.class, - AvailableCommandsPacket::new, - map(0x11, MINECRAFT_1_13, false), - map(0x12, MINECRAFT_1_15, false), - map(0x11, MINECRAFT_1_16, false), - map(0x10, MINECRAFT_1_16_2, false), - map(0x12, MINECRAFT_1_17, false), - map(0x0F, MINECRAFT_1_19, false), - map(0x0E, MINECRAFT_1_19_3, false), - map(0x10, MINECRAFT_1_19_4, false), - map(0x11, MINECRAFT_1_20_2, false)); - clientbound.register( - ClientboundCookieRequestPacket.class, ClientboundCookieRequestPacket::new, - map(0x16, MINECRAFT_1_20_5, false)); - clientbound.register( - PluginMessagePacket.class, - PluginMessagePacket::new, - map(0x3F, MINECRAFT_1_7_2, false), - map(0x18, MINECRAFT_1_9, false), - map(0x19, MINECRAFT_1_13, false), - map(0x18, MINECRAFT_1_14, false), - map(0x19, MINECRAFT_1_15, false), - map(0x18, MINECRAFT_1_16, false), - map(0x17, MINECRAFT_1_16_2, false), - map(0x18, MINECRAFT_1_17, false), - map(0x15, MINECRAFT_1_19, false), - map(0x16, MINECRAFT_1_19_1, false), - map(0x15, MINECRAFT_1_19_3, false), - map(0x17, MINECRAFT_1_19_4, false), - map(0x18, MINECRAFT_1_20_2, false), - map(0x19, MINECRAFT_1_20_5, false)); - clientbound.register( - DisconnectPacket.class, - () -> new DisconnectPacket(this), - map(0x40, MINECRAFT_1_7_2, false), - map(0x1A, MINECRAFT_1_9, false), - map(0x1B, MINECRAFT_1_13, false), - map(0x1A, MINECRAFT_1_14, false), - map(0x1B, MINECRAFT_1_15, false), - map(0x1A, MINECRAFT_1_16, false), - map(0x19, MINECRAFT_1_16_2, false), - map(0x1A, MINECRAFT_1_17, false), - map(0x17, MINECRAFT_1_19, false), - map(0x19, MINECRAFT_1_19_1, false), - map(0x17, MINECRAFT_1_19_3, false), - map(0x1A, MINECRAFT_1_19_4, false), - map(0x1B, MINECRAFT_1_20_2, false), - map(0x1D, MINECRAFT_1_20_5, false)); - clientbound.register( - KeepAlivePacket.class, - KeepAlivePacket::new, - map(0x00, MINECRAFT_1_7_2, false), - map(0x1F, MINECRAFT_1_9, false), - map(0x21, MINECRAFT_1_13, false), - map(0x20, MINECRAFT_1_14, false), - map(0x21, MINECRAFT_1_15, false), - map(0x20, MINECRAFT_1_16, false), - map(0x1F, MINECRAFT_1_16_2, false), - map(0x21, MINECRAFT_1_17, false), - map(0x1E, MINECRAFT_1_19, false), - map(0x20, MINECRAFT_1_19_1, false), - map(0x1F, MINECRAFT_1_19_3, false), - map(0x23, MINECRAFT_1_19_4, false), - map(0x24, MINECRAFT_1_20_2, false), - map(0x26, MINECRAFT_1_20_5, false)); - clientbound.register( - JoinGamePacket.class, - JoinGamePacket::new, - map(0x01, MINECRAFT_1_7_2, false), - map(0x23, MINECRAFT_1_9, false), - map(0x25, MINECRAFT_1_13, false), - map(0x25, MINECRAFT_1_14, false), - map(0x26, MINECRAFT_1_15, false), - map(0x25, MINECRAFT_1_16, false), - map(0x24, MINECRAFT_1_16_2, false), - map(0x26, MINECRAFT_1_17, false), - map(0x23, MINECRAFT_1_19, false), - map(0x25, MINECRAFT_1_19_1, false), - map(0x24, MINECRAFT_1_19_3, false), - map(0x28, MINECRAFT_1_19_4, false), - map(0x29, MINECRAFT_1_20_2, false), - map(0x2B, MINECRAFT_1_20_5, false)); - clientbound.register( - RespawnPacket.class, - RespawnPacket::new, - map(0x07, MINECRAFT_1_7_2, true), - map(0x33, MINECRAFT_1_9, true), - map(0x34, MINECRAFT_1_12, true), - map(0x35, MINECRAFT_1_12_1, true), - map(0x38, MINECRAFT_1_13, true), - map(0x3A, MINECRAFT_1_14, true), - map(0x3B, MINECRAFT_1_15, true), - map(0x3A, MINECRAFT_1_16, true), - map(0x39, MINECRAFT_1_16_2, true), - map(0x3D, MINECRAFT_1_17, true), - map(0x3B, MINECRAFT_1_19, true), - map(0x3E, MINECRAFT_1_19_1, true), - map(0x3D, MINECRAFT_1_19_3, true), - map(0x41, MINECRAFT_1_19_4, true), - map(0x43, MINECRAFT_1_20_2, true), - map(0x45, MINECRAFT_1_20_3, true), - map(0x47, MINECRAFT_1_20_5, true)); - clientbound.register( - RemoveResourcePackPacket.class, - RemoveResourcePackPacket::new, - map(0x43, MINECRAFT_1_20_3, false), - map(0x45, MINECRAFT_1_20_5, false)); - clientbound.register( - ResourcePackRequestPacket.class, - ResourcePackRequestPacket::new, - map(0x48, MINECRAFT_1_8, false), - map(0x32, MINECRAFT_1_9, false), - map(0x33, MINECRAFT_1_12, false), - map(0x34, MINECRAFT_1_12_1, false), - map(0x37, MINECRAFT_1_13, false), - map(0x39, MINECRAFT_1_14, false), - map(0x3A, MINECRAFT_1_15, false), - map(0x39, MINECRAFT_1_16, false), - map(0x38, MINECRAFT_1_16_2, false), - map(0x3C, MINECRAFT_1_17, false), - map(0x3A, MINECRAFT_1_19, false), - map(0x3D, MINECRAFT_1_19_1, false), - map(0x3C, MINECRAFT_1_19_3, false), - map(0x40, MINECRAFT_1_19_4, false), - map(0x42, MINECRAFT_1_20_2, false), - map(0x44, MINECRAFT_1_20_3, false), - map(0x46, MINECRAFT_1_20_5, false)); - clientbound.register( - HeaderAndFooterPacket.class, - HeaderAndFooterPacket::new, - map(0x47, MINECRAFT_1_8, true), - map(0x48, MINECRAFT_1_9, true), - map(0x47, MINECRAFT_1_9_4, true), - map(0x49, MINECRAFT_1_12, true), - map(0x4A, MINECRAFT_1_12_1, true), - map(0x4E, MINECRAFT_1_13, true), - map(0x53, MINECRAFT_1_14, true), - map(0x54, MINECRAFT_1_15, true), - map(0x53, MINECRAFT_1_16, true), - map(0x5E, MINECRAFT_1_17, true), - map(0x5F, MINECRAFT_1_18, true), - map(0x60, MINECRAFT_1_19, true), - map(0x63, MINECRAFT_1_19_1, true), - map(0x61, MINECRAFT_1_19_3, true), - map(0x65, MINECRAFT_1_19_4, true), - map(0x68, MINECRAFT_1_20_2, true), - map(0x6A, MINECRAFT_1_20_3, true), - map(0x6D, MINECRAFT_1_20_5, true)); - clientbound.register( - LegacyTitlePacket.class, - LegacyTitlePacket::new, - map(0x45, MINECRAFT_1_8, true), - map(0x45, MINECRAFT_1_9, true), - map(0x47, MINECRAFT_1_12, true), - map(0x48, MINECRAFT_1_12_1, true), - map(0x4B, MINECRAFT_1_13, true), - map(0x4F, MINECRAFT_1_14, true), - map(0x50, MINECRAFT_1_15, true), - map(0x4F, MINECRAFT_1_16, MINECRAFT_1_16_4, true)); - clientbound.register(TitleSubtitlePacket.class, TitleSubtitlePacket::new, - map(0x57, MINECRAFT_1_17, true), - map(0x58, MINECRAFT_1_18, true), - map(0x5B, MINECRAFT_1_19_1, true), - map(0x59, MINECRAFT_1_19_3, true), - map(0x5D, MINECRAFT_1_19_4, true), - map(0x5F, MINECRAFT_1_20_2, true), - map(0x61, MINECRAFT_1_20_3, true), - map(0x63, MINECRAFT_1_20_5, true)); - clientbound.register( - TitleTextPacket.class, - TitleTextPacket::new, - map(0x59, MINECRAFT_1_17, true), - map(0x5A, MINECRAFT_1_18, true), - map(0x5D, MINECRAFT_1_19_1, true), - map(0x5B, MINECRAFT_1_19_3, true), - map(0x5F, MINECRAFT_1_19_4, true), - map(0x61, MINECRAFT_1_20_2, true), - map(0x63, MINECRAFT_1_20_3, true), - map(0x65, MINECRAFT_1_20_5, true)); - clientbound.register( - TitleActionbarPacket.class, - TitleActionbarPacket::new, - map(0x41, MINECRAFT_1_17, true), - map(0x40, MINECRAFT_1_19, true), - map(0x43, MINECRAFT_1_19_1, true), - map(0x42, MINECRAFT_1_19_3, true), - map(0x46, MINECRAFT_1_19_4, true), - map(0x48, MINECRAFT_1_20_2, true), - map(0x4A, MINECRAFT_1_20_3, true), - map(0x4C, MINECRAFT_1_20_5, true)); - clientbound.register( - TitleTimesPacket.class, - TitleTimesPacket::new, - map(0x5A, MINECRAFT_1_17, true), - map(0x5B, MINECRAFT_1_18, true), - map(0x5E, MINECRAFT_1_19_1, true), - map(0x5C, MINECRAFT_1_19_3, true), - map(0x60, MINECRAFT_1_19_4, true), - map(0x62, MINECRAFT_1_20_2, true), - map(0x64, MINECRAFT_1_20_3, true), - map(0x66, MINECRAFT_1_20_5, true)); - clientbound.register( - TitleClearPacket.class, - TitleClearPacket::new, - map(0x10, MINECRAFT_1_17, true), - map(0x0D, MINECRAFT_1_19, true), - map(0x0C, MINECRAFT_1_19_3, true), - map(0x0E, MINECRAFT_1_19_4, true), - map(0x0F, MINECRAFT_1_20_2, true)); - clientbound.register( - LegacyPlayerListItemPacket.class, - LegacyPlayerListItemPacket::new, - map(0x38, MINECRAFT_1_7_2, false), - map(0x2D, MINECRAFT_1_9, false), - map(0x2E, MINECRAFT_1_12_1, false), - map(0x30, MINECRAFT_1_13, false), - map(0x33, MINECRAFT_1_14, false), - map(0x34, MINECRAFT_1_15, false), - map(0x33, MINECRAFT_1_16, false), - map(0x32, MINECRAFT_1_16_2, false), - map(0x36, MINECRAFT_1_17, false), - map(0x34, MINECRAFT_1_19, false), - map(0x37, MINECRAFT_1_19_1, MINECRAFT_1_19_1, false)); - clientbound.register(RemovePlayerInfoPacket.class, RemovePlayerInfoPacket::new, - map(0x35, MINECRAFT_1_19_3, false), - map(0x39, MINECRAFT_1_19_4, false), - map(0x3B, MINECRAFT_1_20_2, false), - map(0x3D, MINECRAFT_1_20_5, false)); - clientbound.register( - UpsertPlayerInfoPacket.class, - UpsertPlayerInfoPacket::new, - map(0x36, MINECRAFT_1_19_3, false), - map(0x3A, MINECRAFT_1_19_4, false), - map(0x3C, MINECRAFT_1_20_2, false), - map(0x3E, MINECRAFT_1_20_5, false)); - clientbound.register( - ClientboundStoreCookiePacket.class, ClientboundStoreCookiePacket::new, - map(0x6B, MINECRAFT_1_20_5, false)); - clientbound.register( - SystemChatPacket.class, - SystemChatPacket::new, - map(0x5F, MINECRAFT_1_19, true), - map(0x62, MINECRAFT_1_19_1, true), - map(0x60, MINECRAFT_1_19_3, true), - map(0x64, MINECRAFT_1_19_4, true), - map(0x67, MINECRAFT_1_20_2, true), - map(0x69, MINECRAFT_1_20_3, true), - map(0x6C, MINECRAFT_1_20_5, true)); - clientbound.register( - PlayerChatCompletionPacket.class, - PlayerChatCompletionPacket::new, - map(0x15, MINECRAFT_1_19_1, true), - map(0x14, MINECRAFT_1_19_3, true), - map(0x16, MINECRAFT_1_19_4, true), - map(0x17, MINECRAFT_1_20_2, true), - map(0x18, MINECRAFT_1_20_5, true)); - clientbound.register( - ServerDataPacket.class, - ServerDataPacket::new, - map(0x3F, MINECRAFT_1_19, false), - map(0x42, MINECRAFT_1_19_1, false), - map(0x41, MINECRAFT_1_19_3, false), - map(0x45, MINECRAFT_1_19_4, false), - map(0x47, MINECRAFT_1_20_2, false), - map(0x49, MINECRAFT_1_20_3, false), - map(0x4B, MINECRAFT_1_20_5, false)); - clientbound.register( - StartUpdatePacket.class, - () -> StartUpdatePacket.INSTANCE, - map(0x65, MINECRAFT_1_20_2, false), - map(0x67, MINECRAFT_1_20_3, false), - map(0x69, MINECRAFT_1_20_5, false)); - clientbound.register( - BundleDelimiterPacket.class, - () -> BundleDelimiterPacket.INSTANCE, - map(0x00, MINECRAFT_1_19_4, false)); - clientbound.register( - TransferPacket.class, - TransferPacket::new, - map(0x73, MINECRAFT_1_20_5, false) - ); - clientbound.register(ClientboundCustomReportDetailsPacket.class, ClientboundCustomReportDetailsPacket::new, - map(0x7A, MINECRAFT_1_21, false)); - clientbound.register(ClientboundServerLinksPacket.class, ClientboundServerLinksPacket::new, - map(0x7B, MINECRAFT_1_21, false)); + serverbound(TabCompleteRequestPacket.class, TabCompleteRequestPacket::new, m -> { + m.readWrite(0x14, MINECRAFT_1_7_2); + m.readWrite(0x01, MINECRAFT_1_9); + m.readWrite(0x02, MINECRAFT_1_12); + m.readWrite(0x01, MINECRAFT_1_12_1); + m.readWrite(0x05, MINECRAFT_1_13); + m.readWrite(0x06, MINECRAFT_1_14); + m.readWrite(0x08, MINECRAFT_1_19); + m.readWrite(0x09, MINECRAFT_1_19_1); + m.readWrite(0x08, MINECRAFT_1_19_3); + m.readWrite(0x09, MINECRAFT_1_19_4); + m.readWrite(0x0A, MINECRAFT_1_20_2); + m.readWrite(0x0B, MINECRAFT_1_20_5); + }); + serverbound(LegacyChatPacket.class, LegacyChatPacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_7_2); + m.readWrite(0x02, MINECRAFT_1_9); + m.readWrite(0x03, MINECRAFT_1_12); + m.readWrite(0x02, MINECRAFT_1_12_1); + m.readWrite(0x03, MINECRAFT_1_14, MINECRAFT_1_18_2); + }); + serverbound(ChatAcknowledgementPacket.class, ChatAcknowledgementPacket::new, m -> { + m.readWrite(0x03, MINECRAFT_1_19_3); + }); + serverbound(KeyedPlayerCommandPacket.class, KeyedPlayerCommandPacket::new, m -> { + m.readWrite(0x03, MINECRAFT_1_19); + m.readWrite(0x04, MINECRAFT_1_19_1, MINECRAFT_1_19_1); + }); + serverbound(KeyedPlayerChatPacket.class, KeyedPlayerChatPacket::new, m -> { + m.readWrite(0x04, MINECRAFT_1_19); + m.readWrite(0x05, MINECRAFT_1_19_1, MINECRAFT_1_19_1); + }); + serverbound(SessionPlayerCommandPacket.class, SessionPlayerCommandPacket::new, m -> { + m.readWrite(0x04, MINECRAFT_1_19_3); + m.readWrite(0x05, MINECRAFT_1_20_5); + }); + serverbound(UnsignedPlayerCommandPacket.class, UnsignedPlayerCommandPacket::new, m -> { + m.readWrite(0x04, MINECRAFT_1_20_5); + }); + serverbound(SessionPlayerChatPacket.class, SessionPlayerChatPacket::new, m -> { + m.readWrite(0x05, MINECRAFT_1_19_3); + m.readWrite(0x06, MINECRAFT_1_20_5); + }); + serverbound(ClientSettingsPacket.class, ClientSettingsPacket::new, m -> { + m.readWrite(0x15, MINECRAFT_1_7_2); + m.readWrite(0x04, MINECRAFT_1_9); + m.readWrite(0x05, MINECRAFT_1_12); + m.readWrite(0x04, MINECRAFT_1_12_1); + m.readWrite(0x05, MINECRAFT_1_14); + m.readWrite(0x07, MINECRAFT_1_19); + m.readWrite(0x08, MINECRAFT_1_19_1); + m.readWrite(0x07, MINECRAFT_1_19_3); + m.readWrite(0x08, MINECRAFT_1_19_4); + m.readWrite(0x09, MINECRAFT_1_20_2); + m.readWrite(0x0A, MINECRAFT_1_20_5); + }); + serverbound(PluginMessagePacket.class, PluginMessagePacket::new, m -> { + m.readWrite(0x17, MINECRAFT_1_7_2); + m.readWrite(0x09, MINECRAFT_1_9); + m.readWrite(0x0A, MINECRAFT_1_12); + m.readWrite(0x09, MINECRAFT_1_12_1); + m.readWrite(0x0A, MINECRAFT_1_13); + m.readWrite(0x0B, MINECRAFT_1_14); + m.readWrite(0x0A, MINECRAFT_1_17); + m.readWrite(0x0C, MINECRAFT_1_19); + m.readWrite(0x0D, MINECRAFT_1_19_1); + m.readWrite(0x0C, MINECRAFT_1_19_3); + m.readWrite(0x0D, MINECRAFT_1_19_4); + m.readWrite(0x0F, MINECRAFT_1_20_2); + m.readWrite(0x10, MINECRAFT_1_20_3); + m.readWrite(0x12, MINECRAFT_1_20_5); + }); + serverbound(KeepAlivePacket.class, KeepAlivePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_7_2); + m.readWrite(0x0B, MINECRAFT_1_9); + m.readWrite(0x0C, MINECRAFT_1_12); + m.readWrite(0x0B, MINECRAFT_1_12_1); + m.readWrite(0x0E, MINECRAFT_1_13); + m.readWrite(0x0F, MINECRAFT_1_14); + m.readWrite(0x10, MINECRAFT_1_16); + m.readWrite(0x0F, MINECRAFT_1_17); + m.readWrite(0x11, MINECRAFT_1_19); + m.readWrite(0x12, MINECRAFT_1_19_1); + m.readWrite(0x11, MINECRAFT_1_19_3); + m.readWrite(0x12, MINECRAFT_1_19_4); + m.readWrite(0x14, MINECRAFT_1_20_2); + m.readWrite(0x15, MINECRAFT_1_20_3); + m.readWrite(0x18, MINECRAFT_1_20_5); + }); + serverbound(ResourcePackResponsePacket.class, ResourcePackResponsePacket::new, m -> { + m.readWrite(0x19, MINECRAFT_1_8); + m.readWrite(0x16, MINECRAFT_1_9); + m.readWrite(0x18, MINECRAFT_1_12); + m.readWrite(0x1D, MINECRAFT_1_13); + m.readWrite(0x1F, MINECRAFT_1_14); + m.readWrite(0x20, MINECRAFT_1_16); + m.readWrite(0x21, MINECRAFT_1_16_2); + m.readWrite(0x23, MINECRAFT_1_19); + m.readWrite(0x24, MINECRAFT_1_19_1); + m.readWrite(0x27, MINECRAFT_1_20_2); + m.readWrite(0x28, MINECRAFT_1_20_3); + m.readWrite(0x2B, MINECRAFT_1_20_5); + }); + serverbound(FinishedUpdatePacket.class, () -> FinishedUpdatePacket.INSTANCE, m -> { + m.readWrite(0x0B, MINECRAFT_1_20_2); + m.readWrite(0x0C, MINECRAFT_1_20_5); + }); + + clientbound(BossBarPacket.class, BossBarPacket::new, m -> { + m.readWrite(0x0C, MINECRAFT_1_9); + m.readWrite(0x0D, MINECRAFT_1_15); + m.readWrite(0x0C, MINECRAFT_1_16); + m.readWrite(0x0D, MINECRAFT_1_17); + m.readWrite(0x0A, MINECRAFT_1_19); + m.readWrite(0x0B, MINECRAFT_1_19_4); + m.readWrite(0x0A, MINECRAFT_1_20_2); + }); + clientbound(LegacyChatPacket.class, LegacyChatPacket::new, m -> { + m.writeOnly(0x02, MINECRAFT_1_7_2); + m.writeOnly(0x0F, MINECRAFT_1_9); + m.writeOnly(0x0E, MINECRAFT_1_13); + m.writeOnly(0x0F, MINECRAFT_1_15); + m.writeOnly(0x0E, MINECRAFT_1_16); + m.writeOnly(0x0F, MINECRAFT_1_17, MINECRAFT_1_18_2); + }); + clientbound(TabCompleteResponsePacket.class, TabCompleteResponsePacket::new, m -> { + m.readWrite(0x3A, MINECRAFT_1_7_2); + m.readWrite(0x0E, MINECRAFT_1_9); + m.readWrite(0x10, MINECRAFT_1_13); + m.readWrite(0x11, MINECRAFT_1_15); + m.readWrite(0x10, MINECRAFT_1_16); + m.readWrite(0x0F, MINECRAFT_1_16_2); + m.readWrite(0x11, MINECRAFT_1_17); + m.readWrite(0x0E, MINECRAFT_1_19); + m.readWrite(0x0D, MINECRAFT_1_19_3); + m.readWrite(0x0F, MINECRAFT_1_19_4); + m.readWrite(0x10, MINECRAFT_1_20_2); + }); + clientbound(AvailableCommandsPacket.class, AvailableCommandsPacket::new, m -> { + m.readWrite(0x11, MINECRAFT_1_13); + m.readWrite(0x12, MINECRAFT_1_15); + m.readWrite(0x11, MINECRAFT_1_16); + m.readWrite(0x10, MINECRAFT_1_16_2); + m.readWrite(0x12, MINECRAFT_1_17); + m.readWrite(0x0F, MINECRAFT_1_19); + m.readWrite(0x0E, MINECRAFT_1_19_3); + m.readWrite(0x10, MINECRAFT_1_19_4); + m.readWrite(0x11, MINECRAFT_1_20_2); + }); + clientbound(PluginMessagePacket.class, PluginMessagePacket::new, m -> { + m.readWrite(0x3F, MINECRAFT_1_7_2); + m.readWrite(0x18, MINECRAFT_1_9); + m.readWrite(0x19, MINECRAFT_1_13); + m.readWrite(0x18, MINECRAFT_1_14); + m.readWrite(0x19, MINECRAFT_1_15); + m.readWrite(0x18, MINECRAFT_1_16); + m.readWrite(0x17, MINECRAFT_1_16_2); + m.readWrite(0x18, MINECRAFT_1_17); + m.readWrite(0x15, MINECRAFT_1_19); + m.readWrite(0x16, MINECRAFT_1_19_1); + m.readWrite(0x15, MINECRAFT_1_19_3); + m.readWrite(0x17, MINECRAFT_1_19_4); + m.readWrite(0x18, MINECRAFT_1_20_2); + m.readWrite(0x19, MINECRAFT_1_20_5); + }); + clientbound(DisconnectPacket.class, () -> new DisconnectPacket(this), m -> { + m.readWrite(0x40, MINECRAFT_1_7_2); + m.readWrite(0x1A, MINECRAFT_1_9); + m.readWrite(0x1B, MINECRAFT_1_13); + m.readWrite(0x1A, MINECRAFT_1_14); + m.readWrite(0x1B, MINECRAFT_1_15); + m.readWrite(0x1A, MINECRAFT_1_16); + m.readWrite(0x19, MINECRAFT_1_16_2); + m.readWrite(0x1A, MINECRAFT_1_17); + m.readWrite(0x17, MINECRAFT_1_19); + m.readWrite(0x19, MINECRAFT_1_19_1); + m.readWrite(0x17, MINECRAFT_1_19_3); + m.readWrite(0x1A, MINECRAFT_1_19_4); + m.readWrite(0x1B, MINECRAFT_1_20_2); + m.readWrite(0x1D, MINECRAFT_1_20_5); + }); + clientbound(KeepAlivePacket.class, KeepAlivePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_7_2); + m.readWrite(0x1F, MINECRAFT_1_9); + m.readWrite(0x21, MINECRAFT_1_13); + m.readWrite(0x20, MINECRAFT_1_14); + m.readWrite(0x21, MINECRAFT_1_15); + m.readWrite(0x20, MINECRAFT_1_16); + m.readWrite(0x1F, MINECRAFT_1_16_2); + m.readWrite(0x21, MINECRAFT_1_17); + m.readWrite(0x1E, MINECRAFT_1_19); + m.readWrite(0x20, MINECRAFT_1_19_1); + m.readWrite(0x1F, MINECRAFT_1_19_3); + m.readWrite(0x23, MINECRAFT_1_19_4); + m.readWrite(0x24, MINECRAFT_1_20_2); + m.readWrite(0x26, MINECRAFT_1_20_5); + }); + clientbound(JoinGamePacket.class, JoinGamePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_7_2); + m.readWrite(0x23, MINECRAFT_1_9); + m.readWrite(0x25, MINECRAFT_1_13); + m.readWrite(0x25, MINECRAFT_1_14); + m.readWrite(0x26, MINECRAFT_1_15); + m.readWrite(0x25, MINECRAFT_1_16); + m.readWrite(0x24, MINECRAFT_1_16_2); + m.readWrite(0x26, MINECRAFT_1_17); + m.readWrite(0x23, MINECRAFT_1_19); + m.readWrite(0x25, MINECRAFT_1_19_1); + m.readWrite(0x24, MINECRAFT_1_19_3); + m.readWrite(0x28, MINECRAFT_1_19_4); + m.readWrite(0x29, MINECRAFT_1_20_2); + m.readWrite(0x2B, MINECRAFT_1_20_5); + }); + clientbound(RespawnPacket.class, RespawnPacket::new, m -> { + m.writeOnly(0x07, MINECRAFT_1_7_2); + m.writeOnly(0x33, MINECRAFT_1_9); + m.writeOnly(0x34, MINECRAFT_1_12); + m.writeOnly(0x35, MINECRAFT_1_12_1); + m.writeOnly(0x38, MINECRAFT_1_13); + m.writeOnly(0x3A, MINECRAFT_1_14); + m.writeOnly(0x3B, MINECRAFT_1_15); + m.writeOnly(0x3A, MINECRAFT_1_16); + m.writeOnly(0x39, MINECRAFT_1_16_2); + m.writeOnly(0x3D, MINECRAFT_1_17); + m.writeOnly(0x3B, MINECRAFT_1_19); + m.writeOnly(0x3E, MINECRAFT_1_19_1); + m.writeOnly(0x3D, MINECRAFT_1_19_3); + m.writeOnly(0x41, MINECRAFT_1_19_4); + m.writeOnly(0x43, MINECRAFT_1_20_2); + m.writeOnly(0x45, MINECRAFT_1_20_3); + m.writeOnly(0x47, MINECRAFT_1_20_5); + }); + clientbound(RemoveResourcePackPacket.class, RemoveResourcePackPacket::new, m -> { + m.readWrite(0x43, MINECRAFT_1_20_3); + m.readWrite(0x45, MINECRAFT_1_20_5); + }); + clientbound(ResourcePackRequestPacket.class, ResourcePackRequestPacket::new, m -> { + m.readWrite(0x48, MINECRAFT_1_8); + m.readWrite(0x32, MINECRAFT_1_9); + m.readWrite(0x33, MINECRAFT_1_12); + m.readWrite(0x34, MINECRAFT_1_12_1); + m.readWrite(0x37, MINECRAFT_1_13); + m.readWrite(0x39, MINECRAFT_1_14); + m.readWrite(0x3A, MINECRAFT_1_15); + m.readWrite(0x39, MINECRAFT_1_16); + m.readWrite(0x38, MINECRAFT_1_16_2); + m.readWrite(0x3C, MINECRAFT_1_17); + m.readWrite(0x3A, MINECRAFT_1_19); + m.readWrite(0x3D, MINECRAFT_1_19_1); + m.readWrite(0x3C, MINECRAFT_1_19_3); + m.readWrite(0x40, MINECRAFT_1_19_4); + m.readWrite(0x42, MINECRAFT_1_20_2); + m.readWrite(0x44, MINECRAFT_1_20_3); + m.readWrite(0x46, MINECRAFT_1_20_5); + }); + clientbound(HeaderAndFooterPacket.class, HeaderAndFooterPacket::new, m -> { + m.writeOnly(0x47, MINECRAFT_1_8); + m.writeOnly(0x48, MINECRAFT_1_9); + m.writeOnly(0x47, MINECRAFT_1_9_4); + m.writeOnly(0x49, MINECRAFT_1_12); + m.writeOnly(0x4A, MINECRAFT_1_12_1); + m.writeOnly(0x4E, MINECRAFT_1_13); + m.writeOnly(0x53, MINECRAFT_1_14); + m.writeOnly(0x54, MINECRAFT_1_15); + m.writeOnly(0x53, MINECRAFT_1_16); + m.writeOnly(0x5E, MINECRAFT_1_17); + m.writeOnly(0x5F, MINECRAFT_1_18); + m.writeOnly(0x60, MINECRAFT_1_19); + m.writeOnly(0x63, MINECRAFT_1_19_1); + m.writeOnly(0x61, MINECRAFT_1_19_3); + m.writeOnly(0x65, MINECRAFT_1_19_4); + m.writeOnly(0x68, MINECRAFT_1_20_2); + m.writeOnly(0x6A, MINECRAFT_1_20_3); + m.writeOnly(0x6D, MINECRAFT_1_20_5); + }); + clientbound(LegacyTitlePacket.class, LegacyTitlePacket::new, m -> { + m.writeOnly(0x45, MINECRAFT_1_8); + m.writeOnly(0x45, MINECRAFT_1_9); + m.writeOnly(0x47, MINECRAFT_1_12); + m.writeOnly(0x48, MINECRAFT_1_12_1); + m.writeOnly(0x4B, MINECRAFT_1_13); + m.writeOnly(0x4F, MINECRAFT_1_14); + m.writeOnly(0x50, MINECRAFT_1_15); + m.writeOnly(0x4F, MINECRAFT_1_16, MINECRAFT_1_16_4); + }); + clientbound(TitleSubtitlePacket.class, TitleSubtitlePacket::new, m -> { + m.writeOnly(0x57, MINECRAFT_1_17); + m.writeOnly(0x58, MINECRAFT_1_18); + m.writeOnly(0x5B, MINECRAFT_1_19_1); + m.writeOnly(0x59, MINECRAFT_1_19_3); + m.writeOnly(0x5D, MINECRAFT_1_19_4); + m.writeOnly(0x5F, MINECRAFT_1_20_2); + m.writeOnly(0x61, MINECRAFT_1_20_3); + m.writeOnly(0x63, MINECRAFT_1_20_5); + }); + clientbound(TitleTextPacket.class, TitleTextPacket::new, m -> { + m.writeOnly(0x59, MINECRAFT_1_17); + m.writeOnly(0x5A, MINECRAFT_1_18); + m.writeOnly(0x5D, MINECRAFT_1_19_1); + m.writeOnly(0x5B, MINECRAFT_1_19_3); + m.writeOnly(0x5F, MINECRAFT_1_19_4); + m.writeOnly(0x61, MINECRAFT_1_20_2); + m.writeOnly(0x63, MINECRAFT_1_20_3); + m.writeOnly(0x65, MINECRAFT_1_20_5); + }); + clientbound(TitleActionbarPacket.class, TitleActionbarPacket::new, m -> { + m.writeOnly(0x41, MINECRAFT_1_17); + m.writeOnly(0x40, MINECRAFT_1_19); + m.writeOnly(0x43, MINECRAFT_1_19_1); + m.writeOnly(0x42, MINECRAFT_1_19_3); + m.writeOnly(0x46, MINECRAFT_1_19_4); + m.writeOnly(0x48, MINECRAFT_1_20_2); + m.writeOnly(0x4A, MINECRAFT_1_20_3); + m.writeOnly(0x4C, MINECRAFT_1_20_5); + }); + clientbound(TitleTimesPacket.class, TitleTimesPacket::new, m -> { + m.writeOnly(0x5A, MINECRAFT_1_17); + m.writeOnly(0x5B, MINECRAFT_1_18); + m.writeOnly(0x5E, MINECRAFT_1_19_1); + m.writeOnly(0x5C, MINECRAFT_1_19_3); + m.writeOnly(0x60, MINECRAFT_1_19_4); + m.writeOnly(0x62, MINECRAFT_1_20_2); + m.writeOnly(0x64, MINECRAFT_1_20_3); + m.writeOnly(0x66, MINECRAFT_1_20_5); + }); + clientbound(TitleClearPacket.class, TitleClearPacket::new, m -> { + m.writeOnly(0x10, MINECRAFT_1_17); + m.writeOnly(0x0D, MINECRAFT_1_19); + m.writeOnly(0x0C, MINECRAFT_1_19_3); + m.writeOnly(0x0E, MINECRAFT_1_19_4); + m.writeOnly(0x0F, MINECRAFT_1_20_2); + }); + clientbound(LegacyPlayerListItemPacket.class, LegacyPlayerListItemPacket::new, m -> { + m.readWrite(0x38, MINECRAFT_1_7_2); + m.readWrite(0x2D, MINECRAFT_1_9); + m.readWrite(0x2E, MINECRAFT_1_12_1); + m.readWrite(0x30, MINECRAFT_1_13); + m.readWrite(0x33, MINECRAFT_1_14); + m.readWrite(0x34, MINECRAFT_1_15); + m.readWrite(0x33, MINECRAFT_1_16); + m.readWrite(0x32, MINECRAFT_1_16_2); + m.readWrite(0x36, MINECRAFT_1_17); + m.readWrite(0x34, MINECRAFT_1_19); + m.readWrite(0x37, MINECRAFT_1_19_1, MINECRAFT_1_19_1); + }); + clientbound(RemovePlayerInfoPacket.class, RemovePlayerInfoPacket::new, m -> { + m.readWrite(0x35, MINECRAFT_1_19_3); + m.readWrite(0x39, MINECRAFT_1_19_4); + m.readWrite(0x3B, MINECRAFT_1_20_2); + m.readWrite(0x3D, MINECRAFT_1_20_5); + }); + clientbound(UpsertPlayerInfoPacket.class, UpsertPlayerInfoPacket::new, m -> { + m.readWrite(0x36, MINECRAFT_1_19_3); + m.readWrite(0x3A, MINECRAFT_1_19_4); + m.readWrite(0x3C, MINECRAFT_1_20_2); + m.readWrite(0x3E, MINECRAFT_1_20_5); + }); + clientbound(SystemChatPacket.class, SystemChatPacket::new, m -> { + m.writeOnly(0x5F, MINECRAFT_1_19); + m.writeOnly(0x62, MINECRAFT_1_19_1); + m.writeOnly(0x60, MINECRAFT_1_19_3); + m.writeOnly(0x64, MINECRAFT_1_19_4); + m.writeOnly(0x67, MINECRAFT_1_20_2); + m.writeOnly(0x69, MINECRAFT_1_20_3); + m.writeOnly(0x6C, MINECRAFT_1_20_5); + }); + clientbound(PlayerChatCompletionPacket.class, PlayerChatCompletionPacket::new, m -> { + m.writeOnly(0x15, MINECRAFT_1_19_1); + m.writeOnly(0x14, MINECRAFT_1_19_3); + m.writeOnly(0x16, MINECRAFT_1_19_4); + m.writeOnly(0x17, MINECRAFT_1_20_2); + m.writeOnly(0x18, MINECRAFT_1_20_5); + }); + clientbound(ServerDataPacket.class, ServerDataPacket::new, m -> { + m.readWrite(0x3F, MINECRAFT_1_19); + m.readWrite(0x42, MINECRAFT_1_19_1); + m.readWrite(0x41, MINECRAFT_1_19_3); + m.readWrite(0x45, MINECRAFT_1_19_4); + m.readWrite(0x47, MINECRAFT_1_20_2); + m.readWrite(0x49, MINECRAFT_1_20_3); + m.readWrite(0x4B, MINECRAFT_1_20_5); + }); + clientbound(StartUpdatePacket.class, () -> StartUpdatePacket.INSTANCE, m -> { + m.readWrite(0x65, MINECRAFT_1_20_2); + m.readWrite(0x67, MINECRAFT_1_20_3); + m.readWrite(0x69, MINECRAFT_1_20_5); + }); + clientbound(BundleDelimiterPacket.class, () -> BundleDelimiterPacket.INSTANCE, m -> { + m.readWrite(0x00, MINECRAFT_1_19_4); + }); + clientbound(TransferPacket.class, TransferPacket::new, m -> { + m.readWrite(0x73, MINECRAFT_1_20_5); + }); } }, LOGIN { { - serverbound.register(ServerLoginPacket.class, - ServerLoginPacket::new, - map(0x00, MINECRAFT_1_7_2, false)); - serverbound.register( - EncryptionResponsePacket.class, EncryptionResponsePacket::new, - map(0x01, MINECRAFT_1_7_2, false)); - serverbound.register( - LoginPluginResponsePacket.class, LoginPluginResponsePacket::new, - map(0x02, MINECRAFT_1_13, false)); - serverbound.register( - LoginAcknowledgedPacket.class, LoginAcknowledgedPacket::new, - map(0x03, MINECRAFT_1_20_2, false)); - serverbound.register( - ServerboundCookieResponsePacket.class, ServerboundCookieResponsePacket::new, - map(0x04, MINECRAFT_1_20_5, false)); - - clientbound.register( - DisconnectPacket.class, () -> new DisconnectPacket(this), - map(0x00, MINECRAFT_1_7_2, false)); - clientbound.register( - EncryptionRequestPacket.class, EncryptionRequestPacket::new, - map(0x01, MINECRAFT_1_7_2, false)); - clientbound.register( - ServerLoginSuccessPacket.class, ServerLoginSuccessPacket::new, - map(0x02, MINECRAFT_1_7_2, false)); - clientbound.register( - SetCompressionPacket.class, SetCompressionPacket::new, - map(0x03, MINECRAFT_1_8, false)); - clientbound.register( - LoginPluginMessagePacket.class, - LoginPluginMessagePacket::new, - map(0x04, MINECRAFT_1_13, false)); - clientbound.register( - ClientboundCookieRequestPacket.class, ClientboundCookieRequestPacket::new, - map(0x05, MINECRAFT_1_20_5, false)); + serverbound(ServerLoginPacket.class, ServerLoginPacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_7_2); + }); + serverbound(EncryptionResponsePacket.class, EncryptionResponsePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_7_2); + }); + serverbound(LoginPluginResponsePacket.class, LoginPluginResponsePacket::new, m -> { + m.readWrite(0x02, MINECRAFT_1_13); + }); + serverbound(LoginAcknowledgedPacket.class, LoginAcknowledgedPacket::new, m -> { + m.readWrite(0x03, MINECRAFT_1_20_2); + }); + + clientbound(DisconnectPacket.class, () -> new DisconnectPacket(this), m -> { + m.readWrite(0x00, MINECRAFT_1_7_2); + }); + clientbound(EncryptionRequestPacket.class, EncryptionRequestPacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_7_2); + }); + clientbound(ServerLoginSuccessPacket.class, ServerLoginSuccessPacket::new, m -> { + m.readWrite(0x02, MINECRAFT_1_7_2); + }); + clientbound(SetCompressionPacket.class, SetCompressionPacket::new, m -> { + m.readWrite(0x03, MINECRAFT_1_8); + }); + clientbound(LoginPluginMessagePacket.class, LoginPluginMessagePacket::new, m -> { + m.readWrite(0x04, MINECRAFT_1_13); + }); } }; @@ -718,6 +670,14 @@ public enum StateRegistry { protected final PacketRegistry clientbound = new PacketRegistry(CLIENTBOUND, this); protected final PacketRegistry serverbound = new PacketRegistry(SERVERBOUND, this); +

void clientbound(Class

clazz, Supplier

factory, Consumer mapper) { + this.clientbound.register(clazz, factory, mapper); + } + +

void serverbound(Class

clazz, Supplier

factory, Consumer mapper) { + this.serverbound.register(clazz, factory, mapper); + } + public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(Direction direction, ProtocolVersion version) { return (direction == SERVERBOUND ? serverbound : clientbound).getProtocolRegistry(version); @@ -773,18 +733,31 @@ ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) { return registry; } -

void register(Class

clazz, Supplier

packetSupplier, - PacketMapping... mappings) { - if (mappings.length == 0) { +

void register(Class

clazz, Supplier

factory, Consumer mapper) { + final List mappings = new ArrayList<>(); + mapper.accept(new PacketMapper() { + @Override + public void readWrite(final int id, final ProtocolVersion from, final @Nullable ProtocolVersion to) { + mappings.add(new PacketMapping(id, from, to, false)); + } + + @Override + public void writeOnly(final int id, final ProtocolVersion from, final @Nullable ProtocolVersion to) { + mappings.add(new PacketMapping(id, from, to, true)); + } + }); + + final int size = mappings.size(); + if (size == 0) { throw new IllegalArgumentException("At least one mapping must be provided."); } - for (int i = 0; i < mappings.length; i++) { - PacketMapping current = mappings[i]; - PacketMapping next = (i + 1 < mappings.length) ? mappings[i + 1] : current; + for (int i = 0; i < size; i++) { + PacketMapping current = mappings.get(i); + PacketMapping next = (i + 1 < size) ? mappings.get(i + 1) : current; - ProtocolVersion from = current.protocolVersion; - ProtocolVersion lastValid = current.lastValidProtocolVersion; + ProtocolVersion from = current.from(); + ProtocolVersion lastValid = current.to(); if (lastValid != null) { if (next != current) { throw new IllegalArgumentException("Cannot add a mapping after last valid mapping"); @@ -795,7 +768,7 @@

void register(Class

clazz, Supplier

packetSupp } } ProtocolVersion to = current == next ? lastValid != null - ? lastValid : getLast(SUPPORTED_VERSIONS) : next.protocolVersion; + ? lastValid : getLast(SUPPORTED_VERSIONS) : next.from(); ProtocolVersion lastInList = lastValid != null ? lastValid : getLast(SUPPORTED_VERSIONS); @@ -811,15 +784,15 @@

void register(Class

clazz, Supplier

packetSupp ProtocolRegistry registry = this.versions.get(protocol); if (registry == null) { throw new IllegalArgumentException( - "Unknown protocol version " + current.protocolVersion); + "Unknown protocol version " + current.from()); } - if (registry.packetIdToSupplier.containsKey(current.id)) { + if (registry.packetIdToSupplier.containsKey(current.id())) { throw new IllegalArgumentException( "Can not register class " + clazz.getSimpleName() + " with id " - + current.id + + current.id() + " for " + registry.version + " because another packet is already registered"); @@ -830,10 +803,10 @@

void register(Class

clazz, Supplier

packetSupp clazz.getSimpleName() + " is already registered for version " + registry.version); } - if (!current.encodeOnly) { - registry.packetIdToSupplier.put(current.id, packetSupplier); + if (!current.writeOnly()) { + registry.packetIdToSupplier.put(current.id(), factory); } - registry.packetClassToId.put(clazz, current.id); + registry.packetClassToId.put(clazz, current.id()); } } } @@ -899,82 +872,4 @@ public boolean containsPacket(final MinecraftPacket packet) { } } - /** - * Packet mapping. - */ - public static final class PacketMapping { - - private final int id; - private final ProtocolVersion protocolVersion; - private final boolean encodeOnly; - private final @Nullable ProtocolVersion lastValidProtocolVersion; - - PacketMapping(int id, ProtocolVersion protocolVersion, - @Nullable ProtocolVersion lastValidProtocolVersion, - boolean packetDecoding) { - this.id = id; - this.protocolVersion = protocolVersion; - this.lastValidProtocolVersion = lastValidProtocolVersion; - this.encodeOnly = packetDecoding; - } - - @Override - public String toString() { - return "PacketMapping{" - + "id=" - + id - + ", protocolVersion=" - + protocolVersion - + ", encodeOnly=" - + encodeOnly - + '}'; - } - - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - PacketMapping that = (PacketMapping) o; - return id == that.id - && protocolVersion == that.protocolVersion - && encodeOnly == that.encodeOnly; - } - - @Override - public int hashCode() { - return Objects.hash(id, protocolVersion, encodeOnly); - } - } - - /** - * Creates a PacketMapping using the provided arguments. - * - * @param id Packet Id - * @param version Protocol version - * @param encodeOnly When true packet decoding will be disabled - * @return PacketMapping with the provided arguments - */ - @SuppressFBWarnings({"UPM_UNCALLED_PRIVATE_METHOD"}) - private static PacketMapping map(int id, ProtocolVersion version, boolean encodeOnly) { - return map(id, version, null, encodeOnly); - } - - /** - * Creates a PacketMapping using the provided arguments. - * - * @param id Packet Id - * @param version Protocol version - * @param encodeOnly When true packet decoding will be disabled - * @param lastValidProtocolVersion Last version this Mapping is valid at - * @return PacketMapping with the provided arguments - */ - private static PacketMapping map(int id, ProtocolVersion version, - ProtocolVersion lastValidProtocolVersion, boolean encodeOnly) { - return new PacketMapping(id, version, lastValidProtocolVersion, encodeOnly); - } - } \ No newline at end of file diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java index f65674ea1e..c5b659316e 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java @@ -45,10 +45,11 @@ class PacketRegistryTest { private StateRegistry.PacketRegistry setupRegistry() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY); - registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, null, false), - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false), - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_15, MINECRAFT_1_16, false)); + registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_8, null); + m.readWrite(0x00, MINECRAFT_1_12, null); + m.readWrite(0x00, MINECRAFT_1_15, MINECRAFT_1_16); + }); return registry; } @@ -86,7 +87,7 @@ void failOnNoMappings() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket::new)); + () -> registry.register(HandshakePacket.class, HandshakePacket::new, m -> {})); assertThrows(IllegalArgumentException.class, () -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN) .getPacketId(new HandshakePacket())); @@ -97,54 +98,62 @@ void failOnWrongOrder() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, null, false), - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false))); + () -> registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_13, null); + m.readWrite(0x00, MINECRAFT_1_8, null); + })); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, null, false), - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, null, false))); + () -> registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_13, null); + m.readWrite(0x01, MINECRAFT_1_13, null); + })); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, MINECRAFT_1_8, false))); + () -> registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_13, MINECRAFT_1_8); + })); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, MINECRAFT_1_14, false), - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_16, null, false))); + () -> registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_8, MINECRAFT_1_14); + m.readWrite(0x00, MINECRAFT_1_16, null); + })); } @Test void failOnDuplicate() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY); - registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false)); + registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_8, null); + }); assertThrows(IllegalArgumentException.class, - () -> registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12, null, false))); + () -> registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x01, MINECRAFT_1_12, null); + })); assertThrows(IllegalArgumentException.class, - () -> registry.register(StatusPingPacket.class, StatusPingPacket::new, - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_13, null, false))); + () -> registry.register(StatusPingPacket.class, StatusPingPacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_13, null); + })); } @Test void shouldNotFailWhenRegisterLatestProtocolVersion() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY); - assertDoesNotThrow(() -> registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, null, false), - new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS), - null, false))); + assertDoesNotThrow(() -> registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_8, null); + m.readWrite(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS), null); + })); } @Test void registrySuppliesCorrectPacketsByProtocol() { StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( ProtocolUtils.Direction.CLIENTBOUND, StateRegistry.PLAY); - registry.register(HandshakePacket.class, HandshakePacket::new, - new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, null, false), - new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, null, false), - new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, null, false)); + registry.register(HandshakePacket.class, HandshakePacket::new, m -> { + m.readWrite(0x00, MINECRAFT_1_12, null); + m.readWrite(0x01, MINECRAFT_1_12_1, null); + m.readWrite(0x02, MINECRAFT_1_13, null); + }); assertEquals(HandshakePacket.class, registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass()); assertEquals(HandshakePacket.class,