2022-12-02 18:59:18 +01:00
|
|
|
import com.squareup.javapoet.ClassName
|
2023-07-28 18:54:31 +02:00
|
|
|
import com.squareup.javapoet.ParameterizedTypeName
|
2022-12-29 15:51:08 +01:00
|
|
|
import com.squareup.javapoet.TypeSpec
|
2022-12-02 18:59:18 +01:00
|
|
|
import io.gitlab.jfronny.scripts.*
|
2022-12-29 15:51:08 +01:00
|
|
|
import java.nio.file.Files
|
|
|
|
import java.util.*
|
2023-07-28 18:54:31 +02:00
|
|
|
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"
|
2023-07-28 18:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
2023-07-28 18:54:31 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-03-11 12:13:47 +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) {
|
2022-12-29 15:51:08 +01:00
|
|
|
val providerType = ClassName.get("io.gitlab.jfronny.breakme.crash", "CrashProvider")
|
2023-07-28 18:54:31 +02:00
|
|
|
val supplierType = ParameterizedTypeName.get(ClassName.get(Supplier::class.java), providerType)
|
2022-12-29 15:51:08 +01:00
|
|
|
|
|
|
|
`enum`("io.gitlab.jfronny.breakme.crash", "Method") {
|
2022-12-02 18:59:18 +01:00
|
|
|
modifiers(PUBLIC)
|
2022-12-29 15:51:08 +01:00
|
|
|
|
|
|
|
superInterface(providerType)
|
|
|
|
|
|
|
|
for (klazz in classes) {
|
|
|
|
val name = klazz.simpleName()
|
2023-07-28 18:54:31 +02:00
|
|
|
enumConstant(name.substring(0, name.length - "Provider".length), TypeSpec.anonymousClassBuilder("\$T::new", klazz).build())
|
2022-12-29 15:51:08 +01:00
|
|
|
}
|
|
|
|
|
2023-07-28 18:54:31 +02:00
|
|
|
field(supplierType, "provider", PRIVATE, FINAL)
|
2022-12-29 15:51:08 +01:00
|
|
|
|
|
|
|
constructor {
|
2023-07-28 18:54:31 +02:00
|
|
|
parameter(supplierType, "provider")
|
2022-12-29 15:51:08 +01:00
|
|
|
code {
|
2023-07-28 18:54:31 +02:00
|
|
|
addStatement("this.provider = new \$T<>(provider)", ClassName.get("io.gitlab.jfronny.commons", "LazySupplier"))
|
2022-12-29 15:51:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
method("crash") {
|
|
|
|
modifiers(PUBLIC)
|
|
|
|
exception(Exception::class.java)
|
|
|
|
annotation(Override::class.java)
|
|
|
|
code {
|
2023-07-28 18:54:31 +02:00
|
|
|
addStatement("provider.get().crash()")
|
2022-12-02 18:59:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|