Skip to content

Commit

Permalink
Support neoforge platform, move to using architectury (#125)
Browse files Browse the repository at this point in the history
* rebase

* split fabric/neoforge specific code

* more progress

* dependency configuration

* exclude more junk

* neo, you make me go insane

* neoforge seems to work!

* some minor cleanup, add neoforge command module 

* mixin config plugin shenanigans

* fix language strings loading

* some cleanup, yeet Jenkinsfile

* proper repository declaration using plugin, target jitpack branch

* oops

* address reviews

* Update for 1.21

* some minor fixes

* Fix modrinth task, add floodgate version command mixin to disable version checking, update to loom 1.7, update cloud, update floodgate core to not use my branch

* oops

* what on earth is going on now

* neoforge works again!!!!!!!!!

* Address review, dont rely on locals in mixin

* modrinth version/name changes, similar to geyser

* Update README.md

Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com>

* Improve handling of PayloadRegistrar

this took years off my life

* address review

* Move blossom version declaration to libs.versions.toml

* remove unused versions from catalogue

* Only run modrinth task if successful & on Geyser repo

* cleanup & fix gh actions building/archiving

* run and uses are different steps

---------

Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com>
  • Loading branch information
onebeastchris and Konicai authored Sep 10, 2024
1 parent 4502fd2 commit 0ef0659
Show file tree
Hide file tree
Showing 76 changed files with 1,507 additions and 586 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@72f2cec99f417b1a1c5e2e88945068983b7965f9
- uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4
- uses: actions/setup-java@4075bfc1b51bf22876335ae1cd589602d60d8758
- name: Setup Gradle
uses: GeyserMC/actions/setup-gradle-composite@master
with:
distribution: 'temurin'
java-version: 21
setup-java_java-version: 21

- name: Build Floodgate-Modded
run: ./gradlew build

- name: Publish to Modrinth
if: ${{ success() && github.repository == 'GeyserMC/Floodgate-Modded' && github.ref_name == 'master' }}
uses: gradle/gradle-build-action@3bfe3a46584a206fb8361cdedd0647b0c4204232
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
with:
arguments: modrinth
gradle-home-cache-cleanup: true

- name: Archive Artifacts
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
uses: GeyserMC/actions/upload-multi-artifact@master
if: success()
with:
name: Floodgate Fabric
path: build/libs/floodgate-fabric.jar
if-no-files-found: error
artifacts: |
Floodgate-Fabric:fabric/build/libs/floodgate-fabric.jar
Floodgate-NeoForge:neoforge/build/libs/floodgate-neoforge.jar
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Floodgate-Fabric
Fabric port of the hybrid mode plugin to allow for connections from Geyser to join online mode servers.
# Floodgate-Modded
Fabric and NeoForge ports of the hybrid mode plugin to allow for connections from Geyser to join online mode servers.

Download: https://ci.opencollab.dev/job/GeyserMC/job/Floodgate-Fabric/job/master/
Hybrid mode mod to allow for connections from Geyser to join online mode servers.
Geyser is an open collaboration project by CubeCraft Games.

See the Floodgate section in the GeyserMC Wiki for more info about what Floodgate is, how you setup Floodgate and known issues/caveats.
Additionally, it includes a more in-depth look into how Floodgate works and the Floodgate API.

Wiki: https://wiki.geysermc.org/floodgate/
Download: https://modrinth.com/mod/floodgate
23 changes: 23 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
mavenCentral()
maven("https://maven.architectury.dev/")
maven("https://maven.fabricmc.net/")
maven("https://maven.neoforged.net/releases/")
}

dependencies {
// Used to access version catalogue from the convention plugins
// this is OK as long as the same version catalog is used in the main build and build-logic
// see https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.indra)
implementation(libs.shadow)
implementation(libs.architectury.plugin)
implementation(libs.architectury.loom)
implementation(libs.minotaur)
}
11 changes: 11 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@file:Suppress("UnstableApiUsage")

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
6 changes: 6 additions & 0 deletions build-logic/src/main/kotlin/LibsAccessor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType

