forked from RosepadMC/RosepadLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
192 lines (154 loc) · 6.09 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
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
import java.nio.file.Files
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
group 'net.buj'
version '0.1-SNAPSHOT'
def asm_version = '5.2'
static byte[] diff(byte[] src, byte[] target) {
byte[] bytes = new byte[target.length];
for (int i = 0; i < bytes.length; i++) {
byte a = (byte) (i < src.length ? src[i] : 0);
byte b = target[i];
bytes[i] = (byte) (a ^ b);
}
return bytes;
}
repositories {
mavenCentral()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
}
dependencies {
implementation project(":rml")
implementation 'net.fabricmc:tiny-remapper:0.8.6'
shadow files('../libs/lwjgl.jar')
shadow files('../libs/lwjgl_util.jar')
annotationProcessor implementation ("org.ow2.asm:asm:${asm_version}")
annotationProcessor implementation ("org.ow2.asm:asm-analysis:${asm_version}")
annotationProcessor implementation ("org.ow2.asm:asm-commons:${asm_version}")
annotationProcessor implementation ("org.ow2.asm:asm-tree:${asm_version}")
annotationProcessor implementation ("org.ow2.asm:asm-util:${asm_version}")
implementation('net.fabricmc:sponge-mixin:0.9.2+mixin.0.8.2') {
exclude module: 'launchwrapper'
exclude module: 'guava'
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
tasks.register('addDiffFiles', Copy) {
dependsOn shadowJar
from(
projectDir.toPath().resolve("src/main/java/resources/client.diff"),
projectDir.toPath().resolve("src/main/java/resources/server.diff")
)
into(zipTree(shadowJar.archiveFile.get().asFile))
}
processResources {
dependsOn "createDiffs"
}
tasks.register('client', Jar) {
dependsOn 'shadowJar'
archiveFileName = "clientLoader.jar"
exclude "server*"
from zipTree(shadowJar.archiveFile)
}
tasks.register('server', Jar) {
dependsOn 'shadowJar'
archiveFileName = "serverLoader.jar"
manifest {
attributes 'Main-Class': 'net.minecraft.server.MinecraftServer'
}
exclude "client*"
from zipTree(shadowJar.archiveFile)
}
tasks.register('pack', Copy) {
dependsOn "client"
dependsOn "server"
from('build/libs/') {
include 'clientLoader.jar'
include 'serverLoader.jar'
rename 'clientLoader.jar', 'RosepadClient.jar'
rename 'serverLoader.jar', 'RosepadServer.jar'
}
into '../build'
}
processResources {
dependsOn "createDiffs"
}
shadowJar {
dependsOn "createDiffs"
}
tasks.register("createDiffs") {
dependsOn rootProject.compileSub
doLast {
byte[] rosepadClient = Files.readAllBytes(rootProject.rootDir.toPath().resolve("client/build/libs/client-1.1-SNAPSHOT-all.jar"))
byte[] vanillaClient = Files.readAllBytes(rootProject.rootDir.toPath().resolve("jars/lilypad_client_s.jar"))
byte[] diffClient = diff(vanillaClient, rosepadClient);
Files.write(project.projectDir.toPath().resolve("src/main/resources/client.diff"), diffClient);
byte[] rosepadServer = Files.readAllBytes(rootProject.rootDir.toPath().resolve("server/build/libs/server-1.1-SNAPSHOT-all.jar"))
byte[] vanillaServer = Files.readAllBytes(rootProject.rootDir.toPath().resolve("jars/lilypad_server_s.jar"))
byte[] diffServer = diff(vanillaServer, rosepadServer);
Files.write(project.projectDir.toPath().resolve("src/main/resources/server.diff"), diffServer);
}
}
FileCollection getLilypadClasspath(FileCollection originalCollection, String libraryFolder, String mainFile) {
File libFolder = new File(libraryFolder)
ArrayList<File> finalList = libFolder.listFiles()
// Remove files from libFolder that original already has
for (File libraryFile : libFolder.listFiles()) {
for (File classpathFile in originalCollection.getFiles()) {
if (!finalList.contains(classpathFile)) {
finalList.add(classpathFile) // for src/main/java and src/main/resources
}
}
}
finalList.add(mainFile as File)
return files(finalList)
}
static List<String> getRunJVMArgs(String allocatedMemory, java.nio.file.Path libDir, java.nio.file.Path runHome) {
List<String> jvmArgs = new ArrayList<String>()
jvmArgs.add("-Xmx" + allocatedMemory)
jvmArgs.add("-Xms" + allocatedMemory)
jvmArgs.add("-Djava.util.Arrays.useLegacyMergeSort=true")
jvmArgs.add("-Djava.library.path=" + libDir)
jvmArgs.add("-Duser.home=" + runHome)
Files.createDirectories(runHome);
return jvmArgs
}
tasks.register('runServer', JavaExec) {
dependsOn rootProject.project("server").tasks.named("createPatches")
dependsOn rootProject.project("client").tasks.named("createPatches")
dependsOn server
mainClass = "net.minecraft.server.MinecraftServer"
argsString = "nogui"
classpath = getLilypadClasspath(
sourceSets.main.runtimeClasspath,
rootProject.projectDir.toPath().resolve("libs").toString(),
shadowJar.destinationDirectory.file("serverLoader.jar").toString()
)
environment("HOME", rootProject.projectDir.toPath().resolve("run/server"))
workingDir(rootProject.projectDir.toPath().resolve("run/server"))
jvmArgs = getRunJVMArgs("1024M", rootProject.projectDir.toPath().resolve("libs/natives"), rootProject.projectDir.toPath().resolve("run/server"))
}
tasks.register('runClient', JavaExec) {
dependsOn rootProject.project("client").tasks.named("createPatches")
dependsOn rootProject.project("server").tasks.named("createPatches")
dependsOn client
mainClass = "net.minecraft.client.Minecraft"
argsString = "Player"
classpath = getLilypadClasspath(
sourceSets.main.runtimeClasspath,
rootProject.projectDir.toPath().resolve("libs").toString(),
shadowJar.destinationDirectory.file("clientLoader.jar").toString()
)
environment("HOME", rootProject.projectDir.toPath().resolve("run/client"))
workingDir(rootProject.projectDir.toPath().resolve("run/client"))
jvmArgs = getRunJVMArgs("1024M", rootProject.projectDir.toPath().resolve("libs/natives"), rootProject.projectDir.toPath().resolve("run/client"))
}