diff --git a/build.gradle.kts b/build.gradle.kts index ec62673..8ae89bf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,13 @@ import groovy.json.JsonOutput import groovy.json.JsonSlurper +import org.gradle.internal.xml.XmlTransformer +import org.gradle.plugins.ide.idea.model.IdeaProject +import org.jetbrains.gradle.ext.Gradle +import org.jetbrains.gradle.ext.GradleTask +import org.jetbrains.gradle.ext.RunConfiguration +import org.jetbrains.gradle.ext.runConfigurations +import org.jetbrains.gradle.ext.settings import proguard.ConfigurationParser import proguard.ProGuard import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask @@ -10,6 +17,7 @@ import xyz.wagyourtail.unimined.internal.minecraft.task.RemapJarTaskImpl import xyz.wagyourtail.unimined.util.OSUtils import xyz.wagyourtail.unimined.util.sourceSets import xyz.wagyourtail.gradle.shadow.ShadowJar +import xyz.wagyourtail.unimined.util.capitalized import java.util.jar.JarEntry import java.util.jar.JarInputStream import java.util.jar.JarOutputStream @@ -19,16 +27,20 @@ plugins { id("java") id("idea") id("xyz.wagyourtail.unimined") + id("org.jetbrains.gradle.plugin.idea-ext") id("xyz.wagyourtail.unimined.expect-platform") } setup() allprojects { - apply(plugin = "java") - apply(plugin = "idea") - apply(plugin = "xyz.wagyourtail.unimined") - apply(plugin = "xyz.wagyourtail.unimined.expect-platform") + apply { + plugin("java") + plugin("idea") + plugin("xyz.wagyourtail.unimined") + plugin("org.jetbrains.gradle.plugin.idea-ext") + plugin("xyz.wagyourtail.unimined.expect-platform") + } base.archivesName.set("archives_base_name"()) version = "modVersion"() @@ -38,19 +50,13 @@ allprojects { toolchain { languageVersion.set(JavaLanguageVersion.of("java_version"())) } - - sourceCompatibility = JavaVersion.toVersion("java_version"()) - targetCompatibility = JavaVersion.toVersion("java_version"()) } - idea.module.setDownloadSources(true) + idea { + module.isDownloadSources = true + } repositories { - mavenCentral { - content { - excludeGroup("ca.weblite") - } - } unimined.parchmentMaven() exclusiveContent { forRepository { maven("https://api.modrinth.com/maven") } @@ -336,7 +342,7 @@ val compressJar = tasks.register("compressJar") { } tasks.assemble { - dependsOn(mergeJars) + dependsOn(mergeJars, compressJar) } fun setup() { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 3c14e87..e374d1c 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -41,5 +41,6 @@ dependencies { implementation("com.guardsquare:proguard-base:${"proguard_version"()}") plugin(id = "xyz.wagyourtail.unimined", version = "unimined_version"()) + plugin(id = "org.jetbrains.gradle.plugin.idea-ext", version = "idea_ext_version"()) plugin(id = "xyz.wagyourtail.unimined.expect-platform", version = "expectplatform_version"()) } diff --git a/buildSrc/src/main/kotlin/Compressors.kt b/buildSrc/src/main/kotlin/Compressors.kt index 7c18d34..54fe782 100644 --- a/buildSrc/src/main/kotlin/Compressors.kt +++ b/buildSrc/src/main/kotlin/Compressors.kt @@ -9,7 +9,8 @@ import java.util.zip.Deflater object Compressors { // minify json val json: FileProcessor = { - it.outputStream().write(JsonOutput.toJson(JsonSlurper().parse(it)).toByteArray()) + val minifed = JsonOutput.toJson(JsonSlurper().parse(it.readText().toCharArray())).toByteArray() + it.writeBytes(minifed) } // store JIJs instead of deflating them so that the outer jar compresses the entire thing (most of the time better) diff --git a/buildSrc/src/main/kotlin/ProcessJar.kt b/buildSrc/src/main/kotlin/ProcessJar.kt index feffed1..ff4d227 100644 --- a/buildSrc/src/main/kotlin/ProcessJar.kt +++ b/buildSrc/src/main/kotlin/ProcessJar.kt @@ -1,6 +1,8 @@ import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.ListProperty +import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Internal import org.gradle.jvm.tasks.Jar import java.io.File import java.util.jar.JarEntry @@ -10,9 +12,10 @@ import java.util.zip.Deflater typealias FileProcessor = (File) -> Unit abstract class ProcessJar : Jar() { + @get:InputFile abstract val input: RegularFileProperty - @InputFile get + @get:Internal abstract val processors: ListProperty init { @@ -36,9 +39,9 @@ abstract class ProcessJar : Jar() { } } - fun addFileProcessor(extensions: Iterable = emptySet(), - names: Iterable = emptySet(), - paths: Iterable = emptySet(), + fun addFileProcessor(extensions: Set = emptySet(), + names: Set = emptySet(), + paths: Set = emptySet(), processor: FileProcessor) { processors.add { it.walkTopDown().forEach { file -> diff --git a/buildSrc/src/main/kotlin/git.kt b/buildSrc/src/main/kotlin/git.kt index 56fe6a6..8e5ca65 100644 --- a/buildSrc/src/main/kotlin/git.kt +++ b/buildSrc/src/main/kotlin/git.kt @@ -11,7 +11,11 @@ class Git(val repository: File) { fun isDirty() = git("status", "--porcelain").isNotBlank() // last commit hash - fun hash() = git("rev-parse", "--short", "HEAD").trim() + fun hash(long: Boolean = false) = + if(long) + git("rev-parse", "HEAD").trim() + else + git("rev-parse", "--short", "HEAD").trim() // current branch fun currentBranch() = git("rev-parse", "--abbrev-ref", "HEAD").trim() diff --git a/gradle.properties b/gradle.properties index 7406e90..e6842f3 100755 --- a/gradle.properties +++ b/gradle.properties @@ -10,12 +10,13 @@ mixin.debug = true git_max_changes = 10 # gradle plugin versions -unimined_version = 1.3.3 +unimined_version = 1.3.4 +idea_ext_version = 1.1.8 expectplatform_version = 1.0.5 proguard_version = 7.5.0 # the mc version to compile against (see their respective property files for version-specific stuff) -mcVer = 1.19.2 +mcVer = 1.20.1 minimum_create_version = 0.5.1 # the actual stuff diff --git a/proguard.pro b/proguard.pro index 9a67fc8..e811af3 100644 --- a/proguard.pro +++ b/proguard.pro @@ -13,12 +13,19 @@ @org.spongepowered.asm.mixin.Shadow *; } +-keep,allowoptimization class * extends java.lang.Enum { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + -keep,allowoptimization @*.*.fml.common.Mod class * { public (...); } -keep,allowoptimization class * implements net.fabricmc.api.ModInitializer - -keep,allowoptimization class * implements com.terraformersmc.modmenu.api.ModMenuApi +-keep,allowoptimization class * implements org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin --keep,allowoptimization class * implements org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin \ No newline at end of file +-keepclassmembers,allowoptimization class dev.rdh.createunlimited.*.config.PlacementCheck { + boolean isEnabledFor(***); # accessed in asm +} \ No newline at end of file diff --git a/src/main/java/dev/rdh/createunlimited/asm/Asm.java b/src/main/java/dev/rdh/createunlimited/asm/Asm.java index c9328ab..91787cb 100644 --- a/src/main/java/dev/rdh/createunlimited/asm/Asm.java +++ b/src/main/java/dev/rdh/createunlimited/asm/Asm.java @@ -6,7 +6,7 @@ import dev.rdh.createunlimited.Util; import dev.rdh.createunlimited.config.CUConfigs; import dev.rdh.createunlimited.config.CUServer; -import dev.rdh.createunlimited.config.CUServer.PlacementCheck; +import dev.rdh.createunlimited.config.PlacementCheck; import com.simibubi.create.foundation.config.ConfigBase.CValue; import com.simibubi.create.foundation.config.ConfigBase.ConfigEnum; @@ -42,9 +42,9 @@ public static void instrumentTrackPlacement(ClassNode targetClass) { GETFIELD dev/rdh/createunlimited/config/CUServer.placementChecks : Lcom/simibubi/create/foundation/config/ConfigBase$ConfigEnum; GETSTATIC com/simibubi/create/foundation/utility/PlacementCheck.ON : Lcom/simibubi/create/foundation/utility/PlacementCheck; INVOKESTATIC dev/rdh/createunlimited/Util.orElse (Lcom/simibubi/create/foundation/config/ConfigBase$CValue;Ljava/lang/Object;)Ljava/lang/Object; - CHECKCAST dev/rdh/createunlimited/config/CUServer$PlacementCheck; + CHECKCAST dev/rdh/createunlimited/config/PlacementCheck; ALOAD 1 - INVOKEVIRTUAL dev/rdh/createunlimited/config/CUServer$PlacementCheck.isEnabledFor (Lnet/minecraft/world/entity/player/Player;)Z + INVOKEVIRTUAL dev/rdh/createunlimited/config/PlacementCheck.isEnabledFor (Lnet/minecraft/world/entity/player/Player;)Z ISTORE [lvtIndex] */ diff --git a/src/main/java/dev/rdh/createunlimited/asm/mixin/glue/SuperGlueSelectionHelperMixin.java b/src/main/java/dev/rdh/createunlimited/asm/mixin/glue/SuperGlueSelectionHelperMixin.java index 1a0c0fb..1670dee 100644 --- a/src/main/java/dev/rdh/createunlimited/asm/mixin/glue/SuperGlueSelectionHelperMixin.java +++ b/src/main/java/dev/rdh/createunlimited/asm/mixin/glue/SuperGlueSelectionHelperMixin.java @@ -34,7 +34,7 @@ public static Set searchGlueGroup(Level level, BlockPos startPos, Bloc for(double posx = bb.minX; posx <= bb.maxX; posx++) { for(double posy = bb.minY; posy <= bb.maxY; posy++) { for(double posz = bb.minZ; posz <= bb.maxZ; posz++) { - BlockPos pos = new BlockPos(posx, posy, posz); + BlockPos pos = new BlockPos((int) posx, (int) posy, (int) posz); Block block = level.getBlockState(pos).getBlock(); if(block != Blocks.AIR && block != Blocks.WATER) { diff --git a/src/main/java/dev/rdh/createunlimited/config/CUServer.java b/src/main/java/dev/rdh/createunlimited/config/CUServer.java index 116045d..ff5c6c0 100644 --- a/src/main/java/dev/rdh/createunlimited/config/CUServer.java +++ b/src/main/java/dev/rdh/createunlimited/config/CUServer.java @@ -4,12 +4,6 @@ import dev.rdh.createunlimited.CreateUnlimited; -import net.minecraft.world.entity.player.Player; - -import java.util.function.Predicate; - -import static com.google.common.base.Predicates.*; - @SuppressWarnings("unused") // groups are used as markers for the screen and command public class CUServer extends ConfigBase { @Override @@ -66,19 +60,4 @@ public static String getComment(String name) { return "No comment."; } } - - public enum PlacementCheck { - ON(alwaysTrue()), - SURVIVAL_ONLY(not(Player::isCreative)), - OFF(alwaysFalse()); - - final Predicate enabled; - - PlacementCheck(Predicate enabled) { - this.enabled = enabled; - } - public boolean isEnabledFor(Player player) { - return enabled.test(player); - } - } } diff --git a/src/main/java/dev/rdh/createunlimited/config/PlacementCheck.java b/src/main/java/dev/rdh/createunlimited/config/PlacementCheck.java new file mode 100644 index 0000000..759a7d2 --- /dev/null +++ b/src/main/java/dev/rdh/createunlimited/config/PlacementCheck.java @@ -0,0 +1,23 @@ +package dev.rdh.createunlimited.config; + +import net.minecraft.world.entity.player.Player; + +import java.util.function.Predicate; + +import static com.google.common.base.Predicates.*; + +public enum PlacementCheck { + ON(alwaysTrue()), + SURVIVAL_ONLY(not(Player::isCreative)), + OFF(alwaysFalse()); + + final Predicate enabled; + + PlacementCheck(Predicate enabled) { + this.enabled = enabled; + } + + public boolean isEnabledFor(Player player) { + return enabled.test(player); + } +}