diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ca3795..5c5dd81 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,39 +1,31 @@ -# Automatically build the project and run any configured tests for every push -# and submitted pull request. This can help catch issues that only occur on -# certain platforms or Java versions, and provides a first line of defence -# against bad commits. - name: build -on: [pull_request, push] +on: [ pull_request, push ] jobs: build: - strategy: - matrix: - # Use these Java versions - java: [ - 17, # Current Java LTS & minimum supported by Minecraft - ] - # and run on both Linux and Windows - os: [ubuntu-22.04, windows-2022] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest + + env: + PUBLISH_SUFFIX: snapshots + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASS: ${{ secrets.MAVEN_PASS }} + steps: - - name: checkout repository + - name: Checkout Repository uses: actions/checkout@v3 - - name: validate gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: setup jdk ${{ matrix.java }} + + - name: Setup JDK (Java 17) uses: actions/setup-java@v3 with: - java-version: ${{ matrix.java }} - distribution: 'microsoft' - - name: make gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: build - run: ./gradlew build - - name: capture build artifacts - if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS + java-version: 17 + + - name: gradlew Permission Grant + run: chmod +x gradlew + + - name: Build w/ Gradle + run: ./gradlew buildOrPublish + + - name: Capture Build Artifacts uses: actions/upload-artifact@v3 with: name: Artifacts diff --git a/README.md b/README.md index fd96346..817eefa 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,2 @@ -# Fabric Example Mod - -## Setup - -For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using. - -## License - -This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. +# Fabric Nautical Template +Team Nautical's take on the Fabric Example Mod \ No newline at end of file diff --git a/build.gradle b/build.gradle index 66710fb..14af9bc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,48 +1,27 @@ plugins { id 'fabric-loom' version '1.3-SNAPSHOT' id 'maven-publish' + id 'org.ajoberstar.grgit' version '5.2.0' } -version = project.mod_version +archivesBaseName = "${project.archives_base_name}+mc${libs.versions.minecraft.get()}" +version = getVersion() group = project.maven_group -base { - archivesName = project.archives_base_name -} - repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. + maven { url "https://api.modrinth.com/maven" } + maven { url "https://maven.terraformersmc.com/" } } -loom { - splitEnvironmentSourceSets() - - mods { - "modid" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } +dependencies { + minecraft libs.minecraft -} + mappings loom.officialMojangMappings() + modImplementation libs.fabric.loader -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - // Uncomment the following line to enable the deprecated Fabric API modules. - // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. - - // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" + modImplementation libs.fabric.api + modImplementation libs.bundles.dependencies + modLocalRuntime(libs.bundles.dev.mods) } processResources { @@ -73,19 +52,65 @@ jar { } } -// configure the maven publication +task buildOrPublish { + group = "build" + String mavenUser = System.getenv().MAVEN_USER + if (mavenUser != null && !mavenUser.isEmpty()) { + dependsOn(tasks.getByName("publish")) + println("prepared for publish") + } else { + dependsOn(tasks.getByName("build")) + println("prepared for build") + } +} + +// TODO: Uncomment for a non template mod! publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } +// publications { +// mavenJava(MavenPublication) { +// groupId = project.maven_group +// artifactId = project.archives_base_name +// version = "${project.mod_version}-rev.${grgit.head().abbreviatedId}" +// +// from components.java +// } +// } +// +// // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. +// repositories { +// maven { +// url = "https://mvn.devos.one/${System.getenv().PUBLISH_SUFFIX}/" +// credentials { +// username = System.getenv().MAVEN_USER +// password = System.getenv().MAVEN_PASS +// } +// authentication { basic(BasicAuthentication) } +// } +// } +} + +String getVersion() { + def mod_version = project.mod_version + def build_id = System.getenv("GITHUB_RUN_NUMBER") + + // CI builds only + if (build_id != null) { + return "${mod_version}+build.${build_id}" } - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. + if (grgit != null) { + def head = grgit.head() + def id = head.abbreviatedId + + // Flag the build if the build tree is not clean + if (!grgit.status().clean) { + id += "-dirty" + } + + return "${mod_version}+rev.${id}" } + + // No tracking information could be found about the build + return "${mod_version}+unknown" + } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 854298d..7c24489 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,16 +2,9 @@ org.gradle.jvmargs=-Xmx1G org.gradle.parallel=true -# Fabric Properties -# check these on https://fabricmc.net/develop -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.9 -loader_version=0.14.21 - # Mod Properties mod_version=1.0.0 -maven_group=com.example +maven_group=one.devos.nautical archives_base_name=modid -# Dependencies -fabric_version=0.85.0+1.20.1 \ No newline at end of file +# Dependencies are handled in ./gradle/libs.versions.toml \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..abb898c --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,29 @@ +[versions] +# The latest versions are available at https://fabricmc.net/develop +minecraft = "1.20.1" +fabric-loader = "0.14.21" + +fabric-api = "0.85.0+1.20.1" + +sodium_version = "mc1.20.1-0.5.0" +mod_menu_version = "7.2.0" +joml_version = "1.10.5" + +[libraries] +minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } +fabric_loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" } + +fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" } + +sodium = { module = "maven.modrinth:sodium", version.ref = "sodium_version" } +joml = { module = "org.joml:joml", version.ref = "joml_version" } +mod_menu = { module = "com.terraformersmc:modmenu", version.ref = "mod_menu_version" } + +# If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". +[bundles] +fabric_api = ["fabric-api"] +dev_mods = [ "joml", "sodium" ] +dependencies = [ "fabric-loader", "fabric-api", "mod_menu" ] + +[plugins] +fabric_loom = { id = "com.fabricmc.loom", version = "1.3-SNAPSHOT" } \ No newline at end of file diff --git a/src/client/java/com/example/ExampleModClient.java b/src/client/java/one/devos/nautical/ExampleModClient.java similarity index 90% rename from src/client/java/com/example/ExampleModClient.java rename to src/client/java/one/devos/nautical/ExampleModClient.java index e2b0436..09efdce 100644 --- a/src/client/java/com/example/ExampleModClient.java +++ b/src/client/java/one/devos/nautical/ExampleModClient.java @@ -1,4 +1,4 @@ -package com.example; +package one.devos.nautical; import net.fabricmc.api.ClientModInitializer; diff --git a/src/client/java/com/example/mixin/client/ExampleClientMixin.java b/src/client/java/one/devos/nautical/mixin/client/ExampleClientMixin.java similarity index 92% rename from src/client/java/com/example/mixin/client/ExampleClientMixin.java rename to src/client/java/one/devos/nautical/mixin/client/ExampleClientMixin.java index 061b0ef..1a9262c 100644 --- a/src/client/java/com/example/mixin/client/ExampleClientMixin.java +++ b/src/client/java/one/devos/nautical/mixin/client/ExampleClientMixin.java @@ -1,4 +1,4 @@ -package com.example.mixin.client; +package one.devos.nautical.mixin.client; import net.minecraft.client.MinecraftClient; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/client/resources/modid.client.mixins.json b/src/client/resources/modid.client.mixins.json index 21b0fc1..3392b11 100644 --- a/src/client/resources/modid.client.mixins.json +++ b/src/client/resources/modid.client.mixins.json @@ -3,7 +3,7 @@ "package": "com.example.mixin.client", "compatibilityLevel": "JAVA_17", "client": [ - "ExampleClientMixin" + "one.devos.nautical.mixin.client.ExampleClientMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/java/com/example/mixin/ExampleMixin.java b/src/main/java/com/example/mixin/ExampleMixin.java deleted file mode 100644 index 3c4212c..0000000 --- a/src/main/java/com/example/mixin/ExampleMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.mixin; - -import net.minecraft.server.MinecraftServer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -public class ExampleMixin { - @Inject(at = @At("HEAD"), method = "loadWorld") - private void init(CallbackInfo info) { - // This code is injected into the start of MinecraftServer.loadWorld()V - } -} \ No newline at end of file diff --git a/src/main/java/com/example/ExampleMod.java b/src/main/java/one/devos/nautical/ExampleMod.java similarity index 96% rename from src/main/java/com/example/ExampleMod.java rename to src/main/java/one/devos/nautical/ExampleMod.java index f97cce9..5f32f3c 100644 --- a/src/main/java/com/example/ExampleMod.java +++ b/src/main/java/one/devos/nautical/ExampleMod.java @@ -1,4 +1,4 @@ -package com.example; +package one.devos.nautical; import net.fabricmc.api.ModInitializer; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5b8a367..c18ed32 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,26 +16,19 @@ "environment": "*", "entrypoints": { "main": [ - "com.example.ExampleMod" + "one.devos.nautical.ExampleMod" ], "client": [ - "com.example.ExampleModClient" + ] }, "mixins": [ - "modid.mixins.json", - { - "config": "modid.client.mixins.json", - "environment": "client" - } + "modid.mixins.json" ], "depends": { "fabricloader": ">=0.14.21", "minecraft": "~1.20.1", "java": ">=17", "fabric-api": "*" - }, - "suggests": { - "another-mod": "*" } } \ No newline at end of file diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/modid.mixins.json index 166e787..32a3924 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/modid.mixins.json @@ -1,9 +1,12 @@ { "required": true, - "package": "com.example.mixin", + "package": "one.devos.nautical.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ExampleMixin" + + ], + "client": [ + ], "injectors": { "defaultRequire": 1