Skip to content

Commit

Permalink
miscellaneous improvements
Browse files Browse the repository at this point in the history
cant believe i spelled miscellaneous right first try
  • Loading branch information
rhysdh540 committed Apr 30, 2024
1 parent 857fe17 commit 3c8faec
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 59 deletions.
Binary file modified api/src/main/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed api/src/main/resources/icon_large.png
Binary file not shown.
32 changes: 30 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import org.objectweb.asm.ClassWriter
import org.objectweb.asm.tree.ClassNode
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import java.time.ZonedDateTime
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream

plugins {
id("java")
Expand Down Expand Up @@ -67,7 +70,7 @@ enum class ReleaseChannel(
}

val isRelease = rootProject.hasProperty("release_channel")
val releaseChannel = if (isRelease) ReleaseChannel.valueOf("release_channel"()) else ReleaseChannel.DEV_BUILD
val releaseChannel = if (isRelease) ReleaseChannel.valueOf("release_channel"().uppercase()) else ReleaseChannel.DEV_BUILD

println("Release Channel: $releaseChannel")

Expand Down Expand Up @@ -338,6 +341,10 @@ tasks.shadowJar {
"TweakClass" to "org.spongepowered.asm.launch.MixinTweaker",
)
}

doLast {
removeDuplicateEntries(archiveFile.get().asFile)
}
}

tasks.assemble {
Expand All @@ -354,7 +361,9 @@ val compressJar = tasks.register<CompressJarTask>("compressJar") {
jarShrinkingType = releaseChannel.deflation
classShrinkingType = releaseChannel.classes
jsonShrinkingType = releaseChannel.json
useProguard(uniminedImpls.flatMap { implName -> project(":$implName").unimined.minecrafts.values })
if(releaseChannel.proguard) {
useProguard(uniminedImpls.flatMap { implName -> project(":$implName").unimined.minecrafts.values })
}
}

afterEvaluate {
Expand Down Expand Up @@ -528,4 +537,23 @@ afterEvaluate {
}
}
}
}

fun removeDuplicateEntries(zip: File) {
val contents = linkedMapOf<String, ByteArray>()
ZipFile(zip).use {
it.entries().asIterator().forEach { entry ->
if(!entry.isDirectory)
contents[entry.name] = it.getInputStream(entry).readAllBytes()
}
}
zip.delete()
ZipOutputStream(zip.outputStream()).use { out ->
contents.forEach { (name, bytes) ->
out.putNextEntry(ZipEntry(name))
out.write(bytes)
out.closeEntry()
}
out.finish()
}
}
74 changes: 26 additions & 48 deletions buildSrc/src/main/kotlin/dev/nolij/zumegradle/JarCompressing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ enum class ClassShrinkingType {
STRIP_ALL,
;

fun shouldStripLVTs() = this == STRIP_LVTS || this == STRIP_ALL
fun shouldStripSourceFiles() = this == STRIP_SOURCE_FILES || this == STRIP_ALL
fun shouldStripLVTs() = this.ordinal % 2 == 1
fun shouldStripSourceFiles() = this.ordinal >= 2
fun shouldRun() = this != STRIP_NONE
}

Expand Down Expand Up @@ -70,7 +70,7 @@ fun squishJar(jar: File, classProcessing: ClassShrinkingType, jsonProcessing: Js
bytes = when (jsonProcessing) {
JsonShrinkingType.MINIFY -> JsonOutput.toJson(json.parse(bytes)).toByteArray()
JsonShrinkingType.PRETTY_PRINT -> JsonOutput.prettyPrint(JsonOutput.toJson(json.parse(bytes))).toByteArray()
else -> bytes
else -> throw AssertionError()
}
}

Expand All @@ -83,7 +83,6 @@ fun squishJar(jar: File, classProcessing: ClassShrinkingType, jsonProcessing: Js
out.closeEntry()
}
out.finish()
out.close()
}
}

