Skip to content
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

Initial NeoForge support #25

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import io.github.groovymc.modsdotgroovy.AbstractConvertTask
import io.github.groovymc.modsdotgroovy.ConvertToForgeTomlTask
import io.github.groovymc.modsdotgroovy.ConvertToNeoForgeTomlTask

plugins {
id 'java'
Expand All @@ -9,13 +11,19 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(17)

modsDotGroovy {
dslVersion = '1.5.0'
platforms 'forge', 'quilt', 'fabric'
platforms 'forge', 'neoforge', 'quilt', 'fabric'
}

repositories {
mavenLocal()
}

tasks.withType(AbstractConvertTask).configureEach {
it.output.set(file("demo/${it.output.get().asFile.name}"))
if(it instanceof ConvertToNeoForgeTomlTask) {
it.output.set(file("demo/neoforge-${it.output.get().asFile.name}"))
} else if(it instanceof ConvertToForgeTomlTask) {
it.output.set(file("demo/forge-${it.output.get().asFile.name}"))
} else {
it.output.set(file("demo/${it.output.get().asFile.name}"))
}
}
5 changes: 3 additions & 2 deletions Test/demo/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"environment": "server",
"depends": {
"minecraft": ">=1.19 <1.20",
"minecraft": ">=1.19.4 <1.20",
"fabricloader": ">=0.14.19",
"patchouli": ">=1.1"
},
Expand All @@ -39,6 +39,7 @@
"Thanks to the mods.groovy contributors"
],
"mixins": [
"no.mixin.json"
"no.mixin.json",
"test.mixin.json"
]
}
7 changes: 7 additions & 0 deletions Test/demo/mods.toml → Test/demo/forge-mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ license = "MIT"
description = "A very nice example mod"
authors = "GroovyMC, Matyrobbrt, Paint_Ninja and lukebemish"

[[dependencies.examplemod]]
mandatory = true
versionRange = "[20.2,)"
ordering = "NONE"
side = "BOTH"
modId = "neoforge"

[[dependencies.examplemod]]
mandatory = true
versionRange = "[1.1,)"
Expand Down
44 changes: 44 additions & 0 deletions Test/demo/neoforge-mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
modLoader = "gml"
loaderVersion = "[1,)"
license = "MIT"

[[mods]]
modId = "examplemod"
version = "1.0.0"
displayName = "Examplemod"
displayTest = "IGNORE_SERVER_VERSION"
displayURL = "https://curseforge.com/minecraft/mc-mods/spammycombat"
updateJSONURL = "https://forge.curseupdate.com/623297/spammycombat"
credits = "Thanks to the mods.groovy contributors"
description = "A very nice example mod"
authors = "GroovyMC, Matyrobbrt, Paint_Ninja and lukebemish"

[[dependencies.examplemod]]
mandatory = true
versionRange = "[20.2,)"
ordering = "NONE"
side = "BOTH"
modId = "neoforge"

[[dependencies.examplemod]]
mandatory = true
versionRange = "[1.1,)"
ordering = "AFTER"
side = "BOTH"
modId = "patchouli"

[[dependencies.examplemod]]
mandatory = true
versionRange = "[1.19.4,1.20)"
ordering = "NONE"
side = "BOTH"
modId = "minecraft"

[modproperties.examplemod]
customProperty = "hello_neoforge"

[[mixins]]
config = "no.mixin.json"

[[mixins]]
config = "test.mixin.json"
5 changes: 3 additions & 2 deletions Test/demo/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
"optional": false,
"id": "minecraft",
"versions": ">=1.19"
"versions": ">=1.19.4"
},
{
"optional": false,
Expand Down Expand Up @@ -69,6 +69,7 @@
}
},
"mixin": [
"no.mixin.json"
"no.mixin.json",
"test.mixin.json"
]
}
10 changes: 7 additions & 3 deletions Test/src/main/resources/mods.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ ModsDotGroovy.make {
customProperty = 'hello_forge'
}

onNeoForge {
customProperty = 'hello_neoforge'
}

