Skip to content

Fix for the Neoforge Error:Solved #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Zachary-Lee-Jaeho opened this issue Apr 8, 2025 · 4 comments
Open

Fix for the Neoforge Error:Solved #85

Zachary-Lee-Jaeho opened this issue Apr 8, 2025 · 4 comments

Comments

@Zachary-Lee-Jaeho
Copy link

Zachary-Lee-Jaeho commented Apr 8, 2025

Hello, it seems that mcman cannot fetch the latest version of Neoforge properly.

I resolved the issue with the modifications below, but if there’s a better solution, please update it accordingly.
Here is the modified code I used.
I changed src/source/neoforge.rs with the following:

use anyhow::{anyhow, Context, Result};

use crate::{app::App, app::ResolvedFile, util};

pub static NEOFORGE_MAVEN: &str = "https://maven.neoforged.net/releases";
pub static NEOFORGE_GROUP: &str = "net.neoforged";
pub static NEOFORGE_ARTIFACT: &str = "neoforge"; // fix this to neoforge
pub static NEOFORGE_FILENAME: &str = "${artifact}-${version}-installer.jar";

pub struct NeoforgeAPI<'a>(pub &'a App);

impl<'a> NeoforgeAPI<'a> {
    pub async fn fetch_versions(&self) -> Result<Vec<String>> {
        let (_, versions) = self
            .0
            .maven()
            .fetch_versions(NEOFORGE_MAVEN, NEOFORGE_GROUP, NEOFORGE_ARTIFACT)
            .await?;

        //Get the latest version of Neoforge corresponding with the Minecraft version
        let mc_version = self.0.mc_version();
        let trimmed = mc_version.strip_prefix("1.").unwrap_or(mc_version);

        let mut candidates = versions
            .iter()
            .filter(|v| !v.contains("beta"))
            .filter(|v| v.starts_with(trimmed))
            .cloned()
            .collect::<Vec<_>>();

        candidates.sort_by(|a, b| Self::version_key(b).cmp(&Self::version_key(a)));

        Ok(candidates.into_iter().take(1).collect())
    }

    // Just a helper function
    fn version_key(v: &str) -> Vec<u32> {
        v.split('.').filter_map(|s| s.parse::<u32>().ok()).collect()
    }

    pub async fn fetch_latest(&self) -> Result<String> {
        util::get_latest_semver(&self.fetch_versions().await?).ok_or(anyhow!(
            "No forge loader versions for {}",
            self.0.mc_version()
        ))
    }

    pub async fn resolve_version(&self, loader: &str) -> Result<String> {
        Ok(if loader == "latest" || loader.is_empty() {
            self.fetch_latest()
                .await
                .context("Getting latest Forge version")?
        } else {
            loader.to_owned()
        })
    }

    pub async fn resolve_source(&self, loader: &str) -> Result<ResolvedFile> {
        self.0
            .maven()
            .resolve_source(
                NEOFORGE_MAVEN,
                NEOFORGE_GROUP,
                NEOFORGE_ARTIFACT,
                &format!("{}", self.resolve_version(loader).await?), // fix this line to get proper Neoforge URL
                NEOFORGE_FILENAME,
            )
            .await
    }
}

Also, I changed the contents of Cargo.toml file at the top level.

The line mcapi = { git = "https://github.com/ParadigmMC/mcapi.git"}
to mcapi = { git = "https://github.com/ParadigmMC/mcapi.git", branch = "main"}

With this change, it works correctly for the latest version.
However, I didn't test this with lower version. ;)

@Zachary-Lee-Jaeho
Copy link
Author

Also, there is another problem with this error message

Error: could not open `libraries/net/neoforged/forge/1.21.1-21.1.145/unix_args.txt'

I'm now fixing this too...

@Zachary-Lee-Jaeho
Copy link
Author

Also, for src/core/scripts.rs

Fix below

    pub async fn get_startup_method(&self, serverjar_name: &str) -> Result<StartupMethod> {
        let mcver = self.app.mc_version();
        Ok(match &self.app.server.jar {
            ServerType::NeoForge { loader } => {
                let l = self.app.neoforge().resolve_version(loader).await?;

                StartupMethod::Custom {
                    windows: vec![format!(
                        "@libraries/net/neoforged/forge/{mcver}-{l}/win_args.txt"
                    )],
                    linux: vec![format!(
                        "@libraries/net/neoforged/forge/{mcver}-{l}/unix_args.txt"
                    )],
                }
            }

to

impl<'a> BuildContext<'a> {
    pub async fn get_startup_method(&self, serverjar_name: &str) -> Result<StartupMethod> {
        let mcver = self.app.mc_version();
        Ok(match &self.app.server.jar {
            ServerType::NeoForge { loader } => {
                let l = self.app.neoforge().resolve_version(loader).await?;

                StartupMethod::Custom {
                    windows: vec![format!(
                        "@libraries/net/neoforged/neoforge/{l}/win_args.txt"
                    )],
                    linux: vec![format!(
                        "@libraries/net/neoforged/neoforge/{l}/unix_args.txt"
                    )],
                }
            }

@Zachary-Lee-Jaeho Zachary-Lee-Jaeho changed the title Fix for the Neoforge Error Fix for the Neoforge Error:Solved Apr 8, 2025
@TheAlan404
Copy link
Contributor

At a specific version, they changed the package name from forge to neoforge, first versions still use that I think, so adding a way to detect that would be a good idea.

Also, It would be nice if you could submit a Pull Request!

@Zachary-Lee-Jaeho
Copy link
Author

Okay, thank you for the comment.
I submitted the pull request for this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants