1
1
plugins {
2
- id ' fabric-loom' version ' 0.8-SNAPSHOT '
2
+ id ' fabric-loom' version ' 0.8.+ '
3
3
id ' java-library'
4
4
id ' maven-publish'
5
5
id ' com.github.johnrengelman.shadow' version ' 7.0.0'
6
- id ' org.cadixdev.licenser' version ' 0.5.0'
6
+ id ' org.cadixdev.licenser' version ' 0.6.0'
7
+ id ' com.modrinth.minotaur' version ' 1.2.+'
7
8
}
8
9
9
10
import net.fabricmc.loom.task.RemapJarTask
11
+ import com.google.gson.GsonBuilder
12
+ import com.google.gson.JsonObject
13
+ import com.modrinth.minotaur.TaskModrinthUpload
14
+ import com.modrinth.minotaur.request.VersionType
15
+ import com.modrinth.minotaur.responses.ResponseError
16
+ import org.apache.http.client.config.CookieSpecs
17
+ import org.apache.http.client.config.RequestConfig
18
+ import org.apache.http.client.entity.EntityBuilder
19
+ import org.apache.http.client.methods.HttpPatch
20
+ import org.apache.http.entity.ContentType
21
+ import org.apache.http.impl.client.HttpClientBuilder
22
+ import org.apache.http.util.EntityUtils
10
23
11
24
group = project. maven_group
12
25
version = " ${ project.mod_version} +${ getMCVersionString()} "
@@ -15,12 +28,27 @@ archivesBaseName = project.archives_base_name
15
28
// This field defines the Java version your mod target.
16
29
def targetJavaVersion = 16
17
30
18
- def getMCVersionString () {
19
- if (project. minecraft_version. matches(" \\ d\\ dw\\ d\\ d[a-z]" )) {
31
+ boolean isMCVersionNonRelease () {
32
+ return project. minecraft_version. matches(' ^\\ d\\ dw\\ d\\ d[a-z]$' )
33
+ || project. minecraft_version. matches(' \\ d+\\ .\\ d+-(pre|rc)(\\ d+)' )
34
+ }
35
+
36
+ String getMCVersionString () {
37
+ if (isMCVersionNonRelease()) {
20
38
return project. minecraft_version
21
39
}
22
- int lastDot = project. minecraft_version. lastIndexOf(' .' )
23
- return project. minecraft_version. substring(0 , lastDot)
40
+ def version = project. minecraft_version. split(' \\ .' )
41
+ return version[0 ] + ' .' + version[1 ]
42
+ }
43
+
44
+ String parseReadme () {
45
+ def excludeRegex = / (?m)<!-- modrinth_exclude\. start -->(.|\n )*?<!-- modrinth_exclude\. end -->/
46
+ def linkRegex = / !\[ ([A-z_ ]+)]\( (images\/ [A-z.\/ _]+)\) /
47
+
48
+ def readme = (String ) file(' README.md' ). text
49
+ readme = readme. replaceAll(excludeRegex, ' ' )
50
+ // readme = readme.replaceAll(linkRegex, '')
51
+ return readme
24
52
}
25
53
26
54
minecraft {
@@ -58,7 +86,7 @@ configurations {
58
86
59
87
dependencies {
60
88
minecraft " com.mojang:minecraft:${ project.minecraft_version} "
61
- mappings " net.fabricmc:yarn:${ project.yarn_mappings} :v2"
89
+ mappings " net.fabricmc:yarn:${ project.minecraft_version } +build. ${ project. yarn_mappings} :v2"
62
90
modImplementation " net.fabricmc:fabric-loader:${ project.loader_version} "
63
91
64
92
// Fabric API. This is technically optional, but you probably want it anyway.
@@ -70,11 +98,9 @@ dependencies {
70
98
modImplementation(" com.terraformersmc:modmenu:${ project.modmenu_version} " ) {
71
99
transitive = false
72
100
}
73
- // modImplementation "grondag:canvas-mc116:1.0.+"
74
- // modImplementation "com.github.jellysquid3:sodium-fabric:mc1.16.3-0.1.0"
75
101
76
- shadow " com.electronwill.night-config:core:3.6.3"
77
- shadow " com.electronwill.night-config:toml:3.6.3"
102
+ shadow ' com.electronwill.night-config:core:3.6.3'
103
+ shadow ' com.electronwill.night-config:toml:3.6.3'
78
104
}
79
105
80
106
java {
@@ -91,15 +117,15 @@ tasks.withType(JavaCompile).configureEach {
91
117
}
92
118
93
119
processResources {
94
- inputs. property " version" , project. version
120
+ inputs. property ' version' , project. version
95
121
96
- filesMatching(" fabric.mod.json" ) {
97
- expand " version" : project. version
122
+ filesMatching(' fabric.mod.json' ) {
123
+ expand ' version' : project. version
98
124
}
99
125
}
100
126
101
127
jar {
102
- from(" LICENSE" ) {
128
+ from(' LICENSE' ) {
103
129
rename { " ${ it} _${ project.archivesBaseName} " }
104
130
}
105
131
}
@@ -110,22 +136,74 @@ license {
110
136
}
111
137
112
138
shadowJar {
113
- dependsOn(project( " : " ) . jar)
139
+ dependsOn jar
114
140
configurations = [project. configurations. shadow]
115
141
archiveClassifier. set(' dev' )
116
142
117
- relocate ' com.electronwill.nightconfig' , ' me .lambdaurora.lambdynlights.shadow.nightconfig'
143
+ relocate ' com.electronwill.nightconfig' , ' dev .lambdaurora.lambdynlights.shadow.nightconfig'
118
144
}
145
+ remapJar. dependsOn(shadowJar)
119
146
120
147
task shadowRemapJar (type : RemapJarTask ) {
121
148
dependsOn shadowJar
122
149
123
- input = file(" ${ project.buildDir} /libs/$archivesBaseName -$version -dev.jar" )
124
- archiveName = " ${ archivesBaseName} -${ version} .jar"
125
- addNestedDependencies = true
150
+ input. set( file(" ${ project.buildDir} /libs/$archivesBaseName -${ project. version} -dev.jar" ) )
151
+ archiveFileName = " ${ archivesBaseName} -${ project. version} .jar"
152
+ addNestedDependencies. set( true )
126
153
}
127
154
build. dependsOn(shadowRemapJar)
128
155
156
+ task publishModrinth (type : TaskModrinthUpload ) {
157
+ dependsOn(build)
158
+ onlyIf {
159
+ System . getenv(' MODRINTH_TOKEN' )
160
+ }
161
+
162
+ token = System . getenv(' MODRINTH_TOKEN' )
163
+ projectId = project. modrinth_id
164
+ versionNumber = version
165
+ versionName = " LambDynamicLights ${ project.mod_version} (${ getMCVersionString()} )"
166
+ uploadFile = shadowRemapJar
167
+ addGameVersion((String ) project. minecraft_version)
168
+ addLoader(' fabric' )
169
+ versionType = isMCVersionNonRelease() ? VersionType . BETA : VersionType . RELEASE
170
+
171
+ // Changelog fetching
172
+ def changelogText = file(' CHANGELOG.md' ). text
173
+ def regexVersion = ((String ) project. mod_version). replaceAll(' \\ .' , / \\ ./ ). replaceAll(' \\ +' , ' \\ +' )
174
+ def changelogRegex = ~" ###? ${regexVersion}\\ n\\ n(( *- .+\\ n)+)"
175
+ def matcher = changelogText =~ changelogRegex
176
+ matcher. find()
177
+
178
+ changelog = matcher. group(1 )
179
+
180
+ // Readme
181
+ doFirst {
182
+ final def client = HttpClientBuilder . create(). setDefaultRequestConfig(RequestConfig . custom(). setCookieSpec(CookieSpecs . IGNORE_COOKIES ). build()). build()
183
+ final def patch = new HttpPatch ((String ) (apiURL + ' /v1/mod/' + projectId))
184
+ patch. addHeader(" Authorization" , token)
185
+
186
+ var json = new JsonObject ()
187
+ json. addProperty(" body" , parseReadme())
188
+ patch. setEntity(EntityBuilder . create()
189
+ .setText(json. toString())
190
+ .setContentType(ContentType . APPLICATION_JSON )
191
+ .build())
192
+
193
+ final def response = client. execute(patch)
194
+ final int status = response. getStatusLine(). getStatusCode()
195
+
196
+ final def gson = new GsonBuilder (). create()
197
+ if (status == 200 ) {
198
+ project. getLogger(). lifecycle(" Successfully updated readme to ${ projectId} ." )
199
+ } else {
200
+ errorInfo = gson. fromJson(EntityUtils . toString(response. getEntity()), ResponseError . class)
201
+ project. getLogger(). error(" Upload failed! Status: ${ status} Error: ${ errorInfo.getError()} Reason: ${ errorInfo.getDescription()} " )
202
+ throw new GradleException (" Upload failed! Status: ${ status} Reason: ${ errorInfo.getDescription()} " )
203
+ }
204
+ }
205
+ }
206
+
129
207
// configure the maven publication
130
208
publishing {
131
209
publications {
0 commit comments