Search in sources :

Example 1 with ModInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Magma-1.16.x by magmafoundation.

the class ModListScreen method updateCache.

private void updateCache() {
    if (selected == null) {
        this.configButton.active = false;
        this.modInfo.clearInfo();
        return;
    }
    ModInfo 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 ModFileResourcePack resourcePack = ResourcePackLoader.getResourcePackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getResourcePackFor("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.getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
    selectedMod.getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
    selectedMod.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 : NativeImage(net.minecraft.client.renderer.texture.NativeImage) Pair(org.apache.commons.lang3.tuple.Pair) Button(net.minecraft.client.gui.widget.button.Button) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ResourcePackLoader(net.minecraftforge.fml.packs.ResourcePackLoader) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) ConfigGuiHandler(net.minecraftforge.fml.client.ConfigGuiHandler) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Screen(net.minecraft.client.gui.screen.Screen) ScrollPanel(net.minecraftforge.client.gui.ScrollPanel) Environment(cpw.mods.modlauncher.Environment) FMLEnvironment(net.minecraftforge.fml.loading.FMLEnvironment) Entry(java.util.Map.Entry) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Size2i(net.minecraftforge.common.util.Size2i) net.minecraft.util.text(net.minecraft.util.text) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Util(net.minecraft.util.Util) ForgeI18n(net.minecraftforge.fml.ForgeI18n) IReorderingProcessor(net.minecraft.util.IReorderingProcessor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) Minecraft(net.minecraft.client.Minecraft) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) MavenVersionStringHelper(net.minecraftforge.fml.MavenVersionStringHelper) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget) StringUtils(net.minecraftforge.fml.loading.StringUtils) GuiUtils(net.minecraftforge.fml.client.gui.GuiUtils) ExtendedList(net.minecraft.client.gui.widget.list.ExtendedList) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) VersionChecker(net.minecraftforge.fml.VersionChecker) FontRenderer(net.minecraft.client.gui.FontRenderer) Tessellator(net.minecraft.client.renderer.Tessellator) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) ModContainer(net.minecraftforge.fml.ModContainer) IModInfo(net.minecraftforge.forgespi.language.IModInfo) 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(net.minecraft.client.renderer.texture.NativeImage) ResourceLocation(net.minecraft.util.ResourceLocation) Size2i(net.minecraftforge.common.util.Size2i) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo)

Example 2 with ModInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Magma-1.16.x by magmafoundation.

the class ModListScreen method init.

@Override
public void init() {
    for (ModInfo mod : mods) {
        listWidth = Math.max(listWidth, getFontRenderer().width(mod.getDisplayName()) + 10);
        listWidth = Math.max(listWidth, getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
    }
    listWidth = Math.max(Math.min(listWidth, width / 3), 100);
    listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
    int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
    int doneButtonWidth = Math.min(modInfoWidth, 200);
    int y = this.height - 20 - PADDING;
    this.addButton(new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslationTextComponent("gui.done"), b -> ModListScreen.this.onClose()));
    this.addButton(this.openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile())));
    y -= 20 + PADDING;
    this.addButton(this.configButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig()));
    this.configButton.active = false;
    y -= 14 + PADDING + 1;
    search = new TextFieldWidget(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslationTextComponent("fml.menu.mods.search"));
    int fullButtonHeight = PADDING + 20 + PADDING;
    this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().lineHeight - PADDING);
    this.modList.setLeftPos(6);
    this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
    children.add(search);
    children.add(modList);
    children.add(modInfo);
    search.setFocus(false);
    search.setCanLoseFocus(true);
    final int width = listWidth / numButtons;
    int x = PADDING;
    addButton(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
    x += width + buttonMargin;
    addButton(SortType.A_TO_Z.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)));
    x += width + buttonMargin;
    addButton(SortType.Z_TO_A.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)));
    resortMods(SortType.NORMAL);
    updateCache();
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) Pair(org.apache.commons.lang3.tuple.Pair) Button(net.minecraft.client.gui.widget.button.Button) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ResourcePackLoader(net.minecraftforge.fml.packs.ResourcePackLoader) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) ConfigGuiHandler(net.minecraftforge.fml.client.ConfigGuiHandler) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Screen(net.minecraft.client.gui.screen.Screen) ScrollPanel(net.minecraftforge.client.gui.ScrollPanel) Environment(cpw.mods.modlauncher.Environment) FMLEnvironment(net.minecraftforge.fml.loading.FMLEnvironment) Entry(java.util.Map.Entry) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Size2i(net.minecraftforge.common.util.Size2i) net.minecraft.util.text(net.minecraft.util.text) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Util(net.minecraft.util.Util) ForgeI18n(net.minecraftforge.fml.ForgeI18n) IReorderingProcessor(net.minecraft.util.IReorderingProcessor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) Minecraft(net.minecraft.client.Minecraft) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) MavenVersionStringHelper(net.minecraftforge.fml.MavenVersionStringHelper) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget) StringUtils(net.minecraftforge.fml.loading.StringUtils) GuiUtils(net.minecraftforge.fml.client.gui.GuiUtils) ExtendedList(net.minecraft.client.gui.widget.list.ExtendedList) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) VersionChecker(net.minecraftforge.fml.VersionChecker) FontRenderer(net.minecraft.client.gui.FontRenderer) Tessellator(net.minecraft.client.renderer.Tessellator) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) Button(net.minecraft.client.gui.widget.button.Button) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget)

Example 3 with ModInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project LoliServer by Loli-Server.

the class ModListScreen method updateCache.

private void updateCache() {
    if (selected == null) {
        this.configButton.active = false;
        this.modInfo.clearInfo();
        return;
    }
    ModInfo 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 ModFileResourcePack resourcePack = ResourcePackLoader.getResourcePackFor(selectedMod.getModId()).orElse(ResourcePackLoader.getResourcePackFor("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.getConfigElement("credits").ifPresent(credits -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.credits", credits)));
    selectedMod.getConfigElement("authors").ifPresent(authors -> lines.add(ForgeI18n.parseMessage("fml.menu.mods.info.authors", authors)));
    selectedMod.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 : NativeImage(net.minecraft.client.renderer.texture.NativeImage) Pair(org.apache.commons.lang3.tuple.Pair) Button(net.minecraft.client.gui.widget.button.Button) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ResourcePackLoader(net.minecraftforge.fml.packs.ResourcePackLoader) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) ConfigGuiHandler(net.minecraftforge.fml.client.ConfigGuiHandler) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Screen(net.minecraft.client.gui.screen.Screen) ScrollPanel(net.minecraftforge.client.gui.ScrollPanel) Environment(cpw.mods.modlauncher.Environment) FMLEnvironment(net.minecraftforge.fml.loading.FMLEnvironment) Entry(java.util.Map.Entry) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Size2i(net.minecraftforge.common.util.Size2i) net.minecraft.util.text(net.minecraft.util.text) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Util(net.minecraft.util.Util) ForgeI18n(net.minecraftforge.fml.ForgeI18n) IReorderingProcessor(net.minecraft.util.IReorderingProcessor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) Minecraft(net.minecraft.client.Minecraft) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) MavenVersionStringHelper(net.minecraftforge.fml.MavenVersionStringHelper) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget) StringUtils(net.minecraftforge.fml.loading.StringUtils) GuiUtils(net.minecraftforge.fml.client.gui.GuiUtils) ExtendedList(net.minecraft.client.gui.widget.list.ExtendedList) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) VersionChecker(net.minecraftforge.fml.VersionChecker) FontRenderer(net.minecraft.client.gui.FontRenderer) Tessellator(net.minecraft.client.renderer.Tessellator) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) ModContainer(net.minecraftforge.fml.ModContainer) IModInfo(net.minecraftforge.forgespi.language.IModInfo) 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(net.minecraft.client.renderer.texture.NativeImage) ResourceLocation(net.minecraft.util.ResourceLocation) Size2i(net.minecraftforge.common.util.Size2i) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo)

Example 4 with ModInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project LoliServer by Loli-Server.

the class ModListScreen method init.

