From 1dafa7d273092b7d31a81a0750bf1258da9eaca3 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 26 Jan 2024 15:48:10 +0100 Subject: [PATCH] Cleanup config packet registration in newer protocols --- .../api/protocol/AbstractProtocol.java | 132 +++++++----------- .../packet/mapping/PacketIdMapping.java | 10 +- .../packet/mapping/PacketMapping.java | 14 +- .../packet/mapping/PacketTypeMapping.java | 10 +- .../packet/provider/PacketTypeMap.java | 14 +- .../api/protocol/remapper/PacketHandler.java | 8 +- .../Protocol1_19_1To1_19.java | 50 +++---- ...ClientboundConfigurationPackets1_20_2.java | 3 +- .../packet/ClientboundPacket1_20_2.java | 23 +++ .../packet/ClientboundPackets1_20_2.java | 4 +- ...ServerboundConfigurationPackets1_20_2.java | 4 +- .../packet/ServerboundPacket1_20_2.java | 23 +++ .../packet/ServerboundPackets1_20_2.java | 4 +- .../Protocol1_20_3To1_20_2.java | 40 +++--- ...ClientboundConfigurationPackets1_20_3.java | 3 +- .../packet/ClientboundPacket1_20_3.java | 23 +++ .../packet/ClientboundPackets1_20_3.java | 4 +- .../packet/ServerboundPacket1_20_3.java | 23 +++ .../packet/ServerboundPackets1_20_3.java | 4 +- .../BlockItemPacketRewriter1_20_3.java | 8 +- .../rewriter/EntityPacketRewriter1_20_3.java | 6 +- .../Protocol1_20_5To1_20_3.java | 37 ++--- ...ClientboundConfigurationPackets1_20_5.java | 3 +- .../packet/ClientboundPacket1_20_5.java | 23 +++ .../packet/ClientboundPackets1_20_5.java | 4 +- ...ServerboundConfigurationPackets1_20_5.java | 3 +- .../packet/ServerboundPacket1_20_5.java | 23 +++ .../packet/ServerboundPackets1_20_5.java | 4 +- .../BlockItemPacketRewriter1_20_5.java | 8 +- .../rewriter/EntityPacketRewriter1_20_5.java | 7 +- .../viaversion/rewriter/TagRewriter.java | 5 - .../template/protocols/Protocol1_99To_98.java | 32 ++--- .../rewriter/BlockItemPacketRewriter1_99.java | 6 +- .../rewriter/EntityPacketRewriter1_99.java | 8 +- 34 files changed, 332 insertions(+), 241 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPacket1_20_2.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPacket1_20_2.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPacket1_20_3.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPacket1_20_3.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPacket1_20_5.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPacket1_20_5.java diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java index d27270ce3..06faadd21 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java @@ -133,43 +133,33 @@ public abstract class AbstractProtocol void registerPacketIdChanges( @@ -181,17 +171,16 @@ public abstract class AbstractProtocol> entry : mappedPacketTypes.entrySet()) { PacketTypeMap mappedTypes = entry.getValue(); PacketTypeMap unmappedTypes = unmappedPacketTypes.get(entry.getKey()); - registerPacketIdChanges(unmappedTypes, mappedTypes, registeredPredicate, registerConsumer, true); + registerPacketIdChanges(unmappedTypes, mappedTypes, registeredPredicate, registerConsumer); } } - protected void registerPacketIdChanges(PacketTypeMap unmappedTypes, PacketTypeMap mappedTypes, Predicate registeredPredicate, BiConsumer registerConsumer, boolean errorOnMissing) { + protected void registerPacketIdChanges(PacketTypeMap unmappedTypes, PacketTypeMap mappedTypes, Predicate registeredPredicate, BiConsumer registerConsumer) { for (U unmappedType : unmappedTypes.types()) { M mappedType = mappedTypes.typeByName(unmappedType.getName()); if (mappedType == null) { // No mapped packet of the same name exists - Preconditions.checkArgument(registeredPredicate.test(unmappedType) || !errorOnMissing, - "Packet %s in %s has no mapping - it needs to be manually cancelled or remapped", unmappedType, getClass()); + Preconditions.checkArgument(registeredPredicate.test(unmappedType), "Packet %s in %s has no mapping - it needs to be manually cancelled or remapped", unmappedType, getClass()); continue; } @@ -202,40 +191,6 @@ public abstract class AbstractProtocol unmappedPacketTypesClass, Class mappedPacketTypesClass) { - registerPacketIdChanges( - PacketTypeMap.of(unmappedPacketTypesClass), - PacketTypeMap.of(mappedPacketTypesClass), - type -> false, - (unmappedType, mappedType) -> { - final PacketMapping mapping = clientboundMappings.mappedPacket(state, unmappedType.getId()); - this.registerClientbound(state, unmappedType.getId(), mappedType.getId(), wrapper -> { - if (mapping != null && mapping.handler() != null) { - mapping.handler().handle(wrapper); - } - }, true); - }, false - ); - } - - @Deprecated // TODO Should instead be done automatically/properly via the packet types provider - protected void registerServerboundPacketIdChanges(State state, Class unmappedPacketTypesClass, Class mappedPacketTypesClass) { - registerPacketIdChanges( - PacketTypeMap.of(unmappedPacketTypesClass), - PacketTypeMap.of(mappedPacketTypesClass), - type -> false, - (unmappedType, mappedType) -> { - final PacketMapping mapping = serverboundMappings.mappedPacket(state, unmappedType.getId()); - this.registerServerbound(state, unmappedType.getId(), mappedType.getId(), wrapper -> { - if (mapping != null && mapping.handler() != null) { - mapping.handler().handle(wrapper); - } - }, true); - }, false - ); - } - @Override public final void loadMappingData() { getMappingData().load(); @@ -278,10 +233,10 @@ public abstract class AbstractProtocol createPacketTypesProvider() { return new SimplePacketTypesProvider<>( - packetTypeMap(unmappedClientboundPacketType), - packetTypeMap(mappedClientboundPacketType), - packetTypeMap(mappedServerboundPacketType), - packetTypeMap(unmappedServerboundPacketType) + packetTypeMap(unmappedClientboundPacketType, unmappedClientboundPacketType), + packetTypeMap(mappedClientboundPacketType, mappedClientboundPacketType), + packetTypeMap(mappedServerboundPacketType, mappedServerboundPacketType), + packetTypeMap(unmappedServerboundPacketType, unmappedServerboundPacketType) ); } @@ -293,35 +248,50 @@ public abstract class AbstractProtocol Map> packetTypeMap(@Nullable Class

packetTypeClass) { - if (packetTypeClass != null) { - Map> map = new EnumMap<>(State.class); - map.put(State.PLAY, PacketTypeMap.of(packetTypeClass)); - return map; + /** + * Returns a map of packet types by state. + * + * @param parent parent packet type class as given by the Protocol generics + * @param packetTypeClasses packet type enum classes belonging to the parent type + * @param

packet type class + * @return map of packet types by state + */ + @SafeVarargs + protected final

Map> packetTypeMap(@Nullable Class

parent, Class... packetTypeClasses) { + if (parent == null) { + return Collections.emptyMap(); } - return Collections.emptyMap(); + + final Map> map = new EnumMap<>(State.class); + for (final Class packetTypeClass : packetTypeClasses) { + // Get state from first enum type + final P[] types = packetTypeClass.getEnumConstants(); + Preconditions.checkArgument(types != null, "%s not an enum", packetTypeClass); + Preconditions.checkArgument(types.length > 0, "Enum %s has no types", packetTypeClass); + final State state = types[0].state(); + map.put(state, PacketTypeMap.of(packetTypeClass)); + } + return map; } protected @Nullable SU configurationAcknowledgedPacket() { - final Map> packetTypes = packetTypesProvider.unmappedServerboundPacketTypes(); - final PacketTypeMap packetTypeMap = packetTypes.get(State.PLAY); + final PacketTypeMap packetTypeMap = packetTypesProvider.unmappedServerboundPacketTypes().get(State.PLAY); return packetTypeMap != null ? packetTypeMap.typeByName("CONFIGURATION_ACKNOWLEDGED") : null; } protected @Nullable CU startConfigurationPacket() { - final Map> packetTypes = packetTypesProvider.unmappedClientboundPacketTypes(); - final PacketTypeMap packetTypeMap = packetTypes.get(State.PLAY); + final PacketTypeMap packetTypeMap = packetTypesProvider.unmappedClientboundPacketTypes().get(State.PLAY); return packetTypeMap != null ? packetTypeMap.typeByName("START_CONFIGURATION") : null; } - protected @Nullable ServerboundPacketType serverboundFinishConfigurationPacket() { - // To be overridden - return null; + protected @Nullable SU serverboundFinishConfigurationPacket() { + final PacketTypeMap packetTypeMap = packetTypesProvider.unmappedServerboundPacketTypes().get(State.CONFIGURATION); + return packetTypeMap != null ? packetTypeMap.typeByName("FINISH_CONFIGURATION") : null; } - protected @Nullable ClientboundPacketType clientboundFinishConfigurationPacket() { - // To be overridden - return null; + protected @Nullable CU clientboundFinishConfigurationPacket() { + final PacketTypeMap packetTypeMap = packetTypesProvider.unmappedClientboundPacketTypes().get(State.CONFIGURATION); + return packetTypeMap != null ? packetTypeMap.typeByName("FINISH_CONFIGURATION") : null; } // --------------------------------------------------------------------------------- @@ -529,7 +499,7 @@ public abstract class AbstractProtocol getPacketTypesProvider() { + public final PacketTypesProvider getPacketTypesProvider() { return packetTypesProvider; } @@ -544,10 +514,6 @@ public abstract class AbstractProtocol packetTypesProvider() { - return packetTypesProvider; - } - @Override public String toString() { return "Protocol:" + getClass().getSimpleName(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketIdMapping.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketIdMapping.java index 4b2875318..0ee3249ca 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketIdMapping.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketIdMapping.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; final class PacketIdMapping implements PacketMapping { private final int mappedPacketId; - private final PacketHandler handler; + private PacketHandler handler; PacketIdMapping(int mappedPacketId, @Nullable PacketHandler handler) { this.mappedPacketId = mappedPacketId; @@ -42,8 +42,12 @@ final class PacketIdMapping implements PacketMapping { } @Override - public Integer mappedPacketId() { - return mappedPacketId; + public void appendHandler(final PacketHandler handler) { + if (this.handler == null) { + this.handler = handler; + } else { + this.handler = this.handler.then(handler); + } } @Override diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketMapping.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketMapping.java index 6d4880213..662df63ae 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketMapping.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketMapping.java @@ -39,13 +39,6 @@ public interface PacketMapping { */ void applyType(PacketWrapper wrapper); - /** - * Returns the mapped packet id if present. - * - * @return mapped packet type, or null if no action has to be taken - */ - @Nullable Integer mappedPacketId(); - /** * Returns a packet transformer to transform a packet from one protocol version to another. * @@ -53,6 +46,13 @@ public interface PacketMapping { */ @Nullable PacketHandler handler(); + /** + * Appends a packet transformer to the current packet transformer. + * + * @param handler packet transformer + */ + void appendHandler(PacketHandler handler); + static PacketMapping of(final int mappedPacketId, @Nullable final PacketHandler handler) { return new PacketIdMapping(mappedPacketId, handler); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketTypeMapping.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketTypeMapping.java index b4f33c8d3..0b323dbb9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketTypeMapping.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/mapping/PacketTypeMapping.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; final class PacketTypeMapping implements PacketMapping { private final PacketType mappedPacketType; - private final PacketHandler handler; + private PacketHandler handler; PacketTypeMapping(@Nullable PacketType mappedPacketType, @Nullable PacketHandler handler) { this.mappedPacketType = mappedPacketType; @@ -44,8 +44,12 @@ final class PacketTypeMapping implements PacketMapping { } @Override - public @Nullable Integer mappedPacketId() { - return mappedPacketType != null ? mappedPacketType.getId() : null; + public void appendHandler(final PacketHandler handler) { + if (this.handler == null) { + this.handler = handler; + } else { + this.handler = this.handler.then(handler); + } } @Override diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/PacketTypeMap.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/PacketTypeMap.java index 14124a862..4625c7256 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/PacketTypeMap.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/PacketTypeMap.java @@ -22,6 +22,7 @@ */ package com.viaversion.viaversion.api.protocol.packet.provider; +import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.packet.PacketType; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import java.util.Collection; @@ -54,14 +55,11 @@ public interface PacketTypeMap

{ */ Collection

types(); - static PacketTypeMap of(final Class enumClass) { - if (!enumClass.isEnum()) { - throw new IllegalArgumentException("Given class is not an enum"); - } - - final S[] types = enumClass.getEnumConstants(); - final Map byName = new HashMap<>(types.length); - for (final S type : types) { + static PacketTypeMap of(final Class enumClass) { + final T[] types = enumClass.getEnumConstants(); + Preconditions.checkArgument(types != null, "%s is not an enum", enumClass); + final Map byName = new HashMap<>(types.length); + for (final T type : types) { byName.put(type.getName(), type); } return of(byName, types); diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java index 4322c7df8..59c1cc514 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java @@ -35,7 +35,13 @@ public interface PacketHandler { */ void handle(PacketWrapper wrapper) throws Exception; - default PacketHandler append(final PacketHandler handler) { + /** + * Returns a new packet handler that runs the provided handler after this one. + * + * @param handler packet handler to run aftet this one + * @return a new packet handler that runs the provided handler after this one + */ + default PacketHandler then(final PacketHandler handler) { return wrapper -> { this.handle(wrapper); handler.handle(wrapper); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java index 3719256e1..d5518f8de 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java @@ -58,32 +58,32 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class Protocol1_19_1To1_19 extends AbstractProtocol { - private static final String CHAT_REGISTRY_SNBT = "{\n" + - " \"minecraft:chat_type\": {\n" + - " \"type\": \"minecraft:chat_type\",\n" + - " \"value\": [\n" + - " {\n" + - " \"name\":\"minecraft:chat\",\n" + - " \"id\":1,\n" + - " \"element\":{\n" + - " \"chat\":{\n" + - " \"translation_key\":\"chat.type.text\",\n" + - " \"parameters\":[\n" + - " \"sender\",\n" + - " \"content\"\n" + - " ]\n" + - " },\n" + - " \"narration\":{\n" + - " \"translation_key\":\"chat.type.text.narrate\",\n" + - " \"parameters\":[\n" + - " \"sender\",\n" + - " \"content\"\n" + - " ]\n" + - " }\n" + - " }\n" + + private static final String CHAT_REGISTRY_SNBT = "{" + + " \"minecraft:chat_type\": {" + + " \"type\": \"minecraft:chat_type\"," + + " \"value\": [" + + " {" + + " \"name\":\"minecraft:chat\"," + + " \"id\":1," + + " \"element\":{" + + " \"chat\":{" + + " \"translation_key\":\"chat.type.text\"," + + " \"parameters\":[" + + " \"sender\"," + + " \"content\"" + + " ]" + + " }," + + " \"narration\":{" + + " \"translation_key\":\"chat.type.text.narrate\"," + + " \"parameters\":[" + + " \"sender\"," + + " \"content\"" + + " ]" + + " }" + + " }" + " }" + - " ]\n" + - " }\n" + + " ]" + + " }" + "}"; private static final CompoundTag CHAT_REGISTRY; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java index adcf85906..2f8311cf6 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java @@ -17,10 +17,9 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet; -import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.State; -public enum ClientboundConfigurationPackets1_20_2 implements ClientboundPacketType { +public enum ClientboundConfigurationPackets1_20_2 implements ClientboundPacket1_20_2 { CUSTOM_PAYLOAD, // 0x00 DISCONNECT, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPacket1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPacket1_20_2.java new file mode 100644 index 000000000..d1332078b --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPacket1_20_2.java @@ -0,0 +1,23 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and 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.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet; + +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; + +public interface ClientboundPacket1_20_2 extends ClientboundPacketType { +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java index 663339963..fb1097ba9 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java @@ -17,9 +17,7 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet; -import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; - -public enum ClientboundPackets1_20_2 implements ClientboundPacketType { +public enum ClientboundPackets1_20_2 implements ClientboundPacket1_20_2 { BUNDLE, // 0x00 SPAWN_ENTITY, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java index 56a730982..7ba3e7957 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java @@ -17,10 +17,10 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet; -import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.protocol.packet.State; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPacket1_20_3; -public enum ServerboundConfigurationPackets1_20_2 implements ServerboundPacketType { +public enum ServerboundConfigurationPackets1_20_2 implements ServerboundPacket1_20_2, ServerboundPacket1_20_3 { CLIENT_INFORMATION, // 0x00 CUSTOM_PAYLOAD, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPacket1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPacket1_20_2.java new file mode 100644 index 000000000..1cb045e2c --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPacket1_20_2.java @@ -0,0 +1,23 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and 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.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet; + +import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; + +public interface ServerboundPacket1_20_2 extends ServerboundPacketType { +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java index 0f3edc379..2fcf00e97 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java @@ -17,9 +17,7 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet; -import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; - -public enum ServerboundPackets1_20_2 implements ServerboundPacketType { +public enum ServerboundPackets1_20_2 implements ServerboundPacket1_20_2 { TELEPORT_CONFIRM, // 0x00 QUERY_BLOCK_NBT, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java index f7fdf9f91..ce9acd502 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java @@ -24,8 +24,8 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_3; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; -import com.viaversion.viaversion.api.protocol.packet.State; +import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; +import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -34,15 +34,18 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20_3; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.rewriter.CommandRewriter1_19_4; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPacket1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundConfigurationPackets1_20_2; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPacket1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPacket1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.BlockItemPacketRewriter1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.EntityPacketRewriter1_20_3; -import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -51,14 +54,14 @@ import java.nio.charset.StandardCharsets; import java.util.BitSet; import java.util.UUID; -public final class Protocol1_20_3To1_20_2 extends AbstractProtocol { +public final class Protocol1_20_3To1_20_2 extends AbstractProtocol { public static final MappingData MAPPINGS = new MappingDataBase("1.20.2", "1.20.3"); private final BlockItemPacketRewriter1_20_3 itemRewriter = new BlockItemPacketRewriter1_20_3(this); private final EntityPacketRewriter1_20_3 entityRewriter = new EntityPacketRewriter1_20_3(this); public Protocol1_20_3To1_20_2() { - super(ClientboundPackets1_20_2.class, ClientboundPackets1_20_3.class, ServerboundPackets1_20_2.class, ServerboundPackets1_20_3.class); + super(ClientboundPacket1_20_2.class, ClientboundPacket1_20_3.class, ServerboundPacket1_20_2.class, ServerboundPacket1_20_3.class); } @Override @@ -67,10 +70,10 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol tagRewriter = new TagRewriter<>(this); + final TagRewriter tagRewriter = new TagRewriter<>(this); tagRewriter.registerGeneric(ClientboundPackets1_20_2.TAGS); - final SoundRewriter soundRewriter = new SoundRewriter<>(this); + final SoundRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_2.SOUND); soundRewriter.registerSound(ClientboundPackets1_20_2.ENTITY_SOUND); @@ -226,7 +229,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol createPacketTypesProvider() { + return new SimplePacketTypesProvider<>( + packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_2.class, ClientboundConfigurationPackets1_20_2.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_3.class, ClientboundConfigurationPackets1_20_3.class), + packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_2.class, ServerboundConfigurationPackets1_20_2.class), + packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_3.class, ServerboundConfigurationPackets1_20_2.class) + ); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundConfigurationPackets1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundConfigurationPackets1_20_3.java index cf33806d8..b9e6d5ef3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundConfigurationPackets1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundConfigurationPackets1_20_3.java @@ -17,10 +17,9 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet; -import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.State; -public enum ClientboundConfigurationPackets1_20_3 implements ClientboundPacketType { +public enum ClientboundConfigurationPackets1_20_3 implements ClientboundPacket1_20_3 { CUSTOM_PAYLOAD, // 0x00 DISCONNECT, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPacket1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPacket1_20_3.java new file mode 100644 index 000000000..dfe20c279 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPacket1_20_3.java @@ -0,0 +1,23 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and 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.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet; + +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; + +public interface ClientboundPacket1_20_3 extends ClientboundPacketType { +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPackets1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPackets1_20_3.java index cd04b7b21..ea4553407 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPackets1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ClientboundPackets1_20_3.java @@ -17,9 +17,7 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet; -import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; - -public enum ClientboundPackets1_20_3 implements ClientboundPacketType { +public enum ClientboundPackets1_20_3 implements ClientboundPacket1_20_3 { BUNDLE, // 0x00 SPAWN_ENTITY, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPacket1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPacket1_20_3.java new file mode 100644 index 000000000..45b1176d8 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPacket1_20_3.java @@ -0,0 +1,23 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and 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.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet; + +import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; + +public interface ServerboundPacket1_20_3 extends ServerboundPacketType { +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPackets1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPackets1_20_3.java index e48ba5b72..ee93766d6 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPackets1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/packet/ServerboundPackets1_20_3.java @@ -17,9 +17,7 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet; -import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; - -public enum ServerboundPackets1_20_3 implements ServerboundPacketType { +public enum ServerboundPackets1_20_3 implements ServerboundPacket1_20_3 { TELEPORT_CONFIRM, // 0x00 QUERY_BLOCK_NBT, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java index 6bd6bc9b0..8edb5b4e6 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java @@ -24,15 +24,17 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPacket1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.RecipeRewriter1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.Protocol1_20_3To1_20_2; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPacket1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.util.Key; -public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter { +public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter { public BlockItemPacketRewriter1_20_3(final Protocol1_20_3To1_20_2 protocol) { super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY); @@ -40,7 +42,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); + final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); blockRewriter.registerBlockAction(ClientboundPackets1_20_2.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_20_2.BLOCK_CHANGE); blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_2.MULTI_BLOCK_CHANGE); @@ -82,7 +84,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter(protocol) { + new RecipeRewriter1_20_2(protocol) { @Override public void handleCraftingShaped(final PacketWrapper wrapper) throws Exception { // Move width and height down diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java index 3c5742ecc..5306f6118 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java @@ -23,12 +23,12 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_3; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundConfigurationPackets1_20_2; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPacket1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.Protocol1_20_3To1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3; @@ -36,7 +36,7 @@ import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.Key; -public final class EntityPacketRewriter1_20_3 extends EntityRewriter { +public final class EntityPacketRewriter1_20_3 extends EntityRewriter { public EntityPacketRewriter1_20_3(final Protocol1_20_3To1_20_2 protocol) { super(protocol); @@ -48,7 +48,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter { +public final class Protocol1_20_5To1_20_3 extends AbstractProtocol { public static final MappingData MAPPINGS = new MappingDataBase("1.20.3", "1.20.5"); private final EntityPacketRewriter1_20_5 entityRewriter = new EntityPacketRewriter1_20_5(this); private final BlockItemPacketRewriter1_20_5 itemRewriter = new BlockItemPacketRewriter1_20_5(this); public Protocol1_20_5To1_20_3() { - super(ClientboundPackets1_20_3.class, ClientboundPackets1_20_5.class, ServerboundPackets1_20_3.class, ServerboundPackets1_20_5.class); + super(ClientboundPacket1_20_3.class, ClientboundPacket1_20_5.class, ServerboundPacket1_20_3.class, ServerboundPacket1_20_5.class); } @Override protected void registerPackets() { super.registerPackets(); - final TagRewriter tagRewriter = new TagRewriter<>(this); + final TagRewriter tagRewriter = new TagRewriter<>(this); tagRewriter.registerGeneric(ClientboundPackets1_20_3.TAGS); - tagRewriter.registerGeneric(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_TAGS); + tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_3.UPDATE_TAGS); - final SoundRewriter soundRewriter = new SoundRewriter<>(this); + final SoundRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_3.SOUND); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_3.ENTITY_SOUND); @@ -81,11 +85,8 @@ public final class Protocol1_20_5To1_20_3 extends AbstractProtocol createPacketTypesProvider() { + return new SimplePacketTypesProvider<>( + packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_3.class, ClientboundConfigurationPackets1_20_3.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class), + packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_3.class, ServerboundConfigurationPackets1_20_2.class), + packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class) + ); } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundConfigurationPackets1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundConfigurationPackets1_20_5.java index 9c1757ff2..9726b23f5 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundConfigurationPackets1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundConfigurationPackets1_20_5.java @@ -17,10 +17,9 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet; -import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.State; -public enum ClientboundConfigurationPackets1_20_5 implements ClientboundPacketType { +public enum ClientboundConfigurationPackets1_20_5 implements ClientboundPacket1_20_5 { COOKIE_REQUEST, // 0x00 CUSTOM_PAYLOAD, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPacket1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPacket1_20_5.java new file mode 100644 index 000000000..9131cdcaf --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPacket1_20_5.java @@ -0,0 +1,23 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and 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.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet; + +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; + +public interface ClientboundPacket1_20_5 extends ClientboundPacketType { +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPackets1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPackets1_20_5.java index 8ea83f2cb..dc9f8e57b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPackets1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ClientboundPackets1_20_5.java @@ -17,9 +17,7 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet; -import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; - -public enum ClientboundPackets1_20_5 implements ClientboundPacketType { +public enum ClientboundPackets1_20_5 implements ClientboundPacket1_20_5 { BUNDLE, // 0x00 SPAWN_ENTITY, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundConfigurationPackets1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundConfigurationPackets1_20_5.java index 5248a7e98..4eb60d6f2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundConfigurationPackets1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundConfigurationPackets1_20_5.java @@ -17,10 +17,9 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet; -import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.protocol.packet.State; -public enum ServerboundConfigurationPackets1_20_5 implements ServerboundPacketType { +public enum ServerboundConfigurationPackets1_20_5 implements ServerboundPacket1_20_5 { CLIENT_INFORMATION, // 0x00 COOKIE_RESPONSE, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPacket1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPacket1_20_5.java new file mode 100644 index 000000000..7937e5400 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPacket1_20_5.java @@ -0,0 +1,23 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and 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.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet; + +import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; + +public interface ServerboundPacket1_20_5 extends ServerboundPacketType { +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPackets1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPackets1_20_5.java index 31d3d0646..a981f488d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPackets1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/packet/ServerboundPackets1_20_5.java @@ -17,9 +17,7 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet; -import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; - -public enum ServerboundPackets1_20_5 implements ServerboundPacketType { +public enum ServerboundPackets1_20_5 implements ServerboundPacket1_20_5 { TELEPORT_CONFIRM, // 0x00 QUERY_BLOCK_NBT, // 0x01 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index 70bd00d3d..af62f6190 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -24,15 +24,17 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPackets1_20_5; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter; import com.viaversion.viaversion.util.Key; -public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter { +public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter { public BlockItemPacketRewriter1_20_5(final Protocol1_20_5To1_20_3 protocol) { super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY); @@ -40,7 +42,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); + final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); blockRewriter.registerBlockAction(ClientboundPackets1_20_3.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_20_3.BLOCK_CHANGE); blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_3.MULTI_BLOCK_CHANGE); @@ -134,7 +136,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter recipeRewriter = new RecipeRewriter1_20_3<>(protocol); + final RecipeRewriter1_20_3 recipeRewriter = new RecipeRewriter1_20_3<>(protocol); protocol.registerClientbound(ClientboundPackets1_20_3.DECLARE_RECIPES, wrapper -> { final int size = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < size; i++) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index 8c45c9189..7af32caae 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -22,17 +22,18 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.data.entity.DimensionData; import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_20_3; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.AttributeMappings; @@ -41,7 +42,7 @@ import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.util.Key; import java.util.Map; -public final class EntityPacketRewriter1_20_5 extends EntityRewriter { +public final class EntityPacketRewriter1_20_5 extends EntityRewriter { public EntityPacketRewriter1_20_5(final Protocol1_20_5To1_20_3 protocol) { super(protocol); @@ -53,7 +54,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java index 7d6c47179..63b4c392c 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java @@ -24,7 +24,6 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.util.Key; @@ -150,10 +149,6 @@ public class TagRewriter { protocol.registerClientbound(packetType, getGenericHandler()); } - public void registerGeneric(State state, ClientboundPacketType packetType) { - protocol.registerClientbound(state, packetType, getGenericHandler()); - } - public PacketHandler getHandler(@Nullable RegistryType readUntilType) { return wrapper -> { for (RegistryType type : RegistryType.getValues()) { diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java b/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java index 4c1b4bb42..ce3e62634 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java +++ b/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java @@ -22,15 +22,11 @@ import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.AbstractProtocol; -import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; -import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; -import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.data.entity.EntityTrackerBase; -import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5; -import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundConfigurationPackets1_20_5; -import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPackets1_20_5; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -39,13 +35,13 @@ import com.viaversion.viaversion.template.protocols.rewriter.EntityPacketRewrite // Placeholders to replace (in the entire package): // Protocol1_99To_98, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99 -// ClientboundPackets1_20_5 -// ServerboundPackets1_20_5 +// ClientboundPacket1_20_5 +// ServerboundPacket1_20_5 // ClientboundConfigurationPackets1_20_3 // ServerboundConfigurationPackets1_20_2 // Entity1_19_4Types (MAPPED type) // 1.99, 1.98 -public final class Protocol1_99To_98 extends AbstractProtocol { +public final class Protocol1_99To_98 extends AbstractProtocol { public static final MappingData MAPPINGS = new MappingDataBase("1.98", "1.99"); private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this); @@ -53,7 +49,7 @@ public final class Protocol1_99To_98 extends AbstractProtocol tagRewriter = new TagRewriter<>(this); + final TagRewriter tagRewriter = new TagRewriter<>(this); tagRewriter.registerGeneric(ClientboundPackets1_20_5.TAGS); - tagRewriter.registerGeneric(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_TAGS); + tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS); // Registers sound id changes - final SoundRewriter soundRewriter = new SoundRewriter<>(this); + final SoundRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_5.SOUND); soundRewriter.register1_19_3Sound(ClientboundPackets1_20_5.ENTITY_SOUND); @@ -130,14 +126,4 @@ public final class Protocol1_99To_98 extends AbstractProtocol { +public final class BlockItemPacketRewriter1_99 extends ItemRewriter { public BlockItemPacketRewriter1_99(final Protocol1_99To_98 protocol) { super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY); @@ -41,7 +43,7 @@ public final class BlockItemPacketRewriter1_99 extends ItemRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); + final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); blockRewriter.registerBlockAction(ClientboundPackets1_20_5.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_20_5.BLOCK_CHANGE); blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_5.MULTI_BLOCK_CHANGE); diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java b/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java index cdc85647b..fc50f2dbf 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java +++ b/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java @@ -19,11 +19,11 @@ package com.viaversion.viaversion.template.protocols.rewriter; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; -import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; -import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.template.protocols.Protocol1_99To_98; @@ -31,7 +31,7 @@ import com.viaversion.viaversion.template.protocols.Protocol1_99To_98; // Replace if needed // Types1_OLD // Types1_20_5 -public final class EntityPacketRewriter1_99 extends EntityRewriter { +public final class EntityPacketRewriter1_99 extends EntityRewriter { public EntityPacketRewriter1_99(final Protocol1_99To_98 protocol) { super(protocol); @@ -44,7 +44,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter