initial commit
This commit is contained in:
+125
@@ -0,0 +1,125 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Ignore Gradle GUI config
|
||||||
|
gradle-app.setting
|
||||||
|
|
||||||
|
# Cache of project
|
||||||
|
.gradletasknamecache
|
||||||
|
|
||||||
|
**/build/
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
|
|
||||||
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
|
!gradle-wrapper.jar
|
||||||
|
/.gradle/
|
||||||
|
/.idea/
|
||||||
|
/build/
|
||||||
|
/out/
|
||||||
|
/run/
|
||||||
|
/server-run/
|
||||||
|
/out.map
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2021 Draylar
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# ΩConfig
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*The last config library you will ever use.*
|
||||||
|
|
||||||
|
ΩConfig is a hyper-minimal config library based on [Auto Config](https://github.com/shedaniel/AutoConfig). It aims to achieve
|
||||||
|
the following goals:
|
||||||
|
- Be lightweight (<10 KB) for JIJ usage
|
||||||
|
- Exceedingly simple design & API for developers
|
||||||
|
- Intuition and usability for players
|
||||||
|
|
||||||
|
The following is an example of a simple ΩConfig setup:
|
||||||
|
```java
|
||||||
|
public class TestConfig implements Config {
|
||||||
|
|
||||||
|
@Comment(value = "Hello!")
|
||||||
|
boolean value = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFileName() {
|
||||||
|
return "test-config";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
```java
|
||||||
|
public class MyModInitializer {
|
||||||
|
|
||||||
|
public static final TestConfig CONFIG = OmegaConfig.register(TestConfig.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
System.out.printf("Config value: %s%n", CONFIG.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
---
|
||||||
|
### Extra API Utilities
|
||||||
|
|
||||||
|
ΩConfig provides several utility methods for developers.
|
||||||
|
|
||||||
|
**save()** - *saves a modified configuration instance to disk*
|
||||||
|
|
||||||
|
```java
|
||||||
|
MyModInitializer.CONFIG.value = false;
|
||||||
|
MyModInitializer.CONFIG.save(); // writes the new value to disk
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
### License
|
||||||
|
ΩConfig is available under Public Domain.
|
||||||
|
You are encouraged to utilize the code in this repository in any way you wish.
|
||||||
+152
@@ -0,0 +1,152 @@
|
|||||||
|
import groovy.json.JsonSlurper
|
||||||
|
import groovy.json.JsonOutput
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
google()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.guardsquare:proguard-gradle:7.0.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'fabric-loom' version '0.7-SNAPSHOT'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
|
archivesBaseName = project.archives_base_name
|
||||||
|
version = project.mod_version
|
||||||
|
group = project.maven_group
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
testmod {
|
||||||
|
compileClasspath += main.compileClasspath
|
||||||
|
runtimeClasspath += main.runtimeClasspath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url = "https://maven.terraformersmc.com/releases/"}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
//to change the versions see the gradle.properties file
|
||||||
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||||
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
|
modImplementation "com.terraformersmc:modmenu:1.16.8"
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
testmodImplementation sourceSets.main.output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
inputs.property "version", project.version
|
||||||
|
|
||||||
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
|
include "fabric.mod.json"
|
||||||
|
expand "version": project.version
|
||||||
|
}
|
||||||
|
|
||||||
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
|
exclude "fabric.mod.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
def jsonMinifyStart = System.currentTimeMillis()
|
||||||
|
def jsonMinified = 0
|
||||||
|
def jsonBytesSaved = 0
|
||||||
|
|
||||||
|
fileTree(dir: outputs.files.asPath, include: '**/*.json').each {
|
||||||
|
|
||||||
|
File file = it
|
||||||
|
jsonMinified++
|
||||||
|
def oldLength = file.length()
|
||||||
|
file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
|
||||||
|
jsonBytesSaved += oldLength - file.length()
|
||||||
|
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
println('Minified ' + jsonMinified + ' json files. Saved ' + jsonBytesSaved + ' bytes. Took ' + (System.currentTimeMillis() - jsonMinifyStart) + 'ms.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||||
|
// this fixes some edge cases with special characters not displaying correctly
|
||||||
|
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.encoding = "UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||||
|
// if it is present.
|
||||||
|
// If you remove this task, sources will not be generated.
|
||||||
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||||
|
classifier = "sources"
|
||||||
|
from sourceSets.main.allSource
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure the maven publication
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
mavenJava(MavenPublication) {
|
||||||
|
// add all the jars that should be included when publishing to maven
|
||||||
|
artifact(remapJar) {
|
||||||
|
builtBy remapJar
|
||||||
|
}
|
||||||
|
artifact(sourcesJar) {
|
||||||
|
builtBy remapSourcesJar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// select the repositories you want to publish to
|
||||||
|
repositories {
|
||||||
|
// uncomment to publish to the local maven
|
||||||
|
// mavenLocal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// technician what does this do
|
||||||
|
tasks.withType(net.fabricmc.loom.task.AbstractRunTask) {
|
||||||
|
classpath += sourceSets.testmod.runtimeClasspath
|
||||||
|
classpath += sourceSets.testmod.output
|
||||||
|
}
|
||||||
|
|
||||||
|
task ('proguard', type: proguard.gradle.ProGuardTask) {
|
||||||
|
configuration 'proguard.conf'
|
||||||
|
verbose
|
||||||
|
injars 'build/libs/omega-config-1.0.0.jar'
|
||||||
|
outjars 'build/libs/out.jar'
|
||||||
|
printmapping 'out.map'
|
||||||
|
keepparameternames
|
||||||
|
renamesourcefileattribute 'SourceFile'
|
||||||
|
keepattributes 'Signature,Exceptions,InnerClasses,PermittedSubclasses,EnclosingMethod,Deprecated,SourceFile,LineNumberTable'
|
||||||
|
keepattributes '*Annotation*'
|
||||||
|
keep 'public class * { \
|
||||||
|
public protected *; \
|
||||||
|
}'
|
||||||
|
keepclassmembernames 'class * { \
|
||||||
|
java.lang.Class class$(java.lang.String); \
|
||||||
|
java.lang.Class class$(java.lang.String, boolean); \
|
||||||
|
}'
|
||||||
|
|
||||||
|
keepclassmembers 'class draylar.omegaconfig.mixin.* {\
|
||||||
|
<fields>;\
|
||||||
|
<init>();\
|
||||||
|
<methods>;\
|
||||||
|
}'
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Done to increase the memory available to gradle.
|
||||||
|
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.5
|
||||||
|
loader_version=0.11.2
|
||||||
|
# Mod Properties
|
||||||
|
mod_version=1.0.0
|
||||||
|
maven_group=draylar
|
||||||
|
archives_base_name=omega-config
|
||||||
|
# Dependencies
|
||||||
|
# check this on https://modmuss50.me/fabric.html
|
||||||
|
fabric_version=0.32.0+1.16
|
||||||
Vendored
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright 2015 the original author or authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Gradle start up script for UN*X
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG=`dirname "$PRG"`"/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD="maximum"
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN* )
|
||||||
|
cygwin=true
|
||||||
|
;;
|
||||||
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
NONSTOP* )
|
||||||
|
nonstop=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="java"
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
ulimit -n $MAX_FD
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
|
if $darwin; then
|
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
SEP=""
|
||||||
|
for dir in $ROOTDIRSRAW ; do
|
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
|
SEP="|"
|
||||||
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=`expr $i + 1`
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
0) set -- ;;
|
||||||
|
1) set -- "$args0" ;;
|
||||||
|
2) set -- "$args0" "$args1" ;;
|
||||||
|
3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Escape application args
|
||||||
|
save () {
|
||||||
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
|
echo " "
|
||||||
|
}
|
||||||
|
APP_ARGS=`save "$@"`
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||||
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
Vendored
+104
@@ -0,0 +1,104 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:init
|
||||||
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
|
||||||
|
:win9xME_args
|
||||||
|
@rem Slurp the command line arguments.
|
||||||
|
set CMD_LINE_ARGS=
|
||||||
|
set _SKIP=2
|
||||||
|
|
||||||
|
:win9xME_args_slurp
|
||||||
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
|
set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-ignorewarnings
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
}
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
package draylar.omegaconfig;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import draylar.omegaconfig.api.Comment;
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import draylar.omegaconfig.api.SyncableExclusionStrategy;
|
||||||
|
import draylar.omegaconfig.exception.NoValidConstructorException;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class OmegaConfig implements ModInitializer {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
|
||||||
|
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
|
public static final Identifier CONFIG_SYNC_PACKET = new Identifier("omegaconfig", "sync");
|
||||||
|
public static final Gson SYNC_ONLY_GSON = new GsonBuilder().addSerializationExclusionStrategy(new SyncableExclusionStrategy()).setPrettyPrinting().create();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
||||||
|
server.execute(() -> {
|
||||||
|
PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer());
|
||||||
|
|
||||||
|
// list of configurations that are synced
|
||||||
|
CompoundTag root = new CompoundTag();
|
||||||
|
ListTag configurations = new ListTag();
|
||||||
|
|
||||||
|
// Iterate over each configuration.
|
||||||
|
// Find values that should be synced and send the value over.
|
||||||
|
OmegaConfig.getRegisteredConfigurations().forEach(config -> {
|
||||||
|
if(config.hasAnySyncable()) {
|
||||||
|
configurations.add(config.writeSyncingTag());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// save to packet and send to user
|
||||||
|
root.put("Configurations", configurations);
|
||||||
|
packet.writeCompoundTag(root);
|
||||||
|
handler.sendPacket(ServerPlayNetworking.createS2CPacket(CONFIG_SYNC_PACKET, packet));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Config> T register(Class<T> configClass) {
|
||||||
|
try {
|
||||||
|
// Attempt to instantiate a new instance of this class.
|
||||||
|
T config = configClass.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
// Exceptions will have been thrown at this point.
|
||||||
|
// We want to provide access to the config as soon as it is created, so we:
|
||||||
|
// 1. serialize to disk if the config does not already exist
|
||||||
|
// 2. read from disk if it does exist
|
||||||
|
if(!configExists(config)) {
|
||||||
|
writeConfig(configClass, config);
|
||||||
|
REGISTERED_CONFIGURATIONS.add(config);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
// Read from the disk config file to populate the correct values into our config object.
|
||||||
|
List<String> lines = Files.readAllLines(getConfigPath(config));
|
||||||
|
lines.removeIf(line -> line.trim().startsWith("//"));
|
||||||
|
StringBuilder res = new StringBuilder();
|
||||||
|
lines.forEach(res::append);
|
||||||
|
T object = GSON.fromJson(res.toString(), configClass);
|
||||||
|
|
||||||
|
// re-write the config to add new values
|
||||||
|
writeConfig(configClass, object);
|
||||||
|
REGISTERED_CONFIGURATIONS.add(object);
|
||||||
|
return object;
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
LOGGER.error(ioException);
|
||||||
|
LOGGER.info(String.format("Read error, using default values for config %s.", configClass.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||||
|
throw new NoValidConstructorException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T extends Config> void writeConfig(Class<T> configClass, T instance) {
|
||||||
|
// Write the config to disk with the default values.
|
||||||
|
String json = GSON.toJson(instance);
|
||||||
|
|
||||||
|
// Cursed time.
|
||||||
|
List<String> lines = new ArrayList<>(Arrays.asList(json.split("\n")));
|
||||||
|
Map<Integer, String> insertions = new HashMap<>();
|
||||||
|
Map<String, String> keyToComments = new HashMap<>();
|
||||||
|
|
||||||
|
// populate key -> comments map
|
||||||
|
for(Field field : configClass.getDeclaredFields()) {
|
||||||
|
addFieldComments(field, keyToComments);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get inner-class fields
|
||||||
|
// TODO: recursively get inner classes?
|
||||||
|
for(Class<?> innerClass : configClass.getDeclaredClasses()) {
|
||||||
|
for(Field field : innerClass.getDeclaredFields()) {
|
||||||
|
addFieldComments(field, keyToComments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find areas we should insert comments into...
|
||||||
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
|
String at = lines.get(i);
|
||||||
|
|
||||||
|
// Check if we should insert comment
|
||||||
|
for (Map.Entry<String, String> entry : keyToComments.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
String comment = entry.getValue();
|
||||||
|
|
||||||
|
if (at.trim().startsWith(String.format("\"%s\"", key))) {
|
||||||
|
insertions.put(i + insertions.size(), String.format("%s//%s", getStartingWhitespace(at), comment));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// insertions -> list
|
||||||
|
insertions.forEach(lines::add);
|
||||||
|
|
||||||
|
// list -> string
|
||||||
|
StringBuilder res = new StringBuilder();
|
||||||
|
lines.forEach(str -> res.append(String.format("%s%n", str)));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.write(getConfigPath(instance), res.toString().getBytes());
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
LOGGER.error(ioException);
|
||||||
|
LOGGER.info(String.format("Write error, using default values for config %s.", configClass.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addFieldComments(Field field, Map<String, String> keyToComments) {
|
||||||
|
String fieldName = field.getName();
|
||||||
|
Annotation[] annotations = field.getDeclaredAnnotations();
|
||||||
|
|
||||||
|
// Find comment
|
||||||
|
for (Annotation annotation : annotations) {
|
||||||
|
if(annotation instanceof Comment) {
|
||||||
|
keyToComments.put(fieldName, ((Comment) annotation).value());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string with the left-side whitespace characters of the given input, up till the first non-whitespace character.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* " hello" -> " "
|
||||||
|
* "p" -> ""
|
||||||
|
* " p" -> " "
|
||||||
|
*
|
||||||
|
* @param input input to retrieve whitespaces from
|
||||||
|
* @return starting whitespaces from the given input
|
||||||
|
*/
|
||||||
|
private static String getStartingWhitespace(String input) {
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
char[] chars = input.toCharArray();
|
||||||
|
for(int i = 0; i < chars.length; i++) {
|
||||||
|
char at = chars[i];
|
||||||
|
|
||||||
|
if(at != ' ') {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(index != -1) {
|
||||||
|
return input.substring(0, index);
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Path getConfigPath(Config config) {
|
||||||
|
return Paths.get(FabricLoader.getInstance().getConfigDir().toString(), String.format("%s.json", config.getFileName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean configExists(Config config) {
|
||||||
|
return Files.exists(getConfigPath(config));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Config> getRegisteredConfigurations() {
|
||||||
|
return REGISTERED_CONFIGURATIONS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package draylar.omegaconfig;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import draylar.omegaconfig.api.screen.ModMenuHelper;
|
||||||
|
import draylar.omegaconfig.api.screen.OmegaConfigScreen;
|
||||||
|
import draylar.omegaconfig.api.screen.OmegaConfigScreenSupplier;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public class OmegaConfigClient implements ClientModInitializer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Config> void registerConfigScreen(T config) {
|
||||||
|
registerConfigScreen(config, parent -> new OmegaConfigScreen<>(config, parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends Config> void registerConfigScreen(T config, OmegaConfigScreenSupplier<T> screenFactory) {
|
||||||
|
if(FabricLoader.getInstance().isModLoaded("modmenu")) {
|
||||||
|
ModMenuHelper.injectScreen(config, screenFactory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package draylar.omegaconfig.api;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface Comment {
|
||||||
|
String value() default "";
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package draylar.omegaconfig.api;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.OmegaConfig;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.StringTag;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public interface Config {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes this configuration file instance to disk.
|
||||||
|
* Useful for saving modified values during runtime.
|
||||||
|
*/
|
||||||
|
default void save() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an instance of this Config class with all default values.
|
||||||
|
*/
|
||||||
|
default Config getDefault() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
default CompoundTag writeSyncingTag() {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
tag.putString("ConfigName", getFileName());
|
||||||
|
|
||||||
|
// all config vs. individual fields
|
||||||
|
if(Arrays.stream(getClass().getAnnotations()).anyMatch(annotation -> annotation instanceof Syncing)) {
|
||||||
|
// write ALL fields to tag
|
||||||
|
String json = OmegaConfig.GSON.toJson(this);
|
||||||
|
tag.putString("Serialized", json);
|
||||||
|
tag.putBoolean("AllSync", true);
|
||||||
|
} else {
|
||||||
|
// write all syncable fields to tag
|
||||||
|
String json = OmegaConfig.SYNC_ONLY_GSON.toJson(this);
|
||||||
|
tag.putString("Serialized", json);
|
||||||
|
tag.putBoolean("AllSync", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this {@link Config} has any values that should be synced to the client
|
||||||
|
*/
|
||||||
|
default boolean hasAnySyncable() {
|
||||||
|
boolean hasSyncingField = Arrays.stream(getClass().getDeclaredFields()).anyMatch(field -> Arrays.stream(field.getDeclaredAnnotations()).anyMatch(annotation -> annotation instanceof Syncing));
|
||||||
|
boolean classSyncs = Arrays.stream(getClass().getDeclaredAnnotations()).anyMatch(annotation -> annotation instanceof Syncing);
|
||||||
|
return hasSyncingField | classSyncs;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getFileName();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
default String getModid() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean hasMenu() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package draylar.omegaconfig.api;
|
||||||
|
|
||||||
|
import com.google.gson.ExclusionStrategy;
|
||||||
|
import com.google.gson.FieldAttributes;
|
||||||
|
|
||||||
|
public class SyncableExclusionStrategy implements ExclusionStrategy {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldSkipField(FieldAttributes f) {
|
||||||
|
return f.getAnnotations().stream().noneMatch(annotation -> annotation instanceof Syncing);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldSkipClass(Class<?> clazz) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package draylar.omegaconfig.api;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD, ElementType.TYPE})
|
||||||
|
public @interface Syncing {
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package draylar.omegaconfig.api.screen;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import draylar.omegaconfig.mixin.ModMenuAccessor;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public class ModMenuHelper {
|
||||||
|
|
||||||
|
public static <T extends Config> void injectScreen(T config, OmegaConfigScreenSupplier<T> factory) {
|
||||||
|
// collect existing configurations
|
||||||
|
ImmutableMap<String, ConfigScreenFactory<?>> configScreenFactories = ModMenuAccessor.getConfigScreenFactories();
|
||||||
|
Map<String, ConfigScreenFactory<?>> nMap = new HashMap<>();
|
||||||
|
nMap.putAll(configScreenFactories);
|
||||||
|
|
||||||
|
// add our factory
|
||||||
|
nMap.put(config.getModid(), factory::get);
|
||||||
|
|
||||||
|
// they will suspect nothing
|
||||||
|
ModMenuAccessor.setConfigScreenFactories(ImmutableMap.copyOf(nMap));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package draylar.omegaconfig.api.screen;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import draylar.omegaconfig.api.screen.widget.LabelWidget;
|
||||||
|
import draylar.omegaconfig.api.screen.widget.TypeWidgets;
|
||||||
|
import draylar.omegaconfig.api.screen.widget.WidgetSupplier;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.Drawable;
|
||||||
|
import net.minecraft.client.gui.Element;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.Pair;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class OmegaConfigScreen<T extends Config> extends Screen {
|
||||||
|
|
||||||
|
private static final List<Class<?>> validClasses = Arrays.asList(Double.class, String.class, Boolean.class);
|
||||||
|
private final T config;
|
||||||
|
private final Screen parent;
|
||||||
|
private final Map<Field, Pair<WidgetSupplier<Object, AbstractButtonWidget>, AbstractButtonWidget>> fieldWidgets = new HashMap<>();
|
||||||
|
|
||||||
|
public OmegaConfigScreen(T config, Screen parent) {
|
||||||
|
super(new LiteralText(""));
|
||||||
|
this.config = config;
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
super.init();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// add label & button for each config entry
|
||||||
|
// TODO: SUB-CLASS SUPPORT
|
||||||
|
List<Field> collect = Arrays.stream(config.getClass().getDeclaredFields()).filter(field -> validClasses.contains(TypeWidgets.unbox(field.getType()))).collect(Collectors.toList());
|
||||||
|
int over = 0;
|
||||||
|
|
||||||
|
for (Field field : collect) {
|
||||||
|
Class<?> unbox = TypeWidgets.unbox(field.getType());
|
||||||
|
|
||||||
|
// label
|
||||||
|
addChild(new LabelWidget(150, 5 + 20 * over, new LiteralText(field.getName())));
|
||||||
|
|
||||||
|
// get value
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object value = field.get(config);
|
||||||
|
|
||||||
|
// button / interact
|
||||||
|
AbstractButtonWidget button;
|
||||||
|
WidgetSupplier<Object, AbstractButtonWidget> widgetSupplier = (WidgetSupplier<Object, AbstractButtonWidget>) TypeWidgets.get(unbox);
|
||||||
|
if(widgetSupplier != null) {
|
||||||
|
button = widgetSupplier.create(250, 5 + 20 * over, 50, 50, new LiteralText(field.getName()), value);
|
||||||
|
} else {
|
||||||
|
button = new TextFieldWidget(client.textRenderer, 250, 5 + 20 * over, 50, 20, new LiteralText(field.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldWidgets.put(field, new Pair<>(widgetSupplier, button));
|
||||||
|
|
||||||
|
addButton(button);
|
||||||
|
|
||||||
|
over++;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// save and exit
|
||||||
|
ButtonWidget exit = new ButtonWidget(width - 60, height - 30, 50, 20, new LiteralText("Exit"), widget -> onClose());
|
||||||
|
ButtonWidget save = new ButtonWidget(10, height - 30, 50, 20, new LiteralText("Save"), widget -> {
|
||||||
|
fieldWidgets.forEach((field, pair) -> {
|
||||||
|
try {
|
||||||
|
field.set(config, pair.getLeft().get(pair.getRight()));
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
});
|
||||||
|
addButton(save);
|
||||||
|
addButton(exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
renderBackground(matrices);
|
||||||
|
|
||||||
|
for (AbstractButtonWidget button : this.buttons) {
|
||||||
|
button.render(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Element element : this.children) {
|
||||||
|
if (element instanceof Drawable && !buttons.contains(element)) {
|
||||||
|
((Drawable) element).render(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
client.openScreen(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderBackground(MatrixStack matrices) {
|
||||||
|
super.renderBackground(matrices);
|
||||||
|
|
||||||
|
MinecraftClient.getInstance().getTextureManager().bindTexture(new Identifier("textures/block/dirt.png"));
|
||||||
|
drawTexture(matrices, 0, 0, 0, 0, 16, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package draylar.omegaconfig.api.screen;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
|
||||||
|
public interface OmegaConfigScreenSupplier<T extends Config> {
|
||||||
|
OmegaConfigScreen<T> get(Screen parent);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package draylar.omegaconfig.api.screen.widget;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.Drawable;
|
||||||
|
import net.minecraft.client.gui.DrawableHelper;
|
||||||
|
import net.minecraft.client.gui.Element;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class LabelWidget extends DrawableHelper implements Drawable, Element {
|
||||||
|
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final Text message;
|
||||||
|
|
||||||
|
public LabelWidget(int x, int y, Text message) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
drawTextWithShadow(matrices, MinecraftClient.getInstance().textRenderer, message, x, y, 0xffffff);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package draylar.omegaconfig.api.screen.widget;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.screen.widget.supplier.BooleanWidgetSupplier;
|
||||||
|
import draylar.omegaconfig.api.screen.widget.supplier.DoubleWidgetSupplier;
|
||||||
|
import draylar.omegaconfig.api.screen.widget.supplier.StringWidgetSupplier;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TypeWidgets {
|
||||||
|
|
||||||
|
public static final Map<Class<?>, WidgetSupplier<?, ?>> CLASS_WIDGETS = new HashMap<>();
|
||||||
|
public static final Map<Class<?>, Class<?>> PRIMITIVE_TO_BOXED = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CLASS_WIDGETS.put(Double.class, new DoubleWidgetSupplier());
|
||||||
|
CLASS_WIDGETS.put(Boolean.class, new BooleanWidgetSupplier());
|
||||||
|
CLASS_WIDGETS.put(String.class, new StringWidgetSupplier());
|
||||||
|
|
||||||
|
// primitive -> boxed
|
||||||
|
PRIMITIVE_TO_BOXED.put(boolean.class, Boolean.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(byte.class, Byte.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(char.class, Character.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(double.class, Double.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(float.class, Float.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(int.class, Integer.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(long.class, Long.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(short.class, Short.class);
|
||||||
|
PRIMITIVE_TO_BOXED.put(void.class, Void.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static <T> WidgetSupplier<T, ?> get(Class<T> typeClass) {
|
||||||
|
return (WidgetSupplier<T, ?>) CLASS_WIDGETS.get(unbox(typeClass));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<?> unbox(Class<?> c) {
|
||||||
|
return PRIMITIVE_TO_BOXED.getOrDefault(c, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TypeWidgets() {
|
||||||
|
// NO-OP
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package draylar.omegaconfig.api.screen.widget;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
|
||||||
|
public interface WidgetSupplier<T, A extends AbstractButtonWidget> {
|
||||||
|
AbstractButtonWidget create(int x, int y, int width, int height, LiteralText prompt, T value);
|
||||||
|
T get(A widget);
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package draylar.omegaconfig.api.screen.widget.supplier;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.screen.widget.WidgetSupplier;
|
||||||
|
import net.minecraft.client.gui.widget.CheckboxWidget;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
|
||||||
|
public class BooleanWidgetSupplier implements WidgetSupplier<Boolean, CheckboxWidget> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckboxWidget create(int x, int y, int width, int height, LiteralText prompt, Boolean value) {
|
||||||
|
return new CheckboxWidget(x, y, 20, 20, new LiteralText(""), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean get(CheckboxWidget widget) {
|
||||||
|
return widget.isChecked();
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package draylar.omegaconfig.api.screen.widget.supplier;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.screen.widget.WidgetSupplier;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
|
||||||
|
public class DoubleWidgetSupplier implements WidgetSupplier<Double, AbstractButtonWidget> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractButtonWidget create(int x, int y, int width, int height, LiteralText prompt, Double value) {
|
||||||
|
return new TextFieldWidget(MinecraftClient.getInstance().textRenderer, x, y, width, height, new LiteralText(String.valueOf(value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Double get(AbstractButtonWidget widget) {
|
||||||
|
return Double.parseDouble(widget.getMessage().asString());
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package draylar.omegaconfig.api.screen.widget.supplier;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.screen.widget.WidgetSupplier;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
|
||||||
|
public class StringWidgetSupplier implements WidgetSupplier<String, AbstractButtonWidget> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractButtonWidget create(int x, int y, int width, int height, LiteralText prompt, String value) {
|
||||||
|
return new TextFieldWidget(MinecraftClient.getInstance().textRenderer, x, y, width, height, new LiteralText(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(AbstractButtonWidget widget) {
|
||||||
|
return widget.getMessage().asString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package draylar.omegaconfig.exception;
|
||||||
|
|
||||||
|
public class NoValidConstructorException extends RuntimeException {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package draylar.omegaconfig.mixin;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.OmegaConfig;
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import draylar.omegaconfig.api.Syncing;
|
||||||
|
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
||||||
|
import net.fabricmc.fabric.api.util.NbtType;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.RunArgs;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mixin(MinecraftClient.class)
|
||||||
|
public class ClientMixin {
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private final List<Config> savedClientConfig = new ArrayList<>(); // stored config from before sync is applied
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "<init>",
|
||||||
|
at = @At("RETURN"))
|
||||||
|
private void onReturn(RunArgs args, CallbackInfo ci) {
|
||||||
|
ClientSidePacketRegistry.INSTANCE.register(OmegaConfig.CONFIG_SYNC_PACKET, (context, buffer) -> {
|
||||||
|
CompoundTag tag = buffer.readCompoundTag();
|
||||||
|
savedClientConfig.clear();
|
||||||
|
|
||||||
|
context.getTaskQueue().execute(() -> {
|
||||||
|
if(tag != null && tag.contains("Configurations")) {
|
||||||
|
ListTag list = tag.getList("Configurations", NbtType.COMPOUND);
|
||||||
|
list.forEach(compound -> {
|
||||||
|
CompoundTag syncedConfiguration = (CompoundTag) compound;
|
||||||
|
String name = syncedConfiguration.getString("ConfigName");
|
||||||
|
String json = syncedConfiguration.getString("Serialized");
|
||||||
|
boolean allSync = syncedConfiguration.getBoolean("AllSync");
|
||||||
|
|
||||||
|
// find configuration class by name
|
||||||
|
for (Config config : OmegaConfig.getRegisteredConfigurations()) {
|
||||||
|
if (config.getFileName().equals(name)) {
|
||||||
|
// bring values from server to object
|
||||||
|
Config server = OmegaConfig.GSON.fromJson(json, config.getClass());
|
||||||
|
|
||||||
|
// deep-copy original config & save it for a restore later
|
||||||
|
Config cachedClient = OmegaConfig.GSON.fromJson(OmegaConfig.GSON.toJson(config), config.getClass());
|
||||||
|
savedClientConfig.add(cachedClient);
|
||||||
|
|
||||||
|
// locate all fields that differ between the client and server, assign values from server to client (this will mutate the stored object)
|
||||||
|
for (Field field : server.getClass().getDeclaredFields()) {
|
||||||
|
if(allSync || Arrays.stream(field.getAnnotations()).anyMatch(annotation -> annotation instanceof Syncing)) {
|
||||||
|
try {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object serverValue = field.get(server);
|
||||||
|
field.set(config, serverValue);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V",
|
||||||
|
at = @At("RETURN"))
|
||||||
|
private void restoreConfigurations(Screen screen, CallbackInfo ci) {
|
||||||
|
for(Config config : savedClientConfig) {
|
||||||
|
for(Config potentiallySynced : OmegaConfig.getRegisteredConfigurations()) {
|
||||||
|
if(config.getFileName().equals(potentiallySynced.getFileName())) {
|
||||||
|
boolean allConfigSyncs = Arrays.stream(config.getClass().getAnnotations()).anyMatch(annotation -> annotation instanceof Syncing);
|
||||||
|
|
||||||
|
// mutate object in registered configurations
|
||||||
|
for (Field field : config.getClass().getDeclaredFields()) {
|
||||||
|
if(allConfigSyncs || Arrays.stream(field.getAnnotations()).anyMatch(annotation -> annotation instanceof Syncing)) {
|
||||||
|
try {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object preSyncValue = field.get(config);
|
||||||
|
field.set(potentiallySynced, preSyncValue);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
savedClientConfig.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package draylar.omegaconfig.mixin;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.terraformersmc.modmenu.ModMenu;
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(ModMenu.class)
|
||||||
|
public interface ModMenuAccessor {
|
||||||
|
@Accessor
|
||||||
|
static ImmutableMap<String, ConfigScreenFactory<?>> getConfigScreenFactories() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Accessor
|
||||||
|
static void setConfigScreenFactories(ImmutableMap<String, ConfigScreenFactory<?>> configScreenFactories) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "omega-config",
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "OmegaConfig",
|
||||||
|
"description": "The last config solution you will ever use.",
|
||||||
|
"authors": [
|
||||||
|
"Draylar"
|
||||||
|
],
|
||||||
|
"contact": {},
|
||||||
|
"license": "MIT",
|
||||||
|
"icon": "assets/omega-config/icon.png",
|
||||||
|
"environment": "*",
|
||||||
|
"entrypoints": {
|
||||||
|
"main": [
|
||||||
|
"draylar.omegaconfig.OmegaConfig"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"omega-config.mixins.json"
|
||||||
|
],
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": ">=0.11.2",
|
||||||
|
"fabric": "*",
|
||||||
|
"minecraft": "1.16.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "draylar.omegaconfig.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_8",
|
||||||
|
"mixins": [
|
||||||
|
"ModMenuAccessor"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"ClientMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package draylar.omegaconfig;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
|
||||||
|
public class OmegaConfigClientTest implements ClientModInitializer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
OmegaConfigClient.registerConfigScreen(OmegaConfigTest.CONFIG);
|
||||||
|
|
||||||
|
HudRenderCallback.EVENT.register((stack, delta) -> {
|
||||||
|
MinecraftClient.getInstance().textRenderer.draw(stack, new LiteralText(String.valueOf(OmegaConfigTest.CONFIG.v)), 15, 15, 0xffffff);
|
||||||
|
MinecraftClient.getInstance().textRenderer.draw(stack, new LiteralText(String.valueOf(OmegaConfigTest.CONFIG.doubleTest)), 15, 30, 0xffffff);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package draylar.omegaconfig;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
|
public class OmegaConfigTest implements ModInitializer {
|
||||||
|
|
||||||
|
public static final TestConfig CONFIG = OmegaConfig.register(TestConfig.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
System.out.printf("Config value: %s%n", CONFIG.v);
|
||||||
|
System.out.printf("Inner class value: %s%n", CONFIG.test.innerTest);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package draylar.omegaconfig;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Comment;
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
import draylar.omegaconfig.api.Syncing;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@Syncing
|
||||||
|
public class TestConfig implements Config {
|
||||||
|
|
||||||
|
@Comment(value = "Hello!")
|
||||||
|
boolean v = false;
|
||||||
|
|
||||||
|
@Comment(value = "I'm a double.")
|
||||||
|
double doubleTest = 0.0;
|
||||||
|
|
||||||
|
@Comment(value = "This is an inner static class.")
|
||||||
|
public Test test = new Test();
|
||||||
|
|
||||||
|
public static class Test {
|
||||||
|
|
||||||
|
@Comment(value = "This is the value inside the class!")
|
||||||
|
public boolean innerTest = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFileName() {
|
||||||
|
return "test-config";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String getModid() {
|
||||||
|
return "omega-config-test";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "omega-config-test",
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "OmegaConfig Test",
|
||||||
|
"description": "Test mod for Omega Config.",
|
||||||
|
"authors": [
|
||||||
|
"Draylar"
|
||||||
|
],
|
||||||
|
"contact": {},
|
||||||
|
"license": "MIT",
|
||||||
|
"icon": "assets/omega-config/icon.png",
|
||||||
|
"environment": "*",
|
||||||
|
"entrypoints": {
|
||||||
|
"main": [
|
||||||
|
"draylar.omegaconfig.OmegaConfigTest"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"draylar.omegaconfig.OmegaConfigClientTest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": ">=0.11.2",
|
||||||
|
"fabric": "*",
|
||||||
|
"minecraft": "1.16.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user