From 40ecca4904a07c705d115ed4da413c735f4c7b07 Mon Sep 17 00:00:00 2001 From: JFronny <33260128+jfronny@users.noreply.github.com> Date: Sat, 15 May 2021 16:44:42 +0200 Subject: [PATCH] Attempt to use gradle with JDK 16 and fix server --- .gitlab-ci.yml | 2 +- build.gradle | 70 ++++-------------- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- proguard.conf | 11 --- .../io/gitlab/jfronny/libjf/LibjfClient.java | 23 ++++++ .../gitlab/jfronny/libjf/config/Config.java | 74 +++++++++---------- src/main/resources/fabric.mod.json | 6 +- src/main/resources/libjf.mixins.json | 13 ---- 9 files changed, 80 insertions(+), 123 deletions(-) delete mode 100644 proguard.conf create mode 100644 src/main/java/io/gitlab/jfronny/libjf/LibjfClient.java delete mode 100644 src/main/resources/libjf.mixins.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fb14d91..7a93bab 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: gradle:alpine +image: gradle:jdk16 variables: GRADLE_OPTS: "-Dorg.gradle.daemon=false" diff --git a/build.gradle b/build.gradle index 94069b9..989b15b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,6 @@ -import groovy.json.JsonOutput -import groovy.json.JsonSlurper -import proguard.gradle.ProGuardTask -import net.fabricmc.loom.task.RunClientTask -import net.fabricmc.loom.task.RunServerTask - -buildscript { - repositories { - mavenLocal() - google() - } - - dependencies { - classpath 'com.guardsquare:proguard-gradle:7.0.1' - } -} +import net.fabricmc.loom.configuration.ide.RunConfigSettings +import net.fabricmc.loom.task.RunGameTask +import net.fabricmc.loom.LoomGradleExtension plugins { id 'fabric-loom' version '0.7-SNAPSHOT' @@ -29,7 +16,6 @@ group = project.maven_group repositories { maven { url = 'https://maven.terraformersmc.com/'; name = "ModMenu" } - maven { url "https://maven.shedaniel.me/" } } sourceSets { @@ -39,14 +25,6 @@ sourceSets { } } -task runTestmodClient(type: RunClientTask) { - classpath sourceSets.testmod.runtimeClasspath -} - -task runTestmodServer(type: RunServerTask) { - classpath sourceSets.testmod.runtimeClasspath -} - dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -56,40 +34,20 @@ dependencies { modImplementation "com.terraformersmc:modmenu:1.16.9" } +task runTestmodClient(type: RunGameTask, constructorArgs: [getExtensions().getByType(LoomGradleExtension.class).getRunConfigs().getByName("client")]) { + classpath sourceSets.testmod.runtimeClasspath +} + +task runTestmodServer(type: RunGameTask, constructorArgs: [getExtensions().getByType(LoomGradleExtension.class).getRunConfigs().getByName("server")]) { + classpath sourceSets.testmod.runtimeClasspath +} + processResources { inputs.property "version", project.version - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" + filesMatching("fabric.mod.json") { expand "version": project.version } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" - } - - doLast { - fileTree(dir: outputs.files.asPath, include: "**/*.json").each { - File file -> file.text = JsonOutput.toJson(new JsonSlurper().parse(file)) - } - } -} - -def proguardJarOut = file(jar.archiveFile.get().getAsFile().absolutePath.replace(".jar", "-min.jar")) - -task proguardJar(type: ProGuardTask, dependsOn: jar) { - configuration './proguard.conf' - verbose - injars jar.archiveFile.get().getAsFile() - outjars proguardJarOut - libraryjars files(configurations.compileClasspath) - printmapping 'out.map' -} - -tasks.remapJar { - input.set proguardJarOut - archiveClassifier.set null - dependsOn proguardJar } // ensure that the encoding is set to UTF-8, no matter what the system default is @@ -97,6 +55,10 @@ tasks.remapJar { // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html tasks.withType(JavaCompile) { options.encoding = "UTF-8" + def targetVersion = 8 + if (JavaVersion.current().isJava9Compatible()) { + it.options.release = targetVersion + } } // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task diff --git a/gradle.properties b/gradle.properties index c052c05..272d591 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html minecraft_version=1.16.5 -yarn_mappings=1.16.5+build.6 +yarn_mappings=1.16.5+build.9 loader_version=0.11.3 # Mod Properties mod_version=1.0.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bb8b2fc..0f80bbf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/proguard.conf b/proguard.conf deleted file mode 100644 index f634b59..0000000 --- a/proguard.conf +++ /dev/null @@ -1,11 +0,0 @@ --libraryjars /jmods/java.base.jmod(!**.jar;!module-info.class) --keep public class io.gitlab.jfronny.libjf.config.JfConfig { - public protected *; -} --keep public class io.gitlab.jfronny.libjf.Libjf --keep public class io.gitlab.jfronny.libjf.config.ModMenu --repackageclasses 'jf.lib' --allowaccessmodification --overloadaggressively --optimizationpasses 5 --optimizations '*' \ No newline at end of file diff --git a/src/main/java/io/gitlab/jfronny/libjf/LibjfClient.java b/src/main/java/io/gitlab/jfronny/libjf/LibjfClient.java new file mode 100644 index 0000000..277eb96 --- /dev/null +++ b/src/main/java/io/gitlab/jfronny/libjf/LibjfClient.java @@ -0,0 +1,23 @@ +package io.gitlab.jfronny.libjf; + +import io.gitlab.jfronny.libjf.config.Config; +import io.gitlab.jfronny.libjf.config.Entry; +import io.gitlab.jfronny.libjf.config.EntryInfo; +import io.gitlab.jfronny.libjf.gson.GsonHidden; +import net.fabricmc.api.ClientModInitializer; + +public class LibjfClient implements ClientModInitializer { + @Override + public void onInitializeClient() { + for (Config config : Libjf.getConfigs().values()) { + Libjf.LOGGER.info("Registring config UI for " + config.modid); + for (EntryInfo info : config.entries) { + if (info.field.isAnnotationPresent(Entry.class) || info.field.isAnnotationPresent(GsonHidden.class)) + try { + config.initClient(info); + } catch (Exception ignored) { + } + } + } + } +} diff --git a/src/main/java/io/gitlab/jfronny/libjf/config/Config.java b/src/main/java/io/gitlab/jfronny/libjf/config/Config.java index e0cdb96..b6b9fd9 100644 --- a/src/main/java/io/gitlab/jfronny/libjf/config/Config.java +++ b/src/main/java/io/gitlab/jfronny/libjf/config/Config.java @@ -38,55 +38,51 @@ public class Config { for (Field field : config.getFields()) { EntryInfo info = new EntryInfo(); - if (field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(GsonHidden.class)) - try { - initClient(field, info); - } catch (Exception e) {continue;} + info.field = field; if (field.isAnnotationPresent(Entry.class)) try { info.defaultValue = field.get(null); } catch (IllegalAccessException ignored) {} + entries.add(info); } try { Libjf.GSON.fromJson(Files.newBufferedReader(path), config); } catch (Exception e) { write(); } - - for (EntryInfo info : entries) { - if (info.field.isAnnotationPresent(Entry.class)) - try { - info.value = info.field.get(null); - info.tempValue = info.value.toString(); - } catch (IllegalAccessException ignored) { - } - } } - @Environment(EnvType.CLIENT) - public void initClient(Field field, EntryInfo info) { - Class type = field.getType(); - Entry e = field.getAnnotation(Entry.class); - info.width = e != null ? e.width() : 0; - info.field = field; - if (e != null) - if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true); - else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(),false); - else if (type == String.class) textField(info, String::length, null, Math.min(e.min(),0), Math.max(e.max(),1),true); - else if (type == boolean.class) { - Function func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED); - info.widget = new AbstractMap.SimpleEntry>(button -> { - info.value = !(Boolean) info.value; - button.setMessage(func.apply(info.value)); - }, func); - } else if (type.isEnum()) { - List values = Arrays.asList(field.getType().getEnumConstants()); - Function func = value -> new TranslatableText(modid + ".jfconfig." + "enum." + type.getSimpleName() + "." + info.value.toString()); - info.widget = new AbstractMap.SimpleEntry>( button -> { - int index = values.indexOf(info.value) + 1; - info.value = values.get(index >= values.size()? 0 : index); - button.setMessage(func.apply(info.value)); - }, func); - } - entries.add(info); + @Environment(EnvType.CLIENT) + public void initClient(EntryInfo info) { + if (!(info.field.isAnnotationPresent(Entry.class) || info.field.isAnnotationPresent(GsonHidden.class))) return; + Class type = info.field.getType(); + Entry e = info.field.getAnnotation(Entry.class); + info.width = e != null ? e.width() : 0; + + if (e == null) return; + + if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true); + else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(),false); + else if (type == String.class) textField(info, String::length, null, Math.min(e.min(),0), Math.max(e.max(),1),true); + else if (type == boolean.class) { + Function func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED); + info.widget = new AbstractMap.SimpleEntry>(button -> { + info.value = !(Boolean) info.value; + button.setMessage(func.apply(info.value)); + }, func); + } else if (type.isEnum()) { + List values = Arrays.asList(info.field.getType().getEnumConstants()); + Function func = value -> new TranslatableText(modid + ".jfconfig." + "enum." + type.getSimpleName() + "." + info.value.toString()); + info.widget = new AbstractMap.SimpleEntry>( button -> { + int index = values.indexOf(info.value) + 1; + info.value = values.get(index >= values.size()? 0 : index); + button.setMessage(func.apply(info.value)); + }, func); + } + + try { + info.value = info.field.get(null); + info.tempValue = info.value.toString(); + } catch (IllegalAccessException ignored) { + } } private void textField(EntryInfo info, Function f, Pattern pattern, double min, double max, boolean cast) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a574bb5..d18c69f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,13 +18,13 @@ "preLaunch": [ "io.gitlab.jfronny.libjf.Libjf" ], + "client": [ + "io.gitlab.jfronny.libjf.LibjfClient" + ], "modmenu": [ "io.gitlab.jfronny.libjf.config.ModMenu" ] }, - "mixins": [ - "libjf.mixins.json" - ], "depends": { "fabricloader": ">=0.11.3", "minecraft": "1.16.5" diff --git a/src/main/resources/libjf.mixins.json b/src/main/resources/libjf.mixins.json deleted file mode 100644 index 77ee62b..0000000 --- a/src/main/resources/libjf.mixins.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "io.gitlab.jfronny.libjf.mixin", - "compatibilityLevel": "JAVA_8", - "mixins": [ - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -}