1
- import groovy.json.JsonSlurper
2
- import groovy.json.JsonOutput
3
-
4
1
plugins {
2
+ id ' java-library'
5
3
id ' eclipse'
4
+ id ' idea'
6
5
id ' maven-publish'
7
- id ' net.neoforged.gradle' version ' [6.0.18,6.2)'
8
- id " me.modmuss50.mod-publish-plugin" version " 0.3.5"
9
- }
10
-
11
- apply {
12
- // Fixes m1 macs having build time errors (#forgeplzfix)
13
- // from "https://raw.githubusercontent.com/mezz/JustEnoughItems/1.18/Forge/buildtools/AppleSiliconSupport.gradle"
6
+ id ' net.neoforged.gradle.userdev' version ' 7.0.80'
14
7
}
15
8
16
9
version = " ${ mod_version} "
17
- group = ' com.direwolf20.mininggadgets' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
18
- archivesBaseName = ' mininggadgets'
10
+ group = mod_group_id
19
11
20
- java. toolchain. languageVersion = JavaLanguageVersion . of(17 )
12
+ // All jar files from this folder will be added automatically as runtime mod dependencies
13
+ def extraModsDir = " extra-mods"
14
+ def extraAPIDir = " extra-api"
21
15
22
- minecraft {
23
- mappings channel : ' official' , version : " ${ mc_version} "
24
- // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
25
- // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
16
+ repositories {
17
+ mavenLocal()
26
18
27
- runs {
28
- client {
29
- workingDirectory project. file(' run' )
19
+ flatDir {
20
+ name " extra-mods"
21
+ dir file(extraModsDir)
22
+ }
30
23
31
- property ' forge.logging.markers' , ' SCAN,REGISTRIES'
32
- property ' forge.logging.console.level' , ' debug'
24
+ flatDir {
25
+ name " extra-api"
26
+ dir file(extraAPIDir)
27
+ }
33
28
34
- mods {
35
- mininggadgets {
36
- source sourceSets . main
37
- }
38
- }
29
+ maven { // Patchouli && JEI
30
+ url ' https://maven.blamejared.com '
31
+ content {
32
+ includeGroup " vazkii.patchouli "
33
+ includeGroup " mezz.jei "
39
34
}
35
+ }
40
36
41
- server {
42
- workingDirectory project. file(' run' )
43
-
44
- property ' forge.logging.markers' , ' SCAN,REGISTRIES,REGISTRYDUMP'
45
- property ' forge.logging.console.level' , ' debug'
46
-
47
- mods {
48
- mininggadgets {
49
- source sourceSets. main
50
- }
51
- }
37
+ maven { // Curios
38
+ url = " https://maven.theillusivec4.top/"
39
+ content {
40
+ includeGroup " top.theillusivec4.curios"
52
41
}
42
+ }
53
43
54
- data {
55
- workingDirectory project. file(' run' )
56
-
57
- property ' forge.logging.markers' , ' SCAN,REGISTRIES,REGISTRYDUMP'
58
- property ' forge.logging.console.level' , ' debug'
59
-
60
- args ' --mod' , ' mininggadgets' , ' --all' , ' --output' , file(' src/generated/resources/' ), ' --existing' , file(' src/main/resources/' )
61
- mods {
62
- mininggadgets {
63
- source sourceSets. main
64
- }
65
- }
44
+ maven { // mek
45
+ url = ' https://modmaven.dev/'
46
+ content {
47
+ includeGroup " mekanism"
48
+ includeGroup " appeng"
66
49
}
67
50
}
51
+
52
+ maven { url = " https://www.cursemaven.com" } // curse mods
68
53
}
69
54
70
- sourceSets. main. resources { srcDir ' src/generated/resources' }
55
+ base {
56
+ archivesName = mod_id
57
+ }
71
58
72
- // All jar files from this folder will be added automatically as runtime mod dependencies
73
- def extraModsDir = " extra-mods "
59
+ // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
60
+ java . toolchain . languageVersion = JavaLanguageVersion . of( 17 )
74
61
75
- repositories {
76
- flatDir {
77
- name " extra-mods"
78
- dir file(extraModsDir)
62
+ // minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager
63
+
64
+ // Default run configurations.
65
+ // These can be tweaked, removed, or duplicated as needed.
66
+ runs {
67
+ // applies to all the run configs below
68
+ configureEach {
69
+ // Recommended logging data for a userdev environment
70
+ // The markers can be added/remove as needed separated by commas.
71
+ // "SCAN": For mods scan.
72
+ // "REGISTRIES": For firing of registry events.
73
+ // "REGISTRYDUMP": For getting the contents of all registries.
74
+ systemProperty ' forge.logging.markers' , ' REGISTRIES'
75
+
76
+ // Recommended logging level for the console
77
+ // You can set various levels here.
78
+ // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
79
+ systemProperty ' forge.logging.console.level' , ' debug'
80
+
81
+ modSource project. sourceSets. main
79
82
}
80
83
81
- maven {
82
- name " ModMaven"
83
- url " https://modmaven.k-4u.nl"
84
- content {
85
- includeGroup(" mezz.jei" )
86
- }
84
+ client {
85
+ // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
86
+ systemProperty ' forge.enabledGameTestNamespaces' , project. mod_id
87
87
}
88
88
89
- maven { url = " https://maven.architectury.dev" }
89
+ server {
90
+ systemProperty ' forge.enabledGameTestNamespaces' , project. mod_id
91
+ programArgument ' --nogui'
92
+ }
90
93
91
- maven {
92
- url " https://www.cursemaven.com"
93
- content {
94
- includeGroup " curse.maven"
95
- }
94
+ // This run config launches GameTestServer and runs all registered gametests, then exits.
95
+ // By default, the server will crash when no gametests are provided.
96
+ // The gametest system is also enabled by default for other run configs under the /test command.
97
+ gameTestServer {
98
+ systemProperty ' forge.enabledGameTestNamespaces' , project. mod_id
99
+ }
100
+
101
+ data {
102
+ // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
103
+ // workingDirectory project.file('run-data')
104
+
105
+ // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
106
+ programArguments. addAll ' --mod' , project. mod_id, ' --all' , ' --output' , file(' src/generated/resources/' ). getAbsolutePath(), ' --existing' , file(' src/main/resources/' ). getAbsolutePath()
96
107
}
97
108
}
98
109
110
+ // Include resources generated by data generators.
111
+ sourceSets. main. resources { srcDir ' src/generated/resources' }
112
+
99
113
dependencies {
100
- minecraft " net.neoforged:forge:${ mc_version} -${ forge_version} "
114
+ // Specify the version of Minecraft to use.
115
+ // Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above.
116
+ // The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version.
117
+ // You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader.
118
+ // And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version.
119
+ // For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
120
+ implementation " net.neoforged:neoforge:${ neo_version} "
121
+
122
+ // AE2
123
+ // compileOnly "appeng:appliedenergistics2-neoforge:${ae2_version}:api"
124
+ // runtimeOnly "appeng:appliedenergistics2-neoforge:${ae2_version}"
125
+
126
+ // Curios
127
+ // runtimeOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}"
128
+ // compileOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}:api"
129
+
130
+ // Example mod dependency with JEI
131
+ // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
132
+ compileOnly " mezz.jei:jei-${ minecraft_version} -common-api:${ jei_version} "
133
+ compileOnly " mezz.jei:jei-${ minecraft_version} -forge-api:${ jei_version} "
134
+ runtimeOnly " mezz.jei:jei-${ minecraft_version} -neoforge:${ jei_version} "
101
135
102
136
// Locally sourced extra mods for runtime (i.e. testing)
103
137
for (extraModJar in fileTree(dir : extraModsDir, include : ' *.jar' )) {
@@ -106,139 +140,66 @@ dependencies {
106
140
assert versionSep != -1
107
141
def artifactId = basename. substring(0 , versionSep)
108
142
def version = basename. substring(versionSep + 1 )
109
- runtimeOnly fg . deobf( " extra-mods:$artifactId :$version " )
143
+ runtimeOnly " extra-mods:$artifactId :$version "
110
144
}
111
145
112
- // JEI
113
- // compile against the JEI API but do not include it at runtime
114
- compileOnly fg. deobf(" mezz.jei:jei-${ mc_version} -common-api:${ jei_version} " )
115
- compileOnly fg. deobf(" mezz.jei:jei-${ mc_version} -forge-api:${ jei_version} " )
116
- // at runtime, use the full JEI jar
117
- runtimeOnly fg. deobf(" mezz.jei:jei-${ mc_version} -forge:${ jei_version} " )
118
-
119
- // runtimeOnly fg.deobf("curse.maven:inventory-tweaks-renewed:3102237")
120
- // runtimeOnly fg.deobf("curse.maven:lollipop-347954:3232534")
121
- // runtimeOnly fg.deobf("curse.maven:mekanism-268560:268560")
122
-
123
- runtimeOnly fg. deobf(" curse.maven:charging-gadgets-399757:4617304" )
124
- }
146
+ // Locally sourced extra mods for compiling (i.e. API)
147
+ for (extraModJar in fileTree(dir : extraAPIDir, include : ' *.jar' )) {
148
+ def basename = extraModJar. name. substring(0 , extraModJar. name. length() - " .jar" . length())
149
+ def versionSep = basename. lastIndexOf(' -' )
150
+ assert versionSep != -1
151
+ def artifactId = basename. substring(0 , versionSep)
152
+ def version = basename. substring(versionSep + 1 )
153
+ compileOnly " extra-api:$artifactId :$version "
154
+ }
125
155
126
- processResources {
127
- duplicatesStrategy = DuplicatesStrategy . INHERIT
156
+ // Example mod dependency using a mod jar from ./libs with a flat dir repository
157
+ // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
158
+ // The group id is ignored when searching -- in this case, it is "blank"
159
+ // implementation "blank:coolmod-${mc_version}:${coolmod_version}"
128
160
129
- inputs. property " version" , project. version
161
+ // Example mod dependency using a file as dependency
162
+ // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar")
130
163
131
- filesMatching(" META-INF/mods.toml" ) {
132
- expand " version" : project. version,
133
- " mcversion" : project. mc_version,
134
- " forgeversion" : project. forge_version,
135
- " forgeshortversion" : project. forge_version. split(' \\ .' )[0 ],
136
- " forge_acceptable_range" : project. forge_acceptable_range
137
- }
164
+ // Example project dependency using a sister or child project:
165
+ // implementation project(":myproject")
138
166
139
- doLast {
140
- def jsonMinifyStart = System . currentTimeMillis()
141
- def jsonMinified = 0
142
- def jsonBytesSaved = 0
143
-
144
- fileTree(dir : outputs. files. asPath, include : ' **/*.json' ). each {
145
- File file = it
146
- jsonMinified++
147
- def oldLength = file. length()
148
- try {
149
- file. text = JsonOutput . toJson(new JsonSlurper (). parse(file))
150
- jsonBytesSaved + = oldLength - file. length()
151
- } catch (Exception e) {
152
- println (' Failed to minify ' + it + ' ' + e)
153
- }
154
- }
155
-
156
- println (' Minified ' + jsonMinified + ' json files. Saved ' + jsonBytesSaved + ' bytes. Took ' + (System . currentTimeMillis() - jsonMinifyStart) + ' ms.' )
157
- }
167
+ // For more info:
168
+ // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
169
+ // http://www.gradle.org/docs/current/userguide/dependency_management.html
158
170
}
159
171
160
- jar {
161
- manifest {
162
- attributes([
163
- " Specification-Title" : " mininggadgets" ,
164
- " Specification-Vendor" : " direwolf20" ,
165
- " Specification-Version" : " 1" , // We are version 1 of ourselves
166
- " Implementation-Title" : project. name,
167
- " Implementation-Version" : " ${ version} " ,
168
- " Implementation-Vendor" :" direwolf20" ,
169
- " Implementation-Timestamp" : new Date (). format(" yyyy-MM-dd'T'HH:mm:ssZ" )
170
- ])
172
+ // This block of code expands all declared replace properties in the specified resource targets.
173
+ // A missing property will result in an error. Properties are expanded using ${} Groovy notation.
174
+ // When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
175
+ // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
176
+ tasks. withType(ProcessResources ). configureEach {
177
+ var replaceProperties = [
178
+ minecraft_version : minecraft_version, minecraft_version_range : minecraft_version_range,
179
+ neo_version : neo_version, neo_version_range : neo_version_range,
180
+ loader_version_range : loader_version_range,
181
+ mod_id : mod_id, mod_name : mod_name, mod_license : mod_license, mod_version : mod_version,
182
+ mod_authors : mod_authors, mod_description : mod_description,
183
+ ]
184
+ inputs. properties replaceProperties
185
+
186
+ filesMatching([' META-INF/mods.toml' ]) {
187
+ expand replaceProperties + [project : project]
171
188
}
172
189
}
173
190
174
- jar. finalizedBy(' reobfJar' )
175
-
191
+ // Example configuration to allow publishing using the maven-publish plugin
176
192
publishing {
177
193
publications {
178
- maven( MavenPublication ) {
194
+ register( ' mavenJava ' , MavenPublication ) {
179
195
from components. java
180
- artifactId = project. archivesBaseName. toLowerCase()
181
- }
182
- }
183
- }
184
-
185
- def makeChangelog () {
186
- def changelogText = file(" ./CHANGELOG.md" ). text;
187
-
188
- def output = " " ;
189
- def readLines = false
190
- for (line in changelogText. lines()) {
191
- if (line. startsWith(" ### " ) || line. startsWith(" ## " )) {
192
- if (readLines) {
193
- break ;
194
- }
195
-
196
- if (line. contains(" ${ mod_version} " ) && line. startsWith(" ### " )) {
197
- readLines = true ;
198
- }
199
- }
200
- if (readLines) {
201
- output + = line + " \n " ;
202
196
}
203
197
}
204
-
205
- return output. trim();
206
- }
207
-
208
-
209
- tasks. register(" testChangelog" ) {
210
- group = " tests"
211
-
212
- doLast {
213
- println makeChangelog()
214
- }
215
- }
216
-
217
- publishMods {
218
- dryRun = providers. environmentVariable(" CURSE_TOKEN" ). getOrNull() == null
219
- file = jar. archiveFile
220
- changelog = makeChangelog()
221
- type = STABLE
222
-
223
- modLoaders. add(" neoforge" )
224
- modLoaders. add(" forge" )
225
-
226
- curseforge {
227
- projectId = " 351748"
228
- accessToken = providers. environmentVariable(" CURSE_TOKEN" )
229
- minecraftVersions. add(project. mc_version)
230
-
231
- optional {
232
- slug = " charging-gadgets"
198
+ repositories {
199
+ maven {
200
+ url " file://${ project.projectDir} /repo"
233
201
}
234
202
}
235
-
236
- github {
237
- repository = " direwolf20-mc/MiningGadgets"
238
- accessToken = providers. environmentVariable(" GITHUB_TOKEN" )
239
- commitish = providers. environmentVariable(" GITHUB_SHA" ). orElse(" dryRun" )
240
- tagName = providers. environmentVariable(" GITHUB_REF_NAME" ). orElse(" dryRun" )
241
- }
242
203
}
243
204
244
205
tasks. withType(JavaCompile ). configureEach {
0 commit comments