Fix some things (hopefully)
This commit is contained in:
parent
8ca9bd2f02
commit
f5f5071468
|
@ -1,22 +1,118 @@
|
|||
#Gradle
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
classes/
|
||||
|
||||
#IDEA
|
||||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
#vscode
|
||||
.settings/
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
# IntelliJ
|
||||
out/
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
#fabric
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
.gradle
|
||||
build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
**/build/
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
remappedSrc/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 JFronny
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
96
build.gradle
96
build.gradle
|
@ -1,90 +1,92 @@
|
|||
plugins {
|
||||
id 'fabric-loom' version '0.5.11'
|
||||
id 'maven-publish'
|
||||
id 'fabric-loom' version '0.5-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url "https://jitpack.io"
|
||||
}
|
||||
maven {
|
||||
url "https://jitpack.io"
|
||||
}
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = "${project.mod_version}+${project.minecraft_version}"
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
dependencies {
|
||||
//to change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
//to change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
modCompile "com.github.vbauer:yandex-translate-api:1.4.2"
|
||||
include "com.github.vbauer:yandex-translate-api:1.4.2"
|
||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||
// You may need to force-disable transitiveness on them.
|
||||
modCompile "com.github.vbauer:yandex-translate-api:1.4.2"
|
||||
include "com.github.vbauer:yandex-translate-api:1.4.2"
|
||||
|
||||
modCompile "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
|
||||
include "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
|
||||
modApi "me.shedaniel.cloth:config-2:4.7.0-unstable"
|
||||
include "me.shedaniel.cloth:config-2:4.7.0-unstable"
|
||||
modApi "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
|
||||
include "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
|
||||
modApi "me.shedaniel.cloth:config-2:4.6.0"
|
||||
include "me.shedaniel.cloth:config-2:4.6.0"
|
||||
|
||||
modCompile("io.github.prospector:modmenu:1.14.6+build.31")
|
||||
modCompile("io.github.prospector:modmenu:1.14.5+build.30")
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property "version", project.version
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
}
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
from "LICENSE"
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
// uncomment to publish to the local maven
|
||||
// mavenLocal()
|
||||
}
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
// uncomment to publish to the local maven
|
||||
// mavenLocal()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version=1.16.1
|
||||
yarn_mappings=1.16.1+build.1
|
||||
loader_version=0.8.8+build.202
|
||||
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.16.1
|
||||
yarn_mappings=1.16.1+build.21
|
||||
loader_version=0.9.0+build.204
|
||||
# Mod Properties
|
||||
mod_version = 1.0.3
|
||||
maven_group = io.gitlab.jfronny
|
||||
archives_base_name = translater
|
||||
|
||||
mod_version=1.0.4
|
||||
maven_group=io.gitlab.jfronny
|
||||
archives_base_name=translater
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.13.1+build.370-1.16
|
||||
# check this on https://modmuss50.me/fabric.html
|
||||
fabric_version=0.16.2+build.385-1.16.1
|
||||
|
|
Binary file not shown.
|
@ -82,6 +82,7 @@ esac
|
|||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
|
@ -129,6 +130,7 @@ fi
|
|||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
|
|
|
@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
|
|||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package io.gitlab.jfronny.translater;
|
||||
|
||||
import io.gitlab.jfronny.translater.interfaces.StringTransformer;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.ConfigManager;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public abstract class CachingTransformer implements StringTransformer {
|
||||
private static final File cacheFile = new File(FabricLoader.getInstance().getConfigDirectory(), "Translater.cache");
|
||||
Properties cache = null;
|
||||
|
||||
@Override
|
||||
public String transform(String str) {
|
||||
if (str == null)
|
||||
return null;
|
||||
if (cache == null) {
|
||||
cache = new Properties();
|
||||
if (ModInit.cfg.forceRegenerate) {
|
||||
ModInit.cfg.forceRegenerate = false;
|
||||
((ConfigManager<Cfg>) AutoConfig.getConfigHolder(Cfg.class)).save();
|
||||
} else {
|
||||
if (cacheFile.exists()) {
|
||||
try {
|
||||
FileInputStream inS = new FileInputStream(cacheFile);
|
||||
cache.load(inS);
|
||||
inS.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (!ModInit.cfg.breakFully && ModInit.cfg.rounds == 5) {
|
||||
try {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream inS = classLoader.getResourceAsStream("namecache.ini");
|
||||
if (inS != null) {
|
||||
cache.load(inS);
|
||||
inS.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
FileOutputStream outS = new FileOutputStream(cacheFile);
|
||||
cache.store(outS, "---Lang---");
|
||||
outS.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!cache.containsKey(str)) {
|
||||
cache.put(str, getTransformed(str));
|
||||
try {
|
||||
FileOutputStream outS = new FileOutputStream(cacheFile);
|
||||
cache.store(outS, "---Lang---");
|
||||
outS.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return (String) cache.get(str);
|
||||
}
|
||||
|
||||
public abstract String getTransformed(String str);
|
||||
}
|
|
@ -2,9 +2,8 @@ package io.gitlab.jfronny.translater;
|
|||
|
||||
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry.Gui.EnumHandler;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry.Gui.RequiresRestart;
|
||||
|
||||
@Config(name = "TranslaterCF")
|
||||
public class Cfg implements ConfigData {
|
||||
|
@ -17,10 +16,10 @@ public class Cfg implements ConfigData {
|
|||
@Comment("The language to translate to - Leave empty for auto-detection (might break text even more)")
|
||||
public String targetLanguage = "en";
|
||||
@Comment("Significantly slows down the loading time but gives a visual of the progress. Values: Full, Console, None")
|
||||
@EnumHandler(option = EnumHandler.EnumDisplayOption.BUTTON)
|
||||
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
|
||||
public progressMode renderProgress = progressMode.None;
|
||||
@Comment("Use this if something is broken. This initiate the regeneration of the cache")
|
||||
@RequiresRestart
|
||||
@Comment("Use this if something is broken. This initiates the regeneration of the cache")
|
||||
@ConfigEntry.Gui.RequiresRestart
|
||||
public boolean forceRegenerate = false;
|
||||
|
||||
public enum progressMode {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package io.gitlab.jfronny.translater;
|
||||
|
||||
public interface IMinecraftClientMixin {
|
||||
void forceRender();
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package io.gitlab.jfronny.translater;
|
||||
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ModInit implements ClientModInitializer {
|
||||
public static final String MOD_NAME = "translater";
|
||||
public static final String MOD_ID = "translater";
|
||||
private static final Logger logger = LogManager.getFormatterLogger(MOD_ID);
|
||||
public static Cfg cfg;
|
||||
|
||||
public static void loadCfg() {
|
||||
if (cfg == null) {
|
||||
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
|
||||
cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public ModInit() {
|
||||
loadCfg();
|
||||
}
|
||||
|
||||
public static void Log(String msg) {
|
||||
logger.log(Level.INFO, "[" + MOD_NAME + "] " + msg);
|
||||
}
|
||||
|
||||
public static void Warn(String msg) {
|
||||
logger.log(Level.WARN, "[" + MOD_NAME + "] " + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
Log("Loaded translater");
|
||||
}
|
||||
|
||||
public static TransformingMap map = null;
|
||||
|
||||
public static boolean Gui() {
|
||||
return cfg.renderProgress == Cfg.progressMode.Full;
|
||||
}
|
||||
public static boolean Cli() {
|
||||
return cfg.renderProgress == Cfg.progressMode.Full || cfg.renderProgress == Cfg.progressMode.Console;
|
||||
}
|
||||
}
|
|
@ -3,10 +3,7 @@ package io.gitlab.jfronny.translater;
|
|||
import io.github.prospector.modmenu.api.ConfigScreenFactory;
|
||||
import io.github.prospector.modmenu.api.ModMenuApi;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModMenu implements ModMenuApi {
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package io.gitlab.jfronny.translater;
|
||||
|
||||
import io.gitlab.jfronny.translater.transformer.CachingTransformer;
|
||||
import io.gitlab.jfronny.translater.transformer.TransformingMap;
|
||||
import io.gitlab.jfronny.translater.transformer.YnTransformer;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class Translater implements ClientModInitializer {
|
||||
public static final String MOD_NAME = "Translater";
|
||||
public static final String MOD_ID = "translater";
|
||||
private static final Logger logger;
|
||||
public static Cfg cfg;
|
||||
private static TransformingMap map;
|
||||
|
||||
static {
|
||||
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
|
||||
cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig();
|
||||
logger = LogManager.getFormatterLogger(MOD_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean Gui() {
|
||||
return cfg.renderProgress == Cfg.progressMode.Full;
|
||||
}
|
||||
public static boolean Cli() {
|
||||
return cfg.renderProgress == Cfg.progressMode.Full || cfg.renderProgress == Cfg.progressMode.Console;
|
||||
}
|
||||
|
||||
public static void Warn(String msg) {
|
||||
logger.log(Level.WARN, "[" + MOD_NAME + "] " + msg);
|
||||
}
|
||||
|
||||
public static void Log(String msg) {
|
||||
logger.log(Level.INFO, "[" + MOD_NAME + "] " + msg);
|
||||
}
|
||||
|
||||
public static TransformingMap getMap(Map<String, String> base) {
|
||||
if (map == null) {
|
||||
map = new TransformingMap(base, new CachingTransformer(new YnTransformer()));
|
||||
map.init();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static TransformingMap getMap() {
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package io.gitlab.jfronny.translater.interfaces;
|
||||
|
||||
public interface IMClient {
|
||||
void render();
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package io.gitlab.jfronny.translater.interfaces;
|
||||
|
||||
public interface StringTransformer {
|
||||
String transform(String str);
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
package io.gitlab.jfronny.translater.mixin;
|
||||
|
||||
import io.gitlab.jfronny.translater.ModInit;
|
||||
import io.gitlab.jfronny.translater.TransformingMap;
|
||||
import io.gitlab.jfronny.translater.YnTransformer;
|
||||
import io.gitlab.jfronny.translater.Translater;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.MappingResolver;
|
||||
import net.minecraft.client.resource.language.TranslationStorage;
|
||||
|
@ -16,6 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
//This is where the actual magic happens
|
||||
@Mixin(Language.class)
|
||||
public class MixinLanguage {
|
||||
private static final MappingResolver mr = FabricLoader.getInstance().getMappingResolver();
|
||||
|
@ -30,16 +29,12 @@ public class MixinLanguage {
|
|||
@Inject(at = @At("HEAD"), method = "setInstance")
|
||||
private static void languageSetInstance(Language language, CallbackInfo ci) {
|
||||
if (FIELD == null) {
|
||||
ModInit.Warn("Could not set language map, field not found");
|
||||
Translater.Warn("Could not set language map, field not found");
|
||||
return;
|
||||
}
|
||||
if (language instanceof TranslationStorage) {
|
||||
try {
|
||||
if (ModInit.map == null) {
|
||||
ModInit.map = new TransformingMap((Map<String, String>) FIELD.get(language), new YnTransformer());
|
||||
ModInit.map.init();
|
||||
}
|
||||
FIELD.set(language, ModInit.map);
|
||||
FIELD.set(language, Translater.getMap((Map<String, String>) FIELD.get(language)));
|
||||
} catch (IllegalAccessException | ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package io.gitlab.jfronny.translater.mixin;
|
||||
|
||||
import io.gitlab.jfronny.translater.interfaces.IMClient;
|
||||
import io.gitlab.jfronny.translater.IMinecraftClientMixin;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
//This exposes the render method to other code, used for updating the loading screen
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MixinMinecraftClient implements IMClient {
|
||||
public class MixinMinecraftClient implements IMinecraftClientMixin {
|
||||
@Shadow
|
||||
private void render(boolean tick) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void forceRender() {
|
||||
render(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package io.gitlab.jfronny.translater.mixin;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import io.gitlab.jfronny.translater.ModInit;
|
||||
import io.gitlab.jfronny.translater.Translater;
|
||||
import io.gitlab.jfronny.translater.transformer.TransformingMap;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.FontStorage;
|
||||
import net.minecraft.client.font.FontType;
|
||||
|
@ -21,13 +22,15 @@ import java.util.Collections;
|
|||
|
||||
@Mixin(SplashScreen.class)
|
||||
public abstract class MixinSplashScreen extends Overlay {
|
||||
@Shadow @Final
|
||||
@Shadow
|
||||
@Final
|
||||
private MinecraftClient client;
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "renderProgressBar")
|
||||
private void RenderTrnslProgress(MatrixStack matrixStack, int i, int j, int k, int l, float f, CallbackInfo ci) {
|
||||
if (ModInit.map != null && ModInit.map.initializing) {
|
||||
renderer.draw(matrixStack, "Transforming " + ModInit.map.initI + "/" + ModInit.map.initMax, 10, 10, 0);
|
||||
TransformingMap map = Translater.getMap();
|
||||
if (map != null && map.initializing) {
|
||||
renderer.draw(matrixStack, "Transforming " + map.initI + "/" + map.initMax, 10, 10, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package io.gitlab.jfronny.translater;
|
||||
package io.gitlab.jfronny.translater.mixin;
|
||||
|
||||
import io.gitlab.jfronny.translater.mixin.MixinLanguage;
|
||||
import io.gitlab.jfronny.translater.mixin.MixinMinecraftClient;
|
||||
import io.gitlab.jfronny.translater.mixin.MixinSplashScreen;
|
||||
import io.gitlab.jfronny.translater.Translater;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
@ -11,7 +9,7 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class MixinPlugin implements IMixinConfigPlugin {
|
||||
public class Plugin implements IMixinConfigPlugin {
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
|
@ -22,15 +20,15 @@ public class MixinPlugin implements IMixinConfigPlugin {
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ReferenceToMixin")
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
ModInit.loadCfg();
|
||||
if (Objects.equals(mixinClassName, MixinLanguage.class.getName()))
|
||||
return true;
|
||||
else if (Objects.equals(mixinClassName, MixinMinecraftClient.class.getName()))
|
||||
return ModInit.Gui();
|
||||
return Translater.Gui();
|
||||
else if (Objects.equals(mixinClassName, MixinSplashScreen.class.getName()))
|
||||
return ModInit.Gui();
|
||||
return Translater.Gui();
|
||||
else
|
||||
throw new IllegalStateException("Unrecognized mixin! This should never happen");
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package io.gitlab.jfronny.translater.transformer;
|
||||
|
||||
import io.gitlab.jfronny.translater.Cfg;
|
||||
import io.gitlab.jfronny.translater.Translater;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.ConfigManager;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class CachingTransformer implements ITransformer {
|
||||
private static final File cacheFile = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Translater.cache");
|
||||
Properties cache;
|
||||
private final ITransformer transformer;
|
||||
|
||||
@Override
|
||||
public String transform(String str) {
|
||||
if (str == null)
|
||||
return null;
|
||||
//Transform and cache if not present
|
||||
if (!cache.containsKey(str)) {
|
||||
cache.put(str, transformer.transform(str));
|
||||
Save();
|
||||
}
|
||||
//Return cached result
|
||||
return (String) cache.get(str);
|
||||
}
|
||||
|
||||
public CachingTransformer(ITransformer baseTransformer) {
|
||||
transformer = baseTransformer;
|
||||
cache = new Properties();
|
||||
if (Translater.cfg.forceRegenerate) {
|
||||
Translater.cfg.forceRegenerate = false;
|
||||
((ConfigManager<Cfg>) AutoConfig.getConfigHolder(Cfg.class)).save();
|
||||
} else {
|
||||
//Load cache
|
||||
if (cacheFile.exists()) {
|
||||
try {
|
||||
FileInputStream inS = new FileInputStream(cacheFile);
|
||||
cache.load(inS);
|
||||
inS.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
//Save default cache if parameters are default
|
||||
if (!Translater.cfg.breakFully && Translater.cfg.rounds == 5) {
|
||||
try {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream inS = classLoader.getResourceAsStream("namecache.ini");
|
||||
if (inS != null) {
|
||||
cache.load(inS);
|
||||
inS.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Save();
|
||||
}
|
||||
|
||||
private void Save() {
|
||||
try {
|
||||
FileOutputStream outS = new FileOutputStream(cacheFile);
|
||||
cache.store(outS, "---Lang---");
|
||||
outS.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package io.gitlab.jfronny.translater.transformer;
|
||||
|
||||
public interface ITransformer {
|
||||
String transform(String str);
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.translater;
|
||||
package io.gitlab.jfronny.translater.transformer;
|
||||
|
||||
import io.gitlab.jfronny.translater.interfaces.IMClient;
|
||||
import io.gitlab.jfronny.translater.interfaces.StringTransformer;
|
||||
import io.gitlab.jfronny.translater.IMinecraftClientMixin;
|
||||
import io.gitlab.jfronny.translater.Translater;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -10,12 +10,12 @@ import java.util.Set;
|
|||
|
||||
public class TransformingMap implements Map<String, String> {
|
||||
private final Map<String, String> backer;
|
||||
private final StringTransformer transformer;
|
||||
private final ITransformer transformer;
|
||||
public boolean initializing;
|
||||
public int initI;
|
||||
public int initMax;
|
||||
|
||||
public TransformingMap(Map<String, String> m, StringTransformer t) {
|
||||
public TransformingMap(Map<String, String> m, ITransformer t) {
|
||||
backer = m;
|
||||
transformer = t;
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ public class TransformingMap implements Map<String, String> {
|
|||
initMax = strings.size();
|
||||
initializing = true;
|
||||
for (String value : strings) {
|
||||
if (ModInit.Cli() || ModInit.Gui()) {
|
||||
if (Translater.Cli()) {
|
||||
initI++;
|
||||
ModInit.Log("Transforming " + initI + "/" + initMax);
|
||||
if (ModInit.Gui() && initI % 10 == 0)
|
||||
((IMClient)MinecraftClient.getInstance()).render();
|
||||
Translater.Log("Transforming " + initI + "/" + initMax);
|
||||
}
|
||||
if (Translater.Gui() && initI % 10 == 0)
|
||||
((IMinecraftClientMixin) MinecraftClient.getInstance()).forceRender();
|
||||
transformer.transform(value);
|
||||
}
|
||||
initializing = false;
|
|
@ -1,26 +1,22 @@
|
|||
package io.gitlab.jfronny.translater;
|
||||
package io.gitlab.jfronny.translater.transformer;
|
||||
|
||||
import com.github.vbauer.yta.model.Direction;
|
||||
import com.github.vbauer.yta.model.Language;
|
||||
import com.github.vbauer.yta.service.YTranslateApiImpl;
|
||||
import io.gitlab.jfronny.translater.Translater;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class YnTransformer extends CachingTransformer {
|
||||
|
||||
private static final Random rnd = new Random();
|
||||
private static YTranslateApiImpl api = null;
|
||||
private static Set<Language> languages = null;
|
||||
|
||||
//The actual translation methods
|
||||
public class YnTransformer implements ITransformer {
|
||||
private static Random rnd;
|
||||
private static YTranslateApiImpl api;
|
||||
private static Set<Language> languages;
|
||||
@Override
|
||||
public String getTransformed(String str) {
|
||||
public String transform(String str) {
|
||||
try {
|
||||
if (api == null)
|
||||
api = new YTranslateApiImpl(ModInit.cfg.key);
|
||||
if (languages == null)
|
||||
languages = api.languageApi().all().languages();
|
||||
if (str.contains("%")) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
boolean f = true;
|
||||
|
@ -28,9 +24,9 @@ public class YnTransformer extends CachingTransformer {
|
|||
if (!f) {
|
||||
res.append("%");
|
||||
if (s.length() > 0)
|
||||
res.append(s.charAt(0)).append(getTransformed(s.substring(1)).replace("%", ""));
|
||||
res.append(s.charAt(0)).append(transform(s.substring(1)).replace("%", ""));
|
||||
} else
|
||||
res.append(getTransformed(s));
|
||||
res.append(transform(s));
|
||||
f = false;
|
||||
}
|
||||
return res.toString();
|
||||
|
@ -39,9 +35,9 @@ public class YnTransformer extends CachingTransformer {
|
|||
boolean f = true;
|
||||
for (String s : str.split("\\$")) {
|
||||
if (!f) {
|
||||
res.append("$").append(s.charAt(0)).append(getTransformed(s.substring(1)).replace("$", ""));
|
||||
res.append("$").append(s.charAt(0)).append(transform(s.substring(1)).replace("$", ""));
|
||||
} else
|
||||
res.append(getTransformed(s));
|
||||
res.append(transform(s));
|
||||
f = false;
|
||||
}
|
||||
return res.toString();
|
||||
|
@ -50,18 +46,19 @@ public class YnTransformer extends CachingTransformer {
|
|||
boolean f = true;
|
||||
for (String s : str.split("§")) {
|
||||
if (!f) {
|
||||
res.append("§").append(s.charAt(0)).append(getTransformed(s.substring(1)).replace("§", ""));
|
||||
res.append("§").append(s.charAt(0)).append(transform(s.substring(1)).replace("§", ""));
|
||||
} else
|
||||
res.append(getTransformed(s));
|
||||
res.append(transform(s));
|
||||
f = false;
|
||||
}
|
||||
return res.toString();
|
||||
} else {
|
||||
return Break(str);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ModInit.Warn("Failed to transform: " + str + " (" + str.length() + " characters)");
|
||||
ModInit.Warn("Please report this bug with the mod containing the lang file");
|
||||
}
|
||||
catch (Exception e) {
|
||||
Translater.Warn("Failed to transform: " + str + " (" + str.length() + " characters)");
|
||||
Translater.Warn("Please report this bug with the mod containing the lang file");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -71,28 +68,28 @@ public class YnTransformer extends CachingTransformer {
|
|||
if (invalid(str))
|
||||
return str;
|
||||
|
||||
Language startLang = StringUtils.isAlpha(ModInit.cfg.targetLanguage) && ModInit.cfg.targetLanguage.length() == 2
|
||||
? Language.of(ModInit.cfg.targetLanguage)
|
||||
Language startLang = StringUtils.isAlpha(Translater.cfg.targetLanguage) && Translater.cfg.targetLanguage.length() == 2
|
||||
? Language.of(Translater.cfg.targetLanguage)
|
||||
: api.detectionApi().detect(str).orElse(Language.EN);
|
||||
if (invalid(startLang.code())) {
|
||||
ModInit.Warn("Could not detect language for: " + str);
|
||||
ModInit.Warn("Defaulting to EN");
|
||||
Translater.Warn("Could not detect language for: " + str);
|
||||
Translater.Warn("Defaulting to EN");
|
||||
startLang = Language.EN;
|
||||
}
|
||||
String currentState = str;
|
||||
Language currentLang = startLang;
|
||||
for (int i = 0; i < ModInit.cfg.rounds; i++) {
|
||||
for (int i = 0; i < Translater.cfg.rounds; i++) {
|
||||
Language newLang = selectRandom();
|
||||
currentState = api.translationApi().translate(currentState, Direction.of(ModInit.cfg.breakFully ? selectRandom() : currentLang, newLang)).text();
|
||||
currentState = api.translationApi().translate(currentState, Direction.of(Translater.cfg.breakFully ? selectRandom() : currentLang, newLang)).text();
|
||||
currentLang = newLang;
|
||||
}
|
||||
currentState = api.translationApi().translate(currentState, startLang).text();
|
||||
if (ModInit.Cli())
|
||||
ModInit.Log("Transformed: \"" + str + "\" to: \"" + currentState + "\"");
|
||||
if (Translater.Cli())
|
||||
Translater.Log("Transformed: \"" + str + "\" to: \"" + currentState + "\"");
|
||||
return currentState;
|
||||
} catch (Exception e) {
|
||||
ModInit.Warn("Failed to break: " + str + " (" + str.length() + " characters)");
|
||||
ModInit.Warn("Please report this bug with the mod containing the lang file");
|
||||
Translater.Warn("Failed to break: " + str + " (" + str.length() + " characters)");
|
||||
Translater.Warn("Please report this bug with the mod containing the lang file");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -111,4 +108,15 @@ public class YnTransformer extends CachingTransformer {
|
|||
private Language selectRandom() {
|
||||
return languages.stream().skip(rnd.nextInt(languages.size())).findFirst().get();
|
||||
}
|
||||
|
||||
public YnTransformer() {
|
||||
try {
|
||||
rnd = new Random();
|
||||
api = new YTranslateApiImpl(Translater.cfg.key);
|
||||
languages = api.languageApi().all(Language.EN).languages();
|
||||
} catch (Exception e) {
|
||||
Translater.Warn("Failed to initialize transformer. Is your API key valid?");
|
||||
Translater.Warn("Minecraft will continue but issues should be expected");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,44 +2,38 @@
|
|||
"schemaVersion": 1,
|
||||
"id": "translater",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "Translater",
|
||||
"description": "Translates minecraft back and forth",
|
||||
"authors": [
|
||||
"JFronny"
|
||||
],
|
||||
|
||||
"contributors": [],
|
||||
"contact": {},
|
||||
|
||||
"contact": {
|
||||
"website": "https://jfronny.gitlab.io",
|
||||
"repo": "https://gitlab.com/JFronny/translater"
|
||||
},
|
||||
"license": "MIT",
|
||||
"icon": "assets/translater/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"io.gitlab.jfronny.translater.ModInit"
|
||||
"io.gitlab.jfronny.translater.Translater"
|
||||
],
|
||||
"modmenu": [
|
||||
"io.gitlab.jfronny.translater.ModMenu"
|
||||
]
|
||||
|
||||
},
|
||||
"mixins": [
|
||||
"translater.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabricloader": ">=0.9.0+build.204",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
"minecraft": "1.16.1"
|
||||
},
|
||||
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "curseforge",
|
||||
"projectID": 394823
|
||||
},
|
||||
"modmenu:clientsideOnly": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"minVersion": "0.8",
|
||||
"package": "io.gitlab.jfronny.translater.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"plugin": "io.gitlab.jfronny.translater.MixinPlugin",
|
||||
"plugin": "io.gitlab.jfronny.translater.mixin.Plugin",
|
||||
"client": [
|
||||
"MixinLanguage",
|
||||
"MixinMinecraftClient",
|
||||
|
@ -11,7 +11,5 @@
|
|||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"mixins": [
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue