Attempt to use gradle with JDK 16 and fix server

This commit is contained in:
JFronny 2021-05-15 16:44:42 +02:00
parent 632f5a85b8
commit 40ecca4904
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
9 changed files with 80 additions and 123 deletions

View File

@ -1,4 +1,4 @@
image: gradle:alpine image: gradle:jdk16
variables: variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false" GRADLE_OPTS: "-Dorg.gradle.daemon=false"

View File

@ -1,19 +1,6 @@
import groovy.json.JsonOutput import net.fabricmc.loom.configuration.ide.RunConfigSettings
import groovy.json.JsonSlurper import net.fabricmc.loom.task.RunGameTask
import proguard.gradle.ProGuardTask import net.fabricmc.loom.LoomGradleExtension
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'
}
}
plugins { plugins {
id 'fabric-loom' version '0.7-SNAPSHOT' id 'fabric-loom' version '0.7-SNAPSHOT'
@ -29,7 +16,6 @@ group = project.maven_group
repositories { repositories {
maven { url = 'https://maven.terraformersmc.com/'; name = "ModMenu" } maven { url = 'https://maven.terraformersmc.com/'; name = "ModMenu" }
maven { url "https://maven.shedaniel.me/" }
} }
sourceSets { sourceSets {
@ -39,14 +25,6 @@ sourceSets {
} }
} }
task runTestmodClient(type: RunClientTask) {
classpath sourceSets.testmod.runtimeClasspath
}
task runTestmodServer(type: RunServerTask) {
classpath sourceSets.testmod.runtimeClasspath
}
dependencies { dependencies {
//to change the versions see the gradle.properties file //to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
@ -56,40 +34,20 @@ dependencies {
modImplementation "com.terraformersmc:modmenu:1.16.9" 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 { processResources {
inputs.property "version", project.version inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) { filesMatching("fabric.mod.json") {
include "fabric.mod.json"
expand "version": project.version 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 // 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 // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.encoding = "UTF-8" 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 // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task

View File

@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.5 minecraft_version=1.16.5
yarn_mappings=1.16.5+build.6 yarn_mappings=1.16.5+build.9
loader_version=0.11.3 loader_version=0.11.3
# Mod Properties # Mod Properties
mod_version=1.0.0 mod_version=1.0.0

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -1,11 +0,0 @@
-libraryjars <java.home>/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 '*'

View File

@ -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) {
}
}
}
}
}

View File

@ -38,55 +38,51 @@ public class Config {
for (Field field : config.getFields()) { for (Field field : config.getFields()) {
EntryInfo info = new EntryInfo(); EntryInfo info = new EntryInfo();
if (field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(GsonHidden.class)) info.field = field;
try {
initClient(field, info);
} catch (Exception e) {continue;}
if (field.isAnnotationPresent(Entry.class)) if (field.isAnnotationPresent(Entry.class))
try { try {
info.defaultValue = field.get(null); info.defaultValue = field.get(null);
} catch (IllegalAccessException ignored) {} } catch (IllegalAccessException ignored) {}
entries.add(info);
} }
try { try {
Libjf.GSON.fromJson(Files.newBufferedReader(path), config); } Libjf.GSON.fromJson(Files.newBufferedReader(path), config); }
catch (Exception e) { write(); } 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) @Environment(EnvType.CLIENT)
if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true); public void initClient(EntryInfo info) {
else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(),false); if (!(info.field.isAnnotationPresent(Entry.class) || info.field.isAnnotationPresent(GsonHidden.class))) return;
else if (type == String.class) textField(info, String::length, null, Math.min(e.min(),0), Math.max(e.max(),1),true); Class<?> type = info.field.getType();
else if (type == boolean.class) { Entry e = info.field.getAnnotation(Entry.class);
Function<Object,Text> func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED); info.width = e != null ? e.width() : 0;
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
info.value = !(Boolean) info.value; if (e == null) return;
button.setMessage(func.apply(info.value));
}, func); if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true);
} else if (type.isEnum()) { else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(),false);
List<?> values = Arrays.asList(field.getType().getEnumConstants()); else if (type == String.class) textField(info, String::length, null, Math.min(e.min(),0), Math.max(e.max(),1),true);
Function<Object,Text> func = value -> new TranslatableText(modid + ".jfconfig." + "enum." + type.getSimpleName() + "." + info.value.toString()); else if (type == boolean.class) {
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object,Text>>( button -> { Function<Object,Text> func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
int index = values.indexOf(info.value) + 1; info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
info.value = values.get(index >= values.size()? 0 : index); info.value = !(Boolean) info.value;
button.setMessage(func.apply(info.value)); button.setMessage(func.apply(info.value));
}, func); }, func);
} } else if (type.isEnum()) {
entries.add(info); List<?> values = Arrays.asList(info.field.getType().getEnumConstants());
Function<Object,Text> func = value -> new TranslatableText(modid + ".jfconfig." + "enum." + type.getSimpleName() + "." + info.value.toString());
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object,Text>>( 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<String,Number> f, Pattern pattern, double min, double max, boolean cast) { private void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {

View File

@ -18,13 +18,13 @@
"preLaunch": [ "preLaunch": [
"io.gitlab.jfronny.libjf.Libjf" "io.gitlab.jfronny.libjf.Libjf"
], ],
"client": [
"io.gitlab.jfronny.libjf.LibjfClient"
],
"modmenu": [ "modmenu": [
"io.gitlab.jfronny.libjf.config.ModMenu" "io.gitlab.jfronny.libjf.config.ModMenu"
] ]
}, },
"mixins": [
"libjf.mixins.json"
],
"depends": { "depends": {
"fabricloader": ">=0.11.3", "fabricloader": ">=0.11.3",
"minecraft": "1.16.5" "minecraft": "1.16.5"

View File

@ -1,13 +0,0 @@
{
"required": true,
"minVersion": "0.8",
"package": "io.gitlab.jfronny.libjf.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}