-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mixin to locale and I18n to access the key map directly to fix LangKey
- Loading branch information
Showing
6 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package gregtech.api.mui; | ||
|
||
import net.minecraft.client.resources.Locale; | ||
|
||
public interface LocaleAccessor { | ||
|
||
String gregtech$getRawKey(String s); | ||
|
||
ThreadLocal<LocaleAccessor> accessor = new ThreadLocal<>(); | ||
|
||
static String getRawKey(String s) { | ||
if (accessor.get() == null) return s; | ||
return accessor.get().gregtech$getRawKey(s); | ||
} | ||
|
||
static void setLocale(Locale locale) { | ||
accessor.set((LocaleAccessor) locale); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gregtech.mixins.minecraft; | ||
|
||
import gregtech.api.mui.LocaleAccessor; | ||
|
||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.client.resources.Locale; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(I18n.class) | ||
public abstract class L18nMixin { | ||
|
||
@Inject(method = "setLocale", at = @At("HEAD")) | ||
private static void getLocale(Locale i18nLocaleIn, CallbackInfo ci) { | ||
LocaleAccessor.setLocale(i18nLocaleIn); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package gregtech.mixins.minecraft; | ||
|
||
import gregtech.api.mui.LocaleAccessor; | ||
|
||
import net.minecraft.client.resources.Locale; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(Locale.class) | ||
public abstract class LocaleMixin implements LocaleAccessor { | ||
|
||
@Shadow | ||
Map<String, String> properties; | ||
|
||
@Override | ||
public String gregtech$getRawKey(String s) { | ||
return this.properties.get(s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gregtech.mixins.mui2; | ||
|
||
import gregtech.api.mui.LocaleAccessor; | ||
|
||
import com.cleanroommc.modularui.drawable.text.BaseKey; | ||
import com.cleanroommc.modularui.drawable.text.LangKey; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(value = LangKey.class, remap = false) | ||
public abstract class LangKeyMixin extends BaseKey { | ||
|
||
@Redirect(method = "getFormatted", | ||
at = @At(value = "INVOKE", | ||
target = "Lnet/minecraft/client/resources/I18n;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;")) | ||
public String getTranslateKey(String translateKey, Object[] parameters) { | ||
return LocaleAccessor.getRawKey(translateKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
"maxShiftBy": 10 | ||
}, | ||
"mixins": [], | ||
"client": [], | ||
"client": [ | ||
"LangKeyMixin" | ||
], | ||
"server": [] | ||
} |