diff --git a/.gitignore b/.gitignore
index 0a7d1b3..35051e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -97,4 +97,5 @@ env/
.idea/modules.xml
bin/
src/test/
-logs/
\ No newline at end of file
+logs/
+run
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 4dc94db..0b3aab7 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,7 +1,16 @@
-
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..ce76332
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 4863b06..672f0df 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -31,5 +31,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index c862467..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 894885e..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/TranslateMod.main.iml b/.idea/modules/TranslateMod.main.iml
new file mode 100644
index 0000000..1c961d6
--- /dev/null
+++ b/.idea/modules/TranslateMod.main.iml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+ FORGE
+ MIXIN
+ MCP
+
+ 1
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/TranslateMod.test.iml b/.idea/modules/TranslateMod.test.iml
new file mode 100644
index 0000000..c844c6a
--- /dev/null
+++ b/.idea/modules/TranslateMod.test.iml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+ FORGE
+ MIXIN
+ MCP
+
+ 1
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/TranslationMod.main.iml b/.idea/modules/TranslationMod.main.iml
deleted file mode 100644
index cfe7f5e..0000000
--- a/.idea/modules/TranslationMod.main.iml
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-
-
-
-
- FORGE
- MIXIN
- MCP
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/TranslationMod.test.iml b/.idea/modules/TranslationMod.test.iml
deleted file mode 100644
index a9b304a..0000000
--- a/.idea/modules/TranslationMod.test.iml
+++ /dev/null
@@ -1,107 +0,0 @@
-
-
-
-
-
-
- FORGE
- MIXIN
- MCP
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/TranslationMod.iml b/TranslationMod.iml
deleted file mode 100644
index b8c29b9..0000000
--- a/TranslationMod.iml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 1dc2b78..ec72f0d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,135 +1,125 @@
buildscript {
repositories {
- jcenter()
+ maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
- maven {
- url = "http://files.minecraftforge.net/maven"
- }
}
dependencies {
- classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
+ classpath 'org.spongepowered:mixingradle:0.7.+'
}
}
-apply plugin: "net.minecraftforge.gradle"
-apply plugin: 'idea'
+plugins {
+ id 'eclipse'
+ id 'idea'
+ id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
+ id 'org.parchmentmc.librarian.forgegradle' version '1.+'
+}
-sourceSets {
- main {
- java {srcDirs = ["$projectDir/src/main/java"]}
- resources {srcDirs = ["$projectDir/src/main/resources"]}
- }
+apply plugin: 'org.spongepowered.mixin'
+
+group = mod_group_id
+version = mod_version
+
+base {
+ archivesName = mod_id
}
-version = project.mod_version
-/*
- * Copyright (C) 2021 Ringosham
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-// http://maven.apache.org/guides/mini/guide-naming-conventions.html
-group = project.group_name
-archivesBaseName = "[" + project.minecraft_version + "]RealTimeTranslation"
-
-sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
+java {
+ toolchain.languageVersion = JavaLanguageVersion.of(17)
+}
+jarJar.enable()
minecraft {
- mappings channel: project.mappings_channel, version: project.mappings_version
+ mappings channel: mapping_channel, version: mapping_version
+ copyIdeResources = true
runs {
- client {
- workingDirectory project.file('env')
-
- // Recommended logging data for a userdev environment
- property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
+ configureEach {
+ workingDirectory project.file('run')
+ property 'forge.logging.markers', 'REGISTRIES'
- // Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
- examplemod {
+ "${mod_id}" {
source sourceSets.main
}
}
}
- server {
- workingDirectory project.file('env')
-
- // Recommended logging data for a userdev environment
- property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
+ client {
+ property 'forge.enabledGameTestNamespaces', mod_id
+ }
- // Recommended logging level for the console
- property 'forge.logging.console.level', 'debug'
+ server {
+ property 'forge.enabledGameTestNamespaces', mod_id
+ args '--nogui'
+ }
- mods {
- examplemod {
- source sourceSets.main
- }
- }
+ gameTestServer {
+ property 'forge.enabledGameTestNamespaces', mod_id
}
data {
- workingDirectory project.file('env')
+ workingDirectory project.file('run-data')
- // Recommended logging data for a userdev environment
- property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
-
- // Recommended logging level for the console
- property 'forge.logging.console.level', 'debug'
+ args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
+ }
+ }
+}
- args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/')
+sourceSets.main.resources { srcDir 'src/generated/resources' }
- mods {
- examplemod {
- source sourceSets.main
- }
- }
- }
+repositories {
+ flatDir {
+ dir 'libs'
+ }
+ maven { // TOP
+ url "https://cursemaven.com"
+ }
+ maven { //mirror
+ name = "ModMaven"
+ url = "https://modmaven.dev"
}
}
-configurations {
- embed
- compile.extendsFrom(embed)
+mixin {
+ add sourceSets.main, mod_id+".refmap.json"
+ config "${mod_id}.mixins.json"
+ debug.export = true
}
dependencies {
- // you may put jars on which you depend on in ./libs
- // or you may define them like so..
- //compile "some.group:artifact:version:classifier"
- //compile "some.group:artifact:version"
- // real examples
- //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
- //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
- // for more info...
- // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
- // http://www.gradle.org/docs/current/userguide/dependency_management.html
- minecraft 'net.minecraftforge:forge:' + project.forge_version
+ minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
+ annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
-jar {
+tasks.named('processResources', ProcessResources).configure {
+ var replaceProperties = [minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range,
+ forge_version : forge_version, forge_version_range: forge_version_range,
+ loader_version_range: loader_version_range,
+ mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
+ mod_authors : mod_authors, mod_description: mod_description,]
+
+ inputs.properties replaceProperties
+
+ filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
+ expand replaceProperties + [project: project]
+ }
+}
+// Example for how to get properties into the manifest for reading at runtime.
+tasks.named('jar', Jar).configure {
manifest {
- attributes([
- "Specification-Title" : project.mod_name,
- "Specification-Vendor" : project.mod_vendor,
- "Specification-Version" : project.mod_version, // We are version 1 of ourselves
- "Implementation-Title" : project.mod_name,
- "Implementation-Version" : project.mod_version,
- "Implementation-Vendor" : project.mod_vendor,
- "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
- ])
+ attributes(["Specification-Title" : mod_id,
+ "Specification-Vendor" : mod_authors,
+ "Specification-Version" : "1", // We are version 1 of ourselves
+ "Implementation-Title" : project.name,
+ "Implementation-Version" : project.jar.archiveVersion,
+ "Implementation-Vendor" : mod_authors,
+ "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")])
}
-}
\ No newline at end of file
+ finalizedBy 'reobfJar'
+}
+tasks.withType(JavaCompile).configureEach {
+ options.encoding = 'UTF-8'
+}
diff --git a/gradle.properties b/gradle.properties
index e383077..81118db 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,19 +15,25 @@
# along with this program. If not, see .
#
-minecraft_version=1.16.5
-forge_version=1.16.5-36.0.42
-mappings_channel=snapshot
-mappings_version=20210309-1.16.5
-mod_version=6.0
+minecraft_version=1.18.2
+forge_version=40.2.21
+mapping_channel=parchment
+minecraft_version_range=[1.18.2,1.19)
+mapping_version=2022.08.07-1.18.2
+forge_version_range=[40,)
+loader_version_range=[40,)
+mod_version=7.2
# suppress inspection "UnusedProperty"
mod_id=translationmod
mod_name=Real time translation mod
-mod_vendor=Ringosham
+mod_authors=Ringosham
group_name=com.ringosham.translationmod
# Gradle import fix
# suppress inspection "UnusedProperty"
+mod_license=Licensed under GPL version 3
org.gradle.daemon=false
# suppress inspection "UnusedProperty"
# Gradle needs more memory
-org.gradle.jvmargs=-Xmx3G
\ No newline at end of file
+org.gradle.jvmargs=-Xmx3G
+mod_group_id=com.ringosham
+mod_description=This mod translate your Minecraft chat in real time! Translation results are powered by Google.
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..d2ac2cd
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1,16 @@
+pluginManagement {
+ repositories {
+ gradlePluginPortal()
+ maven {
+ name = 'MinecraftForge'
+ url = 'https://maven.minecraftforge.net/'
+ }
+ maven { url = 'https://maven.parchmentmc.org' }
+ }
+}
+
+plugins {
+ id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
+}
+
+rootProject.name = 'TranslateMod'
diff --git a/src/main/java/com/ringosham/translationmod/client/BaiduClient.java b/src/main/java/com/ringosham/translationmod/client/BaiduClient.java
index 97aae3f..85b9446 100644
--- a/src/main/java/com/ringosham/translationmod/client/BaiduClient.java
+++ b/src/main/java/com/ringosham/translationmod/client/BaiduClient.java
@@ -50,11 +50,8 @@ public RequestResult translate(String message, Language from, Language to) {
Map queryParam = new HashMap<>();
String encodedMessage = null;
//Percent encode message
- try {
- encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8.name());
- } catch (UnsupportedEncodingException ignored) {
- }
- //Query message
+ encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8);
+ //Query message
queryParam.put("q", encodedMessage);
//Language codes from Baidu does not follow International standards at all
//From language
diff --git a/src/main/java/com/ringosham/translationmod/client/GoogleClient.java b/src/main/java/com/ringosham/translationmod/client/GoogleClient.java
index c1d08f2..f4e0a85 100644
--- a/src/main/java/com/ringosham/translationmod/client/GoogleClient.java
+++ b/src/main/java/com/ringosham/translationmod/client/GoogleClient.java
@@ -32,7 +32,7 @@
import java.util.Map;
public class GoogleClient extends RESTClient {
- //Google translate is a paid service. This is the secret free API for use of the web Google translate
+ //Google translationmod.mixins.json is a paid service. This is the secret free API for use of the web Google translationmod.mixins.json
private static boolean accessDenied = false;
public GoogleClient() {
@@ -48,11 +48,8 @@ public RequestResult translate(String message, Language from, Language to) {
Map queryParam = new HashMap<>();
String encodedMessage = null;
//Percent encode message
- try {
- encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8.name());
- } catch (UnsupportedEncodingException ignored) {
- }
- //Necessary query parameters to trick Google translate
+ encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8);
+ //Necessary query parameters to trick Google translationmod.mixins.json
queryParam.put("client", "gtx");
queryParam.put("sl", from.getGoogleCode());
queryParam.put("tl", to.getGoogleCode());
@@ -74,7 +71,7 @@ public RequestResult translate(String message, Language from, Language to) {
}
}
String responseString = response.getEntity();
- //This secret API is specifically made for Google translate. So the response contains lots of useless information.
+ //This secret API is specifically made for Google translationmod.mixins.json. So the response contains lots of useless information.
//Each sentence translated is divided into separate JSON arrays.
Gson gson = new GsonBuilder().setLenient().create();
JsonArray json = gson.fromJson(responseString, JsonArray.class);
diff --git a/src/main/java/com/ringosham/translationmod/client/GooglePaidClient.java b/src/main/java/com/ringosham/translationmod/client/GooglePaidClient.java
index b036c1a..d10ac15 100644
--- a/src/main/java/com/ringosham/translationmod/client/GooglePaidClient.java
+++ b/src/main/java/com/ringosham/translationmod/client/GooglePaidClient.java
@@ -56,11 +56,8 @@ public RequestResult translate(String message, Language from, Language to) {
Map queryParam = new HashMap<>();
String encodedMessage = null;
//Percent encode message
- try {
- encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8.name());
- } catch (UnsupportedEncodingException ignored) {
- }
- //The query supports multiline using an array, however we only have one line to text to translate.
+ encodedMessage = URLEncoder.encode(message, StandardCharsets.UTF_8);
+ //The query supports multiline using an array, however we only have one line to text to translationmod.mixins.json.
queryParam.put("q", encodedMessage);
//Query parameters
queryParam.put("target", to.getGoogleCode());
diff --git a/src/main/java/com/ringosham/translationmod/client/LangManager.java b/src/main/java/com/ringosham/translationmod/client/LangManager.java
index 365842b..8f5be7f 100644
--- a/src/main/java/com/ringosham/translationmod/client/LangManager.java
+++ b/src/main/java/com/ringosham/translationmod/client/LangManager.java
@@ -20,7 +20,7 @@
import com.google.gson.Gson;
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.client.types.Language;
-import net.minecraft.util.ResourceLocation;
+import net.minecraft.resources.ResourceLocation;
import java.io.BufferedReader;
import java.io.InputStream;
@@ -33,7 +33,7 @@
public class LangManager {
//Loads the language list from local json
- //Technically the cloud translate API provides an endpoint to tell what languages are available, but even that requires an API key and payment info.
+ //Technically the cloud translationmod.mixins.json API provides an endpoint to tell what languages are available, but even that requires an API key and payment info.
private static final ResourceLocation langLocation = new ResourceLocation(TranslationMod.MODID, "lang.json");
private static LangManager instance;
private static Language autoLang;
diff --git a/src/main/java/com/ringosham/translationmod/common/ChatUtil.java b/src/main/java/com/ringosham/translationmod/common/ChatUtil.java
index d1b3e11..9d3de88 100644
--- a/src/main/java/com/ringosham/translationmod/common/ChatUtil.java
+++ b/src/main/java/com/ringosham/translationmod/common/ChatUtil.java
@@ -18,47 +18,46 @@
package com.ringosham.translationmod.common;
import com.ringosham.translationmod.TranslationMod;
+import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
-import net.minecraft.util.text.Color;
-import net.minecraft.util.text.StringTextComponent;
-import net.minecraft.util.text.Style;
-import net.minecraft.util.text.TextFormatting;
-import net.minecraft.util.text.event.HoverEvent;
+import net.minecraft.network.chat.HoverEvent;
+import net.minecraft.network.chat.Style;
+import net.minecraft.network.chat.TextComponent;
import net.minecraftforge.fml.ModList;
import java.util.ArrayList;
import java.util.List;
public class ChatUtil {
- private static final String prefix = TextFormatting.GREEN + "[" + TextFormatting.WHITE + "RTTM" + TextFormatting.GREEN + "] " + TextFormatting.RESET;
+ private static final String prefix = ChatFormatting.GREEN + "[" + ChatFormatting.WHITE + "RTTM" + ChatFormatting.GREEN + "] " + ChatFormatting.RESET;
- public static void printChatMessage(boolean addPrefix, String message, TextFormatting color) {
- //Color.func_240774_a_(TextFormatting) -> Color.fromTextFormatting(...)
- Style style = Style.EMPTY.setColor(Color.fromTextFormatting(color));
- Minecraft.getInstance().ingameGUI.getChatGUI().printChatMessage((new StringTextComponent((addPrefix ? prefix : "") + color + message).mergeStyle(style)));
+ public static void printChatMessage(boolean addPrefix, String message, ChatFormatting color) {
+ //Color.func_240774_a_(ChatFormatting) -> Color.fromChatFormatting(...)
+ Style style = Style.EMPTY.withColor(color);
+ Minecraft.getInstance().gui.getChat().addMessage((new TextComponent((addPrefix ? prefix : "") + color + message).withStyle(style)));
}
- public static void printChatMessageAdvanced(String message, String hoverText, boolean bold, boolean italic, boolean underline, TextFormatting color) {
+ public static void printChatMessageAdvanced(String message, String hoverText, boolean bold, boolean italic, boolean underline, ChatFormatting color) {
//Styles are immutable in 1.16. So we have that...
- List formattings = new ArrayList<>();
- formattings.add(color);
+ Style style = Style.EMPTY.withColor(color);
if (bold)
- formattings.add(TextFormatting.BOLD);
+ style = style.withBold(true);
if (italic)
- formattings.add(TextFormatting.ITALIC);
+ style = style.withItalic(true);
if (underline)
- formattings.add(TextFormatting.UNDERLINE);
- Style style = Style.EMPTY.mergeWithFormatting(formattings.toArray(new TextFormatting[0]));
+ style = style.withUnderlined(true);
+
if (hoverText != null)
- style = style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent(hoverText)));
- Minecraft.getInstance().ingameGUI.getChatGUI().printChatMessage(new StringTextComponent(message).mergeStyle(style));
+ style = style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent(hoverText)));
+ Minecraft.getInstance().gui.getChat().addMessage(new TextComponent(message).withStyle(style));
}
@SuppressWarnings("OptionalGetWithoutIsPresent")
public static void printCredits() {
String version = ModList.get().getModContainerById(TranslationMod.MODID).get().getModInfo().getVersion().toString();
- ChatUtil.printChatMessage(false, "Real-time translation mod by Ringosham. Version " + version, TextFormatting.AQUA);
- ChatUtil.printChatMessage(false, "Online translation services powered by Google", TextFormatting.AQUA);
- ChatUtil.printChatMessage(false, "Translation results may not be 100% accurate", TextFormatting.AQUA);
+ ChatUtil.printChatMessage(false, "Real-time translation mod by Ringosham. Version " + version, ChatFormatting.AQUA);
+ ChatUtil.printChatMessage(false, "Transplanted to 1.18.2. --By LostInLinearPast(一只戏鸢)", ChatFormatting.AQUA);
+ ChatUtil.printChatMessage(false, "Online translation services powered by Google", ChatFormatting.AQUA);
+ ChatUtil.printChatMessage(false, "Translation results may not be 100% accurate", ChatFormatting.AQUA);
}
}
diff --git a/src/main/java/com/ringosham/translationmod/common/ConfigManager.java b/src/main/java/com/ringosham/translationmod/common/ConfigManager.java
index fd8116a..b6d6088 100644
--- a/src/main/java/com/ringosham/translationmod/common/ConfigManager.java
+++ b/src/main/java/com/ringosham/translationmod/common/ConfigManager.java
@@ -21,7 +21,7 @@
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.client.LangManager;
import com.ringosham.translationmod.client.types.Language;
-import net.minecraft.util.text.TextFormatting;
+import net.minecraft.ChatFormatting;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
@@ -40,45 +40,10 @@ public class ConfigManager {
public static final ClientConfig config;
public static final ForgeConfigSpec configSpec;
public static final String[] defaultRegex = {
- "<(\\w+)> ", //Default
- "\\(From (\\w+)\\):( )?", //PM
- "(\\w+) whispers ", //PM
- "(\\[\\S+\\]( )?){0,2}(\\w+)( )?\u00BB( )?", //The Hive, etc.
- "(\\[\\S+\\]( )?){0,2}(\\w+)( )?:( )?(Eye\\[\\d\\] )?", //Shotbow, MineZ, etc.
- //Screw you Mineplex for the most complicated chat system
- "\\d{1,3} (\\w+ )?(\\w+) ", //Mineplex survival games
- "Dead (\\d+ )?(\\w+ )?(\\w+) ", //Other Mineplex games
- "(\\w+) > \\w+ ", //Mineplex PM
- "(\\w+) whispers to you: ", //Default PM
- "(\\(Team\\) )?(\\[\\w+\\] ){1,2}(\\w+): ", //Annihilation
- "(\\w+ )?\\w+: (\\w+) > ", //Pika network. Thanks for the shout out!
- "\\[Lvl \\d+\\] \u25b6 (\\w+: )?(\\w+) > ",
- "\u25b6 \\[\\d+\\] (\\w+: )?(\\w+) > ",
- "\u25b6 (\\w+: )?(\\w+) > ",
- "(\\[\\w+\\])?\\[Level \\d+\\] \\[(\\w+)\\] ", //Frostcraft
- "(\\w+) tells you: ", //Frostcraft PM
- "\\[(\\w+) -> \\w+\\] ", //Default Bukkit PM? Essential?
- "(\\w+ )?(\\w+-)?(\\w+)(\\*)?(\\+){0,2}:", //Mineyourmind(Specifically the forum members). Thanks for the shout out!
+ "<(\\w+)> (?!\\[By Translator\\] )"//Default
};
public static final int[] defaultGroups = {
- 1,
- 1,
- 1,
- 3,
- 3,
- 2,
- 3,
- 1,
- 1,
- 3,
- 2,
- 2,
- 2,
- 2,
- 2,
- 1,
- 1,
- 3
+ 1
};
private static final String[] engines = {"google", "baidu"};
//In case there are future updates that drastically change how the mod works. This variable would be here to check if the configs are out of date.
@@ -123,7 +88,7 @@ public static void validateConfig() {
}
//Validates the color.
- ArrayList colors = new ArrayList<>(TextFormatting.getValidValues(true, false));
+ ArrayList colors = new ArrayList<>(ChatFormatting.getNames(true, false));
if (!colors.contains(config.color.get())) {
config.color.set("gray");
valid = false;
@@ -146,6 +111,7 @@ private static void versionCheck() {
config.italic.set(false);
config.underline.set(false);
config.translateSign.set(true);
+ config.modAble.set(true);
config.color.set("gray");
config.regexList.set(Arrays.asList(defaultRegex));
config.groupList.set(Ints.asList(defaultGroups));
@@ -171,6 +137,7 @@ public static void saveConfig() {
config.baiduKey.save();
config.baiduAppId.save();
config.translationEngine.save();
+ config.modAble.save();
validateConfig();
}
@@ -190,20 +157,22 @@ public static class ClientConfig {
public final ConfigValue baiduAppId;
public final ConfigValue baiduKey;
public final ConfigValue translationEngine;
+ public final BooleanValue modAble;
final IntValue configMinVersion;
ClientConfig(ForgeConfigSpec.Builder builder) {
builder.comment("Real time translation mod configs").push(TranslationMod.MODID);
+ modAble = builder.comment("switch").define("modAble", true);
configMinVersion = builder.comment("Config version. DO NOT CHANGE.").defineInRange("configMinVersion", 1, 0, Integer.MAX_VALUE);
- targetLanguage = builder.comment("Target language to translate for the chat").define("targetLanguage", "English", lang -> validateLang((String) lang));
+ targetLanguage = builder.comment("Target language to translationmod.mixins.json for the chat").define("targetLanguage", "English", lang -> validateLang((String) lang));
selfLanguage = builder.comment("The language the user types").define("selfLanguage", "English", lang -> validateLang((String) lang));
- speakAsLanguage = builder.comment("The language the user wants their message to translate to").define("speakAsLanguage", "Japanese", lang -> validateLang((String) lang));
+ speakAsLanguage = builder.comment("The language the user wants their message to translationmod.mixins.json to").define("speakAsLanguage", "Japanese", lang -> validateLang((String) lang));
bold = builder.comment("Bold the translated message").define("bold", false);
italic = builder.comment("Italic the translated message").define("italic", false);
underline = builder.comment("Underline the translated message").define("underline", false);
color = builder.comment("Changes the color of the translated message").define("color", "gray", color -> {
- List colors = new ArrayList<>(TextFormatting.getValidValues(true, false));
+ List colors = new ArrayList<>(ChatFormatting.getNames(true, false));
String c = (String) color;
return colors.contains(c);
});
diff --git a/src/main/java/com/ringosham/translationmod/events/Handler.java b/src/main/java/com/ringosham/translationmod/events/Handler.java
index 6e2ed39..1e89672 100644
--- a/src/main/java/com/ringosham/translationmod/events/Handler.java
+++ b/src/main/java/com/ringosham/translationmod/events/Handler.java
@@ -4,60 +4,47 @@
import com.ringosham.translationmod.common.ChatUtil;
import com.ringosham.translationmod.common.ConfigManager;
import com.ringosham.translationmod.common.Log;
+import com.ringosham.translationmod.gui.CommonGui;
import com.ringosham.translationmod.gui.TranslateGui;
import com.ringosham.translationmod.translate.SignTranslate;
import com.ringosham.translationmod.translate.Translator;
import com.ringosham.translationmod.translate.types.SignText;
-import net.minecraft.block.Block;
-import net.minecraft.block.Blocks;
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.settings.KeyBinding;
-import net.minecraft.tileentity.SignTileEntity;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.RayTraceResult;
-import net.minecraft.util.math.vector.Vector3d;
-import net.minecraft.util.text.ITextComponent;
-import net.minecraft.util.text.TextFormatting;
-import net.minecraft.world.World;
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.chat.Component;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.SignBlock;
+import net.minecraft.world.level.block.entity.SignBlockEntity;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
-import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.InputEvent;
+import net.minecraftforge.client.event.ScreenOpenEvent;
import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.event.entity.player.PlayerInteractEvent;
+import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
-import net.minecraftforge.fml.config.ModConfig.Reloading;
+import net.minecraftforge.fml.event.config.ModConfigEvent;
import java.util.Objects;
public class Handler {
- private static Thread readSign;
- private SignText lastSign;
- private boolean hintShown = false;
- private int ticks = 0;
- private static final Block[] signBlocks = {
- Blocks.ACACIA_SIGN,
- Blocks.ACACIA_WALL_SIGN,
- Blocks.BIRCH_SIGN,
- Blocks.BIRCH_WALL_SIGN,
- Blocks.DARK_OAK_SIGN,
- Blocks.DARK_OAK_WALL_SIGN,
- Blocks.JUNGLE_SIGN,
- Blocks.JUNGLE_WALL_SIGN,
- Blocks.OAK_SIGN,
- Blocks.OAK_WALL_SIGN,
- Blocks.SPRUCE_SIGN,
- Blocks.SPRUCE_WALL_SIGN
- };
+ private boolean hintShown = false;
- @SubscribeEvent
- public void onGuiOpen(GuiOpenEvent event) {
- if (event.getGui() == null) {
- Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
+ @SubscribeEvent
+ public void onGuiOpen(ScreenOpenEvent event) {
+ if (event.getScreen() == null) {
+ Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(false);
}
}
@SubscribeEvent
public void chatReceived(ClientChatReceivedEvent event) {
- ITextComponent eventMessage = event.getMessage();
+ if(!ConfigManager.config.modAble.get()) return;
+ Component eventMessage = event.getMessage();
String message = eventMessage.getString().replaceAll("§(.)", "");
Thread translate = new Translator(message, null, LangManager.getInstance().findLanguageFromName(ConfigManager.config.targetLanguage.get()));
translate.start();
@@ -69,89 +56,64 @@ public void onPlayerTick(TickEvent.PlayerTickEvent event) {
return;
if (!hintShown) {
hintShown = true;
- ChatUtil.printChatMessage(true, "Press [" + TextFormatting.AQUA + KeyBinding.getDisplayString(KeyBind.translateKey.getKeyDescription()).get().getUnformattedComponentText() + TextFormatting.WHITE + "] for translation settings", TextFormatting.WHITE);
- if (ConfigManager.config.regexList.get().size() == 0) {
+ ChatUtil.printChatMessage(true, "Press [" + ChatFormatting.AQUA + KeyMapping.createNameSupplier(KeyBind.translateKey.getName()).get().getString() + ChatFormatting.WHITE + "] for translation settings", ChatFormatting.WHITE);
+ if (ConfigManager.config.regexList.get().isEmpty()) {
Log.logger.warn("No chat regex in the configurations");
- ChatUtil.printChatMessage(true, "The mod needs chat regex to function. Check the mod options to add one", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "The mod needs chat regex to function. Check the mod options to add one", ChatFormatting.RED);
}
}
}
- @SubscribeEvent
- public void onWorldTick(TickEvent.WorldTickEvent event) {
- if (event.world == null)
- return;
- //Scan for signs
- if (ConfigManager.config.translateSign.get() && event.phase == TickEvent.Phase.END) {
- processSign(event.world);
- }
- }
-
//If config is somehow changed through other means
@SubscribeEvent
- public void onConfigChanged(Reloading event) {
+ public void onConfigChanged(ModConfigEvent.Reloading event) {
ConfigManager.saveConfig();
}
+
@SubscribeEvent
public void onKeybind(InputEvent.KeyInputEvent event) {
- if (KeyBind.translateKey.isPressed())
- Minecraft.getInstance().displayGuiScreen(new TranslateGui());
+ if (KeyBind.translateKey.isDown() && !(Minecraft.getInstance().screen instanceof CommonGui)){
+ Minecraft.getInstance().setScreen(new TranslateGui());
+ event.setResult(Event.Result.ALLOW);
+ }
}
- private void processSign(World world) {
- RayTraceResult mouseOver = Minecraft.getInstance().objectMouseOver;
- if (mouseOver == null)
- return;
- else if (mouseOver.getType() != RayTraceResult.Type.BLOCK) {
- lastSign = null;
- ticks = 0;
- return;
- }
- Vector3d vec = mouseOver.getHitVec();
- BlockPos blockPos = new BlockPos(vec);
- //Ignore air tiles
- if (world.getBlockState(blockPos).getBlock() == Blocks.AIR)
- return;
- //Wall signs and standing signs
- boolean isSign = false;
- for (Block signBlock : signBlocks) {
- if (world.getBlockState(blockPos).getBlock() == signBlock) {
- //Ensure the player is staring at the same sign
- if (lastSign != null && lastSign.getText() != null) {
- if (lastSign.sameSign(blockPos)) {
- ticks++;
- //Count number of ticks the player is staring
- //Assuming 20 TPS
- if (ticks >= 20)
- if (readSign != null && readSign.getState() == Thread.State.NEW)
- readSign.start();
- } else
- readSign = getSignThread(world, blockPos);
- } else
- readSign = getSignThread(world, blockPos);
- isSign = true;
+
+ @SubscribeEvent
+ public void processSign(PlayerInteractEvent.RightClickBlock event) {
+ if(ConfigManager.config.translateSign.get() && ConfigManager.config.modAble.get()
+ && event.getHand() == InteractionHand.MAIN_HAND
+ && event.getSide().isClient())
+ {
+ BlockHitResult hitVec = event.getHitVec();
+ if(hitVec != null){
+ Level level = event.getPlayer().level;
+ BlockPos blockPos = hitVec.getBlockPos();
+ BlockState blockState = level.getBlockState(blockPos);
+ if(blockState.getBlock() instanceof SignBlock){
+ SignTranslate signThread = getSignThread(level, blockPos);
+ if(signThread != null){
+ signThread.start();
+ }
+ }
}
}
- if (!isSign) {
- lastSign = null;
- ticks = 0;
- }
}
- private SignTranslate getSignThread(World world, BlockPos pos) {
+ private SignTranslate getSignThread(Level world, BlockPos pos) {
StringBuilder text = new StringBuilder();
//Four lines of text in signs
for (int i = 0; i < 4; i++) {
- ITextComponent line = ((SignTileEntity) Objects.requireNonNull(world.getTileEntity(pos))).getText(i);
+ Component line = ((SignBlockEntity) Objects.requireNonNull(world.getBlockEntity(pos))).getMessage(i,false);
//Combine each line of the sign with spaces.
//Due to differences between languages, this may break asian languages. (Words don't separate with spaces)
- text.append(" ").append(line.getUnformattedComponentText().replaceAll("§(.)", ""));
+ text.append(" ").append(line.getString().replaceAll("§(.)", ""));
}
text = new StringBuilder(text.toString().replaceAll("§(.)", ""));
- if (text.length() == 0)
+ if (text.isEmpty())
return null;
- lastSign = new SignText();
+ SignText lastSign = new SignText();
lastSign.setSign(text.toString(), pos);
return new SignTranslate(text.toString(), pos);
}
diff --git a/src/main/java/com/ringosham/translationmod/events/KeyBind.java b/src/main/java/com/ringosham/translationmod/events/KeyBind.java
index e8ab916..a2f7049 100644
--- a/src/main/java/com/ringosham/translationmod/events/KeyBind.java
+++ b/src/main/java/com/ringosham/translationmod/events/KeyBind.java
@@ -1,14 +1,14 @@
package com.ringosham.translationmod.events;
-import net.minecraft.client.settings.KeyBinding;
-import net.minecraftforge.fml.client.registry.ClientRegistry;
+import net.minecraft.client.KeyMapping;
+import net.minecraftforge.client.ClientRegistry;
import org.lwjgl.glfw.GLFW;
public class KeyBind {
- static KeyBinding translateKey;
+ static KeyMapping translateKey;
public static void keyInit() {
- translateKey = new KeyBinding("Translator menu", GLFW.GLFW_KEY_Y, "key.categories.multiplayer");
+ translateKey = new KeyMapping("key.translation.settings", GLFW.GLFW_KEY_Y, "Translate mod");
ClientRegistry.registerKeyBinding(translateKey);
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/CommonGui.java b/src/main/java/com/ringosham/translationmod/gui/CommonGui.java
index d485312..6bb18d4 100644
--- a/src/main/java/com/ringosham/translationmod/gui/CommonGui.java
+++ b/src/main/java/com/ringosham/translationmod/gui/CommonGui.java
@@ -1,9 +1,11 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.util.ResourceLocation;
-import net.minecraft.util.text.StringTextComponent;
+
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.blaze3d.vertex.PoseStack;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.network.chat.TextComponent;
+import net.minecraft.resources.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class CommonGui extends Screen {
@@ -15,7 +17,7 @@ public class CommonGui extends Screen {
private final int guiWidth;
CommonGui(String title, int guiHeight, int guiWidth) {
- super(new StringTextComponent(title));
+ super(new TextComponent(title));
if (guiWidth < 10 || guiHeight < 10)
throw new IllegalArgumentException("GUI width too short!");
this.guiHeight = guiHeight;
@@ -24,11 +26,11 @@ public class CommonGui extends Screen {
@SuppressWarnings("NullableProblems")
@Override
- public void render(MatrixStack stack, int x, int y, float tick) {
+ public void render(PoseStack stack, int x, int y, float tick) {
//Draws the base background
- GL11.glColor4f(1, 1, 1, 1);
+ RenderSystem.setShaderColor(1, 1, 1, 1);
renderBackground(stack);
- getMinecraft().getTextureManager().bindTexture(texture);
+ getMinecraft().getTextureManager().bindForSetup(texture);
//Top left corner
blit(stack, getXOrigin(), getYOrigin(), 0, 0, 4, 4);
//Bottom left corner
@@ -83,19 +85,19 @@ public int getTopMargin() {
}
public int getTextWidth(String text) {
- return font.getStringWidth(text);
+ return font.width(text);
}
/**
* Draws strings from the top-left of the gui
*/
- public void drawStringLine(MatrixStack stack, String title, String[] lines, int offset) {
- font.drawString(stack, title, getLeftMargin(), getTopMargin(), 0x555555);
+ public void drawStringLine(PoseStack stack, String title, String[] lines, int offset) {
+ font.draw(stack, title, getLeftMargin(), getTopMargin(), 0x555555);
int lineCount = 1;
if (lines == null)
return;
for (String text : lines) {
- font.drawString(stack, text, getLeftMargin(), getTopMargin() + offset + 10 * lineCount, 0x555555);
+ font.draw(stack, text, getLeftMargin(), getTopMargin() + offset + 10 * lineCount, 0x555555);
lineCount++;
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/ConfigGui.java b/src/main/java/com/ringosham/translationmod/gui/ConfigGui.java
index 3873602..115d033 100644
--- a/src/main/java/com/ringosham/translationmod/gui/ConfigGui.java
+++ b/src/main/java/com/ringosham/translationmod/gui/ConfigGui.java
@@ -17,17 +17,17 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.vertex.PoseStack;
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.client.LangManager;
import com.ringosham.translationmod.client.types.Language;
import com.ringosham.translationmod.common.ChatUtil;
import com.ringosham.translationmod.common.ConfigManager;
-import net.minecraft.client.gui.widget.button.Button;
-import net.minecraft.util.text.ITextComponent;
-import net.minecraft.util.text.StringTextComponent;
-import net.minecraft.util.text.Style;
-import net.minecraft.util.text.TextFormatting;
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.Style;
+import net.minecraft.network.chat.TextComponent;
import net.minecraftforge.fml.ModList;
import java.util.ArrayList;
@@ -36,33 +36,33 @@
public class ConfigGui extends CommonGui {
private static final int guiWidth = 250;
private static final int guiHeight = 206;
- private static final StringTextComponent targetTooltip = new StringTextComponent("The language your chat will be translated to");
- private static final List selfTooltip = new ArrayList<>();
- private static final List speakAsTooltip = new ArrayList<>();
- private static final List regexTooltip = new ArrayList<>();
- private static final List apiKeyTooltip = new ArrayList<>();
- private static final List colorTooltip = new ArrayList<>();
- private static final List boldTooltip = new ArrayList<>();
- private static final List underlineTooltip = new ArrayList<>();
- private static final List italicTooltip = new ArrayList<>();
- private static final List signTooltip = new ArrayList<>();
+ private static final TextComponent targetTooltip = new TextComponent("The language your chat will be translated to");
+ private static final List selfTooltip = new ArrayList<>();
+ private static final List speakAsTooltip = new ArrayList<>();
+ private static final List regexTooltip = new ArrayList<>();
+ private static final List apiKeyTooltip = new ArrayList<>();
+ private static final List colorTooltip = new ArrayList<>();
+ private static final List boldTooltip = new ArrayList<>();
+ private static final List underlineTooltip = new ArrayList<>();
+ private static final List italicTooltip = new ArrayList<>();
+ private static final List signTooltip = new ArrayList<>();
private static final String title;
static {
- selfTooltip.add(new StringTextComponent("The language you speak in game"));
- selfTooltip.add(new StringTextComponent("This will be utilised when you want to translate what you speak"));
- speakAsTooltip.add(new StringTextComponent("The language your messages will be translated to."));
- speakAsTooltip.add(new StringTextComponent("After you typed your messages through this mod,"));
- speakAsTooltip.add(new StringTextComponent("it will be translated to the language you specified"));
- regexTooltip.add(new StringTextComponent("Regex are patterns for the mod to detect chat messages."));
- regexTooltip.add(new StringTextComponent("If you notice the mod doesn't do anything on a server,"));
- regexTooltip.add(new StringTextComponent("chances are you need to add one here."));
- signTooltip.add(new StringTextComponent("Translates signs when you look at them"));
- apiKeyTooltip.add(new StringTextComponent("Change your translation engine options and enter your API key"));
- colorTooltip.add(new StringTextComponent("Changes the color of the translated message"));
- boldTooltip.add(new StringTextComponent("Bolds the translated message"));
- italicTooltip.add(new StringTextComponent("Italics the translated message"));
- underlineTooltip.add(new StringTextComponent("Underlines the translated message"));
+ selfTooltip.add(new TextComponent("The language you speak in game"));
+ selfTooltip.add(new TextComponent("This will be utilised when you want to translationmod.mixins.json what you speak"));
+ speakAsTooltip.add(new TextComponent("The language your messages will be translated to."));
+ speakAsTooltip.add(new TextComponent("After you typed your messages through this mod,"));
+ speakAsTooltip.add(new TextComponent("it will be translated to the language you specified"));
+ regexTooltip.add(new TextComponent("Regex are patterns for the mod to detect chat messages."));
+ regexTooltip.add(new TextComponent("If you notice the mod doesn't do anything on a server,"));
+ regexTooltip.add(new TextComponent("chances are you need to add one here."));
+ signTooltip.add(new TextComponent("Translates signs when you look at them"));
+ apiKeyTooltip.add(new TextComponent("Change your translation engine options and enter your API key"));
+ colorTooltip.add(new TextComponent("Changes the color of the translated message"));
+ boldTooltip.add(new TextComponent("Bolds the translated message"));
+ italicTooltip.add(new TextComponent("Italics the translated message"));
+ underlineTooltip.add(new TextComponent("Underlines the translated message"));
@SuppressWarnings("OptionalGetWithoutIsPresent")
String modName = ModList.get().getModContainerById(TranslationMod.MODID).get().getModInfo().getDisplayName();
title = modName + " - Settings";
@@ -78,6 +78,9 @@ public class ConfigGui extends CommonGui {
private boolean italic;
private boolean underline;
private boolean translateSign;
+ private boolean modAble;
+
+ Button modAbleButton;
ConfigGui() {
super(title, guiHeight, guiWidth);
@@ -95,6 +98,7 @@ public class ConfigGui extends CommonGui {
this.underline = instance.underline;
this.translateSign = instance.translateSign;
this.isTransition = true;
+ this.modAble = instance.modAble;
if (lang != null) {
switch (langSelect) {
case 0:
@@ -111,51 +115,69 @@ public class ConfigGui extends CommonGui {
}
@Override
- public void render(MatrixStack stack, int x, int y, float tick) {
+ public void render(PoseStack stack, int x, int y, float tick) {
super.render(stack, x, y, tick);
drawStringLine(stack, title, null, 0);
- font.drawString(stack, "Regex list:", getLeftMargin(), getYOrigin() + 25, 0x555555);
- font.drawString(stack, "Target language:", getLeftMargin(), getYOrigin() + 55, 0x555555);
- font.drawString(stack, "Self language:", getLeftMargin(), getYOrigin() + 75, 0x555555);
- font.drawString(stack, "Speak as language:", getLeftMargin(), getYOrigin() + 95, 0x555555);
- font.drawString(stack, "Preview: ", getLeftMargin(), getYOrigin() + 115, 0x555555);
+ font.draw(stack, "Regex list:", getLeftMargin(), getYOrigin() + 25, 0x555555);
+ font.draw(stack, "Target language:", getLeftMargin(), getYOrigin() + 55, 0x555555);
+ font.draw(stack, "Self language:", getLeftMargin(), getYOrigin() + 75, 0x555555);
+ font.draw(stack, "Speak as language:", getLeftMargin(), getYOrigin() + 95, 0x555555);
+ font.draw(stack, "Preview: ", getLeftMargin(), getYOrigin() + 115, 0x555555);
- Style previewStyle = Style.EMPTY.setFormatting(TextFormatting.getValueByName(color))
- .mergeStyle(Style.EMPTY.setBold(bold))
- .mergeStyle(Style.EMPTY.setItalic(italic))
- .mergeStyle(Style.EMPTY.setUnderlined(underline));
- font.drawText(stack, new StringTextComponent("Notch --> English: Hello!").setStyle(previewStyle), getLeftMargin() + 45, getYOrigin() + 115, 0);
+ Style previewStyle = Style.EMPTY.applyFormats(ChatFormatting.getByName(color))
+ .withBold(bold).withItalic(italic).withUnderlined(underline);
+ font.draw(stack, new TextComponent("Notch --> English: Hello!").setStyle(previewStyle), getLeftMargin() + 45, getYOrigin() + 115, 0);
//func_243308_b(MatrixStack, List, int, int) -> renderTooltip(...)
+ Button button2,button3,button4, button5, button6, button7, button8, button9, button10, button11;
+ button10 = button11 = button9 = button8 = button7 = button6 = button5 = button4 = button3 = button2 = null;
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button){
+ if(j == 2) button2 = (Button)renderables.get(i);
+ if(j == 3) button3 = (Button)renderables.get(i);
+ if(j == 4) button4 = (Button)renderables.get(i);
+ if(j == 5) button5 = (Button)renderables.get(i);
+ if(j == 6) button6 = (Button)renderables.get(i);
+ if(j == 7) button7 = (Button)renderables.get(i);
+ if(j == 8) button8 = (Button)renderables.get(i);
+ if(j == 9) button9 = (Button)renderables.get(i);
+ if(j == 10) button10 = (Button)renderables.get(i);
+ if(j == 11) {
+ button11 = (Button)renderables.get(i);
+ break;
+ }
+ j++;
+ }
+ }
//Target language
- if (this.buttons.get(2).isHovered())
+ if (button2 != null && button2.isHoveredOrFocused())
renderTooltip(stack, targetTooltip, x, y);
//Self language
- if (this.buttons.get(3).isHovered())
- func_243308_b(stack, selfTooltip, x, y);
+ if (button3 != null && button3.isHoveredOrFocused())
+ renderComponentTooltip(stack, selfTooltip, x, y);
//Speak as language
- if (this.buttons.get(4).isHovered())
- func_243308_b(stack, speakAsTooltip, x, y);
+ if (button4 != null && button4.isHoveredOrFocused())
+ renderComponentTooltip(stack, speakAsTooltip, x, y);
//Regex list
- if (this.buttons.get(11).isHovered())
- func_243308_b(stack, regexTooltip, x, y);
+ if (button11 != null && button11.isHoveredOrFocused())
+ renderComponentTooltip(stack, regexTooltip, x, y);
//API key
- if (this.buttons.get(6).isHovered())
- func_243308_b(stack, apiKeyTooltip, x, y);
+ if (button6 != null && button6.isHoveredOrFocused())
+ renderComponentTooltip(stack, apiKeyTooltip, x, y);
//Translate sign
- if (this.buttons.get(5).isHovered())
- func_243308_b(stack, signTooltip, x, y);
+ if (button5 != null && button5.isHoveredOrFocused())
+ renderComponentTooltip(stack, signTooltip, x, y);
//Color message
- if (this.buttons.get(7).isHovered())
- func_243308_b(stack, colorTooltip, x, y);
+ if (button7 != null && button7.isHoveredOrFocused())
+ renderComponentTooltip(stack, colorTooltip, x, y);
//Bold
- if (this.buttons.get(8).isHovered())
- func_243308_b(stack, boldTooltip, x, y);
+ if (button8 != null && button8.isHoveredOrFocused())
+ renderComponentTooltip(stack, boldTooltip, x, y);
//Italic
- if (this.buttons.get(9).isHovered())
- func_243308_b(stack, italicTooltip, x, y);
+ if (button9 != null && button9.isHoveredOrFocused())
+ renderComponentTooltip(stack, italicTooltip, x, y);
//Underline
- if (this.buttons.get(10).isHovered())
- func_243308_b(stack, underlineTooltip, x, y);
+ if (button10 != null && button10.isHoveredOrFocused())
+ renderComponentTooltip(stack, underlineTooltip, x, y);
}
@Override
@@ -165,51 +187,58 @@ public void init() {
bold = ConfigManager.config.bold.get();
italic = ConfigManager.config.italic.get();
underline = ConfigManager.config.underline.get();
+ modAble = ConfigManager.config.modAble.get();
translateSign = ConfigManager.config.translateSign.get();
targetLang = LangManager.getInstance().findLanguageFromName(ConfigManager.config.targetLanguage.get());
selfLang = LangManager.getInstance().findLanguageFromName(ConfigManager.config.selfLanguage.get());
speakAsLang = LangManager.getInstance().findLanguageFromName(ConfigManager.config.speakAsLanguage.get());
}
- addButton(new Button(getLeftMargin(), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new StringTextComponent("Save and close"),
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new TextComponent("Save and close"),
(button) -> this.applySettings()));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new StringTextComponent("Reset to default"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new TextComponent("Reset to default"),
(button) -> this.resetDefault()));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 50, regularButtonWidth, regularButtonHeight, new StringTextComponent(targetLang.getName()),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 50, regularButtonWidth, regularButtonHeight, new TextComponent(targetLang.getName()),
(button) -> this.langSelect(0)));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 70, regularButtonWidth, regularButtonHeight, new StringTextComponent(selfLang.getName()),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 70, regularButtonWidth, regularButtonHeight, new TextComponent(selfLang.getName()),
(button) -> this.langSelect(1)));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 90, regularButtonWidth, regularButtonHeight, new StringTextComponent(speakAsLang.getName()),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 90, regularButtonWidth, regularButtonHeight, new TextComponent(speakAsLang.getName()),
(button) -> this.langSelect(2)));
- addButton(new Button(getLeftMargin(), getYOrigin() + guiHeight - 15 - regularButtonHeight * 3, regularButtonWidth, regularButtonHeight, new StringTextComponent(translateSign ? TextFormatting.GREEN + "Translate signs" : TextFormatting.RED + "Translate signs"),
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + guiHeight - 15 - regularButtonHeight * 3, regularButtonWidth, regularButtonHeight, new TextComponent(translateSign ? ChatFormatting.GREEN + "Translate signs" : ChatFormatting.RED + "Translate signs"),
(button) -> {
translateSign = !translateSign;
this.toggleButtonBool(translateSign, button);
}));
- addButton(new Button(getLeftMargin(), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new StringTextComponent("Engine options"),
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new TextComponent("Engine options"),
(button) -> this.addKeyGui()));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new StringTextComponent(TextFormatting.getValueByName(color) + "Message color"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new TextComponent(ChatFormatting.getByName(color) + "Message color"),
this::rotateColor));
- addButton(new Button(getLeftMargin() + regularButtonWidth + 10, getYOrigin() + guiHeight - 15 - regularButtonHeight * 3, smallButtonLength, smallButtonLength, new StringTextComponent(bold ? "\u00a7a" + TextFormatting.BOLD + "B" : "\u00a7c" + TextFormatting.BOLD + "B"),
+ addRenderableWidget(new Button(getLeftMargin() + regularButtonWidth + 10, getYOrigin() + guiHeight - 15 - regularButtonHeight * 3, smallButtonLength, smallButtonLength, new TextComponent(bold ? "\u00a7a" + ChatFormatting.BOLD + "B" : "\u00a7c" + ChatFormatting.BOLD + "B"),
(button) -> {
bold = !bold;
- this.toggleButtonBool(bold, button, TextFormatting.BOLD);
+ this.toggleButtonBool(bold, button, ChatFormatting.BOLD);
}));
- addButton(new Button(getLeftMargin() + regularButtonWidth + 10, getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, smallButtonLength, smallButtonLength, new StringTextComponent(italic ? "\u00a7a" + TextFormatting.ITALIC + "I" : "\u00a7c" + TextFormatting.ITALIC + "I"),
+ addRenderableWidget(new Button(getLeftMargin() + regularButtonWidth + 10, getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, smallButtonLength, smallButtonLength, new TextComponent(italic ? "\u00a7a" + ChatFormatting.ITALIC + "I" : "\u00a7c" + ChatFormatting.ITALIC + "I"),
(button) -> {
italic = !italic;
- this.toggleButtonBool(italic, button, TextFormatting.ITALIC);
+ this.toggleButtonBool(italic, button, ChatFormatting.ITALIC);
}));
- addButton(new Button(getLeftMargin() + regularButtonWidth + 10, getYOrigin() + guiHeight - 5 - regularButtonHeight, smallButtonLength, smallButtonLength, new StringTextComponent(underline ? "\u00a7a" + TextFormatting.UNDERLINE + "U" : "\u00a7c" + TextFormatting.UNDERLINE + "U"),
+ addRenderableWidget(new Button(getLeftMargin() + regularButtonWidth + 10, getYOrigin() + guiHeight - 5 - regularButtonHeight, smallButtonLength, smallButtonLength, new TextComponent(underline ? "\u00a7a" + ChatFormatting.UNDERLINE + "U" : "\u00a7c" + ChatFormatting.UNDERLINE + "U"),
(button) -> {
underline = !underline;
- this.toggleButtonBool(underline, button, TextFormatting.UNDERLINE);
+ this.toggleButtonBool(underline, button, ChatFormatting.UNDERLINE);
}));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 20, regularButtonWidth, regularButtonHeight, new StringTextComponent("View / Add"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + 20, regularButtonWidth, regularButtonHeight, new TextComponent("View / Add"),
(button) -> this.regexGui()));
+ modAbleButton = new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 15 - regularButtonHeight * 3, regularButtonWidth, regularButtonHeight, new TextComponent(modAble ? ChatFormatting.GREEN + "Translate Able" : ChatFormatting.RED + "Translate Able"),
+ (button) -> {
+ modAble = !modAble;
+ this.toggleButtonBool(modAble, button);
+ });
+ addRenderableWidget(modAbleButton);
}
private void applySettings() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
ConfigManager.config.targetLanguage.set(targetLang.getName());
ConfigManager.config.selfLanguage.set(selfLang.getName());
ConfigManager.config.speakAsLanguage.set(speakAsLang.getName());
@@ -218,28 +247,29 @@ private void applySettings() {
ConfigManager.config.italic.set(italic);
ConfigManager.config.underline.set(underline);
ConfigManager.config.translateSign.set(translateSign);
+ ConfigManager.config.modAble.set(modAble);
ConfigManager.saveConfig();
- ChatUtil.printChatMessage(true, "Settings applied.", TextFormatting.WHITE);
+ ChatUtil.printChatMessage(true, "Settings applied.", ChatFormatting.WHITE);
exitGui();
}
private void exitGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(null);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(null);
}
private void langSelect(int id) {
- getMinecraft().displayGuiScreen(new LanguageSelectGui(this, id));
+ getMinecraft().pushGuiLayer(new LanguageSelectGui(this, id));
}
- private void toggleButtonBool(boolean state, Button button, TextFormatting prefixFormat) {
- String rawString = button.getMessage().getUnformattedComponentText().replaceAll("\u00a7(.)", "");
- StringTextComponent buttonText;
- TextFormatting color = state ? TextFormatting.GREEN : TextFormatting.RED;
+ private void toggleButtonBool(boolean state, Button button, ChatFormatting prefixFormat) {
+ String rawString = button.getMessage().getString().replaceAll("\u00a7(.)", "");
+ TextComponent buttonText;
+ ChatFormatting color = state ? ChatFormatting.GREEN : ChatFormatting.RED;
if (prefixFormat == null) {
- buttonText = new StringTextComponent(color + rawString);
+ buttonText = new TextComponent(color + rawString);
} else {
- buttonText = new StringTextComponent(prefixFormat + "" + color + rawString);
+ buttonText = new TextComponent(prefixFormat + "" + color + rawString);
}
button.setMessage(buttonText);
}
@@ -250,24 +280,24 @@ private void toggleButtonBool(boolean state, Button button) {
@SuppressWarnings("ConstantConditions")
private void rotateColor(Button button) {
- TextFormatting formatColor = TextFormatting.getValueByName(color);
- int colorCode = formatColor.getColorIndex();
+ ChatFormatting formatColor = ChatFormatting.getByName(color);
+ int colorCode = formatColor.getColor();
colorCode++;
colorCode = colorCode & 0xf;
- TextFormatting newColor = TextFormatting.fromColorIndex(colorCode);
- color = newColor.getFriendlyName();
- StringTextComponent buttonText = new StringTextComponent(newColor + button.getMessage().getUnformattedComponentText().replaceAll("\u00a7(.)", ""));
+ ChatFormatting newColor = ChatFormatting.getById(colorCode);
+ color = newColor.getName();
+ TextComponent buttonText = new TextComponent(newColor + button.getMessage().getString().replaceAll("\u00a7(.)", ""));
button.setMessage(buttonText);
}
private void regexGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(true);
- getMinecraft().displayGuiScreen(new RegexGui());
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
+ getMinecraft().setScreen(new RegexGui());
}
private void addKeyGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(true);
- getMinecraft().displayGuiScreen(new EngineGui());
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
+ getMinecraft().setScreen(new EngineGui());
}
private void resetDefault() {
@@ -276,16 +306,52 @@ private void resetDefault() {
italic = false;
underline = false;
translateSign = true;
+ modAble = true;
targetLang = LangManager.getInstance().findLanguageFromName("English");
selfLang = targetLang;
speakAsLang = LangManager.getInstance().findLanguageFromName("Japanese");
- this.buttons.get(2).setMessage(new StringTextComponent("English"));
- this.buttons.get(3).setMessage(new StringTextComponent("English"));
- this.buttons.get(4).setMessage(new StringTextComponent("Japanese"));
- this.buttons.get(5).setMessage(new StringTextComponent(TextFormatting.GREEN + "Translate signs"));
- this.buttons.get(7).setMessage(new StringTextComponent(TextFormatting.getValueByName(color) + "Message color"));
- this.buttons.get(8).setMessage(new StringTextComponent(bold ? "\u00a7a" : "\u00a7c" + TextFormatting.BOLD + "B"));
- this.buttons.get(9).setMessage(new StringTextComponent(italic ? "\u00a7a" : "\u00a7c" + TextFormatting.ITALIC + "I"));
- this.buttons.get(10).setMessage(new StringTextComponent(underline ? "\u00a7a" : "\u00a7c" + TextFormatting.UNDERLINE + "U"));
+ Button button2,button3,button4, button5, button7, button8, button9, button10;
+ button10 = button9 = button8 = button7 = button5 = button4 = button3 = button2 = null;
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button){
+ if(j == 2) button2 = (Button)renderables.get(i);
+ if(j == 3) button3 = (Button)renderables.get(i);
+ if(j == 4) button4 = (Button)renderables.get(i);
+ if(j == 5) button5 = (Button)renderables.get(i);
+ if(j == 7) button7 = (Button)renderables.get(i);
+ if(j == 8) button8 = (Button)renderables.get(i);
+ if(j == 9) button9 = (Button)renderables.get(i);
+ if(j == 10) {
+ button10 = (Button)renderables.get(i);
+ break;
+ }
+ j++;
+ }
+ }
+ if(button2 != null) {
+ button2.setMessage(new TextComponent("English"));
+ }
+ if(button3 != null) {
+ button3.setMessage(new TextComponent("English"));
+ }
+ if(button4 != null) {
+ button4.setMessage(new TextComponent("Japanese"));
+ }
+ if(button5 != null) {
+ button5.setMessage(new TextComponent(ChatFormatting.GREEN + "Translate signs"));
+ }
+ if(button7 != null) {
+ button7.setMessage(new TextComponent(ChatFormatting.getByName(color) + "Message color"));
+ }
+ if(button8 != null) {
+ button8.setMessage(new TextComponent(bold ? "\u00a7a" : "\u00a7c" + ChatFormatting.BOLD + "B"));
+ }
+ if(button9 != null) {
+ button9.setMessage(new TextComponent(italic ? "\u00a7a" : "\u00a7c" + ChatFormatting.ITALIC + "I"));
+ }
+ if(button10 != null) {
+ button10.setMessage(new TextComponent(underline ? "\u00a7a" : "\u00a7c" + ChatFormatting.UNDERLINE + "U"));
+ }
+ modAbleButton.setMessage(new TextComponent(ChatFormatting.GREEN + "Translate Able"));
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/EngineGui.java b/src/main/java/com/ringosham/translationmod/gui/EngineGui.java
index 0b01932..df62dc4 100644
--- a/src/main/java/com/ringosham/translationmod/gui/EngineGui.java
+++ b/src/main/java/com/ringosham/translationmod/gui/EngineGui.java
@@ -17,16 +17,16 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.vertex.PoseStack;
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.common.ChatUtil;
import com.ringosham.translationmod.common.ConfigManager;
import com.ringosham.translationmod.common.Log;
-import net.minecraft.client.gui.widget.TextFieldWidget;
-import net.minecraft.client.gui.widget.button.Button;
-import net.minecraft.util.text.ITextComponent;
-import net.minecraft.util.text.StringTextComponent;
-import net.minecraft.util.text.TextFormatting;
+import net.minecraft.ChatFormatting;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.client.gui.components.EditBox;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TextComponent;
import net.minecraftforge.fml.ModList;
import org.lwjgl.glfw.GLFW;
@@ -38,30 +38,30 @@ public class EngineGui extends CommonGui {
private static final int guiHeight = 150;
private static final String title;
- private static final List googleTooltip = new ArrayList<>();
- private static final List baiduTooltip = new ArrayList<>();
+ private static final List googleTooltip = new ArrayList<>();
+ private static final List baiduTooltip = new ArrayList<>();
static {
@SuppressWarnings("OptionalGetWithoutIsPresent")
String modName = ModList.get().getModContainerById(TranslationMod.MODID).get().getModInfo().getDisplayName();
title = modName + " - Engine options";
- googleTooltip.add(new StringTextComponent("By default, you are using the \"free\" version of Google translation"));
- googleTooltip.add(new StringTextComponent("This is the same API the Google translate website is using"));
- googleTooltip.add(new StringTextComponent("However, too many requests and Google will block you for a few minutes"));
- googleTooltip.add(new StringTextComponent("Cloud translation API is the paid version of Google translate"));
- googleTooltip.add(new StringTextComponent("Please check the mod page for details"));
- baiduTooltip.add(new StringTextComponent("If you cannot use Google due to country restrictions,"));
- baiduTooltip.add(new StringTextComponent("Baidu is your second option"));
- baiduTooltip.add(new StringTextComponent("An account is needed to use this API (Phone verification required)"));
- baiduTooltip.add(new StringTextComponent("Free tier only allows 1 request per second"));
- baiduTooltip.add(new StringTextComponent("Paying allows for more requests per second"));
- baiduTooltip.add(new StringTextComponent("Please check the mod page for details"));
+ googleTooltip.add(new TextComponent("By default, you are using the \"free\" version of Google translation"));
+ googleTooltip.add(new TextComponent("This is the same API the Google translationmod.mixins.json website is using"));
+ googleTooltip.add(new TextComponent("However, too many requests and Google will block you for a few minutes"));
+ googleTooltip.add(new TextComponent("Cloud translation API is the paid version of Google translationmod.mixins.json"));
+ googleTooltip.add(new TextComponent("Please check the mod page for details"));
+ baiduTooltip.add(new TextComponent("If you cannot use Google due to country restrictions,"));
+ baiduTooltip.add(new TextComponent("Baidu is your second option"));
+ baiduTooltip.add(new TextComponent("An account is needed to use this API (Phone verification required)"));
+ baiduTooltip.add(new TextComponent("Free tier only allows 1 request per second"));
+ baiduTooltip.add(new TextComponent("Paying allows for more requests per second"));
+ baiduTooltip.add(new TextComponent("Please check the mod page for details"));
}
private String engine;
- private TextFieldWidget googleKeyBox;
- private TextFieldWidget baiduKeyBox;
- private TextFieldWidget baiduAppIdBox;
+ private EditBox googleKeyBox;
+ private EditBox baiduKeyBox;
+ private EditBox baiduAppIdBox;
EngineGui() {
super(title, guiHeight, guiWidth);
@@ -69,7 +69,7 @@ public class EngineGui extends CommonGui {
}
@Override
- public void render(MatrixStack stack, int x, int y, float tick) {
+ public void render(PoseStack stack, int x, int y, float tick) {
super.render(stack, x, y, tick);
drawStringLine(stack, title, new String[]{
"Please choose your translation engine",
@@ -77,78 +77,131 @@ public void render(MatrixStack stack, int x, int y, float tick) {
}, 5);
switch (engine) {
case "google":
- font.drawString(stack, "Cloud platform API key", getLeftMargin(), getYOrigin() + 75, 0x555555);
googleKeyBox.render(stack, x, y, tick);
- font.drawString(stack, "Delete/Leave empty to use the free API", getLeftMargin(), getYOrigin() + 110, 0x555555);
+ baiduKeyBox.active = false;
+ baiduAppIdBox.active = false;
+ baiduKeyBox.visible = false;
+ baiduAppIdBox.visible = false;
+ googleKeyBox.active = true;
+ googleKeyBox.visible = true;
+ font.draw(stack, "Cloud platform API key", getLeftMargin(), getYOrigin() + 75, 0);
+ font.draw(stack, "Delete/Leave empty to use the free API", getLeftMargin(), getYOrigin() + 110, 0);
break;
case "baidu":
- font.drawString(stack, "Baidu developer App ID", getLeftMargin(), getYOrigin() + 65, 0x555555);
+ baiduKeyBox.active = true;
+ baiduAppIdBox.active = true;
+ baiduKeyBox.visible = true;
+ baiduAppIdBox.visible = true;
+ googleKeyBox.active = false;
+ googleKeyBox.visible = false;
+ font.draw(stack, "Baidu developer App ID", getLeftMargin(), getYOrigin() + 65, 0);
baiduAppIdBox.render(stack, x, y, tick);
- font.drawString(stack, "Baidu API key", getLeftMargin(), getYOrigin() + 95, 0x555555);
+ font.draw(stack, "Baidu API key", getLeftMargin(), getYOrigin() + 95, 0);
baiduKeyBox.render(stack, x, y, tick);
break;
}
- if (this.buttons.get(0).isHovered())
- func_243308_b(stack, googleTooltip, x, y);
- if (this.buttons.get(1).isHovered())
- func_243308_b(stack, baiduTooltip, x, y);
+ Button button0 = null;
+ Button button1 = null;
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button){
+ if(j == 0) button0 = (Button)renderables.get(i);
+ if(j == 1) {
+ button1 = (Button)renderables.get(i);
+ break;
+ }
+ j++;
+ }
+ }
+ if (button0 != null && button0.isHoveredOrFocused())
+ renderComponentTooltip(stack, googleTooltip, x, y);
+ if (button1 != null && button1.isHoveredOrFocused())
+ renderComponentTooltip(stack, baiduTooltip, x, y);
}
@Override
public void init() {
- getMinecraft().keyboardListener.enableRepeatEvents(true);
- this.googleKeyBox = new TextFieldWidget(this.font, getLeftMargin(), getYOrigin() + 90, guiWidth - 10, 15, null);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
+ this.googleKeyBox = new EditBox(this.font, getLeftMargin(), getYOrigin() + 90, guiWidth - 10, 15, null);
googleKeyBox.setCanLoseFocus(true);
- googleKeyBox.setMaxStringLength(84);
- googleKeyBox.setEnableBackgroundDrawing(true);
- googleKeyBox.setText(ConfigManager.config.googleKey.get());
- this.children.add(googleKeyBox);
- this.baiduAppIdBox = new TextFieldWidget(this.font, getLeftMargin(), getYOrigin() + 75, guiWidth - 10, 15, null) {
+ googleKeyBox.setMaxLength(84);
+ googleKeyBox.setBordered(true);
+ googleKeyBox.setValue(ConfigManager.config.googleKey.get());
+ addRenderableWidget(googleKeyBox);
+ this.baiduAppIdBox = new EditBox(this.font, getLeftMargin(), getYOrigin() + 75, guiWidth - 10, 15, null) {
@Override
public void onClick(double mouseX, double mouseY) {
- baiduKeyBox.setFocused2(false);
- super.onClick(mouseX, mouseY);
+ baiduKeyBox.setFocus(false);
+ super.clicked(mouseX, mouseY);
}
};
baiduAppIdBox.setCanLoseFocus(true);
- baiduAppIdBox.setMaxStringLength(20);
- baiduAppIdBox.setEnableBackgroundDrawing(true);
- baiduAppIdBox.setText(ConfigManager.config.baiduAppId.get());
- this.children.add(baiduAppIdBox);
- this.baiduKeyBox = new TextFieldWidget(this.font, getLeftMargin(), getYOrigin() + 105, guiWidth - 10, 15, null) {
+ baiduAppIdBox.setMaxLength(20);
+ baiduAppIdBox.setBordered(true);
+ baiduAppIdBox.setValue(ConfigManager.config.baiduAppId.get());
+ addRenderableWidget(baiduAppIdBox);
+ this.baiduKeyBox = new EditBox(this.font, getLeftMargin(), getYOrigin() + 105, guiWidth - 10, 15, null) {
@Override
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
- baiduAppIdBox.setFocused2(false);
+ baiduAppIdBox.setFocus(false);
}
};
baiduKeyBox.setCanLoseFocus(true);
- baiduKeyBox.setEnableBackgroundDrawing(true);
- baiduKeyBox.setMaxStringLength(24);
- baiduKeyBox.setText(ConfigManager.config.baiduKey.get());
- this.children.add(baiduKeyBox);
+ baiduKeyBox.setBordered(true);
+ baiduKeyBox.setMaxLength(24);
+ baiduKeyBox.setValue(ConfigManager.config.baiduKey.get());
+ addRenderableWidget(baiduKeyBox);
- addButton(new Button(getLeftMargin(), getYOrigin() + 40, guiWidth / 2 - 10, regularButtonHeight, new StringTextComponent("Google"), (button) -> {
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + 40, guiWidth / 2 - 10, regularButtonHeight, new TextComponent("Google"), (button) -> {
button.active = false;
- this.buttons.get(1).active = true;
+ Button button1 = null;
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button){
+ if(j == 1) {
+ button1 = (Button)renderables.get(i);
+ break;
+ }
+ j++;
+ }
+ }
+ if(button1 != null) button1.active = true;
engine = "google";
}));
- addButton(new Button(getRightMargin(guiWidth / 2 - 5), getYOrigin() + 40, guiWidth / 2 - 10, regularButtonHeight, new StringTextComponent("Baidu"), (button) -> {
+ addRenderableWidget(new Button(getRightMargin(guiWidth / 2 - 5), getYOrigin() + 40, guiWidth / 2 - 10, regularButtonHeight, new TextComponent("Baidu"), (button) -> {
button.active = false;
- this.buttons.get(0).active = true;
+ Button button0 = null;
+ for (net.minecraft.client.gui.components.Widget renderable : renderables) {
+ if (renderable instanceof Button) {
+ button0 = (Button) renderable;
+ break;
+ }
+ }
+ if(button0 != null) button0.active = true;
engine = "baidu";
}));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new StringTextComponent("Apply and close"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new TextComponent("Apply and close"),
(button) -> this.applyKey()));
- addButton(new Button(getRightMargin(regularButtonWidth) - regularButtonWidth - 5, getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new StringTextComponent("Back"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth) - regularButtonWidth - 5, getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new TextComponent("Back"),
(button) -> this.configGui()));
+ Button button0 = null;
+ Button button1 = null;
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button){
+ if(j == 0) button0 = (Button)renderables.get(i);
+ if(j == 1) {
+ button1 = (Button)renderables.get(i);
+ break;
+ }
+ j++;
+ }
+ }
switch (engine) {
case "google":
- this.buttons.get(0).active = false;
+ if(button0 != null) button0.active = true;
break;
case "baidu":
- this.buttons.get(1).active = false;
+ if(button1 != null) button1.active = true;
break;
}
}
@@ -156,27 +209,49 @@ public void onClick(double mouseX, double mouseY) {
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifier) {
if (keyCode == GLFW.GLFW_KEY_E && !this.googleKeyBox.isFocused()) {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(null);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(null);
return false;
}
return super.keyPressed(keyCode, scanCode, modifier);
}
private void configGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(new ConfigGui());
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(new ConfigGui());
}
private void applyKey() {
- getMinecraft().keyboardListener.enableRepeatEvents(true);
- ConfigManager.config.googleKey.set(googleKeyBox.getText());
- ConfigManager.config.baiduAppId.set(baiduAppIdBox.getText());
- ConfigManager.config.baiduKey.set(baiduKeyBox.getText());
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
+ ConfigManager.config.googleKey.set(googleKeyBox.getValue());
+ ConfigManager.config.baiduAppId.set(baiduAppIdBox.getValue());
+ ConfigManager.config.baiduKey.set(baiduKeyBox.getValue());
ConfigManager.config.translationEngine.set(engine);
ConfigManager.saveConfig();
Log.logger.info("Saved engine options");
- ChatUtil.printChatMessage(true, "New translation engine options have been applied.", TextFormatting.WHITE);
- getMinecraft().displayGuiScreen(null);
+ ChatUtil.printChatMessage(true, "New translation engine options have been applied.", ChatFormatting.WHITE);
+ getMinecraft().setScreen(null);
+ }
+
+ @Override
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
+ // 点击 headerField 区域时转移焦点
+ if (googleKeyBox.isMouseOver(mouseX, mouseY)) {
+ googleKeyBox.setFocus(true);
+ googleKeyBox.setFocus(false); // 移除其他框的焦点
+ }
+
+ // 点击 messageField 区域时同理
+ if (baiduKeyBox.isMouseOver(mouseX, mouseY)) {
+ baiduKeyBox.setFocus(true);
+ baiduKeyBox.setFocus(false);
+ }
+
+ if (baiduAppIdBox.isMouseOver(mouseX, mouseY)) {
+ baiduAppIdBox.setFocus(true);
+ baiduAppIdBox.setFocus(false);
+ }
+
+ return super.mouseClicked(mouseX, mouseY, button);
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/LangList.java b/src/main/java/com/ringosham/translationmod/gui/LangList.java
index 5c5a445..6192449 100644
--- a/src/main/java/com/ringosham/translationmod/gui/LangList.java
+++ b/src/main/java/com/ringosham/translationmod/gui/LangList.java
@@ -17,26 +17,31 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.blaze3d.vertex.*;
import com.ringosham.translationmod.client.LangManager;
import com.ringosham.translationmod.client.types.Language;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.AbstractGui;
-import net.minecraft.client.gui.FontRenderer;
-import net.minecraft.client.gui.widget.list.ExtendedList;
-import net.minecraft.client.renderer.BufferBuilder;
-import net.minecraft.client.renderer.Tessellator;
-import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
-import net.minecraft.util.math.MathHelper;
+import net.minecraft.client.gui.Font;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.components.AbstractSelectionList;
+import net.minecraft.client.gui.components.ObjectSelectionList;
+import net.minecraft.client.gui.components.events.GuiEventListener;
+import net.minecraft.client.gui.narration.NarrationElementOutput;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TextComponent;
+import net.minecraft.util.Mth;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
import java.util.List;
+import java.util.Optional;
-public class LangList extends ExtendedList {
+public class LangList extends ObjectSelectionList {
private final List langList;
- private final FontRenderer font;
+ private final Font font;
{
langList = LangManager.getInstance().getAllLanguages();
@@ -46,11 +51,17 @@ public class LangList extends ExtendedList {
langList.sort(Comparator.comparing(Language::getName));
}
- public LangList(Minecraft client, FontRenderer font, int width, int height, int top, int bottom, int entryHeight) {
+ public LangList(Minecraft client, Font font, int width, int height, int top, int bottom, int entryHeight) {
+ // 修复:使用正确的构造函数参数顺序和方法
super(client, width, height, top, bottom, entryHeight);
this.font = font;
- for (Language lang : langList)
+ this.setRenderBackground(false);
+ this.setRenderTopAndBottom(false);
+
+ // 修复:确保在正确时机添加条目
+ for (Language lang : langList) {
this.addEntry(new LangEntry(lang));
+ }
}
@Override
@@ -63,30 +74,25 @@ public int getRowWidth() {
return this.width;
}
- @Override
- protected boolean isFocused() {
- return true;
- }
-
//The dirt background does not render correctly and it covers UI elements, needs to be disabled
//Had to extract the entire rendering method as by default it renders the dirt background and there is no way to override it. This is so dumb.
- @SuppressWarnings({"NullableProblems", "deprecation"})
@Override
- public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
+ public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
int i = this.getScrollbarPosition();
int j = i + 6;
- Tessellator tessellator = Tessellator.getInstance();
- BufferBuilder bufferbuilder = tessellator.getBuffer();
- this.minecraft.getTextureManager().bindTexture(AbstractGui.BACKGROUND_LOCATION);
- RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
- bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
- bufferbuilder.pos(this.x0, this.y1, 0.0D).tex((float) this.x0 / 32.0F, (float) (this.y1 + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
- bufferbuilder.pos(this.x1, this.y1, 0.0D).tex((float) this.x1 / 32.0F, (float) (this.y1 + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
- bufferbuilder.pos(this.x1, this.y0, 0.0D).tex((float) this.x1 / 32.0F, (float) (this.y0 + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
- bufferbuilder.pos(this.x0, this.y0, 0.0D).tex((float) this.x0 / 32.0F, (float) (this.y0 + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
- tessellator.draw();
+ Tesselator tessellator = Tesselator.getInstance();
+ BufferBuilder bufferbuilder = tessellator.getBuilder();
+ this.minecraft.getTextureManager().bindForSetup(Gui.BACKGROUND_LOCATION);
+ RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
+ bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
+ bufferbuilder.vertex(matrixStack.last().pose(), getLeft(), getBottom(), 0).uv((float) getLeft() / 32.0F, (float) (getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getRight(), getBottom(), 0).uv((float) getRight() / 32.0F, (float) (getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getRight(), getTop(), 0).uv((float) getRight() / 32.0F, (float) (getTop() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getLeft(), getTop(), 0).uv((float) getLeft() / 32.0F, (float) (getTop() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).endVertex();
+ bufferbuilder.end();
+ BufferUploader.end(bufferbuilder);
int k = this.getRowLeft();
- int l = this.y0 + 4 - (int) this.getScrollAmount();
+ int l = getTop() + 4 - (int) this.getScrollAmount();
this.renderList(matrixStack, k, l, mouseX, mouseY, partialTicks);
@@ -94,52 +100,68 @@ public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partia
RenderSystem.disableDepthTest();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
- RenderSystem.disableAlphaTest();
- RenderSystem.shadeModel(7425);
RenderSystem.disableTexture();
- bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
- bufferbuilder.pos(this.x0, this.y0 + 4, 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 0).endVertex();
- bufferbuilder.pos(this.x1, this.y0 + 4, 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 0).endVertex();
- bufferbuilder.pos(this.x1, this.y0, 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(this.x0, this.y0, 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(this.x0, this.y1, 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(this.x1, this.y1, 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(this.x1, this.y1 - 4, 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 0).endVertex();
- bufferbuilder.pos(this.x0, this.y1 - 4, 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 0).endVertex();
- tessellator.draw();
- int k1 = Math.max(0, this.getMaxPosition() - (this.y1 - this.y0 - 4));
+ bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
+ bufferbuilder.vertex(matrixStack.last().pose(),getLeft(), getTop() + 4, 0).uv(0.0F, 1.0F).color(0, 0, 0, 0).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getRight(), getTop() + 4, 0).uv(1.0F, 1.0F).color(0, 0, 0, 0).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getRight(), getTop(), 0).uv(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getLeft(), getTop(), 0).uv(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getLeft(), getBottom(), 0).uv(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getRight(), getBottom(), 0).uv(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getRight(), getBottom() - 4, 0).uv(1.0F, 0.0F).color(0, 0, 0, 0).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(),getLeft(), getBottom() - 4, 0).uv(0.0F, 0.0F).color(0, 0, 0, 0).endVertex();
+ bufferbuilder.end();
+ BufferUploader.end(bufferbuilder);
+ int k1 = Math.max(0, this.getMaxPosition() - (getBottom() - getTop() - 4));
if (k1 > 0) {
- int l1 = (int) ((float) ((this.y1 - this.y0) * (this.y1 - this.y0)) / (float) this.getMaxPosition());
- l1 = MathHelper.clamp(l1, 32, this.y1 - this.y0 - 8);
- int i2 = (int) this.getScrollAmount() * (this.y1 - this.y0 - l1) / k1 + this.y0;
- if (i2 < this.y0) {
- i2 = this.y0;
+ int l1 = (int) ((float) ((getBottom() - getTop()) * (getBottom() - getTop())) / (float) this.getMaxPosition());
+ l1 = Mth.clamp(l1, 32, getBottom() - getTop() - 8);
+ int i2 = (int) this.getScrollAmount() * (getBottom() - getTop() - l1) / k1 + getTop();
+ if (i2 < getTop()) {
+ i2 = getTop();
}
- bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
- bufferbuilder.pos(i, this.y1, 0.0D).tex(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(j, this.y1, 0.0D).tex(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(j, this.y0, 0.0D).tex(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(i, this.y0, 0.0D).tex(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
- bufferbuilder.pos(i, i2 + l1, 0.0D).tex(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
- bufferbuilder.pos(j, i2 + l1, 0.0D).tex(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
- bufferbuilder.pos(j, i2, 0.0D).tex(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
- bufferbuilder.pos(i, i2, 0.0D).tex(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
- bufferbuilder.pos(i, i2 + l1 - 1, 0.0D).tex(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
- bufferbuilder.pos(j - 1, i2 + l1 - 1, 0.0D).tex(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
- bufferbuilder.pos(j - 1, i2, 0.0D).tex(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
- bufferbuilder.pos(i, i2, 0.0D).tex(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
- tessellator.draw();
+ bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
+ bufferbuilder.vertex(matrixStack.last().pose(), i, getBottom(), 0).uv(0.0F, 1.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), j, getBottom(), 0).uv(1.0F, 1.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), j, getTop(), 0).uv(1.0F, 0.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), i, getTop(), 0).uv(0.0F, 0.0F).color(0, 0, 0, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), i, i2 + l1, 0).uv(0.0F, 1.0F).color(128, 128, 128, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), j, i2 + l1, 0).uv(1.0F, 1.0F).color(128, 128, 128, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), j, i2, 0).uv(1.0F, 0.0F).color(128, 128, 128, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), i, i2, 0).uv(0.0F, 0.0F).color(128, 128, 128, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), i, i2 + l1 - 1, 0).uv(0.0F, 1.0F).color(192, 192, 192, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), j - 1, i2 + l1 - 1, 0).uv(1.0F, 1.0F).color(192, 192, 192, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), j - 1, i2, 0).uv(1.0F, 0.0F).color(192, 192, 192, 255).endVertex();
+ bufferbuilder.vertex(matrixStack.last().pose(), i, i2, 0).uv(0.0F, 0.0F).color(192, 192, 192, 255).endVertex();
+ bufferbuilder.end();
+ BufferUploader.end(bufferbuilder);
}
this.renderDecorations(matrixStack, mouseX, mouseY);
RenderSystem.enableTexture();
- RenderSystem.shadeModel(7424);
- RenderSystem.enableAlphaTest();
RenderSystem.disableBlend();
}
- public class LangEntry extends ExtendedList.AbstractListEntry {
+ @Override
+ public void updateNarration(@NotNull NarrationElementOutput pNarrationElementOutput) {
+ }
+
+ @Override
+ public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
+ return super.mouseScrolled(mouseX, mouseY, delta);
+ }
+ @Override
+ public boolean isFocused() {
+ return this.getFocused() != null;
+ }
+
+ @Override
+ public void setFocused(@Nullable GuiEventListener listener) {
+ super.setFocused(listener);
+ }
+
+ public class LangEntry extends ObjectSelectionList.Entry {
private final Language lang;
private final String langName;
@@ -153,25 +175,29 @@ public LangEntry(Language lang) {
@SuppressWarnings("NullableProblems")
@Override
- public void render(MatrixStack stack, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean p_194999_5_, float partialTicks) {
+ public void render(PoseStack stack, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean p_194999_5_, float partialTicks) {
//font.setBidiFlag(true);
- if (top + 1 < getBottom() && getTop() < top + 1)
+// if (top + 1 < getBottom() && getTop() < top + 1)
drawString(stack, font, this.langName, left + 5, top + 1, 16777215);
}
//Undocumented parameter names are fun!
@Override
- public boolean mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_, int p_mouseClicked_5_) {
- if (p_mouseClicked_5_ == 0) {
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
+ if (button == 0) {
LangList.this.setSelected(this);
return true;
- } else {
- return false;
}
+ return false;
}
public Language getLang() {
return lang;
}
+
+ @Override
+ public Component getNarration() {
+ return new TextComponent(langName);
+ }
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/LanguageSelectGui.java b/src/main/java/com/ringosham/translationmod/gui/LanguageSelectGui.java
index 7234211..44bc9ce 100644
--- a/src/main/java/com/ringosham/translationmod/gui/LanguageSelectGui.java
+++ b/src/main/java/com/ringosham/translationmod/gui/LanguageSelectGui.java
@@ -1,13 +1,13 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.vertex.PoseStack;
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.client.LangManager;
import com.ringosham.translationmod.client.types.Language;
import com.ringosham.translationmod.common.ConfigManager;
import com.ringosham.translationmod.translate.Retranslate;
-import net.minecraft.client.gui.widget.button.Button;
-import net.minecraft.util.text.StringTextComponent;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.network.chat.TextComponent;
import net.minecraftforge.fml.ModList;
public class LanguageSelectGui extends CommonGui {
@@ -46,9 +46,9 @@ public class LanguageSelectGui extends CommonGui {
}
@Override
- public void render(MatrixStack stack, int x, int y, float tick) {
+ public void render(PoseStack stack, int x, int y, float tick) {
super.render(stack, x, y, tick);
- font.drawString(stack, title, getLeftMargin(), getTopMargin(), 0x555555);
+ font.draw(stack, title, getLeftMargin(), getTopMargin(), 0x555555);
langList.render(stack, x, y, tick);
}
@@ -56,8 +56,8 @@ public void render(MatrixStack stack, int x, int y, float tick) {
public void init() {
langList = new LangList(getMinecraft(), font, guiWidth - 18, guiHeight - 48, getYOrigin() + 15, getYOrigin() + guiHeight - 10 - regularButtonHeight, 18);
langList.setLeftPos(getLeftMargin());
- this.children.add(langList);
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new StringTextComponent("Select language"),
+ addRenderableWidget(langList);
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new TextComponent("Select language"),
(button) -> {
if (langList.getSelected() != null) {
if (config != null)
@@ -66,23 +66,31 @@ public void init() {
this.retranslate(langList.getSelected().getLang());
}
}));
- addButton(new Button(getLeftMargin(), getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new StringTextComponent("Back"),
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + guiHeight - regularButtonHeight - 5, regularButtonWidth, regularButtonHeight, new TextComponent("Back"),
(button) -> {
if (config != null)
this.selectLanguage(null);
else
- getMinecraft().displayGuiScreen(new RetranslateGui());
+ getMinecraft().setScreen(new RetranslateGui());
}));
}
@SuppressWarnings("ConstantConditions")
private void selectLanguage(Language lang) {
- getMinecraft().displayGuiScreen(new ConfigGui(config, langSelect, lang));
+ getMinecraft().setScreen(new ConfigGui(config, langSelect, lang));
}
private void retranslate(Language source) {
Thread retranslate = new Retranslate(sender, message, source, LangManager.getInstance().findLanguageFromName(ConfigManager.config.targetLanguage.get()));
retranslate.start();
- getMinecraft().displayGuiScreen(null);
+ getMinecraft().setScreen(null);
+ }
+
+ @Override
+ public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
+ if (langList.isMouseOver(pMouseX, pMouseY)) {
+ return langList.mouseScrolled(pMouseX, pMouseY, pDelta);
+ }
+ return super.mouseScrolled(pMouseX, pMouseY, pDelta);
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/RegexGui.java b/src/main/java/com/ringosham/translationmod/gui/RegexGui.java
index 9351d84..9c2543c 100644
--- a/src/main/java/com/ringosham/translationmod/gui/RegexGui.java
+++ b/src/main/java/com/ringosham/translationmod/gui/RegexGui.java
@@ -18,23 +18,25 @@
package com.ringosham.translationmod.gui;
import com.google.common.primitives.Ints;
-import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.blaze3d.vertex.PoseStack;
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.common.ChatUtil;
import com.ringosham.translationmod.common.ConfigManager;
+import com.ringosham.translationmod.mixin.ChatComponentField;
+import net.minecraft.ChatFormatting;
+import net.minecraft.Util;
+import net.minecraft.client.GuiMessage;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.ChatLine;
-import net.minecraft.client.gui.NewChatGui;
-import net.minecraft.client.gui.screen.ConfirmOpenLinkScreen;
-import net.minecraft.client.gui.widget.TextFieldWidget;
-import net.minecraft.client.gui.widget.button.Button;
-import net.minecraft.util.Util;
-import net.minecraft.util.text.ITextComponent;
-import net.minecraft.util.text.StringTextComponent;
-import net.minecraft.util.text.TextFormatting;
-import net.minecraft.util.text.TranslationTextComponent;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.client.gui.components.ChatComponent;
+import net.minecraft.client.gui.components.EditBox;
+import net.minecraft.client.gui.screens.ConfirmLinkScreen;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TextComponent;
+import net.minecraft.network.chat.TranslatableComponent;
import net.minecraftforge.fml.ModList;
-import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
+import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
@@ -51,8 +53,8 @@ public class RegexGui extends CommonGui {
private static final String testMessage = "Notch --> English: Hello!";
private static final int guiWidth = 400;
private static final int guiHeight = 230;
- private static final List cheatsheet;
- private static final List> cheatsheetDesc;
+ private static final List cheatsheet;
+ private static final List> cheatsheetDesc;
private static final String regexTest = "https://regexr.com";
private static final String title;
@@ -67,80 +69,80 @@ public class RegexGui extends CommonGui {
cheatsheetDesc = new ArrayList<>();
for (int i = 0; i < 12; i++)
cheatsheetDesc.add(new ArrayList<>());
- cheatsheet.add(new StringTextComponent(". - Matches any character"));
- cheatsheetDesc.get(0).add(new StringTextComponent("Matches any character"));
- cheatsheetDesc.get(0).add(new StringTextComponent("The only exception is the newline character (\\n)"));
- cheatsheetDesc.get(0).add(new StringTextComponent("Newlines are not used in chat so it doesn't matter"));
-
- cheatsheet.add(new StringTextComponent("\\w - Matches word"));
- cheatsheetDesc.get(1).add(new StringTextComponent("Matches all alphabets (Both capital and small), numbers and underscore"));
- cheatsheetDesc.get(1).add(new StringTextComponent("Minecraft usernames are based on words. They are perfect to detect player names"));
-
- cheatsheet.add(new StringTextComponent("\\d - Digit"));
- cheatsheetDesc.get(2).add(new StringTextComponent("Matches all numbers"));
-
- cheatsheet.add(new StringTextComponent("[a-g] - Match character in range"));
- cheatsheetDesc.get(3).add(new StringTextComponent("Matches any characters in tis specific range"));
- cheatsheetDesc.get(3).add(new StringTextComponent("Example: [a-g]"));
- cheatsheetDesc.get(3).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "a"));
- cheatsheetDesc.get(3).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "b"));
- cheatsheetDesc.get(3).add(new StringTextComponent("\u2717 " + TextFormatting.RED + "z"));
-
- cheatsheet.add(new StringTextComponent("* - Matches 0 or more"));
- cheatsheetDesc.get(4).add(new StringTextComponent("Matches 0 or more of its character class"));
- cheatsheetDesc.get(4).add(new StringTextComponent("Example: N\\w*"));
- cheatsheetDesc.get(4).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "N"));
- cheatsheetDesc.get(4).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "No"));
- cheatsheetDesc.get(4).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "Notch"));
-
- cheatsheet.add(new StringTextComponent("+ - Matches 1 or more"));
- cheatsheetDesc.get(5).add(new StringTextComponent("Matches 1 or more of a character/group"));
- cheatsheetDesc.get(5).add(new StringTextComponent("Example: N\\w+"));
- cheatsheetDesc.get(5).add(new StringTextComponent("\u2717 " + TextFormatting.RED + "N"));
- cheatsheetDesc.get(5).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "No"));
- cheatsheetDesc.get(5).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "Notch"));
-
- cheatsheet.add(new StringTextComponent("? - Optional"));
- cheatsheetDesc.get(6).add(new StringTextComponent("Exactly as the name suggests"));
- cheatsheetDesc.get(6).add(new StringTextComponent("Example: (VIP )?\\w+"));
- cheatsheetDesc.get(6).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "VIP PlayerName"));
- cheatsheetDesc.get(6).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "PlayerName"));
-
- cheatsheet.add(new StringTextComponent("{2,} - Matches n or more"));
- cheatsheetDesc.get(7).add(new StringTextComponent("Matches a group/character n times or more"));
- cheatsheetDesc.get(7).add(new StringTextComponent("Add a number after the comma if you want the it match x to y times"));
- cheatsheetDesc.get(7).add(new StringTextComponent("Or omit the comma if you want the it match exactly n times"));
- cheatsheetDesc.get(7).add(new StringTextComponent("Example: Level \\d{1,3}"));
- cheatsheetDesc.get(7).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "Level 1"));
- cheatsheetDesc.get(7).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "Level 420"));
- cheatsheetDesc.get(7).add(new StringTextComponent("\u2717 " + TextFormatting.RED + "Level 42069"));
-
-
- cheatsheet.add(new StringTextComponent("| - Either"));
- cheatsheetDesc.get(8).add(new StringTextComponent("Must match either of them, but not both."));
- cheatsheetDesc.get(8).add(new StringTextComponent("Example: (Dead)|(Alive) (\\w+)"));
- cheatsheetDesc.get(8).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "Dead PlayerName"));
- cheatsheetDesc.get(8).add(new StringTextComponent("\u2713 " + TextFormatting.GREEN + "Alive PlayerName"));
- cheatsheetDesc.get(8).add(new StringTextComponent("\u2717 " + TextFormatting.RED + "DeadAlive PlayerName"));
-
- cheatsheet.add(new StringTextComponent("() - Group"));
- cheatsheetDesc.get(9).add(new StringTextComponent("Think of groups as parentheses like in mathematics"));
- cheatsheetDesc.get(9).add(new StringTextComponent("They also have a second function. Capture groups."));
- cheatsheetDesc.get(9).add(new StringTextComponent("By specifying the group number below, the mod can know which group"));
- cheatsheetDesc.get(9).add(new StringTextComponent(" contains the player's username"));
-
- cheatsheet.add(new StringTextComponent("\\ - Escape character"));
- cheatsheetDesc.get(10).add(new StringTextComponent("If you need to capture special characters mentioned in this list,"));
- cheatsheetDesc.get(10).add(new StringTextComponent(" you will need to add an extra backslash to escape them."));
- cheatsheetDesc.get(10).add(new StringTextComponent("Correct:" + TextFormatting.GREEN + " \\(VIP\\) \\w+"));
- cheatsheetDesc.get(10).add(new StringTextComponent("Wrong:" + TextFormatting.RED + " (VIP) \\w+"));
+ cheatsheet.add(new TextComponent(". - Matches any character"));
+ cheatsheetDesc.get(0).add(new TextComponent("Matches any character"));
+ cheatsheetDesc.get(0).add(new TextComponent("The only exception is the newline character (\\n)"));
+ cheatsheetDesc.get(0).add(new TextComponent("Newlines are not used in chat so it doesn't matter"));
+
+ cheatsheet.add(new TextComponent("\\w - Matches word"));
+ cheatsheetDesc.get(1).add(new TextComponent("Matches all alphabets (Both capital and small), numbers and underscore"));
+ cheatsheetDesc.get(1).add(new TextComponent("Minecraft usernames are based on words. They are perfect to detect player names"));
+
+ cheatsheet.add(new TextComponent("\\d - Digit"));
+ cheatsheetDesc.get(2).add(new TextComponent("Matches all numbers"));
+
+ cheatsheet.add(new TextComponent("[a-g] - Match character in range"));
+ cheatsheetDesc.get(3).add(new TextComponent("Matches any characters in tis specific range"));
+ cheatsheetDesc.get(3).add(new TextComponent("Example: [a-g]"));
+ cheatsheetDesc.get(3).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "a"));
+ cheatsheetDesc.get(3).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "b"));
+ cheatsheetDesc.get(3).add(new TextComponent("\u2717 " + ChatFormatting.RED + "z"));
+
+ cheatsheet.add(new TextComponent("* - Matches 0 or more"));
+ cheatsheetDesc.get(4).add(new TextComponent("Matches 0 or more of its character class"));
+ cheatsheetDesc.get(4).add(new TextComponent("Example: N\\w*"));
+ cheatsheetDesc.get(4).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "N"));
+ cheatsheetDesc.get(4).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "No"));
+ cheatsheetDesc.get(4).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "Notch"));
+
+ cheatsheet.add(new TextComponent("+ - Matches 1 or more"));
+ cheatsheetDesc.get(5).add(new TextComponent("Matches 1 or more of a character/group"));
+ cheatsheetDesc.get(5).add(new TextComponent("Example: N\\w+"));
+ cheatsheetDesc.get(5).add(new TextComponent("\u2717 " + ChatFormatting.RED + "N"));
+ cheatsheetDesc.get(5).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "No"));
+ cheatsheetDesc.get(5).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "Notch"));
+
+ cheatsheet.add(new TextComponent("? - Optional"));
+ cheatsheetDesc.get(6).add(new TextComponent("Exactly as the name suggests"));
+ cheatsheetDesc.get(6).add(new TextComponent("Example: (VIP )?\\w+"));
+ cheatsheetDesc.get(6).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "VIP PlayerName"));
+ cheatsheetDesc.get(6).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "PlayerName"));
+
+ cheatsheet.add(new TextComponent("{2,} - Matches n or more"));
+ cheatsheetDesc.get(7).add(new TextComponent("Matches a group/character n times or more"));
+ cheatsheetDesc.get(7).add(new TextComponent("Add a number after the comma if you want the it match x to y times"));
+ cheatsheetDesc.get(7).add(new TextComponent("Or omit the comma if you want the it match exactly n times"));
+ cheatsheetDesc.get(7).add(new TextComponent("Example: Level \\d{1,3}"));
+ cheatsheetDesc.get(7).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "Level 1"));
+ cheatsheetDesc.get(7).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "Level 420"));
+ cheatsheetDesc.get(7).add(new TextComponent("\u2717 " + ChatFormatting.RED + "Level 42069"));
+
+
+ cheatsheet.add(new TextComponent("| - Either"));
+ cheatsheetDesc.get(8).add(new TextComponent("Must match either of them, but not both."));
+ cheatsheetDesc.get(8).add(new TextComponent("Example: (Dead)|(Alive) (\\w+)"));
+ cheatsheetDesc.get(8).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "Dead PlayerName"));
+ cheatsheetDesc.get(8).add(new TextComponent("\u2713 " + ChatFormatting.GREEN + "Alive PlayerName"));
+ cheatsheetDesc.get(8).add(new TextComponent("\u2717 " + ChatFormatting.RED + "DeadAlive PlayerName"));
+
+ cheatsheet.add(new TextComponent("() - Group"));
+ cheatsheetDesc.get(9).add(new TextComponent("Think of groups as parentheses like in mathematics"));
+ cheatsheetDesc.get(9).add(new TextComponent("They also have a second function. Capture groups."));
+ cheatsheetDesc.get(9).add(new TextComponent("By specifying the group number below, the mod can know which group"));
+ cheatsheetDesc.get(9).add(new TextComponent(" contains the player's username"));
+
+ cheatsheet.add(new TextComponent("\\ - Escape character"));
+ cheatsheetDesc.get(10).add(new TextComponent("If you need to capture special characters mentioned in this list,"));
+ cheatsheetDesc.get(10).add(new TextComponent(" you will need to add an extra backslash to escape them."));
+ cheatsheetDesc.get(10).add(new TextComponent("Correct:" + ChatFormatting.GREEN + " \\(VIP\\) \\w+"));
+ cheatsheetDesc.get(10).add(new TextComponent("Wrong:" + ChatFormatting.RED + " (VIP) \\w+"));
}
private int index;
private final LinkedList regexes = new LinkedList<>();
private final LinkedList groups = new LinkedList<>();
- private TextFieldWidget regexTextBox;
- private TextFieldWidget groupTextBox;
+ private EditBox regexTextBox;
+ private EditBox groupTextBox;
{
regexes.addAll(ConfigManager.config.regexList.get());
@@ -150,171 +152,216 @@ public class RegexGui extends CommonGui {
RegexGui() {
super(title, guiHeight, guiWidth);
+ index = Math.max(regexes.size() - 1, 0);
+ if(regexes.isEmpty()) {
+ regexes.add(ConfigManager.defaultRegex[0]);
+ groups.clear();
+ groups.add(1);
+ }
}
@Override
- public void render(MatrixStack stack, int x, int y, float tick) {
+ public void render(PoseStack stack, int x, int y, float tick) {
super.render(stack, x, y, tick);
drawStringLine(stack, title, new String[]{
"Regex(Regular expression) are search patterns used to detect messages.",
"You can use this website to test your regex.",
"Cheatsheet: (Hover your mouse to see explanation)",
}, 0);
- font.drawString(stack, "TIP: Combine classes and quantifiers together to match several characters", getLeftMargin(), getYOrigin() + guiHeight - 40, 0x555555);
- font.drawString(stack, (index + 1) + " of " + Math.max(index + 1, regexes.size()), getLeftMargin() + 15 + smallButtonLength * 2, getYOrigin() + guiHeight - regularButtonHeight, 0x555555);
- String regex = regexTextBox.getText();
- int group = groupTextBox.getText().isEmpty() ? -1 : Integer.parseInt(groupTextBox.getText());
+ font.draw(stack, "TIP: Combine classes and quantifiers together to match several characters", getLeftMargin(), getYOrigin() + guiHeight - 40, 0x555555);
+ font.draw(stack, (index + 1) + " of " + Math.max(index + 1, regexes.size()), getLeftMargin() + 15 + smallButtonLength * 2, getYOrigin() + guiHeight - regularButtonHeight, 0x555555);
+ String regex = regexTextBox.getValue();
+ int group = groupTextBox.getValue().isEmpty() ? -1 : Integer.parseInt(groupTextBox.getValue());
if (validateRegex(regex)) {
if (!isRegexConflict(regex)) {
int groupCount = countGroups(regex);
if (groupCount == 0)
- font.drawString(stack, TextFormatting.YELLOW + "Regex valid, but it needs at least 1 group to detect player names", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
+ font.draw(stack, ChatFormatting.YELLOW + "Regex valid, but it needs at least 1 group to detect player names", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
else
- font.drawString(stack, TextFormatting.GREEN + "Regex valid! The regex should stop at before the message content", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
- font.drawString(stack, "Possible match: " + findMatch(getChatLog(), regex), getLeftMargin(), getYOrigin() + guiHeight - 110, 0x555555);
+ font.draw(stack, ChatFormatting.GREEN + "Regex valid! The regex should stop at before the message content", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
+ font.draw(stack, "Possible match: " + findMatch(getChatLog(), regex), getLeftMargin(), getYOrigin() + guiHeight - 110, 0x555555);
if (groupCount > 0)
- font.drawString(stack, "Group number: (1 - " + groupCount + ")", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
+ font.draw(stack, "Group number: (1 - " + groupCount + ")", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
else
- font.drawString(stack, "Group number: (?)", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
- font.drawString(stack, "Matching username: " + matchUsername(findMatch(getChatLog(), regex), regex, group), getLeftMargin(), getYOrigin() + guiHeight - 70, 0x555555);
+ font.draw(stack, "Group number: (?)", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
+ font.draw(stack, "Matching username: " + matchUsername(findMatch(getChatLog(), regex), regex, group), getLeftMargin(), getYOrigin() + guiHeight - 70, 0x555555);
} else {
- font.drawString(stack, TextFormatting.RED + "Regex conflict with the mod messages! Please be more specific", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
- font.drawString(stack, "Possible match: ---", getLeftMargin(), getYOrigin() + guiHeight - 110, 0x555555);
- font.drawString(stack, "Matching username: ---", getLeftMargin(), getYOrigin() + guiHeight - 70, 0x555555);
- font.drawString(stack, "Group number: (?)", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
+ font.draw(stack, ChatFormatting.RED + "Regex conflict with the mod messages! Please be more specific", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
+ font.draw(stack, "Possible match: ---", getLeftMargin(), getYOrigin() + guiHeight - 110, 0x555555);
+ font.draw(stack, "Matching username: ---", getLeftMargin(), getYOrigin() + guiHeight - 70, 0x555555);
+ font.draw(stack, "Group number: (?)", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
}
} else {
- font.drawString(stack, TextFormatting.RED + "Regex invalid! Please check your syntax", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
- font.drawString(stack, "Possible match: ---", getLeftMargin(), getYOrigin() + guiHeight - 110, 0x555555);
- font.drawString(stack, "Matching username: ---", getLeftMargin(), getYOrigin() + guiHeight - 70, 0x555555);
- font.drawString(stack, "Group number: (?)", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
+ font.draw(stack, ChatFormatting.RED + "Regex invalid! Please check your syntax", getLeftMargin(), getYOrigin() + guiHeight - 120, 0x555555);
+ font.draw(stack, "Possible match: ---", getLeftMargin(), getYOrigin() + guiHeight - 110, 0x555555);
+ font.draw(stack, "Matching username: ---", getLeftMargin(), getYOrigin() + guiHeight - 70, 0x555555);
+ font.draw(stack, "Group number: (?)", getLeftMargin(), getYOrigin() + guiHeight - 80, 0x555555);
}
regexTextBox.render(stack, x, y, tick);
groupTextBox.render(stack, x, y, tick);
//Draw tooltips
- for (int i = 5; i < this.buttons.size(); i++) {
- HoveringText button = (HoveringText) this.buttons.get(i);
- if (button.isHovered())
- //func_243308_b(MatrixStack, List, int, int) -> renderTooltip(...)
- func_243308_b(stack, button.getHoverText(), x, y);
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button) {
+ if(j >= 5){
+ HoveringText button = (HoveringText) renderables.get(i);
+ if (button.isHoveredOrFocused())
+ //func_243308_b(PoseStack, List, int, int) -> renderTooltip(...)
+ renderComponentTooltip(stack, button.getHoverText(), x, y);
+ }
+ j++;
+ }
}
}
@Override
public void init() {
- regexTextBox = new TextFieldWidget(this.font, getLeftMargin(), getYOrigin() + guiHeight - 100, guiWidth - 10, 15, new StringTextComponent(""));
+ regexTextBox = new EditBox(this.font, getLeftMargin(), getYOrigin() + guiHeight - 100, guiWidth - 10, 15, new TextComponent(""));
regexTextBox.setCanLoseFocus(true);
- regexTextBox.setMaxStringLength(200);
- regexTextBox.setEnableBackgroundDrawing(true);
- regexTextBox.setText(regexes.get(index));
- groupTextBox = new TextFieldWidget(this.font, getLeftMargin(), getYOrigin() + guiHeight - 60, guiWidth - 10, 15, new StringTextComponent(""));
+ regexTextBox.setMaxLength(200);
+ regexTextBox.setBordered(true);
+ regexTextBox.setValue(regexes.get(index));
+ groupTextBox = new EditBox(this.font, getLeftMargin(), getYOrigin() + guiHeight - 60, guiWidth - 10, 15, new TextComponent(""));
groupTextBox.setCanLoseFocus(true);
- groupTextBox.setMaxStringLength(10);
- groupTextBox.setEnableBackgroundDrawing(true);
- groupTextBox.setText(Integer.toString(groups.get(index)));
- this.children.add(groupTextBox);
- this.children.add(regexTextBox);
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- addButton(new TextButton(getRightMargin(150), getYOrigin() + 25, getTextWidth(regexTest), new StringTextComponent(regexTest),
+ groupTextBox.setMaxLength(10);
+ groupTextBox.setBordered(true);
+ groupTextBox.setValue(Integer.toString(groups.get(index)));
+ addRenderableWidget(groupTextBox);
+ addRenderableWidget(regexTextBox);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ addRenderableWidget(new TextButton(getRightMargin(150), getYOrigin() + 25, getTextWidth(regexTest), new TextComponent(regexTest),
(button) -> this.openLink(), 0x0000aa));
- addButton(new Button(getLeftMargin() + 5 + smallButtonLength, getYOrigin() + guiHeight - 5 - regularButtonHeight, smallButtonLength, smallButtonLength, new StringTextComponent("+"),
+ addRenderableWidget(new Button(getLeftMargin() + 5 + smallButtonLength, getYOrigin() + guiHeight - 5 - regularButtonHeight, smallButtonLength, smallButtonLength, new TextComponent("+"),
this::nextPage));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new StringTextComponent("Save and close"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new TextComponent("Save and close"),
(button) -> this.applySettings()));
- addButton(new Button(getLeftMargin(), getYOrigin() + guiHeight - 5 - regularButtonHeight, smallButtonLength, smallButtonLength, new StringTextComponent("<"),
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + guiHeight - 5 - regularButtonHeight, smallButtonLength, smallButtonLength, new TextComponent("<"),
this::previousPage));
- addButton(new Button(getRightMargin(regularButtonWidth) - 5 - regularButtonWidth, getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new StringTextComponent("Reset to default"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth) - 5 - regularButtonWidth, getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new TextComponent("Reset to default"),
(button) -> this.resetDefault()));
//Needs to be cleared since resizing the window calls initGui() again
- addButton(new HoveringText(getLeftMargin(), getYOrigin() + 45, cheatsheet.get(0), cheatsheetDesc.get(0)));
- addButton(new HoveringText(getLeftMargin(), getYOrigin() + 55, cheatsheet.get(1), cheatsheetDesc.get(1)));
- addButton(new HoveringText(getLeftMargin(), getYOrigin() + 65, cheatsheet.get(2), cheatsheetDesc.get(2)));
- addButton(new HoveringText(getLeftMargin(), getYOrigin() + 75, cheatsheet.get(3), cheatsheetDesc.get(3)));
- addButton(new HoveringText(getLeftMargin(), getYOrigin() + 85, cheatsheet.get(4), cheatsheetDesc.get(4)));
- addButton(new HoveringText(getLeftMargin(), getYOrigin() + 95, cheatsheet.get(5), cheatsheetDesc.get(5)));
- addButton(new HoveringText(getLeftMargin() + 210, getYOrigin() + 45, cheatsheet.get(6), cheatsheetDesc.get(6)));
- addButton(new HoveringText(getLeftMargin() + 210, getYOrigin() + 55, cheatsheet.get(7), cheatsheetDesc.get(7)));
- addButton(new HoveringText(getLeftMargin() + 210, getYOrigin() + 65, cheatsheet.get(8), cheatsheetDesc.get(8)));
- addButton(new HoveringText(getLeftMargin() + 210, getYOrigin() + 75, cheatsheet.get(9), cheatsheetDesc.get(9)));
- addButton(new HoveringText(getLeftMargin() + 210, getYOrigin() + 85, cheatsheet.get(10), cheatsheetDesc.get(10)));
+ addRenderableWidget(new HoveringText(getLeftMargin(), getYOrigin() + 45, cheatsheet.get(0), cheatsheetDesc.get(0)));
+ addRenderableWidget(new HoveringText(getLeftMargin(), getYOrigin() + 55, cheatsheet.get(1), cheatsheetDesc.get(1)));
+ addRenderableWidget(new HoveringText(getLeftMargin(), getYOrigin() + 65, cheatsheet.get(2), cheatsheetDesc.get(2)));
+ addRenderableWidget(new HoveringText(getLeftMargin(), getYOrigin() + 75, cheatsheet.get(3), cheatsheetDesc.get(3)));
+ addRenderableWidget(new HoveringText(getLeftMargin(), getYOrigin() + 85, cheatsheet.get(4), cheatsheetDesc.get(4)));
+ addRenderableWidget(new HoveringText(getLeftMargin(), getYOrigin() + 95, cheatsheet.get(5), cheatsheetDesc.get(5)));
+ addRenderableWidget(new HoveringText(getLeftMargin() + 210, getYOrigin() + 45, cheatsheet.get(6), cheatsheetDesc.get(6)));
+ addRenderableWidget(new HoveringText(getLeftMargin() + 210, getYOrigin() + 55, cheatsheet.get(7), cheatsheetDesc.get(7)));
+ addRenderableWidget(new HoveringText(getLeftMargin() + 210, getYOrigin() + 65, cheatsheet.get(8), cheatsheetDesc.get(8)));
+ addRenderableWidget(new HoveringText(getLeftMargin() + 210, getYOrigin() + 75, cheatsheet.get(9), cheatsheetDesc.get(9)));
+ addRenderableWidget(new HoveringText(getLeftMargin() + 210, getYOrigin() + 85, cheatsheet.get(10), cheatsheetDesc.get(10)));
}
private void openLink() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(new ConfirmOpenLinkScreen((ConfirmOpen) -> {
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(new ConfirmLinkScreen((ConfirmOpen) -> {
if (ConfirmOpen)
- Util.getOSType().openURI(regexTest);
- getMinecraft().displayGuiScreen(this);
+ Util.getPlatform().openUri(regexTest);
+ getMinecraft().setScreen(this);
}, regexTest, false));
- getMinecraft().keyboardListener.enableRepeatEvents(true);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
}
private void nextPage(Button button) {
- regexes.set(index, regexTextBox.getText());
- if (groupTextBox.getText().trim().isEmpty())
+ regexes.set(index, regexTextBox.getValue());
+ if (groupTextBox.getValue().trim().isEmpty())
groups.set(index, 0);
else
- groups.set(index, Integer.parseInt(groupTextBox.getText()));
+ groups.set(index, Integer.parseInt(groupTextBox.getValue()));
index++;
if (index == regexes.size()) {
button.active = false;
regexes.add("");
groups.add(1);
- regexTextBox.setText("");
- groupTextBox.setText("1");
+ regexTextBox.setValue("");
+ groupTextBox.setValue("1");
} else {
- regexTextBox.setText(regexes.get(index));
- groupTextBox.setText(groups.get(index).toString());
- button.setMessage(new StringTextComponent(">"));
+ regexTextBox.setValue(regexes.get(index));
+ groupTextBox.setValue(groups.get(index).toString());
+ button.setMessage(new TextComponent(">"));
button.active = true;
}
if (index >= regexes.size() - 1)
- button.setMessage(new StringTextComponent("+"));
- this.buttons.get(3).active = true;
- regexTextBox.setCursorPositionEnd();
- getMinecraft().keyboardListener.enableRepeatEvents(true);
+ button.setMessage(new TextComponent("+"));
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button button1){
+ if(j == 3){
+ button1.active = true;
+ break;
+ }
+ j++;
+ }
+ }
+ regexTextBox.moveCursorToEnd();
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
}
private void previousPage(Button button) {
//Discard changes if the textboxes are empty.
- if (regexTextBox.getText().trim().isEmpty() || groupTextBox.getText().isEmpty()) {
+ if (regexTextBox.getValue().trim().isEmpty() || groupTextBox.getValue().isEmpty()) {
regexes.remove(index);
groups.remove(index);
} else {
- regexes.set(index, regexTextBox.getText());
- groups.set(index, Integer.parseInt(groupTextBox.getText()));
+ regexes.set(index, regexTextBox.getValue());
+ groups.set(index, Integer.parseInt(groupTextBox.getValue()));
}
index--;
if (index == 0)
button.active = false;
- if (regexes.size() - 1 == index)
- this.buttons.get(1).setMessage(new StringTextComponent("+"));
- else
- this.buttons.get(1).setMessage(new StringTextComponent(">"));
- this.buttons.get(1).active = true;
- regexTextBox.setText(regexes.get(index));
- groupTextBox.setText(groups.get(index).toString());
- regexTextBox.setCursorPositionEnd();
- getMinecraft().keyboardListener.enableRepeatEvents(true);
+ Button button1 = null;
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button){
+ if(j == 1) {
+ button1 = (Button)renderables.get(i);
+ button1.active = true;
+ break;
+ }
+ j++;
+ }
+ }
+ if(button1 != null){
+ if (regexes.size() - 1 == index)
+ button1.setMessage(new TextComponent("+"));
+ else
+ button1.setMessage(new TextComponent(">"));
+ button1.active = true;
+ }
+
+ regexTextBox.setValue(regexes.get(index));
+ groupTextBox.setValue(groups.get(index).toString());
+ regexTextBox.moveCursorToEnd();
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
}
private void resetDefault() {
- this.buttons.get(3).active = true;
- this.buttons.get(1).setMessage(new StringTextComponent("+"));
+ Button button1 = null;
+ Button button3 = null;
+ for (int i = 0, j = 0; i < renderables.size(); i++) {
+ if(renderables.get(i) instanceof Button){
+ if(j == 1) button1 = (Button)renderables.get(i);
+ if(j == 3) {
+ button3 = (Button)renderables.get(i);
+ break;
+ }
+ j++;
+ }
+ }
+ if(button3 != null) button3.active = true;
+ if(button1 != null) button1.setMessage(new TextComponent("+"));
regexes.clear();
regexes.addAll(Arrays.asList(ConfigManager.defaultRegex));
groups.clear();
groups.addAll(Ints.asList(ConfigManager.defaultGroups));
index = regexes.size() - 1;
- regexTextBox.setText(regexes.get(index));
- groupTextBox.setText(groups.get(index).toString());
- regexTextBox.setCursorPositionEnd();
- getMinecraft().keyboardListener.enableRepeatEvents(true);
+ regexTextBox.setValue(regexes.get(index));
+ groupTextBox.setValue(groups.get(index).toString());
+ regexTextBox.moveCursorToEnd();
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
}
private void exitGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(null);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(null);
}
@Override
@@ -322,9 +369,9 @@ public boolean charTyped(char typedchar, int keyCode) {
if (this.groupTextBox.isFocused()) {
if (typedchar >= '0' && typedchar <= '9')
//No group 0 allowed.
- if (this.groupTextBox.getText().isEmpty() && typedchar != 48)
+ if (this.groupTextBox.getValue().isEmpty() && typedchar != 48)
return super.charTyped(typedchar, keyCode);
- else if (!this.groupTextBox.getText().isEmpty())
+ else if (!this.groupTextBox.getValue().isEmpty())
return super.charTyped(typedchar, keyCode);
return false;
}
@@ -334,7 +381,7 @@ else if (!this.groupTextBox.getText().isEmpty())
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifier) {
if (keyCode == GLFW.GLFW_KEY_E && !this.regexTextBox.isFocused()) {
- getMinecraft().displayGuiScreen(null);
+ getMinecraft().setScreen(null);
return false;
}
return super.keyPressed(keyCode, scanCode, modifier);
@@ -373,18 +420,20 @@ private boolean isRegexConflict(String regex) {
@SuppressWarnings("ConstantConditions")
private List getChatLog() {
//Chat log is a private field.
- List> fullChatLog = ObfuscationReflectionHelper.getPrivateValue(NewChatGui.class, Minecraft.getInstance().ingameGUI.getChatGUI(), "field_146252_h");
- //For 1.7.10 debug use.
- //List fullChatLog = ObfuscationReflectionHelper.getPrivateValue(GuiNewChat.class, Minecraft.getInstance().ingameGUI.getChatGUI(), "chatLines");
+ List> fullChatLog;
+ try {
+ fullChatLog = ((ChatComponentField)Minecraft.getInstance().gui.getChat()).getAllMessages();
+ }catch (Exception ignored){
+ fullChatLog = new ArrayList<>();
+ }
List chatLog = new ArrayList<>();
for (int i = 0; i < Math.min(fullChatLog.size(), 20); i++) {
- //func_238169_a_() --> getITextComponent()
- ITextComponent chatLine = fullChatLog.get(i).getLineString();
- if (chatLine instanceof TranslationTextComponent) {
- TranslationTextComponent ttc = (TranslationTextComponent) chatLine;
- chatLog.add(ttc.getString().replaceAll("§(.)", ""));
+ //func_238169_a_() --> getComponent()
+ Component chatLine = fullChatLog.get(i).getMessage();
+ if (chatLine instanceof TranslatableComponent ttc) {
+ chatLog.add(ttc.getString().replaceAll("§(.)", ""));
} else {
- chatLog.add(fullChatLog.get(i).getLineString().getUnformattedComponentText().replaceAll("§(.)", ""));
+ chatLog.add(fullChatLog.get(i).getMessage().getString().replaceAll("§(.)", ""));
}
}
return chatLog;
@@ -399,7 +448,7 @@ private String findMatch(List chatLog, String regex) {
Matcher matcher = pattern.matcher(message);
if (!matcher.find())
continue;
- String matchMessage = TextFormatting.GREEN + matcher.group(0) + TextFormatting.DARK_GRAY + message.replace(matcher.group(0), "");
+ String matchMessage = ChatFormatting.GREEN + matcher.group(0) + ChatFormatting.DARK_GRAY + message.replace(matcher.group(0), "");
String shorten = matchMessage;
for (int i = getTextWidth(matchMessage); i > 120; i--) {
shorten = shorten.substring(0, matchMessage.length() - 1);
@@ -407,25 +456,25 @@ private String findMatch(List chatLog, String regex) {
shorten = shorten + "...";
return matchMessage.length() < shorten.length() ? matchMessage : shorten;
}
- return TextFormatting.RED + "No match from chat log :(";
+ return ChatFormatting.RED + "No match from chat log :(";
}
private String matchUsername(String message, String regex, int group) {
- if (group == -1 || group > countGroups(regex) || message.equals(TextFormatting.RED + "No match from chat log :("))
+ if (group == -1 || group > countGroups(regex) || message.equals(ChatFormatting.RED + "No match from chat log :("))
return "---";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(message);
if (!matcher.find())
- return TextFormatting.RED + "Can't find player username :(";
+ return ChatFormatting.RED + "Can't find player username :(";
return matcher.group(group);
}
private void applySettings() {
- regexes.set(index, regexTextBox.getText());
- if (groupTextBox.getText().trim().isEmpty())
+ regexes.set(index, regexTextBox.getValue());
+ if (groupTextBox.getValue().trim().isEmpty())
groups.set(index, 0);
else
- groups.set(index, Integer.parseInt(groupTextBox.getText()));
+ groups.set(index, Integer.parseInt(groupTextBox.getValue()));
for (int i = 0; i < regexes.size(); i++) {
if (!validateRegex(regexes.get(i)) || isRegexConflict(regexes.get(i))) {
regexes.remove(i);
@@ -444,28 +493,28 @@ private void applySettings() {
ConfigManager.config.groupList.set(groups);
//Let the manager do all the validation
ConfigManager.validateConfig();
- ChatUtil.printChatMessage(true, "Regex list applied", TextFormatting.WHITE);
+ ChatUtil.printChatMessage(true, "Regex list applied", ChatFormatting.WHITE);
exitGui();
}
//Must be inner class due to protected access to renderTooltip in GuiScreen
public class HoveringText extends Button {
- private final List hoverText;
+ private final List hoverText;
- HoveringText(int x, int y, ITextComponent text, List hoverText) {
- super(x, y, getTextWidth(text.getUnformattedComponentText()), 10, text, (button) -> {
+ HoveringText(int x, int y, Component text, List hoverText) {
+ super(x, y, getTextWidth(text.getString()), 10, text, (button) -> {
});
this.hoverText = hoverText;
}
@Override
- public void render(MatrixStack stack, int mouseX, int mouseY, float tick) {
- GL11.glColor4f(1, 1, 1, 1);
- font.drawString(stack, this.getMessage().getString(), x, y, 0xFF555555);
+ public void render(PoseStack stack, int mouseX, int mouseY, float tick) {
+ RenderSystem.setShaderColor(1, 1, 1, 1);
+ font.draw(stack, this.getMessage().getString(), x, y, 0xFF555555);
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
}
- List getHoverText() {
+ List getHoverText() {
return hoverText;
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/RetranslateGui.java b/src/main/java/com/ringosham/translationmod/gui/RetranslateGui.java
index 700f24c..49cd958 100644
--- a/src/main/java/com/ringosham/translationmod/gui/RetranslateGui.java
+++ b/src/main/java/com/ringosham/translationmod/gui/RetranslateGui.java
@@ -1,10 +1,10 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.vertex.PoseStack;
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.translate.Translator;
-import net.minecraft.util.text.ITextComponent;
-import net.minecraft.util.text.StringTextComponent;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TextComponent;
import net.minecraftforge.fml.ModList;
import java.util.ArrayList;
@@ -32,20 +32,20 @@ public RetranslateGui() {
}
@Override
- public void render(MatrixStack stack, int x, int y, float tick) {
+ public void render(PoseStack stack, int x, int y, float tick) {
super.render(stack, x, y, tick);
drawStringLine(stack, title, new String[]{
"Translations are in the incorrect language?",
"Select the messages below to retranslate.",
}, 0);
- for (int i = 0; i < buttons.size(); i++) {
- TextButton button = (TextButton) buttons.get(i);
- if (button.isHovered()) {
- List hoverText = new ArrayList<>();
- hoverText.add(new StringTextComponent("Sender: " + logs.get(i).getSender()));
- hoverText.add(new StringTextComponent("Message: " + logs.get(i).getMessage()));
+ for (int i = 0; i < renderables.size(); i++) {
+ TextButton button = (TextButton) renderables.get(i);
+ if (button.isHoveredOrFocused()) {
+ List hoverText = new ArrayList<>();
+ hoverText.add(new TextComponent("Sender: " + logs.get(i).sender()));
+ hoverText.add(new TextComponent("Message: " + logs.get(i).message()));
//func_243308_b(MatrixStack, List, int, int) -> renderTooltip(...)
- func_243308_b(stack, hoverText, x, y);
+ renderComponentTooltip(stack, hoverText, x, y);
}
}
}
@@ -54,18 +54,18 @@ public void render(MatrixStack stack, int x, int y, float tick) {
public void init() {
int offset = 0;
for (Translator.TranslationLog log : logs) {
- String buttonText = log.getMessage();
+ String buttonText = log.message();
if (getTextWidth(buttonText) > guiWidth - 15) {
buttonText = buttonText + "...";
while (getTextWidth(buttonText) > guiWidth - 15)
buttonText = buttonText.substring(0, buttonText.length() - 4) + "...";
}
- addButton(new TextButton(getLeftMargin(), getTopMargin() + 40 + offset, getTextWidth(buttonText), new StringTextComponent(buttonText), (button) -> selectLanguage(log.getSender(), log.getMessage()), 0));
+ addRenderableWidget(new TextButton(getLeftMargin(), getTopMargin() + 40 + offset, getTextWidth(buttonText), new TextComponent(buttonText), (button) -> selectLanguage(log.sender(), log.message()), 0));
offset += 10;
}
}
private void selectLanguage(String sender, String message) {
- getMinecraft().displayGuiScreen(new LanguageSelectGui(sender, message));
+ getMinecraft().pushGuiLayer(new LanguageSelectGui(sender, message));
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/TextButton.java b/src/main/java/com/ringosham/translationmod/gui/TextButton.java
index 8465c3c..cfc3b7c 100644
--- a/src/main/java/com/ringosham/translationmod/gui/TextButton.java
+++ b/src/main/java/com/ringosham/translationmod/gui/TextButton.java
@@ -1,25 +1,26 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.widget.button.Button;
-import net.minecraft.util.text.ITextComponent;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.network.chat.Component;
import org.lwjgl.opengl.GL11;
public class TextButton extends Button {
private final int color;
- public TextButton(int x, int y, int width, ITextComponent text, Button.IPressable onPress, int color) {
+ public TextButton(int x, int y, int width, Component text, Button.OnPress onPress, int color) {
super(x, y, width, 10, text, onPress);
this.color = color;
}
@SuppressWarnings("NullableProblems")
@Override
- public void render(MatrixStack stack, int mouseX, int mouseY, float tick) {
- GL11.glColor4f(1, 1, 1, 1);
+ public void render(PoseStack stack, int mouseX, int mouseY, float tick) {
+ RenderSystem.setShaderColor(1, 1, 1, 1);
this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
- Minecraft.getInstance().fontRenderer.drawString(stack, this.getMessage().getUnformattedComponentText(), x, y, color);
+ Minecraft.getInstance().font.draw(stack, this.getMessage().getString(), x, y, color);
}
}
diff --git a/src/main/java/com/ringosham/translationmod/gui/TranslateGui.java b/src/main/java/com/ringosham/translationmod/gui/TranslateGui.java
index 5a998c1..14c97b5 100644
--- a/src/main/java/com/ringosham/translationmod/gui/TranslateGui.java
+++ b/src/main/java/com/ringosham/translationmod/gui/TranslateGui.java
@@ -1,13 +1,15 @@
package com.ringosham.translationmod.gui;
-import com.mojang.blaze3d.matrix.MatrixStack;
+import com.mojang.blaze3d.vertex.PoseStack;
import com.ringosham.translationmod.TranslationMod;
import com.ringosham.translationmod.common.ChatUtil;
import com.ringosham.translationmod.translate.SelfTranslate;
-import net.minecraft.client.gui.widget.TextFieldWidget;
-import net.minecraft.client.gui.widget.button.Button;
-import net.minecraft.util.text.StringTextComponent;
+import net.minecraft.client.gui.components.Button;
+import net.minecraft.client.gui.components.EditBox;
+import net.minecraft.client.gui.components.events.GuiEventListener;
+import net.minecraft.network.chat.TextComponent;
import net.minecraftforge.fml.ModList;
+import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
public class TranslateGui extends CommonGui {
@@ -21,70 +23,79 @@ public class TranslateGui extends CommonGui {
title = modName + " - by Ringosham";
}
- private TextFieldWidget headerField;
- private TextFieldWidget messageField;
+ private EditBox headerField;
+ private EditBox messageField;
+
+ static boolean flag;
public TranslateGui() {
super(title, guiHeight, guiWidth);
+ flag = true;
}
@Override
- public void render(MatrixStack stack, int x, int y, float tick) {
+ public void render(PoseStack stack, int x, int y, float tick) {
super.render(stack, x, y, tick);
- font.drawString(stack, title, getLeftMargin(), getTopMargin(), 0x555555);
- font.drawString(stack, "Enter the command/prefix here (Optional)", getLeftMargin(), getTopMargin() + 10, 0x555555);
- font.drawString(stack, "Enter your message here (Enter to send)", getLeftMargin(), getTopMargin() + 40, 0x555555);
+ if (flag) {
+ messageField.setValue("");
+ flag = false;
+ }
+ font.draw(stack, title, getLeftMargin(), getTopMargin(), 0x555555);
+ font.draw(stack, "Enter the command/prefix here (Optional)", getLeftMargin(), getTopMargin() + 10, 0x555555);
+ font.draw(stack, "Enter your message here (Enter to send)", getLeftMargin(), getTopMargin() + 40, 0x555555);
headerField.render(stack, x, y, tick);
messageField.render(stack, x, y, tick);
}
@Override
public void init() {
- this.headerField = new TextFieldWidget(font, getLeftMargin(), getYOrigin() + 25, guiWidth - 10, 15, new StringTextComponent(""));
- this.messageField = new TextFieldWidget(font, getLeftMargin(), getYOrigin() + 55, guiWidth - 10, 15, new StringTextComponent(""));
- headerField.setMaxStringLength(25);
+ this.headerField = new EditBox(font, getLeftMargin(), getYOrigin() + 25, guiWidth - 10, 15, new TextComponent(""));
+ this.messageField = new EditBox(font, getLeftMargin(), getYOrigin() + 55, guiWidth - 10, 15, new TextComponent(""));
+ headerField.setMaxLength(25);
headerField.setCanLoseFocus(true);
- headerField.setEnableBackgroundDrawing(true);
- messageField.setMaxStringLength(75);
+ headerField.setBordered(true);
+ messageField.setMaxLength(75);
messageField.setCanLoseFocus(true);
- messageField.setEnableBackgroundDrawing(true);
- children.add(headerField);
- children.add(messageField);
- getMinecraft().keyboardListener.enableRepeatEvents(true);
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new StringTextComponent("Settings"),
+ messageField.setBordered(true);
+ addWidget(headerField);
+ addWidget(messageField);
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new TextComponent("Settings"),
(button) -> this.configGui()));
- addButton(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new StringTextComponent("Close"),
+ addRenderableWidget(new Button(getRightMargin(regularButtonWidth), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new TextComponent("Close"),
(button) -> this.exitGui()));
- addButton(new Button(getLeftMargin(), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new StringTextComponent("Retranslate"), (button) -> this.retranslateGui()));
- addButton(new Button(getLeftMargin(), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new StringTextComponent("Credits"),
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + guiHeight - 5 - regularButtonHeight, regularButtonWidth, regularButtonHeight, new TextComponent("Retranslate"), (button) -> this.retranslateGui()));
+ addRenderableWidget(new Button(getLeftMargin(), getYOrigin() + guiHeight - 10 - regularButtonHeight * 2, regularButtonWidth, regularButtonHeight, new TextComponent("Credits"),
(button) -> {
ChatUtil.printCredits();
this.exitGui();
}));
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ this.setFocused(messageField);
+ messageField.setFocus(true);
}
private void retranslateGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(new RetranslateGui());
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(new RetranslateGui());
}
private void configGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(new ConfigGui());
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(new ConfigGui());
}
private void exitGui() {
- getMinecraft().keyboardListener.enableRepeatEvents(false);
- getMinecraft().displayGuiScreen(null);
+ getMinecraft().keyboardHandler.setSendRepeatsToGui(false);
+ getMinecraft().setScreen(null);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_ENTER && (this.messageField.isFocused() || this.headerField.isFocused())) {
exitGui();
- Thread translate = new SelfTranslate(this.messageField.getText(), this.headerField.getText());
+ Thread translate = new SelfTranslate(this.messageField.getValue(), this.headerField.getValue());
translate.start();
- return false;
+ return true;
}
if (keyCode == GLFW.GLFW_KEY_E && !this.messageField.isFocused() && !this.headerField.isFocused()) {
exitGui();
@@ -92,4 +103,20 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
+ @Override
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
+ // 点击 headerField 区域时转移焦点
+ if (headerField.isMouseOver(mouseX, mouseY)) {
+ headerField.setFocus(true);
+ messageField.setFocus(false); // 移除其他框的焦点
+ }
+
+ // 点击 messageField 区域时同理
+ if (messageField.isMouseOver(mouseX, mouseY)) {
+ messageField.setFocus(true);
+ headerField.setFocus(false);
+ }
+
+ return super.mouseClicked(mouseX, mouseY, button);
+ }
}
diff --git a/src/main/java/com/ringosham/translationmod/mixin/ChatComponentField.java b/src/main/java/com/ringosham/translationmod/mixin/ChatComponentField.java
new file mode 100644
index 0000000..d14f980
--- /dev/null
+++ b/src/main/java/com/ringosham/translationmod/mixin/ChatComponentField.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2025 Ringosham
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.ringosham.translationmod.mixin;
+
+import net.minecraft.client.GuiMessage;
+import net.minecraft.client.gui.components.ChatComponent;
+import net.minecraft.network.chat.Component;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+import java.util.List;
+
+@Mixin(ChatComponent.class)
+public interface ChatComponentField {
+ @Accessor("allMessages")
+ List> getAllMessages();
+}
diff --git a/src/main/java/com/ringosham/translationmod/translate/Retranslate.java b/src/main/java/com/ringosham/translationmod/translate/Retranslate.java
index 7bf4d29..cd57ded 100644
--- a/src/main/java/com/ringosham/translationmod/translate/Retranslate.java
+++ b/src/main/java/com/ringosham/translationmod/translate/Retranslate.java
@@ -4,7 +4,7 @@
import com.ringosham.translationmod.common.ChatUtil;
import com.ringosham.translationmod.common.ConfigManager;
import com.ringosham.translationmod.translate.types.TranslateResult;
-import net.minecraft.util.text.TextFormatting;
+import net.minecraft.ChatFormatting;
public class Retranslate extends Thread {
@@ -28,7 +28,7 @@ public void run() {
return;
TranslateResult translatedMessage = translator.translate(message.trim());
if (translatedMessage == null) {
- ChatUtil.printChatMessage(true, "An error occurred during translation", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "An error occurred during translation", ChatFormatting.RED);
return;
}
String fromStr = null;
@@ -42,9 +42,9 @@ public void run() {
(fromStr == null ? "Unknown" : fromStr) + " -> " + to.getName();
//If the translation result is the same as the original message, this means the translation failed.
if (translatedMessage.getMessage().trim().equals(message.trim())) {
- ChatUtil.printChatMessage(true, "Translation failed. Try another language maybe?", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Translation failed. Try another language maybe?", ChatFormatting.RED);
return;
}
- ChatUtil.printChatMessageAdvanced(chatMessage, hoverText, ConfigManager.config.bold.get(), ConfigManager.config.italic.get(), ConfigManager.config.underline.get(), TextFormatting.getValueByName(ConfigManager.config.color.get()));
+ ChatUtil.printChatMessageAdvanced(chatMessage, hoverText, ConfigManager.config.bold.get(), ConfigManager.config.italic.get(), ConfigManager.config.underline.get(), ChatFormatting.getByName(ConfigManager.config.color.get()));
}
}
diff --git a/src/main/java/com/ringosham/translationmod/translate/SelfTranslate.java b/src/main/java/com/ringosham/translationmod/translate/SelfTranslate.java
index f940fa0..e8fb358 100644
--- a/src/main/java/com/ringosham/translationmod/translate/SelfTranslate.java
+++ b/src/main/java/com/ringosham/translationmod/translate/SelfTranslate.java
@@ -21,6 +21,7 @@
import com.ringosham.translationmod.common.ConfigManager;
import com.ringosham.translationmod.translate.types.TranslateResult;
import net.minecraft.client.Minecraft;
+import net.minecraft.network.chat.TextComponent;
public class SelfTranslate extends Thread {
private final String message;
@@ -41,6 +42,6 @@ public void run() {
if (translatedMessage == null)
return;
//noinspection ConstantConditions
- Minecraft.getInstance().player.sendChatMessage(selfHeader + " " + translatedMessage.getMessage());
+ Minecraft.getInstance().player.chat(selfHeader + "[By Translator] " + translatedMessage.getMessage());
}
}
diff --git a/src/main/java/com/ringosham/translationmod/translate/SignTranslate.java b/src/main/java/com/ringosham/translationmod/translate/SignTranslate.java
index 1320c2e..2c37edb 100644
--- a/src/main/java/com/ringosham/translationmod/translate/SignTranslate.java
+++ b/src/main/java/com/ringosham/translationmod/translate/SignTranslate.java
@@ -24,8 +24,8 @@
import com.ringosham.translationmod.common.Log;
import com.ringosham.translationmod.translate.types.SignText;
import com.ringosham.translationmod.translate.types.TranslateResult;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.text.TextFormatting;
+import net.minecraft.ChatFormatting;
+import net.minecraft.core.BlockPos;
public class SignTranslate extends Thread {
private final String text;
@@ -54,6 +54,6 @@ public void run() {
"\n" +
"Translation: " +
translatedMessage.getSourceLanguage().getName() + " -> " + targetLanguage.getName();
- ChatUtil.printChatMessageAdvanced(chatMessage, hoverText, ConfigManager.config.bold.get(), ConfigManager.config.italic.get(), ConfigManager.config.underline.get(), TextFormatting.getValueByName(ConfigManager.config.color.get()));
+ ChatUtil.printChatMessageAdvanced(chatMessage, hoverText, ConfigManager.config.bold.get(), ConfigManager.config.italic.get(), ConfigManager.config.underline.get(), ChatFormatting.getByName(ConfigManager.config.color.get()));
}
}
diff --git a/src/main/java/com/ringosham/translationmod/translate/Translator.java b/src/main/java/com/ringosham/translationmod/translate/Translator.java
index 21eee2f..62989fa 100644
--- a/src/main/java/com/ringosham/translationmod/translate/Translator.java
+++ b/src/main/java/com/ringosham/translationmod/translate/Translator.java
@@ -26,11 +26,10 @@
import com.ringosham.translationmod.common.ConfigManager;
import com.ringosham.translationmod.common.Log;
import com.ringosham.translationmod.translate.types.TranslateResult;
-import net.minecraft.util.text.TextFormatting;
+import net.minecraft.ChatFormatting;
import java.util.LinkedList;
import java.util.List;
-import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -142,71 +141,71 @@ private void logException(RequestResult transRequest) {
break;
case 411:
Log.logger.error("Google API >> API call error");
- ChatUtil.printChatMessage(true, "API call error. Please report this error as it shouldn't happen", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "API call error. Please report this error as it shouldn't happen", ChatFormatting.RED);
break;
case 429:
Log.logger.warn("Google denied access to translation API. Pausing translation for 5 minutes");
- ChatUtil.printChatMessage(true, "Google translate has stopped responding. Pausing translations", TextFormatting.YELLOW);
+ ChatUtil.printChatMessage(true, "Google translationmod.mixins.json has stopped responding. Pausing translations", ChatFormatting.YELLOW);
break;
case 403:
Log.logger.error("Google API >> Exceeded API quota / User rate limit reached");
- ChatUtil.printChatMessage(true, "You have exceeded your quota / rate limit. Please check your quota settings", TextFormatting.RED);
- ChatUtil.printChatMessage(true, "Falling back to free version until you restart the game", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "You have exceeded your quota / rate limit. Please check your quota settings", ChatFormatting.RED);
+ ChatUtil.printChatMessage(true, "Falling back to free version until you restart the game", ChatFormatting.RED);
GooglePaidClient.setDisable();
break;
case 400:
Log.logger.error("Google API >> API key invalid");
- ChatUtil.printChatMessage(true, "API key invalid. If you do not wish to use a key, please remove it from the settings", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "API key invalid. If you do not wish to use a key, please remove it from the settings", ChatFormatting.RED);
break;
case 500:
Log.logger.error("Google API >> Failed to determine source language: " + transRequest.getMessage());
- ChatUtil.printChatMessage(true, "Server side failure. Cannot translate", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Server side failure. Cannot translationmod.mixins.json", ChatFormatting.RED);
break;
case 52001:
Log.logger.error("Baidu API >> Connection timeout");
break;
case 52002:
Log.logger.error("Baidu API >> Server side failure");
- ChatUtil.printChatMessage(true, "Server side failure. Cannot translate", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Server side failure. Cannot translationmod.mixins.json", ChatFormatting.RED);
break;
case 52003:
Log.logger.error("Baidu API >> Unauthorized request");
- ChatUtil.printChatMessage(true, "Authentication failure. Please check your App ID and API key", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Authentication failure. Please check your App ID and API key", ChatFormatting.RED);
break;
case 54003:
Log.logger.warn("Baidu API >> Restricted request per second limit");
if (!warnLimit) {
- ChatUtil.printChatMessage(true, "Request restricted due to tier limits. Consider upgrading your plan", TextFormatting.YELLOW);
+ ChatUtil.printChatMessage(true, "Request restricted due to tier limits. Consider upgrading your plan", ChatFormatting.YELLOW);
warnLimit = true;
}
break;
case 54004:
Log.logger.error("Baidu API >> Not enough balance");
- ChatUtil.printChatMessage(true, "Balance insufficient. Please go to Baidu's control panel to top up", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Balance insufficient. Please go to Baidu's control panel to top up", ChatFormatting.RED);
break;
case 54005:
Log.logger.error("Baidu API >> Request too large");
- ChatUtil.printChatMessage(true, "Request denied due to size too large", TextFormatting.YELLOW);
+ ChatUtil.printChatMessage(true, "Request denied due to size too large", ChatFormatting.YELLOW);
break;
case 58000:
Log.logger.error("Baidu API >> Client IP is not whitelisted");
- ChatUtil.printChatMessage(true, "Request denied due to client IP not whitelisted. Please add your IP or remove whitelisting in the Baidu control panel", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Request denied due to client IP not whitelisted. Please add your IP or remove whitelisting in the Baidu control panel", ChatFormatting.RED);
break;
case 58001:
Log.logger.error("Baidu API >> Translation direction not supported");
- ChatUtil.printChatMessage(true, "Cannot translate from " + transRequest.getFrom().getName() + " to " + transRequest.getTo().getName(), TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Cannot translationmod.mixins.json from " + transRequest.getFrom().getName() + " to " + transRequest.getTo().getName(), ChatFormatting.RED);
break;
case 58002:
Log.logger.error("Baidu API >> Translation service is not enabled");
- ChatUtil.printChatMessage(true, "Translation service is not enabled. Please turn it on in Baidu's control panel", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Translation service is not enabled. Please turn it on in Baidu's control panel", ChatFormatting.RED);
break;
case 90107:
Log.logger.error("Baidu API >> Verification failed");
- ChatUtil.printChatMessage(true, "Verification failed. Please check your verification status", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Verification failed. Please check your verification status", ChatFormatting.RED);
break;
case BaiduClient.LANGUAGE_NOT_SUPPORTED:
Log.logger.error("Baidu API >> Language not supported");
- ChatUtil.printChatMessage(true, "Selected language is not supported by your translation engine", TextFormatting.RED);
+ ChatUtil.printChatMessage(true, "Selected language is not supported by your translation engine", ChatFormatting.RED);
break;
default:
Log.logger.error("Unknown error/Server side failure: " + transRequest.getMessage());
@@ -270,7 +269,7 @@ public void run() {
//In cases where the message language and the target language is the same
if (translatedMessage.getMessage().trim().equals(rawMessage.trim()))
return;
- ChatUtil.printChatMessageAdvanced(chatMessage, hoverText, ConfigManager.config.bold.get(), ConfigManager.config.italic.get(), ConfigManager.config.underline.get(), TextFormatting.getValueByName(ConfigManager.config.color.get()));
+ ChatUtil.printChatMessageAdvanced(chatMessage, hoverText, ConfigManager.config.bold.get(), ConfigManager.config.italic.get(), ConfigManager.config.underline.get(), ChatFormatting.getByName(ConfigManager.config.color.get()));
}
private void addToLog(TranslationLog log) {
@@ -281,40 +280,5 @@ private void addToLog(TranslationLog log) {
translationLog.pollFirst();
}
- public static class TranslationLog {
- private final String sender;
- private final String message;
- private final TranslateResult result;
-
- public TranslationLog(String sender, String message, TranslateResult result) {
- this.sender = sender;
- this.message = message;
- this.result = result;
- }
-
- public String getMessage() {
- return message;
- }
-
- public String getSender() {
- return sender;
- }
-
- public TranslateResult getResult() {
- return result;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- TranslationLog that = (TranslationLog) o;
- return Objects.equals(sender, that.sender) && Objects.equals(message, that.message) && Objects.equals(result, that.result);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(sender, message, result);
- }
- }
+ public record TranslationLog(String sender, String message, TranslateResult result) {}
}
diff --git a/src/main/java/com/ringosham/translationmod/translate/types/SignText.java b/src/main/java/com/ringosham/translationmod/translate/types/SignText.java
index 3ad948c..c6b8290 100644
--- a/src/main/java/com/ringosham/translationmod/translate/types/SignText.java
+++ b/src/main/java/com/ringosham/translationmod/translate/types/SignText.java
@@ -1,6 +1,6 @@
package com.ringosham.translationmod.translate.types;
-import net.minecraft.util.math.BlockPos;
+import net.minecraft.core.BlockPos;
public class SignText {
private String text;
diff --git a/src/main/resources/Changelog.txt b/src/main/resources/Changelog.txt
index 7be573e..2d1de10 100644
--- a/src/main/resources/Changelog.txt
+++ b/src/main/resources/Changelog.txt
@@ -111,4 +111,5 @@
6.0 - ADD: Baidu translation. For people from North Korea and "other countries" (#8)
- FIX: Translator crash due to previously failed translation (#11)
- FIX: Failed to get chat log from regex screen (#10)
- - FIX: Google translate API call error (#14)
\ No newline at end of file
+ - FIX: Google translate API call error (#14)
+ 7.0 - VERSION: change to version 1.18.2
\ No newline at end of file
diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml
index ab6a3c7..69df1d3 100644
--- a/src/main/resources/META-INF/mods.toml
+++ b/src/main/resources/META-INF/mods.toml
@@ -5,42 +5,40 @@
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader = "javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
-loaderVersion = "[33,)" #mandatory (28 is current forge version)
-license = "Licensed under GPL version 3"
+loaderVersion = "${loader_version_range}" #mandatory (28 is current forge version)
+license = "${mod_license}"
# A URL to refer people to when problems occur with this mod
issueTrackerURL = "https://github.com/ringosham/TranslateMod/issues" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
-modId = "translationmod" #mandatory
+modId = "${mod_id}" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
-version = "6.0" #mandatory
+version = "${mod_version}" #mandatory
# A display name for the mod
-displayName = "Real time translation mod" #mandatory
+displayName = "${mod_name}" #mandatory
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL = "http://minecraft.curseforge.com/projects/real-time-chat-translation-mod" #optional
# A text field displayed in the mod UI
-authors = "Ringosham" #optional
+authors = "${mod_authors}" #optional
# The description text for the mod (multi line!) (#mandatory)
-description = '''
-This mod translate your Minecraft chat in real time! Translation results are powered by Google.
-'''
+description = '''${mod_description}'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
-[[dependencies.examplemod]] #optional
+[[dependencies."${mod_id}"]] #optional
# the modid of the dependency
modId = "forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory = true #mandatory
# The version range of the dependency
-versionRange = "[33,)" #mandatory
+versionRange = "${forge_version_range}" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering = "NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side = "BOTH"
# Here's another dependency
-[[dependencies.examplemod]]
+[[dependencies."${mod_id}"]]
modId = "minecraft"
mandatory = true
-versionRange = "[1.16.4]"
+versionRange = "${minecraft_version_range}"
ordering = "NONE"
side = "BOTH"
diff --git a/src/main/resources/translationmod.mixins.json b/src/main/resources/translationmod.mixins.json
new file mode 100644
index 0000000..498ea24
--- /dev/null
+++ b/src/main/resources/translationmod.mixins.json
@@ -0,0 +1,12 @@
+{
+ "package": "com.ringosham.translationmod.mixin",
+ "mixins": [
+ ],
+ "refmap": "translationmod.refmap.json",
+ "required": true,
+ "minVersion": "0.8",
+ "compatibilityLevel": "JAVA_17",
+ "client": [
+ "ChatComponentField"
+ ]
+}
\ No newline at end of file