【问题标题】:How to add another sourceSet with a mod in Minecraft Forge (Forge Gradle 3)?如何在 Minecraft Forge (Forge Gradle 3) 中使用 mod 添加另一个 sourceSet?
【发布时间】:2020-04-08 11:59:47
【问题描述】:

我有一个在 Forge 开发环境下制作的库,一个在 main 源集中,包含库代码;另一个在testmod(或任何其他名称)源集中,包含需要作为 Forge 模组加载的测试代码。

简单添加

sourceSets {
    testmod {
        compileClasspath += sourceSets.main.output
        runtimeClasspath += sourceSets.main.output

        java {
            srcDir "src/testmod/java"
        }
        resources {
            srcDir "src/testmod/resources"
        }
    }
}

在我的build.gradle 中,Forge 不会扫描源集,因此不会加载我的 mod。如何让 Forge 加载我的模组?

请注意,我的 mod 在 Forge 1.14.4 中,这应该适用于 Forge Gradle 3 的所有版本。

【问题讨论】:

    标签: gradle minecraft minecraft-forge


    【解决方案1】:

    Forge 通过 minecraft/run 部分中声明的 mod 加载 mod。您将需要添加以下行以使 Forge 扫描 testmod 源集的 mods。

    minecraft {
        // ...
        runs {
            client {
                // ...
                mods {
                    mainmodid {
                        source sourceSets.main
                    }
                    testmodid {
                        source sourceSets.testmod
                    }
                }
            }
    
            server {
                // ...
                mods {
                    mainmodid {
                        source sourceSets.main
                    }
                    testmodid {
                        source sourceSets.testmod
                    }
                }
            }
        }
    }
    

    用您自己的 modid 替换 mainmodidtestmodidmainmodid 应该作为examplemod 包含在MDK 中。


    虽然这确实使 Forge 加载您的类,但它无法正确找到您的 mods.toml(取决于 ForgeGradle 版本)。如果您遇到加载错误说在 mods.toml 中找不到 test mod,请添加以下 sn-p

    processResources {
        from(sourceSets.testmod.resources.srcDirs) {
            include "META_INF/mods.toml"
        }
    }
    

    同样简单地添加源集testmod 不会自动添加 Forge 和 Minecraft 作为它的依赖项。您还将添加

    configurations {
        testmodCompile.extendsFrom(compile)
        testmodCompileOnly.extendsFrom(compileOnly)
        testmodRuntimeOnly.extendsFrom(runtimeOnly)
    }
    

    让 Gradle 添加 Forge 和 Minecraft(testmodCompile 中的 testmod 是源集名称,请参阅 Gradle 文档)。

    【讨论】:

    • 同时重新运行 genIntellijRuns 并删除 build/out/ (IDEA)、bin/ (Eclipse)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多