val Project.libs: LibrariesForLibs
get() = rootProject.extensions.getByType()
36 changes: 36 additions & 0 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import org.gradle.api.Project
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.provider.Provider

val providedDependencies = mutableMapOf<String, MutableSet<String>>()

fun Project.provided(pattern: String, name: String, excludedOn: Int = 0b110) {
providedDependencies.getOrPut(project.name) { mutableSetOf() }
.add("${calcExclusion(pattern, 0b100, excludedOn)}:${calcExclusion(name, 0b10, excludedOn)}")
}

fun Project.provided(dependency: ProjectDependency) =
provided(dependency.group!!, dependency.name)

fun Project.provided(dependency: MinimalExternalModuleDependency) =
provided(dependency.module.group, dependency.module.name)

fun Project.provided(provider: Provider<MinimalExternalModuleDependency>) =
provided(provider.get())

fun getProvidedDependenciesForProject(projectName: String): MutableSet<String> {
return providedDependencies.getOrDefault(projectName, emptySet()).toMutableSet()
}

private fun calcExclusion(section: String, bit: Int, excludedOn: Int): String =
if (excludedOn and bit > 0) section else ""

fun projectVersion(project: Project): String =
project.version.toString().replace("SNAPSHOT", "b" + buildNumber())

fun versionName(project: Project): String =
"Floodgate-" + project.name.replaceFirstChar { it.uppercase() } + "-" + projectVersion(project)

fun buildNumber(): Int =
(System.getenv("GITHUB_RUN_NUMBER"))?.let { Integer.parseInt(it) } ?: -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
`java-library`
id("net.kyori.indra")
}

dependencies {
compileOnly("org.checkerframework", "checker-qual", "3.19.0")
}

indra {
github("GeyserMC", "floodgate-modded") {
ci(true)
issues(true)
scm(true)
}
mitLicense()

javaVersions {
target(21)
}
}

