Fix "Cannot register receiver while client is not logging in!"

Since MC provides no reliable way to get the connection while still in the login
phase, Fabric API tries to determine it either from MinecraftClient's connection
field (for the integrated server) or from the ConnectScreen (for multiplayer).
However, neither is present during a replay, leading to the aforementioned
error.

To fix this, we store our ClientConnection in MinecraftClient's connection
field. This should have no significant effect on vanilla behavior.

Also remove the dead Forge 1.14 code which was in the same place.
This commit is contained in:
Jonas Herzig
2021-06-05 13:34:48 +02:00
parent 25a6cdc502
commit 5f2dca08d1
2 changed files with 8 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package com.replaymod.core.mixin; package com.replaymod.core.mixin;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.network.ClientConnection;
import net.minecraft.util.crash.CrashReport; import net.minecraft.util.crash.CrashReport;
import net.minecraft.client.render.RenderTickCounter; import net.minecraft.client.render.RenderTickCounter;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -50,4 +51,9 @@ public interface MinecraftAccessor {
//$$ @Accessor //$$ @Accessor
//$$ List<IResourcePack> getDefaultResourcePacks(); //$$ List<IResourcePack> getDefaultResourcePacks();
//#endif //#endif
//#if MC>=11400
@Accessor
void setConnection(ClientConnection connection);
//#endif
} }

View File

@@ -308,8 +308,8 @@ public class ReplayHandler {
channel.pipeline().addLast("packet_handler", networkManager); channel.pipeline().addLast("packet_handler", networkManager);
channel.pipeline().fireChannelActive(); channel.pipeline().fireChannelActive();
//#if MC>=11400 && MC<11400 //#if MC>=11400
//$$ NetworkHooks.registerClientLoginChannel(networkManager); ((MinecraftAccessor) mc).setConnection(networkManager);
//#endif //#endif
} }