Skip to content

Commit

Permalink
add mixin support and fix runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftschurli committed Mar 8, 2024
1 parent e01c968 commit d9422d2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

group = "com.github.minecraftschurlimods"
version = "1.6"
version = "1.7"
base.archivesName = "HelperPlugin"

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.SourceSet
Expand Down Expand Up @@ -87,6 +88,7 @@ open class HelperExtension @Inject constructor(private val project: Project) {
.convention(project.layout.projectDirectory.dir("src/main/generated"))
val dependencies: ModDependencyContainer = project.objects.newInstance<ModDependencyContainer>()
val modproperties: MapProperty<String, String> = project.objects.mapProperty()
val mixinConfigs: SetProperty<String> = project.objects.setProperty()

init {
dependencies {
Expand Down Expand Up @@ -219,7 +221,9 @@ open class HelperExtension @Inject constructor(private val project: Project) {
}
project.artifacts.add("archives", apiJar)
publication.artifact(apiJar)
project.runs.configureEach { modSource(apiSourceSet) }
project.runs.all {
modSources.add(apiSourceSet)
}
}

private lateinit var testSourceSet: SourceSet
Expand All @@ -233,7 +237,11 @@ open class HelperExtension @Inject constructor(private val project: Project) {
testSourceSet.implementationConfigurationName(apiSourceSet.output)
}
}
project.runs.findByName("gameTestServer")?.modSource(testSourceSet)
project.runs.all {
if (name != "data") {
modSources.add(testSourceSet)
}
}
}

private lateinit var dataGenSourceSet: SourceSet
Expand All @@ -247,19 +255,19 @@ open class HelperExtension @Inject constructor(private val project: Project) {
dataGenSourceSet.implementationConfigurationName(apiSourceSet.output)
}
}
project.runs.findByName("data")?.modSource(dataGenSourceSet)
project.runs.findByName("data")?.modSources?.add(dataGenSourceSet)
}

fun withCommonRuns() {
project.runs {
configureEach {
all {
workingDirectory.set(project.layout.projectDirectory.dir("run"))
systemProperties.put("forge.logging.markers", "REGISTRIES")
systemProperties.put("forge.logging.console.level", "debug")
modSources.add(project.sourceSets.main)
if (!runningInCI.getOrElse(false)) {
jvmArgument("-XX:+AllowEnhancedClassRedefinition")
}
modSources.add(project.sourceSets.main)
}
create("client")
create("server") {
Expand All @@ -272,9 +280,6 @@ open class HelperExtension @Inject constructor(private val project: Project) {
fun withDataGenRuns(cfg: Action<Run> = Action<Run>{}) {
project.runs.create("data") {
singleInstance()
if (::dataGenSourceSet.isInitialized) {
modSource(dataGenSourceSet)
}
programArguments.add("--mod")
programArguments.add(projectId)
programArguments.add("--all")
Expand All @@ -293,12 +298,9 @@ open class HelperExtension @Inject constructor(private val project: Project) {
}

fun withGameTestRuns(cfg: Action<Run> = Action<Run>{}) {
project.runs.configureEach {
project.runs.all {
if (name != "data") {
systemProperties.put("forge.enabledGameTestNamespaces", projectId)
if (::testSourceSet.isInitialized) {
modSource(testSourceSet)
}
systemProperties.put("neoforge.enabledGameTestNamespaces", projectId)
}
}
project.runs.create("gameTestServer") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class HelperPlugin : Plugin<Project> {
val generateModsToml = register<GenerateModsTomlTask>("generateModsToml") {
modsToml.set(project.provider {
val modproperties = helperExtension.modproperties.orNull
val mixins = helperExtension.mixinConfigs.orNull ?: setOf<String>()
val dependencies: List<Dependency> = helperExtension.dependencies.map {
val mcPublish = DependencyMcPublish(
it.modrinthId.orNull,
Expand Down Expand Up @@ -198,6 +199,7 @@ class HelperPlugin : Plugin<Project> {
authors = helperExtension.projectAuthors.orNull,
description = helperExtension.projectDescription.orNull
)),
mixins = if (mixins.isNotEmpty()) mixins.map { Mixin(it) } else null,
mcPublish = if (mcPublish.modrinth != null || mcPublish.curseforge != null) mcPublish else null,
dependencies = if (dependencies.isNotEmpty()) mapOf(projectId to dependencies) else null,
modproperties = if (!modproperties.isNullOrEmpty()) mapOf(projectId to modproperties) else null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.minecraftschurlimods.helperplugin

import com.github.minecraftschurlimods.helperplugin.moddependencies.ModDependency
import net.neoforged.gradle.common.extensions.JarJarExtension
import net.neoforged.gradle.dsl.common.runs.run.Run
import net.neoforged.gradle.util.TransformerUtils
Expand Down Expand Up @@ -50,3 +51,5 @@ val TaskContainer.javadocJar: TaskProvider<Jar> get() = named<Jar>("javadocJar")

operator fun JavaPluginExtension.invoke(action: Action<JavaPluginExtension>) = action.execute(this)
operator fun PublishingExtension.invoke(action: Action<PublishingExtension>) = action.execute(this)

val NamedDomainObjectProvider<ModDependency>.version: Provider<String> get() = flatMap { it.version }
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class ModsToml(
val license: String,
val issueTrackerURL: String?,
val mods: List<Mod>,
val mixins: List<Mixin>?,
@SerialName("mc-publish")
val mcPublish: McPublish?,
val dependencies: Map<String, List<Dependency>>?,
Expand All @@ -33,6 +34,11 @@ data class Mod(
val description: String?,
) : java.io.Serializable

@Serializable
data class Mixin(
val config: String
) : java.io.Serializable

@Serializable
data class McPublish(
val modrinth: String?,
Expand Down

0 comments on commit d9422d2

Please sign in to comment.