forked from bornato/fitmclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
202 lines (165 loc) · 6.98 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
193
194
195
196
197
198
199
200
201
202
import java.util.jar.JarFile
plugins {
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '6.0.0'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name
version = project.mod_version + (System.getenv("CIRCLE_BUILD_NUM") != null ? ("-" + System.getenv("CIRCLE_BUILD_NUM")) : "")
group = project.maven_group
minecraft {
accessWidener "src/main/resources/meteor-client.accesswidener"
}
repositories {
maven { url "https://jitpack.io" }
jcenter()
}
dependencies {
def dependency = { id ->
implementation id
shadow id
}
// Minecraft
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// For XRay compatibility
modImplementation "com.github.jellysquid3:sodium-fabric:1.16.x~stable-SNAPSHOT"
// Baritone
modImplementation("com.gitlab.CDAGaming:fabritone:fabric~1.16.3-SNAPSHOT") {
exclude(group: "org.lwjgl.lwjgl", module: "lwjgl-platform")
exclude(group: "org.lwjgl.lwjgl", module: "lwjgl")
exclude(group: "net.java.jinput", module: "jinput-platform")
exclude(group: "net.java.jinput", module: "jinput")
exclude(group: "net.sf.jopt-simple", module: "jopt-simple")
exclude(group: "org.ow2.asm", module: "asm-debug-all")
}
include "com.gitlab.CDAGaming:fabritone:fabric~1.16.3-SNAPSHOT"
// Other dependencies
dependency "com.github.MeteorDevelopment:orbit:0.1.5"
dependency "com.g00fy2:versioncompare:1.3.7"
dependency "com.github.minndevelopment:java-discordrpc:2.0.2"
}
shadowJar {
configurations = [ project.configurations.shadow ]
}
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
filter { line -> line.replace("@devbuild@", System.getenv("CIRCLE_BUILD_NUM") != null ? System.getenv("CIRCLE_BUILD_NUM") : "") }
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}
task generatePacketUtils() {
doLast {
// Get minecraft jar file
def mc = ""
def dir = new File(".gradle/loom-cache/${project.minecraft_version}-projectmapped-net.fabricmc.yarn-${project.yarn_mappings}-v2")
for (def file in dir.listFiles()) {
if (file.name.contains("minecraft") && file.name.contains("mapped") && file.name.endsWith((String) project.yarn_mappings + "-v2.jar")) {
mc = file.absolutePath
break
}
}
// Get packets
def s2cPackets = []
def c2sPackets = []
def file = new JarFile(mc)
for (entry in file.entries()) {
if (entry.name.endsWith("S2CPacket.class")) s2cPackets << entry.name.substring(0, entry.name.length() - 6)
else if (entry.name.endsWith("C2SPacket.class")) c2sPackets << entry.name.substring(0, entry.name.length() - 6)
}
// Generate PacketUtils.java
def writer = new File("src/main/java/minegame159/meteorclient/utils/network/PacketUtils.java").newWriter()
writer << "package minegame159.meteorclient.utils.network;\n\n"
// Write imports
writer << "import net.minecraft.network.Packet;\n"
writer << "import java.util.Map;\n"
writer << "import java.util.HashMap;\n"
writer << "import java.util.Set;\n"
// Write class
writer << "\npublic class PacketUtils {\n"
// Write fields
writer << " private static final Map<Class<? extends Packet<?>>, String> S2C_PACKETS = new HashMap<>();\n"
writer << " private static final Map<Class<? extends Packet<?>>, String> C2S_PACKETS = new HashMap<>();\n\n"
writer << " private static final Map<String, Class<? extends Packet<?>>> S2C_PACKETS_R = new HashMap<>();\n"
writer << " private static final Map<String, Class<? extends Packet<?>>> C2S_PACKETS_R = new HashMap<>();\n\n"
// Write static block
writer << " static {\n"
s2cPackets.each { def packet = (String) it; def name = packet.substring(packet.lastIndexOf("/") + 1); writer << " S2C_PACKETS.put(${packet.replace("/", ".")}.class, \"$name\");\n" }
writer << "\n"
c2sPackets.each { def packet = (String) it; def name = packet.substring(packet.lastIndexOf("/") + 1); writer << " C2S_PACKETS.put(${packet.replace("/", ".")}.class, \"$name\");\n" }
writer << "\n\n"
s2cPackets.each { def packet = (String) it; def name = packet.substring(packet.lastIndexOf("/") + 1); writer << " S2C_PACKETS_R.put(\"$name\", ${packet.replace("/", ".")}.class);\n" }
writer << "\n"
c2sPackets.each { def packet = (String) it; def name = packet.substring(packet.lastIndexOf("/") + 1); writer << " C2S_PACKETS_R.put(\"$name\", ${packet.replace("/", ".")}.class);\n" }
writer << " }\n\n"
// Write getName method
writer << " public static String getName(Class<? extends Packet<?>> packetClass) {\n"
writer << " String name = S2C_PACKETS.get(packetClass);\n"
writer << " if (name != null) return name;\n"
writer << " return C2S_PACKETS.get(packetClass);\n"
writer << " }\n\n"
// Write getPacket method
writer << " public static Class<? extends Packet<?>> getPacket(String name) {\n"
writer << " Class<? extends Packet<?>> packet = S2C_PACKETS_R.get(name);\n"
writer << " if (packet != null) return packet;\n"
writer << " return C2S_PACKETS_R.get(name);\n"
writer << " }\n\n"
// Write getS2CPackets method
writer << " public static Set<Class<? extends Packet<?>>> getS2CPackets() {\n"
writer << " return S2C_PACKETS.keySet();\n"
writer << " }\n\n"
// Write getC2SPackets method
writer << " public static Set<Class<? extends Packet<?>>> getC2SPackets() {\n"
writer << " return C2S_PACKETS.keySet();\n"
writer << " }\n"
// Write end class
writer << "}\n"
writer.close()
}
}
jar {
from "LICENSE"
manifest {
attributes("Main-Class": "minegame159.meteorclient.Main")
}
}
remapJar {
dependsOn shadowJar
input.set(shadowJar.archiveFile)
}
publishing {
publications {
maven(MavenPublication) {
artifact ("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar") {
classifier null
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
}