Switch to Yarn mappings 26.2+build.3
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Loom rejected officialMojangMappings() with a non-obfuscated environment error, and Mojang client_mappings are not published for 26.2 yet. Pin Yarn at 26.2+build.3 via the new yarn_mappings property and rewrite the client entrypoint with Yarn names: MinecraftClient, Text, Formatting, inGameHud.getChatHud(), getSession().getUsername().
This commit is contained in:
@@ -5,9 +5,9 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -49,8 +49,8 @@ public final class ClientIrcMod implements ClientModInitializer {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
IrcService.DisplayLine line;
|
||||
while ((line = service.pollLine()) != null) {
|
||||
ChatFormatting color = line.system() ? ChatFormatting.GRAY : ChatFormatting.AQUA;
|
||||
pushClientChat(client, Component.literal(line.text()).withStyle(color));
|
||||
Formatting color = line.system() ? Formatting.GRAY : Formatting.AQUA;
|
||||
pushClientChat(client, Text.literal(line.text()).formatted(color));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -63,17 +63,17 @@ public final class ClientIrcMod implements ClientModInitializer {
|
||||
return false;
|
||||
}
|
||||
|
||||
Minecraft client = Minecraft.getInstance();
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
String argument = trimmed.length() == COMMAND_PREFIX.length() ? "" : trimmed.substring(COMMAND_PREFIX.length()).trim();
|
||||
|
||||
if (argument.isBlank()) {
|
||||
pushClientChat(client, Component.literal("[IRC] Usage: .irc <message> | .irc status | .irc reconnect | .irc reload").withStyle(ChatFormatting.YELLOW));
|
||||
pushClientChat(client, Text.literal("[IRC] Usage: .irc <message> | .irc status | .irc reconnect | .irc reload").formatted(Formatting.YELLOW));
|
||||
return true;
|
||||
}
|
||||
|
||||
if ("status".equalsIgnoreCase(argument)) {
|
||||
String status = service.isConnected() ? "connected" : "disconnected";
|
||||
pushClientChat(client, Component.literal("[IRC] " + status + " | " + config.host + ":" + config.port + " | clientName=" + config.clientName).withStyle(ChatFormatting.YELLOW));
|
||||
pushClientChat(client, Text.literal("[IRC] " + status + " | " + config.host + ":" + config.port + " | clientName=" + config.clientName).formatted(Formatting.YELLOW));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ public final class ClientIrcMod implements ClientModInitializer {
|
||||
String playerName = resolvePlayerName(client);
|
||||
IO_EXECUTOR.execute(() -> {
|
||||
boolean connected = service.reconnect(playerName);
|
||||
ChatFormatting color = connected ? ChatFormatting.GREEN : ChatFormatting.RED;
|
||||
pushClientChat(client, Component.literal("[IRC] reconnect " + (connected ? "ok" : "failed")).withStyle(color));
|
||||
Formatting color = connected ? Formatting.GREEN : Formatting.RED;
|
||||
pushClientChat(client, Text.literal("[IRC] reconnect " + (connected ? "ok" : "failed")).formatted(color));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -90,40 +90,40 @@ public final class ClientIrcMod implements ClientModInitializer {
|
||||
if ("reload".equalsIgnoreCase(argument)) {
|
||||
config = IrcConfig.load(FabricLoader.getInstance().getConfigDir().resolve("clientirc.json"));
|
||||
service.updateConfig(config);
|
||||
pushClientChat(client, Component.literal("[IRC] config reloaded").withStyle(ChatFormatting.YELLOW));
|
||||
pushClientChat(client, Text.literal("[IRC] config reloaded").formatted(Formatting.YELLOW));
|
||||
return true;
|
||||
}
|
||||
|
||||
String playerName = resolvePlayerName(client);
|
||||
IO_EXECUTOR.execute(() -> {
|
||||
if (!service.ensureConnected(playerName)) {
|
||||
pushClientChat(client, Component.literal("[IRC] server is offline or config is wrong").withStyle(ChatFormatting.RED));
|
||||
pushClientChat(client, Text.literal("[IRC] server is offline or config is wrong").formatted(Formatting.RED));
|
||||
return;
|
||||
}
|
||||
if (!service.sendChat(playerName, argument)) {
|
||||
pushClientChat(client, Component.literal("[IRC] send failed").withStyle(ChatFormatting.RED));
|
||||
pushClientChat(client, Text.literal("[IRC] send failed").formatted(Formatting.RED));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void pushClientChat(Minecraft client, Component text) {
|
||||
private static void pushClientChat(MinecraftClient client, Text text) {
|
||||
if (client == null) {
|
||||
return;
|
||||
}
|
||||
client.execute(() -> {
|
||||
if (client.gui != null && client.gui.getChat() != null) {
|
||||
client.gui.getChat().addMessage(text);
|
||||
if (client.inGameHud != null && client.inGameHud.getChatHud() != null) {
|
||||
client.inGameHud.getChatHud().addMessage(text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static String resolvePlayerName(Minecraft client) {
|
||||
private static String resolvePlayerName(MinecraftClient client) {
|
||||
if (client != null && client.player != null) {
|
||||
return client.player.getGameProfile().getName();
|
||||
}
|
||||
if (client != null && client.getUser() != null) {
|
||||
return client.getUser().getName();
|
||||
if (client != null && client.getSession() != null) {
|
||||
return client.getSession().getUsername();
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user