├── .gitignore ├── LICENSE ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src └── main ├── java └── youyihj │ └── nolocalizationconflict │ ├── ILocaleExtension.java │ ├── LanguageEntry.java │ ├── LocalizationMap.java │ ├── NoLocalizationConflict.java │ ├── core │ └── NoLocalizationConflictPlugin.java │ └── mixins │ ├── MixinBlock.java │ ├── MixinItem.java │ ├── MixinLanguageMap.java │ └── MixinLocale.java └── resources ├── META-INF └── nolocalizationconflict_at.cfg ├── mcmod.info ├── mixins.nolocalizationconflict.json └── pack.mcmeta /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 youyihj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { url = "https://maven.minecraftforge.net/" } 4 | maven { 5 | name = "sponge" 6 | url = "https://repo.spongepowered.org/maven" 7 | } 8 | } 9 | dependencies { 10 | classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' 11 | classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' 12 | } 13 | 14 | } 15 | apply plugin: 'net.minecraftforge.gradle.forge' 16 | apply plugin: 'org.spongepowered.mixin' 17 | //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. 18 | 19 | 20 | version = "1.4" 21 | group = "youyihj.nolocalizationconflict" // http://maven.apache.org/guides/mini/guide-naming-conventions.html 22 | archivesBaseName = "NoLocalizationConflict" 23 | 24 | sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. 25 | compileJava { 26 | sourceCompatibility = targetCompatibility = '1.8' 27 | } 28 | 29 | minecraft { 30 | version = "1.12.2-14.23.5.2847" 31 | runDir = "run" 32 | 33 | // the mappings can be changed at any time, and must be in the following format. 34 | // snapshot_YYYYMMDD snapshot are built nightly. 35 | // stable_# stables are built at the discretion of the MCP team. 36 | // Use non-default mappings at your own risk. they may not always work. 37 | // simply re-run your setup task after changing the mappings to update your workspace. 38 | mappings = "snapshot_20171003" 39 | // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. 40 | 41 | def args = [ 42 | "-Dfml.coreMods.load=youyihj.nolocalizationconflict.core.NoLocalizationConflictPlugin", 43 | "-Dmixin.debug.export=true", 44 | '-Dmixin.hotSwap=true', 45 | '-Dmixin.checks.interfaces=true' 46 | ] 47 | clientJvmArgs.addAll(args) 48 | serverJvmArgs.addAll(args) 49 | } 50 | 51 | repositories { 52 | maven { 53 | name = "sponge" 54 | url = "https://repo.spongepowered.org/maven" 55 | } 56 | maven { 57 | url "https://maven.cleanroommc.com" 58 | } 59 | } 60 | 61 | dependencies { 62 | deobfCompile ("zone.rong:mixinbooter:4.2") 63 | 64 | compile('org.spongepowered:mixin:0.8-SNAPSHOT') { 65 | exclude module: 'guava' 66 | exclude module: 'commons-io' 67 | exclude module: 'gson' 68 | } 69 | // you may put jars on which you depend on in ./libs 70 | // or you may define them like so.. 71 | //compile "some.group:artifact:version:classifier" 72 | //compile "some.group:artifact:version" 73 | 74 | // real examples 75 | //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env 76 | //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env 77 | 78 | // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. 79 | //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' 80 | 81 | // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, 82 | // except that these dependencies get remapped to your current MCP mappings 83 | //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' 84 | //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' 85 | 86 | // for more info... 87 | // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html 88 | // http://www.gradle.org/docs/current/userguide/dependency_management.html 89 | 90 | } 91 | 92 | processResources { 93 | // this will ensure that this task is redone when the versions change. 94 | inputs.property "version", project.version 95 | inputs.property "mcversion", project.minecraft.version 96 | 97 | // replace stuff in mcmod.info, nothing else 98 | from(sourceSets.main.resources.srcDirs) { 99 | include 'mcmod.info' 100 | 101 | // replace version and mcversion 102 | expand 'version':project.version, 'mcversion':project.minecraft.version 103 | } 104 | 105 | // copy everything else except the mcmod.info 106 | from(sourceSets.main.resources.srcDirs) { 107 | exclude 'mcmod.info' 108 | } 109 | } 110 | 111 | mixin { 112 | add sourceSets.main, "mixins.nolocalizationconflict.refmap.json" 113 | } 114 | 115 | jar { 116 | manifest { 117 | attributes([ 118 | 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker', 119 | "FMLCorePlugin": "youyihj.nolocalizationconflict.core.NoLocalizationConflictPlugin", 120 | "FMLCorePluginContainsFMLMod": true, 121 | "ForceLoadAsMod": true, 122 | 'FMLAT': 'nolocalizationconflict_at.cfg' 123 | ]) 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Sets default memory used for gradle commands. Can be overridden by user or command line properties. 2 | # This is required to provide enough memory for the Minecraft decompilation process. 3 | org.gradle.jvmargs=-Xmx3G 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/friendlyhj/NoLocalizationConflict/6dfdd60c80411e3263c0975539512e5ddd932fea/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 14 12:28:28 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/ILocaleExtension.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict; 2 | 3 | import net.minecraft.client.resources.Locale; 4 | 5 | /** 6 | * @author youyihj 7 | */ 8 | public interface ILocaleExtension { 9 | String nlc$getCurrentModifyingMod(); 10 | 11 | Locale nlc$getSelf(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/LanguageEntry.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | public class LanguageEntry { 10 | private String defaultValue; 11 | private final String firstDomain; 12 | private final Map conflictValues = new HashMap<>(); 13 | private boolean conflicted; 14 | 15 | public LanguageEntry(String defaultValue, String firstDomain) { 16 | this.defaultValue = defaultValue; 17 | this.firstDomain = firstDomain; 18 | } 19 | 20 | public void put(String value, String domain) { 21 | if (firstDomain.equals(domain)) { 22 | defaultValue = value; 23 | } else { 24 | conflictValues.put(domain, value); 25 | conflicted = true; 26 | } 27 | } 28 | 29 | public String get() { 30 | if (!conflicted) { 31 | return defaultValue; 32 | } else { 33 | return conflictValues.getOrDefault(NoLocalizationConflict.getCallerMod(), defaultValue); 34 | } 35 | } 36 | 37 | public String get(String domain) { 38 | if (!conflicted) { 39 | return defaultValue; 40 | } else { 41 | return conflictValues.getOrDefault(domain, defaultValue); 42 | } 43 | } 44 | 45 | public String getDefaultValue() { 46 | return defaultValue; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/LocalizationMap.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict; 2 | 3 | import java.util.*; 4 | import java.util.stream.Collectors; 5 | 6 | /** 7 | * @author youyihj 8 | */ 9 | public class LocalizationMap extends AbstractMap { 10 | private final ILocaleExtension locale; 11 | private final Map localization = new HashMap<>(); 12 | 13 | public LocalizationMap(ILocaleExtension locale) { 14 | this.locale = locale; 15 | } 16 | 17 | public LocalizationMap copy() { 18 | LocalizationMap copy = new LocalizationMap(locale); 19 | copy.localization.putAll(this.localization); 20 | return copy; 21 | } 22 | 23 | @Override 24 | public String put(String key, String value) { 25 | LanguageEntry entry = localization.get(key); 26 | if (entry == null) { 27 | localization.put(key, new LanguageEntry(value, locale.nlc$getCurrentModifyingMod())); 28 | return null; 29 | } else { 30 | entry.put(value, locale.nlc$getCurrentModifyingMod()); 31 | return entry.getDefaultValue(); 32 | } 33 | } 34 | 35 | @Override 36 | public void clear() { 37 | localization.clear(); 38 | } 39 | 40 | @Override 41 | public String get(Object k) { 42 | LanguageEntry entry = localization.get(k); 43 | return entry == null ? null : entry.get(); 44 | } 45 | 46 | public String getValueExplicitMod(String key, String mod) { 47 | LanguageEntry entry = localization.get(key); 48 | return entry == null ? null : entry.get(mod); 49 | } 50 | 51 | @Override 52 | public Set> entrySet() { 53 | return localization.entrySet().stream() 54 | .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDefaultValue())) 55 | .entrySet(); 56 | } 57 | 58 | @Override 59 | public boolean containsKey(Object key) { 60 | return localization.containsKey(key); 61 | } 62 | 63 | @Override 64 | public int size() { 65 | return localization.size(); 66 | } 67 | 68 | @Override 69 | public Collection values() { 70 | return localization.values().stream().map(LanguageEntry::getDefaultValue).collect(Collectors.toList()); 71 | } 72 | 73 | @Override 74 | public Set keySet() { 75 | return localization.keySet(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/NoLocalizationConflict.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict; 2 | 3 | import net.minecraftforge.fml.common.Loader; 4 | import net.minecraftforge.fml.common.Mod; 5 | import net.minecraftforge.fml.common.ModContainer; 6 | import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; 7 | import org.apache.logging.log4j.Logger; 8 | 9 | import java.net.MalformedURLException; 10 | import java.net.URL; 11 | import java.security.CodeSource; 12 | import java.security.ProtectionDomain; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | import java.util.Optional; 16 | 17 | /** 18 | * @author youyihj 19 | */ 20 | @Mod(modid = NoLocalizationConflict.MODID, name = NoLocalizationConflict.NAME, version = NoLocalizationConflict.VERSION, dependencies = NoLocalizationConflict.DEPENDENCIES) 21 | public class NoLocalizationConflict { 22 | public static final String MODID = "nolocalizationconflict"; 23 | public static final String NAME = "No Localization Conflict"; 24 | public static final String VERSION = "1.4"; 25 | public static final String DEPENDENCIES = "required-after:mixinbooter@[4.2,)"; 26 | public static final Map pathToModMap = new HashMap<>(); 27 | public static Logger logger; 28 | 29 | @Mod.EventHandler 30 | public void preInit(FMLPreInitializationEvent event) { 31 | logger = event.getModLog(); 32 | Loader.instance().getActiveModList().forEach(mod -> { 33 | try { 34 | URL url = mod.getSource().toURI().toURL(); 35 | if (!pathToModMap.containsKey(url)) { 36 | pathToModMap.put(url, mod); 37 | } 38 | } catch (MalformedURLException e) { 39 | logger.throwing(e); 40 | } 41 | }); 42 | } 43 | 44 | public static String getCallerMod() { 45 | StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); 46 | for (StackTraceElement stackTraceElement : stackTrace) { 47 | String className = stackTraceElement.getClassName(); 48 | Class clazz; 49 | try { 50 | clazz = Class.forName(className, false, NoLocalizationConflict.class.getClassLoader()); 51 | } catch (ClassNotFoundException e) { 52 | continue; 53 | } 54 | Optional url = Optional.of(clazz).map(Class::getProtectionDomain).map(ProtectionDomain::getCodeSource).map(CodeSource::getLocation); 55 | if (!url.isPresent()) continue; 56 | ModContainer mod = pathToModMap.get(url.get()); 57 | if (mod == null || mod.getModId().equals(NoLocalizationConflict.MODID)) continue; 58 | return mod.getModId(); 59 | } 60 | return ""; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/core/NoLocalizationConflictPlugin.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict.core; 2 | 3 | import net.minecraftforge.fml.relauncher.CoreModManager; 4 | import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; 5 | import org.apache.logging.log4j.LogManager; 6 | import org.spongepowered.asm.launch.MixinBootstrap; 7 | import org.spongepowered.asm.mixin.Mixins; 8 | import zone.rong.mixinbooter.IEarlyMixinLoader; 9 | 10 | import javax.annotation.Nullable; 11 | import java.io.File; 12 | import java.net.URISyntaxException; 13 | import java.net.URL; 14 | import java.security.CodeSource; 15 | import java.util.Collections; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | /** 20 | * @author youyihj 21 | */ 22 | @IFMLLoadingPlugin.Name("no_localization_conflict_core") 23 | @IFMLLoadingPlugin.MCVersion("1.12.2") 24 | public class NoLocalizationConflictPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { 25 | 26 | @Override 27 | public String[] getASMTransformerClass() { 28 | return new String[0]; 29 | } 30 | 31 | @Override 32 | public String getModContainerClass() { 33 | return null; 34 | } 35 | 36 | @Nullable 37 | @Override 38 | public String getSetupClass() { 39 | return null; 40 | } 41 | 42 | @Override 43 | public void injectData(Map data) { 44 | 45 | } 46 | 47 | @Override 48 | public String getAccessTransformerClass() { 49 | return null; 50 | } 51 | 52 | @Override 53 | public List getMixinConfigs() { 54 | return Collections.singletonList("mixins.nolocalizationconflict.json"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/mixins/MixinBlock.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict.mixins; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.util.text.translation.LanguageMap; 5 | import net.minecraftforge.registries.IForgeRegistryEntry; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.Shadow; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 11 | import youyihj.nolocalizationconflict.LocalizationMap; 12 | 13 | import java.util.Map; 14 | 15 | /** 16 | * @author youyihj 17 | */ 18 | @Mixin(Block.class) 19 | public abstract class MixinBlock extends IForgeRegistryEntry.Impl { 20 | @Shadow 21 | public abstract String getUnlocalizedName(); 22 | 23 | @Inject(method = "getLocalizedName", at = @At("HEAD"), cancellable = true) 24 | public void getNameBasedOnDomain(CallbackInfoReturnable cir) { 25 | Map languageList = LanguageMap.getInstance().languageList; 26 | String key = this.getUnlocalizedName() + ".name"; 27 | String value; 28 | if (languageList instanceof LocalizationMap) { 29 | value = ((LocalizationMap) languageList).getValueExplicitMod(key, this.getRegistryName().getResourceDomain()); 30 | } else { 31 | value = languageList.get(key); 32 | } 33 | cir.setReturnValue(value == null ? key : value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/mixins/MixinItem.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict.mixins; 2 | 3 | import net.minecraft.item.Item; 4 | import net.minecraft.item.ItemStack; 5 | import net.minecraft.util.text.translation.LanguageMap; 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.injection.At; 8 | import org.spongepowered.asm.mixin.injection.Inject; 9 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 10 | import youyihj.nolocalizationconflict.LocalizationMap; 11 | 12 | import java.util.Map; 13 | 14 | /** 15 | * @author youyihj 16 | */ 17 | @Mixin(Item.class) 18 | public abstract class MixinItem { 19 | 20 | @Inject(method = "getItemStackDisplayName", at = @At(value = "HEAD"), cancellable = true) 21 | public void getNameBasedOnDomain(ItemStack stack, CallbackInfoReturnable cir) { 22 | Map languageList = LanguageMap.getInstance().languageList; 23 | Item item = stack.isEmpty() ? ((Item) ((Object) this)) : stack.getItem(); 24 | String key = item.getUnlocalizedNameInefficiently(stack) + ".name"; 25 | String value; 26 | if (languageList instanceof LocalizationMap) { 27 | value = ((LocalizationMap) languageList).getValueExplicitMod(key, stack.getItem().getRegistryName().getResourceDomain()); 28 | } else { 29 | value = languageList.get(key); 30 | } 31 | cir.setReturnValue(value == null ? key : value); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/mixins/MixinLanguageMap.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict.mixins; 2 | 3 | import net.minecraft.util.text.translation.LanguageMap; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.Inject; 7 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 8 | import youyihj.nolocalizationconflict.LocalizationMap; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * @author youyihj 14 | */ 15 | @Mixin(LanguageMap.class) 16 | public abstract class MixinLanguageMap { 17 | 18 | @Inject(method = "replaceWith", at = @At("HEAD"), cancellable = true) 19 | private static void setList(Map map, CallbackInfo ci) { 20 | if (map.getClass() == LocalizationMap.class) { 21 | LanguageMap.getInstance().languageList = ((LocalizationMap) map).copy(); 22 | } 23 | LanguageMap.getInstance().lastUpdateTimeInMilliseconds = System.currentTimeMillis(); 24 | ci.cancel(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/youyihj/nolocalizationconflict/mixins/MixinLocale.java: -------------------------------------------------------------------------------- 1 | package youyihj.nolocalizationconflict.mixins; 2 | 3 | import net.minecraft.client.resources.IResource; 4 | import net.minecraft.client.resources.Locale; 5 | import org.spongepowered.asm.mixin.Mixin; 6 | import org.spongepowered.asm.mixin.Shadow; 7 | import org.spongepowered.asm.mixin.Unique; 8 | import org.spongepowered.asm.mixin.injection.At; 9 | import org.spongepowered.asm.mixin.injection.Inject; 10 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 11 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 12 | import youyihj.nolocalizationconflict.ILocaleExtension; 13 | import youyihj.nolocalizationconflict.LocalizationMap; 14 | 15 | import java.util.Iterator; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | /** 20 | * @author youyihj 21 | */ 22 | @Mixin(Locale.class) 23 | public abstract class MixinLocale implements ILocaleExtension { 24 | 25 | @Shadow 26 | Map properties; 27 | 28 | @Unique 29 | private String nlc$currentModifyingMod; 30 | 31 | @Inject(method = "", at = @At(value = "RETURN")) 32 | private void setProperties(CallbackInfo ci) { 33 | properties = new LocalizationMap(this); 34 | } 35 | 36 | @Inject(method = "loadLocaleData(Ljava/util/List;)V", 37 | at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/IResource;getInputStream()Ljava/io/InputStream;"), 38 | locals = LocalCapture.CAPTURE_FAILHARD 39 | ) 40 | private void setCurrentModifyingMod(List resourcesList, CallbackInfo ci, Iterator resourceIterator, IResource resource) { 41 | nlc$currentModifyingMod = resource.getResourceLocation().getResourceDomain(); 42 | } 43 | 44 | @Override 45 | public Locale nlc$getSelf() { 46 | return ((Locale) ((Object) this)); 47 | } 48 | 49 | @Override 50 | public String nlc$getCurrentModifyingMod() { 51 | return nlc$currentModifyingMod; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/nolocalizationconflict_at.cfg: -------------------------------------------------------------------------------- 1 | public-f net.minecraft.util.text.translation.LanguageMap field_74816_c # languageList 2 | public net.minecraft.util.text.translation.LanguageMap field_150511_e # lastUpdateTimeInMilliseconds 3 | public net.minecraft.util.text.translation.LanguageMap func_74808_a()Lnet/minecraft/util/text/translation/LanguageMap; # getInstance -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "nolocalizationconflict", 4 | "name": "No Localization Conflict", 5 | "description": "Avoid localization conflict", 6 | "version": "${version}", 7 | "mcversion": "${mcversion}", 8 | "url": "", 9 | "updateUrl": "", 10 | "authorList": ["youyihj"], 11 | "logoFile": "", 12 | "screenshots": [], 13 | "dependencies": [] 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /src/main/resources/mixins.nolocalizationconflict.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "compatibilityLevel": "JAVA_8", 4 | "package": "youyihj.nolocalizationconflict.mixins", 5 | "minVersion": "0.7.11", 6 | "target": "@env(INIT)", 7 | "refmap": "mixins.nolocalizationconflict.refmap.json", 8 | "priority": 0, 9 | "mixins": [ 10 | "MixinBlock", 11 | "MixinItem", 12 | "MixinLanguageMap" 13 | ], 14 | "client": [ 15 | "MixinLocale" 16 | ] 17 | } -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "examplemod resources", 4 | "pack_format": 3, 5 | "_comment": "A pack_format of 3 should be used starting with Minecraft 1.11. All resources, including language files, should be lowercase (eg: en_us.lang). A pack_format of 2 will load your mod resources with LegacyV2Adapter, which requires language files to have uppercase letters (eg: en_US.lang)." 6 | } 7 | } 8 | --------------------------------------------------------------------------------