-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
155 lines (136 loc) · 5.39 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import org.apache.commons.io.FileUtils
plugins {
id 'fabric-loom' version '1.8.11'
id 'maven-publish'
}
loom {
accessWidenerPath = new File("src/main/resources/" + project.artifact_id + ".accesswidener")
}
version = project.mod_version
group = project.group_id
base {
archivesName = project.artifact_id
}
repositories {
maven { url "https://api.modrinth.com/maven" }
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}" }
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
/**
* Adds a mod from Modrinth to your mod.
*/
void addMod(String name, String version, ModState state) {
dependencies {
if (state == ModState.COMPILE_ONLY) modCompileOnly("maven.modrinth:" + name + ":" + version)
else if (state == ModState.IDE_ONLY) modImplementation("maven.modrinth:" + name + ":" + version)
else if (state == ModState.JAR_IN_JAR) include(modImplementation("maven.modrinth:" + name + ":" + version))
}
}
enum ModState {
JAR_IN_JAR,
IDE_ONLY,
COMPILE_ONLY
}
// --------------------------------------------------------------------------------------------------------------------------
// EVERYTHING BELOW THIS (INCLUDING THIS COMMENT) CAN BE DELETED AFTER RUNNING THE TASK.
// --------------------------------------------------------------------------------------------------------------------------
class FinalSetupTask extends DefaultTask {
@Input
String groupId
@Input
String modId
@Input
String modName
@Input
String modDescription
@Input
String modAuthor
@Input
String modVersion
@TaskAction
def run() {
replaceConfigs(new File("gradle.properties"))
replaceConfigs(new File("src/main/resources/fabric.mod.json"))
replaceConfigs(new File("src/main/resources/modid.mixins.json"))
FileUtils.moveFile(new File("src/main/resources/modid.accesswidener"), new File("src/main/resources/" + modId + ".accesswidener"))
FileUtils.moveFile(new File("src/main/resources/modid.mixins.json"), new File("src/main/resources/" + modId + ".mixins.json"))
project.mkdir "src/main/java/" + groupId.replace(".", "/") + "/" + modId + "/mixin"
project.mkdir("src/main/resources/assets/" + modId)
FileUtils.moveFile(new File("src/main/resources/icon.png"), new File("src/main/resources/assets/" + modId + "/icon.png"))
}
private void replaceConfigs(File file) {
def reader = new BufferedReader(new FileReader(file))
List<String> lines = reader.readLines()
List<String> list = new ArrayList<>()
def writer = new BufferedWriter(new FileWriter(file))
switch (file.getName()) {
case "gradle.properties": {
lines.forEach { String s ->
list.add(s.replace("group_id=com.example", "group_id=" + groupId)
.replace("artifact_id=modid", "artifact_id=" + modId)
.replace("mod_version=modVersion", "mod_version=" + modVersion)
)
}
break
}
case "fabric.mod.json": {
for (def s in lines) {
list.add(s.replace("<mod_id>", modId)
.replace("<mod_name>", modName)
.replace("<mod_description>", modDescription)
.replace("<author>", modAuthor)
)
}
break
}
case "modid.mixins.json": {
for (def s in lines) {
list.add(s.replace("<group_id>.<mod_id>", groupId + "." + modId))
}
break
}
}
for (final def s in list) {
writer.writeLine(s)
}
writer.close()
}
}
tasks.register("finalSetup", FinalSetupTask) {
groupId = "com.example" // Group-ID. If using a domain, make 100% sure you own it. If you don't own one, use either "me.yourusername" or "io.github.yourgithubusername" if you have a github user
modId = "modid" // Mod-ID. Please only use lowercase a-z characters
modName = "Example Mod" // Mod-Name - Will be used in mods like ModMenu to show your mod name.
modDescription = "Some Mod man, idk either lol. It's me, UwU OwO" // Description. Same as above, but for a Description
modAuthor = "Your beautiful name <3" // Author of the Mod.
modVersion = "1.0+build.1" // Mod-Version. You can use multiple schemes, i like to use schemes like "1.20.2.build.*" for my mods, some also prefer schemes like "1.0.1" or "1.0+build.1". If you don't know, simply use a semantic scheme, aka "major.minor.patch", ie. "1.0.0"
}