Skip to content

Commit 97615b7

Browse files
committed
Fix path split
1 parent 0ce5389 commit 97615b7

File tree

3 files changed

+26
-35
lines changed

3 files changed

+26
-35
lines changed

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

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,77 +17,69 @@
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,
2424
CallbackInfoReturnable<Map<Identifier, Resource>> cir) {
2525

2626
String currentLang = LangTextureCache.getCurrentLanguage();
27+
2728
if ("en_us".equals(currentLang)) {
2829
return;
2930
}
3031

3132
Map<Identifier, Resource> originalResources = cir.getReturnValue();
32-
if (originalResources.isEmpty()) return;
33+
if (originalResources.isEmpty()) {
34+
return;
35+
}
3336

3437
Map<Identifier, Resource> langSpecificResources = new HashMap<>();
35-
String textureKey = "textures/";
3638

3739
for (Map.Entry<Identifier, Resource> entry : originalResources.entrySet()) {
3840
Identifier originalId = entry.getKey();
41+
String originalPath = originalId.getPath();
3942

40-
if (!allowedPathPredicate.test(originalId)) {
41-
continue;
42-
}
43+
String[] parts = originalPath.split("/", 2);
4344

44-
String path = originalId.getPath();
45-
int idx = path.indexOf(textureKey);
46-
if (idx == -1) {
47-
continue; // 跳过不含 textures/ 的路径
45+
if (parts.length < 2) {
46+
continue;
4847
}
4948

50-
String before = path.substring(0, idx + textureKey.length());
51-
String after = path.substring(idx + textureKey.length());
49+
String topLevelDir = parts[0];
50+
String subPath = parts[1];
5251

5352
// 避免重复,如zh_cn/zh_cn
54-
if (after.startsWith(currentLang + "/")) {
53+
if (subPath.startsWith(currentLang + "/")) {
5554
continue;
5655
}
5756

58-
String langSpecificPath = before + currentLang + '/' + after;
57+
String langSpecificPath = topLevelDir + "/" + currentLang + "/" + subPath;
5958
Identifier langId = new Identifier(originalId.getNamespace(), langSpecificPath);
6059

6160
Boolean cache = LangTextureCache.get(langId);
6261
if (cache != null) {
6362
if (cache) {
64-
try {
65-
((ResourceManager) this).getResource(langId).ifPresent(resource -> {
66-
langSpecificResources.put(originalId, resource);
67-
TextureLocaleRedirector.LOGGER.info("Using cached localized texture: {}", langId);
68-
});
69-
} catch (Exception ignored) {}
63+
this.getResource(langId).ifPresent(resource -> {
64+
langSpecificResources.put(originalId, resource);
65+
TextureLocaleRedirector.LOGGER.info("Using cached localized resource: {}", langId);
66+
});
7067
}
7168
continue;
7269
}
7370

74-
try {
75-
Optional<Resource> langResource = ((ResourceManager) this).getResource(langId);
76-
if (langResource.isPresent()) {
77-
langSpecificResources.put(originalId, langResource.get());
78-
LangTextureCache.put(langId, true);
79-
TextureLocaleRedirector.LOGGER.info("Found and cached localized texture: {}", langId);
80-
} else {
81-
LangTextureCache.put(langId, false);
82-
}
83-
} 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 {
8477
LangTextureCache.put(langId, false);
85-
TextureLocaleRedirector.LOGGER.warn("Failed to load localized texture: {}", langId, e);
8678
}
8779
}
8880

8981
if (!langSpecificResources.isEmpty()) {
9082
originalResources.putAll(langSpecificResources);
9183
}
9284
}
93-
}
85+
}

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 <1.20.5"
2827
}
2928
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ enabled_platforms=fabric,forge,neoforge
66
yarn_mappings=1.20.4+build.3
77

88
archives_base_name=Texture-Locale-Redirector
9-
mod_version=1.3.0
9+
mod_version=1.4.0
1010
maven_group=com.wulian.texturelocaleredirector
1111

12-
forge_version=49.2.0
12+
forge_version=49.2.2
1313
neoforge_version=20.4.250
1414

1515
fabric_loader_version=0.17.2

0 commit comments

Comments
 (0)