diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java index 0f6b44d3c1..c33bfea686 100644 --- a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/impl/ResourceLoaderImpl.java @@ -17,6 +17,7 @@ package org.quiltmc.qsl.resource.loader.impl; +import java.io.IOException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -52,8 +53,10 @@ import net.minecraft.resource.pack.ResourcePack; import net.minecraft.resource.pack.ResourcePackProfile; import net.minecraft.resource.pack.ResourcePackProvider; +import net.minecraft.resource.pack.VanillaDataPackProvider; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.Language; import net.minecraft.util.Pair; import org.quiltmc.loader.api.ModContainer; @@ -499,4 +502,31 @@ public static void registerBuiltinResourcePacks(ResourceType type, Consumer map) { + var pack = ResourceLoaderImpl.buildMinecraftResourcePack(ResourceType.CLIENT_RESOURCES, + new DefaultResourcePack(VanillaDataPackProvider.DEFAULT_PACK_METADATA, "minecraft") + ); + + try (var manager = new MultiPackResourceManager(ResourceType.CLIENT_RESOURCES, List.of(pack))) { + for (var namespace : manager.getAllNamespaces()) { + var langId = new Identifier(namespace, "lang/" + Language.DEFAULT_LANGUAGE + ".json"); + + for (var resource : manager.getAllResources(langId)) { + try (var stream = resource.open()) { + Language.load(stream, map::put); + } catch (IOException e) { + LOGGER.error("Couldn't load language file {} from pack {}.", langId, resource.getSourceName()); + } + } + } + } + } } diff --git a/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/server/LanguageMixin.java b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/server/LanguageMixin.java new file mode 100644 index 0000000000..f92e970715 --- /dev/null +++ b/library/core/resource_loader/src/main/java/org/quiltmc/qsl/resource/loader/mixin/server/LanguageMixin.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.resource.loader.mixin.server; + +import com.google.common.collect.ImmutableMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.util.Language; + +import org.quiltmc.loader.api.minecraft.DedicatedServerOnly; +import org.quiltmc.qsl.resource.loader.impl.ResourceLoaderImpl; + +@DedicatedServerOnly +@Mixin(Language.class) +public class LanguageMixin { + @Redirect( + method = "create", + at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableMap$Builder;build()Lcom/google/common/collect/ImmutableMap;") + ) + private static ImmutableMap create(ImmutableMap.Builder builder) { + var map = new Object2ObjectOpenHashMap<>(builder.buildOrThrow()); + ResourceLoaderImpl.appendLanguageEntries(map); + return ImmutableMap.copyOf(map); + } +} diff --git a/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json b/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json index 1bad2961a9..0d25552f20 100644 --- a/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json +++ b/library/core/resource_loader/src/main/resources/quilt_resource_loader.mixins.json @@ -19,17 +19,20 @@ "server.MainMixin" ], "client": [ - "client.IntegratedServerLoaderMixin", "client.ClientBuiltinResourcePackProviderMixin", "client.CreateWorldScreenMixin", "client.EntryListWidgetAccessor", "client.FontManagerResourceReloadListenerMixin", "client.GameOptionsMixin", + "client.IntegratedServerLoaderMixin", "client.KeyedClientResourceReloaderMixin", "client.MinecraftClientMixin", "client.PackScreenMixin", "client.ResourcePackEntryAccessor" ], + "server": [ + "server.LanguageMixin" + ], "injectors": { "defaultRequire": 1 }