Skip to content

Commit

Permalink
Combine ViaVersion injections into one mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 16, 2023
1 parent bf2a1ab commit f3151e8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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));
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3151e8

Please sign in to comment.