11package com .wulian .texturelocaleredirector .mixin ;
22
3- import com .wulian .texturelocaleredirector .LangTextureCache ;
3+ import com .wulian .texturelocaleredirector .TranslatableTextureCache ;
44import com .wulian .texturelocaleredirector .TextureLocaleRedirector ;
5- import net .minecraft .resource .NamespaceResourceManager ;
6- import net .minecraft .resource .Resource ;
7- import net .minecraft .resource .ResourceManager ;
8- //? if >=1.21.11 {
5+ import net .minecraft .server .packs .resources .FallbackResourceManager ;
6+ import net .minecraft .server .packs .resources .Resource ;
7+ import net .minecraft .server .packs .resources .ResourceManager ;
98import net .minecraft .resources .Identifier ;
10- //?} else if >=1.20.6 && <=1.21.10 {
11- /*import net.minecraft.resources.ResourceLocation;
12- */ //?}
139import org .spongepowered .asm .mixin .Mixin ;
1410import org .spongepowered .asm .mixin .Unique ;
1511import org .spongepowered .asm .mixin .injection .At ;
2117import java .util .Optional ;
2218import java .util .function .Predicate ;
2319
24- @ Mixin (NamespaceResourceManager .class )
25- public abstract class NamespaceResourceManagerMixin implements ResourceManager {
20+ @ Mixin (FallbackResourceManager .class )
21+ public abstract class FallbackResourceManagerMixin implements ResourceManager {
2622
27- @ Inject (method = "findResources " , at = @ At ("RETURN" ))
28- private void onFindResources (
23+ @ Inject (method = "listResources " , at = @ At ("RETURN" ))
24+ private void onListResources (
2925 String startingPath ,
3026 Predicate <
31- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/
27+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/
3228 > allowedPathPredicate ,
3329 CallbackInfoReturnable <
3430 Map <
35- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/ ,
31+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/ ,
3632 Resource
3733 >
3834 > cir
3935 ) {
4036
41- if ("en_us" .equals (LangTextureCache .getCurrentLanguage ())) {
37+ if ("en_us" .equals (TranslatableTextureCache .getCurrentLanguage ())) {
4238 return ;
4339 }
4440
4541 Map <
46- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/ ,
42+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/ ,
4743 Resource
4844 > originalResources = cir .getReturnValue ();
4945
@@ -52,23 +48,23 @@ private void onFindResources(
5248 }
5349
5450 Map <
55- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/ ,
51+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/ ,
5652 Resource
5753 > langSpecificResources = new HashMap <>();
5854
5955 for (Map .Entry <
60- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/ ,
56+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/ ,
6157 Resource
6258 > entry : originalResources .entrySet ()) {
6359
6460 var originalId = entry .getKey ();
65- var langId = LangTextureCache .getLocalizedId (originalId );
61+ var langId = TranslatableTextureCache .getLocalizedId (originalId );
6662
6763 if (langId == null ) {
6864 continue ;
6965 }
7066
71- Optional <Resource > langResource = this .checkResourceAndCache (langId , originalId );
67+ Optional <Resource > langResource = this .textureLocaleRedirector$ checkResourceAndCache (langId , originalId );
7268 langResource .ifPresent (resource -> langSpecificResources .put (originalId , resource ));
7369 }
7470
@@ -79,27 +75,27 @@ private void onFindResources(
7975
8076 @ Inject (method = "getResource" , at = @ At ("HEAD" ), cancellable = true )
8177 private void onGetResource (
82- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/ id ,
78+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/ id ,
8379 CallbackInfoReturnable <Optional <Resource >> cir
8480 ) {
8581
86- var langId = LangTextureCache .getLocalizedId (id );
82+ var langId = TranslatableTextureCache .getLocalizedId (id );
8783 if (langId == null ) {
8884 return ;
8985 }
9086
91- Optional <Resource > langResource = this .checkResourceAndCache (langId , id );
87+ Optional <Resource > langResource = this .textureLocaleRedirector$ checkResourceAndCache (langId , id );
9288 if (langResource .isPresent ()) {
9389 cir .setReturnValue (langResource );
9490 }
9591 }
9692
9793 @ Unique
98- public Optional <Resource > checkResourceAndCache (
99- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/ langId ,
100- /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*ResourceLocation*/ /*?}*/ originalId
94+ public Optional <Resource > textureLocaleRedirector$ checkResourceAndCache (
95+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/ langId ,
96+ /*? if >=1.21.11 {*/ Identifier /*?} else {*/ /*Identifier */ /*?}*/ originalId
10197 ) {
102- Boolean cache = LangTextureCache .get (langId );
98+ Boolean cache = TranslatableTextureCache .get (langId );
10399
104100 if (cache != null ) {
105101 if (cache ) {
@@ -112,11 +108,11 @@ public Optional<Resource> checkResourceAndCache(
112108 Optional <Resource > langResource = this .getResource (langId );
113109
114110 if (langResource .isPresent ()) {
115- LangTextureCache .put (langId , true );
111+ TranslatableTextureCache .put (langId , true );
116112 TextureLocaleRedirector .LOGGER .info ("Redirected resource {} -> {}" , originalId , langId );
117113 return langResource ;
118114 } else {
119- LangTextureCache .put (langId , false );
115+ TranslatableTextureCache .put (langId , false );
120116 return Optional .empty ();
121117 }
122118 }
0 commit comments