From f274d643a5d84b99d3141fe4879647a942756631 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Sat, 19 Oct 2024 01:47:38 +0200 Subject: [PATCH] Emulate CLIENT_TICK_END packet --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 8 +++ .../task/ClientEndTickPacketTask.java | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/ClientEndTickPacketTask.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index a6182aec..d7ca0ec0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -29,8 +29,11 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.ClientEndTickPacketTask; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; +import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; @@ -147,6 +150,11 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol. + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.task; + +import com.viaversion.viabackwards.ViaBackwards; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.packet.State; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; +import io.netty.channel.Channel; +import java.util.logging.Level; + +public final class ClientEndTickPacketTask implements Runnable { + + @Override + public void run() { + for (final UserConnection user : Via.getManager().getConnectionManager().getConnections()) { + if (user.getProtocolInfo().getClientState() != State.PLAY || !user.getProtocolInfo().getPipeline().contains(Protocol1_21_2To1_21.class)) { + continue; + } + final Channel channel = user.getChannel(); + channel.eventLoop().submit(() -> { + if (!channel.isActive()) { + return; + } + try { + final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, user); + clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class); + } catch (Throwable t) { + ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending client tick end packet.", t); + } + }); + } + } +}