@Override
public void init() {
    for (ModInfo mod : mods) {
        listWidth = Math.max(listWidth, getFontRenderer().width(mod.getDisplayName()) + 10);
        listWidth = Math.max(listWidth, getFontRenderer().width(MavenVersionStringHelper.artifactVersionToString(mod.getVersion())) + 5);
    }
    listWidth = Math.max(Math.min(listWidth, width / 3), 100);
    listWidth += listWidth % numButtons != 0 ? (numButtons - listWidth % numButtons) : 0;
    int modInfoWidth = this.width - this.listWidth - (PADDING * 3);
    int doneButtonWidth = Math.min(modInfoWidth, 200);
    int y = this.height - 20 - PADDING;
    this.addButton(new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslationTextComponent("gui.done"), b -> ModListScreen.this.onClose()));
    this.addButton(this.openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile())));
    y -= 20 + PADDING;
    this.addButton(this.configButton = new Button(6, y, this.listWidth, 20, new TranslationTextComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig()));
    this.configButton.active = false;
    y -= 14 + PADDING + 1;
    search = new TextFieldWidget(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslationTextComponent("fml.menu.mods.search"));
    int fullButtonHeight = PADDING + 20 + PADDING;
    this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().lineHeight - PADDING);
    this.modList.setLeftPos(6);
    this.modInfo = new InfoPanel(this.minecraft, modInfoWidth, this.height - PADDING - fullButtonHeight, PADDING);
    children.add(search);
    children.add(modList);
    children.add(modInfo);
    search.setFocus(false);
    search.setCanLoseFocus(true);
    final int width = listWidth / numButtons;
    int x = PADDING;
    addButton(SortType.NORMAL.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.NORMAL.getButtonText(), b -> resortMods(SortType.NORMAL)));
    x += width + buttonMargin;
    addButton(SortType.A_TO_Z.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.A_TO_Z.getButtonText(), b -> resortMods(SortType.A_TO_Z)));
    x += width + buttonMargin;
    addButton(SortType.Z_TO_A.button = new Button(x, PADDING, width - buttonMargin, 20, SortType.Z_TO_A.getButtonText(), b -> resortMods(SortType.Z_TO_A)));
    resortMods(SortType.NORMAL);
    updateCache();
}
Also used : NativeImage(net.minecraft.client.renderer.texture.NativeImage) Pair(org.apache.commons.lang3.tuple.Pair) Button(net.minecraft.client.gui.widget.button.Button) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ResourcePackLoader(net.minecraftforge.fml.packs.ResourcePackLoader) FMLPaths(net.minecraftforge.fml.loading.FMLPaths) ConfigGuiHandler(net.minecraftforge.fml.client.ConfigGuiHandler) ModList(net.minecraftforge.fml.ModList) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Screen(net.minecraft.client.gui.screen.Screen) ScrollPanel(net.minecraftforge.client.gui.ScrollPanel) Environment(cpw.mods.modlauncher.Environment) FMLEnvironment(net.minecraftforge.fml.loading.FMLEnvironment) Entry(java.util.Map.Entry) ModFileResourcePack(net.minecraftforge.fml.packs.ModFileResourcePack) Size2i(net.minecraftforge.common.util.Size2i) net.minecraft.util.text(net.minecraft.util.text) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) ForgeHooks(net.minecraftforge.common.ForgeHooks) ModContainer(net.minecraftforge.fml.ModContainer) Util(net.minecraft.util.Util) ForgeI18n(net.minecraftforge.fml.ForgeI18n) IReorderingProcessor(net.minecraft.util.IReorderingProcessor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) Minecraft(net.minecraft.client.Minecraft) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) MavenVersionStringHelper(net.minecraftforge.fml.MavenVersionStringHelper) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget) StringUtils(net.minecraftforge.fml.loading.StringUtils) GuiUtils(net.minecraftforge.fml.client.gui.GuiUtils) ExtendedList(net.minecraft.client.gui.widget.list.ExtendedList) IOException(java.io.IOException) TextureManager(net.minecraft.client.renderer.texture.TextureManager) Consumer(java.util.function.Consumer) VersionChecker(net.minecraftforge.fml.VersionChecker) FontRenderer(net.minecraft.client.gui.FontRenderer) Tessellator(net.minecraft.client.renderer.Tessellator) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) Button(net.minecraft.client.gui.widget.button.Button) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) ModListWidget(net.minecraftforge.fml.client.gui.widget.ModListWidget)

Example 5 with ModInfo

use of net.minecraftforge.fml.loading.moddiscovery.ModInfo in project Catalogue by MrCrayfish.

the class CatalogueModListScreen method loadAndCacheLogo.

private void loadAndCacheLogo(IModInfo info) {
    if (LOGO_CACHE.containsKey(info.getModId()))
        return;
    // Fills an empty logo as logo may not be present
    LOGO_CACHE.put(info.getModId(), Pair.of(null, new Size2i(0, 0)));
    // Attempts to load the real logo
    ModInfo modInfo = (ModInfo) info;
    modInfo.getLogoFile().ifPresent(s -> {
        if (s.isEmpty())
            return;
        if (s.contains("/") || s.contains("\\")) {
            Catalogue.LOGGER.warn("Skipped loading logo file from {}. The file name '{}' contained illegal characters '/' or '\\'", info.getDisplayName(), s);
            return;
        }
        PathResourcePack resourcePack = ResourcePackLoader.getPackFor(info.getModId()).orElse(ResourcePackLoader.getPackFor("forge").orElseThrow(() -> new RuntimeException("Can't find forge, WHAT!")));
        try (InputStream is = resourcePack.getRootResource(s);
            NativeImage logo = NativeImage.read(is)) {
            TextureManager textureManager = this.getMinecraft().getTextureManager();
            LOGO_CACHE.put(info.getModId(), Pair.of(textureManager.register("modlogo", this.createLogoTexture(logo, modInfo.getLogoBlur())), new Size2i(logo.getWidth(), logo.getHeight())));
        } catch (IOException ignored) {
        }
    });
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) NativeImage(com.mojang.blaze3d.platform.NativeImage) InputStream(java.io.InputStream) Size2i(net.minecraftforge.common.util.Size2i) IOException(java.io.IOException) IModInfo(net.minecraftforge.forgespi.language.IModInfo) ModInfo(net.minecraftforge.fml.loading.moddiscovery.ModInfo) PathResourcePack(net.minecraftforge.resource.PathResourcePack)

Aggregations

ModInfo (net.minecraftforge.fml.loading.moddiscovery.ModInfo)11 IModInfo (net.minecraftforge.forgespi.language.IModInfo)10 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 TextureManager (net.minecraft.client.renderer.texture.TextureManager)6 Size2i (net.minecraftforge.common.util.Size2i)6 DynamicTexture (net.minecraft.client.renderer.texture.DynamicTexture)5 VersionChecker (net.minecraftforge.fml.VersionChecker)5 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)4 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)4 Environment (cpw.mods.modlauncher.Environment)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Comparator (java.util.Comparator)4 List (java.util.List)4 Entry (java.util.Map.Entry)4 Consumer (java.util.function.Consumer)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 Minecraft (net.minecraft.client.Minecraft)4