跳到主要内容

非 Minecraft 依赖

非 Minecraft 依赖是指既不是 Mod、也不是 Minecraft 或 NeoForge 本身所依赖的那些构件。默认情况下,NeoForge 在加载 Mod 时不会加载非 Minecraft 依赖。在开发环境中,它们必须作为运行时依赖添加;而在生产环境中,则应当利用 jar-in-jar 系统

1.21.9 及以上

在 1.21.9 及以上版本运行 NeoForge 时,开发环境中会加载类路径上的任何内容,包括非 Minecraft 依赖。这意味着添加该库与添加任何其他 gradle 依赖一样简单:

// This adds the library at compile and runtime
// In practice, this should be wrapped with 'jarJar'
// to include the library in your jar
implementation 'com.example:example:1.0'

1.21.8 及以下

在 1.21.8 及以下版本运行 NeoForge 时,还需要额外将该库添加到运行时类路径中:

dependencies {
// This is required to add the library at compile time
implementation 'com.example:example:1.0'
// This adds the library to all the runs
additionalRuntimeClasspath 'com.example:example:1.0'
}