Using net.minecraft.server (NMS)

So, for a project I’m working on, I want to be able to use NMS. (No, not because something is unimplemented, no there isn’t another alternative).

The problem I’m having is how to add a dependency to my build.gradle for this. I’ve tried depending on SpongeForge, and it didn’t appear to work. Additionally, I’d want my plugin to still work on SpongeVanilla.

I’ve got a feeling I need to mess with MCP, but I’m not sure how. I haven’t really tried much, as I’ve no idea what to try. Any help would be greatly appreciated!

Try adding Workspace\SpongeForge\SpongeCommon\.gradle\minecraft\minecraft_serverSrc-1.8.9-PROJECT(SpongeCommon).jar as dependency

I’d highly recommend using spongeGradle or forgeGradle as your build tool. I don’t know the specifics but I’ve seen people discuss it in IRC a few times. It will assist with obfuscated and deobfuscated versions of your mod.

If you’re using Gradle you can use something like the following to get the Vanilla server source additionally to your dependency on SpongeAPI. This will setup a ForgeGradle project which sets up the same workspace we use in SpongeCommon.

Make sure to run setupDecompWorkspace before importing the project into your IDE.

Note: That doesn’t add the Sponge implementation to your classpath, although in most cases you will probably only want to access MCP anyway.

Thanks for that!

Edit:
And yeah, I don’t really want access to Sponge impl, just MCP.

@Minecrell
Just a quick question about mixins:
When I create an “something” in sponge, like an entity, I’m given the interface. Can this be safely casted to a Minecraft entity? I’m lead to believe it can be, because both SpongeVanilla and SpongeForge work by forcing interfaces onto the bytecode of minecraft, and don’t actually have their own classes for this (Entity, Item, etc.).

Edit: I’ll test it myself today, but in general is this safe?

Sponge uses Mixins, meaning 90% of the classes are their NMS class with the interface injected into it

This is infact what Sponge uses themselves, for example

EntityMinecart cart = (EntityMinecart) world.createEntity(EntityTypes.MINECART, Vector3i(0, 0, 0).get()

Cool, thanks!

If in doubt, use an instanceof check

@Minecrell
I’m getting the following error on a fresh setup. I believe that it is my fault, as I ran setupDecompWorkspace just fine a few days previously. Any help would be greatly appreciated.

Can you post your full build.gradle? I’ve never seen this problem before.

// Gradle plugins
buildscript {
    repositories {
        jcenter()
        maven {
            name = 'forge'
            url = 'http://files.minecraftforge.net/maven'
        }
        maven {
            name = 'minecrell'
            url = 'http://repo.minecrell.net/releases'
        }
    }

    dependencies {
        classpath 'net.minecrell:VanillaGradle:2.0.3_1'
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.0.1'
    }
}

apply plugin: 'net.minecrell.vanilla.server.library'

group = 'com.gmail.socraticphoenix.sponge'
version = '0.0.0'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
    maven {
        name = 'sponge'
        url = 'http://repo.spongepowered.org/maven'
    }
}

minecraft {
    version = '1.8.9'
    mappings = 'snapshot_20160204'
}

dependencies {
    compile 'org.spongepowered:spongeapi:3.0.0'
}

reobf.jar {
    mappingType = 'SEARGE'
}

Make sure your JDK is up to date.

That’s probably it, I haven’t got a new one for quite a while now… Downloading now

You need to use ForgeGradle 2.1+ for Minecraft 1.8.9 (2.1-SNAPSHOT)

Oh how strange…

I changed it to 2.0.1 because here it is listed as the latest build, and the string of numbers in the build.gradle you posted was reporting as not existing… Its working now though, thanks.

The ForgeGradle version used by Sponge is currently a fixed snapshot build (otherwise it will always use the latest one), but you need at least Gradle 2.4+ to be able to use them.