Skip to content

Commit

Permalink
Add all subprojects and most of the platform code (not yet mapping-ed)
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed May 28, 2024
1 parent da68bef commit b71369c
Show file tree
Hide file tree
Showing 21 changed files with 548 additions and 0 deletions.
22 changes: 22 additions & 0 deletions templates/1.20.1/{{ common_path }}/build.gradle.kts.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("{{ modid }}.minecraft")
}

architectury {
common("fabric", "forge")
}

dependencies {
implementation(libs.kotlin.stdlib)

// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation(libs.fabric.loader)
modApi(libs.architectury)

modApi(libs.hexcasting.common)

modApi(libs.clothConfig.common)

implementation(libs.mixinExtras)
}
1 change: 1 addition & 0 deletions templates/1.20.1/{{ common_path }}/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
platform=common
90 changes: 90 additions & 0 deletions templates/1.20.1/{{ fabric_path }}/build.gradle.kts.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
plugins {
id("{{ modid }}.platform")
}

architectury {
fabric()
}

{{ modid }}ModDependencies {
filesMatching.add("fabric.mod.json")

anyVersion = "*"
mapVersions {
replace(",", " ")
replace(Regex("""\s+"""), " ")
replace(Regex("""\[(\S+)"""), ">=$1")
replace(Regex("""(\S+)\]"""), "<=$1")
replace(Regex("""\](\S+)"""), ">$1")
replace(Regex("""(\S+)\["""), "<$1")
}

requires("architectury-api")
requires("cloth-config")
requires(curseforge = "hexcasting", modrinth = "hex-casting")

requires("fabric-api")
requires("fabric-language-kotlin")

optional("modmenu")
}

dependencies {
modApi(libs.fabric.api)
modImplementation(libs.fabric.loader)

modImplementation(libs.kotlin.fabric)

modApi(libs.architectury.fabric) {
// Fix for the "two fabric loaders" loading crash
exclude(group = "net.fabricmc", module = "fabric-loader")
}

modApi(libs.hexcasting.fabric) {
// If not excluded here, calls a nonexistent method and crashes the dev client
exclude(module = "phosphor")
}
modLocalRuntime(libs.paucal.fabric)
modLocalRuntime(libs.patchouli.fabric)
modLocalRuntime(libs.cardinalComponents)
modLocalRuntime(libs.serializationHooks)
modLocalRuntime(libs.trinkets)

libs.mixinExtras.also {
localRuntime(it)
include(it)
}

modApi(libs.clothConfig.fabric) {
exclude(group = "net.fabricmc.fabric-api")
}
modImplementation(libs.modMenu)
}

publishMods {
modLoaders.add("quilt")

// this fails if we do it for all projects, since the tag already exists :/
// see https://github.com/modmuss50/mod-publish-plugin/issues/3
github {
accessToken = System.getenv("GITHUB_TOKEN") ?: ""
repository = System.getenv("GITHUB_REPOSITORY") ?: ""
commitish = System.getenv("GITHUB_SHA") ?: ""

type = STABLE
displayName = "v${project.version}"
tagName = "v${project.version}"

additionalFiles.from(project(":Common").tasks.remapJar.get().archiveFile)
project(":Forge").afterEvaluate {
additionalFiles.from(tasks.remapJar.get().archiveFile)
}
}
}

tasks {
named("publishGithub") {
dependsOn(project(":Common").tasks.remapJar)
dependsOn(project(":Forge").tasks.remapJar)
}
}
1 change: 1 addition & 0 deletions templates/1.20.1/{{ fabric_path }}/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
platform=fabric
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package {{ package }}.fabric

import {{ package }}.{{ base_classname }}
import net.fabricmc.api.ModInitializer

