Skip to content

Commit bfd3417

Browse files
committed
Fix path split
1 parent 7483305 commit bfd3417

File tree

3 files changed

+24
-31
lines changed

3 files changed

+24
-31
lines changed

common/src/main/java/com/wulian/texturelocaleredirector/mixin/NamespaceResourceManagerMixin.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import 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

fabric/src/main/resources/fabric.mod.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"texturelocaleredirector.mixins.json"
2424
],
2525
"depends": {
26-
"fabric": "*",
2726
"minecraft": ">=1.20.5 <1.21"
2827
}
2928
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ yarn_mappings=1.20.6+build.3
77
yarn_patch=1.20.6+build.4
88

99
archives_base_name=Texture-Locale-Redirector
10-
mod_version=1.3.0
10+
mod_version=1.4.0
1111
maven_group=com.wulian.texturelocaleredirector
1212

13-
forge_version=50.2.1
13+
forge_version=50.2.2
1414
neoforge_version=20.6.138
1515

1616
fabric_loader_version=0.17.2

0 commit comments

Comments
 (0)