diff --git a/README.md b/README.md index 946733c..46172e9 100644 --- a/README.md +++ b/README.md @@ -12,30 +12,37 @@ The official VS Addon template, for VS 2.4.0 and onward! ### Namespace / Mod ID This template's default namespace/mod ID is "vs_template"- you'll likely want to change this! +**Note:** Mod ids can only have lowercase letters and underscores! Other characters will make your mod invalid! + You can do so by altering the following files: - Change the base package name in `settings.gradle.kts` -- Change the name and id variables in `gradle.properties` -- Change the MOD_ID in `VSTemplateMod.kt` in the `common` module -- Edit the `mods.toml` file in `src/main/resources/META-INF/` in the `forge` module -- Edit the `fabric.mod.json` file in `src/main/resources/` in the `fabric` module +- Change the mod_name and mod_id variables in `gradle.properties` +- Change the MOD_ID in `VSTemplateModForge.kt` You should also rename anything prefixed with "VSTemplate" to your mod's name! +Keep in mind files are case-sensitive, for example: +- `VSTemplateMod.kt` -> `MySpecialMod.kt` :heavy_check_mark: +- `vs_templatae.mixins.json` -> `myspecialmod.mixins.json` :heavy_check_mark: +- `VSTemplateMod.kt` -> `mySpecialMod.kt` :x: (ok technically this is legal, but it's ugly) +- `vs_template.mixins.json` -> `MySpecialMod.mixins.json` :x: -If you are using IntelliJ, it is reccomended to refactor in your IDE rather than +If you are using IntelliJ, it is recommended to refactor in your IDE rather than changing the file name in file explorer, as it will automatically edit the references to the old name to match your new one. +IntelliJ tip: ctrl+shift+r for a project-wide find and replace + ### Understanding Dependencies In this mod's `gradle.properties` file, you will find a few properties that define the versions of each dependency this project has, including VS2 and its core. You can change these properties to update dependency versions easily across the entire project, without having to edit buildscripts! -Most dependencies have some easy way to discover the latest/reccomended version to depend on. +Most dependencies have some easy way to discover the latest/recommended version to depend on. Valkyrien Skies itself is similar! The `vs_core_version` property should be equal to the identically named property in the [Valkyrien Skies Github Repo](https://github.com/ValkyrienSkies/Valkyrien-Skies-2), and the `vs2_version` is the mod version, followed by the first 10 characters of the latest commit hash. You can find the most recent -retrievable version of VS easily by going to the Packages tab for [Fabric](https://github.com/ValkyrienSkies/Valkyrien-Skies-2/packages/2020982) or [Forge](https://github.com/ValkyrienSkies/Valkyrien-Skies-2/packages/2020984)! +retrievable version of VS easily by going to the Packages tab for [Fabric](https://github.com/ValkyrienSkies/Valkyrien-Skies-2/packages/2020982) or [Forge](https://github.com/ValkyrienSkies/Valkyrien-Skies-2/packages/2020984)! ### Building and Running Before running the mod after each change made, it is recommended to run the `./gradlew clean` task in your command line, followed by clicking the sync button in the top right. @@ -43,16 +50,15 @@ This ensures the files built are up to date with your code changes. Alternatively to gradle clean, you can also manually delete your build folders. This is helpful if that task fails, for whatever reason. +To run the mod, run the `mod development/runClient` gradle task. + +To get an exported jar, run the `build/build` gradle task, then find your jar at `/build/libs` + ### Mod Structure -This mod template uses a multiloader structure, with 3 modules: -- `common` : This module contains code shared between both Fabric and Forge. This is where the majority of your mod's code should go! -- `fabric` : This module contains code specific to the Fabric loader. This includes the Fabric mod initializer, and any Fabric-specific implementations of common code. -- `forge` : This module contains code specific to the Forge loader. This includes the Forge mod class, and any Forge-specific implementations of common code. -Within each module, you will find 3 primary submodules: - `src/main/java` : This is where Java code goes. This is primarily used for Mixins, as Mixins cannot be written in Kotlin. You may also choose to relocate your primary mod files here, and not use Kotlin at all if you wish. - `src/main/kotlin` : This is where Kotlin code goes. VS is primarily written in Kotlin, so it tends to be easier to work with VS when also writing in Kotlin. -- `src/main/resources` : This is where resources go, such as Forge's `mods.toml`, Fabric's `fabric.mod.json`, mod assets, and data files. +- `src/main/resources` : This is where resources go, such as Forge's `mods.toml`, block models, item textures, etc ### Using the VS Api You can access the VS Core Api statically through `ValkyrienSkies.api` (with parenthesis for a method call in Java). The API's javadocs contain tons of extra information on how to use each part of it, so give them a read! diff --git a/build.gradle b/build.gradle index f3010fc..1c2a50f 100644 --- a/build.gradle +++ b/build.gradle @@ -13,8 +13,8 @@ buildscript { } plugins { - id 'dev.architectury.loom' version '1.3.355' - id 'architectury-plugin' version '3.4.146' + id 'net.neoforged.moddev.legacyforge' version '2.0.137' + id "org.jetbrains.kotlin.jvm" version "$kotlin_version" id 'com.matthewprenger.cursegradle' version '1.4.0' @@ -22,170 +22,167 @@ plugins { id "com.github.johnrengelman.shadow" version "7.1.2" } -// Version determinance in line with VS conventions -if (project.hasProperty("CustomReleaseVersion")) { - // Remove release/ from the version if present - version = project.property("CustomReleaseVersion").replaceFirst("^release/", "") -} else { - String gitRevision = "git rev-parse HEAD".execute().text.trim() - if (gitRevision.isEmpty()) { - gitRevision = 'unknown' - } - - version = mod_version + '+' + (gitRevision.length() >= 10 ? gitRevision.substring(0, 10) : gitRevision) +java { + withSourcesJar() } -architectury { - minecraft = project.minecraft_version - platformSetupLoomIde() - forge() -} +legacyForge { + version = "${minecraft_version}-${forge_version}" -allprojects { -// apply plugin: "java" -// apply plugin: "kotlin" -// apply plugin: "architectury-plugin" -// apply plugin: "maven-publish" -// apply plugin: 'dev.architectury.loom' -// apply plugin: "org.jetbrains.kotlin.jvm" - - archivesBaseName = rootProject.archives_base_name - version = rootProject.version - group = rootProject.maven_group - - // Copied from VS oddities. Forces arch to use the right version (which it doesn't for some reason on some machines) - configurations.configureEach { - resolutionStrategy.force "org.lwjgl:lwjgl-stb:3.3.1" - resolutionStrategy.force "org.lwjgl:lwjgl-opengl:3.3.1" - resolutionStrategy.force "org.lwjgl:lwjgl-openal:3.3.1" - resolutionStrategy.force "org.lwjgl:lwjgl-tinyfd:3.3.1" - resolutionStrategy.force "org.lwjgl:lwjgl-jemalloc:3.3.1" - resolutionStrategy.force "org.lwjgl:lwjgl-glfw:3.3.1" - resolutionStrategy.force "org.lwjgl:lwjgl:3.3.1" - } + // Validate AT files and raise errors when they have invalid targets + // This option is false by default, but turning it on is recommended + validateAccessTransformers = true - repositories { - //Add any repositories to fetch dependencies from here. - //Most dependencies are mirrored to the VS Maven, so by default only it is included alongside mavenLocal and KFF. - mavenLocal() - maven { - name = "Valkyrien Skies Internal" - url = project.vs_maven_url ?: 'https://maven.valkyrienskies.org' - if (project.vs_maven_username && project.vs_maven_password) { - credentials { - username = project.vs_maven_username - password = project.vs_maven_password - } - } + runs { + client { + client() } - maven { - name = 'Kotlin for Forge' - url = 'https://thedarkcolour.github.io/KotlinForForge/' - content { includeGroup "thedarkcolour" } + data { + data() + } + server { + server() } } - loom { - silentMojangMappingsLicense() - } - - dependencies { - minecraft "net.minecraft:minecraft:$rootProject.minecraft_version" - mappings loom.officialMojangMappings() + mods { + // Should this be vs_addon_template instead of testproject? I'm not sure + testproject { + sourceSet sourceSets.main + } } +} - java { - withSourcesJar() - } +var mixinId = "vstemplate" - tasks.withType(JavaCompile).configureEach { - options.encoding = "UTF-8" +mixin { + add sourceSets.main, "mixins.${mixinId}.refmap.json" - options.release = 17 - } + config "${mixinId}.mixins.json" +} - tasks.withType(KotlinJvmCompile).configureEach { - kotlinOptions { - jvmTarget = "17" - freeCompilerArgs += "-Xjvm-default=all" +// Include resources generated by data generators. +sourceSets.main.resources { srcDir 'src/generated/resources' } + +repositories { + //Add any repositories to fetch dependencies from here. + //Most dependencies are mirrored to the VS Maven, so by default only it is included alongside mavenLocal and KFF. + mavenLocal() + maven { + name = "Valkyrien Skies Internal" + url = project.vs_maven_url ?: 'https://maven.valkyrienskies.org' + if (project.vs_maven_username && project.vs_maven_password) { + credentials { + username = project.vs_maven_username + password = project.vs_maven_password + } } } - - String buildNumber = System.getenv("GITHUB_RUN_NUMBER") + maven { + name = 'Kotlin for Forge' + url = 'https://thedarkcolour.github.io/KotlinForForge/' + content { includeGroup "thedarkcolour" } + } } -dependencies { - forge("net.minecraftforge:forge:${minecraft_version}-${forge_version}") - include(modApi("dev.architectury:architectury-forge:${rootProject.architectury_api_version}")) - implementation(include((("io.github.llamalad7:mixinextras-forge:0.4.1")))) +dependencies { + // region mixins + annotationProcessor "org.spongepowered:mixin:0.8.5:processor" + compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1")) + // endregion - //VS2 Dependencies. The latest VS2 and VSCore versions can be retrieved from the Valkyrien Skies Github repository. - //The version tag is usually the major version, followed by the first 10 characters of the git commit hash. - //The VSCore version tag can be grabbed directly from the gradle.properties file in the Valkyrien skies repo. - modApi("org.valkyrienskies:valkyrienskies-120-forge:${rootProject.vs2_version}") { transitive = false - exclude group: 'org.valkyrienskies.core', module: '' - exclude group: "com.simibubi.create" - exclude group: "io.github.fabricators_of_create" - exclude group: "dev.engine-room" - exclude group: "dev.engine_room" + // region Valkyrien Skies + implementation("org.valkyrienskies.core:api:${vs_core_version}") { transitive = false + exclude group: 'org.joml', module: '' } - implementation("org.valkyrienskies.core:api:${rootProject.vscore_version}") { transitive = false + implementation("org.valkyrienskies.core:internal:${vs_core_version}") { transitive = false exclude group: 'org.joml', module: '' } - implementation("org.valkyrienskies.core:util:${rootProject.vscore_version}") { transitive = false + implementation("org.valkyrienskies.core:util:${vs_core_version}") { transitive = false exclude group: 'org.joml', module: '' } - implementation("org.valkyrienskies.core:internal:${rootProject.vscore_version}") { transitive = false + implementation("org.valkyrienskies.core:impl:${vs_core_version}") { transitive = false exclude group: 'org.joml', module: '' } + modApi("org.valkyrienskies:valkyrienskies-120-forge:${vs2_version}") { transitive = false + exclude group: 'org.valkyrienskies.core', module: '' + } + // endregion - // Kotlin - implementation("thedarkcolour:kotlinforforge:${rootProject.kotlin_forge}") - + // region VS deps + implementation "com.fasterxml.jackson.core:jackson-annotations:2.13.3" compileOnly("org.joml:joml:1.10.4") compileOnly("org.joml:joml-primitives:1.10.0") + modImplementation "thedarkcolour:kotlinforforge:4.11.0" + // endregion + + // Create + //modImplementation("com.simibubi.create:create-${minecraft_version}:${create_version}:slim") { transitive = false } + //modImplementation("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}") + //modCompileOnly("dev.engine-room.flywheel:flywheel-forge-api-${minecraft_version}:${flywheel_version}") + //modRuntimeOnly("dev.engine-room.flywheel:flywheel-forge-${minecraft_version}:${flywheel_version}") + //modImplementation("com.tterrag.registrate:Registrate:${registrate_version}") + + // JEI + //modCompileOnly("mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}") + //modImplementation("mezz.jei:jei-${minecraft_version}-forge:${jei_version}") } -processResources { - filesMatching("META-INF/mods.toml") { - expand "version": version - } + +tasks.withType(JavaCompile).configureEach { + options.encoding = "UTF-8" + + options.release = 17 } -loom { - forge { - mixinConfig "vs_template.mixins.json" - convertAccessWideners.set(true) - } - mixin { - defaultRefmapName = "vs_template-refmap.json" +tasks.withType(KotlinJvmCompile).configureEach { + kotlinOptions { + jvmTarget = "17" + freeCompilerArgs += "-Xjvm-default=all" + } } -tasks.withType(JavaCompile).configureEach { - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 17 +jar { + manifest { + attributes([ + "Specification-Title": mod_id, + "Specification-Vendor": mod_authors, + "Specification-Version": "1", + "Implementation-Title": project.name, + "Implementation-Version": mod_version, + "Implementation-Vendor": mod_authors, + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + "MixinConfigs": "${mixinId}.mixins.json", // TODO: figure out why the MixinConfigs field did not add automatically + ]) + } } -shadowJar { - archiveClassifier.set "dev-shadow" +configurations { + shade + implementation.extendsFrom shade } -remapJar { - input.set shadowJar.archiveFile - dependsOn shadowJar - archiveClassifier.set null -} +processResources { + var replaceProperties = [ + mod_id : mod_id, + mod_name : mod_name, + mod_license : mod_license, + mod_version : mod_version, + mod_authors : mod_authors, + mod_description : mod_description + ] -jar { - archiveClassifier.set "dev" -} + inputs.properties replaceProperties -components.java { - withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { - skip() + filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { + expand replaceProperties + [project: project] } } +tasks.withType(JavaCompile).configureEach { + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 +} diff --git a/gradle.properties b/gradle.properties index 722cfd2..d98a973 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,9 +5,14 @@ org.gradle.parallel=true # Meta dependency kotlin_version=2.0.0 -# Mod properties +# Mod properties (mostly for the mods.toml metadata) mod_version = 1.0.0 mod_id = vs_template +mod_name = Valkyrien Skies Addon Template +mod_license = MIT +mod_authors = Me! +mod_description = multiline \n description goes here + maven_group = org.valkyrienskies archives_base_name = vs-template-mod enabled_platforms = forge @@ -17,19 +22,20 @@ loom.platform = forge minecraft_version = 1.20.1 # Dependencies -architectury_api_version = 9.1.12 -fabric_loader_version = 0.14.24 -fabric_api_version = 0.90.7+1.20.1 forge_version = 47.4.10 # VS dependencies vs2_version=2.4.0+7e18c81efc -vscore_version=1.1.0+3434464932 +vs_core_version=1.1.0+3434464932 # Kotlin platform dependencies kotlin_forge=4.11.0 kotlin_fabric=1.11.0+kotlin.2.0.0 +# Makes MDG use parchment +neoForge.parchment.minecraftVersion=1.20.1 +neoForge.parchment.mappingsVersion=2023.09.03 + # Leave blank, only ever set in CI tasks. vs_maven_url= vs_maven_username= diff --git a/settings.gradle.kts b/settings.gradle.kts index 7cc2666..31ac264 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,4 +23,4 @@ pluginManagement { } } -rootProject.name = "vs-template-mod" +rootProject.name = "vs_template" diff --git a/src/main/java/org/valkyrienskies/vs_template/forge/mixin/mixins.md b/src/main/java/org/valkyrienskies/vs_template/mixin/mixins.md similarity index 100% rename from src/main/java/org/valkyrienskies/vs_template/forge/mixin/mixins.md rename to src/main/java/org/valkyrienskies/vs_template/mixin/mixins.md diff --git a/src/main/kotlin/org/valkyrienskies/vs_template/forge/VSTemplateModForge.kt b/src/main/kotlin/org/valkyrienskies/vs_template/VSTemplateModForge.kt similarity index 94% rename from src/main/kotlin/org/valkyrienskies/vs_template/forge/VSTemplateModForge.kt rename to src/main/kotlin/org/valkyrienskies/vs_template/VSTemplateModForge.kt index b36a1f2..5aad9dd 100644 --- a/src/main/kotlin/org/valkyrienskies/vs_template/forge/VSTemplateModForge.kt +++ b/src/main/kotlin/org/valkyrienskies/vs_template/VSTemplateModForge.kt @@ -1,4 +1,4 @@ -package org.valkyrienskies.vs_template.forge +package org.valkyrienskies.vs_template import net.minecraft.world.item.BlockItem import net.minecraft.world.item.Item @@ -11,7 +11,7 @@ import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.ForgeRegistries import net.minecraftforge.registries.RegistryObject import org.valkyrienskies.mod.api.vsApi -import org.valkyrienskies.vs_template.forge.client.VSTemplateModForgeClient +import org.valkyrienskies.vs_template.client.VSTemplateModForgeClient @Mod("vs_template") class VSTemplateModForge { diff --git a/src/main/kotlin/org/valkyrienskies/vs_template/forge/client/VSTemplateModForgeClient.kt b/src/main/kotlin/org/valkyrienskies/vs_template/client/VSTemplateModForgeClient.kt similarity index 84% rename from src/main/kotlin/org/valkyrienskies/vs_template/forge/client/VSTemplateModForgeClient.kt rename to src/main/kotlin/org/valkyrienskies/vs_template/client/VSTemplateModForgeClient.kt index 95308f2..77602ce 100644 --- a/src/main/kotlin/org/valkyrienskies/vs_template/forge/client/VSTemplateModForgeClient.kt +++ b/src/main/kotlin/org/valkyrienskies/vs_template/client/VSTemplateModForgeClient.kt @@ -1,4 +1,4 @@ -package org.valkyrienskies.vs_template.forge.client +package org.valkyrienskies.vs_template.client import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index c2eb2f9..7949d5a 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,40 +1,33 @@ modLoader = "javafml" loaderVersion = "[40,)" #issueTrackerURL = "" -license = "Insert License Here" +license = "${mod_license}" [[mods]] -modId = "vs_template" -version = "${version}" -displayName = "Valkyrien Skies Addon Template" -authors = "Me!" +modId = "${mod_id}" +version = "${mod_version}" +displayName = "${mod_name}" +authors = "${mod_authors}" description = ''' -This is an example description! Tell everyone what your mod is about! +${mod_description} ''' logoFile = "icon.png" -[[dependencies.vs_template]] +[[dependencies.${mod_id}]] modId = "forge" mandatory = true versionRange = "[47,)" ordering = "NONE" side = "BOTH" -[[dependencies.vs_template]] +[[dependencies.${mod_id}]] modId = "minecraft" mandatory = true versionRange = "[1.20.1,)" ordering = "NONE" side = "BOTH" -[[dependencies.vs_template]] -modId = "architectury" -mandatory = true -versionRange = "[9.1.12,)" -ordering = "AFTER" -side = "BOTH" - -[[dependencies.vs_template]] +[[dependencies.${mod_id}]] modId = "valkyrienskies" mandatory = true versionRange = "[2.4.0,)" diff --git a/src/main/resources/vs_template.mixins.json b/src/main/resources/vstemplate.mixins.json similarity index 62% rename from src/main/resources/vs_template.mixins.json rename to src/main/resources/vstemplate.mixins.json index a19867a..10cc428 100644 --- a/src/main/resources/vs_template.mixins.json +++ b/src/main/resources/vstemplate.mixins.json @@ -1,6 +1,7 @@ { "required": true, - "package": "org.valkyrienskies.vs_template.forge.mixin", + "package": "org.valkyrienskies.vs_template.mixin", + "refmap": "mixins.vstemplate.refmap.json", "compatibilityLevel": "JAVA_17", "mixins": [ ],