Skip to content

Commit

Permalink
Replace JOIN event with our own mixin
Browse files Browse the repository at this point in the history
Fixes a weird issue where packets can't be received during the `JOIN` event, making the client "miss" the server's response
  • Loading branch information
tal5 committed Jun 4, 2023
1 parent 5aa9f89 commit b58b9ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
@@ -0,0 +1,17 @@
package com.denizenscript.clientizen.mixin;

import com.denizenscript.clientizen.network.NetworkManager;
import net.minecraft.client.network.ClientPlayNetworkHandler;
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;

@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {

@Inject(method = "onGameJoin", at = @At("TAIL"))
private void clientizen$onGameJoin(CallbackInfo ci) {
NetworkManager.onConnect();
}
}
Expand Up @@ -2,7 +2,6 @@

import com.denizenscript.denizencore.utilities.CoreConfiguration;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.util.Identifier;
Expand All @@ -11,13 +10,14 @@ public class NetworkManager {

public static void init() {
Debug.log("Initializing NetworkManager...");
ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> {
debugNetwork("Sending join confirmation packet...");
send(Channels.SEND_CONFIRM, null);
}));
ScriptNetworking.init();
}

public static void onConnect() {
debugNetwork("Sending join confirmation packet...");
send(Channels.SEND_CONFIRM, null);
}

public static void registerInChannel(Identifier channel, ClientizenReceiver receiver) {
if (!ClientPlayNetworking.registerGlobalReceiver(channel, (client, handler, buf, responseSender) -> {
debugNetwork("Received plugin message on channel " + channel);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/clientizen.mixins.json
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_17",
"mixins": [],
"client": [
"ClientPlayNetworkHandlerMixin",
"KeyBindingMixin",
"MinecraftClientMixin",
"IntPropertyAccessor",
Expand Down

0 comments on commit b58b9ba

Please sign in to comment.