Skip to content
Open
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
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,53 @@ The official VS Addon template, for VS <b>2.4.0</b> 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 <b>first 10 characters</b> 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.
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 `<root>/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!
Expand Down
243 changes: 120 additions & 123 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,179 +13,176 @@ 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'
id "com.modrinth.minotaur" version "2.4.5"
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
}
Loading