diff --git a/api/src/main/resources/icon.png b/api/src/main/resources/icon.png index a8c0d3cd..9463d529 100644 Binary files a/api/src/main/resources/icon.png and b/api/src/main/resources/icon.png differ diff --git a/api/src/main/resources/icon_large.png b/api/src/main/resources/icon_large.png deleted file mode 100644 index 9463d529..00000000 Binary files a/api/src/main/resources/icon_large.png and /dev/null differ diff --git a/build.gradle.kts b/build.gradle.kts index becde301..c4c1a9d4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") @@ -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") @@ -338,6 +341,10 @@ tasks.shadowJar { "TweakClass" to "org.spongepowered.asm.launch.MixinTweaker", ) } + + doLast { + removeDuplicateEntries(archiveFile.get().asFile) + } } tasks.assemble { @@ -354,7 +361,9 @@ val compressJar = tasks.register("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 { @@ -528,4 +537,23 @@ afterEvaluate { } } } +} + +fun removeDuplicateEntries(zip: File) { + val contents = linkedMapOf() + 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() + } } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/dev/nolij/zumegradle/JarCompressing.kt b/buildSrc/src/main/kotlin/dev/nolij/zumegradle/JarCompressing.kt index 0a9dfdc0..d80147b4 100644 --- a/buildSrc/src/main/kotlin/dev/nolij/zumegradle/JarCompressing.kt +++ b/buildSrc/src/main/kotlin/dev/nolij/zumegradle/JarCompressing.kt @@ -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 } @@ -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() } } @@ -83,7 +83,6 @@ fun squishJar(jar: File, classProcessing: ClassShrinkingType, jsonProcessing: Js out.closeEntry() } out.finish() - out.close() } } @@ -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) { - val inputJar = outputJar.copyTo( - outputJar.parentFile.resolve("${outputJar.nameWithoutExtension}_.jar"), true) - inputJar.deleteOnExit() +fun applyProguard(jar: File, minecraftConfigs: List, configDir: File) { + val inputJar = jar.copyTo( + jar.parentFile.resolve("${jar.nameWithoutExtension}_.jar"), true).also { + it.deleteOnExit() + } - val proguardCommand = ArrayList() - 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 ; }", // 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 (...); " + - "@*.*.fml.common.Mod\$EventHandler ; " + - "@*.*.fml.common.eventhandler.SubscribeEvent ; }", - "-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() libraries.add("${JAVA_HOME}/jmods/java.base.jmod") @@ -205,7 +183,7 @@ fun applyProguard(outputJar: File, minecraftConfigs: List) { try { ProGuard(configuration).execute() } catch(ex: Exception) { - throw IllegalStateException("ProGuard failed for $outputJar", ex) + throw IllegalStateException("ProGuard failed for $jar", ex) } finally { inputJar.delete() } @@ -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 @@ -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? = null + private var minecraftConfigs: List = 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) { @@ -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) } } @@ -251,15 +229,15 @@ open class CompressJarTask : DefaultTask() { jsonShrinkingType = JsonShrinkingType.valueOf(value.uppercase()) } - fun useProguard(minecraftConfigs: List?) { + fun useProguard(minecraftConfigs: List) { 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!!) } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c9b57e7b..4534c968 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/icon_padded.png b/icon_padded.png index 5da40b05..94bf1616 100644 Binary files a/icon_padded.png and b/icon_padded.png differ diff --git a/icon_padded_large.png b/icon_padded_large.png index 1c458368..249b149b 100644 Binary files a/icon_padded_large.png and b/icon_padded_large.png differ diff --git a/lexforge/src/main/resources/META-INF/mods.toml b/lexforge/src/main/resources/META-INF/mods.toml index 040d2b02..afad0e5c 100644 --- a/lexforge/src/main/resources/META-INF/mods.toml +++ b/lexforge/src/main/resources/META-INF/mods.toml @@ -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} diff --git a/lexforge16/src/main/resources/META-INF/mods.toml b/lexforge16/src/main/resources/META-INF/mods.toml index ea84fa07..fdd919bb 100644 --- a/lexforge16/src/main/resources/META-INF/mods.toml +++ b/lexforge16/src/main/resources/META-INF/mods.toml @@ -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} diff --git a/lexforge18/src/main/resources/META-INF/mods.toml b/lexforge18/src/main/resources/META-INF/mods.toml index 10cc4ff2..f6100037 100644 --- a/lexforge18/src/main/resources/META-INF/mods.toml +++ b/lexforge18/src/main/resources/META-INF/mods.toml @@ -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} diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml index 0a4d0765..2988beec 100644 --- a/neoforge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -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} diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 0a4d0765..2988beec 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -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} diff --git a/proguard.pro b/proguard.pro new file mode 100644 index 00000000..f9c12822 --- /dev/null +++ b/proguard.pro @@ -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 ; } # 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 (...); + @*.*.fml.common.Mod$EventHandler ; + @*.*.fml.common.eventhandler.SubscribeEvent ; +} +-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 *; } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 495ef8c3..9985b1a9 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -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} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index f35cd8c3..b0f2e339 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -9,7 +9,7 @@ "updateUrl": "", "authorList": ["${nolij}"], "credits": "", - "logoFile": "icon_large.png", + "logoFile": "icon.png", "screenshots": [], "dependencies": [] } diff --git a/vintage/src/main/resources/mcmod.info b/vintage/src/main/resources/mcmod.info index 17251517..8586a830 100644 --- a/vintage/src/main/resources/mcmod.info +++ b/vintage/src/main/resources/mcmod.info @@ -9,7 +9,7 @@ "updateUrl": "", "authorList": ["${nolij}"], "credits": "", - "logoFile": "icon_large.png", + "logoFile": "icon.png", "screenshots": [], "dependencies": [] }