onFabricAndQuilt {
customProperty = 'hello_quabric'
}
Expand All @@ -34,6 +38,7 @@ ModsDotGroovy.make {
//minecraft = 1.19..1.20 // equivalent to `minecraft = '[1.19,1.20)'`
minecraft = 19.4..20.0 // equivalent to `minecraft = '[1.19.4,1.20)'`
forge = '[43.0.0,)' // equivalent to `forge { versionRange = '[43.0.0,)' }`
neoforge = '[20.2,)' // equivalent to `neoforge { versionRange = '[20.2,)' }`
quiltLoader = '>=0.17.3'
fabricLoader = '[0.14.19,)'

Expand Down Expand Up @@ -90,7 +95,6 @@ ModsDotGroovy.make {
}
}

onFabricAndQuilt {
mixin = 'no.mixin.json'
}
mixin = 'no.mixin.json'
mixin = 'test.mixin.json'
}
42 changes: 37 additions & 5 deletions src/lib/groovy/ModsDotGroovy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ModsDotGroovy {
this.data = ['schemaVersion': 1]
break
case Platform.FORGE:
case Platform.NEOFORGE:
this.data = [:]
}
}
Expand Down Expand Up @@ -70,6 +71,26 @@ class ModsDotGroovy {
}
}

/**
* Run a given block only if the plugin is configuring the mods.toml file for NeoForge.
*/
void onNeoForge(Closure closure) {
if (platform === Platform.NEOFORGE) {
closure.resolveStrategy = DELEGATE_FIRST
closure.call()
}
}

/**
* Run a given block only if the plugin is configuring the mods.toml file for Forge or NeoForge.
*/
void onForgeAndNeo(Closure closure) {
if (platform === Platform.NEOFORGE || platform === Platform.FORGE) {
closure.resolveStrategy = DELEGATE_FIRST
closure.call()
}
}

