From 9aa248e7f22704e9f1d4b5263be1d40b88fa3d46 Mon Sep 17 00:00:00 2001 From: xtex Date: Tue, 1 Aug 2023 15:45:21 +0800 Subject: [PATCH] build: add fabric support --- .gitignore | 2 +- build.gradle.kts | 4 + common/build.gradle.kts | 2 +- common/src/main/kotlin/quaedam/Quaedam.kt | 6 ++ .../projection/swarm/ProjectedPersonEntity.kt | 2 +- .../swarm/ProjectedPersonRenderer.kt | 8 +- .../main/resources/assets/quaedam}/icon.png | Bin fabric-like/build.gradle.kts | 17 ++++ .../quaedam.fabriclike/QuaedamFabricLike.kt | 12 +++ .../src/main/resources/quaedam.mixins.json | 13 +++ fabric/build.gradle.kts | 88 ++++++++++++++++++ fabric/src/main/resources/fabric.mod.json | 34 +++++++ forge/src/main/resources/META-INF/mods.toml | 2 +- gradle.properties | 8 +- settings.gradle.kts | 1 + 15 files changed, 192 insertions(+), 7 deletions(-) rename {forge/src/main/resources => common/src/main/resources/assets/quaedam}/icon.png (100%) create mode 100644 fabric-like/build.gradle.kts create mode 100644 fabric-like/src/main/kotlin/quaedam.fabriclike/QuaedamFabricLike.kt create mode 100644 fabric-like/src/main/resources/quaedam.mixins.json create mode 100644 fabric/build.gradle.kts create mode 100644 fabric/src/main/resources/fabric.mod.json diff --git a/.gitignore b/.gitignore index 3cb6ab7..5f055bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ build .gradle -forge/run +*/run .idea diff --git a/build.gradle.kts b/build.gradle.kts index 8318f6e..21a4e85 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,6 +45,10 @@ allprojects { name = "ParchmentMC" setUrl("https://maven.parchmentmc.org") } + maven { + name = "QuiltMC" + setUrl("https://maven.quiltmc.org/repository/release/") + } } dependencies { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index c08659a..3354539 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,5 +1,5 @@ architectury { - common("forge") + common("forge", "fabric", "quilt") } loom { diff --git a/common/src/main/kotlin/quaedam/Quaedam.kt b/common/src/main/kotlin/quaedam/Quaedam.kt index 3755efe..9691fde 100644 --- a/common/src/main/kotlin/quaedam/Quaedam.kt +++ b/common/src/main/kotlin/quaedam/Quaedam.kt @@ -20,6 +20,7 @@ import quaedam.projection.misc.NoiseProjection import quaedam.projection.misc.SkylightProjection import quaedam.projection.misc.SoundProjection import quaedam.projection.music.MusicProjection +import quaedam.projection.swarm.ProjectedPersonEntity import quaedam.projection.swarm.SwarmProjection import quaedam.projector.Projector import quaedam.shell.ProjectionShell @@ -48,6 +49,8 @@ object Quaedam { } } + val lateinit = mutableListOf<() -> Unit>() + fun init() { QuaedamConfig Projector @@ -75,6 +78,9 @@ object Quaedam { soundEvents.register() poiTypes.register() projectionEffects.register() + + lateinit.forEach { it() } + lateinit.clear() } fun resource(path: String) = ResourceLocation(ID, path) diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt index 8c0ee8d..f3e22cc 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt @@ -60,7 +60,7 @@ class ProjectedPersonEntity(entityType: EntityType, level: Le }!! init { - EntityAttributeRegistry.register(entity, ::createAttributes) + Quaedam.lateinit += { EntityAttributeRegistry.register(entity, ::createAttributes) } if (Platform.getEnv() == EnvType.CLIENT) ProjectedPersonRenderer ProjectedPersonShape ProjectedPersonAI diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonRenderer.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonRenderer.kt index 383c38d..e4333ed 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonRenderer.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonRenderer.kt @@ -10,6 +10,7 @@ import net.minecraft.client.renderer.entity.EntityRendererProvider import net.minecraft.client.renderer.entity.MobRenderer import net.minecraft.client.renderer.entity.layers.CustomHeadLayer import net.minecraft.client.renderer.entity.layers.ItemInHandLayer +import quaedam.Quaedam @Environment(EnvType.CLIENT) class ProjectedPersonRenderer(context: EntityRendererProvider.Context) : @@ -21,7 +22,12 @@ class ProjectedPersonRenderer(context: EntityRendererProvider.Context) : companion object { init { - EntityRendererRegistry.register(ProjectedPersonEntity.entity, ::ProjectedPersonRenderer) + Quaedam.lateinit += { + EntityRendererRegistry.register( + ProjectedPersonEntity.entity, + ::ProjectedPersonRenderer + ) + } } } diff --git a/forge/src/main/resources/icon.png b/common/src/main/resources/assets/quaedam/icon.png similarity index 100% rename from forge/src/main/resources/icon.png rename to common/src/main/resources/assets/quaedam/icon.png diff --git a/fabric-like/build.gradle.kts b/fabric-like/build.gradle.kts new file mode 100644 index 0000000..4a406fa --- /dev/null +++ b/fabric-like/build.gradle.kts @@ -0,0 +1,17 @@ +architectury { + common("fabric", "quilt") +} + +loom { + accessWidenerPath.set(project(":common").loom.accessWidenerPath) +} + +dependencies { + modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}") + modApi("net.fabricmc.fabric-api:fabric-api:${rootProject.property("fabric_version")}") + modApi("dev.architectury:architectury-fabric:${rootProject.property("architectury_version")}") + + compileOnly(project(":common", "namedElements")) { + isTransitive = false + } +} diff --git a/fabric-like/src/main/kotlin/quaedam.fabriclike/QuaedamFabricLike.kt b/fabric-like/src/main/kotlin/quaedam.fabriclike/QuaedamFabricLike.kt new file mode 100644 index 0000000..98c9bab --- /dev/null +++ b/fabric-like/src/main/kotlin/quaedam.fabriclike/QuaedamFabricLike.kt @@ -0,0 +1,12 @@ +package quaedam.fabriclike + +import net.fabricmc.api.ModInitializer +import quaedam.Quaedam + +object QuaedamFabricLike: ModInitializer { + + override fun onInitialize() { + Quaedam.init() + } + +} \ No newline at end of file diff --git a/fabric-like/src/main/resources/quaedam.mixins.json b/fabric-like/src/main/resources/quaedam.mixins.json new file mode 100644 index 0000000..cf1aeb5 --- /dev/null +++ b/fabric-like/src/main/resources/quaedam.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "quaedam.fabric.mixin", + "compatibilityLevel": "JAVA_17", + "minVersion": "0.8", + "client": [ + ], + "mixins": [ + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts new file mode 100644 index 0000000..e387460 --- /dev/null +++ b/fabric/build.gradle.kts @@ -0,0 +1,88 @@ +plugins { + id("com.github.johnrengelman.shadow") +} + +architectury { + platformSetupLoomIde() + fabric() +} + +loom { + accessWidenerPath.set(project(":common").loom.accessWidenerPath) +} + +val common: Configuration by configurations.creating +val shadowCommon: Configuration by configurations.creating +val developmentFabric: Configuration by configurations.getting + +configurations { + compileOnly.configure { extendsFrom(common) } + runtimeOnly.configure { extendsFrom(common) } + developmentFabric.extendsFrom(common) +} + +dependencies { + modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}") + modApi("net.fabricmc.fabric-api:fabric-api:${rootProject.property("fabric_version")}") + modApi("dev.architectury:architectury-fabric:${rootProject.property("architectury_version")}") + modImplementation("net.fabricmc:fabric-language-kotlin:${rootProject.property("fabric_kotlin_version")}") + + common(project(":common", "namedElements")) { + isTransitive = false + } + shadowCommon(project(":common", "transformProductionFabric")){ + isTransitive = false + } + common(project(":fabric-like", "namedElements")) { + isTransitive = false + } + shadowCommon(project(":fabric-like", "transformProductionFabric")){ + isTransitive = false + } +} + +tasks.processResources { + inputs.property("version", project.version) + + filesMatching("fabric.mod.json") { + expand( + mapOf( + "version" to project.version, + + "minecraft_version" to rootProject.property("minecraft_version"), + "architectury_version" to rootProject.property("architectury_version"), + "fabric_kotlin_version" to rootProject.property("fabric_kotlin_version") + ) + ) + } +} + +tasks.shadowJar { + exclude("architectury.common.json") + configurations = listOf(shadowCommon) + archiveClassifier.set("dev-shadow") +} + +tasks.remapJar { + injectAccessWidener.set(true) + inputFile.set(tasks.shadowJar.get().archiveFile) + dependsOn(tasks.shadowJar) + archiveClassifier.set(null as String?) +} + +tasks.jar { + archiveClassifier.set("dev") +} + +tasks.sourcesJar { + val commonSources = project(":common").tasks.getByName("sourcesJar") + dependsOn(commonSources) + from(commonSources.archiveFile.map { zipTree(it) }) +} + +components.getByName("java") { + this as AdhocComponentWithVariants + this.withVariantsFromConfiguration(project.configurations["shadowRuntimeElements"]) { + skip() + } +} \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..09f8d4e --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,34 @@ +{ + "schemaVersion": 1, + "id": "quaedam", + "version": "${version}", + "name": "Quaedam", + "description": "Hot hot hot!", + "authors": [ + "xtex" + ], + "contact": { + "homepage": "https://codeberg.org/xtex/quaedam", + "sources": "https://codeberg.org/xtex/quaedam" + }, + "license": "Apache-2.0", + "icon": "assets/quaedam/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + { + "adapter": "kotlin", + "value": "quaedam.fabriclike.QuaedamFabricLike" + } + ] + }, + "mixins": [ + "quaedam-common.mixins.json" + ], + "depends": { + "fabric": "*", + "minecraft": ">=${minecraft_version}", + "architectury": ">=${architectury_version}", + "fabric-language-kotlin": ">=${fabric_kotlin_version}" + } +} \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 43aa20e..f8afac7 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -11,7 +11,7 @@ authors = "xtex" description = ''' Hot hot hot! ''' -logoFile = "icon.png" +logoFile = "assets/quaedam/icon.png" [[dependencies.quaedam]] modId = "forge" diff --git a/gradle.properties b/gradle.properties index 4fe6869..2cc34e2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,17 @@ org.gradle.parallel=true org.gradle.caching=true org.gradle.jvmargs=-Xmx2048M + minecraft_version=1.20.1 parchment_version=2023.07.16 -# https://www.curseforge.com/minecraft/mc-mods/architectury-api +# https://modrinth.com/mod/architectury-api architectury_version=9.1.12 # https://files.minecraftforge.net/net/minecraftforge/forge/ forge_version=1.20.1-47.1.43 -# https://www.curseforge.com/minecraft/mc-mods/kotlin-for-forge/files +# https://modrinth.com/mod/kotlin-for-forge kotlin_for_forge_version=4.4.0 # https://fabricmc.net/develop/ fabric_loader_version=0.14.21 +fabric_version=0.86.1+1.20.1 +# https://modrinth.com/mod/fabric-language-kotlin +fabric_kotlin_version=1.10.8+kotlin.1.9.0 diff --git a/settings.gradle.kts b/settings.gradle.kts index c1a4a41..48b5288 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,5 +10,6 @@ pluginManagement { include("common") include("forge") +include("fabric-like", "fabric") rootProject.name = "quaedam"