Search in sources :

Example 1 with PathResourcePack

use of net.minecraftforge.resource.PathResourcePack in project MinecraftForge by MinecraftForge.

the class ModListScreen method updateCache.

private void updateCache() {
    if (selected == null) {
        this.configButton.active = false;
        this.modInfo.clearInfo();
        return;
    }
    IModInfo selectedMod = selected.getInfo();
    this.configButton.active = ConfigGuiHandler.getGuiFactoryFor(selectedMod).isPresent();
    List<String> lines = new ArrayList<>();
    VersionChecker.CheckResult vercheck = VersionChecker.getResult(selectedMod);
    @SuppressWarnings("resource") Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
        TextureManager tm = this.minecraft.getTextureManager();
        final PathResourcePack resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getPackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
        try {
            NativeImage logo = null;
            InputStream logoResource = resourcePack.getRootResource(logoFile);
            if (logoResource != null)
                logo = NativeImage.read(logoResource);
            if (logo != null) {
                return Pair.of(tm.register("modlogo", new DynamicTexture(logo) {

                    @Override
                    public void upload() {
                        this.bind();
                        NativeImage td = this.getPixels();
                        // Use custom "blur" value which controls texture filtering (nearest-neighbor vs linear)
                        this.getPixels().upload(0, 0, 0, 0, 0, td.getWidth(), td.getHeight(), selectedMod.getLogoBlur(), false, false, false);
                    }
                }), new Size2i(logo.getWidth(), logo.getHeight()));
            }
        } catch (IOException e) {
        }
        return Pair.<ResourceLocation, Size2i>of(null, new Size2i(0, 0));
    }).orElse(Pair.of(null, new Size2i(0, 0)));
    lines.add(selectedMod.getDisplayName());
    lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
    lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
    selectedMod.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
    selectedMod.getConfig().getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
    selectedMod.getConfig().getConfigElement("displayURL").ifPresent(displayURL -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.displayurl", displayURL)));
    if (selectedMod.getOwningFile() == null || selectedMod.getOwningFile().getMods().size() == 1)
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.nochildmods"));
    else
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.childmods", selectedMod.getOwningFile().getMods().stream().map(IModInfo::getDisplayName).collect(Collectors.joining(","))));
    if (vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED)
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.updateavailable", vercheck.url() == null ? "" : vercheck.url()));
    lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.license", selectedMod.getOwningFile().getLicense()));
    lines.add(null);
    lines.add(selectedMod.getDescription());
    if ((vercheck.status() == VersionChecker.Status.OUTDATED || vercheck.status() == VersionChecker.Status.BETA_OUTDATED) && vercheck.changes().size() > 0) {
        lines.add(null);
        lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.changelogheader"));
        for (Entry<ComparableVersion, String> entry : vercheck.changes().entrySet()) {
            lines.add("  " + entry.getKey() + ":");
            lines.add(entry.getValue());
            lines.add(null);
        }
    }
    modInfo.setInfo(lines, logoData.getLeft(), logoData.getRight());
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Font(net.minecraft.client.gui.Font) ObjectSelectionList(net.minecraft.client.gui.components.ObjectSelectionList) Pair(org.apache.commons.lang3.tuple.Pair) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) PathResourcePack(net.minecraftforge.resource.PathResourcePack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) Screen(net.minecraft.client.gui.screens.Screen) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) Language(net.minecraft.locale.Language) Style(net.minecraft.network.chat.Style) List(java.util.List) Util(net.minecraft.Util) Logger(org.apache.logging.log4j.Logger) EditBox(net.minecraft.client.gui.components.EditBox) Entry(java.util.Map.Entry) FormattedCharSequence(net.minecraft.util.FormattedCharSequence) ForgeI18n(net.minecraftforge.common.ForgeI18n) Size2i(net.minecraftforge.common.util.Size2i) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Minecraft(net.minecraft.client.Minecraft) MavenVersionStringHelper(net.minecraftforge.common.util.MavenVersionStringHelper) NativeImage(com.mojang.blaze3d.platform.NativeImage) Button(net.minecraft.client.gui.components.Button) StringUtils(net.minecraftforge.fml.loading.StringUtils) GameRenderer(net.minecraft.client.renderer.GameRenderer) ResourcePackLoader(net.minecraftforge.resource.ResourcePackLoader) Component(net.minecraft.network.chat.Component) NarrationElementOutput(net.minecraft.client.gui.narration.NarrationElementOutput) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) Tesselator(com.mojang.blaze3d.vertex.Tesselator) VersionChecker(net.minecraftforge.fml.VersionChecker) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ModListWidget(net.minecraftforge.client.gui.widget.ModListWidget) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) ConfigGuiHandler(net.minecraftforge.client.ConfigGuiHandler) InputStream(java.io.InputStream) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModContainer(net.minecraftforge.fml.ModContainer) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) IOException(java.io.IOException) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) VersionChecker(net.minecraftforge.fml.VersionChecker) TextureManager(net.minecraft.client.renderer.texture.TextureManager) NativeImage(com.mojang.blaze3d.platform.NativeImage) ResourceLocation(net.minecraft.resources.ResourceLocation) Size2i(net.minecraftforge.common.util.Size2i) PathResourcePack(net.minecraftforge.resource.PathResourcePack)

Example 2 with PathResourcePack

use of net.minecraftforge.resource.PathResourcePack in project MinecraftForge by MinecraftForge.

