Skip to content

Commit

Permalink
a bunch of small fixes
Browse files Browse the repository at this point in the history
trying to get glue working
  • Loading branch information
rhysdh540 committed Aug 4, 2024
1 parent bf27dd0 commit a24191e
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 49 deletions.
34 changes: 20 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"()
Expand All @@ -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") }
Expand Down Expand Up @@ -336,7 +342,7 @@ val compressJar = tasks.register<ProcessJar>("compressJar") {
}

tasks.assemble {
dependsOn(mergeJars)
dependsOn(mergeJars, compressJar)
}

fun setup() {
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"())
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Compressors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions buildSrc/src/main/kotlin/ProcessJar.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<FileProcessor>

init {
Expand All @@ -36,9 +39,9 @@ abstract class ProcessJar : Jar() {
}
}

fun addFileProcessor(extensions: Iterable<String> = emptySet(),
names: Iterable<String> = emptySet(),
paths: Iterable<String> = emptySet(),
fun addFileProcessor(extensions: Set<String> = emptySet(),
names: Set<String> = emptySet(),
paths: Set<String> = emptySet(),
processor: FileProcessor) {
processors.add {
it.walkTopDown().forEach { file ->
Expand Down
6 changes: 5 additions & 1 deletion buildSrc/src/main/kotlin/git.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions proguard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init>(...);
}

-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
-keepclassmembers,allowoptimization class dev.rdh.createunlimited.*.config.PlacementCheck {
boolean isEnabledFor(***); # accessed in asm
}
6 changes: 3 additions & 3 deletions src/main/java/dev/rdh/createunlimited/asm/Asm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Set<BlockPos> 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) {
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/dev/rdh/createunlimited/config/CUServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Player> enabled;

PlacementCheck(Predicate<Player> enabled) {
this.enabled = enabled;
}
public boolean isEnabledFor(Player player) {
return enabled.test(player);
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/dev/rdh/createunlimited/config/PlacementCheck.java
Original file line number Diff line number Diff line change
@@ -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<Player> enabled;

PlacementCheck(Predicate<Player> enabled) {
this.enabled = enabled;
}

public boolean isEnabledFor(Player player) {
return enabled.test(player);
}
}

0 comments on commit a24191e

Please sign in to comment.