diff --git a/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/MixinClientConnection.java b/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/MixinClientConnection.java index e42ec38f..d11aee34 100644 --- a/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/MixinClientConnection.java +++ b/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/MixinClientConnection.java @@ -1,8 +1,20 @@ package com.viaversion.fabric.mc120.mixin.pipeline; +import com.viaversion.fabric.common.handler.CommonTransformer; +import com.viaversion.fabric.common.handler.FabricDecodeHandler; +import com.viaversion.fabric.common.handler.FabricEncodeHandler; import com.viaversion.fabric.common.handler.PipelineReorderEvent; +import com.viaversion.fabric.common.protocol.HostnameParserProtocol; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.ProtocolPipeline; +import com.viaversion.viaversion.connection.UserConnectionImpl; +import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import io.netty.channel.Channel; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; import net.minecraft.network.ClientConnection; +import net.minecraft.network.NetworkSide; +import net.minecraft.network.handler.PacketSizeLogger; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -19,4 +31,19 @@ public class MixinClientConnection { private void reorderCompression(int compressionThreshold, boolean rejectBad, CallbackInfo ci) { channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent()); } + + @Inject(method = "addHandlers", at = @At("RETURN")) + private static void onAddHandlers(ChannelPipeline pipeline, NetworkSide side, PacketSizeLogger packetSizeLogger, CallbackInfo ci) { + final Channel channel = pipeline.channel(); + if (channel instanceof SocketChannel) { + UserConnection user = new UserConnectionImpl(channel, side == NetworkSide.CLIENTBOUND); + ProtocolPipeline protocolPipeline = new ProtocolPipelineImpl(user); + if (user.isClientSide()) { + protocolPipeline.add(HostnameParserProtocol.INSTANCE); + } + + pipeline.addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user)); + pipeline.addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user)); + } + } } diff --git a/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/MixinServerNetworkIoChInit.java b/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/MixinServerNetworkIoChInit.java deleted file mode 100644 index 6cfd6141..00000000 --- a/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/MixinServerNetworkIoChInit.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.viaversion.fabric.mc120.mixin.pipeline; - -import com.viaversion.fabric.common.handler.CommonTransformer; -import com.viaversion.fabric.common.handler.FabricDecodeHandler; -import com.viaversion.fabric.common.handler.FabricEncodeHandler; -import com.viaversion.viaversion.connection.UserConnectionImpl; -import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; -import io.netty.channel.Channel; -import io.netty.channel.socket.SocketChannel; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.viaversion.viaversion.api.connection.UserConnection; - -@Mixin(targets = "net.minecraft.server.ServerNetworkIo$1") -public class MixinServerNetworkIoChInit { - @Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false) - private void onInitChannel(Channel channel, CallbackInfo ci) { - if (channel instanceof SocketChannel) { - UserConnection user = new UserConnectionImpl(channel); - new ProtocolPipelineImpl(user); - - channel.pipeline().addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user)); - channel.pipeline().addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user)); - } - } -} diff --git a/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/client/MixinClientConnectionChInit.java b/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/client/MixinClientConnectionChInit.java deleted file mode 100644 index b60113df..00000000 --- a/viafabric-mc120/src/main/java/com/viaversion/fabric/mc120/mixin/pipeline/client/MixinClientConnectionChInit.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.viaversion.fabric.mc120.mixin.pipeline.client; - -import com.viaversion.fabric.common.handler.FabricDecodeHandler; -import com.viaversion.fabric.common.handler.FabricEncodeHandler; -import com.viaversion.fabric.common.handler.CommonTransformer; -import com.viaversion.fabric.common.protocol.HostnameParserProtocol; -import com.viaversion.viaversion.connection.UserConnectionImpl; -import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; -import io.netty.channel.Channel; -import io.netty.channel.socket.SocketChannel; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.viaversion.viaversion.api.connection.UserConnection; - -@Mixin(targets = "net.minecraft.network.ClientConnection$1") -public class MixinClientConnectionChInit { - @Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false) - private void onInitChannel(Channel channel, CallbackInfo ci) { - if (channel instanceof SocketChannel) { - UserConnection user = new UserConnectionImpl(channel, true); - new ProtocolPipelineImpl(user).add(HostnameParserProtocol.INSTANCE); - - channel.pipeline() - .addBefore("encoder", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user)) - .addBefore("decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user)); - } - } -} diff --git a/viafabric-mc120/src/main/resources/mixins.viafabric120.pipeline.json b/viafabric-mc120/src/main/resources/mixins.viafabric120.pipeline.json index 6a51fa96..e1ed3a08 100644 --- a/viafabric-mc120/src/main/resources/mixins.viafabric120.pipeline.json +++ b/viafabric-mc120/src/main/resources/mixins.viafabric120.pipeline.json @@ -3,12 +3,10 @@ "compatibilityLevel": "JAVA_17", "package": "com.viaversion.fabric.mc120.mixin.pipeline", "mixins": [ - "MixinClientConnection", - "MixinServerNetworkIoChInit" + "MixinClientConnection" ], "client": [ - "client.MixinClientConnection", - "client.MixinClientConnectionChInit" + "client.MixinClientConnection" ], "injectors": { "defaultRequire": 1