Skip to content

Commit

Permalink
refactor(legacy): usage of ChatComponentText and DecimalFormat (#5010)
Browse files Browse the repository at this point in the history
  • Loading branch information
MukjepScarlet authored Dec 22, 2024
1 parent 09fd2c3 commit 9e058a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package net.ccbluex.liquidbounce.injection.forge.mixins.gui;

import com.google.gson.JsonObject;
import com.mojang.authlib.Agent;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
Expand All @@ -28,7 +27,7 @@
import net.minecraft.client.gui.GuiDisconnected;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.Session;
import net.minecraftforge.fml.client.config.GuiSlider;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -47,8 +46,6 @@

@Mixin(GuiDisconnected.class)
public abstract class MixinGuiDisconnected extends MixinGuiScreen {
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#0");

@Shadow
private int field_175353_i;

Expand Down Expand Up @@ -113,10 +110,7 @@ private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) throws
return null;
}, e -> {
mc.addScheduledTask(() -> {
final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", e.getMessage());

mc.displayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), e.getMessage(), IChatComponent.Serializer.jsonToComponent(jsonObject.toString())));
mc.displayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), e.getMessage(), new ChatComponentText(e.getMessage())));
});
return null;
}, () -> null));
Expand Down Expand Up @@ -171,7 +165,7 @@ private void updateSliderText() {
if (!AutoReconnect.INSTANCE.isEnabled()) {
autoReconnectDelaySlider.displayString = "AutoReconnect: Off";
} else {
autoReconnectDelaySlider.displayString = "AutoReconnect: " + DECIMAL_FORMAT.format(AutoReconnect.INSTANCE.getDelay() / 1000.0) + "s";
autoReconnectDelaySlider.displayString = "AutoReconnect: " + Math.floor(AutoReconnect.INSTANCE.getDelay() / 1000.0) + "s";
}
}

Expand Down
14 changes: 3 additions & 11 deletions src/main/java/net/ccbluex/liquidbounce/utils/client/ClientUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
*/
package net.ccbluex.liquidbounce.utils.client

import com.google.gson.JsonObject
import net.ccbluex.liquidbounce.LiquidBounce.CLIENT_NAME
import net.minecraft.client.settings.GameSettings
import net.minecraft.network.NetworkManager
import net.minecraft.network.login.client.C01PacketEncryptionResponse
import net.minecraft.network.login.server.S01PacketEncryptionRequest
import net.minecraft.util.IChatComponent
import net.minecraft.util.ChatComponentText
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import org.apache.logging.log4j.LogManager
Expand Down Expand Up @@ -51,15 +50,8 @@ object ClientUtils : MinecraftInstance {
}

fun displayChatMessage(message: String) {
if (mc.thePlayer == null) {
LOGGER.info("(MCChat) $message")
return
}

val prefixMessage = "§8[§9§l$CLIENT_NAME§8]§r $message"
val jsonObject = JsonObject()
jsonObject.addProperty("text", prefixMessage)
mc.thePlayer.addChatMessage(IChatComponent.Serializer.jsonToComponent(jsonObject.toString()))
mc.thePlayer?.addChatMessage(ChatComponentText("§8[§9§l$CLIENT_NAME§8]§r $message"))
?: LOGGER.info("(MCChat) $message")
}
}

Expand Down

0 comments on commit 9e058a5

Please sign in to comment.