Skip to content

Commit

Permalink
Merge branch 'kotlin-quilt-rewrite'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	gradle.properties
#	gradle/wrapper/gradle-wrapper.properties
#	src/main/java/io/github/silverandro/rpgstats/mixin/BowAccuracyMixin.java
#	src/main/java/io/github/silverandro/rpgstats/mixin/BowArrowMixin.java
#	src/main/java/io/github/silverandro/rpgstats/mixin/StatusEffectsImmuneMixin.java
#	src/main/java/mc/rpgstats/main/Events.java
#	src/main/resources/fabric.mod.json
  • Loading branch information
SilverAndro committed Jan 1, 2023
2 parents 538662d + 9237dbc commit 060b822
Show file tree
Hide file tree
Showing 101 changed files with 3,263 additions and 2,681 deletions.
17 changes: 17 additions & 0 deletions Hooky/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
java
kotlin("jvm")
}

java {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}

repositories {
mavenCentral()
}

dependencies {
implementation("com.google.devtools.ksp:symbol-processing-api:1.7.22-1.0.8")
}
131 changes: 131 additions & 0 deletions Hooky/src/main/kotlin/mc/rpgstats/hooky_gen/HookyProcessor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package mc.rpgstats.hooky_gen

import com.google.devtools.ksp.getDeclaredProperties
import com.google.devtools.ksp.processing.*
import com.google.devtools.ksp.symbol.*

class HookyProcessor(val environment: SymbolProcessorEnvironment, val codeGenerator: CodeGenerator, val logger: KSPLogger) : SymbolProcessor {
var invoked = false

override fun process(resolver: Resolver): List<KSAnnotated> {
if (invoked) return emptyList() else invoked = true

@Suppress("UNCHECKED_CAST")
val commands = resolver.getSymbolsWithAnnotation("mc.rpgstats.hooky_gen.api.Command").toList() as List<KSClassDeclaration>
@Suppress("UNCHECKED_CAST")
val quickFunctions = resolver.getSymbolsWithAnnotation("mc.rpgstats.hooky_gen.api.RegisterOn").toList() as List<KSFunctionDeclaration>

commands.forEach {
logger.info(it.qualifiedName?.asString().toString() )
}
logger.info("---")
quickFunctions.forEach {
logger.info(it.qualifiedName?.asString().toString())
}

val annotatedFunctions = mutableMapOf<String, Pair<KSAnnotation, MutableList<KSFunctionDeclaration>>>()
quickFunctions.forEach { func ->
func.annotations.forEach {
annotatedFunctions.getOrPut(it.arguments[0].value.toString()) { it to mutableListOf() }.second.add(func)
}
}

logger.info("Generating file")
val commandsFile = codeGenerator.createNewFile(
Dependencies.ALL_FILES,
"io.github.silverandro.rpgstats.hooky",
"Hooky",
"kt"
)

val file = buildString {
appendLine("// Autogenerated by Hooky subproject, DO NOT EDIT")
appendLine("package io.github.silverandro.rpgstats.hooky")
appendLine()
appendLine("object Hooky {")
appendLine(" fun registerAll() {")

if (commands.isNotEmpty()) {
appendLine(" org.quiltmc.qsl.command.api.CommandRegistrationCallback.EVENT.register { dispatcher, _, _ ->")
commands.forEach {
appendLine(" ${it.qualifiedName!!.asString()}.register(dispatcher)")
}
appendLine(" }")
}

annotatedFunctions.forEach { (_, pair) ->
append(constructEventAttach(pair.first, pair.second, resolver))
}

appendLine(" }")
appendLine("}")
}
commandsFile.write(file.toByteArray())

return emptyList()
}

private fun constructEventAttach(annotation: KSAnnotation, functions: List<KSFunctionDeclaration>, resolver: Resolver): String {
val fullID = annotation.arguments[0].value.toString()
val split = fullID.lastIndexOf('.')
val eventClassName = fullID.substring(0, split)
val eventName = fullID.substring(split+1)

val eventClass = resolver.getClassDeclarationByName(resolver.getKSNameFromString(eventClassName))!!
val eventParam = eventClass.getDeclaredProperties().find { it.simpleName.asString() == eventName }!!
val specialMethod = (eventParam.type.resolve().arguments[0].type!!.resolve().declaration as KSClassDeclaration)
.getAllFunctions().find {
val asString = it.simpleName.asString()
!(asString == "equals" || asString == "hashCode" || asString == "toString")
}!!

logger.info("Managed to resolve `${fullID}` to ${specialMethod.simpleName.asString()} with params ${specialMethod.parameters.map { it.type }}")
val params = specialMethod.parameters
functions.forEach {
verifyParams(params, it.parameters)
}

var currentParam = 'a'.dec()
fun next(): Char { currentParam = currentParam.inc(); return currentParam }

return buildString {
if (params.isNotEmpty()) {
if (fullID == "net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents.AFTER") {
appendLine(" $fullID.register { ${params.joinToString { "${next()}: ${it.type.resolve().declaration.qualifiedName!!.asString()}" }}? ->")
} else {
appendLine(" $fullID.register { ${params.joinToString { "${next()}: ${it.type.resolve().declaration.qualifiedName!!.asString()}" }} ->")
}
} else {
appendLine(" $fullID.register { ")
}
functions.forEach {
var passParam = 'a'.dec()
fun new(): Char { passParam = passParam.inc(); return passParam }
if (it.parameters.isNotEmpty()) {
appendLine(" ${it.qualifiedName!!.asString()}(${it.parameters.joinToString { new().toString() }})")
} else {
appendLine(" ${it.qualifiedName!!.asString()}()")
}
}
appendLine(" }")
}
}

private fun verifyParams(absoluteSet: List<KSValueParameter>, toCheck: List<KSValueParameter>) {
if (toCheck.size > absoluteSet.size) throw IllegalStateException("Too large parameter list! Was expecting at most ${absoluteSet.size}, but got ${toCheck.size}")

toCheck.forEachIndexed { index, parameter ->
val expected = parameter.type.resolve()
var actual = absoluteSet[index].type.resolve()

if (!actual.isMarkedNullable) {
actual = actual.makeNotNullable()
}

logger.info(actual.isMarkedNullable.toString())
if (expected != actual) {
throw IllegalStateException("Parameter mismatch! Expected $expected but got $actual at index $index")
}
}
}
}
11 changes: 11 additions & 0 deletions Hooky/src/main/kotlin/mc/rpgstats/hooky_gen/HookyProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mc.rpgstats.hooky_gen

