Search in sources :

Example 1 with PackMetadataSection

use of net.minecraft.resources.data.PackMetadataSection in project Magma-1.16.x by magmafoundation.

the class ClientModLoader method clientPackFinder.

private static void clientPackFinder(Map<ModFile, ? extends ModFileResourcePack> modResourcePacks, BiConsumer<? super ModFileResourcePack, ResourcePackInfo> packSetter, Consumer<ResourcePackInfo> consumer, ResourcePackInfo.IFactory factory) {
    List<ModFileResourcePack> hiddenPacks = new ArrayList<>();
    for (Entry<ModFile, ? extends ModFileResourcePack> e : modResourcePacks.entrySet()) {
        IModInfo mod = e.getKey().getModInfos().get(0);
        // skip the minecraft "mod"
        if (Objects.equals(mod.getModId(), "minecraft"))
            continue;
        final String name = "mod:" + mod.getModId();
        final ResourcePackInfo packInfo = ResourcePackInfo.create(name, false, e::getValue, factory, ResourcePackInfo.Priority.BOTTOM, IPackNameDecorator.DEFAULT);
        if (packInfo == null) {
            // Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
            ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
            continue;
        }
        packSetter.accept(e.getValue(), packInfo);
        LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
        if (mod.getOwningFile().showAsResourcePack()) {
            consumer.accept(packInfo);
        } else {
            hiddenPacks.add(e.getValue());
        }
    }
    final ResourcePackInfo packInfo = ResourcePackInfo.create("mod_resources", true, () -> new DelegatingResourcePack("mod_resources", "Mod Resources", new PackMetadataSection(new TranslationTextComponent("fml.resources.modresources", hiddenPacks.size()), 6), hiddenPacks), factory, ResourcePackInfo.Priority.BOTTOM, IPackNameDecorator.DEFAULT);
    consumer.accept(packInfo);
}
Also used : DelegatingResourcePack(net.minecraftforge.fml.packs.DelegatingResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) CompletableFuture(java.util.concurrent.CompletableFuture) File(java.io.File) MinecraftForge(net.minecraftforge.common.MinecraftForge) ResourcePackInfo(net.minecraft.resources.ResourcePackInfo) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) PackMetadataSection(net.minecraft.resources.data.PackMetadataSection)

Example 2 with PackMetadataSection

use of net.minecraft.resources.data.PackMetadataSection in project LoliServer by Loli-Server.

the class ClientModLoader method clientPackFinder.

private static void clientPackFinder(Map<ModFile, ? extends ModFileResourcePack> modResourcePacks, BiConsumer<? super ModFileResourcePack, ResourcePackInfo> packSetter, Consumer<ResourcePackInfo> consumer, ResourcePackInfo.IFactory factory) {
    List<ModFileResourcePack> hiddenPacks = new ArrayList<>();
    for (Entry<ModFile, ? extends ModFileResourcePack> e : modResourcePacks.entrySet()) {
        IModInfo mod = e.getKey().getModInfos().get(0);
        // skip the minecraft "mod"
        if (Objects.equals(mod.getModId(), "minecraft"))
            continue;
        final String name = "mod:" + mod.getModId();
        final ResourcePackInfo packInfo = ResourcePackInfo.create(name, false, e::getValue, factory, ResourcePackInfo.Priority.BOTTOM, IPackNameDecorator.DEFAULT);
        if (packInfo == null) {
            // Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
            ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
            continue;
        }
        packSetter.accept(e.getValue(), packInfo);
        LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
        if (mod.getOwningFile().showAsResourcePack()) {
            consumer.accept(packInfo);
        } else {
            hiddenPacks.add(e.getValue());
        }
    }
    final ResourcePackInfo packInfo = ResourcePackInfo.create("mod_resources", true, () -> new DelegatingResourcePack("mod_resources", "Mod Resources", new PackMetadataSection(new TranslationTextComponent("fml.resources.modresources", hiddenPacks.size()), 6), hiddenPacks), factory, ResourcePackInfo.Priority.BOTTOM, IPackNameDecorator.DEFAULT);
    consumer.accept(packInfo);
}
Also used : DelegatingResourcePack(net.minecraftforge.fml.packs.DelegatingResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) CompletableFuture(java.util.concurrent.CompletableFuture) File(java.io.File) MinecraftForge(net.minecraftforge.common.MinecraftForge) ResourcePackInfo(net.minecraft.resources.ResourcePackInfo) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) PackMetadataSection(net.minecraft.resources.data.PackMetadataSection)

Aggregations

File (java.io.File)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ResourcePackInfo (net.minecraft.resources.ResourcePackInfo)2 PackMetadataSection (net.minecraft.resources.data.PackMetadataSection)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 MinecraftForge (net.minecraftforge.common.MinecraftForge)2 ModFile (net.minecraftforge.fml.loading.moddiscovery.ModFile)2 DelegatingResourcePack (net.minecraftforge.fml.packs.DelegatingResourcePack)2 ModFileResourcePack (net.minecraftforge.fml.packs.ModFileResourcePack)2 IModInfo (net.minecraftforge.forgespi.language.IModInfo)2