tasks {
processResources {
filesMatching(listOf("fabric.mod.json", "META-INF/neoforge.mods.toml")) {
expand(
"id" to "floodgate",
"name" to "Floodgate",
"version" to project.version,
"description" to project.description,
"url" to "https://geysermc.org",
"author" to "GeyserMC",
"minecraft_version" to libs.versions.minecraft.version.get()
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repositories {
// mavenLocal()
mavenCentral()
maven("https://maven.fabricmc.net/")
maven("https://maven.neoforged.net/releases")
maven("https://repo.opencollab.dev/main/")
maven("https://jitpack.io") {
content {
includeGroupByRegex("com.github.*")
}
}
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import net.fabricmc.loom.task.RemapJarTask

plugins {
id("floodgate-modded.publish-conventions")
id("architectury-plugin")
id("dev.architectury.loom")
id("com.modrinth.minotaur")
}

// These are all provided by Minecraft/server platforms
provided("com.google.code.gson", "gson")
provided("org.slf4j", ".*")
provided("com.google.guava", "guava")
provided("org.ow2.asm", "asm")
provided("com.nukkitx.fastutil", ".*")

// these we just don't want to include
provided("org.checkerframework", ".*")
provided("com.google.errorprone", ".*")
provided("com.github.spotbugs", "spotbugs-annotations")
provided("com.google.code.findbugs", ".*")

// cloud-fabric/cloud-neoforge jij's all cloud depends already
provided("org.incendo", ".*")
provided("io.leangen.geantyref", "geantyref")

architectury {
minecraft = libs.versions.minecraft.version.get()
}

loom {
silentMojangMappingsLicense()
}

configurations {
create("includeTransitive").isTransitive = true
}

dependencies {
minecraft(libs.minecraft)
mappings(loom.officialMojangMappings())

// These are under our own namespace
shadow(libs.floodgate.api) { isTransitive = false }
shadow(libs.floodgate.core) { isTransitive = false }

// Requires relocation
shadow(libs.bstats) { isTransitive = false }

// Shadow & relocate these since the (indirectly) depend on quite old dependencies
shadow(libs.guice) { isTransitive = false }
shadow(libs.configutils) {
exclude("org.checkerframework")
exclude("com.google.errorprone")
exclude("com.github.spotbugs")
exclude("com.nukkitx.fastutil")
}

}

tasks {
sourcesJar {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}

shadowJar {
// Mirrors the example fabric project, otherwise tons of dependencies are shaded that shouldn't be
configurations = listOf(project.configurations.shadow.get())

// Relocate these
relocate("org.bstats", "org.geysermc.floodgate.shadow.bstats")
relocate("com.google.inject", "org.geysermc.floodgate.shadow.google.inject")
relocate("org.yaml", "org.geysermc.floodgate.shadow.org.yaml")

// The remapped shadowJar is the final desired mod jar
archiveVersion.set(project.version.toString())
archiveClassifier.set("shaded")
}

remapJar {
dependsOn(shadowJar)
inputFile.set(shadowJar.get().archiveFile)
archiveClassifier.set("")
archiveVersion.set("")
}

register("remapModrinthJar", RemapJarTask::class) {
dependsOn(shadowJar)
inputFile.set(shadowJar.get().archiveFile)
archiveVersion.set(versionName(project))
archiveClassifier.set("")
}

// Readme sync
modrinth.get().dependsOn(tasks.modrinthSyncBody)
}

afterEvaluate {
val providedDependencies = getProvidedDependenciesForProject(project.name)

// These are shaded, no need to JiJ them
configurations["shadow"].resolvedConfiguration.resolvedArtifacts.forEach {shadowed ->
val string = "${shadowed.moduleVersion.id.group}:${shadowed.moduleVersion.id.name}"
println("Not including shadowed dependency: $string")
providedDependencies.add(string)
}

configurations["includeTransitive"].resolvedConfiguration.resolvedArtifacts.forEach { dep ->
if (!providedDependencies.contains("${dep.moduleVersion.id.group}:${dep.moduleVersion.id.name}")
and !providedDependencies.contains("${dep.moduleVersion.id.group}:.*")) {
println("Including dependency via JiJ: ${dep.id}")
dependencies.add("include", dep.moduleVersion.id.toString())
} else {
println("Not including ${dep.id} for ${project.name}!")
}
}
}

modrinth {
token.set(System.getenv("MODRINTH_TOKEN")) // Even though this is the default value, apparently this prevents GitHub Actions caching the token?
projectId.set("bWrNNfkb")
versionName.set(versionName(project))
versionNumber.set(projectVersion(project))
versionType.set("release")
changelog.set("A changelog can be found at https://github.com/GeyserMC/Floodgate-Modded/commits")

syncBodyFrom.set(rootProject.file("README.md").readText())

uploadFile.set(tasks.getByPath("remapModrinthJar"))
gameVersions.add(libs.minecraft.get().version as String)
gameVersions.add("1.21.1")
failSilently.set(false)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id("floodgate-modded.shadow-conventions")
id("net.kyori.indra.publishing")
}

indra {
publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/maven-snapshots")
publishReleasesTo("geysermc", "https://repo.opencollab.dev/maven-releases")
}

publishing {
// skip shadow jar from publishing. Workaround for https://github.com/johnrengelman/shadow/issues/651
val javaComponent = project.components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("floodgate-modded.base-conventions")
id("com.github.johnrengelman.shadow")
}

tasks {
named<Jar>("jar") {
archiveClassifier.set("unshaded")
from(project.rootProject.file("LICENSE"))
}
val shadowJar = named<ShadowJar>("shadowJar") {
archiveBaseName.set(project.name)
archiveVersion.set("")
archiveClassifier.set("")

val sJar: ShadowJar = this

doFirst {
providedDependencies[project.name]?.forEach { string ->
sJar.dependencies {
println("Excluding $string from ${project.name}")
exclude(dependency(string))
}
}

sJar.dependencies {
exclude(dependency("org.checkerframework:checker-qual:.*"))
exclude(dependency("org.jetbrains:annotations:.*"))
}
}
}
named("build") {
dependsOn(shadowJar)
}
}
Loading

0 comments on commit 0ef0659

Please sign in to comment.