
Chat Lag Fix - Fixing Chat Lags in Minecraft
This mod solves the problem of Minecraft client freezes when receiving chat messages, caused by the peculiarities of the player blocking system.
Important Version Information
ATTENTION: Starting from version 1.18, this mod is no longer required! Mojang developers have fixed the bug in their API that was causing an error to be returned instead of an empty list. Minecraft now loads the blocked players list once when entering the world. However, the mod may slightly speed up world loading by saving time on the HTTP request, especially with a slow internet connection.
Official confirmation of the bug fix from a Mojang employee is available at: https://bugs.mojang.com/browse/WEB-5587?focusedCommentId=1134973&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-1134973
The problem continues to affect versions 1.17 and 1.16, but only manifests when receiving the first chat message: https://bugs.mojang.com/browse/MC-218167
Technical Operation Features
When receiving a chat message, Minecraft sends an HTTP request in the rendering thread to check your blocked players list. The current frame does not complete rendering until this request finishes, causing a sharp performance drop. This mod allows chat messages to pass through until the block list can be retrieved.
Causes of the Problem
Why did this problem appear now and not before? Changes occurred in Mojang's API. When entering the world, the block list usually loaded normally, but Mojang's API started returning errors for users who switched to Microsoft accounts, forcing the system to re-request the block list at 2-minute intervals when receiving messages.
Detailed explanation of the bug cause with comments
// Simplified view of the code private static final long BLOCKLIST_REQUEST_COOLDOWN = 120; private Instant nextRequest; private final blockList Set; // This method is called when receiving a chat message public boolean isBlockedPlayer(UUID playerID) { // If we don't have the blocklist yet, fetch it // Note that when there's an error, fetchBlockList returns null // if (this.blockList == null) { this.blockList = fetchBlockList(); // If we still don't have it, assume the player is not blocked if (this.blockList == null) { return false; } } return this.blockList.contains(playerID); } public Set fetchBlockList() { // Only check at least every 2 minutes. // This is why lags occur only every 2 minutes or later if (this.nextRequest == null || Instant.now().isAfter(this.nextRequest)) { return null; } // Reset the 2 minute timer this.nextRequest = Instant.now().plusSeconds(BLOCKLIST_REQUEST_COOLDOWN); try { // Make the HTTP request BlockListResponse response = minecraftClient.get(routeBlocklist, BlockListResponse.class); return response.getBlockedProfiles(); } catch (/ exception /) { // If there's an error return null return null; } }
If you want to study the source code yourself, refer to com.mojang.authlib.yggdrasil.YggdrasilUserApiService, remembering that these methods are called in the rendering thread, blocking frame completion.
GIF demonstration of the problem
