Skip to content

Commit 1416521

Browse files
committed
修复kubejs环境下加载路径的问题
1 parent eedc893 commit 1416521

File tree

6 files changed

+30
-49
lines changed

6 files changed

+30
-49
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v4
10+
- uses: actions/checkout@v5
1111

1212
- name: Set up JDK 17
1313
uses: actions/setup-java@v4
@@ -29,11 +29,6 @@ jobs:
2929
chmod +x gradlew
3030
./gradlew build
3131
32-
- name: Merge Fabric & Neoforge JARs
33-
run: |
34-
chmod +x gradlew
35-
./gradlew fusejars
36-
3732
- name: Upload fabric artifacts
3833
uses: actions/upload-artifact@v4
3934
with:
@@ -51,9 +46,3 @@ jobs:
5146
with:
5247
name: neoforge-artifacts
5348
path: ${{ github.workspace }}/neoforge/build/libs
54-
55-
- name: Upload merged artifacts
56-
uses: actions/upload-artifact@v4
57-
with:
58-
name: merged
59-
path: ${{ github.workspace }}/build/merged/*

build.gradle

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ plugins {
22
id "architectury-plugin" version "3.4-SNAPSHOT"
33
id "dev.architectury.loom" version "1.10-SNAPSHOT" apply false
44
id "com.gradleup.shadow" version "9.+" apply false
5-
id "com.hypherionmc.modutils.modfusioner" version "1.+"
65
}
76

87
architectury {
@@ -38,25 +37,3 @@ allprojects {
3837
withSourcesJar()
3938
}
4039
}
41-
42-
fusioner {
43-
packageGroup = rootProject.maven_group
44-
mergedJarName = "${rootProject.archives_base_name}.jar"
45-
outputDirectory = "build/merged"
46-
jarVersion = rootProject.version
47-
48-
fabric {
49-
projectName = "fabric"
50-
inputTaskName = "remapJar"
51-
}
52-
53-
forge {
54-
projectName = "forge"
55-
inputTaskName = "remapJar"
56-
}
57-
58-
neoforge {
59-
projectName = "neoforge"
60-
inputTaskName = "remapJar"
61-
}
62-
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,38 @@ private void onFindResources(String startingPath, Predicate<Identifier> allowedP
2424
CallbackInfoReturnable<Map<Identifier, Resource>> cir) {
2525

2626
String currentLang = LangTextureCache.getCurrentLanguage();
27-
28-
if ("en_us".equals(currentLang) || !startingPath.startsWith("textures/")) {
27+
if ("en_us".equals(currentLang)) {
2928
return;
3029
}
3130

3231
Map<Identifier, Resource> originalResources = cir.getReturnValue();
3332
if (originalResources.isEmpty()) return;
3433

3534
Map<Identifier, Resource> langSpecificResources = new HashMap<>();
36-
String texturePrefix = "textures/";
37-
int prefixLength = texturePrefix.length();
35+
String textureKey = "textures/";
3836

3937
for (Map.Entry<Identifier, Resource> entry : originalResources.entrySet()) {
4038
Identifier originalId = entry.getKey();
4139

42-
if (originalId.getPath().endsWith(".mcmeta") || !allowedPathPredicate.test(originalId)) {
40+
if (!allowedPathPredicate.test(originalId)) {
41+
continue;
42+
}
43+
44+
String path = originalId.getPath();
45+
int idx = path.indexOf(textureKey);
46+
if (idx == -1) {
47+
continue; // 跳过不含 textures/ 的路径
48+
}
49+
50+
String before = path.substring(0, idx + textureKey.length());
51+
String after = path.substring(idx + textureKey.length());
52+
53+
// 避免重复,如zh_cn/zh_cn
54+
if (after.startsWith(currentLang + "/")) {
4355
continue;
4456
}
4557

46-
String langSpecificPath = texturePrefix + currentLang + '/' + originalId.getPath().substring(prefixLength);
58+
String langSpecificPath = before + currentLang + '/' + after;
4759
Identifier langId = new Identifier(originalId.getNamespace(), langSpecificPath);
4860

4961
Boolean cache = LangTextureCache.get(langId);
@@ -74,9 +86,8 @@ private void onFindResources(String startingPath, Predicate<Identifier> allowedP
7486
}
7587
}
7688

77-
//noinspection ConstantConditions
7889
if (!langSpecificResources.isEmpty()) {
7990
originalResources.putAll(langSpecificResources);
8091
}
8192
}
82-
}
93+
}

common/src/main/java/com/wulian/texturelocaleredirector/mixin/ftbquests/ChapterImageMixin.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ public abstract class ChapterImageMixin {
1818
)
1919
private Icon injectLocalizedImage(Icon image) {
2020
String currentLang = LangTextureCache.getCurrentLanguage();
21-
if ("en_us".equals(currentLang)) {
21+
22+
if ("en_us".equals(currentLang) || image == null) {
2223
return image;
2324
}
2425

2526
String path = image.toString();
26-
if (path.startsWith("textures/")) {
27-
String localizedPath = "textures/" + currentLang + "/" + path.substring(9);
27+
int idx = path.indexOf("textures/");
28+
if (idx != -1) {
29+
String before = path.substring(0, idx + 9); // 包含 "textures/"
30+
String after = path.substring(idx + 9);
31+
String localizedPath = before + currentLang + "/" + after;
32+
2833
Icon localizedIcon = Icon.getIcon(localizedPath);
2934

3035
if (!localizedIcon.isEmpty()) {
@@ -35,4 +40,4 @@ private Icon injectLocalizedImage(Icon image) {
3540

3641
return image;
3742
}
38-
}
43+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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.2.0
9+
mod_version=1.3.0
1010
maven_group=com.wulian.texturelocaleredirector
1111

1212
forge_version=49.2.0

settings.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pluginManagement {
44
maven { url "https://maven.fabricmc.net/" }
55
maven { url "https://maven.minecraftforge.net/" }
66
maven { url "https://maven.neoforged.net/releases/" }
7-
maven { url "https://maven.firstdarkdev.xyz/releases/" }
87
gradlePluginPortal()
98
}
109
}

0 commit comments

Comments
 (0)