forked from DrFair/ExampleMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
201 lines (158 loc) · 7.5 KB
/
Copy pathbuild.gradle
File metadata and controls
201 lines (158 loc) · 7.5 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
plugins {
id 'java'
}
// Change the values below this to your mods values
// To change the project name, edit the settings.gradle file
project.ext.modID = "fair.examplemod" // The unique id of your mod. Must be all lowercase and cannot use special characters.
project.ext.modName = "Example Mod" // The display name of your mod.
project.ext.modVersion = "1.0" // Your current builds version. Must follow the xx.xx... format.
project.ext.gameVersion = "1.3.2" // The target game version.
project.ext.modDescription = "Just an example mod" // Short description of what your mod is.
project.ext.author = "Fair" // Your name
/**
* When setting clientside to true, it means servers do not need this mod for clients to connect and vice versa.
* IMPORTANT: If you set this to true, make sure that your mod does not add any content or do anything
* that could cause clients and servers to desync. This includes registering any items, objects, tiles, packets etc.
*/
project.ext.clientside = false
/**
* The other mod dependencies of this mod
* Dependencies define the default load order of mods
* Uncomment and configure these if your mod has dependencies
*/
//project.ext.modDependencies = ["other.modid1", "other.modid2"]
//project.ext.modOptionalDependencies = ["optional.modid1", "optional.modid2"]
// The path to the games install directory, modify this only if the auto-detection fails
def gameDirectory = getDefaultGamePath()
// =================================================
// ========== DO NOT EDIT BELOW THIS LINE ==========
// =================================================
// Name of the jar
def jarName = "${project.ext.modName.replace(" ", "")}-${project.ext.gameVersion}-${project.ext.modVersion}"
group project.ext.modID
version project.ext.modVersion
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
configurations {
libDepends
}
sourceSets.main.output.resourcesDir = file("build/mod/resources/")
sourceSets.main.java.getDestinationDirectory().set(file("build/mod/"))
sourceSets.main.compileClasspath += configurations.libDepends // Adds libDepends configuration to classpath
def buildLocation = "build/jar/"
compileJava.options.encoding = "UTF-8"
println "Checking for the Necesse.jar inside: ${gameDirectory}"
if (!file(gameDirectory + "/Necesse.jar").exists()) {
throw new Exception("Could not find game install directory. Make sure it is correct in build.gradle file.")
} else {
println "Success"
}
dependencies {
implementation files(gameDirectory + "/Necesse.jar")
implementation fileTree(gameDirectory + "/lib/")
implementation fileTree("./mods/") // Add all mods located in local mods folder
// Add any third party library dependencies here. Remember to use libDepends, so that they will be added to your jar on build
// These are some examples:
// libDepends group: 'com.google.guava', name: 'guava', version: '31.1-jre'
// libDepends files("path/to/library/jar.jar")
}
tasks.register('createAppID') {
group "necesse"
description "Creates steam_appid.txt file"
doLast {
file("steam_appid.txt").text = "1169040"
}
}
tasks.register('createModInfoFile', JavaExec) {
group "necesse"
description "Creates the mod info file"
classpath = files(gameDirectory + "/Necesse.jar")
getMainClass().set("CreateModInfoFile")
args "-file", "${sourceSets.main.java.getClassesDirectory().get()}/mod.info",
"-id", "${project.ext.modID}",
"-name", "${project.ext.modName}",
"-version", "${project.ext.modVersion}",
"-gameVersion", "${project.ext.gameVersion}",
"-description", "${project.ext.modDescription}",
"-author", "${project.ext.author}",
"-clientside", "${project.ext.clientside}",
"-dependencies", project.ext.has("modDependencies") ? "[" + project.ext.modDependencies.join(", ") + "]" : "",
"-optionalDependencies", project.ext.has("modOptionalDependencies") ? "[" + project.ext.modOptionalDependencies.join(", ") + "]" : ""
}
// Makes compiling also create mod info file
classes.dependsOn("createModInfoFile")
tasks.register('preAntialiasTextures', JavaExec) {
group "necesse"
description "Runs pre-antialiasing on all textures in the resources folder"
classpath = files(gameDirectory + "/Necesse.jar")
main "PreAntialiasTextures"
args "-folders", "${sourceSets.main.resources.srcDirs.stream().map { file -> file.path }.toArray().join(";")}"
}
tasks.register('runClient', JavaExec) {
group "necesse"
description "Run client with current mod"
dependsOn "buildModJar", "createAppID"
classpath = files(gameDirectory + "/Necesse.jar")
getMainClass().set("StartSteamClient")
jvmArgs "-Xms512m", "-Xmx4G", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseG1GC", "-XX:G1NewSizePercent=20", "-XX:G1ReservePercent=20", "-XX:MaxGCPauseMillis=50", "-XX:G1HeapRegionSize=32M"
args "-dev", "-mod \"${buildLocation}\""
}
tasks.register('runDevClient', JavaExec) {
group "necesse"
description "Run client with current mod"
dependsOn "buildModJar", "createAppID"
classpath = files(gameDirectory + "/Necesse.jar")
getMainClass().set("StartSteamClient")
jvmArgs "-Xms512m", "-Xmx4G", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseG1GC", "-XX:G1NewSizePercent=20", "-XX:G1ReservePercent=20", "-XX:MaxGCPauseMillis=50", "-XX:G1HeapRegionSize=32M"
args "-dev 1", "-mod \"${buildLocation}\""
}
tasks.register('runServer', JavaExec) {
group "necesse"
description "Run server with current mod"
dependsOn "buildModJar"
classpath = files(gameDirectory + "/Server.jar")
getMainClass().set("StartDesktopServer")
jvmArgs "-Xms512m", "-Xmx4G", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseG1GC", "-XX:G1NewSizePercent=20", "-XX:G1ReservePercent=20", "-XX:MaxGCPauseMillis=50", "-XX:G1HeapRegionSize=32M"
args "-mod \"${buildLocation}\""
}
tasks.register('buildModJar', Jar) {
group "necesse"
description "Generates the mod jar into the build folder"
dependsOn "classes", "createModInfoFile"
doFirst {
fileTree(dir: buildLocation).exclude("${jarName}.jar").visit { FileVisitDetails details ->
delete details.file
}
}
// Add mod output
from sourceSets.main.java.getClassesDirectory()
// Add the dependencies
from configurations.libDepends.collect { it.isDirectory() ? it : zipTree(it) }
setArchiveFileName("${jarName}.jar")
setDestinationDirectory(file(buildLocation))
}
enum OS { WINDOWS, MAC, LINUX, UNKNOWN }
// Returns the Enum value of OS based on the match
// Linux has more options as Ubuntu-like, NixOS and OpenBSD may not contain "linux"
def getOS() {
def os = System.getProperty("os.name").toLowerCase()
println "Detected OS: ${os}"
if (os.contains("win")) return OS.WINDOWS
else if (os.contains("mac") || os.contains("darwin")) return OS.MAC
else if (os.contains("untu") || os.contains("nux") || os.contains("nix") || os.contains("bsd")) return OS.LINUX
else return OS.UNKNOWN
}
// On the UNKNOWN we try linux-like path as it's the most likely to have a specific name
def getDefaultGamePath() {
def homeDir = System.getProperty('user.home')
return switch (getOS()) {
case OS.WINDOWS -> "C:/Program Files (x86)/Steam/steamapps/common/Necesse"
case OS.MAC -> homeDir + "/Library/Application Support/Steam/steamapps/common/Necesse"
case OS.LINUX, OS.UNKNOWN -> homeDir + "/.local/share/Steam/steamapps/common/Necesse"
}
}