diff --git a/build.gradle b/build.gradle index 5ddf4e6..2c7905c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,19 @@ plugins { - id 'fabric-loom' version "${loom_version}" + id 'net.fabricmc.fabric-loom' version "${loom_version}" id 'maven-publish' - id 'io.freefair.lombok' version '8.10' + id 'io.freefair.lombok' version '9.5.0' } java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + toolchain { + languageVersion = JavaLanguageVersion.of(25) + } + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 +} + +lombok { + version = project.lombok_version } version = "${project.minecraft_version}-${project.mod_version}" @@ -23,41 +27,46 @@ if (file("extra.properties").exists()) { repositories { mavenCentral() maven { url 'https://masa.dy.fi/maven' } + maven { url 'https://masa.dy.fi/maven/sakura-ryoko' } maven { url 'https://maven.terraformersmc.com/releases/' } maven { url 'https://jitpack.io' } maven { url 'https://maven.wispforest.io' } - maven { url 'https://maven.fallenbreath.me/releases' } + maven { url 'https://maven.fallenbreath.me/releases' } + maven { url 'https://api.modrinth.com/maven' } } dependencies { + // No `mappings` line: 26.2 is distributed unobfuscated, so Loom uses the + // official names directly. For the same reason mod dependencies are declared + // with the plain configurations rather than `modImplementation` — the `mod*` + // ones invoke Loom's remapper, which then demands a mappings dependency that + // no longer exists for this Minecraft version. minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" - modImplementation "com.github.sakura-ryoko:malilib:${project.malilib_version}" - modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" + implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" + implementation "maven.modrinth:malilib:${project.malilib_version}" + compileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" implementation "com.github.DarkKronicle.Konstruct:addons:${project.konstruct_version}" implementation "com.github.DarkKronicle.Konstruct:core:${project.konstruct_version}" + include "com.github.DarkKronicle.Konstruct:addons:${project.konstruct_version}" + include "com.github.DarkKronicle.Konstruct:core:${project.konstruct_version}" implementation 'com.electronwill.night-config:toml:3.6.5' - // Transitive include 'com.electronwill.night-config:toml:3.6.5' include 'com.electronwill.night-config:core:3.6.5' - - include "com.github.DarkKronicle.Konstruct:addons:${project.konstruct_version}" - include "com.github.DarkKronicle.Konstruct:core:${project.konstruct_version}" - implementation "org.mariuszgromada.math:MathParser.org-mXparser:${project.mxparser_version}" include "org.mariuszgromada.math:MathParser.org-mXparser:${project.mxparser_version}" - implementation "io.github.maowimpl:owo:${project.owo_version}" - include "io.github.maowimpl:owo:${project.owo_version}" - implementation 'org.apache.commons:commons-csv:1.8' include 'org.apache.commons:commons-csv:1.8' + // No Java source in this repo imports owo, but Konstruct's bundled `addons` jar + // calls dev.maow.owo.util.OwOFactory at runtime, so it must stay on the jar-in-jar + // list or AdvancedChatKonstruct dies with NoClassDefFoundError. + implementation "io.github.maowimpl:owo:${project.owo_version}" + include "io.github.maowimpl:owo:${project.owo_version}" } processResources { @@ -70,14 +79,11 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - it.options.release = 21 + it.options.release = 25 + // Default cap is 100; during the 26.2 port we want the whole list at once. + it.options.compilerArgs << "-Xmaxerrs" << "10000" } -//task sourcesJar(type: Jar, dependsOn: classes) { -// classifier = "sources" -// from sourceSets.main.allSource -//} - tasks.register('sourcesJar', Jar) { dependsOn classes archiveClassifier.set('sources') @@ -85,7 +91,7 @@ tasks.register('sourcesJar', Jar) { } jar { - from "LICENSE.txt" + from "LICENSE.txt" } tasks.register('downloadExtra') { @@ -104,12 +110,13 @@ publishing { publications { mavenJava(MavenPublication) { artifactId = 'advancedchatcore' // Set artifact ID in lowercase - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar + // 26.2 needs no remapping, so `remapJar`/`remapSourcesJar` no longer + // exist and the plain jar tasks are the published artifacts. + artifact(jar) { + builtBy jar } artifact(sourcesJar) { - builtBy remapSourcesJar + builtBy sourcesJar } } } diff --git a/gradle.properties b/gradle.properties index 7da8f11..9b4b5b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,26 +1,27 @@ -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx3G # https://fabricmc.net/develop -minecraft_version=1.21.11 -yarn_mappings=1.21.11+build.4 -loader_version=0.18.4 -loom_version=1.15-SNAPSHOT -fabric_api_version=0.141.3+1.21.11 +# Minecraft 26.2 ships unobfuscated: there is no yarn or intermediary any more, +# so no `mappings` dependency is declared and the source uses Mojang names. +minecraft_version=26.2 +loader_version=0.19.3 +loom_version=1.17.+ +fabric_api_version=0.156.0+26.2 -mod_version=1.5.17-alpha.1 +mod_version=1.7.2-alpha.1 maven_group=com.arematics archives_base_name=AdvancedChatCore -# https://jitpack.io/#sakura-ryoko/malilib -malilib_version=1.21.11-0.27.5 +# https://modrinth.com/mod/malilib (sakura-ryoko builds) +malilib_version=0.29.3 # https://jitpack.io/com/github/DarkKronicle/Konstruct konstruct_version=2.0.3-build1 # https://repo.maven.apache.org/maven2/org/mariuszgromada/math/MathParser.org-mXparser mxparser_version=6.1.0 -# https://repo.maven.apache.org/maven2/io/github/maowimpl/owo -owo_version=2.0.0 # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu -modmenu_version=17.0.0-beta.2 +modmenu_version=20.0.1 +# https://projectlombok.org - 1.18.42+ is required for JDK 25 +lombok_version=1.18.46 modrinth_slug=advancedchatcore-next modrinth_id=iptu1EVO @@ -34,3 +35,4 @@ project_color=0x134bff changelog_hide_unimportant_commits=true changelog_max_commit_search=200 discord_webhook_changelog_line_limit=10 +owo_version=2.0.0 diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 0000000..e3ced56 --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,3 @@ +#This file is generated by updateDaemonJvm +#Minecraft 26.2 requires the Gradle daemon itself to run on Java 25. +toolchainVersion=25 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4185038..ec4c7ad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sun Jun 16 00:47:33 CEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 55e39a6..6369cb4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,3 +8,8 @@ pluginManagement { mavenCentral() } } + +// Lets Gradle download a JDK 25 toolchain automatically, so no system JDK 25 is required. +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' +} diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/AdvancedChatCore.java b/src/main/java/io/github/darkkronicle/advancedchatcore/AdvancedChatCore.java index 559041a..7ff5c37 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/AdvancedChatCore.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/AdvancedChatCore.java @@ -26,7 +26,7 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -66,13 +66,13 @@ public void onInitializeClient() { // Important to get first since configuration options depend on colors Colors.getInstance().load(); InitializationHandler.getInstance().registerInitializationHandler(new InitHandler()); - MinecraftClient client = MinecraftClient.getInstance(); + Minecraft client = Minecraft.getInstance(); ClientTickEvents.START_CLIENT_TICK.register( s -> { // Allow for delayed tasks to be added - SyncTaskQueue.getInstance().update(s.inGameHud.getTicks()); + SyncTaskQueue.getInstance().update(s.gui.hud.getGuiTicks()); // Make sure we're not in the sleeping screen while awake - if (client.currentScreen instanceof AdvancedSleepingChatScreen + if (client.gui.screen() instanceof AdvancedSleepingChatScreen && !client.player.isSleeping()) { GuiBase.openGui(null); } @@ -118,13 +118,13 @@ public static String getRandomString() { * @return The server address if connected, 'singleplayer' if singleplayer, 'none' if none. */ public static String getServer() { - MinecraftClient client = MinecraftClient.getInstance(); - if (client.isInSingleplayer()) { + Minecraft client = Minecraft.getInstance(); + if (client.isLocalServer()) { return "singleplayer"; } - if (client.getCurrentServerEntry() == null) { + if (client.getCurrentServer() == null) { return "none"; } - return client.getCurrentServerEntry().address; + return client.getCurrentServer().ip; } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java b/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java index 47b7dff..740644e 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/InitHandler.java @@ -28,8 +28,8 @@ import io.github.darkkronicle.advancedchatcore.util.TextUtil; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; import java.util.*; @@ -73,7 +73,7 @@ public void registerModHandlers() { new HashMap<>(); for (StringMatch bad : profanity) { insertions.put(bad, (current, match) -> - Text.literal("*".repeat(bad.end - bad.start)).fillStyle(current.getStyle()) + Component.literal("*".repeat(bad.end - bad.start)).withStyle(current.getStyle()) ); } text = TextUtil.replaceStrings(text, insertions); @@ -101,33 +101,35 @@ public void registerModHandlers() { InputHandler.getInstance().addDisplayName("core_general", "advancedchatcore.config.tab.hotkeysgeneral"); InputHandler.getInstance().add("core_general", ConfigStorage.Hotkeys.OPEN_CHAT.config, (action, key) -> { - if (MinecraftClient.getInstance().world == null) { + if (Minecraft.getInstance().level == null) { return true; } GuiBase.openGui(new AdvancedChatScreen("")); return true; }); InputHandler.getInstance().add("core_general", ConfigStorage.Hotkeys.OPEN_CHAT_WITH_LAST.config, (action, key) -> { - if (MinecraftClient.getInstance().world == null) { + if (Minecraft.getInstance().level == null) { return true; } GuiBase.openGui(new AdvancedChatScreen(0)); return true; }); InputHandler.getInstance().add("core_general", ConfigStorage.Hotkeys.OPEN_CHAT_FREE_MOVEMENT.config, (action, key) -> { - if (MinecraftClient.getInstance().world == null) { + if (Minecraft.getInstance().level == null) { return true; } // Manually update stuff so that movement keys are continued to be pressed - MinecraftClient client = MinecraftClient.getInstance(); - if (client.currentScreen != null) { - client.currentScreen.removed(); + Minecraft client = Minecraft.getInstance(); + if (client.gui.screen() != null) { + client.gui.screen().removed(); } - client.currentScreen = new AdvancedChatScreen(true); - client.mouse.unlockCursor(); - client.currentScreen.init(client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight()); - client.skipGameRender = false;; - client.updateWindowTitle(); + // 26.2 moved the current screen onto Gui and made the field private, so the + // old direct assignment (which deliberately skipped the normal open path) now + // has to go through Gui#setScreen. That handles init itself, so the manual + // init call is gone. Minecraft#noRender no longer exists. + client.gui.setScreen(new AdvancedChatScreen(true)); + client.mouseHandler.releaseMouse(); + client.updateTitle(); return true; }); InputHandler.getInstance().add("core_general", ConfigStorage.Hotkeys.TOGGLE_PERMANENT.config, (action, key) -> { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java index 1d1e7fb..99ce0ee 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedChatScreen.java @@ -21,19 +21,19 @@ import io.github.darkkronicle.advancedchatcore.util.ModifierKeyUtil; import io.github.darkkronicle.advancedchatcore.util.RowList; import lombok.Getter; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.input.CharInput; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.KeyMapping; +import com.mojang.blaze3d.platform.InputConstants; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; +import net.minecraft.util.Mth; import java.util.ArrayList; import java.util.List; @@ -66,7 +66,7 @@ public class AdvancedChatScreen extends GuiBase { @Override protected void closeGui(boolean showParent) { if (ConfigStorage.ChatScreen.PERSISTENT_TEXT.config.getBooleanValue()) { - last = chatField.getText(); + last = chatField.getValue(); } super.closeGui(showParent); } @@ -105,11 +105,11 @@ private Color4f getColor() { } public void resetCurrentMessage() { - this.messageHistorySize = this.client.inGameHud.getChatHud().getMessageHistory().size(); + this.messageHistorySize = this.minecraft.gui.hud.getChat().getRecentChat().size(); } @Override - public boolean charTyped(CharInput input) { + public boolean charTyped(CharacterEvent input) { if (passEvents) { return true; } @@ -123,13 +123,13 @@ public void initGui() { resetCurrentMessage(); this.chatField = new AdvancedTextField( - this.textRenderer, + this.font, 4, this.height - 12, this.width - 10, 12, - Text.translatable("chat.editBox")) { - protected MutableText getNarrationMessage() { + Component.translatable("chat.editBox")) { + protected MutableComponent getNarrationMessage() { return null; } }; @@ -138,19 +138,19 @@ protected MutableText getNarrationMessage() { } else { this.chatField.setMaxLength(256); } - this.chatField.setDrawsBackground(false); + this.chatField.setBordered(false); if (!this.originalChatText.isEmpty()) { this.chatField.setText(this.originalChatText); } else if (ConfigStorage.ChatScreen.PERSISTENT_TEXT.config.getBooleanValue() && !last.isEmpty()) { this.chatField.setText(last); } - this.chatField.setChangedListener(this::onChatFieldUpdate); + this.chatField.setResponder(this::onChatFieldUpdate); // Add settings button - rightSideButtons.add("settings", new IconButton(0, 0, 14, 64, Identifier.of(AdvancedChatCore.MOD_ID, "textures/gui/settings.png"), (button) -> GuiBase.openGui(GuiConfigHandler.getInstance().getDefaultScreen()))); + rightSideButtons.add("settings", new IconButton(0, 0, 14, 64, Identifier.fromNamespaceAndPath(AdvancedChatCore.MOD_ID, "textures/gui/settings.png"), (button) -> GuiBase.openGui(GuiConfigHandler.getInstance().getDefaultScreen()))); - this.addSelectableChild(this.chatField); + this.addWidget(this.chatField); this.setInitialFocus(this.chatField); @@ -158,8 +158,8 @@ protected MutableText getNarrationMessage() { section.initGui(); } - int originalX = client.getWindow().getScaledWidth() - 1; - int y = client.getWindow().getScaledHeight() - 30; + int originalX = minecraft.getWindow().getGuiScaledWidth() - 1; + int y = minecraft.getWindow().getGuiScaledHeight() - 30; for (int i = 0; i < rightSideButtons.rowSize(); i++) { List buttonList = rightSideButtons.get(i); int maxHeight = 0; @@ -173,7 +173,7 @@ protected MutableText getNarrationMessage() { y -= maxHeight + 1; } originalX = 1; - y = client.getWindow().getScaledHeight() - 30; + y = minecraft.getWindow().getGuiScaledHeight() - 30; for (int i = 0; i < leftSideButtons.rowSize(); i++) { List buttonList = leftSideButtons.get(i); int maxHeight = 0; @@ -193,7 +193,7 @@ protected MutableText getNarrationMessage() { } public void resize(int width, int height) { - String string = this.chatField.getText(); + String string = this.chatField.getValue(); this.init(width, height); this.setText(string); for (AdvancedChatScreenSection section : sections) { @@ -213,22 +213,22 @@ public void tick() { } private void onChatFieldUpdate(String chatText) { - String string = this.chatField.getText(); + String string = this.chatField.getValue(); for (AdvancedChatScreenSection section : sections) { section.onChatFieldUpdate(chatText, string); } } @Override - public boolean keyReleased(KeyInput input) { + public boolean keyReleased(KeyEvent input) { if (passEvents) { - InputUtil.Key key = InputUtil.fromKeyCode(input); - KeyBinding.setKeyPressed(key, false); + InputConstants.Key key = InputConstants.getKey(input); + KeyMapping.set(key, false); } return false; } - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { if (!passEvents) { for (AdvancedChatScreenSection section : sections) { if (section.keyPressed(input)) { @@ -245,7 +245,7 @@ public boolean keyPressed(KeyInput input) { return true; } if (input.key() == KeyCodes.KEY_ENTER || input.key() == KeyCodes.KEY_KP_ENTER) { - String string = this.chatField.getText().trim(); + String string = this.chatField.getValue().trim(); // Strip message and send MessageSender.getInstance().sendMessage(string); this.chatField.setText(""); @@ -266,23 +266,23 @@ public boolean keyPressed(KeyInput input) { } if (input.key() == KeyCodes.KEY_PAGE_UP) { // Scroll - client.inGameHud - .getChatHud() - .scroll(this.client.inGameHud.getChatHud().getVisibleLineCount() - 1); + minecraft.gui.hud + .getChat() + .scrollChat(this.minecraft.gui.hud.getChat().getLinesPerPage() - 1); return true; } if (input.key() == KeyCodes.KEY_PAGE_DOWN) { // Scroll - client.inGameHud - .getChatHud() - .scroll(-this.client.inGameHud.getChatHud().getVisibleLineCount() + 1); + minecraft.gui.hud + .getChat() + .scrollChat(-this.minecraft.gui.hud.getChat().getLinesPerPage() + 1); return true; } if (passEvents) { this.chatField.setText(""); - InputUtil.Key key = InputUtil.fromKeyCode(input); - KeyBinding.setKeyPressed(key, true); - KeyBinding.onKeyPressed(key); + InputConstants.Key key = InputConstants.getKey(input); + KeyMapping.set(key, true); + KeyMapping.click(key); return true; } return false; @@ -308,7 +308,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou } // Send to hud to scroll - client.inGameHud.getChatHud().scroll((int) verticalAmount); + minecraft.gui.hud.getChat().scrollChat((int) verticalAmount); return true; } @@ -319,7 +319,7 @@ protected void drawScreenBackground(GuiContext ctx, int mouseX, int mouseY) } @Override - public boolean mouseClicked(Click click, boolean doubled) { + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { for (AdvancedChatScreenSection section : sections) { if (section.mouseClicked(click, doubled)) { return true; @@ -329,7 +329,7 @@ public boolean mouseClicked(Click click, boolean doubled) { Style style = ChatHudStyleHolder.getLastHoveredStyle(); if (style != null) { if (style.getClickEvent() != null) { - Screen.handleClickEvent(style.getClickEvent(), this.client, this); + Screen.defaultHandleGameClickEvent(style.getClickEvent(), this.minecraft, this); return true; } } @@ -342,7 +342,7 @@ public boolean mouseClicked(Click click, boolean doubled) { } @Override - public boolean mouseDragged(Click click, double deltaX, double deltaY) { + public boolean mouseDragged(MouseButtonEvent click, double deltaX, double deltaY) { for (AdvancedChatScreenSection section : sections) { if (section.mouseDragged(click, deltaX, deltaY)) { return true; @@ -356,24 +356,24 @@ protected void insertText(String text, boolean override) { if (override) { this.chatField.setText(text); } else { - this.chatField.write(text); + this.chatField.insertText(text); } } public void setChatFromHistory(int i) { int targetIndex = this.messageHistorySize + i; - int maxIndex = this.client.inGameHud.getChatHud().getMessageHistory().size(); - targetIndex = MathHelper.clamp(targetIndex, 0, maxIndex); + int maxIndex = this.minecraft.gui.hud.getChat().getRecentChat().size(); + targetIndex = Mth.clamp(targetIndex, 0, maxIndex); if (targetIndex != this.messageHistorySize) { if (targetIndex == maxIndex) { this.messageHistorySize = maxIndex; this.chatField.setText(this.finalHistory); } else { if (this.messageHistorySize == maxIndex) { - this.finalHistory = this.chatField.getText(); + this.finalHistory = this.chatField.getValue(); } - String hist = this.client.inGameHud.getChatHud().getMessageHistory().get(targetIndex); + String hist = this.minecraft.gui.hud.getChat().getRecentChat().get(targetIndex); this.chatField.setText(hist); for (AdvancedChatScreenSection section : sections) { section.setChatFromHistory(hist); @@ -384,22 +384,23 @@ public void setChatFromHistory(int i) { } @Override - public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - // Render ChatHud FIRST (before GuiBase does anything) - ChatHud hud = this.client.inGameHud.getChatHud(); - hud.render(context, this.client.textRenderer, this.client.inGameHud.getTicks(), mouseX, mouseY, true, true); + public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float partialTicks) { + // Render ChatComponent FIRST (before GuiBase does anything) + ChatComponent hud = this.minecraft.gui.hud.getChat(); + hud.extractRenderState(context, this.minecraft.font, this.minecraft.gui.hud.getGuiTicks(), mouseX, mouseY, + ChatComponent.DisplayMode.FOREGROUND, true); // Then render chat field this.setFocused(this.chatField); this.chatField.setFocused(true); - this.chatField.render(context, mouseX, mouseY, partialTicks); + this.chatField.extractRenderState(context, mouseX, mouseY, partialTicks); // Then buttons (from GuiBase) - super.render(context, mouseX, mouseY, partialTicks); + super.extractRenderState(context, mouseX, mouseY, partialTicks); // Custom sections last for (AdvancedChatScreenSection section : sections) { - section.render(context, mouseX, mouseY, partialTicks); + section.extractRenderState(context, mouseX, mouseY, partialTicks); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedSleepingChatScreen.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedSleepingChatScreen.java index 27f2401..7707f5c 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedSleepingChatScreen.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedSleepingChatScreen.java @@ -11,10 +11,10 @@ import fi.dy.masa.malilib.gui.button.ButtonGeneric; import fi.dy.masa.malilib.util.KeyCodes; import fi.dy.masa.malilib.util.StringUtils; -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket; +import net.minecraft.client.gui.screens.ChatScreen; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket; public class AdvancedSleepingChatScreen extends AdvancedChatScreen { @@ -38,17 +38,17 @@ public void onClose() { this.stopSleeping(); } - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { if (input.key() == KeyCodes.KEY_ESCAPE) { this.stopSleeping(); } else if (input.key() == KeyCodes.KEY_ENTER || input.key() == KeyCodes.KEY_KP_ENTER) { - String string = this.chatField.getText().trim(); + String string = this.chatField.getValue().trim(); if (!string.isEmpty()) { MessageSender.getInstance().sendMessage(string); } this.chatField.setText(""); - this.client.inGameHud.getChatHud().resetScroll(); + this.minecraft.gui.hud.getChat().resetChatScroll(); // Prevents really weird interactions with chat history resetCurrentMessage(); return true; @@ -58,10 +58,10 @@ public boolean keyPressed(KeyInput input) { } private void stopSleeping() { - ClientPlayNetworkHandler clientPlayNetworkHandler = this.client.player.networkHandler; - clientPlayNetworkHandler.sendPacket( - new ClientCommandC2SPacket( - this.client.player, ClientCommandC2SPacket.Mode.STOP_SLEEPING)); + ClientPacketListener clientPlayNetworkHandler = this.minecraft.player.connection; + clientPlayNetworkHandler.send( + new ServerboundPlayerCommandPacket( + this.minecraft.player, ServerboundPlayerCommandPacket.Action.STOP_SLEEPING)); GuiBase.openGui(null); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedTextField.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedTextField.java index 2cf2170..25b513d 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedTextField.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/AdvancedTextField.java @@ -10,25 +10,25 @@ import fi.dy.masa.malilib.util.KeyCodes; import io.github.darkkronicle.advancedchatcore.config.ConfigStorage; import io.github.darkkronicle.advancedchatcore.util.*; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gl.RenderPipelines; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.render.*; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.math.MathHelper; +import net.minecraft.client.gui.Font; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.renderer.*; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.function.BiFunction; -public class AdvancedTextField extends TextFieldWidget { +public class AdvancedTextField extends EditBox { private final static int MAX_HISTORY = 50; @@ -42,29 +42,29 @@ public class AdvancedTextField extends TextFieldWidget { private final List history = new ArrayList<>(); private int focusedTicks = 0; - private List renderLines = new ArrayList<>(); - private TextRenderer textRenderer; + private List renderLines = new ArrayList<>(); + private Font textRenderer; private String suggestion = null; private int maxLength = 32; private int selectionEnd; private int selectionStart; // TODO Split? - private BiFunction renderTextProvider = (string, firstCharacterIndex) -> OrderedText.styledForwardsVisitedString(string, Style.EMPTY); + private BiFunction renderTextProvider = (string, firstCharacterIndex) -> FormattedCharSequence.forward(string, Style.EMPTY); private int historyIndex = -1; - public AdvancedTextField(TextRenderer textRenderer, int x, int y, int width, int height, Text text) { + public AdvancedTextField(Font textRenderer, int x, int y, int width, int height, Component text) { this(textRenderer, x, y, width, height, null, text); } public AdvancedTextField( - TextRenderer textRenderer, + Font textRenderer, int x, int y, int width, int height, - @Nullable TextFieldWidget copyFrom, - Text text) { + @Nullable EditBox copyFrom, + Component text) { super(textRenderer, x, y, width, height, copyFrom, text); history.add(""); this.textRenderer = textRenderer; @@ -82,16 +82,16 @@ public void setMaxLength(int maxLength) { super.setMaxLength(maxLength); } - public static boolean isUndo(KeyInput input) { + public static boolean isUndo(KeyEvent input) { // Undo (Ctrl + Z) - return input.key() == KeyCodes.KEY_Z && input.hasCtrl() && !input.hasAlt(); + return input.key() == KeyCodes.KEY_Z && input.hasControlDown() && !input.hasAltDown(); } /** Triggers undo for the text box */ public void undo() { // Save the current snapshot if it's been edited - if (!this.lastSaved.equals(this.getText()) && historyIndex < 0) { - addToHistory(getText()); + if (!this.lastSaved.equals(this.getValue()) && historyIndex < 0) { + addToHistory(getValue()); } // History index < 0 means not in the middle of undoing if (historyIndex < 0) { @@ -115,15 +115,15 @@ public void redo() { } @Override - public void write(String text) { - super.write(text); + public void insertText(String text) { + super.insertText(text); updateHistory(); updateRender(); } @Override - public void eraseCharacters(int characterOffset) { - super.eraseCharacters(characterOffset); + public void deleteChars(int characterOffset) { + super.deleteChars(characterOffset); updateHistory(); updateRender(); } @@ -134,9 +134,9 @@ public void setSuggestion(@Nullable String suggestion) { } @Override - public boolean mouseClicked(Click click, boolean doubled) { + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { - int renderY = getY() - (renderLines.size() - 1) * (textRenderer.fontHeight + 2); + int renderY = getY() - (renderLines.size() - 1) * (textRenderer.lineHeight + 2); if (click.button() < renderY - 2 || click.y() > getY() + height + 2 || click.x() < getX() - 2 || click.x() > getX() + width + 4) { return false; } @@ -145,12 +145,12 @@ public boolean mouseClicked(Click click, boolean doubled) { @Override - public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { + public void extractWidgetRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) { int color = 0xFFE0E0E0; - int cursor = getCursor(); + int cursor = getCursorPosition(); int cursorRow = renderLines.size() - 1; boolean renderCursor = this.isFocused() && focusedTicks / 6 % 2 == 0; - int renderY = getY() - (renderLines.size() - 1) * (textRenderer.fontHeight + 2); + int renderY = getY() - (renderLines.size() - 1) * (textRenderer.lineHeight + 2); int endX = 0; int charCount = 0; int cursorX = -1; @@ -170,57 +170,57 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float delt int y = getY() ; context.fill(getX() - 2, renderY - 2, getX() + width + 4, getY() + height + 4, ConfigStorage.ChatScreen.COLOR.config.getIntegerValue()); for (int line = 0; line < renderLines.size(); line++) { - Text text = renderLines.get(line); + Component text = renderLines.get(line); if (cursor >= charCount && cursor < text.getString().length() + charCount) { - cursorX = textRenderer.getWidth(text.getString().substring(0, cursor - charCount)); + cursorX = textRenderer.width(text.getString().substring(0, cursor - charCount)); cursorRow = line; } - endX = x + textRenderer.getWidth(text); - context.drawTextWithShadow(textRenderer, text, x, renderY, color); + endX = x + textRenderer.width(text); + context.text(textRenderer, text, x, renderY, color); if (selection) { if (!started && selStart >= charCount && selStart <= text.getString().length() + charCount) { started = true; - int startX = textRenderer.getWidth(TextUtil.truncate(text, new StringMatch("", 0, selStart - charCount))); + int startX = textRenderer.width(TextUtil.truncate(text, new StringMatch("", 0, selStart - charCount))); if (selEnd > charCount && selEnd <= text.getString().length() + charCount) { ended = true; - int sEndX = textRenderer.getWidth(TextUtil.truncate(text, new StringMatch("", 0, selEnd - charCount))); - drawSelectionHighlight(context, x + startX, renderY - 1, x + sEndX, renderY + textRenderer.fontHeight); + int sEndX = textRenderer.width(TextUtil.truncate(text, new StringMatch("", 0, selEnd - charCount))); + drawSelectionHighlight(context, x + startX, renderY - 1, x + sEndX, renderY + textRenderer.lineHeight); } else { - int sEndX = textRenderer.getWidth(text); - drawSelectionHighlight(context, x + startX, renderY - 1, x + sEndX, renderY + textRenderer.fontHeight); + int sEndX = textRenderer.width(text); + drawSelectionHighlight(context, x + startX, renderY - 1, x + sEndX, renderY + textRenderer.lineHeight); } } else if (started && !ended) { if (selEnd >= charCount && selEnd <= text.getString().length() + charCount) { ended = true; - int sEndX = textRenderer.getWidth(TextUtil.truncate(text, new StringMatch("", 0, selEnd - charCount))); - drawSelectionHighlight(context, x, renderY - 1, x + sEndX, renderY + textRenderer.fontHeight); + int sEndX = textRenderer.width(TextUtil.truncate(text, new StringMatch("", 0, selEnd - charCount))); + drawSelectionHighlight(context, x, renderY - 1, x + sEndX, renderY + textRenderer.lineHeight); } else { - int sEndX = textRenderer.getWidth(text); - drawSelectionHighlight(context, x, renderY - 1, x + sEndX, renderY + textRenderer.fontHeight); + int sEndX = textRenderer.width(text); + drawSelectionHighlight(context, x, renderY - 1, x + sEndX, renderY + textRenderer.lineHeight); } } } - renderY += textRenderer.fontHeight + 2; + renderY += textRenderer.lineHeight + 2; charCount += text.getString().length(); } if (cursorX < 0) { cursorX = endX; } - boolean cursorAtEnd = getCursor() == getText().length(); + boolean cursorAtEnd = getCursorPosition() == getValue().length(); if (!cursorAtEnd && this.suggestion != null) { - context.drawTextWithShadow(textRenderer, this.suggestion, endX - 1, y, -8355712); + context.text(textRenderer, this.suggestion, endX - 1, y, -8355712); } if (renderCursor) { - int cursorY = y - (renderLines.size() - 1 - cursorRow) * (textRenderer.fontHeight + 2); + int cursorY = y - (renderLines.size() - 1 - cursorRow) * (textRenderer.lineHeight + 2); if (cursorAtEnd) { - context.fill(cursorX, cursorY - 1, cursorX + 1, cursorY + 1 + this.textRenderer.fontHeight, -3092272); + context.fill(cursorX, cursorY - 1, cursorX + 1, cursorY + 1 + this.textRenderer.lineHeight, -3092272); } else { - context.drawTextWithShadow(textRenderer, "_", x + cursorX, cursorY, color); + context.text(textRenderer, "_", x + cursorX, cursorY, color); } } } - private void drawSelectionHighlight(DrawContext context, int x1, int y1, int x2, int y2) { + private void drawSelectionHighlight(GuiGraphicsExtractor context, int x1, int y1, int x2, int y2) { int x = getX(); int y = getY(); int i; @@ -245,32 +245,27 @@ private void drawSelectionHighlight(DrawContext context, int x1, int y1, int x2, } @Override - public void setSelectionStart(int cursor) { - this.selectionStart = MathHelper.clamp(cursor, 0, getText().length()); - super.setSelectionStart(cursor); + public void setCursorPosition(int cursor) { + this.selectionStart = Mth.clamp(cursor, 0, getValue().length()); + super.setCursorPosition(cursor); } @Override - public void setSelectionEnd(int index) { - int i = getText().length(); - this.selectionEnd = MathHelper.clamp(index, 0, i); - super.setSelectionEnd(index); - } - - @Override - public SelectionType getType() { - return super.getType(); + public void setHighlightPos(int index) { + int i = getValue().length(); + this.selectionEnd = Mth.clamp(index, 0, i); + super.setHighlightPos(index); } /** * Sets the text for the text field * - * @param text Text to set + * @param text Component to set * @param update Updates the history */ public void setText(String text, boolean update) { // Wrapper class for setText - super.setText(text); + super.setValue(text); if (update) { updateHistory(); } @@ -278,12 +273,17 @@ public void setText(String text, boolean update) { } @Override + public void setValue(String text) { + setText(text, true); + } + + /** Convenience wrapper kept for callers that used the old yarn name. */ public void setText(String text) { setText(text, true); } private void updateRender() { - OrderedText formatted = renderTextProvider.apply(getText(), 0); + FormattedCharSequence formatted = renderTextProvider.apply(getValue(), 0); renderLines = StyleFormatter.wrapText(textRenderer, getWidth(), new TextBuilder().append(formatted).build()); } @@ -294,12 +294,12 @@ private void updateHistory() { historyIndex = -1; } // Check to see if it should log - int dif = getText().length() - lastSaved.length(); - double sim = TextUtil.similarity(getText(), lastSaved); + int dif = getValue().length() - lastSaved.length(); + double sim = TextUtil.similarity(getValue(), lastSaved); if (sim >= .3 && (dif < 5 && dif * -1 < 5) || (sim >= .9)) { return; } - addToHistory(getText()); + addToHistory(getValue()); } private void addToHistory(String text) { @@ -326,14 +326,14 @@ private void pruneHistory(int index) { } @Override - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { if (!this.isActive()) { return false; } if (!isUndo(input)) { return super.keyPressed(input); } - if (input.hasShift()) { + if (input.hasShiftDown()) { redo(); } else { undo(); @@ -342,17 +342,17 @@ public boolean keyPressed(KeyInput input) { } @Override - public void appendClickableNarrations(NarrationMessageBuilder builder) { - // Crashes here because Text is null + public void updateWidgetNarration(NarrationElementOutput builder) { + // Crashes here because Component is null } @Override - public void eraseWords(int wordOffset) { - if (!this.getText().isEmpty()) { + public void deleteWords(int wordOffset) { + if (!this.getValue().isEmpty()) { if (this.selectionEnd != this.selectionStart) { this.setText(""); } else { - this.eraseCharacters(this.getWordSkipPosition(wordOffset) - this.selectionStart); + this.deleteChars(this.getWordPosition(wordOffset) - this.selectionStart); } } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java index 7e243b8..dceb84b 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatHistoryProcessor.java @@ -17,23 +17,25 @@ import java.time.format.DateTimeFormatter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.client.gui.hud.ChatHudLine; -import net.minecraft.client.gui.hud.MessageIndicator; -import net.minecraft.network.message.MessageSignatureData; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.text.TextColor; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.client.multiplayer.chat.GuiMessage; +import net.minecraft.client.multiplayer.chat.GuiMessageSource; +import net.minecraft.client.multiplayer.chat.GuiMessageTag; +import net.minecraft.network.chat.MessageSignature; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextColor; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public class ChatHistoryProcessor implements IMessageProcessor { - private static boolean sendToHud(Text text, @Nullable MessageSignatureData signature, MessageIndicator indicator) { + private static boolean sendToHud(Component text, @Nullable MessageSignature signature, GuiMessageTag indicator) { if (AdvancedChatCore.FORWARD_TO_HUD) { - ChatHud chatHud = MinecraftClient.getInstance().inGameHud.getChatHud(); - ChatHudLine chatHudLine = new ChatHudLine(MinecraftClient.getInstance().inGameHud.getTicks(), text, signature, indicator); + ChatComponent chatHud = Minecraft.getInstance().gui.hud.getChat(); + GuiMessage chatHudLine = new GuiMessage(Minecraft.getInstance().gui.hud.getGuiTicks(), text, signature, + GuiMessageSource.SYSTEM_CLIENT, indicator); ((MixinChatHudInvoker) chatHud).invokeAddVisibleMessage(chatHudLine); ((MixinChatHudInvoker) chatHud).invokeAddMessage(chatHudLine); @@ -44,12 +46,12 @@ private static boolean sendToHud(Text text, @Nullable MessageSignatureData signa } @Override - public boolean process(Text text, @Nullable Text unfiltered) { - return process(text, unfiltered, null, MessageIndicator.system()); + public boolean process(Component text, @Nullable Component unfiltered) { + return process(text, unfiltered, null, GuiMessageTag.system()); } @Override - public boolean process(Text text, @Nullable Text unfiltered, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator) { + public boolean process(Component text, @Nullable Component unfiltered, @Nullable MessageSignature signature, @Nullable GuiMessageTag indicator) { if (unfiltered == null) { unfiltered = text; } @@ -58,7 +60,7 @@ public boolean process(Text text, @Nullable Text unfiltered, @Nullable MessageSi LocalTime time = LocalTime.now(); boolean showtime = ConfigStorage.General.SHOW_TIME.config.getBooleanValue(); // Store original so we can get stuff without the time - Text original = text.copy(); + Component original = text.copy(); if (showtime) { DateTimeFormatter format = DateTimeFormatter.ofPattern( @@ -69,21 +71,21 @@ public boolean process(Text text, @Nullable Text unfiltered, @Nullable MessageSi Style style = Style.EMPTY; TextColor textColor = TextColor.fromRgb(color.getIntValue()); style = style.withColor(textColor); - text.getSiblings().addFirst(Text.literal(replaceFormat.replaceAll("%TIME%", time.format(format))).fillStyle(style)); + text.getSiblings().addFirst(Component.literal(replaceFormat.replaceAll("%TIME%", time.format(format))).withStyle(style)); } int width = 0; // Find player MessageOwner player = SearchUtils.getAuthor( - MinecraftClient.getInstance().getNetworkHandler(), unfiltered.getString()); + Minecraft.getInstance().getConnection(), unfiltered.getString()); ChatMessage line = ChatMessage.builder() .displayText(text) .originalText(original) .owner(player) .id(0) .width(width) - .creationTick(MinecraftClient.getInstance().inGameHud.getTicks()) + .creationTick(Minecraft.getInstance().gui.hud.getGuiTicks()) .time(time) .backgroundColor(null) .build(); diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatMessage.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatMessage.java index 90b23c0..1ab272a 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatMessage.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/ChatMessage.java @@ -17,10 +17,10 @@ import lombok.Data; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.hud.MessageIndicator; -import net.minecraft.network.message.MessageSignatureData; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.chat.GuiMessageTag; +import net.minecraft.network.chat.MessageSignature; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; /** A message from chat with data stored within it. */ @@ -32,10 +32,10 @@ public class ChatMessage { protected int creationTick; /** The text that will be displayed on render. */ - protected Text displayText; + protected Component displayText; /** The unmodified original text. Used to keep time stamp off of. */ - protected Text originalText; + protected Component originalText; /** ID of the message. */ protected int id; @@ -59,17 +59,17 @@ public class ChatMessage { protected List lines; @Nullable - protected MessageSignatureData signature; + protected MessageSignature signature; - protected MessageIndicator indicator; + protected GuiMessageTag indicator; /** * Set's the display text of the message and formats the line breaks. * - * @param text Text to set to + * @param text Component to set to * @param width The width that a line break should be enforced */ - public void setDisplayText(Text text, int width) { + public void setDisplayText(Component text, int width) { this.displayText = text; formatChildren(width); } @@ -102,15 +102,15 @@ public ChatMessage shallowClone(int width) { public static class AdvancedChatLine { /** Render text */ - private Text text; + private Component text; private final ChatMessage parent; private int width; - private AdvancedChatLine(ChatMessage parent, Text text) { + private AdvancedChatLine(ChatMessage parent, Component text) { this.parent = parent; this.text = text; - this.width = MinecraftClient.getInstance().textRenderer.getWidth(text); + this.width = Minecraft.getInstance().font.width(text); } @Override @@ -122,15 +122,15 @@ public String toString() { @Builder protected ChatMessage( int creationTick, - Text displayText, - Text originalText, + Component displayText, + Component originalText, int id, LocalTime time, Color backgroundColor, int width, MessageOwner owner, - @Nullable MessageSignatureData signature, - @Nullable MessageIndicator indicator) { + @Nullable MessageSignature signature, + @Nullable GuiMessageTag indicator) { this.creationTick = creationTick; this.displayText = displayText; this.id = id; @@ -141,7 +141,7 @@ protected ChatMessage( this.owner = owner; this.originalText = originalText == null ? displayText : originalText; this.signature = signature; - this.indicator = indicator == null ? MessageIndicator.system() : indicator; + this.indicator = indicator == null ? GuiMessageTag.system() : indicator; formatChildren(width); } @@ -155,9 +155,9 @@ public void formatChildren(int width) { if (width == 0) { this.lines.add(new AdvancedChatLine(this, displayText)); } else { - for (Text t : + for (Component t : StyleFormatter.wrapText( - MinecraftClient.getInstance().textRenderer, width, displayText)) { + Minecraft.getInstance().font, width, displayText)) { this.lines.add(new AdvancedChatLine(this, t)); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/DefaultChatSuggestor.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/DefaultChatSuggestor.java index eae52e7..0ed8353 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/DefaultChatSuggestor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/DefaultChatSuggestor.java @@ -10,18 +10,18 @@ import io.github.darkkronicle.advancedchatcore.interfaces.AdvancedChatScreenSection; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.CommandSuggestions; +import net.minecraft.client.input.KeyEvent; +import com.mojang.blaze3d.vertex.PoseStack; /** Handles the CommandSuggestor for the chat */ @Environment(EnvType.CLIENT) public class DefaultChatSuggestor extends AdvancedChatScreenSection { - private ChatInputSuggestor commandSuggestor; + private CommandSuggestions commandSuggestor; public DefaultChatSuggestor(AdvancedChatScreen screen) { super(screen); @@ -29,23 +29,23 @@ public DefaultChatSuggestor(AdvancedChatScreen screen) { @Override public void onChatFieldUpdate(String chatText, String text) { - this.commandSuggestor.setWindowActive(!text.equals(getScreen().getOriginalChatText())); - this.commandSuggestor.refresh(); + this.commandSuggestor.setAllowSuggestions(!text.equals(getScreen().getOriginalChatText())); + this.commandSuggestor.updateCommandInfo(); } @Override - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { return this.commandSuggestor.keyPressed(input); } @Override - public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - this.commandSuggestor.render(context, mouseX, mouseY); + public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float partialTicks) { + this.commandSuggestor.extractRenderState(context, mouseX, mouseY); } @Override public void setChatFromHistory(String hist) { - this.commandSuggestor.setWindowActive(false); + this.commandSuggestor.setAllowSuggestions(false); } @Override @@ -54,31 +54,31 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { } @Override - public boolean mouseClicked(Click click, boolean doubled) { + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { return this.commandSuggestor.mouseClicked(click); } @Override public void resize(int width, int height) { - this.commandSuggestor.refresh(); + this.commandSuggestor.updateCommandInfo(); } @Override public void initGui() { - MinecraftClient client = MinecraftClient.getInstance(); + Minecraft client = Minecraft.getInstance(); AdvancedChatScreen screen = getScreen(); this.commandSuggestor = - new ChatInputSuggestor( + new CommandSuggestions( client, screen, screen.chatField, - client.textRenderer, + client.font, false, false, 1, 10, true, -805306368); - this.commandSuggestor.refresh(); + this.commandSuggestor.updateCommandInfo(); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageDispatcher.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageDispatcher.java index e95c019..d957a69 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageDispatcher.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageDispatcher.java @@ -24,11 +24,11 @@ import java.util.Optional; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.hud.MessageIndicator; -import net.minecraft.network.message.MessageSignatureData; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.client.multiplayer.chat.GuiMessageTag; +import net.minecraft.network.chat.MessageSignature; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Component; import org.apache.logging.log4j.LogManager; import org.jetbrains.annotations.Nullable; @@ -78,9 +78,9 @@ private MessageDispatcher() { url = "https://" + url; } if (current.getStyle().getClickEvent() == null) { - return Text.literal(match1.match).fillStyle(current.getStyle().withClickEvent(new ClickEvent.OpenUrl(URI.create(url)))); + return Component.literal(match1.match).withStyle(current.getStyle().withClickEvent(new ClickEvent.OpenUrl(URI.create(url)))); } - return MutableText.of(current.getContent()).fillStyle(current.getStyle()); + return MutableComponent.create(current.getContents()).withStyle(current.getStyle()); }); } text = TextUtil.replaceStrings(text, insert); @@ -105,12 +105,12 @@ private MessageDispatcher() { * This is ONLY used for new messages in chat * *

Note: It is not recommended to call this method to force add new text. Typically, grabbing - * the {@link net.minecraft.client.gui.hud.ChatHud} from {@link - * net.minecraft.client.MinecraftClient} and calling addText is a safer way. + * the {@link net.minecraft.client.gui.hud.ChatComponent} from {@link + * net.minecraft.client.Minecraft} and calling addText is a safer way. * - * @param text Text that is received + * @param text Component that is received */ - public void handleText(Text text, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator) { + public void handleText(Component text, @Nullable MessageSignature signature, @Nullable GuiMessageTag indicator) { boolean previouslyBlank = text.getString().isEmpty(); text = preFilter(text, signature, indicator); if (text.getString().isEmpty() && !previouslyBlank) { @@ -120,9 +120,9 @@ public void handleText(Text text, @Nullable MessageSignatureData signature, @Nul process(text, signature, indicator); } - private Text preFilter(Text text, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator) { + private Component preFilter(Component text, @Nullable MessageSignature signature, @Nullable GuiMessageTag indicator) { for (IMessageFilter f : preFilters) { - Optional t = f.filter(text); + Optional t = f.filter(text); if (t.isPresent()) { text = t.get(); } @@ -130,7 +130,7 @@ private Text preFilter(Text text, @Nullable MessageSignatureData signature, @Nul return text; } - private void process(Text text, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator) { + private void process(Component text, @Nullable MessageSignature signature, @Nullable GuiMessageTag indicator) { for (IMessageFilter f : processors) { f.filter(text); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageOwner.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageOwner.java index 20970fa..84ac738 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageOwner.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageOwner.java @@ -12,8 +12,8 @@ import lombok.Value; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.network.PlayerListEntry; -import net.minecraft.util.Identifier; +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.resources.Identifier; /** Stores data about a message owner */ @Data @@ -26,7 +26,7 @@ public class MessageOwner { String name; /** Entry that has player data */ - PlayerListEntry entry; + PlayerInfo entry; /** * The texture of the player's skin @@ -34,6 +34,6 @@ public class MessageOwner { * @return Identifier with texture data */ public Identifier getTexture() { - return entry.getSkinTextures().body().texturePath(); + return entry.getSkin().body().texturePath(); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageSender.java b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageSender.java index c1a2ffd..e5e3b70 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageSender.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/chat/MessageSender.java @@ -9,7 +9,7 @@ import io.github.darkkronicle.advancedchatcore.AdvancedChatCore; import io.github.darkkronicle.advancedchatcore.interfaces.IStringFilter; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; import org.apache.logging.log4j.Level; import java.util.ArrayList; @@ -19,7 +19,7 @@ public class MessageSender { private static final MessageSender INSTANCE = new MessageSender(); - private final MinecraftClient client = MinecraftClient.getInstance(); + private final Minecraft client = Minecraft.getInstance(); public static MessageSender getInstance() { return INSTANCE; @@ -48,7 +48,7 @@ public void sendMessage(String string) { if (string.length() > 256) { string = string.substring(0, 256); } - this.client.inGameHud.getChatHud().addToMessageHistory(unfiltered); + this.client.gui.hud.getChat().addRecentChat(unfiltered); if (string.isEmpty()) { AdvancedChatCore.LOGGER.log(Level.WARN, "Blank message was attempted to be sent. " + unfiltered); @@ -57,9 +57,9 @@ public void sendMessage(String string) { if (client.player != null) { if (string.startsWith("/")) { - this.client.getNetworkHandler().sendChatCommand(string.substring(1)); + this.client.getConnection().sendCommand(string.substring(1)); } else { - this.client.getNetworkHandler().sendChatMessage(string); + this.client.getConnection().sendChat(string); } } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/ConfigStorage.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/ConfigStorage.java index 23cb1b8..dc0d888 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/ConfigStorage.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/ConfigStorage.java @@ -20,7 +20,7 @@ import fi.dy.masa.malilib.hotkeys.KeyAction; import fi.dy.masa.malilib.hotkeys.KeybindSettings; import fi.dy.masa.malilib.util.FileUtils; -import fi.dy.masa.malilib.util.JsonUtils; +import fi.dy.masa.malilib.util.data.json.JsonUtils; import fi.dy.masa.malilib.util.StringUtils; import io.github.darkkronicle.advancedchatcore.AdvancedChatCore; import io.github.darkkronicle.advancedchatcore.interfaces.ConfigRegistryOption; diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java index f1f8b3a..4e17487 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfig.java @@ -15,7 +15,7 @@ import fi.dy.masa.malilib.gui.button.IButtonActionListener; import fi.dy.masa.malilib.util.data.Color4f; import io.github.darkkronicle.advancedchatcore.AdvancedChatCore; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; import java.util.List; diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java index bc632c3..c977533 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/GuiConfigHandler.java @@ -22,8 +22,8 @@ import lombok.Value; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; @Environment(EnvType.CLIENT) public class GuiConfigHandler { @@ -84,10 +84,10 @@ public List getButtons() { int y = 26; int rows = 1; ArrayList buttons = new ArrayList<>(); - MinecraftClient client = MinecraftClient.getInstance(); - int windowWidth = client.getWindow().getScaledWidth(); + Minecraft client = Minecraft.getInstance(); + int windowWidth = client.getWindow().getGuiScaledWidth(); for (TabSupplier tab : tabs) { - int width = client.textRenderer.getWidth(tab.getName()) + 10; + int width = client.font.width(tab.getName()) + 10; if (x >= windowWidth - width - 10) { x = 10; diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/TabSupplier.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/TabSupplier.java index 9e2a01f..c19dcef 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/TabSupplier.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/TabSupplier.java @@ -4,7 +4,7 @@ import fi.dy.masa.malilib.util.StringUtils; import lombok.Getter; import lombok.Setter; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetColor.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetColor.java index 5ff79aa..76e957e 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetColor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetColor.java @@ -13,9 +13,9 @@ import io.github.darkkronicle.advancedchatcore.util.Color; import io.github.darkkronicle.advancedchatcore.util.Colors; import java.util.Optional; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import com.mojang.blaze3d.vertex.PoseStack; public class WidgetColor extends GuiTextFieldGeneric { @@ -23,16 +23,16 @@ public class WidgetColor extends GuiTextFieldGeneric { private Color currentColor; public WidgetColor( - int x, int y, int width, int height, Color color, TextRenderer textRenderer) { + int x, int y, int width, int height, Color color, Font textRenderer) { super(x, y, width - 22, height, textRenderer); this.colorX = x + width - 20; this.currentColor = color; - setText(String.format("#%08X", this.currentColor.color())); + setValue(String.format("#%08X", this.currentColor.color())); } @Override - public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { - super.renderWidget(context, mouseX, mouseY, delta); + public void extractWidgetRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) { + super.extractWidgetRenderState(context, mouseX, mouseY, delta); int y = this.y; RenderUtils.drawRect(this.colorX, y, 19, 19, 0xFFFFFFFF); RenderUtils.drawRect(this.colorX + 1, y + 1, 17, 17, 0xFF000000); @@ -40,8 +40,8 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float delt } @Override - public void write(String text) { - super.write(text); + public void insertText(String text) { + super.insertText(text); getAndRefreshColor4f(); } @@ -51,12 +51,12 @@ public int getWidth() { } public Color getAndRefreshColor4f() { - Optional color = Colors.getInstance().getColor(getText()); + Optional color = Colors.getInstance().getColor(getValue()); if (color.isPresent()) { this.currentColor = color.get(); return this.currentColor; } - this.currentColor = new Color(StringUtils.getColor(getText(), 0)); + this.currentColor = new Color(StringUtils.getColor(getValue(), 0)); return this.currentColor; } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetIntBox.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetIntBox.java index 1d8006e..3a9510e 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetIntBox.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetIntBox.java @@ -15,32 +15,47 @@ import java.util.Optional; import lombok.Getter; import lombok.Setter; -import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.Font; public class WidgetIntBox extends GuiTextFieldGeneric { @Setter @Getter private Runnable apply = null; - public WidgetIntBox(int x, int y, int width, int height, TextRenderer textRenderer) { + public WidgetIntBox(int x, int y, int width, int height, Font textRenderer) { super(x, y, width, height, textRenderer); - this.setTextPredicate( - text -> { - if (text.equals("")) { - return true; - } - try { - // Only allow numbers! - Integer.valueOf(text); - } catch (NumberFormatException e) { - return false; - } - return true; - }); - this.setDrawsBackground(true); + this.setBordered(true); + } + + /** + * EditBox#setFilter was removed in 26.2, so the numbers-only rule is enforced by + * letting the insert happen and rolling it back when the result isn't an integer. + */ + @Override + public void insertText(String text) { + String before = this.getValue(); + int cursor = this.getCursorPosition(); + super.insertText(text); + if (!isInteger(this.getValue())) { + super.setValue(before); + this.setCursorPosition(cursor); + } + } + + private static boolean isInteger(String text) { + if (text.isEmpty()) { + return true; + } + try { + // Only allow numbers! + Integer.valueOf(text); + } catch (NumberFormatException e) { + return false; + } + return true; } public Integer getInt() { - String text = this.getText(); + String text = this.getValue(); if (text == null || text.length() == 0) { return null; } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetLabelHoverable.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetLabelHoverable.java index bd91390..449611a 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetLabelHoverable.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetLabelHoverable.java @@ -13,8 +13,8 @@ import java.util.Arrays; import java.util.List; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import com.mojang.blaze3d.vertex.PoseStack; public class WidgetLabelHoverable extends WidgetLabel { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetListRegistryOption.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetListRegistryOption.java index 902f21e..5ca16ee 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetListRegistryOption.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetListRegistryOption.java @@ -13,7 +13,7 @@ import io.github.darkkronicle.advancedchatcore.util.AbstractRegistry; import java.util.Collection; import java.util.stream.Collectors; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; import org.jetbrains.annotations.Nullable; public class WidgetListRegistryOption> diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetRegistryOptionEntry.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetRegistryOptionEntry.java index 6c05f74..64b8d7d 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetRegistryOptionEntry.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetRegistryOptionEntry.java @@ -22,9 +22,9 @@ import java.util.List; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.screens.Screen; +import com.mojang.blaze3d.vertex.PoseStack; @Environment(EnvType.CLIENT) public class WidgetRegistryOptionEntry> diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetToggle.java b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetToggle.java index 247ba6c..60195ce 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetToggle.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/config/gui/widgets/WidgetToggle.java @@ -9,7 +9,7 @@ import fi.dy.masa.malilib.gui.button.ButtonOnOff; import lombok.Getter; -import net.minecraft.client.gui.Click; +import net.minecraft.client.input.MouseButtonEvent; public class WidgetToggle extends ButtonOnOff { @@ -28,7 +28,7 @@ public WidgetToggle( } @Override - protected boolean onMouseClickedImpl(Click click, boolean doubled) { + protected boolean onMouseClickedImpl(MouseButtonEvent click, boolean doubled) { this.currentlyOn = !this.currentlyOn; this.updateDisplayString(this.currentlyOn); return super.onMouseClickedImpl(click, doubled); diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/finder/RegexFinder.java b/src/main/java/io/github/darkkronicle/advancedchatcore/finder/RegexFinder.java index 16e8fee..875b0ae 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/finder/RegexFinder.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/finder/RegexFinder.java @@ -9,12 +9,12 @@ import io.github.darkkronicle.advancedchatcore.AdvancedChatCore; import io.github.darkkronicle.advancedchatcore.util.*; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.text.TextColor; -import net.minecraft.util.Formatting; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextColor; +import net.minecraft.ChatFormatting; import java.util.*; import java.util.regex.Matcher; @@ -34,7 +34,7 @@ public Pattern getPattern(String toMatch) { } @Override - public List getMatches(Text input, String toMatch) { + public List getMatches(Component input, String toMatch) { // Find named groups Optional> optionalGroups = SearchUtils.findMatches(toMatch, "\\(\\?<([a-zA-Z][a-zA-Z0-9]*)>", FindType.REGEX); if (optionalGroups.isEmpty()) { @@ -80,7 +80,7 @@ public List getMatches(Text input, String toMatch) { return matches; } - public static boolean isAllowed(Text input, String group, Matcher matcher) { + public static boolean isAllowed(Component input, String group, Matcher matcher) { group = group.toLowerCase(Locale.ROOT); String groupText = matcher.group(group); String groupCondition = group.substring(3); @@ -92,7 +92,7 @@ public static boolean isAllowed(Text input, String group, Matcher matcher) { if (groupCondition.startsWith("0")) { groupCondition = groupCondition.substring(1); while (groupCondition.length() != 0) { - MutableText truncated = TextUtil.truncate(input, new StringMatch("", start, end)); + MutableComponent truncated = TextUtil.truncate(input, new StringMatch("", start, end)); char val = groupCondition.charAt(0); groupCondition = groupCondition.substring(1); if (val == 'l') { @@ -127,8 +127,8 @@ public static boolean isAllowed(Text input, String group, Matcher matcher) { } if (val == 'z') { if (!TextUtil.styleChanges( - truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().getAction() == ClickEvent.Action.OPEN_URL - && style2.getClickEvent() != null && style2.getClickEvent().getAction() == ClickEvent.Action.OPEN_URL) + truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().action() == ClickEvent.Action.OPEN_URL + && style2.getClickEvent() != null && style2.getClickEvent().action() == ClickEvent.Action.OPEN_URL) ) { return true; } @@ -136,8 +136,8 @@ public static boolean isAllowed(Text input, String group, Matcher matcher) { } if (val == 'x') { if (!TextUtil.styleChanges( - truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().getAction() == ClickEvent.Action.COPY_TO_CLIPBOARD - && style2.getClickEvent() != null && style2.getClickEvent().getAction() == ClickEvent.Action.COPY_TO_CLIPBOARD) + truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().action() == ClickEvent.Action.COPY_TO_CLIPBOARD + && style2.getClickEvent() != null && style2.getClickEvent().action() == ClickEvent.Action.COPY_TO_CLIPBOARD) ) { return true; } @@ -145,8 +145,8 @@ public static boolean isAllowed(Text input, String group, Matcher matcher) { } if (val == 'y') { if (!TextUtil.styleChanges( - truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().getAction() == ClickEvent.Action.OPEN_FILE - && style2.getClickEvent() != null && style2.getClickEvent().getAction() == ClickEvent.Action.OPEN_FILE) + truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().action() == ClickEvent.Action.OPEN_FILE + && style2.getClickEvent() != null && style2.getClickEvent().action() == ClickEvent.Action.OPEN_FILE) ) { return true; } @@ -154,8 +154,8 @@ public static boolean isAllowed(Text input, String group, Matcher matcher) { } if (val == 'w') { if (!TextUtil.styleChanges( - truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().getAction() == ClickEvent.Action.RUN_COMMAND - && style2.getClickEvent() != null && style2.getClickEvent().getAction() == ClickEvent.Action.RUN_COMMAND) + truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().action() == ClickEvent.Action.RUN_COMMAND + && style2.getClickEvent() != null && style2.getClickEvent().action() == ClickEvent.Action.RUN_COMMAND) ) { return true; } @@ -163,8 +163,8 @@ public static boolean isAllowed(Text input, String group, Matcher matcher) { } if (val == 'v') { if (!TextUtil.styleChanges( - truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().getAction() == ClickEvent.Action.SUGGEST_COMMAND - && style2.getClickEvent() != null && style2.getClickEvent().getAction() == ClickEvent.Action.SUGGEST_COMMAND) + truncated, (style1, style2) -> style1.getClickEvent() != null && style1.getClickEvent().action() == ClickEvent.Action.SUGGEST_COMMAND + && style2.getClickEvent() != null && style2.getClickEvent().action() == ClickEvent.Action.SUGGEST_COMMAND) ) { return true; } @@ -190,11 +190,14 @@ public static boolean isAllowed(Text input, String group, Matcher matcher) { } continue; } - Formatting formatting = Formatting.byCode(val); - if (formatting == null || !formatting.isColor()) { + ChatFormatting formatting = ChatFormatting.getByCode(val); + TextColor legacyColor = + formatting == null ? null : TextColor.fromLegacyFormat(formatting); + if (legacyColor == null) { + // Not a colour code (formatting-only, e.g. bold) continue; } - if (color.getRgb() == formatting.getColorValue()) { + if (color.getValue() == legacyColor.getValue()) { return true; } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CleanButton.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CleanButton.java index 6b95193..a2128bd 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CleanButton.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CleanButton.java @@ -16,9 +16,9 @@ import lombok.ToString; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import com.mojang.blaze3d.vertex.PoseStack; /** A simple button */ @EqualsAndHashCode(callSuper = false) @@ -28,7 +28,7 @@ public class CleanButton extends ButtonBase { protected Color baseColor; - private MinecraftClient client = MinecraftClient.getInstance(); + private Minecraft client = Minecraft.getInstance(); /** * Constructs a new simple clean button @@ -38,7 +38,7 @@ public class CleanButton extends ButtonBase { * @param width Width * @param height Height * @param baseColor Color that it should render when not hovered - * @param text Text to render + * @param text Component to render */ public CleanButton(int x, int y, int width, int height, Color baseColor, String text) { super(x, y, width, height, text); diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ContextMenu.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ContextMenu.java index 99594d5..e908d89 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ContextMenu.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/ContextMenu.java @@ -6,17 +6,17 @@ import io.github.darkkronicle.advancedchatcore.util.TextUtil; import lombok.Getter; import lombok.Setter; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.network.chat.Component; import java.util.LinkedHashMap; public class ContextMenu extends WidgetBase { - private final LinkedHashMap options; - private Text hoveredEntry = null; + private final LinkedHashMap options; + private Component hoveredEntry = null; @Getter private final int contextX; @@ -36,11 +36,11 @@ public class ContextMenu extends WidgetBase { @Getter private Color hover; - public ContextMenu(int x, int y, LinkedHashMap options, Runnable close) { + public ContextMenu(int x, int y, LinkedHashMap options, Runnable close) { this(x, y, options, close, new Color(0, 0, 0, 200), new Color(255, 255, 255, 100)); } - public ContextMenu(int x, int y, LinkedHashMap options, Runnable close, Color background, Color hover) { + public ContextMenu(int x, int y, LinkedHashMap options, Runnable close, Color background, Color hover) { super(x, y, 10, 10); this.contextX = x; this.contextY = y; @@ -52,10 +52,10 @@ public ContextMenu(int x, int y, LinkedHashMap options, R } public void updateDimensions() { - setWidth(TextUtil.getMaxLengthString(options.keySet().stream().map(Text::getString).toList()) + 4); - setHeight(options.size() * (textRenderer.fontHeight + 2)); - int windowWidth = MinecraftClient.getInstance().getWindow().getScaledWidth(); - int windowHeight = MinecraftClient.getInstance().getWindow().getScaledHeight(); + setWidth(TextUtil.getMaxLengthString(options.keySet().stream().map(Component::getString).toList()) + 4); + setHeight(options.size() * (textRenderer.lineHeight + 2)); + int windowWidth = Minecraft.getInstance().getWindow().getGuiScaledWidth(); + int windowHeight = Minecraft.getInstance().getWindow().getGuiScaledHeight(); if (x + width > windowWidth) { x = windowWidth - width; } @@ -65,7 +65,7 @@ public void updateDimensions() { } @Override - public boolean onMouseClicked(Click click, boolean doubled) { + public boolean onMouseClicked(MouseButtonEvent click, boolean doubled) { boolean success = super.onMouseClicked(click, doubled); if (success) { return true; @@ -76,7 +76,7 @@ public boolean onMouseClicked(Click click, boolean doubled) { } @Override - protected boolean onMouseClickedImpl(Click click, boolean doubled) { + protected boolean onMouseClickedImpl(MouseButtonEvent click, boolean doubled) { if (click.button() != 0) { return false; } @@ -94,13 +94,13 @@ public void render(GuiContext context, int mouseX, int mouseY, boolean selected) int rX = x + 2; int rY = y + 2; hoveredEntry = null; - for (Text option : options.keySet()) { + for (Component option : options.keySet()) { if (mouseX >= x && mouseX <= x + width && mouseY >= rY - 2 && mouseY < rY + fontHeight + 1) { hoveredEntry = option; - drawRect(context, rX - 2, rY - 2, width, textRenderer.fontHeight + 2, hover.color()); + drawRect(context, rX - 2, rY - 2, width, textRenderer.lineHeight + 2, hover.color()); } - context.drawTextWithShadow(textRenderer, option, rX, rY, -1); - rY += textRenderer.fontHeight + 2; + context.text(textRenderer, option, rX, rY, -1); + rY += textRenderer.lineHeight + 2; } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CoreGuiListBase.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CoreGuiListBase.java index a581991..3659f64 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CoreGuiListBase.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/CoreGuiListBase.java @@ -13,7 +13,7 @@ import fi.dy.masa.malilib.gui.widgets.WidgetListBase; import fi.dy.masa.malilib.gui.widgets.WidgetListEntryBase; import io.github.darkkronicle.advancedchatcore.interfaces.IClosable; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; public abstract class CoreGuiListBase< TYPE, @@ -31,7 +31,7 @@ public void resize(int width, int height) { this.width = width; this.height = height; this.clearElements(); - this.clearAndInit(); + this.rebuildWidgets(); } @Override diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/IconButton.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/IconButton.java index dbdd091..e09f74e 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/IconButton.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/IconButton.java @@ -6,12 +6,12 @@ import io.github.darkkronicle.advancedchatcore.util.Colors; import lombok.Getter; import lombok.Setter; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gl.RenderPipelines; -import net.minecraft.client.gui.Click; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.Identifier; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.resources.Identifier; import java.util.function.Consumer; @@ -72,12 +72,12 @@ public void render(GuiContext context, int mouseX, int mouseY, boolean unused) { context.fill(x, y, x + width, y + height, plusBack.color()); - context.drawTexture(RenderPipelines.GUI_TEXTURED, icon, x + padding, y + padding, 0, 0, + context.blit(RenderPipelines.GUI_TEXTURED, icon, x + padding, y + padding, 0, 0, width - (padding * 2), height - (padding * 2), iconWidth, iconHeight, iconWidth, iconHeight); if (hovered && onHover != null) { - context.drawCenteredTextWithShadow( - MinecraftClient.getInstance().textRenderer, + context.drawCenteredString( + Minecraft.getInstance().font, onHover, mouseX + 4, mouseY - 16, @@ -86,8 +86,8 @@ public void render(GuiContext context, int mouseX, int mouseY, boolean unused) { } @Override - protected boolean onMouseClickedImpl(Click click, boolean doubled) { - this.mc.getSoundManager().play(PositionedSoundInstance.ui(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + protected boolean onMouseClickedImpl(MouseButtonEvent click, boolean doubled) { + this.mc.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); onClick.accept(this); return true; } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigList.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigList.java index 27a1376..80acf0c 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigList.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigList.java @@ -14,10 +14,10 @@ import java.util.ArrayList; import java.util.List; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.input.KeyInput; +import net.minecraft.client.Minecraft; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.input.KeyEvent; public abstract class WidgetConfigList> extends WidgetListBase { @@ -41,7 +41,7 @@ public void resize(int width, int height) { this.width = width; this.height = height; this.clearElements(); - this.clearAndInit(); + this.rebuildWidgets(); } @Override @@ -62,13 +62,13 @@ protected void clearTextFieldFocus() { } @Override - public boolean onMouseClicked(Click click, boolean doubled) { + public boolean onMouseClicked(MouseButtonEvent click, boolean doubled) { clearTextFieldFocus(); return super.onMouseClicked(click, doubled); } @Override - public boolean onKeyTyped(KeyInput input) { + public boolean onKeyTyped(KeyEvent input) { for (WidgetConfigListEntry widget : this.listWidgets) { if (widget.onKeyTyped(input)) { return true; diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigListEntry.java b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigListEntry.java index 9cf696d..fe1038a 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigListEntry.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/gui/WidgetConfigListEntry.java @@ -19,10 +19,10 @@ import lombok.Setter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.input.CharInput; -import net.minecraft.client.input.KeyInput; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; @Environment(EnvType.CLIENT) public abstract class WidgetConfigListEntry extends WidgetListEntryBase { @@ -126,7 +126,7 @@ public void postRenderHovered( } @Override - protected boolean onKeyTypedImpl(KeyInput input) { + protected boolean onKeyTypedImpl(KeyEvent input) { if (getTextFields() == null) { return false; } @@ -139,7 +139,7 @@ protected boolean onKeyTypedImpl(KeyInput input) { } @Override - protected boolean onCharTypedImpl(CharInput input) { + protected boolean onCharTypedImpl(CharacterEvent input) { if (getTextFields() != null) { for (TextFieldWrapper field : getTextFields()) { if (field != null && field.onCharTyped(input)) { @@ -152,7 +152,7 @@ protected boolean onCharTypedImpl(CharInput input) { } @Override - protected boolean onMouseClickedImpl(Click click, boolean doubled) { + protected boolean onMouseClickedImpl(MouseButtonEvent click, boolean doubled) { if (super.onMouseClickedImpl(click, doubled)) { return true; } @@ -178,12 +178,12 @@ protected boolean onMouseClickedImpl(Click click, boolean doubled) { return ret; } - protected void drawTextFields(int mouseX, int mouseY, DrawContext context) { + protected void drawTextFields(int mouseX, int mouseY, GuiGraphicsExtractor context) { if (getTextFields() == null) { return; } for (TextFieldWrapper field : getTextFields()) { - field.textField().render(context, mouseX, mouseY, 0f); + field.textField().extractRenderState(context, mouseX, mouseY, 0f); } } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/AdvancedChatScreenSection.java b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/AdvancedChatScreenSection.java index b826ad2..bcea9e8 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/AdvancedChatScreenSection.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/AdvancedChatScreenSection.java @@ -9,17 +9,18 @@ import io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen; import lombok.Getter; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.Drawable; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.input.KeyEvent; +import com.mojang.blaze3d.vertex.PoseStack; /** * A class meant to extend onto the {@link AdvancedChatScreen} * *

This is used so that many modules can add onto the screen without problems occuring. */ -public abstract class AdvancedChatScreenSection implements Drawable { +public abstract class AdvancedChatScreenSection implements Renderable { /** The {@link AdvancedChatScreen} that is linked to this section */ @Getter private final AdvancedChatScreen screen; @@ -58,7 +59,7 @@ public void onChatFieldUpdate(String chatText, String text) {} * @param modifiers Modifiers * @return If it was handled and should stop. */ - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { return false; } @@ -82,7 +83,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { * @param button Mouse button * @return If it was handled and should stop. */ - public boolean mouseClicked(Click click, boolean doubled) { + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { return false; } @@ -94,7 +95,7 @@ public boolean mouseClicked(Click click, boolean doubled) { * @param mouseButton Mouse button * @return If it was handled and should stop. */ - public boolean mouseReleased(Click click) { + public boolean mouseReleased(MouseButtonEvent click) { return false; } @@ -106,7 +107,7 @@ public boolean mouseReleased(Click click) { * @param deltaY * @return If it was handled and should stop. */ - public boolean mouseDragged(Click click, double deltaX, double deltaY) { + public boolean mouseDragged(MouseButtonEvent click, double deltaX, double deltaY) { return false; } @@ -120,10 +121,11 @@ public void setChatFromHistory(String hist) {} /** * Called when the screen renders. * - * @param matrixStack MatrixStack + * @param matrixStack PoseStack * @param mouseX MouseX * @param mouseY MouseY * @param partialTicks Partial tick from the last tick */ - public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {} + public void extractRenderState( + GuiGraphicsExtractor context, int mouseX, int mouseY, float partialTicks) {} } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IFinder.java b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IFinder.java index 4fa4aa2..bcb1f0c 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IFinder.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IFinder.java @@ -8,7 +8,7 @@ package io.github.darkkronicle.advancedchatcore.interfaces; import io.github.darkkronicle.advancedchatcore.util.StringMatch; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.List; @@ -16,13 +16,13 @@ public interface IFinder { boolean isMatch(String input, String toMatch); - default boolean isMatch(Text input, String toMatch) { + default boolean isMatch(Component input, String toMatch) { return isMatch(input.getString(), toMatch); } List getMatches(String input, String toMatch); - default List getMatches(Text input, String toMatch) { + default List getMatches(Component input, String toMatch) { return getMatches(input.getString(), toMatch); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMatchProcessor.java b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMatchProcessor.java index 6215388..104df4c 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMatchProcessor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMatchProcessor.java @@ -8,7 +8,7 @@ package io.github.darkkronicle.advancedchatcore.interfaces; import io.github.darkkronicle.advancedchatcore.util.SearchResult; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; /** @@ -43,7 +43,7 @@ public static Result getFromBool(boolean success) { } @Override - default boolean process(Text text, Text unfiltered) { + default boolean process(Component text, Component unfiltered) { return processMatches(text, unfiltered, null).success; } @@ -56,7 +56,7 @@ default boolean process(Text text, Text unfiltered) { * @return The {@link Result} that the method performed */ Result processMatches( - Text text, @Nullable Text unfiltered, @Nullable SearchResult search); + Component text, @Nullable Component unfiltered, @Nullable SearchResult search); /** * Whether or not this processor should only trigger when matches are present. If false {@link diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageFilter.java b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageFilter.java index f224756..72f40a7 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageFilter.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageFilter.java @@ -7,7 +7,7 @@ */ package io.github.darkkronicle.advancedchatcore.interfaces; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.Optional; /** An interface to modify text. */ @@ -15,8 +15,8 @@ public interface IMessageFilter { /** * Modifies text * - * @param text Text to modify + * @param text Component to modify * @return Modified text. If empty, the text won't be changed. */ - Optional filter(Text text); + Optional filter(Component text); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageProcessor.java b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageProcessor.java index cb2b992..5ee46bc 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageProcessor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IMessageProcessor.java @@ -7,9 +7,9 @@ */ package io.github.darkkronicle.advancedchatcore.interfaces; -import net.minecraft.client.gui.hud.MessageIndicator; -import net.minecraft.network.message.MessageSignatureData; -import net.minecraft.text.Text; +import net.minecraft.client.multiplayer.chat.GuiMessageTag; +import net.minecraft.network.chat.MessageSignature; +import net.minecraft.network.chat.Component; import java.util.Optional; import org.jetbrains.annotations.Nullable; @@ -21,12 +21,12 @@ public interface IMessageProcessor extends IMessageFilter { *

Deprecated because it won't return anything. If unfiltered doesn't exist, insert null into * process. * - * @param text Text to modify + * @param text Component to modify * @return Empty */ @Deprecated @Override - default Optional filter(Text text) { + default Optional filter(Component text) { process(text, null); return Optional.empty(); } @@ -38,9 +38,9 @@ default Optional filter(Text text) { * @param unfiltered Original text (if available) * @return If the processing was a success */ - boolean process(Text text, @Nullable Text unfiltered); + boolean process(Component text, @Nullable Component unfiltered); - default boolean process(Text text, @Nullable Text unfilterered, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator) { + default boolean process(Component text, @Nullable Component unfilterered, @Nullable MessageSignature signature, @Nullable GuiMessageTag indicator) { return process(text, unfilterered); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IScreenSupplier.java b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IScreenSupplier.java index f652491..4256b7a 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IScreenSupplier.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/IScreenSupplier.java @@ -8,7 +8,7 @@ package io.github.darkkronicle.advancedchatcore.interfaces; import java.util.function.Supplier; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; import org.jetbrains.annotations.Nullable; /** An interface to supply a screen. */ diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/RegistryOption.java b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/RegistryOption.java index 98da20c..94551e7 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/RegistryOption.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/interfaces/RegistryOption.java @@ -10,7 +10,7 @@ import io.github.darkkronicle.advancedchatcore.util.AbstractRegistry; import java.util.List; import java.util.function.Supplier; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; /** * An interface to get a RegistryOption that can be saved/configured in game. diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/konstruct/AdvancedChatKonstruct.java b/src/main/java/io/github/darkkronicle/advancedchatcore/konstruct/AdvancedChatKonstruct.java index 14d8772..aa1c07e 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/konstruct/AdvancedChatKonstruct.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/konstruct/AdvancedChatKonstruct.java @@ -84,7 +84,7 @@ public IntRange getArgumentCount() { return IntRange.of(1); } }); - addVariable("ms", () -> new IntegerObject((int) Util.getMeasuringTimeMs())); + addVariable("ms", () -> new IntegerObject((int) Util.getMillis())); } public ParseResult parse(Node node) { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHud.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHud.java index 037f0d4..f966b57 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHud.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHud.java @@ -11,12 +11,13 @@ import io.github.darkkronicle.advancedchatcore.chat.MessageDispatcher; import io.github.darkkronicle.advancedchatcore.config.ConfigStorage; import io.github.darkkronicle.advancedchatcore.util.ChatHudStyleHolder; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.client.gui.hud.MessageIndicator; -import net.minecraft.network.message.MessageSignatureData; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.client.multiplayer.chat.GuiMessageSource; +import net.minecraft.client.multiplayer.chat.GuiMessageTag; +import net.minecraft.network.chat.MessageSignature; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -26,21 +27,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(value = ChatHud.class, priority = 1050) +@Mixin(value = ChatComponent.class, priority = 1050) public class MixinChatHud { - @Shadow @Final private MinecraftClient client; + @Shadow @Final private Minecraft minecraft; @Inject( - method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", + method = "addMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/MessageSignature;Lnet/minecraft/client/multiplayer/chat/GuiMessageSource;Lnet/minecraft/client/multiplayer/chat/GuiMessageTag;)V", at = @At("HEAD"), cancellable = true) - private void addMessage(Text message, @Nullable MessageSignatureData signature, @Nullable MessageIndicator indicator, CallbackInfo ci) { + private void addMessage(Component message, @Nullable MessageSignature signature, + GuiMessageSource source, @Nullable GuiMessageTag indicator, CallbackInfo ci) { MessageDispatcher.getInstance().handleText(message, signature, indicator); ci.cancel(); } - @Inject(method = "clear", at = @At("HEAD"), cancellable = true) + @Inject(method = "clearMessages", at = @At("HEAD"), cancellable = true) private void clearMessages(boolean clearTextHistory, CallbackInfo ci) { if (!clearTextHistory) { return; @@ -52,29 +54,22 @@ private void clearMessages(boolean clearTextHistory, CallbackInfo ci) { @Inject(method = "isChatFocused", at = @At("HEAD"), cancellable = true) private void isChatFocused(CallbackInfoReturnable ci) { - ci.setReturnValue(AdvancedChatScreen.PERMANENT_FOCUS || client.currentScreen instanceof AdvancedChatScreen); + ci.setReturnValue(AdvancedChatScreen.PERMANENT_FOCUS || minecraft.gui.screen() instanceof AdvancedChatScreen); } - @Inject( - method = "render(Lnet/minecraft/client/gui/hud/ChatHud$Backend;IIZ)V", - at = @At("RETURN") - ) - private void captureHoveredStyle(ChatHud.Backend drawer, int windowHeight, int currentTick, boolean expanded, CallbackInfo ci) { - // Check if it's the Interactable backend by checking if it's an instance of the accessor - try { - if (drawer instanceof ChatHudInteractableAccessor) { - Style style = ((ChatHudInteractableAccessor) drawer).getStyle(); - ChatHudStyleHolder.setLastHoveredStyle(style); - } - } catch (Exception e) { - ChatHudStyleHolder.setLastHoveredStyle(null); - } - } + /** + * 26.2 replaced ChatHud$Interactable (whose `style` field was read after render) with + * ChatComponent$DrawingFocusedGraphicsAccess, which is a Consumer<Style> fed the + * hovered style as the chat draws. Hooking that consumer is both simpler and more + * direct than re-deriving the style after the fact. + */ + @Mixin(targets = "net.minecraft.client.gui.components.ChatComponent$DrawingFocusedGraphicsAccess") + public static class MixinDrawingFocusedGraphicsAccess { - @Mixin(targets = "net.minecraft.client.gui.hud.ChatHud$Interactable") - interface ChatHudInteractableAccessor { - @org.spongepowered.asm.mixin.gen.Accessor("style") - @Nullable - Style getStyle(); + @Inject(method = "accept(Lnet/minecraft/network/chat/Style;)V", at = @At("RETURN")) + private void advancedchatcore$captureHoveredStyle( + @Nullable Style style, CallbackInfo ci) { + ChatHudStyleHolder.setLastHoveredStyle(style); + } } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHudInvoker.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHudInvoker.java index f3d5283..a1097b9 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHudInvoker.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatHudInvoker.java @@ -7,16 +7,16 @@ */ package io.github.darkkronicle.advancedchatcore.mixin; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.client.gui.hud.ChatHudLine; +import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.client.multiplayer.chat.GuiMessage; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -@Mixin(ChatHud.class) +@Mixin(ChatComponent.class) public interface MixinChatHudInvoker { - @Invoker("addVisibleMessage") - void invokeAddVisibleMessage(ChatHudLine message); + @Invoker("addMessageToDisplayQueue") + void invokeAddVisibleMessage(GuiMessage message); - @Invoker("addMessage") - void invokeAddMessage(ChatHudLine message); + @Invoker("addMessageToQueue") + void invokeAddMessage(GuiMessage message); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatScreen.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatScreen.java index 97db1c0..57465f7 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatScreen.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinChatScreen.java @@ -9,8 +9,8 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; +import net.minecraft.client.gui.screens.ChatScreen; +import net.minecraft.client.gui.narration.NarrationElementOutput; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -20,8 +20,8 @@ @Mixin(ChatScreen.class) public class MixinChatScreen { - @Inject(method = "addScreenNarrations", at = @At("HEAD"), cancellable = true) - public void screenNarrations(NarrationMessageBuilder builder, CallbackInfo ci) { + @Inject(method = "updateNarrationState", at = @At("HEAD"), cancellable = true) + public void screenNarrations(NarrationElementOutput builder, CallbackInfo ci) { // Don't cause random narrations to happen/crashes ci.cancel(); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinClientPlayerEntity.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinClientPlayerEntity.java index 355db3d..3163bd2 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinClientPlayerEntity.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinClientPlayerEntity.java @@ -1,11 +1,11 @@ package io.github.darkkronicle.advancedchatcore.mixin; import io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.world.World; +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -13,31 +13,31 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ClientPlayerEntity.class) +@Mixin(LocalPlayer.class) public abstract class MixinClientPlayerEntity extends Entity { - @Shadow @Final protected MinecraftClient client; + @Shadow @Final protected Minecraft minecraft; - @Shadow public float nauseaIntensity; + @Shadow public float portalEffectIntensity; - public MixinClientPlayerEntity(EntityType type, World world) { + public MixinClientPlayerEntity(EntityType type, Level world) { super(type, world); } @Inject( - method="tickNausea", - at = @At(value="INVOKE", target="Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V"), + method="handlePortalTransitionEffect", + at = @At(value="INVOKE", target="Lnet/minecraft/client/gui/Gui;setScreen(Lnet/minecraft/client/gui/screens/Screen;)V"), cancellable = true ) public void tickNauseaHook(CallbackInfo ci) { - if (client.currentScreen instanceof AdvancedChatScreen) { + if (minecraft.gui.screen() instanceof AdvancedChatScreen) { ci.cancel(); - nauseaIntensity += 0.0125f; - if (this.nauseaIntensity >= 1.0f) { - this.nauseaIntensity = 1.0f; + portalEffectIntensity += 0.0125f; + if (this.portalEffectIntensity >= 1.0f) { + this.portalEffectIntensity = 1.0f; } - if(this.portalManager != null){ - portalManager.setInPortal(false); + if(this.portalProcess != null){ + portalProcess.setAsInsidePortalThisTick(false); } } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinKeyboard.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinKeyboard.java index 30cd665..48e2930 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinKeyboard.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinKeyboard.java @@ -10,21 +10,21 @@ import io.github.darkkronicle.advancedchatcore.chat.ChatHistory; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.Keyboard; -import net.minecraft.client.input.KeyInput; +import net.minecraft.client.KeyboardHandler; +import net.minecraft.client.input.KeyEvent; 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.CallbackInfoReturnable; @Environment(EnvType.CLIENT) -@Mixin(Keyboard.class) +@Mixin(KeyboardHandler.class) public class MixinKeyboard { @Inject( - method = "processF3", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;clear(Z)V")) - public void processF3Chat(KeyInput keyInput, CallbackInfoReturnable cir) { + method = "handleDebugKeys", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/ChatComponent;clearMessages(Z)V")) + public void processF3Chat(KeyEvent keyInput, CallbackInfoReturnable cir) { // Make it so that history can still be cleared ChatHistory.getInstance().clearAll(); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMessageIndicator.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMessageIndicator.java index 728ca22..6a5926d 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMessageIndicator.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMessageIndicator.java @@ -1,19 +1,19 @@ package io.github.darkkronicle.advancedchatcore.mixin; import io.github.darkkronicle.advancedchatcore.config.ConfigStorage; -import net.minecraft.client.gui.hud.MessageIndicator; +import net.minecraft.client.multiplayer.chat.GuiMessageTag; 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.CallbackInfoReturnable; -@Mixin(MessageIndicator.class) +@Mixin(GuiMessageTag.class) public class MixinMessageIndicator { @Inject(method = "indicatorColor", at = @At("HEAD"), cancellable = true) private void getColor(CallbackInfoReturnable ci) { - MessageIndicator indicator = ((MessageIndicator) (Object) this); - String name = indicator.loggedName(); + GuiMessageTag indicator = ((GuiMessageTag) (Object) this); + String name = indicator.logTag(); ci.setReturnValue(switch (name) { case "Modified" -> ConfigStorage.ChatScreen.MODIFIED.config.getColor().intValue; case "Filtered" -> ConfigStorage.ChatScreen.FILTERED.config.getColor().intValue; @@ -25,7 +25,7 @@ private void getColor(CallbackInfoReturnable ci) { } @Inject(method = "icon", at = @At("HEAD"), cancellable = true) - private void getIcon(CallbackInfoReturnable ci) { + private void getIcon(CallbackInfoReturnable ci) { if (!ConfigStorage.ChatScreen.SHOW_CHAT_ICONS.config.getBooleanValue()) { ci.setReturnValue(null); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMinecraftClient.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMinecraftClient.java index bc1e858..e409efc 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMinecraftClient.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinMinecraftClient.java @@ -13,29 +13,30 @@ import io.github.darkkronicle.advancedchatcore.chat.AdvancedSleepingChatScreen; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.client.gui.screen.ChatScreen; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.client.gui.screens.ChatScreen; 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; @Environment(EnvType.CLIENT) -@Mixin(MinecraftClient.class) +@Mixin(Gui.class) public class MixinMinecraftClient { @Inject(method = "openChatScreen", at = @At(value = "HEAD"), cancellable = true) - public void openChatScreen(ChatHud.ChatMethod method, CallbackInfo ci) { - MinecraftClient.getInstance().setScreen(new AdvancedChatScreen(method.getReplacement())); + public void openChatScreen(ChatComponent.ChatMethod method, CallbackInfo ci) { + Minecraft.getInstance().gui.setScreen(new AdvancedChatScreen(method.prefix())); ci.cancel(); } @WrapOperation(method = "tick", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/gui/hud/ChatHud;setClientScreen(Lnet/minecraft/client/gui/hud/ChatHud$ChatMethod;Lnet/minecraft/client/gui/screen/ChatScreen$Factory;)V")) - public void openSleepingChatScreen(ChatHud instance, ChatHud.ChatMethod method, ChatScreen.Factory factory, Operation original) { - MinecraftClient.getInstance().setScreen(new AdvancedSleepingChatScreen()); + target = "Lnet/minecraft/client/gui/components/ChatComponent;openScreen(Lnet/minecraft/client/gui/components/ChatComponent$ChatMethod;Lnet/minecraft/client/gui/screens/ChatScreen$ChatConstructor;)V")) + public void openSleepingChatScreen(ChatComponent instance, ChatComponent.ChatMethod method, ChatScreen.ChatConstructor factory, Operation original) { + Minecraft.getInstance().gui.setScreen(new AdvancedSleepingChatScreen()); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinSleepingChatScreen.java b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinSleepingChatScreen.java index f935fb7..1f24c09 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinSleepingChatScreen.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/mixin/MixinSleepingChatScreen.java @@ -10,27 +10,27 @@ import io.github.darkkronicle.advancedchatcore.chat.AdvancedChatScreen; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.SleepingChatScreen; +import net.minecraft.client.gui.screens.ChatScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.InBedChatScreen; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; @Environment(EnvType.CLIENT) -@Mixin(SleepingChatScreen.class) +@Mixin(InBedChatScreen.class) public class MixinSleepingChatScreen extends ChatScreen { public MixinSleepingChatScreen() { super("", false); } - @ModifyArg(method = "closeChatIfEmpty", + @ModifyArg(method = "onPlayerWokeUp", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 1)) + target = "Lnet/minecraft/client/gui/Gui;setScreen(Lnet/minecraft/client/gui/screens/Screen;)V", ordinal = 1)) public Screen openSleepingChatScreen(@Nullable Screen screen) { - return new AdvancedChatScreen(this.chatField.getText()); + return new AdvancedChatScreen(this.input.getValue()); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/ChatHudStyleHolder.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/ChatHudStyleHolder.java index afd2df8..97e837d 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/ChatHudStyleHolder.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/ChatHudStyleHolder.java @@ -1,6 +1,6 @@ package io.github.darkkronicle.advancedchatcore.util; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import org.jspecify.annotations.Nullable; public class ChatHudStyleHolder { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/ColorUtil.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/ColorUtil.java index 7a017a7..149216d 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/ColorUtil.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/ColorUtil.java @@ -8,7 +8,8 @@ package io.github.darkkronicle.advancedchatcore.util; import lombok.experimental.UtilityClass; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.TextColor; /** * A static utility class that helps when dealing with colors that use bit shifting, like Minecraft. @@ -56,7 +57,9 @@ public Color fade(Color color, float percent) { return color.withAlpha((int) Math.floor((alpha * percent))); } - public Color colorFromFormatting(Formatting formatting) { - return new Color(formatting.getColorValue()); + public Color colorFromFormatting(ChatFormatting formatting) { + TextColor color = TextColor.fromLegacyFormat(formatting); + // Formatting-only codes (bold, italic, ...) carry no colour + return color == null ? new Color(0) : new Color(color.getValue()); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/ModifierKeyUtil.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/ModifierKeyUtil.java index eb3fd16..bf469dc 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/ModifierKeyUtil.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/ModifierKeyUtil.java @@ -1,33 +1,33 @@ package io.github.darkkronicle.advancedchatcore.util; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.input.SystemKeycodes; -import net.minecraft.client.util.InputUtil; +import net.minecraft.client.Minecraft; +import net.minecraft.client.input.InputQuirks; +import com.mojang.blaze3d.platform.InputConstants; public class ModifierKeyUtil { public static boolean hasControlDown() { - if (SystemKeycodes.IS_MAC_OS) { - return InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow(), 343) - || InputUtil.isKeyPressed( - MinecraftClient.getInstance().getWindow(), + if (InputQuirks.REPLACE_CTRL_KEY_WITH_CMD_KEY) { + return InputConstants.isKeyDown(Minecraft.getInstance().getWindow(), 343) + || InputConstants.isKeyDown( + Minecraft.getInstance().getWindow(), 347 ); } else { - return InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow(), 341) - || InputUtil.isKeyPressed( - MinecraftClient.getInstance().getWindow(), + return InputConstants.isKeyDown(Minecraft.getInstance().getWindow(), 341) + || InputConstants.isKeyDown( + Minecraft.getInstance().getWindow(), 345 ); } } public static boolean hasShiftDown() { - return InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow(), 340) - || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow(), 344); + return InputConstants.isKeyDown(Minecraft.getInstance().getWindow(), 340) + || InputConstants.isKeyDown(Minecraft.getInstance().getWindow(), 344); } public static boolean hasAltDown() { - return InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow(), 342) - || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow(), 346); + return InputConstants.isKeyDown(Minecraft.getInstance().getWindow(), 342) + || InputConstants.isKeyDown(Minecraft.getInstance().getWindow(), 346); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/RawText.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/RawText.java index 85ef30c..7d9beb2 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/RawText.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/RawText.java @@ -1,12 +1,14 @@ package io.github.darkkronicle.advancedchatcore.util; -import net.minecraft.text.*; -import net.minecraft.util.Language; +import net.minecraft.network.chat.*; +import net.minecraft.network.chat.contents.PlainTextContents; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.locale.Language; import java.util.ArrayList; import java.util.List; -public record RawText(String content, Style style) implements Text { +public record RawText(String content, Style style) implements Component { @Override public Style getStyle() { @@ -14,8 +16,8 @@ public Style getStyle() { } @Override - public TextContent getContent() { - return PlainTextContent.of(content); + public ComponentContents getContents() { + return PlainTextContents.create(content); } @Override @@ -24,14 +26,14 @@ public String getString() { } @Override - public List getSiblings() { + public List getSiblings() { return new ArrayList<>(); } @Override - public OrderedText asOrderedText() { + public FormattedCharSequence getVisualOrderText() { Language language = Language.getInstance(); - return language.reorder(this); + return language.getVisualOrder(this); } public RawText withString(String string) { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchResult.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchResult.java index 124d654..4d672f3 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchResult.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchResult.java @@ -12,7 +12,7 @@ import lombok.Getter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.ArrayList; import java.util.Collections; @@ -147,7 +147,7 @@ public static SearchResult searchOf(String input, String match, FindType type) { * @param type {@link FindType} way to search * @return SearchResult with compiled searches */ - public static SearchResult searchOf(Text input, String match, FindType type) { + public static SearchResult searchOf(Component input, String match, FindType type) { IFinder finder = type.getFinder(); List matches = finder.getMatches(input, match); return new SearchResult(input.getString(), match, finder, matches); diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchUtils.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchUtils.java index 96e1c53..1724ce9 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchUtils.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/SearchUtils.java @@ -21,9 +21,9 @@ import lombok.experimental.UtilityClass; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.PlayerListEntry; -import net.minecraft.text.Text; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.network.chat.Component; /** * A class used for helping filters find matches and act on them. Helps with Regular Expressions and @@ -61,7 +61,7 @@ public boolean isMatch(String input, String toMatch, FindType type) { * @param type How toMatch should be interpreted. * @return If a match is found. */ - public boolean isMatch(Text input, String toMatch, FindType type) { + public boolean isMatch(Component input, String toMatch, FindType type) { IFinder finder = type.getFinder(); if (finder == null) { return false; @@ -125,15 +125,15 @@ public Optional> findMatches(String input, String toMatch, Fin } /** - * Method to find all matches within a text. Is similar to {@link #isMatch(Text, String, + * Method to find all matches within a text. Is similar to {@link #isMatch(Component, String, * FindType)}}. This method just finds every match and returns it. * - * @param input Text to search. + * @param input Component to search. * @param toMatch Expression to find. * @param type How toMatch should be interpreted. * @return An Optional containing a list of {@link StringMatch} */ - public Optional> findMatches(Text input, String toMatch, FindType type) { + public Optional> findMatches(Component input, String toMatch, FindType type) { IFinder finder = type.getFinder(); if (finder == null) { return Optional.empty(); @@ -175,7 +175,7 @@ public Optional getMatch(String input, String toMatch, FindType typ * @param type {@link FindType} way to search * @return Optional of a {@link StringMatch} if found */ - public Optional getMatch(Text input, String toMatch, FindType type) { + public Optional getMatch(Component input, String toMatch, FindType type) { IFinder finder = type.getFinder(); if (finder == null) { return Optional.empty(); @@ -193,10 +193,10 @@ public Optional getMatch(Text input, String toMatch, FindType type) * Get the author of a message using regex * * @param networkHandler Network handler to get player data - * @param text Text to search + * @param text Component to search * @return Owner of the message */ - public MessageOwner getAuthor(ClientPlayNetworkHandler networkHandler, String text) { + public MessageOwner getAuthor(ClientPacketListener networkHandler, String text) { if (networkHandler == null) { return null; } @@ -209,16 +209,16 @@ public MessageOwner getAuthor(ClientPlayNetworkHandler networkHandler, String te return null; } // Start by just checking names and such - PlayerListEntry player = null; + PlayerInfo player = null; StringMatch match = null; for (StringMatch m : words.get()) { if (player != null) { break; } - for (PlayerListEntry e : networkHandler.getPlayerList()) { + for (PlayerInfo e : networkHandler.getOnlinePlayers()) { // Easy mode - if ((e.getDisplayName() != null - && m.match.equals(stripColorCodes(e.getDisplayName().getString()))) + if ((e.getTabListDisplayName() != null + && m.match.equals(stripColorCodes(e.getTabListDisplayName().getString()))) || m.match.equals(e.getProfile().name())) { player = e; match = m; @@ -227,13 +227,13 @@ public MessageOwner getAuthor(ClientPlayNetworkHandler networkHandler, String te } } // Check for ***everything*** - HashMap> entryMatches = new HashMap<>(); - for (PlayerListEntry e : networkHandler.getPlayerList()) { + HashMap> entryMatches = new HashMap<>(); + for (PlayerInfo e : networkHandler.getOnlinePlayers()) { String name = stripColorCodes( - e.getDisplayName() == null + e.getTabListDisplayName() == null ? e.getProfile().name() - : e.getDisplayName().getString()); + : e.getTabListDisplayName().getString()); Optional> nameWords = SearchUtils.findMatches( name, @@ -245,7 +245,7 @@ public MessageOwner getAuthor(ClientPlayNetworkHandler networkHandler, String te entryMatches.put(e, nameWords.get()); } for (StringMatch m : words.get()) { - for (Map.Entry> entry : entryMatches.entrySet()) { + for (Map.Entry> entry : entryMatches.entrySet()) { for (StringMatch nm : entry.getValue()) { if (nm.match.equals(m.match)) { if (player != null && match.start <= m.start) { diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/StringInsert.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/StringInsert.java index 47ae42c..d5ea5b9 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/StringInsert.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/StringInsert.java @@ -1,19 +1,19 @@ package io.github.darkkronicle.advancedchatcore.util; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Component; /** * An interface to provide a way to get the text that should be replaced based off of the - * current {@link Text} and the current {@link StringMatch} + * current {@link Component} and the current {@link StringMatch} */ public interface StringInsert { /** - * Return's the {@link MutableText} that should be inserted. + * Return's the {@link MutableComponent} that should be inserted. * - * @param current The current {@link Text} + * @param current The current {@link Component} * @param match The current {@link StringMatch} * @return */ - MutableText getText(Text current, StringMatch match); + MutableComponent getText(Component current, StringMatch match); } \ No newline at end of file diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/StyleFormatter.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/StyleFormatter.java index 70760ab..4dcb25b 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/StyleFormatter.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/StyleFormatter.java @@ -12,10 +12,12 @@ import java.util.Optional; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.util.ChatMessages; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.ComponentRenderUtils; +import net.minecraft.network.chat.*; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.network.chat.FormattedText; +import net.minecraft.ChatFormatting; import net.minecraft.util.Unit; /** Class to format text without losing data */ @@ -24,7 +26,7 @@ public class StyleFormatter { /** * An interface to take multiple inputs from a string that has the Section Symbol formatting - * combined with standard {@link Text} formatting. + * combined with standard {@link Component} formatting. */ public interface FormattingVisitable { /** @@ -101,13 +103,13 @@ private Result updateSection(Style textStyle, Character nextChar, String rest) { if (currentStyle.equals(Style.EMPTY) || currentStyle.equals(textStyle)) { // If it's empty or different rely on just the current text style // Arbitrary color - currentStyle = textStyle.withExclusiveFormatting(Formatting.BLACK); + currentStyle = textStyle.applyLegacyFormat(ChatFormatting.BLACK); } else { // Styles are different so we take what happened before. This allows us to chain // formatting symbols. // Arbitrary color to reset - currentStyle = currentStyle.withExclusiveFormatting(Formatting.BLACK); + currentStyle = currentStyle.applyLegacyFormat(ChatFormatting.BLACK); } currentStyle = currentStyle.withColor(color); currentIndex += 7; @@ -115,19 +117,19 @@ private Result updateSection(Style textStyle, Character nextChar, String rest) { } return Result.INCREMENT; } - Formatting formatting = Formatting.byCode(nextChar); + ChatFormatting formatting = ChatFormatting.getByCode(nextChar); if (formatting != null) { - if (formatting == Formatting.RESET) { + if (formatting == ChatFormatting.RESET) { // If it resets, just go to what the current text is. currentStyle = textStyle; } else { if (currentStyle.equals(Style.EMPTY) || currentStyle.equals(textStyle)) { // If it's empty or different rely on just the current text style - currentStyle = textStyle.withExclusiveFormatting(formatting); + currentStyle = textStyle.applyLegacyFormat(formatting); } else { // Styles are different so we take what happened before. This allows us to chain // formatting symbols. - currentStyle = currentStyle.withExclusiveFormatting(formatting); + currentStyle = currentStyle.applyLegacyFormat(formatting); } } if (currentStyle.equals(Style.EMPTY)) { @@ -166,7 +168,7 @@ public Optional> updateStyle(Style textStyle, String string) { case SKIP: return Optional.empty(); case TERMINATE: - return Optional.of(StringVisitable.TERMINATE_VISIT); + return Optional.of(FormattedText.STOP_ITERATION); case INCREMENT: i++; } @@ -174,7 +176,7 @@ public Optional> updateStyle(Style textStyle, String string) { } else if (sendToVisitor(c, textStyle)) { realIndex++; } else { - return Optional.of(StringVisitable.TERMINATE_VISIT); + return Optional.of(FormattedText.STOP_ITERATION); } currentIndex++; } @@ -188,16 +190,16 @@ public Optional> updateStyle(Style textStyle, String string) { *

This method is used to remove section symbols while maintaining previous formatting as * well as new formatting. * - * @param text Text to reformat + * @param text Component to reformat * @return Formatted text */ - public static MutableText formatText(Text text) { - MutableText t = Text.empty(); + public static MutableComponent formatText(Component text) { + MutableComponent t = Component.empty(); int length = text.getString().length(); StyleFormatter formatter = new StyleFormatter( (c, index, formattedIndex, style, formattedStyle) -> { - t.append(Text.literal(String.valueOf(c)).fillStyle(formattedStyle)); + t.append(Component.literal(String.valueOf(c)).withStyle(formattedStyle)); return true; }, length); @@ -205,22 +207,22 @@ public static MutableText formatText(Text text) { return flattenText(t); } - public static MutableText flattenText(Text text) { - List newSiblings = new ArrayList<>(); + public static MutableComponent flattenText(Component text) { + List newSiblings = new ArrayList<>(); Style last = text.getStyle(); - StringBuilder content = new StringBuilder(TextUtil.getContent(text.getContent())); - for (Text t : text.getSiblings()) { + StringBuilder content = new StringBuilder(TextUtil.getContent(text.getContents())); + for (Component t : text.getSiblings()) { if (t.getStyle().equals(last)) { - content.append(TextUtil.getContent(t.getContent())); + content.append(TextUtil.getContent(t.getContents())); continue; } - newSiblings.add(Text.literal(content.toString()).fillStyle(last)); - content = new StringBuilder(TextUtil.getContent(t.getContent())); + newSiblings.add(Component.literal(content.toString()).withStyle(last)); + content = new StringBuilder(TextUtil.getContent(t.getContents())); last = t.getStyle(); } - newSiblings.add(Text.literal(content.toString()).fillStyle(last)); - MutableText newText = Text.empty(); - for (Text sibling : newSiblings) { + newSiblings.add(Component.literal(content.toString()).withStyle(last)); + MutableComponent newText = Component.empty(); + for (Component sibling : newSiblings) { newText.append(sibling); } return newText; @@ -229,14 +231,14 @@ public static MutableText flattenText(Text text) { /** * Wraps text into multiple lines * - * @param textRenderer TextRenderer to handle text + * @param textRenderer Font to handle text * @param scaledWidth Maximum width before the line breaks - * @param text Text to break up - * @return List of MutableText of the new lines + * @param text Component to break up + * @return List of MutableComponent of the new lines */ - public static List wrapText(TextRenderer textRenderer, int scaledWidth, Text text) { - ArrayList lines = new ArrayList<>(); - for (OrderedText breakRenderedChatMessageLine : ChatMessages.breakRenderedChatMessageLines(text, scaledWidth, textRenderer)) { + public static List wrapText(Font textRenderer, int scaledWidth, Component text) { + ArrayList lines = new ArrayList<>(); + for (FormattedCharSequence breakRenderedChatMessageLine : ComponentRenderUtils.wrapComponents(text, scaledWidth, textRenderer)) { lines.add(new TextBuilder().append(breakRenderedChatMessageLine).build()); } return lines; diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/SyncTaskQueue.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/SyncTaskQueue.java index a1daa5d..d89f41f 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/SyncTaskQueue.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/SyncTaskQueue.java @@ -33,7 +33,7 @@ public static class QueuedTask implements Comparable { /** * Tick number when it should be triggered. This isn't delay, this is based off of the - * current tick value in {@link net.minecraft.client.gui.hud.InGameHud} + * current tick value in {@link net.minecraft.client.gui.hud.Gui} */ int tick; diff --git a/src/main/java/io/github/darkkronicle/advancedchatcore/util/TextBuilder.java b/src/main/java/io/github/darkkronicle/advancedchatcore/util/TextBuilder.java index 72fc4d3..81bc8bd 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatcore/util/TextBuilder.java +++ b/src/main/java/io/github/darkkronicle/advancedchatcore/util/TextBuilder.java @@ -1,6 +1,7 @@ package io.github.darkkronicle.advancedchatcore.util; -import net.minecraft.text.*; +import net.minecraft.network.chat.*; +import net.minecraft.util.FormattedCharSequence; import java.util.ArrayList; import java.util.List; @@ -25,7 +26,7 @@ public List getTexts() { return siblings; } - public TextBuilder append(OrderedText text) { + public TextBuilder append(FormattedCharSequence text) { AtomicReference