1717import java .util .function .Predicate ;
1818
1919@ Mixin (NamespaceResourceManager .class )
20- public abstract class NamespaceResourceManagerMixin {
20+ public abstract class NamespaceResourceManagerMixin implements ResourceManager {
2121
2222 @ Inject (method = "findResources" , at = @ At ("RETURN" ))
2323 private void onFindResources (String startingPath , Predicate <Identifier > allowedPathPredicate ,
@@ -30,57 +30,51 @@ private void onFindResources(String startingPath, Predicate<Identifier> allowedP
3030 }
3131
3232 Map <Identifier , Resource > originalResources = cir .getReturnValue ();
33- if (originalResources .isEmpty ()) return ;
33+ if (originalResources .isEmpty ()) {
34+ return ;
35+ }
3436
3537 Map <Identifier , Resource > langSpecificResources = new HashMap <>();
36- String texturePrefix = "textures/" ;
3738
3839 for (Map .Entry <Identifier , Resource > entry : originalResources .entrySet ()) {
3940 Identifier originalId = entry .getKey ();
41+ String originalPath = originalId .getPath ();
42+
43+ String [] parts = originalPath .split ("/" , 2 );
4044
41- if (! allowedPathPredicate . test ( originalId ) ) {
45+ if (parts . length < 2 ) {
4246 continue ;
4347 }
4448
45- String originalPath = originalId .getPath ();
46- int index = originalPath .indexOf (texturePrefix ) + texturePrefix .length ();
47-
48- String before = originalPath .substring (0 , index );
49- String after = originalPath .substring (index );
49+ String topLevelDir = parts [0 ];
50+ String subPath = parts [1 ];
5051
5152 // 避免重复,如zh_cn/zh_cn
52- if (after .startsWith (currentLang + "/" )) {
53+ if (subPath .startsWith (currentLang + "/" )) {
5354 continue ;
5455 }
5556
56- String langSpecificPath = before + currentLang + '/' + after ;
57+ String langSpecificPath = topLevelDir + "/" + currentLang + "/" + subPath ;
5758 Identifier langId = Identifier .of (originalId .getNamespace (), langSpecificPath );
5859
5960 Boolean cache = LangTextureCache .get (langId );
6061 if (cache != null ) {
6162 if (cache ) {
62- try {
63- ((ResourceManager ) this ).getResource (langId ).ifPresent (resource -> {
64- langSpecificResources .put (originalId , resource );
65- TextureLocaleRedirector .LOGGER .info ("Using cached localized texture: {}" , langId );
66- });
67- } catch (Exception ignored ) {}
63+ this .getResource (langId ).ifPresent (resource -> {
64+ langSpecificResources .put (originalId , resource );
65+ TextureLocaleRedirector .LOGGER .info ("Using cached localized resource: {}" , langId );
66+ });
6867 }
6968 continue ;
7069 }
7170
72- try {
73- Optional <Resource > langResource = ((ResourceManager ) this ).getResource (langId );
74- if (langResource .isPresent ()) {
75- langSpecificResources .put (originalId , langResource .get ());
76- LangTextureCache .put (langId , true );
77- TextureLocaleRedirector .LOGGER .info ("Found and cached localized texture: {}" , langId );
78- } else {
79- LangTextureCache .put (langId , false );
80- }
81- } catch (Exception e ) {
71+ Optional <Resource > langResource = this .getResource (langId );
72+ if (langResource .isPresent ()) {
73+ langSpecificResources .put (originalId , langResource .get ());
74+ LangTextureCache .put (langId , true );
75+ TextureLocaleRedirector .LOGGER .info ("Found and cached localized resource: {}" , langId );
76+ } else {
8277 LangTextureCache .put (langId , false );
83- TextureLocaleRedirector .LOGGER .warn ("Failed to load localized texture: {}" , langId , e );
8478 }
8579 }
8680
0 commit comments