Jump to content

Adding an API Mod to Another Project


hammy3502

Recommended Posts

Hello! I have a mod (let's just call it `apimod`) that I want to have other mods depend on existing. For example, if I had a mod called `examplemod`, it would require `apimod` to be installed separately for it to work properly, similarly to how other mods can use JEI's API to do things within JEI. Assuming I have both mods fully working except for any interoperability from `examplemod` to `apimod`, how would I go about adding `apimod` into my workspace for `examplemod`, but making sure the mod needs to be installed separately when running a built version of `examplemod`? So far, my closest attempts to getting this to work have been adding a "libs" folder as a repository to `examplemod`, then adding as both `compileOnly` and `runtimeOnly` dependencies, the JAR for `apimod`. However, this seems to result in a `MethodNotFoundException` when first entering a world as `apimod` fails to run some of its own, internal logic. Thank you so much for any help!

Edited by hammy3502
Link to comment
Share on other sites

My bad, I should have clarified before that I was using `fg.deobf`. If it helps, the crash report indicates that it can't find a method:
`java.lang.NoSuchMethodError: net.minecraft.server.MinecraftServer.func_184103_al()Lnet/minecraft/server/management/PlayerList;`

I have both mods using the same mappings (the mappings pre-Mojang, I'm forgetting what they're called off of the top of my head), and both mods report the actual method name as being getPlayerList(), rather than func_184103_al() when browsing through code in IntelliJ.

 

EDIT: If it helps, the code to `apimod` is here (it fails on running PlayerTracker.tick() ). 

 

EDIT 2: To clarify a bit, the `apimod` is being built with the usual `gradlew build`, and being loaded into `examplemod` through the line you sent in your post. The `apimod` runs perfectly fine on its own in both SP and MP, so I know it's not reaching across sides. `examplemod` also makes no calls or references to `apimod`, only `apimod` is loaded alongside `examplemod` via the build.gradle line you sent.

Edited by hammy3502
Link to comment
Share on other sites

buildscript {
    repositories {
        maven { url = 'https://files.minecraftforge.net/maven' }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
    }
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '2.0.0'
group = 'net.blf02.survivalextras2' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'survival_extras_2'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {
    // The mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   Snapshot are built nightly.
    // stable_#            Stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not always work.
    // Simply re-run your setup task after changing the mappings to update your workspace.
    mappings channel: 'snapshot', version: '20201028-1.16.3'
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
    
    // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

    // Default run configurations.
    // These can be tweaked, removed, or duplicated as needed.
    runs {
        client {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            mods {
                examplemod {
                    source sourceSets.main
                }
            }

            // For Patchouli
            property 'mixin.env.remapRefMap', 'true'
            property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg"
        }

        server {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }

        data {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

            // Recommended logging level for the console
            property 'forge.logging.console.level', 'debug'

            // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
            args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }
    }
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories {
    maven {
        // location of the maven that hosts JEI files
        name = "Progwml6 maven"
        url = "https://dvs1.progwml6.com/files/maven/"
    }
    maven {
        // location of a maven mirror for JEI files, as a fallback
        name = "ModMaven"
        url = "https://modmaven.k-4u.nl"
    }
    maven {
        name = "Patchouli"
        url = "https://maven.blamejared.com"
    }
    flatDir {
        dirs 'libs'
    }
}


dependencies {
    // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
    // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
    // The userdev artifact is a special name and will get all sorts of transformations applied to it.
    minecraft 'net.minecraftforge:forge:1.16.4-35.1.37'

    // compile against the JEI API but do not include it at runtime
    compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api")
    // at runtime, use the full JEI jar
    runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}")

    compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api")
    runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50")

    compile fg.deobf("net.blf02.vivecraftapi:Vivecraft-API-1.16.4-0.1.0")

    // You may put jars on which you depend on in ./libs or you may define them like so..
    // compile "some.group:artifact:version:classifier"
    // compile "some.group:artifact:version"

    // Real examples
    // compile 'com.mod-buildcraft:buildcraft:6.0.8:dev'  // adds buildcraft to the dev env
    // compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

    // The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
    // provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'

    // These dependencies get remapped to your current MCP mappings
    // deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'

    // For more info...
    // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
    // http://www.gradle.org/docs/current/userguide/dependency_management.html

}

// Example for how to get properties into the manifest for reading by the runtime..
jar {
    manifest {
        attributes([
            "Specification-Title": "examplemod",
            "Specification-Vendor": "examplemodsareus",
            "Specification-Version": "1", // We are version 1 of ourselves
            "Implementation-Title": project.name,
            "Implementation-Version": "${version}",
            "Implementation-Vendor" :"examplemodsareus",
            "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }
}

// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar') 
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact jar
        }
    }
    repositories {
        maven {
            url "file:///${project.projectDir}/mcmodsrepo"
        }
    }
}

EDIT: The JAR is stored in libs/, and is named `Vivecraft-API-1.16.4-0.1.0.jar`

Edited by hammy3502
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.