BreakMe/build.gradle.kts

109 lines
3.3 KiB
Plaintext
Raw Normal View History

2022-12-02 18:59:18 +01:00
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeSpec
2022-12-02 18:59:18 +01:00
import io.gitlab.jfronny.scripts.*
import java.nio.file.Files
import java.util.*
import java.util.function.Supplier
2022-12-02 18:59:18 +01:00
import javax.lang.model.element.Modifier.*
plugins {
2024-04-25 21:51:15 +02:00
id("jfmod") version "1.6-SNAPSHOT"
}
allprojects { group = "io.gitlab.jfronny" }
base.archivesName = "breakme"
// https://fabricmc.net/develop/
jfMod {
2024-10-23 21:37:19 +02:00
minecraftVersion = "1.21.3"
yarn("build.2")
loaderVersion = "0.16.7"
libJfVersion = "3.18.0"
fabricApiVersion = "0.106.1+1.21.3"
modrinth {
projectId = "breakme"
requiredDependencies.add("libjf")
optionalDependencies.add("modmenu")
}
curseforge {
projectId = "400842"
requiredDependencies.add("libjf")
optionalDependencies.add("modmenu")
}
2022-12-02 18:59:18 +01:00
}
2022-12-03 16:19:36 +01:00
if (flavour == "") flavour = "modrinth"
2022-12-02 18:59:18 +01:00
dependencies {
2024-04-25 21:51:15 +02:00
modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v2")
2022-12-02 18:59:18 +01:00
// Dev env
2024-04-25 21:51:15 +02:00
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil")
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-ui-tiny")
modLocalRuntime("net.fabricmc.fabric-api:fabric-api")
2024-10-23 21:37:19 +02:00
modLocalRuntime("com.terraformersmc:modmenu:12.0.0-beta.1")
2022-12-02 18:59:18 +01:00
}
loom {
runs {
this.named("client").get().vmArg("-Xmx2G")
}
}
2024-06-14 14:21:37 +02:00
fun list(`package`: String): List<ClassName> = Files.list(projectDir.resolve("src/main/java").resolve(`package`.replace('.', '/')).toPath()).use { stream ->
2022-12-02 18:59:18 +01:00
stream
.map { it.fileName.toString() }
.map { it.substring(0, it.lastIndexOf('.')) }
.filter { it.endsWith("Provider") }
.map { ClassName.get(`package`, it) }
.toList()
}
val classes = LinkedList(list("io.gitlab.jfronny.breakme.crash.safe"))
2022-12-03 16:19:36 +01:00
if (flavour == "curseforge") {
2022-12-02 18:59:18 +01:00
sourceSets.main.get().java.filter.exclude("**/unsafe/*")
} else {
classes.addAll(list("io.gitlab.jfronny.breakme.crash.unsafe"))
}
sourceSets {
main {
generate(project) {
val providerType = ClassName.get("io.gitlab.jfronny.breakme.crash", "CrashProvider")
val supplierType = ParameterizedTypeName.get(ClassName.get(Supplier::class.java), providerType)
`enum`("io.gitlab.jfronny.breakme.crash", "Method") {
2022-12-02 18:59:18 +01:00
modifiers(PUBLIC)
superInterface(providerType)
for (klazz in classes) {
val name = klazz.simpleName()
enumConstant(name.substring(0, name.length - "Provider".length), TypeSpec.anonymousClassBuilder("\$T::new", klazz).build())
}
field(supplierType, "provider", PRIVATE, FINAL)
constructor {
parameter(supplierType, "provider")
code {
addStatement("this.provider = new \$T<>(provider)", ClassName.get("io.gitlab.jfronny.commons", "LazySupplier"))
}
}
method("crash") {
modifiers(PUBLIC)
exception(Exception::class.java)
annotation(Override::class.java)
code {
addStatement("provider.get().crash()")
2022-12-02 18:59:18 +01:00
}
}
}
}
}
}