/**
* Run a given block only if the plugin is configuring the quilt.mod.json file for quilt.
*/
Expand Down Expand Up @@ -109,6 +130,7 @@ class ModsDotGroovy {
switch (platform) {
case Platform.FABRIC:
case Platform.FORGE:
case Platform.NEOFORGE:
put 'license', license
break
case Platform.QUILT:
Expand All @@ -122,6 +144,7 @@ class ModsDotGroovy {
void setIssueTrackerUrl(String issueTrackerUrl) {
switch (platform) {
case Platform.FORGE:
case Platform.NEOFORGE:
put 'issueTrackerURL', issueTrackerUrl
break
case Platform.QUILT:
Expand Down Expand Up @@ -150,23 +173,23 @@ class ModsDotGroovy {
* For GroovyModLoader @GMod mods it should be {@code gml}.
*/
void setModLoader(String modLoader) {
if (platform === Platform.FORGE)
if (platform === Platform.NEOFORGE || platform === Platform.FORGE)
put 'modLoader', modLoader
}

/**
* A version range to match for the {@link #setModLoader(java.lang.String)}.
*/
void setLoaderVersion(String loaderVersion) {
if (platform === Platform.FORGE)
if (platform === Platform.NEOFORGE || platform === Platform.FORGE)
put 'loaderVersion', VersionRange.of(loaderVersion).toForge()
}

/**
* A version range to match for the {@link #setModLoader(java.lang.String)}.
*/
void setLoaderVersion(List<String> loaderVersion) {
if (platform === Platform.FORGE) {
if (platform === Platform.NEOFORGE || platform === Platform.FORGE) {
final VersionRange range = new VersionRange()
range.versions = loaderVersion.collectMany {VersionRange.of(it).versions}
put 'loaderVersion', range.toForge()
Expand Down Expand Up @@ -194,6 +217,7 @@ class ModsDotGroovy {

protected void pushMod(ImmutableModInfo modInfo) {
switch (platform) {
case Platform.NEOFORGE:
case Platform.FORGE:
final mods = (data.computeIfAbsent('mods', {[]}) as List)
modInfo.dependencies?.each {
Expand Down Expand Up @@ -347,14 +371,22 @@ class ModsDotGroovy {
}

/**
* Declare a mixin config. Only works on Fabric or Quilt.
* Declare a mixin config. Only works on Fabric, Quilt or NeoForge.
* @param mixins the mixin configs to declare
*/
void setMixin(List<String> mixins) {
if (platform === Platform.FABRIC) {
this.data = merge(this.data, ['mixins': mixins.toList()])
} else if (platform === Platform.QUILT) {
this.data = merge(this.data, ['mixin': mixins.toList()])
} else if (platform === Platform.NEOFORGE) {
// NeoForge supports setting mixin configs directly in the mods.toml file
// https://github.com/neoforged/FancyModLoader/pull/31
final mixinsCfg = data.computeIfAbsent('mixins', {[]}) as List

mixins.each {
mixinsCfg.add([config: it])
}
}
}

Expand Down Expand Up @@ -447,7 +479,7 @@ class ModsDotGroovy {
*/
@Nullable
String inferUpdateJsonUrl(final ImmutableModInfo modInfo) {
if (platform !== Platform.FORGE) return null
if (!(platform === Platform.NEOFORGE || platform === Platform.FORGE)) return null

final String displayOrIssueTrackerUrl = modInfo.displayUrl ?: ((String) data.issueTrackerURL) ?: ''
if (displayOrIssueTrackerUrl === null || displayOrIssueTrackerUrl.isEmpty() || displayOrIssueTrackerUrl.isAllWhitespace())
Expand Down
2 changes: 1 addition & 1 deletion src/lib/groovy/Platform.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import groovy.transform.CompileStatic

@CompileStatic
enum Platform {
FORGE, QUILT, FABRIC
FORGE, NEOFORGE, QUILT, FABRIC

Platform() {}
}
19 changes: 19 additions & 0 deletions src/lib/groovy/modsdotgroovy/DependenciesBuilder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ class DependenciesBuilder extends HashMap {
}
}

void neoforge(@DelegatesTo(value = NeoForgeDependency, strategy = DELEGATE_FIRST)
@ClosureParams(value = SimpleType, options = 'modsdotgroovy.NeoForgeDependency') final Closure closure) {
if (platform === Platform.NEOFORGE) {
final neoDependency = new NeoForgeDependency()
closure.delegate = neoDependency
closure.resolveStrategy = DELEGATE_FIRST
closure.call(neoDependency)
dependencies << neoDependency.copy()
}
}

void setNeoForge(final String versionRange) {
if (platform === Platform.NEOFORGE) {
final neoDependency = new NeoForgeDependency()
neoDependency.versionRange = versionRange
dependencies << neoDependency.copy()
}
}

void quiltLoader(@DelegatesTo(value = QuiltLoaderDependency, strategy = DELEGATE_FIRST)
@ClosureParams(value = SimpleType, options = 'modsdotgroovy.QuiltLoaderDependency') final Closure closure) {
if (platform === Platform.QUILT) {
Expand Down
17 changes: 17 additions & 0 deletions src/lib/groovy/modsdotgroovy/NeoForgeDependency.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2022 GroovyMC
* SPDX-License-Identifier: MIT
*/

package modsdotgroovy

import groovy.transform.CompileStatic

@CompileStatic
class NeoForgeDependency extends Dependency {
{
modId = 'neoforge'
mandatory = true
ordering = DependencyOrdering.NONE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.moandjiezana.toml.TomlWriter
import groovy.transform.CompileStatic

@CompileStatic
abstract class ConvertToTomlTask extends AbstractConvertTask {
abstract class ConvertToForgeTomlTask extends AbstractConvertTask {
@Override
protected String getOutputName() {
return 'mods.toml'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 GroovyMC
* SPDX-License-Identifier: MIT
*/

package io.github.groovymc.modsdotgroovy


import groovy.transform.CompileStatic

@CompileStatic
abstract class ConvertToNeoForgeTomlTask extends ConvertToForgeTomlTask {
@Override
protected void setupPlatformSpecificArguments() {
final mcDependency = project.configurations.findByName('minecraft')
?.getDependencies()?.find()
if (mcDependency !== null) {
final version = mcDependency.version.split('-')
arg('minecraftVersion', version[0])

// TODO: Extract out neoforge version
/*if (version.length > 1) {
arg('forgeVersion', version[1].split('_mapped_')[0])
}*/

final mcSplit = version[0].split('\\.')
if (mcSplit.length > 1) {
try {
final currentVersion = Integer.parseInt(mcSplit[1])
arg('minecraftVersionRange', "[${version[0]},1.${currentVersion + 1})")
} catch (Exception ignored) {}
}
}
}

@Override
protected String getPlatform() {
return 'neoforge'
}
}
Loading