import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.processing.SymbolProcessorProvider

class HookyProvider : SymbolProcessorProvider {
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
return HookyProcessor(environment, environment.codeGenerator, environment.logger)
}
}
5 changes: 5 additions & 0 deletions Hooky/src/main/kotlin/mc/rpgstats/hooky_gen/api/Command.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mc.rpgstats.hooky_gen.api

@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
annotation class Command
5 changes: 5 additions & 0 deletions Hooky/src/main/kotlin/mc/rpgstats/hooky_gen/api/RegisterOn.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mc.rpgstats.hooky_gen.api

@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.FUNCTION)
annotation class RegisterOn(val event: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mc.rpgstats.hooky_gen.HookyProvider
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# RPGStats

RPGStats adds simple, easy to understand stats to your minecraft game
RPGStats adds simple, easy to understand stats to your minecraft game.
The majority of content is data-drivable or controlable through datapacks/functions.

Open an issue or join the discord for support: https://discord.gg/PZAunp345q
120 changes: 58 additions & 62 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'io.github.p03w.machete' version '1.+'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.7.1'
id 'maven-publish'
id 'io.github.p03w.machete' version '2.+'
id 'org.quiltmc.loom' version '+'
id 'org.jetbrains.kotlin.jvm' version '1.7.22'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.22'
id("com.google.devtools.ksp") version "1.7.22-1.0.8"
}

