Skip to content

Commit fdd105e

Browse files
committed
Fix path split
1 parent 7672743 commit fdd105e

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: 22 additions & 29 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,61 +30,54 @@ 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

87-
//noinspection ConstantConditions
8881
if (!langSpecificResources.isEmpty()) {
8982
originalResources.putAll(langSpecificResources);
9083
}

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

gradle.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
org.gradle.jvmargs=-Xmx4g
22

33
minecraft_version=1.21.1
4-
enabled_platforms=fabric,forge,neoforge
4+
enabled_platforms=fabric,neoforge
55

66
yarn_mappings=1.21.1+build.3
77
yarn_patch=1.21+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=52.1.3
14-
neoforge_version=21.1.206
13+
neoforge_version=21.1.209
1514
conditional_mixin_version=0.6.4
1615

1716
fabric_loader_version=0.17.2
1817
fabric_api_version=0.116.6+1.21.1
1918

20-
ftb_quests_version=2101.1.14
19+
ftb_quests_version=2101.1.16

0 commit comments

Comments
 (0)