Fixing OptiFine, until something better comes.
1import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel
2import org.jetbrains.gradle.ext.runConfigurations
3import org.jetbrains.gradle.ext.settings
4
5plugins {
6 id("org.jetbrains.gradle.plugin.idea-ext") version "1.3"
7 id("com.gtnewhorizons.retrofuturagradle") version "2.0.2"
8 id("com.github.gmazzo.buildconfig") version "6.0.7"
9 id("io.freefair.lombok") version "9.1.0"
10}
11
12group = "dev.redstudio"
13version = "1.0" // Versioning must follow Ragnarök versioning convention: https://github.com/Red-Studio-Ragnarok/Commons/blob/main/Ragnar%C3%B6k%20Versioning%20Convention.md
14
15val id = project.name.lowercase()
16val plugin = "${project.group}.${id}.asm.${project.name}Plugin"
17
18val jvmCommonArgs = "-Dfile.encoding=UTF-8 -XX:+UseStringDeduplication"
19
20val redCoreVersion = "0.7"
21
22val configAnytimeVersion = "3.0"
23
24minecraft {
25 mcVersion = "1.12.2"
26 username = "Desoroxxx"
27 extraRunJvmArguments = listOf("-Dforge.logging.console.level=debug", "-Dfml.coreMods.load=${plugin}") + jvmCommonArgs.split(" ")
28}
29
30repositories {
31 arrayOf("Release", "Beta", "Dev").forEach { repoType ->
32 maven {
33 name = "Red Studio - $repoType"
34 url = uri("https://repo.redstudio.dev/${repoType.lowercase()}")
35 content {
36 includeGroup("dev.redstudio")
37 }
38 }
39 }
40
41 maven {
42 name = "Cleanroom"
43 url = uri("https://maven.cleanroommc.com")
44 content {
45 includeGroup("com.cleanroommc")
46 }
47 }
48
49 mavenCentral()
50 mavenLocal()
51}
52
53dependencies {
54 implementation("dev.redstudio:Red-Core-MC:1.8-1.12-$redCoreVersion")
55
56 implementation("com.cleanroommc:configanytime:$configAnytimeVersion")
57}
58
59buildConfig {
60 packageName("${project.group}.${id}")
61 className("ProjectConstants")
62 documentation.set("This class defines constants for ${project.name}.\n<p>\nThey are automatically updated by Gradle.")
63 useJavaOutput()
64
65 // Details
66 buildConfigField("ID",id)
67 buildConfigField("NAME", project.name)
68 buildConfigField("VERSION", project.version.toString())
69
70 // Versions
71 buildConfigField("RED_CORE_VERSION", redCoreVersion)
72 buildConfigField("CONFIG_ANYTIME_VERSION", configAnytimeVersion)
73
74 // Loggers
75 buildConfigField("org.apache.logging.log4j.Logger", "LOGGER", "org.apache.logging.log4j.LogManager.getLogger(NAME)")
76 buildConfigField("dev.redstudio.redcore.logging.RedLogger", "RED_LOGGER", """new RedLogger(NAME, "https://tangled.org/desoroxxx.redstudio.dev/${project.name}/issues/new", LOGGER)""")
77}
78
79// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
80java {
81 toolchain {
82 languageVersion.set(JavaLanguageVersion.of(8))
83 vendor.set(JvmVendorSpec.ADOPTIUM)
84 }
85 if (!project.version.toString().contains("Dev"))
86 withSourcesJar() // Generate sources jar, for releases
87}
88
89tasks {
90 processResources {
91 val expandProperties = mapOf(
92 "version" to project.version,
93 "name" to project.name,
94 "id" to id
95 )
96
97 inputs.properties(expandProperties)
98
99 filesMatching("**/*.*") {
100 val exclusions = arrayOf(".png")
101 if (!exclusions.any { path.endsWith(it) })
102 expand(expandProperties)
103 }
104 }
105
106 val processReadme by registering {
107 val input = rootProject.file("README.md")
108 val output = layout.buildDirectory.file("processed-readme/README.md")
109
110 inputs.file(input)
111 outputs.file(output)
112
113 doLast {
114 val content = input.readText()
115 val firstHash = content.indexOf('#')
116 val lastSeparator = content.lastIndexOf("---")
117
118 val trimmed = when {
119 firstHash != -1 && lastSeparator > firstHash -> content.substring(firstHash, lastSeparator)
120 firstHash != -1 -> content.substring(firstHash)
121 else -> content
122 }
123
124 output.get().asFile.parentFile.mkdirs()
125 output.get().asFile.writeText(trimmed.trim())
126 }
127 }
128
129 withType<Jar> {
130 dependsOn(processReadme)
131 from(processReadme.map { it.outputs.files })
132 from(rootProject.file("LICENSE"))
133 from(rootProject.file("CHANGELOG.md"))
134
135 manifest {
136 attributes(
137 "ModSide" to "CLIENT",
138 "FMLCorePlugin" to plugin,
139 "FMLCorePluginContainsFMLMod" to "true",
140 "ForceLoadAsMod" to "true"
141 )
142 }
143 }
144
145 withType<JavaCompile>{
146 options.encoding = "UTF-8"
147
148 options.isFork = true
149 options.forkOptions.jvmArgs = jvmCommonArgs.split(" ")
150 }
151}
152
153idea {
154 module {
155 inheritOutputDirs = true
156 excludeDirs.addAll(setOf(".gradle", ".idea", "build", "gradle", "run", "gradlew", "gradlew.bat", "desktop.ini").map(::file))
157 }
158
159 project {
160 settings {
161 jdkName = "1.8"
162 languageLevel = IdeaLanguageLevel("JDK_1_8")
163
164
165 runConfigurations {
166 listOf("Client", "Server", "Obfuscated Client", "Obfuscated Server", "Vanilla Client", "Vanilla Server").forEach { name ->
167 create(name, org.jetbrains.gradle.ext.Gradle::class.java) {
168 val prefix = name.substringBefore(" ").let { if (it == "Obfuscated") "Obf" else it }
169 val suffix = name.substringAfter(" ").takeIf { it != prefix } ?: ""
170 taskNames = setOf("run$prefix$suffix")
171
172 jvmArgs = jvmCommonArgs
173 }
174 }
175 }
176 }
177 }
178}