From 78bce8895a0772545a209595da3d1269f5f42c6d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 18 Jan 2023 18:11:59 +0100 Subject: [PATCH] 23w03a --- build.gradle.kts | 2 +- .../api/ViaBackwardsPlatform.java | 5 +- .../Protocol1_19_3To1_19_4.java | 73 +++++++++++++++ .../data/EntityPackets1_19_4.java | 92 +++++++++++++++++++ gradle/libs.versions.toml | 8 +- 5 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java diff --git a/build.gradle.kts b/build.gradle.kts index fbcc751a..854177d9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { allprojects { group = "com.viaversion" - version = "4.5.2-SNAPSHOT" + version = "4.6.0-23w03a-SNAPSHOT" description = "Allow older clients to join newer server versions." } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index e1108f3c..88e89425 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -48,6 +48,7 @@ import com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.Protocol1_17To1 import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.Protocol1_18_2To1_19; import com.viaversion.viabackwards.protocol.protocol1_18to1_18_2.Protocol1_18To1_18_2; import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_1To1_19_3; +import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.Protocol1_19_3To1_19_4; import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1; import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import com.viaversion.viaversion.api.Via; @@ -60,7 +61,7 @@ import java.util.logging.Logger; public interface ViaBackwardsPlatform { - String MINIMUM_VV_VERSION = "4.5.0"; + String MINIMUM_VV_VERSION = "4.6.0"; String IMPL_VERSION = "$IMPL_VERSION"; /** @@ -120,8 +121,8 @@ public interface ViaBackwardsPlatform { protocolManager.registerProtocol(new Protocol1_18_2To1_19(), ProtocolVersion.v1_18_2, ProtocolVersion.v1_19); protocolManager.registerProtocol(new Protocol1_19To1_19_1(), ProtocolVersion.v1_19, ProtocolVersion.v1_19_1); - protocolManager.registerProtocol(new Protocol1_19_1To1_19_3(), ProtocolVersion.v1_19_1, ProtocolVersion.v1_19_3); + protocolManager.registerProtocol(new Protocol1_19_3To1_19_4(), ProtocolVersion.v1_19_3, ProtocolVersion.v1_19_4); } /** diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java new file mode 100644 index 00000000..726d7268 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java @@ -0,0 +1,73 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2023 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.viabackwards.protocol.protocol1_19_3to1_19_4; + +import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.data.EntityPackets1_19_4; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.data.MappingData; +import com.viaversion.viaversion.api.data.MappingDataBase; +import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_3Types; +import com.viaversion.viaversion.api.protocol.AbstractProtocol; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.data.entity.EntityTrackerBase; +import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; +import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; +import com.viaversion.viaversion.rewriter.CommandRewriter; + +public final class Protocol1_19_3To1_19_4 extends AbstractProtocol { + + private static final MappingData MAPPINGS = new MappingDataBase("1.19.3", "1.19.3"); + private final EntityPackets1_19_4 entityRewriter = new EntityPackets1_19_4(this); + + public Protocol1_19_3To1_19_4() { + super(ClientboundPackets1_19_4.class, ClientboundPackets1_19_3.class, ServerboundPackets1_19_4.class, ServerboundPackets1_19_3.class); + } + + @Override + protected void registerPackets() { + // TODO fallback field in components + entityRewriter.register(); + + final CommandRewriter commandRewriter = new CommandRewriter(this) { + @Override + public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception { + if (argumentType.equals("minecraft:time")) { + wrapper.read(Type.INT); // Minimum + } else { + super.handleArgument(wrapper, argumentType); + } + } + }; + commandRewriter.registerDeclareCommands1_19(ClientboundPackets1_19_4.DECLARE_COMMANDS); + + cancelClientbound(ClientboundPackets1_19_4.BUNDLE); + } + + @Override + public void init(final UserConnection user) { + addEntityTracker(user, new EntityTrackerBase(user, Entity1_19_3Types.PLAYER)); + } + + @Override + public MappingData getMappingData() { + return MAPPINGS; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java new file mode 100644 index 00000000..1f4c712e --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/data/EntityPackets1_19_4.java @@ -0,0 +1,92 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2023 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.viabackwards.protocol.protocol1_19_3to1_19_4.data; + +import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.Protocol1_19_3To1_19_4; +import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_3Types; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; +import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; +import com.viaversion.viaversion.rewriter.EntityRewriter; + +public final class EntityPackets1_19_4 extends EntityRewriter { + + public EntityPackets1_19_4(final Protocol1_19_3To1_19_4 protocol) { + super(protocol); + } + + @Override + public void registerPackets() { + protocol.registerClientbound(ClientboundPackets1_19_4.JOIN_GAME, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // Entity id + map(Type.BOOLEAN); // Hardcore + map(Type.UNSIGNED_BYTE); // Gamemode + map(Type.BYTE); // Previous Gamemode + map(Type.STRING_ARRAY); // World List + map(Type.NBT); // Dimension registry + map(Type.STRING); // Dimension key + map(Type.STRING); // World + handler(dimensionDataHandler()); + handler(biomeSizeTracker()); + handler(worldDataTrackerHandlerByKey()); + handler(wrapper -> { + final CompoundTag registry = wrapper.get(Type.NBT, 0); + final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome"); + final ListTag biomes = biomeRegistry.get("value"); + for (final Tag biomeTag : biomes) { + final CompoundTag biomeData = ((CompoundTag) biomeTag).get("element"); + final ByteTag hasPrecipitation = biomeData.get("has_precipitation"); + biomeData.put("precipitation", new StringTag(hasPrecipitation.asByte() == 1 ? "rain" : "none")); + } + }); + } + }); + + protocol.registerClientbound(ClientboundPackets1_19_4.HIT_ANIMATION, ClientboundPackets1_19_3.ENTITY_ANIMATION, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // Entity id + read(Type.FLOAT); // Yaw + create(Type.UNSIGNED_BYTE, (short) 1); // Hit + } + }); + + protocol.registerClientbound(ClientboundPackets1_19_4.RESPAWN, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING); // Dimension + map(Type.STRING); // World + handler(worldDataTrackerHandlerByKey()); + } + }); + } + + @Override + public EntityType typeFromId(final int type) { + return Entity1_19_3Types.getTypeFromId(type); + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1b273a33..7c9858e6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,20 +3,20 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "4.5.0" +viaver = "4.6.0-23w03a-SNAPSHOT" # Common provided netty = "4.0.20.Final" guava = "17.0" log4j = "2.8.1" -checkerQual = "3.18.0" +checkerQual = "3.29.0" # Platforms paper = "1.16.5-R0.1-SNAPSHOT" -bungee = "1.16-R0.5-SNAPSHOT" +bungee = "1.19-R0.1-SNAPSHOT" sponge = "8.0.0" -velocity = "3.1.0-SNAPSHOT" +velocity = "3.1.1" fabricLoader = "0.11.6"