Skip to content

Commit 7900d7b

Browse files
committed
init
0 parents  commit 7900d7b

28 files changed

Lines changed: 907 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build
2+
3+
on: [ pull_request, push, workflow_dispatch ]
4+
5+
jobs:
6+
Build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Set up JDK 21
13+
uses: actions/setup-java@v4
14+
with:
15+
distribution: 'temurin'
16+
java-version: 21
17+
18+
- name: Cache
19+
uses: actions/cache@v4
20+
with:
21+
path: |
22+
~/.gradle/caches
23+
~/.gradle/wrapper
24+
.gradle
25+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'build.gradle') }}
26+
27+
- name: Build with Gradle
28+
run: |
29+
chmod +x gradlew
30+
./gradlew build
31+
32+
- name: Merge Fabric & Neoforge JARs
33+
run: |
34+
chmod +x gradlew
35+
./gradlew fusejars
36+
37+
- name: Upload fabric artifacts
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: fabric-artifacts
41+
path: ${{ github.workspace }}/fabric/build/libs
42+
43+
- name: Upload neoforge artifacts
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: neoforge-artifacts
47+
path: ${{ github.workspace }}/neoforge/build/libs
48+
49+
- name: Upload merged artifacts
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: merged
53+
path: ${{ github.workspace }}/build/merged/*

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
build/
2+
*.ipr
3+
run/
4+
*.iws
5+
out/
6+
*.iml
7+
.gradle/
8+
output/
9+
bin/
10+
libs/
11+
12+
.classpath
13+
.project
14+
.idea/
15+
classes/
16+
.metadata
17+
.vscode
18+
.settings
19+
*.launch
20+
/.architectury-transformer/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-2025 VM Chinese translate group | VM汉化组
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div align="center">
2+
<img height="100px" width="100px" alt="logo" src="./common/src/main/resources/assets/vmtranslationupdate/icon.png"/>
3+
<h1>VM Translation Update</h1>
4+
5+
<a href="https://modrinth.com/project/vmupdate/">
6+
<img alt="modrinth" height="56" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/available/modrinth_vector.svg">
7+
</a>
8+
<a href="https://www.curseforge.com/minecraft/mc-mods/vmtranslationupdate">
9+
<img alt="curseforge" height="56" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/available/curseforge_vector.svg">
10+
</a>
11+
<a href="https://www.mcmod.cn/class/11203.html">
12+
<img alt="mcmod.cn" height="56" src="https://raw.githubusercontent.com/KessokuTeaTime/Badges-Extra/main/assets/cozy/available/mcmodcn_vector.svg">
13+
</a>
14+
15+
<img alt="forge" height="56" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/supported/forge_vector.svg"> (1.12.2、1.16.5、1.18-1.20.1)
16+
<img alt="neoforge" height="56" src="https://raw.githubusercontent.com/KessokuTeaTime/Badges-Extra/main/assets/cozy/supported/neoforge_vector.svg"> (≥1.20.1)
17+
<img alt="fabric" height="56" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/supported/fabric_vector.svg"> (≥1.16.5)
18+
</div>

build.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
plugins {
2+
id "architectury-plugin" version "3.4-SNAPSHOT"
3+
id "dev.architectury.loom" version "1.10-SNAPSHOT" apply false
4+
id "com.gradleup.shadow" version "8.+" apply false
5+
id "com.hypherionmc.modutils.modfusioner" version "1.+"
6+
}
7+
8+
architectury {
9+
minecraft = rootProject.minecraft_version
10+
}
11+
12+
subprojects {
13+
apply plugin: "dev.architectury.loom"
14+
apply plugin: "com.gradleup.shadow"
15+
16+
dependencies {
17+
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
18+
mappings loom.layered {
19+
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
20+
mappings "dev.architectury:yarn-mappings-patch-neoforge:${project.yarn_patch}"
21+
}
22+
}
23+
}
24+
25+
allprojects {
26+
apply plugin: "java"
27+
apply plugin: "architectury-plugin"
28+
29+
archivesBaseName = rootProject.archives_base_name
30+
version = "${rootProject.mod_version}+mc${rootProject.minecraft_version}"
31+
group = rootProject.maven_group
32+
33+
tasks.withType(JavaCompile).configureEach {
34+
options.encoding = "UTF-8"
35+
options.release = 21
36+
}
37+
38+
java {
39+
withSourcesJar()
40+
}
41+
}
42+
43+
fusioner {
44+
packageGroup = rootProject.maven_group
45+
mergedJarName = "${rootProject.archives_base_name}.jar"
46+
outputDirectory = "build/merged"
47+
jarVersion = rootProject.version
48+
49+
neoforge {
50+
projectName = "neoforge"
51+
inputTaskName = "remapJar"
52+
}
53+
54+
fabric {
55+
projectName = "fabric"
56+
inputTaskName = "remapJar"
57+
}
58+
}

common/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
architectury {
2+
common(rootProject.enabled_platforms.split(","))
3+
}
4+
5+
dependencies {
6+
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
7+
// Do NOT use other classes from fabric loader
8+
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
9+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.wulian.texturelocaleredirector;
2+
3+
4+
import net.minecraft.util.Identifier;
5+
6+
public class LanguageTextureManager {
7+
private static final String TEXTURES_PREFIX = "textures/";
8+
private static final int TEXTURES_PREFIX_LENGTH = TEXTURES_PREFIX.length();
9+
10+
private static final ThreadLocal<Boolean> IS_REPLACING_ATLAS_TEXTURES = ThreadLocal.withInitial(() -> false);
11+
12+
public static boolean isReplacingAtlasTextures() {
13+
return IS_REPLACING_ATLAS_TEXTURES.get();
14+
}
15+
16+
public static void setReplacingAtlasTextures(boolean replacing) {
17+
IS_REPLACING_ATLAS_TEXTURES.set(replacing);
18+
}
19+
20+
public static Identifier getLanguageSpecificIdForAtlas(Identifier originalId, String currentLang) {
21+
if ("en_us".equals(currentLang)) {
22+
return null;
23+
}
24+
25+
String path = originalId.getPath();
26+
if (path.startsWith(TEXTURES_PREFIX)) {
27+
return createLanguageSpecificId(originalId, currentLang, path);
28+
}
29+
return null;
30+
}
31+
32+
private static Identifier createLanguageSpecificId(Identifier original, String language, String path) {
33+
String langSpecificPath = TEXTURES_PREFIX + language + "/" + path.substring(TEXTURES_PREFIX_LENGTH);
34+
return Identifier.of(original.getNamespace(), langSpecificPath);
35+
}
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.wulian.texturelocaleredirector;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class TextureLocaleRedirector {
7+
public static final String MOD_ID = "texturelocaleredirector";
8+
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
9+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.wulian.texturelocaleredirector.mixin;
2+
3+
import com.wulian.texturelocaleredirector.LanguageTextureManager;
4+
import net.minecraft.client.MinecraftClient;
5+
import net.minecraft.resource.NamespaceResourceManager;
6+
import net.minecraft.resource.Resource;
7+
import net.minecraft.resource.ResourceManager;
8+
import net.minecraft.util.Identifier;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13+
14+
import java.util.HashMap;
15+
import java.util.Map;
16+
import java.util.function.Predicate;
17+
18+
@Mixin(NamespaceResourceManager.class)
19+
public abstract class NamespaceResourceManagerMixin implements ResourceManager {
20+
@Inject(method = "findResources", at = @At("RETURN"))
21+
private void onFindResources(String startingPath, Predicate<Identifier> allowedPathPredicate, CallbackInfoReturnable<Map<Identifier, Resource>> cir) {
22+
if (LanguageTextureManager.isReplacingAtlasTextures()) {
23+
return;
24+
}
25+
26+
String currentLang = MinecraftClient.getInstance().getLanguageManager().getLanguage();
27+
if ("en_us".equals(currentLang)) {
28+
return;
29+
}
30+
31+
Map<Identifier, Resource> originalMap = cir.getReturnValue();
32+
Map<Identifier, Resource> replacements = new HashMap<>();
33+
34+
for (Identifier originalId : originalMap.keySet()) {
35+
Identifier langId = LanguageTextureManager.getLanguageSpecificIdForAtlas(originalId, currentLang);
36+
37+
if (langId != null) {
38+
LanguageTextureManager.setReplacingAtlasTextures(true);
39+
try {
40+
this.getResource(langId).ifPresent(langResource -> {
41+
replacements.put(originalId, langResource);
42+
});
43+
} finally {
44+
LanguageTextureManager.setReplacingAtlasTextures(false);
45+
}
46+
}
47+
}
48+
49+
if (!replacements.isEmpty()) {
50+
originalMap.putAll(replacements);
51+
}
52+
}
53+
}
78.8 KB
Loading

0 commit comments

Comments
 (0)