Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.20.1] Fix overriding vanilla translations (Backport of #4187) #4335

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import net.minecraft.util.Language;

import net.fabricmc.fabric.impl.resource.loader.ServerLanguageUtil;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;

@Mixin(Language.class)
class LanguageMixin {
Expand All @@ -54,6 +56,18 @@ private static ImmutableMap<String, String> create(ImmutableMap.Builder<String,
return ImmutableMap.copyOf(map);
}

@Redirect(method = "load(Ljava/util/function/BiConsumer;Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Ljava/lang/Class;getResourceAsStream(Ljava/lang/String;)Ljava/io/InputStream;"))
private static InputStream readCorrectVanillaResource(Class instance, String path) throws IOException {
ModContainer mod = FabricLoader.getInstance().getModContainer("minecraft").orElseThrow();
Path langPath = mod.findPath(path).orElse(null);

if (langPath == null) {
throw new IOException("Could not read %s from minecraft ModContainer".formatted(path));
} else {
return Files.newInputStream(langPath);
}
}

private static void loadFromPath(Path path, BiConsumer<String, String> entryConsumer) {
try (InputStream stream = Files.newInputStream(path)) {
LOGGER.debug("Loading translations from {}", path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public void onInitializeServer() {
}

private static void testTranslationLoaded() {
testTranslationLoaded("item.minecraft.potato", "Potato"); // Test that vanilla translation loads
testTranslationLoaded("text.fabric-resource-loader-v0-testmod.server.lang.override", "Vanilla override test");
testTranslationLoaded("pack.source.fabricmod", "Fabric mod");
testTranslationLoaded("text.fabric-resource-loader-v0-testmod.server.lang.test0", "Test from fabric-resource-loader-v0-testmod");
testTranslationLoaded("text.fabric-resource-loader-v0-testmod.server.lang.test1", "Test from fabric-resource-loader-v0-testmod-test1");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"text.fabric-resource-loader-v0-testmod.server.lang.override": "Vanilla override test"
}