Expand Down Expand Up @@ -138,43 +137,22 @@ fun deflate(zip: File, type: JarShrinkingType) {
val JAVA_HOME = System.getProperty("java.home")

@Suppress("UnstableApiUsage")
fun applyProguard(outputJar: File, minecraftConfigs: List<MinecraftConfig>) {
val inputJar = outputJar.copyTo(
outputJar.parentFile.resolve("${outputJar.nameWithoutExtension}_.jar"), true)
inputJar.deleteOnExit()
fun applyProguard(jar: File, minecraftConfigs: List<MinecraftConfig>, configDir: File) {
val inputJar = jar.copyTo(
jar.parentFile.resolve("${jar.nameWithoutExtension}_.jar"), true).also {
it.deleteOnExit()
}

val proguardCommand = ArrayList<String>()
proguardCommand.addAll(arrayOf(
"-ignorewarnings", "-dontnote",
"-optimizationpasses", "10",
"-optimizations", "!class/merging/*,!method/marking/private",
"-allowaccessmodification",
"-optimizeaggressively",
"-overloadaggressively",
"-repackageclasses", "dev.nolij.zume",
"-printmapping", outputJar.parentFile.resolve("${outputJar.nameWithoutExtension}-mappings.txt").absolutePath,
val config = configDir.resolve("proguard.pro")
if (!config.exists()) {
error("proguard.pro not found")
}
val proguardCommand = mutableListOf(
"@${config.absolutePath}",
"-printmapping", jar.parentFile.resolve("${jar.nameWithoutExtension}-mappings.txt").absolutePath,
"-injars", inputJar.absolutePath,
"-outjars", outputJar.absolutePath,
"-keepattributes", "Runtime*Annotations", // keep annotations
"-keep,allowoptimization", "public class dev.nolij.zume.api.** { public *; }", // public APIs
"-keepclassmembers", "class dev.nolij.zume.impl.config.ZumeConfigImpl { public <fields>; }", // dont rename config fields
"-keep,allowoptimization", "class dev.nolij.zume.ZumeMixinPlugin", // dont rename mixin plugin
"-keep", "class dev.nolij.zume.mixin.** { *; }", // dont touch mixins
"-keep,allowobfuscation,allowoptimization", "@*.*.fml.common.Mod class dev.nolij.zume.** { " + // Forge entrypoints
"public <init>(...); " +
"@*.*.fml.common.Mod\$EventHandler <methods>; " +
"@*.*.fml.common.eventhandler.SubscribeEvent <methods>; }",
"-keepclassmembers,allowoptimization", "class dev.nolij.zume.** { " + // screens
"public void render(int,int,float); " +
"public void tick(); " +
"public void init(); }",
"-keepclassmembers,allowoptimization", "class dev.nolij.zume.** extends net.minecraft.client.gui.screens.Screen { public *; }",
"-keep,allowoptimization", "class dev.nolij.zume.** implements *.*.fml.client.IModGuiFactory", // Legacy Forge config providers
"-keep,allowoptimization", "class dev.nolij.zume.FabricZumeBootstrapper", // referenced in FMJ
"-keep,allowoptimization", "class dev.nolij.zume.modern.integration.ZumeModMenuIntegration", // referenced in FMJ
"-keep,allowoptimization", "class dev.nolij.zume.primitive.event.KeyBindingRegistrar { public *; }", // referenced in FMJ
"-keep,allowoptimization", "class io.github.prospector.modmenu.** { *; }", // ugly classloader hack
))
"-outjars", jar.absolutePath,
)

val libraries = HashSet<String>()
libraries.add("${JAVA_HOME}/jmods/java.base.jmod")
Expand Down Expand Up @@ -205,7 +183,7 @@ fun applyProguard(outputJar: File, minecraftConfigs: List<MinecraftConfig>) {
try {
ProGuard(configuration).execute()
} catch(ex: Exception) {
throw IllegalStateException("ProGuard failed for $outputJar", ex)
throw IllegalStateException("ProGuard failed for $jar", ex)
} finally {
inputJar.delete()
}
Expand All @@ -217,6 +195,7 @@ open class CompressJarTask : DefaultTask() {

@Input
var classShrinkingType = ClassShrinkingType.STRIP_ALL
get() = if (useProguard) ClassShrinkingType.STRIP_NONE else field

@Input
var jarShrinkingType = JarShrinkingType.LIBDEFLATE
Expand All @@ -225,13 +204,12 @@ open class CompressJarTask : DefaultTask() {
var jsonShrinkingType = JsonShrinkingType.NONE

@get:Input
val useProguard get() = this.minecraftConfigs != null
val useProguard get() = !this.minecraftConfigs.isEmpty()

private var minecraftConfigs: List<MinecraftConfig>? = null
private var minecraftConfigs: List<MinecraftConfig> = emptyList()

@get:OutputFile
val outputJar: File
get() = inputJar // compressed jar will replace the input jar
val outputJar get() = inputJar // compressed jar will replace the input jar

@Option(option = "class-file-compression", description = "How to process class files")
fun setClassShrinkingType(value: String) {
Expand All @@ -242,7 +220,7 @@ open class CompressJarTask : DefaultTask() {
fun setJarShrinkingType(value: String) {
jarShrinkingType = value.uppercase().let {
if(it.matches(Regex("7Z(?:IP)?"))) JarShrinkingType.SEVENZIP
else JarShrinkingType.valueOf(it.uppercase())
else JarShrinkingType.valueOf(it)
}
}

Expand All @@ -251,15 +229,15 @@ open class CompressJarTask : DefaultTask() {
jsonShrinkingType = JsonShrinkingType.valueOf(value.uppercase())
}

fun useProguard(minecraftConfigs: List<MinecraftConfig>?) {
fun useProguard(minecraftConfigs: List<MinecraftConfig>) {
this.minecraftConfigs = minecraftConfigs
}

@TaskAction
fun compressJar() {
if (useProguard)
applyProguard(inputJar, minecraftConfigs, project.rootDir)
squishJar(inputJar, classShrinkingType, jsonShrinkingType)
deflate(outputJar, jarShrinkingType)
if (useProguard)
applyProguard(outputJar, minecraftConfigs!!)
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ vintage_forge_version = 14.23.5.2860
mixinbooter_version = 9.1

# Misc Dependencies
# https://central.sonatype.com/artifact/com.github.bsideup.jabel/jabel-javac-plugin
# https://central.sonatype.com/artifact/com.pkware.jabel/jabel-javac-plugin
jabel_version = 1.0.1-1
# https://central.sonatype.com/artifact/blue.endless/jankson/overview
jankson_version = 1.2.3
Expand Down
Binary file modified icon_padded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icon_padded_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lexforge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modId="zume"
version="${mod_version}"
displayName="${mod_name}"
displayURL="${mod_url}"
logoFile="icon_large.png"
logoFile="icon.png"
authors="${nolij}"
description="""
${mod_description}
Expand Down
2 changes: 1 addition & 1 deletion lexforge16/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modId="zume"
version="${mod_version}"
displayName="${mod_name}"
displayURL="${mod_url}"
logoFile="icon_large.png"
logoFile="icon.png"
authors="${nolij}"
description="""
${mod_description}
Expand Down
2 changes: 1 addition & 1 deletion lexforge18/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modId="zume"
version="${mod_version}"
displayName="${mod_name}"
displayURL="${mod_url}"
logoFile="icon_large.png"
logoFile="icon.png"
authors="${nolij}"
description="""
${mod_description}
Expand Down
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modId="zume"
version="${mod_version}"
displayName="${mod_name}"
displayURL="${mod_url}"
logoFile="icon_large.png"
logoFile="icon.png"
authors="${nolij}"
description="""
${mod_description}
Expand Down
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modId="zume"
version="${mod_version}"
displayName="${mod_name}"
displayURL="${mod_url}"
logoFile="icon_large.png"
logoFile="icon.png"
authors="${nolij}"
description="""
${mod_description}
Expand Down
36 changes: 36 additions & 0 deletions proguard.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-ignorewarnings
-dontnote
-optimizationpasses 10
-optimizations !class/merging/*,!method/marking/private
-allowaccessmodification
#noinspection ShrinkerInvalidFlags
-optimizeaggressively
-overloadaggressively
-repackageclasses dev.nolij.zume
-keepattributes RuntimeVisibleAnnotations # keep annotations

-keep,allowoptimization public class dev.nolij.zume.api.** { public *; } # public APIs
-keepclassmembers class dev.nolij.zume.impl.config.ZumeConfigImpl { public <fields>; } # dont rename config fields
-keep,allowoptimization class dev.nolij.zume.ZumeMixinPlugin # dont rename mixin plugin
-keep class dev.nolij.zume.mixin.** { *; } # dont touch mixins

-keep,allowobfuscation,allowoptimization @*.*.fml.common.Mod class dev.nolij.zume.** { # Forge entrypoints
public <init>(...);
@*.*.fml.common.Mod$EventHandler <methods>;
@*.*.fml.common.eventhandler.SubscribeEvent <methods>;
}
-keep,allowoptimization class dev.nolij.zume.** implements *.*.fml.client.IModGuiFactory # Legacy Forge config providers

-keepclassmembers,allowoptimization class dev.nolij.zume.** { # screens
public void render(int,int,float);
public void tick();
public void init();
}
-keepclassmembers,allowoptimization class dev.nolij.zume.** extends net.minecraft.client.gui.screens.Screen { public *; }

-keep,allowoptimization class io.github.prospector.modmenu.** { *; } # ugly classloader hack

# Fabric entrypoints
-keep,allowoptimization class dev.nolij.zume.FabricZumeBootstrapper
-keep,allowoptimization class dev.nolij.zume.modern.integration.ZumeModMenuIntegration
-keep,allowoptimization class dev.nolij.zume.primitive.event.KeyBindingRegistrar { public *; }
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modId="zume"
version="${mod_version}"
displayName="${mod_name}"
displayURL="${mod_url}"
logoFile="icon_large.png"
logoFile="icon.png"
authors="${nolij}"
description="""
${mod_description}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"updateUrl": "",
"authorList": ["${nolij}"],
"credits": "",
"logoFile": "icon_large.png",
"logoFile": "icon.png",
"screenshots": [],
"dependencies": []
}
Expand Down
2 changes: 1 addition & 1 deletion vintage/src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"updateUrl": "",
"authorList": ["${nolij}"],
"credits": "",
"logoFile": "icon_large.png",
"logoFile": "icon.png",
"screenshots": [],
"dependencies": []
}
Expand Down

0 comments on commit 3c8faec

Please sign in to comment.