diff --git a/build.gradle b/build.gradle index e190e94..d2f3bf6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,23 +1,29 @@ 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) + languageVersion = JavaLanguageVersion.of(25) } } base { archivesName = project.archives_base_name } +lombok { + version = project.lombok_version +} + version = "${project.minecraft_version}-${project.mod_version}" group = project.maven_group repositories { + mavenLocal() mavenCentral() + maven { url 'https://api.modrinth.com/maven' } mavenLocal() // only used to build the mod locally maven { url 'https://masa.dy.fi/maven' } maven { url 'https://jitpack.io' } @@ -36,11 +42,10 @@ repositories { dependencies { 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 files("../malilib-fabric-1.21.11-0.27.8.jar") - modImplementation files("../AdvancedChatCore-1.21.11-1.5.17-alpha.1.jar") + 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}" + implementation "com.arematics:advancedchatcore:${project.advancedchat_version}" implementation "org.mariuszgromada.math:MathParser.org-mXparser:${project.mxparser_version}" include "org.mariuszgromada.math:MathParser.org-mXparser:${project.mxparser_version}" @@ -80,7 +85,8 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - it.options.release = 21 + it.options.release = 25 + it.options.compilerArgs << "-Xmaxerrs" << "10000" } java { @@ -94,11 +100,11 @@ jar { publishing { publications { mavenJava(MavenPublication) { - artifact(remapJar) { - builtBy remapJar + artifact(jar) { + builtBy jar } artifact(sourcesJar) { - builtBy remapSourcesJar + builtBy sourcesJar } } } diff --git a/gradle.properties b/gradle.properties index 3fe0687..da68ee5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,18 @@ org.gradle.jvmargs=-Xmx3g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # https://fabricmc.net/develop -minecraft_version=1.21.11 -yarn_mappings=1.21.11+build.4 -loader_version=0.17.3 -loom_version=1.15.5 -fabric_api_version=0.136.0+1.21.11 +minecraft_version=26.2 +loader_version=0.19.3 +loom_version=1.17.+ +fabric_api_version=0.156.0+26.2 -mod_version=1.6.1 +mod_version=1.7.2-alpha.1 maven_group=com.arematics archives_base_name=AdvancedChatBox -advancedchat_version=1.21.11-1.6.1 +advancedchat_version=26.2-1.7.2-alpha.1 # https://jitpack.io/#sakura-ryoko/malilib -malilib_version=0.27.8 +malilib_version=0.29.3 # https://repo.maven.apache.org/maven2/org/mariuszgromada/math/MathParser.org-mXparser mxparser_version=4.4.2 @@ -29,3 +28,7 @@ project_color=0x4480ad changelog_hide_unimportant_commits=true changelog_max_commit_search=200 discord_webhook_changelog_line_limit=10 + +# 1.18.42+ is required for JDK 25 +lombok_version=1.18.46 +modmenu_version=20.0.1 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 63e0e83..52ad5e7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-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 dfacbd1..6369cb4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,7 +4,12 @@ pluginManagement { name = 'Fabric' url = 'https://maven.fabricmc.net/' } - mavenCentral() gradlePluginPortal() + 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/advancedchatbox/chat/AdvancedSuggestion.java b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/AdvancedSuggestion.java index 92c245d..36e007d 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/AdvancedSuggestion.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/AdvancedSuggestion.java @@ -15,15 +15,15 @@ import lombok.Getter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; /** Suggestion that contains render text, suggested text, suggested start/stop, and tooltip. */ @Environment(EnvType.CLIENT) public class AdvancedSuggestion extends Suggestion { @Nonnull @Getter - private final Text render; + private final Component render; /** * @param range Range from the original string where it is recommending @@ -31,7 +31,7 @@ public class AdvancedSuggestion extends Suggestion { * @param render How the suggestion will render * @param tooltip Message to show up on hover */ - public AdvancedSuggestion(StringRange range, String text, Text render, Message tooltip) { + public AdvancedSuggestion(StringRange range, String text, Component render, Message tooltip) { super(range, text, tooltip); if (render == null) { this.render = new RawText(text, Style.EMPTY); diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatBoxSection.java b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatBoxSection.java index 87d9d21..4bc2d5b 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatBoxSection.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatBoxSection.java @@ -12,11 +12,11 @@ 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.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.input.KeyEvent; +import com.mojang.blaze3d.vertex.PoseStack; @Environment(EnvType.CLIENT) public class ChatBoxSection extends AdvancedChatScreenSection { @@ -33,12 +33,12 @@ public void onChatFieldUpdate(String chatText, String text) { } @Override - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { return this.suggestor.keyPressed(input); } @Override - public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { + public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float partialTicks) { this.suggestor.render(context, mouseX, mouseY); } @@ -53,7 +53,7 @@ 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.suggestor.mouseClicked(click, doubled); } @@ -64,9 +64,9 @@ public void resize(int width, int height) { @Override public void initGui() { - MinecraftClient client = MinecraftClient.getInstance(); + Minecraft client = Minecraft.getInstance(); AdvancedChatScreen screen = getScreen(); - this.suggestor = new ChatSuggestorGui(client, screen, screen.getChatField(), client.textRenderer, false, false, + this.suggestor = new ChatSuggestorGui(client, screen, screen.getChatField(), client.font, false, false, 1, ChatBoxConfigStorage.General.SUGGESTION_SIZE.config.getIntegerValue(), true); this.suggestor.refresh(); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatFormatter.java b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatFormatter.java index 493d808..22b7c41 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatFormatter.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatFormatter.java @@ -19,9 +19,10 @@ import io.github.darkkronicle.advancedchatcore.util.TextUtil; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.network.chat.*; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.ChatFormatting; /** * A class to format the chat box on the @@ -32,12 +33,12 @@ public class ChatFormatter { private String current = null; /** The formatted current */ - private Text last = null; + private Component last = null; - private final TextFieldWidget widget; + private final EditBox widget; private final ChatSuggestor suggestor; - public ChatFormatter(TextFieldWidget widget, ChatSuggestor suggestor) { + public ChatFormatter(EditBox widget, ChatSuggestor suggestor) { this.widget = widget; this.suggestor = suggestor; } @@ -48,8 +49,8 @@ public ChatFormatter(TextFieldWidget widget, ChatSuggestor suggestor) { * @param string Contents * @return Formatted FluidText. If nothing is changed it will be the contents with Style.EMPTY */ - public Text format(String string) { - Text text = Text.literal(string); + public Component format(String string) { + Component text = Component.literal(string); if (string.length() == 0) { return text; } @@ -82,11 +83,11 @@ public Text format(String string) { String matchString = string.subSequence(start, end).toString(); format.put(new StringMatch(matchString, start, end), (current, match) -> { Style style = Style.EMPTY; - style = style.withFormatting(Formatting.UNDERLINE); + style = style.applyFormat(ChatFormatting.UNDERLINE); TextColor textColor = TextColor .fromRgb(ChatBoxConfigStorage.General.AVAILABLE_SUGGESTION_COLOR.config.getIntegerValue()); style = style.withColor(textColor); - return Text.literal(matchString).fillStyle(style); + return Component.literal(matchString).withStyle(style); }); } text = TextUtil.replaceStrings(text, format); @@ -95,7 +96,7 @@ public Text format(String string) { if (!option.isActive()) { continue; } - Optional otext = option.getOption().format(text, suggestor.getParse()); + Optional otext = option.getOption().format(text, suggestor.getParse()); if (otext.isPresent()) { text = otext.get(); } @@ -103,13 +104,13 @@ public Text format(String string) { return text; } - private OrderedText set(String s, Integer integer) { + private FormattedCharSequence set(String s, Integer integer) { int length = s.length(); if (length == 0) { - return OrderedText.EMPTY; + return FormattedCharSequence.EMPTY; } if (last.getString().length() == 0) { - return OrderedText.EMPTY; + return FormattedCharSequence.EMPTY; } int start = integer; int end = integer + length; @@ -117,11 +118,11 @@ private OrderedText set(String s, Integer integer) { if (end > fluidLength) { end = fluidLength; } - return TextUtil.truncate(last, new StringMatch(s, start, end)).asOrderedText(); + return TextUtil.truncate(last, new StringMatch(s, start, end)).getVisualOrderText(); } - public OrderedText apply(String s, Integer integer) { - String text = widget.getText(); + public FormattedCharSequence apply(String s, Integer integer) { + String text = widget.getValue(); if (text.equals(current)) { // If the content hasn't changed, use the previous one. return set(s, integer); diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestor.java b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestor.java index e4da52e..3910154 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestor.java @@ -32,10 +32,10 @@ import lombok.Getter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.network.ClientCommandSource; -import net.minecraft.command.CommandSource; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; +import net.minecraft.commands.SharedSuggestionProvider; /** A maintainer of suggestions to suggest to the player. */ @Environment(EnvType.CLIENT) @@ -45,7 +45,7 @@ public class ChatSuggestor { /** Parsed command results */ @Getter - private ParseResults parse; + private ParseResults parse; /** Suggestions to complete */ @Getter @@ -59,12 +59,12 @@ public class ChatSuggestor { @Getter private List allSuggestions; - private final TextFieldWidget textField; - private final MinecraftClient client; + private final EditBox textField; + private final Minecraft client; - public ChatSuggestor(TextFieldWidget textField) { + public ChatSuggestor(EditBox textField) { this.textField = textField; - this.client = MinecraftClient.getInstance(); + this.client = Minecraft.getInstance(); } /** @@ -111,7 +111,7 @@ public void updateCommandSuggestions(Runnable after) { public void updateCommandSuggestions(boolean includePlayerFallback, Runnable after) { allSuggestions = null; - CommandDispatcher commandDispatcher = client.player.networkHandler.getCommandDispatcher(); + CommandDispatcher commandDispatcher = client.player.connection.getCommands(); pendingSuggestions = commandDispatcher.getCompletionSuggestions(this.parse, getCursorIndex()) .thenApplyAsync(suggestions -> { AdvancedSuggestions vanillaSuggestions = AdvancedSuggestions.fromSuggestions(suggestions); @@ -136,7 +136,7 @@ public boolean updateCommandSpellcheckSuggestions() { } private AdvancedSuggestions getCommandSpellcheckSuggestions() { - String currentText = textField.getText(); + String currentText = textField.getValue(); String startToCursor = currentText.substring(0, getCursorIndex()); int wordIndex = getLastWord(startToCursor); ArrayList suggestions = new ArrayList<>(); @@ -146,7 +146,7 @@ private AdvancedSuggestions getCommandSpellcheckSuggestions() { } private AdvancedSuggestions getCommandFallbackSuggestions(boolean includePlayerFallback) { - String currentText = textField.getText(); + String currentText = textField.getValue(); String startToCursor = currentText.substring(0, getCursorIndex()); int wordIndex = getLastWord(startToCursor); ArrayList suggestions = new ArrayList<>(); @@ -230,9 +230,9 @@ private static int getCommandSpellcheckStart(String currentText) { * @param stringReader StringReader which contains reading string */ public void updateParse(StringReader stringReader) { - CommandDispatcher commandDispatcher = client.player.networkHandler.getCommandDispatcher(); + CommandDispatcher commandDispatcher = client.player.connection.getCommands(); if (parse == null) { - parse = commandDispatcher.parse(stringReader, client.player.networkHandler.getCommandSource()); + parse = commandDispatcher.parse(stringReader, client.player.connection.getSuggestionsProvider()); } } @@ -242,7 +242,7 @@ public void updateParse(StringReader stringReader) { * @return Cursor index */ private int getCursorIndex() { - return textField.getCursor(); + return textField.getCursorPosition(); } /** Update's suggestions specifically for chat (not command). */ @@ -252,7 +252,7 @@ public void updateChatSuggestions() { /** Update's suggestions specifically for chat (not command). */ public void updateChatSuggestions(boolean includePlayers) { - String startToCursor = textField.getText().substring(0, getCursorIndex()); + String startToCursor = textField.getValue().substring(0, getCursorIndex()); int wordIndex = getLastWord(startToCursor); ArrayList suggestions = new ArrayList<>(); for (ChatSuggestorRegistry.ChatSuggestorOption option : ChatSuggestorRegistry.getInstance().getAll()) { @@ -260,7 +260,7 @@ public void updateChatSuggestions(boolean includePlayers) { continue; } IMessageSuggestor suggestor = option.getOption(); - Optional> suggestion = suggestor.suggest(textField.getText()); + Optional> suggestion = suggestor.suggest(textField.getValue()); suggestion.ifPresent(suggestions::addAll); } this.allSuggestions = suggestions; @@ -297,8 +297,8 @@ private CompletableFuture suggestMatching(int start, String } for (AdvancedSuggestions suggestions : other) { - if (suggestions.getRange().getStart() <= textField.getCursor() - && suggestions.getRange().getEnd() >= textField.getCursor()) { + if (suggestions.getRange().getStart() <= textField.getCursorPosition() + && suggestions.getRange().getEnd() >= textField.getCursorPosition()) { newSuggestions.addAll(suggestions.getSuggestions()); } } @@ -391,7 +391,7 @@ private List modifySuggestions(AdvancedSuggestions suggestio * @return Ordered suggestions */ private List orderSuggestions(List suggestions) { - String string = this.textField.getText().substring(0, this.textField.getCursor()); + String string = this.textField.getValue().substring(0, this.textField.getCursorPosition()); String lastWord = string.substring(getLastWord(string)).toLowerCase(Locale.ROOT); List minecraftSuggestions = Lists.newArrayList(); List otherSuggestions = Lists.newArrayList(); diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestorGui.java b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestorGui.java index ab991cd..9640e5f 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestorGui.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/chat/ChatSuggestorGui.java @@ -28,39 +28,39 @@ import io.github.darkkronicle.advancedchatcore.util.ModifierKeyUtil; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.network.ClientCommandSource; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.client.util.math.Rect2i; -import net.minecraft.command.CommandSource; -import net.minecraft.server.command.CommandManager; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.text.Texts; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec2f; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; +import net.minecraft.client.resources.language.I18n; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.Rect2i; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.commands.Commands; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentUtils; +import net.minecraft.ChatFormatting; +import net.minecraft.util.Mth; +import net.minecraft.world.phys.Vec2; @Environment(EnvType.CLIENT) public class ChatSuggestorGui { - private final MinecraftClient client; + private final Minecraft client; private final Screen owner; - private final TextFieldWidget textField; - private final TextRenderer textRenderer; + private final EditBox textField; + private final Font textRenderer; private final boolean slashOptional; private final boolean suggestingWhenEmpty; private final int inWindowIndexOffset; private final int maxSuggestionSize; private final boolean chatScreenSized; - private final List messages = Lists.newArrayList(); + private final List messages = Lists.newArrayList(); private int x; private int width; private SuggestionWindow window; @@ -72,7 +72,7 @@ public class ChatSuggestorGui { private final ChatFormatter formatter; private final ChatSuggestor suggestor; - public ChatSuggestorGui(MinecraftClient client, Screen owner, TextFieldWidget textField, TextRenderer textRenderer, + public ChatSuggestorGui(Minecraft client, Screen owner, EditBox textField, Font textRenderer, boolean slashRequired, boolean suggestingWhenEmpty, int inWindowIndexOffset, int maxSuggestionSize, boolean chatScreenSized) { this.client = client; @@ -95,14 +95,14 @@ public void setWindowActive(boolean windowActive) { } } - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { if (this.window != null && this.window.keyPressed(input)) { return true; } if (this.owner.getFocused() == this.textField && input.key() == KeyCodes.KEY_TAB) { this.windowActive = true; this.showSuggestionsWhenReady = true; - if (isCommand(this.textField.getText())) { + if (isCommand(this.textField.getValue())) { if (this.suggestor.updateCommandSpellcheckSuggestions()) { this.showSuggestions(true); this.showSuggestionsWhenReady = false; @@ -124,10 +124,10 @@ public boolean keyPressed(KeyInput input) { } public boolean mouseScrolled(double amount) { - return (this.window != null && this.window.mouseScrolled(MathHelper.clamp(amount, -1.0D, 1.0D))); + return (this.window != null && this.window.mouseScrolled(Mth.clamp(amount, -1.0D, 1.0D))); } - public boolean mouseClicked(Click click, boolean doubled) { + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { return (this.window != null && this.window.mouseClicked((int) click.x(), (int) click.y(), click.button())); } @@ -142,17 +142,17 @@ public void showSuggestions(boolean narrateFirstSuggestion) { int width = 0; for (AdvancedSuggestion value : suggestions) { // Have suggestion be as wide as the biggest - width = Math.max(width, this.textRenderer.getWidth(value.getRender())); + width = Math.max(width, this.textRenderer.width(value.getRender())); } - int x = MathHelper.clamp(this.textField.getCharacterX(suggestor.getRange().getStart()), 0, - this.textField.getCharacterX(0) + this.textField.getInnerWidth() - width); + int x = Mth.clamp(this.textField.getScreenX(suggestor.getRange().getStart()), 0, + this.textField.getScreenX(0) + this.textField.getInnerWidth() - width); int y = this.chatScreenSized ? this.owner.height - 12 : 72; this.window = new SuggestionWindow(x, y, width, suggestions, narrateFirstSuggestion); } public void refresh() { - String currentText = this.textField.getText(); + String currentText = this.textField.getValue(); if (this.suggestor.getParse() != null && !this.suggestor.getParse().getReader().getString().equals(currentText)) { // Set it to null to signify that if it is still a command, to parse it @@ -173,7 +173,7 @@ public void refresh() { boolean suggestCommand = this.slashOptional || command; if (suggestCommand) { - int cursorIndex = this.textField.getCursor(); + int cursorIndex = this.textField.getCursorPosition(); this.suggestor.updateParse(stringReader); // Index 1 will enforce that the player typed at LEAST ONE character if ((this.suggestingWhenEmpty || cursorIndex >= stringReader.getCursor()) @@ -197,16 +197,16 @@ public void refresh() { } } - private static OrderedText formatException(CommandSyntaxException exception) { - Text text = Texts.toText(exception.getRawMessage()); + private static FormattedCharSequence formatException(CommandSyntaxException exception) { + Component text = ComponentUtils.fromMessage(exception.getRawMessage()); String string = exception.getContext(); - return string == null ? text.asOrderedText() - : (Text.translatable("command.context.parse_error", text, exception.getCursor(), string)) - .asOrderedText(); + return string == null ? text.getVisualOrderText() + : (Component.translatable("command.context.parse_error", text, exception.getCursor(), string)) + .getVisualOrderText(); } private void showIfActive(boolean autoShow) { - ParseResults parse = this.suggestor.getParse(); + ParseResults parse = this.suggestor.getParse(); if (parse == null) { this.x = 0; this.width = this.owner.width; @@ -218,11 +218,11 @@ private void showIfActive(boolean autoShow) { return; } - if (this.textField.getCursor() == this.textField.getText().length()) { + if (this.textField.getCursorPosition() == this.textField.getValue().length()) { if (this.suggestor.getSuggestions().isEmpty() && !parse.getExceptions().isEmpty()) { int builtInExceptions = 0; - for (Map.Entry, CommandSyntaxException> commandNodeCommandSyntaxExceptionEntry : parse + for (Map.Entry, CommandSyntaxException> commandNodeCommandSyntaxExceptionEntry : parse .getExceptions().entrySet()) { CommandSyntaxException commandSyntaxException = commandNodeCommandSyntaxExceptionEntry.getValue(); if (commandSyntaxException.getType() == CommandSyntaxException.BUILT_IN_EXCEPTIONS @@ -238,13 +238,13 @@ private void showIfActive(boolean autoShow) { CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().create())); } } else if (parse.getReader().canRead()) { - this.messages.add(formatException(CommandManager.getException(parse))); + this.messages.add(formatException(Commands.getParseException(parse))); } } this.x = 0; this.width = this.owner.width; if (this.messages.isEmpty()) { - this.showUsages(Formatting.GRAY); + this.showUsages(ChatFormatting.GRAY); } this.window = null; if (autoShow || this.windowActive) { @@ -257,35 +257,35 @@ private static boolean isCommand(String currentText) { return !currentText.isEmpty() && currentText.charAt(0) == '/'; } - private void showUsages(Formatting formatting) { + private void showUsages(ChatFormatting formatting) { if (this.suggestor.getParse() == null) { return; } - CommandContextBuilder commandContextBuilder = this.suggestor.getParse().getContext(); - SuggestionContext suggestionContext = - commandContextBuilder.findSuggestionContext(this.textField.getCursor()); - Map, String> map = this.client.player.networkHandler.getCommandDispatcher() - .getSmartUsage(suggestionContext.parent, this.client.player.networkHandler.getCommandSource()); - List list = new ArrayList<>(); + CommandContextBuilder commandContextBuilder = this.suggestor.getParse().getContext(); + SuggestionContext suggestionContext = + commandContextBuilder.findSuggestionContext(this.textField.getCursorPosition()); + Map, String> map = this.client.player.connection.getCommands() + .getSmartUsage(suggestionContext.parent, this.client.player.connection.getSuggestionsProvider()); + List list = new ArrayList<>(); int i = 0; Style style = Style.EMPTY.withColor(formatting); - for (Map.Entry, String> commandNodeStringEntry : map.entrySet()) { + for (Map.Entry, String> commandNodeStringEntry : map.entrySet()) { if (!(commandNodeStringEntry.getKey() instanceof LiteralCommandNode)) { - list.add(OrderedText.styledForwardsVisitedString(commandNodeStringEntry.getValue(), style)); - i = Math.max(i, this.textRenderer.getWidth(commandNodeStringEntry.getValue())); + list.add(FormattedCharSequence.forward(commandNodeStringEntry.getValue(), style)); + i = Math.max(i, this.textRenderer.width(commandNodeStringEntry.getValue())); } } if (!list.isEmpty()) { this.messages.addAll(list); - this.x = MathHelper.clamp(this.textField.getCharacterX(suggestionContext.startPos), 0, - this.textField.getCharacterX(0) + this.textField.getInnerWidth() - i); + this.x = Mth.clamp(this.textField.getScreenX(suggestionContext.startPos), 0, + this.textField.getScreenX(0) + this.textField.getInnerWidth() - i); this.width = i; } } - private OrderedText provideRenderText(String original, int firstCharacterIndex) { + private FormattedCharSequence provideRenderText(String original, int firstCharacterIndex) { return this.formatter.apply(original, firstCharacterIndex); } @@ -294,19 +294,19 @@ private static String getSuggestionSuffix(String original, String suggestion) { return suggestion.startsWith(original) ? suggestion.substring(original.length()) : null; } - public void render(DrawContext context, int mouseX, int mouseY) { + public void render(GuiGraphicsExtractor context, int mouseX, int mouseY) { if (this.window != null) { this.window.render(context, mouseX, mouseY); } else { int i = 0; - for (OrderedText message : this.messages) { + for (FormattedCharSequence message : this.messages) { i++; int j = this.chatScreenSized ? this.owner.height - 14 - 13 - 12 * i : 72 + 12 * i; context.fill(this.x - 1, j, this.x + this.width + 1, j + 12, ChatBoxConfigStorage.General.BACKGROUND_COLOR.config.getIntegerValue()); if (message != null) { - context.drawTextWithShadow(textRenderer, message, this.x, j + 2, -1); + context.text(textRenderer, message, this.x, j + 2, -1); } } } @@ -323,33 +323,33 @@ public class SuggestionWindow { private final List suggestions; private int inWindowIndex; private int selection; - private Vec2f mouse; + private Vec2 mouse; private boolean completed; private int lastNarrationIndex; private SuggestionWindow(int x, int y, int width, List list, boolean narrateFirstSuggestion) { - this.mouse = Vec2f.ZERO; + this.mouse = Vec2.ZERO; int renderX = x - 1; int renderY = ChatSuggestorGui.this.chatScreenSized ? y - 3 - Math.min(list.size(), ChatSuggestorGui.this.maxSuggestionSize) * 12 : y; this.area = new Rect2i(renderX, renderY, width + 1, Math.min(list.size(), ChatSuggestorGui.this.maxSuggestionSize) * 12); - this.typedText = ChatSuggestorGui.this.textField.getText(); + this.typedText = ChatSuggestorGui.this.textField.getValue(); this.lastNarrationIndex = narrateFirstSuggestion ? -1 : 0; this.suggestions = list; this.select(0); } - public void render(DrawContext context, int mouseX, int mouseY) { + public void render(GuiGraphicsExtractor context, int mouseX, int mouseY) { int suggestionSize = Math.min(this.suggestions.size(), ChatSuggestorGui.this.maxSuggestionSize); boolean moreBelow = this.inWindowIndex > 0; boolean moreAbove = this.suggestions.size() > this.inWindowIndex + suggestionSize; boolean more = moreBelow || moreAbove; boolean updateMouse = this.mouse.x != (float) mouseX || this.mouse.y != (float) mouseY; if (updateMouse) { - this.mouse = new Vec2f((float) mouseX, (float) mouseY); + this.mouse = new Vec2((float) mouseX, (float) mouseY); } if (more) { @@ -400,7 +400,7 @@ public void render(DrawContext context, int mouseX, int mouseY) { hover = true; } - context.drawTextWithShadow(ChatSuggestorGui.this.textRenderer, suggestion.getRender(), + context.text(ChatSuggestorGui.this.textRenderer, suggestion.getRender(), (this.area.getX() + 1), (this.area.getY() + 2 + 12 * s), (s + this.inWindowIndex) == this.selection ? ChatBoxConfigStorage.General.HIGHLIGHT_COLOR.config.getIntegerValue() @@ -410,7 +410,7 @@ public void render(DrawContext context, int mouseX, int mouseY) { if (hover) { Message message = this.suggestions.get(this.selection).getTooltip(); if (message != null) { - context.drawTooltip(textRenderer, Texts.toText(message), mouseX, mouseY); + context.setTooltipForNextFrame(textRenderer, ComponentUtils.fromMessage(message), mouseX, mouseY); } } } @@ -429,21 +429,21 @@ public boolean mouseClicked(int x, int y, int button) { } public boolean mouseScrolled(double amount) { - int x = (int) (ChatSuggestorGui.this.client.mouse.getX() - * (double) ChatSuggestorGui.this.client.getWindow().getScaledWidth() + int x = (int) (ChatSuggestorGui.this.client.mouseHandler.xpos() + * (double) ChatSuggestorGui.this.client.getWindow().getGuiScaledWidth() / (double) ChatSuggestorGui.this.client.getWindow().getWidth()); - int y = (int) (ChatSuggestorGui.this.client.mouse.getY() - * (double) ChatSuggestorGui.this.client.getWindow().getScaledHeight() + int y = (int) (ChatSuggestorGui.this.client.mouseHandler.ypos() + * (double) ChatSuggestorGui.this.client.getWindow().getGuiScaledHeight() / (double) ChatSuggestorGui.this.client.getWindow().getHeight()); if (this.area.contains(x, y)) { - this.inWindowIndex = MathHelper.clamp((int) ((double) this.inWindowIndex - amount), 0, + this.inWindowIndex = Mth.clamp((int) ((double) this.inWindowIndex - amount), 0, Math.max(this.suggestions.size() - ChatSuggestorGui.this.maxSuggestionSize, 0)); return true; } return false; } - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { if (input.key() == KeyCodes.KEY_UP) { this.scroll(-1); this.completed = false; @@ -475,10 +475,10 @@ public void scroll(int offset) { int maxInWindow = this.inWindowIndex + ChatSuggestorGui.this.maxSuggestionSize - 1; // Moving window logic if (this.selection < windowIndex) { - this.inWindowIndex = MathHelper.clamp(this.selection, 0, + this.inWindowIndex = Mth.clamp(this.selection, 0, Math.max(this.suggestions.size() - ChatSuggestorGui.this.maxSuggestionSize, 0)); } else if (this.selection > maxInWindow) { - this.inWindowIndex = MathHelper.clamp( + this.inWindowIndex = Mth.clamp( this.selection + ChatSuggestorGui.this.inWindowIndexOffset - ChatSuggestorGui.this.maxSuggestionSize, 0, Math.max(this.suggestions.size() - ChatSuggestorGui.this.maxSuggestionSize, 0)); @@ -499,32 +499,32 @@ public void select(int index) { Suggestion suggestion = this.suggestions.get(this.selection); ChatSuggestorGui.this.textField.setSuggestion(ChatSuggestorGui - .getSuggestionSuffix(ChatSuggestorGui.this.textField.getText(), suggestion.apply(this.typedText))); - if (client.getNarratorManager().isActive() && this.lastNarrationIndex != this.selection) { - client.getNarratorManager().narrate(this.getNarration()); + .getSuggestionSuffix(ChatSuggestorGui.this.textField.getValue(), suggestion.apply(this.typedText))); + if (client.getNarrator().isActive() && this.lastNarrationIndex != this.selection) { + client.getNarrator().saySystemChatQueued(this.getNarration()); } } public void complete() { Suggestion suggestion = this.suggestions.get(this.selection); ChatSuggestorGui.this.completingSuggestions = true; - ChatSuggestorGui.this.textField.setText(suggestion.apply(this.typedText)); + ChatSuggestorGui.this.textField.setValue(suggestion.apply(this.typedText)); int i = suggestion.getRange().getStart() + suggestion.getText().length(); - ChatSuggestorGui.this.textField.setSelectionStart(i); - ChatSuggestorGui.this.textField.setSelectionEnd(i); + ChatSuggestorGui.this.textField.setCursorPosition(i); + ChatSuggestorGui.this.textField.setHighlightPos(i); this.select(this.selection); ChatSuggestorGui.this.completingSuggestions = false; this.completed = true; } - private Text getNarration() { + private Component getNarration() { this.lastNarrationIndex = this.selection; Suggestion suggestion = this.suggestions.get(this.selection); Message message = suggestion.getTooltip(); - return Text.literal(message != null - ? I18n.translate("narration.suggestion.tooltip", this.selection + 1, this.suggestions.size(), + return Component.literal(message != null + ? I18n.get("narration.suggestion.tooltip", this.selection + 1, this.suggestions.size(), suggestion.getText(), message.getString()) - : I18n.translate("narration.suggestion", this.selection + 1, this.suggestions.size(), + : I18n.get("narration.suggestion", this.selection + 1, this.suggestions.size(), suggestion.getText())); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/config/ChatBoxConfigStorage.java b/src/main/java/io/github/darkkronicle/advancedchatbox/config/ChatBoxConfigStorage.java index 1237880..4b66fc7 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/config/ChatBoxConfigStorage.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/config/ChatBoxConfigStorage.java @@ -19,7 +19,7 @@ import fi.dy.masa.malilib.config.options.ConfigString; import fi.dy.masa.malilib.config.options.ConfigStringList; 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.advancedchatbox.AdvancedChatBox; import io.github.darkkronicle.advancedchatbox.registry.ChatFormatterRegistry; diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiChatBoxConfig.java b/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiChatBoxConfig.java index ce6a1c0..ad3be80 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiChatBoxConfig.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiChatBoxConfig.java @@ -18,7 +18,7 @@ import io.github.darkkronicle.advancedchatcore.config.gui.GuiConfigHandler; import io.github.darkkronicle.advancedchatcore.gui.buttons.ConfigTabsButtonListener; import io.github.darkkronicle.advancedchatcore.gui.buttons.NamedSimpleButton; -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/advancedchatbox/config/GuiFormatterRegistry.java b/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiFormatterRegistry.java index de2e22b..22cc85e 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiFormatterRegistry.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiFormatterRegistry.java @@ -14,7 +14,7 @@ import io.github.darkkronicle.advancedchatcore.gui.CoreGuiListBase; import io.github.darkkronicle.advancedchatcore.gui.buttons.BackButtonListener; import io.github.darkkronicle.advancedchatcore.gui.buttons.NamedSimpleButton; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; public class GuiFormatterRegistry extends CoreGuiListBase, WidgetListRegistryOption> { diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiSuggestorRegistry.java b/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiSuggestorRegistry.java index 33bf706..3557e50 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiSuggestorRegistry.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/config/GuiSuggestorRegistry.java @@ -14,7 +14,7 @@ import io.github.darkkronicle.advancedchatcore.gui.CoreGuiListBase; import io.github.darkkronicle.advancedchatcore.gui.buttons.BackButtonListener; import io.github.darkkronicle.advancedchatcore.gui.buttons.NamedSimpleButton; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; public class GuiSuggestorRegistry extends CoreGuiListBase, WidgetListRegistryOption> { diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckEntryWidget.java b/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckEntryWidget.java index dc996c2..2f50f0a 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckEntryWidget.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckEntryWidget.java @@ -20,7 +20,7 @@ import java.util.List; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.Minecraft; @Environment(EnvType.CLIENT) public class CommandSpellcheckEntryWidget extends WidgetConfigListEntry { @@ -44,9 +44,9 @@ public CommandSpellcheckEntryWidget(int x, int y, int width, int height, boolean pos -= removeWidth; GuiTextFieldGeneric commandField = new GuiTextFieldGeneric(x, y, pos - x, 20, - MinecraftClient.getInstance().textRenderer); + Minecraft.getInstance().font); commandField.setMaxLength(128); - commandField.setText(entry.getCommand()); + commandField.setValue(entry.getCommand()); command = new TextFieldWrapper<>(commandField, new SaveListener(this)); texts.add(command); parent.addTextField(command); @@ -63,7 +63,7 @@ public String getName() { } public void save() { - entry.setCommand(ChatBoxConfigStorage.General.normalizeCommand(command.textField().getText())); + entry.setCommand(ChatBoxConfigStorage.General.normalizeCommand(command.textField().getValue())); } private static class SaveListener implements ITextFieldListener { @@ -75,7 +75,7 @@ public SaveListener(CommandSpellcheckEntryWidget parent) { @Override public boolean onTextChange(GuiTextFieldGeneric textField) { - parent.entry.setCommand(textField.getText()); + parent.entry.setCommand(textField.getValue()); parent.parent.screen.saveCommands(); return false; } diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckListWidget.java b/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckListWidget.java index 5d6afb6..df1e387 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckListWidget.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckListWidget.java @@ -11,8 +11,8 @@ import io.github.darkkronicle.advancedchatcore.gui.WidgetConfigList; import java.util.Collection; import javax.annotation.Nullable; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.input.KeyInput; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.input.KeyEvent; public class CommandSpellcheckListWidget extends WidgetConfigList { @@ -33,7 +33,7 @@ protected CommandSpellcheckEntryWidget createListEntryWidget(int x, int y, int l } @Override - public boolean onKeyTyped(KeyInput input) { + public boolean onKeyTyped(KeyEvent input) { boolean value = super.onKeyTyped(input); save(); return value; diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckScreen.java b/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckScreen.java index c3732ca..84cee39 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckScreen.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/config/gui/CommandSpellcheckScreen.java @@ -17,8 +17,8 @@ import io.github.darkkronicle.advancedchatcore.gui.buttons.NamedSimpleButton; import java.util.ArrayList; import java.util.List; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.input.KeyInput; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.input.KeyEvent; public class CommandSpellcheckScreen extends CoreGuiListBase { @@ -61,7 +61,7 @@ protected void addButton(int x, int y, String translation, IButtonActionListener } @Override - public boolean onKeyTyped(KeyInput input) { + public boolean onKeyTyped(KeyEvent input) { if (input.key() == KeyCodes.KEY_ESCAPE) { closeGui(false); return true; diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/ColorCodeFormatter.java b/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/ColorCodeFormatter.java index 59c6124..7e7e486 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/ColorCodeFormatter.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/ColorCodeFormatter.java @@ -16,18 +16,18 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.network.ClientCommandSource; -import net.minecraft.command.CommandSource; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; +import net.minecraft.ChatFormatting; @Environment(EnvType.CLIENT) public class ColorCodeFormatter implements IMessageFormatter { @Override - public Optional format(Text text, @Nullable ParseResults parse) { + public Optional format(Component text, @Nullable ParseResults parse) { if (parse != null) { return Optional.empty(); } @@ -43,14 +43,14 @@ public Optional format(Text text, @Nullable ParseResults format(Text text, @Nullable ParseResults parse) { + public Optional format(Component text, @Nullable ParseResults parse) { if (parse == null) { if (text.getString().charAt(0) == '/') { - return Optional.of(Text.literal(text.getString()).fillStyle(Style.EMPTY.withColor(CommandColorerStorage.ERROR_COLOR.config.getIntegerValue()))); + return Optional.of(Component.literal(text.getString()).withStyle(Style.EMPTY.withColor(CommandColorerStorage.ERROR_COLOR.config.getIntegerValue()))); } return Optional.empty(); } - CommandContextBuilder commandContextBuilder = parse.getContext().getLastChild(); + CommandContextBuilder commandContextBuilder = parse.getContext().getLastChild(); HashMap replace = new HashMap<>(); int lowest = -1; int max = 0; @@ -90,9 +90,9 @@ public Optional format(Text text, @Nullable ParseResults { if (current.getStyle().equals(Style.EMPTY)) { - return Text.literal(match1.match).fillStyle(Style.EMPTY.withColor(color.color())); + return Component.literal(match1.match).withStyle(Style.EMPTY.withColor(color.color())); } - return Text.literal(match1.match).fillStyle(current.getStyle()); + return Component.literal(match1.match).withStyle(current.getStyle()); }); index += 1; } @@ -100,18 +100,18 @@ public Optional format(Text text, @Nullable ParseResults -1) { replace.put(new StringMatch(text.getString().substring(0, lowest), 0, lowest), (current, match) -> { if (current.getStyle().equals(Style.EMPTY)) { - return Text.literal(match.match).fillStyle(Style.EMPTY.withColor(CommandColorerStorage.COMMAND_COLOR.config.getIntegerValue())); + return Component.literal(match.match).withStyle(Style.EMPTY.withColor(CommandColorerStorage.COMMAND_COLOR.config.getIntegerValue())); } - return Text.literal(match.match).fillStyle(current.getStyle()); + return Component.literal(match.match).withStyle(current.getStyle()); }); } if (max != string.length()) { replace.put(new StringMatch(text.getString().substring(max, string.length()), max, string.length()), (current, match) -> { if (current.getStyle().equals(Style.EMPTY)) { - return Text.literal(match.match).fillStyle(Style.EMPTY.withColor(CommandColorerStorage.ERROR_COLOR.config.getIntegerValue())); + return Component.literal(match.match).withStyle(Style.EMPTY.withColor(CommandColorerStorage.ERROR_COLOR.config.getIntegerValue())); } - return Text.literal(match.match).fillStyle(current.getStyle()); + return Component.literal(match.match).withStyle(current.getStyle()); }); } @@ -119,39 +119,39 @@ public Optional format(Text text, @Nullable ParseResults> compileObjects(ParseResults parse, String input) { - CommandContextBuilder commandContextBuilder = parse.getContext(); + private List> compileObjects(ParseResults parse, String input) { + CommandContextBuilder commandContextBuilder = parse.getContext(); List> sections = new ArrayList<>(); - for (CommandContextBuilder child : getAllChildren(commandContextBuilder)) { + for (CommandContextBuilder child : getAllChildren(commandContextBuilder)) { sections.addAll(addSubs(child, input)); sections.addAll(addArgs(child, input)); } return sections; } - private List>> addSubs(CommandContextBuilder context, + private List>> addSubs(CommandContextBuilder context, String input) { - List>> nodes = new ArrayList<>(); - for (ParsedCommandNode node : context.getNodes()) { + List>> nodes = new ArrayList<>(); + for (ParsedCommandNode node : context.getNodes()) { nodes.add(new CommandSection<>(node, fromRange(node.getRange(), input), CommandSection.Section.COMMAND)); } return nodes; } - private List>> addArgs(CommandContextBuilder context, + private List>> addArgs(CommandContextBuilder context, String input) { - List>> nodes = new ArrayList<>(); + List>> nodes = new ArrayList<>(); if (context.getArguments() == null) { return nodes; } - for (ParsedArgument node : context.getArguments().values()) { + for (ParsedArgument node : context.getArguments().values()) { nodes.add(new CommandSection<>(node, fromRange(node.getRange(), input), CommandSection.Section.ARGUMENT)); } return nodes; } - private List> getAllChildren(CommandContextBuilder context) { - List> children = new ArrayList<>(); + private List> getAllChildren(CommandContextBuilder context) { + List> children = new ArrayList<>(); while (context != null) { children.add(context); context = context.getChild(); diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/JSONFormatter.java b/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/JSONFormatter.java index bb79fd8..62ea611 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/JSONFormatter.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/formatter/JSONFormatter.java @@ -20,11 +20,11 @@ import lombok.Value; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.network.ClientCommandSource; -import net.minecraft.command.CommandSource; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; @Environment(EnvType.CLIENT) public class JSONFormatter implements IMessageFormatter { @@ -62,7 +62,7 @@ public static class JSONToken { } @Override - public Optional format(Text text, @Nullable ParseResults parse) { + public Optional format(Component text, @Nullable ParseResults parse) { String content = text.getString(); Optional> omatches = SearchUtils.findMatches(content, "\\{.+\\}", FindType.REGEX); if (!omatches.isPresent()) { @@ -77,7 +77,7 @@ public Optional format(Text text, @Nullable ParseResults format(Text text, @Nullable ParseResults parse); + Optional format(Component text, @Nullable ParseResults parse); } diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/PlayerSuggestor.java b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/PlayerSuggestor.java index 23e220c..4e67730 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/PlayerSuggestor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/PlayerSuggestor.java @@ -21,8 +21,8 @@ import java.util.Optional; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.PlayerInfo; @Environment(EnvType.CLIENT) public class PlayerSuggestor implements IMessageSuggestor { @@ -41,16 +41,16 @@ public Optional> suggestCurrentWord(String text, String private Collection getPlayerNames() { List list = new ArrayList<>(); - for (PlayerListEntry playerListEntry : MinecraftClient.getInstance().player.networkHandler.getPlayerList()) { + for (PlayerInfo playerListEntry : Minecraft.getInstance().player.connection.getOnlinePlayers()) { //checking if player name is empty, to avoid fake players if (playerListEntry.getProfile().name().equals("")) continue; if (ChatBoxConfigStorage.General.PRUNE_PLAYER_SUGGESTIONS.config.getBooleanValue() - && playerListEntry.getDisplayName() != null) { + && playerListEntry.getTabListDisplayName() != null) { // Try to get their actual name (without prefix) StringMatch match = SearchUtils - .getMatch(playerListEntry.getDisplayName().getString(), + .getMatch(playerListEntry.getTabListDisplayName().getString(), ConfigStorage.General.MESSAGE_OWNER_REGEX.config.getStringValue(), FindType.REGEX) .orElse(null); if (match != null) { @@ -60,8 +60,8 @@ private Collection getPlayerNames() { } } else { // Check to make sure it isn't blank - if (!playerListEntry.getDisplayName().getString().equals("")) { - list.add(playerListEntry.getDisplayName().getString()); + if (!playerListEntry.getTabListDisplayName().getString().equals("")) { + list.add(playerListEntry.getTabListDisplayName().getString()); } } } else { diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/ShortcutSuggestor.java b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/ShortcutSuggestor.java index 4ef6cdd..a6ad12f 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/ShortcutSuggestor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/ShortcutSuggestor.java @@ -37,9 +37,9 @@ import lombok.Getter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; @Environment(EnvType.CLIENT) public class ShortcutSuggestor implements IMessageSuggestor, IJsonApplier, IScreenSupplier { @@ -137,7 +137,7 @@ private List getSuggestions(String current, StringRange rang if (current.length() == 0 || shortcut.name.toLowerCase().startsWith(current.toLowerCase())) { TextBuilder text = new TextBuilder(); text.append(shortcut.name); - suggestions.add(new AdvancedSuggestion(range, shortcut.replace, text.build(), Text.literal(shortcut.replace))); + suggestions.add(new AdvancedSuggestion(range, shortcut.replace, text.build(), Component.literal(shortcut.replace))); } } return suggestions; diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/SpellCheckSuggestor.java b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/SpellCheckSuggestor.java index a752a05..6f034af 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/SpellCheckSuggestor.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/SpellCheckSuggestor.java @@ -24,8 +24,8 @@ import java.util.Optional; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.Component; import org.languagetool.JLanguageTool; import org.languagetool.ResultCache; import org.languagetool.UserConfig; @@ -43,6 +43,12 @@ public static SpellCheckSuggestor getInstance() { } private SpellCheckSuggestor() { + // LanguageTool's en/grammar.xml trips the JDK's XML entity-size hardening + // (JAXP00010004) on Java 25, so loading its rules threw and took the whole mod + // down with it. The file ships inside the mod, so lifting the limit is safe. + if (System.getProperty("jdk.xml.totalEntitySizeLimit") == null) { + System.setProperty("jdk.xml.totalEntitySizeLimit", "0"); + } lt = new JLanguageTool(new AmericanEnglish(), new AmericanEnglish(), new ResultCache(15), new UserConfig(new ArrayList<>(), new HashMap<>(), 20)); lt.setMaxErrorsPerWordRate(0.33f); @@ -81,19 +87,19 @@ private static List convertSuggestions(RuleMatch match, Stri return replacements; } - private static Text getHover(String message) { + private static Component getHover(String message) { String text = ChatBoxConfigStorage.SpellChecker.HOVER_TEXT.config.getStringValue(); text = text.replaceAll("&", "ยง"); Optional match = SearchUtils.getMatch(message, "(.+)", FindType.REGEX); if (match.isEmpty()) { text = text.replaceAll("\\$1", message).replaceAll("\\$2", "").replaceAll("\\$3", ""); - return StyleFormatter.formatText(Text.literal(text)); + return StyleFormatter.formatText(Component.literal(text)); } StringMatch stringMatch = match.get(); String start = message.substring(0, stringMatch.start); String end = message.substring(stringMatch.end); String middle = message.substring(stringMatch.start + 12, stringMatch.end - 13); text = text.replaceAll("\\$1", start).replaceAll("\\$2", middle).replaceAll("\\$3", end); - return StyleFormatter.formatText(Text.literal(text)); + return StyleFormatter.formatText(Component.literal(text)); } } diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutEntryListWidget.java b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutEntryListWidget.java index de0e1c7..eabc9c8 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutEntryListWidget.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutEntryListWidget.java @@ -20,9 +20,9 @@ import java.util.List; 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; @Environment(EnvType.CLIENT) public class ShortcutEntryListWidget extends WidgetConfigListEntry { @@ -45,17 +45,17 @@ public ShortcutEntryListWidget(int x, int y, int width, int height, boolean isOd pos -= removeWidth; int replaceWidth = width - removeWidth - nameWidth + 1; GuiTextFieldGeneric replaceField = new GuiTextFieldGeneric(pos - replaceWidth, y, replaceWidth, 20, - MinecraftClient.getInstance().textRenderer); + Minecraft.getInstance().font); replaceField.setMaxLength(512); - replaceField.setText(entry.getReplace()); + replaceField.setValue(entry.getReplace()); replace = new TextFieldWrapper<>(replaceField, new SaveListener(this, false)); parent.addTextField(replace); pos -= replaceWidth + 1; GuiTextFieldGeneric nameField = - new GuiTextFieldGeneric(pos - nameWidth, y, nameWidth, 20, MinecraftClient.getInstance().textRenderer); + new GuiTextFieldGeneric(pos - nameWidth, y, nameWidth, 20, Minecraft.getInstance().font); nameField.setMaxLength(512); - nameField.setText(entry.getName()); + nameField.setValue(entry.getName()); name = new TextFieldWrapper<>(nameField, new SaveListener(this, true)); texts.add(name); texts.add(replace); @@ -79,9 +79,9 @@ public SaveListener(ShortcutEntryListWidget parent, boolean name) { @Override public boolean onTextChange(GuiTextFieldGeneric textField) { if (name) { - parent.entry.setName(textField.getText()); + parent.entry.setName(textField.getValue()); } else { - parent.entry.setReplace(textField.getText()); + parent.entry.setReplace(textField.getValue()); } return false; } diff --git a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutListWidget.java b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutListWidget.java index 7d7a494..0b81d6c 100644 --- a/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutListWidget.java +++ b/src/main/java/io/github/darkkronicle/advancedchatbox/suggester/gui/ShortcutListWidget.java @@ -12,7 +12,7 @@ import io.github.darkkronicle.advancedchatcore.gui.WidgetConfigList; import java.util.Collection; import javax.annotation.Nullable; -import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screens.Screen; public class ShortcutListWidget extends WidgetConfigList { public final ShortcutSuggestor suggestor; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 10a0463..d4266a1 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,11 +22,11 @@ ] }, "depends": { - "fabricloader": ">=0.15.11", - "fabric": "*", - "minecraft": "1.21.11", - "malilib": ">=0.27.8", - "advancedchatcore": ">=1.21.11-1.5.17-alpha.1" + "fabricloader": ">=0.19.3", + "fabric-api": "*", + "minecraft": ">=26.2", + "malilib": ">=0.29.0", + "advancedchatcore": ">=1.7.0" }, "custom": { "acmodule": true,