diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java new file mode 100644 index 0000000..2065cb5 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java @@ -0,0 +1,18 @@ +package land.chipmunk.chipmunkmod.mixin; + +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 net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.text.Text; + +@Mixin(net.minecraft.network.ClientConnection.class) +public class ClientConnectionMixin { + @Inject(at = @At("HEAD"), method = "disconnect", cancellable = true) + public void disconnect (Text disconnectReason, CallbackInfo ci) { + if (disconnectReason == ClientPlayNetworkHandlerAccessor.chatValidationFailedText()) { + ci.cancel(); + } + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java new file mode 100644 index 0000000..22576d9 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java @@ -0,0 +1,11 @@ +package land.chipmunk.chipmunkmod.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import net.minecraft.text.Text; + +@Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) +public interface ClientPlayNetworkHandlerAccessor { + @Accessor("CHAT_VALIDATION_FAILED_TEXT") + public static Text chatValidationFailedText () { throw new AssertionError(); } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 53f3e39..e36dc97 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -7,7 +7,9 @@ ], "client": [ "ChatScreenMixin", - "ChatInputSuggestorMixin" + "ChatInputSuggestorMixin", + "ClientPlayNetworkHandlerAccessor", + "ClientConnectionMixin" ], "injectors": { "defaultRequire": 1