sourceCompatibility = JavaVersion.VERSION_16
Expand All @@ -17,10 +20,6 @@ repositories {
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
}
maven {
name = "CottonMC"
url = "https://server.bbkr.space/artifactory/libs-release"
}
maven {
name = "Curseforge"
url "https://www.cursemaven.com"
Expand All @@ -29,8 +28,11 @@ repositories {
}
}
maven {
name = "Jitpack"
url = "https://jitpack.io"
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup 'maven.modrinth'
}
}
maven {
name = "Nucleoid"
Expand All @@ -40,19 +42,39 @@ repositories {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/"
}
maven {
name = "Sleeping Town"
url 'https://repo.sleeping.town'
content {
includeGroup 'com.unascribed'
}
}
maven {
name = "JitPack"
url = "https://jitpack.io"
}
mavenLocal()
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${quilt_mappings}:intermediary-v2"
modImplementation "org.quiltmc:quilt-loader:${project.loader_version}"

// QSL
modImplementation "org.quiltmc:qsl:${qsl_version}+${minecraft_version}"
modImplementation("org.quiltmc.quilted-fabric-api:quilted-fabric-api:${qfapi_version}") {
exclude(group: "org.quiltmc.qsl")
}

// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// QKL
modImplementation("org.quiltmc.quilt-kotlin-libraries:quilt-kotlin-libraries:1.0.1+kt.1.7.22+flk.1.8.6") {
exclude(group: "org.quiltmc.qsl")
}

// LibGui
modImplementation "io.github.cottonmc:LibGui:${project.libgui_version}"
include "io.github.cottonmc:LibGui:${project.libgui_version}"
// Hooky
implementation(project("Hooky"))
ksp(project("Hooky"))

// Cardinal components base
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}"
Expand All @@ -62,33 +84,15 @@ dependencies {
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca_version}"

// Auto config
modImplementation "com.github.p03w-rehost:AutoConfig:1.18-SNAPSHOT"
include "com.github.p03w-rehost:AutoConfig:1.18-SNAPSHOT"

// Translations
modImplementation "fr.catcore:server-translations-api:1.4.14+1.19-rc2"
include "fr.catcore:server-translations-api:1.4.14+1.19-rc2"

// Harvest scythes
modImplementation "curse.maven:harvestscythes-412225:3823173"
// Dependency for Harvest Scythes
modImplementation("com.github.Chocohead:Fabric-ASM:v2.3") {
exclude (group: "net.fabricmc.fabric-api")
}

// Harvest
modImplementation 'curse.maven:simplerharvest-481720:3307870'

/*
// Artifality
modImplementation 'curse.maven:artifality-490812:3650925'
// Dependency for Artifality (Trinkets)
modImplementation ("dev.emi:trinkets:3.3.0") {
exclude (group: "net.fabricmc.fabric-api")
exclude (group: "dev.onyxstudios.cardinal-components-api")
}
*/
modImplementation "fr.catcore:server-translations-api:1.4.18+1.19.2"
include "fr.catcore:server-translations-api:1.4.18+1.19.2"

// Switchy
modImplementation "maven.modrinth:switchy:1.7.3+1.19"
// Dependency for Switchy
modImplementation "com.unascribed:lib39-core:1.4.0"
modImplementation "com.unascribed:lib39-dessicant:1.4.0"
}

processResources {
Expand All @@ -102,10 +106,10 @@ processResources {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"

it.options.release = 16
it.options.release = 17
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
Expand All @@ -120,23 +124,15 @@ jar {
from "LICENSE"
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
tasks.withType(KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = '17'
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
mavenLocal()
kotlin {
sourceSets {
main.kotlin.srcDirs += 'build/generated/ksp/main/kotlin'
test.kotlin.srcDirs += 'build/generated/ksp/test/kotlin'
}
}
}
14 changes: 6 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx3G
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.9
loader_version=0.14.9

#Fabric api
fabric_version=0.60.0+1.19.2
quilt_mappings=21
loader_version=0.18.1-beta.25

# Mod Properties
mod_version = 4.4.2
mod_version = 5.0.0
maven_group = mc.rpgstats
archives_base_name = rpgstats

# Dependencies
cca_version = 4.1.4
libgui_version = 6.0.0+1.19
cca_version = 5.1.0
qsl_version = 3.0.0-beta.24
qfapi_version = 4.0.0-beta.24+0.68.0-1.19.2
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 060b822

Please sign in to comment.