object Fabric{{ base_classname }} : ModInitializer {
override fun onInitialize() {
{{ base_classname }}.init()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package {{ package }}.fabric

import {{ package }}.{{ base_classname }}Client
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.api.EnvType.CLIENT
import net.fabricmc.api.Environment

@Environment(CLIENT)
object Fabric{{ base_classname }}Client : ClientModInitializer {
override fun onInitializeClient() {
{{ base_classname }}Client.init()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package {{ package }}.fabric

import com.terraformersmc.modmenu.api.ConfigScreenFactory
import com.terraformersmc.modmenu.api.ModMenuApi
import {{ package }}.config.{{ base_classname }}Config
import net.fabricmc.api.EnvType.CLIENT
import net.fabricmc.api.Environment

@Environment(CLIENT)
object Fabric{{ base_classname }}ModMenu : ModMenuApi {
override fun getModConfigScreenFactory() = ConfigScreenFactory({{ base_classname }}Config::getConfigScreen)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@file:JvmName("{{ base_classname }}AbstractionsImpl")

package {{ package }}.fabric

import {{ package }}.registry.HexDebugRegistrar
import net.minecraft.core.Registry

fun <T : Any> initRegistry(registrar: HexDebugRegistrar<T>) {
val registry = registrar.registry
registrar.init { id, value -> Registry.register(registry, id, value) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"schemaVersion": 1,
"id": "{{ modid }}",
"version": "${modVersion}",
"name": "{{ display_name }}",
"description": "{{ description }}",
"authors": [
"{{ github_user }}"
],
"contact": {
"homepage": "{{ homepage_url }}",
"sources": "{{ sources_url }}"
},
"license": "MIT",
"icon": "icon.png",
"environment": "*",
"entrypoints": {
"main": [{
"adapter": "kotlin",
"value": "{{ package }}.fabric.Fabric{{ base_classname }}"
}],
"client": [{
"adapter": "kotlin",
"value": "{{ package }}.fabric.Fabric{{ base_classname }}Client"
}],
"modmenu": [{
"adapter": "kotlin",
"value": "{{ package }}.fabric.Fabric{{ base_classname }}ModMenu"
}]
},
"mixins": [
"{{ modid }}-common.mixins.json"
],
"depends": {
"minecraft": "${versions.minecraft}",
"fabricloader": ">=${versions.fabric_loader}",
"fabric-api": ">=${versions.fabric_api}",
"fabric-language-kotlin": ">=${versions.kotlin_fabric}",
"architectury": ">=${versions.architectury}",
"hexcasting": ">=${versions.hexcasting}",
"cloth-config": ">=${versions.clothConfig}"
},
"suggests": {
"modmenu": ">=${versions.modMenu}"
}
}
81 changes: 81 additions & 0 deletions templates/1.20.1/{{ forge_path }}/build.gradle.kts.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
plugins {
id("{{ modid }}.platform")
}

val modId: String by project

architectury {
forge()
}

loom {
forge {
convertAccessWideners = true
extraAccessWideners.add(loom.accessWidenerPath.get().asFile.name)

mixinConfig("{{ modid }}-common.mixins.json", "{{ modid }}.mixins.json")
}

runs {
register("commonDatagen") {
data()
programArgs(
"--mod", modId,
"--all",
// we use forge to do the common datagen because fabric's datagen kind of sucks
"--output", project(":Common").file("src/generated/resources").absolutePath,
"--existing", file("src/main/resources").absolutePath,
"--existing", project(":Common").file("src/main/resources").absolutePath,
)
property("{{ modid }}.apply-datagen-mixin", "true")
}
}
}

{{ modid }}ModDependencies {
filesMatching.add("META-INF/mods.toml")

anyVersion = ""
mapVersions {
replace(Regex("""\](\S+)"""), "($1")
replace(Regex("""(\S+)\["""), "$1)")
}

requires("architectury-api")
requires("cloth-config")
requires(curseforge = "hexcasting", modrinth = "hex-casting")

requires("kotlin-for-forge")
}

dependencies {
forge(libs.forge)
modApi(libs.architectury.forge)

implementation(libs.kotlin.forge)

modApi(libs.hexcasting.forge) { isTransitive = false }
modImplementation(libs.paucal.forge)
modLocalRuntime(libs.patchouli.forge)
modLocalRuntime(libs.caelus)

modApi(libs.clothConfig.forge)

libs.mixinExtras.also {
localRuntime(it)
include(it)
}
}

tasks {
shadowJar {
exclude("fabric.mod.json")
}

named("runCommonDatagen") {
doFirst {
// avoid keeping stale generated resources
project(":{{ common_path }}").delete("src/generated/resources")
}
}
}
2 changes: 2 additions & 0 deletions templates/1.20.1/{{ forge_path }}/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
platform=forge
loom.platform=forge
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package {{ package }}.forge.mixin;

import {{ package }}.{{ base_classname }};
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

// disable MixinDatagenMain if we're not running the datagen task, since it's not necessary at any other time
public class ForgeMixinConfigPlugin implements IMixinConfigPlugin {
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (mixinClassName.equals("{{ package }}.forge.mixin.MixinDatagenMain")) {
var shouldApply = System.getProperty("{{ modid }}.apply-datagen-mixin", "false").equals("true");
if (shouldApply) {
{{ base_classname }}.LOGGER.error("Applying scuffed datagen mixin. This should not happen if not running datagen!");
}
return shouldApply;
}
return true;
}

@Override
public void onLoad(String mixinPackage) {}

@Override
public String getRefMapperConfig() { return null; }

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> getMixins() { return null; }

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package {{ package }}.forge.mixin;

import {{ package }}.{{ base_classname }};
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;

// scuffed workaround for https://github.com/architectury/architectury-loom/issues/189
@Mixin(net.minecraft.data.Main.class)
public class MixinDatagenMain {
@Inject(method = "main", at = @At("TAIL"), remap = false)
private static void {{ modid }}$systemExitAfterDatagenFinishes(String[] strings, CallbackInfo ci) {
{{ base_classname }}.LOGGER.info("Terminating datagen.");
System.exit(0);
}
}
Loading

0 comments on commit b71369c

Please sign in to comment.