Skip to content

Commit

Permalink
Add most of the build config stuff from HexDebug
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed May 28, 2024
1 parent 0916b63 commit 567bde1
Show file tree
Hide file tree
Showing 29 changed files with 1,074 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
"*.css.jinja": "jinja-css",
"*.gradle.jinja": "jinja-groovy",
"*.java.jinja": "jinja-java",
"*.kt.jinja": "jinja-groovy",
"*.kt.jinja": "kotlin",
"*.gradle.kts.jinja": "gradle-kotlin-dsl",
"*.mcmeta.jinja": "jinja-json",
"*.properties.jinja": "jinja-properties",
"*_copier_conf.answers_file*.jinja": "jinja-yaml",
},
"git.ignoredRepositories": [
".ctt/*",
],
"kotlin.languageServer.enabled": false,
}
23 changes: 18 additions & 5 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copier settings

_subdirectory: template
_answers_file: .copier-answers.hexdummy.yml

_exclude:
Expand Down Expand Up @@ -98,6 +97,11 @@ capitalize_platforms:
help: Capitalize platform directory names? (eg. Common vs common)
default: false

kotlin:
type: bool
help: Use Kotlin?
default: true

mappings_name:
type: str
help: "Mappings (note: Hex Casting uses Mojmap)"
Expand All @@ -106,13 +110,22 @@ mappings_name:
- Yarn
default: Mojmap

minecraft_version:
type: str
help: "Minecraft version"
choices:
- "1.19.2"
- "1.20.1"

---
!include "prompts/{{ minecraft_version }}.yml"
---

# static/computed values

mappings_values:
kotlin_plugin:
when: false
default:
Mojmap: 'loom.officialMojangMappings()'
Yarn: '"net.fabricmc:yarn:1.19.2+build.28:v2"'
default: "{{ 'kotlin' if kotlin else 'java' }}"

common_path:
when: false
Expand Down
3 changes: 2 additions & 1 deletion ctt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

[defaults]
modid = "hexdummy"
author = "artynova"
github_user = "artynova"
classname = "HexDummy"
display_name = "Hex Dummy"
minecraft_version = "1.20.1"

[output.".ctt/mojmap"]
mappings_name = "Mojmap"
Expand Down
1 change: 1 addition & 0 deletions prompts/1.19.2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_subdirectory: templates/1.19.2
1 change: 1 addition & 0 deletions prompts/1.20.1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_subdirectory: templates/1.20.1
Empty file added templates/1.19.2/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions templates/1.20.1/.hexdoc-template-inputs.yml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
author: {{ github_user }}
book_id: "{{ modid }}:{{ book_id_path }}"
default_branch: {{ default_branch }}
github_repo: {{ github_repo }}
gradle_mod_version_key: modVersion
hexdoc_mod_plugin_classname: {{ base_classname }}ModPlugin
hexdoc_plugin_classname: {{ base_classname }}Plugin
java_lang:
ext: java
src: java
java_package: {{ package_path }}
mod_display_name: {{ display_name }}
modid: {{ modid }}
multiloader: true
pages_url: {{ homepage_url }}
pattern_regex:
regex: '(?P<is_per_world>register|registerPerWorld)\(HexPattern\.fromAngles\("(?P<signature>[qweasd]+)",\s*HexDir\.(?P<startdir>\w+)\),\s*"(?P<name>[^"]+)"?'
per_world_value: registerPerWorld
pattern_registry: registry/{{ base_classname }}Patterns.java
11 changes: 11 additions & 0 deletions templates/1.20.1/CHANGELOG.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## {{ initial_version }}

### Added

- Initial version.
21 changes: 21 additions & 0 deletions templates/1.20.1/LICENSE.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 {{ github_user }}

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions templates/1.20.1/README.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# {{ display_name }}

[![powered by hexdoc](https://img.shields.io/endpoint?url=https://hexxy.media/api/v0/badge/hexdoc?label=1)](https://github.com/hexdoc-dev/hexdoc)

{{ description }}
14 changes: 14 additions & 0 deletions templates/1.20.1/build.gradle.kts.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id("{{ modid }}.{{ kotlin_plugin }}")
}

architectury {
// this looks up the value from gradle/libs.versions.toml
minecraft = libs.versions.minecraft.get()
}

tasks {
register("runAllDatagen") {
dependsOn(":Forge:runCommonDatagen")
}
}
44 changes: 44 additions & 0 deletions templates/1.20.1/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import org.gradle.api.internal.artifacts.DefaultModuleIdentifier
import org.gradle.api.internal.artifacts.dependencies.DefaultMinimalDependency
import org.gradle.api.internal.artifacts.dependencies.DefaultMutableVersionConstraint

plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
maven { url = uri("https://maven.architectury.dev/") }
maven { url = uri("https://maven.fabricmc.net/") }
maven { url = uri("https://maven.minecraftforge.net/") }
maven { url = uri("https://maven.blamejared.com/") }
}