the class ClientModLoader method clientPackFinder.

private static void clientPackFinder(Map<IModFile, ? extends PathResourcePack> modResourcePacks, Consumer<Pack> consumer, Pack.PackConstructor factory) {
    List<PathResourcePack> hiddenPacks = new ArrayList<>();
    for (Entry<IModFile, ? extends PathResourcePack> e : modResourcePacks.entrySet()) {
        IModInfo mod = e.getKey().getModInfos().get(0);
        final String name = "mod:" + mod.getModId();
        final Pack packInfo = Pack.create(name, false, e::getValue, factory, Pack.Position.BOTTOM, PackSource.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;
        }
        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 Pack packInfo = Pack.create("mod_resources", true, () -> new DelegatingResourcePack("mod_resources", "Mod Resources", new PackMetadataSection(new TranslatableComponent("fml.resources.modresources", hiddenPacks.size()), PackType.CLIENT_RESOURCES.getVersion(SharedConstants.getCurrentVersion())), hiddenPacks), factory, Pack.Position.BOTTOM, PackSource.DEFAULT);
    consumer.accept(packInfo);
}
Also used : DelegatingResourcePack(net.minecraftforge.resource.DelegatingResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ClientPackSource(net.minecraft.client.resources.ClientPackSource) RepositorySource(net.minecraft.server.packs.repository.RepositorySource) PackType(net.minecraft.server.packs.PackType) File(java.io.File) MinecraftForge(net.minecraftforge.common.MinecraftForge) PackSource(net.minecraft.server.packs.repository.PackSource) IModFile(net.minecraftforge.forgespi.locating.IModFile) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) IModFile(net.minecraftforge.forgespi.locating.IModFile) Pack(net.minecraft.server.packs.repository.Pack) PathResourcePack(net.minecraftforge.resource.PathResourcePack) DelegatingResourcePack(net.minecraftforge.resource.DelegatingResourcePack) PathResourcePack(net.minecraftforge.resource.PathResourcePack) PackMetadataSection(net.minecraft.server.packs.metadata.pack.PackMetadataSection)

Example 3 with PathResourcePack

use of net.minecraftforge.resource.PathResourcePack in project MinecraftForge by MinecraftForge.

the class AddPackFinderEventTest method addPackFinders.

@SubscribeEvent
public static void addPackFinders(AddPackFindersEvent event) {
    try {
        if (event.getPackType() == PackType.CLIENT_RESOURCES) {
            var resourcePath = ModList.get().getModFileById(MODID).getFile().findResource("test_nested_resource_pack");
            var pack = new PathResourcePack(ModList.get().getModFileById(MODID).getFile().getFileName() + ":" + resourcePath, resourcePath);
            var metadataSection = pack.getMetadataSection(PackMetadataSection.SERIALIZER);
            if (metadataSection != null) {
                event.addRepositorySource((packConsumer, packConstructor) -> packConsumer.accept(packConstructor.create("builtin/add_pack_finders_test", new TextComponent("display name"), false, () -> pack, metadataSection, Pack.Position.BOTTOM, PackSource.BUILT_IN, false)));
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) IOException(java.io.IOException) PathResourcePack(net.minecraftforge.resource.PathResourcePack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with PathResourcePack

use of net.minecraftforge.resource.PathResourcePack in project MinecraftForge by MinecraftForge.

the class ServerLifecycleHooks method serverPackFinder.

private static void serverPackFinder(Map<IModFile, ? extends PathResourcePack> modResourcePacks, Consumer<Pack> consumer, Pack.PackConstructor factory) {
    for (Entry<IModFile, ? extends PathResourcePack> 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 Pack packInfo = Pack.create(name, false, e::getValue, factory, Pack.Position.BOTTOM, PackSource.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;
        }
        LOGGER.debug(CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
        consumer.accept(packInfo);
    }
}
Also used : IModInfo(net.minecraftforge.forgespi.language.IModInfo) RepositorySource(net.minecraft.server.packs.repository.RepositorySource) ModLoadingStage(net.minecraftforge.fml.ModLoadingStage) MinecraftForge(net.minecraftforge.common.MinecraftForge) ConnectionType(net.minecraftforge.network.ConnectionType) PackSource(net.minecraft.server.packs.repository.PackSource) IModFile(net.minecraftforge.forgespi.locating.IModFile) LevelResource(net.minecraft.world.level.storage.LevelResource) IModFile(net.minecraftforge.forgespi.locating.IModFile) ModLoadingWarning(net.minecraftforge.fml.ModLoadingWarning) Pack(net.minecraft.server.packs.repository.Pack) PathResourcePack(net.minecraftforge.resource.PathResourcePack)

Aggregations

PathResourcePack (net.minecraftforge.resource.PathResourcePack)3 IOException (java.io.IOException)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 Pack (net.minecraft.server.packs.repository.Pack)2 PackSource (net.minecraft.server.packs.repository.PackSource)2 RepositorySource (net.minecraft.server.packs.repository.RepositorySource)2 MinecraftForge (net.minecraftforge.common.MinecraftForge)2 IModInfo (net.minecraftforge.forgespi.language.IModInfo)2 IModFile (net.minecraftforge.forgespi.locating.IModFile)2 NativeImage (com.mojang.blaze3d.platform.NativeImage)1 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 Tesselator (com.mojang.blaze3d.vertex.Tesselator)1 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Entry (java.util.Map.Entry)1