-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 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
Showing
101 changed files
with
3,263 additions
and
2,681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
131
Hooky/src/main/kotlin/mc/rpgstats/hooky_gen/HookyProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
Hooky/src/main/kotlin/mc/rpgstats/hooky_gen/HookyProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
5
Hooky/src/main/kotlin/mc/rpgstats/hooky_gen/api/RegisterOn.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mc.rpgstats.hooky_gen.HookyProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.