dependencies {
// plugins
// https://github.com/gradle/gradle/issues/15383#issuecomment-1855984127
implementation(libs.plugins.kotlin.jvm.toLibrary())
implementation(libs.plugins.architectury.toLibrary())
implementation(libs.plugins.architectury.loom.toLibrary())
implementation(libs.plugins.shadow.toLibrary())
implementation(libs.plugins.modPublish.toLibrary())

// libraries used by script plugins
implementation(libs.pkpcpbp)

// https://stackoverflow.com/a/70878181
// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}

// support declaring dependencies on libs.plugins.*

fun ProviderConvertible<PluginDependency>.toLibrary() = asProvider().toLibrary()

fun Provider<PluginDependency>.toLibrary() = get().toLibrary()

fun PluginDependency.toLibrary() = DefaultMinimalDependency(
DefaultModuleIdentifier.newId(pluginId, "$pluginId.gradle.plugin"),
DefaultMutableVersionConstraint(version),
)
8 changes: 8 additions & 0 deletions templates/1.20.1/buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencyResolutionManagement {
versionCatalogs {
// allow referencing the version catalog from the main project
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package {{ modid }}

// this is in a separate file so it can be referenced both by minecraft.gradle.kts and platform.gradle.kts
interface I{{ base_classname }}MinecraftExtension {
fun platform(platform: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package {{ modid }}

import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.kotlin.dsl.the

val Project.libs get() = the<LibrariesForLibs>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// alternative title: OTJFPOPKPCPBP (Only The JSON5 Flattening Part Of PKPCPBP)

package {{ modid }}

import at.petrak.pkpcpbp.filters.FlatteningJson5Transmogrifier
import at.petrak.pkpcpbp.filters.Json5Transmogrifier

// https://github.com/gamma-delta/PKPCPBP/blob/786194a590/src/main/java/at/petrak/pkpcpbp/PKSubprojPlugin.java#L84
tasks.withType<ProcessResources>().configureEach {
outputs.upToDateWhen { false }

filesMatching(listOf("assets/**/*.flatten.json5", "data/**/*.flatten.json5")) {
path = path.replace(".flatten.json5", ".json")
filter<FlatteningJson5Transmogrifier>()
}

filesMatching(listOf("assets/**/*.json5", "data/**/*.json5")) {
path = path.replace(".json5", ".json")
filter<Json5Transmogrifier>()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% from "macros/mappings.jinja" import is_yarn, is_mojmap with context -%}

// A convention plugin that should be applied to all Minecraft-related subprojects, including {{ common_path }}.

package {{ modid }}

plugins {
id("{{ modid }}.kotlin")
id("{{ modid }}.json5")

`maven-publish`
id("dev.architectury.loom")
}

// plugin config

abstract class {{ base_classname }}MinecraftExtension(private val project: Project) : I{{ base_classname }}MinecraftExtension {
override fun platform(platform: String) = project.run {
val modId: String by project

base.archivesName = "$modId-$platform"
}
}

val extension = extensions.create<{{ base_classname }}MinecraftExtension>("{{ base_classname|lower }}Minecraft")

// build logic

loom {
silentMojangMappingsLicense()
accessWidenerPath = project(":{{ common_path }}").file("src/main/resources/{{ modid }}.accesswidener")
}

dependencies {
minecraft(libs.minecraft)

{{ mappings(
mojmap=
"mappings(loom.layered {
officialMojangMappings()
parchment(libs.parchment)
})",
yarn="mappings(libs.yarn)",
) }}

annotationProcessor(libs.bundles.asm)
}

sourceSets {
main {
kotlin {
srcDir(file("src/main/java"))
}
resources {
srcDir(file("src/generated/resources"))
}
}
}

tasks {
val artifactsTask = register<Copy>("githubArtifacts") {
from(remapJar, remapSourcesJar, get("javadocJar"))
into(rootDir.toPath() / "build" / "githubArtifacts")
}

build {
dependsOn(artifactsTask)
}
}
Loading

0 comments on commit 567bde1

Please sign in to comment.