1
+ import com.google.common.collect.ImmutableList
2
+ import com.google.common.collect.ImmutableMap
3
+ import org.objectweb.asm.ClassReader
4
+ import org.objectweb.asm.ClassWriter
5
+ import org.objectweb.asm.tree.ClassNode
6
+ import org.objectweb.asm.tree.LdcInsnNode
7
+
1
8
apply(plugin : " maven-publish" )
2
9
apply(plugin : " fabric-loom" )
3
- apply(plugin : " io.github.juuxel.loom-quiltflower" )
4
- apply(plugin : " net.kyori.blossom" )
10
+ apply(plugin : " io.github.juuxel.loom-vineflower" )
5
11
apply(plugin : " com.replaymod.preprocess" )
6
12
7
13
int mcVersion = 1
@@ -200,12 +206,6 @@ processResources {
200
206
}
201
207
}
202
208
203
- blossom {
204
- replaceToken(" @MOD_IDENTIFIER@" , project. mod_id)
205
- replaceToken(" @MOD_NAME@" , project. mod_name)
206
- replaceToken(" @MINECRAFT_VERSION_IDENTIFY@" , project. minecraft_version. replace(" ." , " _" ))
207
- }
208
-
209
209
java {
210
210
sourceCompatibility(JavaVersion . VERSION_1_8 )
211
211
targetCompatibility(JavaVersion . VERSION_1_8 )
@@ -232,3 +232,64 @@ publishing {
232
232
}
233
233
}
234
234
}
235
+
236
+ ImmutableMap<Object , Object > replaceTokenMap = ImmutableMap . builder()
237
+ .put(" @MOD_IDENTIFIER@" , project. mod_id)
238
+ .put(" @MOD_NAME@" , project. mod_name)
239
+ .put(" @MINECRAFT_VERSION_IDENTIFY@" , project. minecraft_version. replace(" ." , " _" ))
240
+ .build()
241
+ ImmutableList<Object > replaceTokenFile = ImmutableList . builder()
242
+ .add(" OhMyMinecraftClientReference" )
243
+ .build()
244
+
245
+ tasks. classes {
246
+ doLast {
247
+ File dir = file(" build/classes/java" )
248
+
249
+ dir. eachFileRecurse {
250
+ String path = it. path. replace(dir. path, " " )
251
+
252
+ if (path. endsWith(" .class" ) && replaceTokenFile. stream(). anyMatch { path. contains(it as String ) }) {
253
+ ClassReader cr = new ClassReader (it. newInputStream(). bytes)
254
+ ClassNode cn = new ClassNode ()
255
+ cr. accept(cn, ClassReader . SKIP_FRAMES | ClassReader . SKIP_DEBUG )
256
+
257
+ // ReplaceToken in fields
258
+ cn. fields. each {
259
+ if (it. desc == " Ljava/lang/String;" && it. value instanceof String ) {
260
+ String value = it. value as String
261
+
262
+ replaceTokenMap. each {
263
+ value = value. replace(it. key as String , it. value as String )
264
+ }
265
+
266
+ it. value = value
267
+ }
268
+ }
269
+
270
+ // ReplaceToken in methods
271
+ cn. methods. each {
272
+ it. instructions. each {
273
+ if (it instanceof LdcInsnNode ) {
274
+ LdcInsnNode ldc = it as LdcInsnNode
275
+
276
+ if (ldc. cst instanceof String ) {
277
+ String value = ldc. cst as String
278
+
279
+ replaceTokenMap. each {
280
+ value = value. replace(it. key as String , it. value as String )
281
+ }
282
+
283
+ ldc. cst = value
284
+ }
285
+ }
286
+ }
287
+ }
288
+
289
+ ClassWriter cw = new ClassWriter (ClassWriter . COMPUTE_FRAMES )
290
+ cn. accept(cw)
291
+ new FileOutputStream (it). write(cw. toByteArray())
292
+ }
293
+ }
294
+ }
295
+ }
0 commit comments