File tree Expand file tree Collapse file tree 6 files changed +86
-1
lines changed
Expand file tree Collapse file tree 6 files changed +86
-1
lines changed Original file line number Diff line number Diff line change 1+ package gregtech .api .mui ;
2+
3+ import net .minecraft .client .resources .Locale ;
4+
5+ public interface LocaleAccessor {
6+
7+ String gregtech$getRawKey (String s );
8+
9+ ThreadLocal <LocaleAccessor > accessor = new ThreadLocal <>();
10+
11+ static String getRawKey (String s ) {
12+ if (accessor .get () == null ) return s ;
13+ return accessor .get ().gregtech$getRawKey (s );
14+ }
15+
16+ static void setLocale (Locale locale ) {
17+ accessor .set ((LocaleAccessor ) locale );
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package gregtech .mixins .minecraft ;
2+
3+ import gregtech .api .mui .LocaleAccessor ;
4+
5+ import net .minecraft .client .resources .I18n ;
6+ import net .minecraft .client .resources .Locale ;
7+
8+ import org .spongepowered .asm .mixin .Mixin ;
9+ import org .spongepowered .asm .mixin .injection .At ;
10+ import org .spongepowered .asm .mixin .injection .Inject ;
11+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
12+
13+ @ Mixin (I18n .class )
14+ public abstract class L18nMixin {
15+
16+ @ Inject (method = "setLocale" , at = @ At ("HEAD" ))
17+ private static void getLocale (Locale i18nLocaleIn , CallbackInfo ci ) {
18+ LocaleAccessor .setLocale (i18nLocaleIn );
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package gregtech .mixins .minecraft ;
2+
3+ import gregtech .api .mui .LocaleAccessor ;
4+
5+ import net .minecraft .client .resources .Locale ;
6+
7+ import org .spongepowered .asm .mixin .Mixin ;
8+ import org .spongepowered .asm .mixin .Shadow ;
9+
10+ import java .util .Map ;
11+
12+ @ Mixin (Locale .class )
13+ public abstract class LocaleMixin implements LocaleAccessor {
14+
15+ @ Shadow
16+ Map <String , String > properties ;
17+
18+ @ Override
19+ public String gregtech$getRawKey (String s ) {
20+ return this .properties .get (s );
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package gregtech .mixins .mui2 ;
2+
3+ import gregtech .api .mui .LocaleAccessor ;
4+
5+ import com .cleanroommc .modularui .drawable .text .BaseKey ;
6+ import com .cleanroommc .modularui .drawable .text .LangKey ;
7+ import org .spongepowered .asm .mixin .Mixin ;
8+ import org .spongepowered .asm .mixin .injection .At ;
9+ import org .spongepowered .asm .mixin .injection .Redirect ;
10+
11+ @ Mixin (value = LangKey .class , remap = false )
12+ public abstract class LangKeyMixin extends BaseKey {
13+
14+ @ Redirect (method = "getFormatted" ,
15+ at = @ At (value = "INVOKE" ,
16+ target = "Lnet/minecraft/client/resources/I18n;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;" ))
17+ public String getTranslateKey (String translateKey , Object [] parameters ) {
18+ return LocaleAccessor .getRawKey (translateKey );
19+ }
20+ }
Original file line number Diff line number Diff line change 1717 "client" : [
1818 " BlockMixin" ,
1919 " EntityRendererMixin" ,
20+ " L18nMixin" ,
2021 " LayerArmorBaseMixin" ,
2122 " LayerCustomHeadMixin" ,
23+ " LocaleMixin" ,
2224 " RecipeRepairItemMixin" ,
2325 " RegionRenderCacheBuilderMixin" ,
2426 " RenderChunkMixin" ,
Original file line number Diff line number Diff line change 88 "maxShiftBy" : 10
99 },
1010 "mixins" : [],
11- "client" : [],
11+ "client" : [
12+ " LangKeyMixin"
13+ ],
1214 "server" : []
1315}
You can’t perform that action at this time.
0 commit comments