mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-24 08:38:17 -05:00
Fix overriding vanilla translations (#4187)
This commit is contained in:
parent
89cb0a4eef
commit
e82f21f7e9
3 changed files with 19 additions and 0 deletions
|
@ -35,6 +35,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||
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 {
|
||||
|
@ -51,6 +53,18 @@ class LanguageMixin {
|
|||
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);
|
||||
|
|
|
@ -27,6 +27,8 @@ public class LanguageTestMod implements DedicatedServerModInitializer {
|
|||
}
|
||||
|
||||
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");
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"text.fabric-resource-loader-v0-testmod.server.lang.override": "Vanilla override test"
|
||||
}
|
Loading…
Reference in a new issue