First beta build

Most basic features work
Support for some mods
This commit is contained in:
Motschen
2021-04-25 21:47:51 +02:00
parent 3bafb61f32
commit b167872a6b
32 changed files with 1373 additions and 0 deletions

25
.gitignore vendored Executable file
View File

@@ -0,0 +1,25 @@
# gradle
.gradle/
out/
classes/
build/
# idea
.idea/
*.iml
*.ipr
*.iws
# vscode
.settings/
.vscode/
bin/
.classpath
.project
# fabric
run/

21
LICENSE Executable file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 MidnightDust
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.

104
build.gradle Executable file
View File

@@ -0,0 +1,104 @@
plugins {
id 'fabric-loom' version '0.6-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
minecraft {
}
repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://jitpack.io" }
maven { url "https://maven.terraformersmc.com/releases" }
maven { url "https://aperlambda.github.io/maven" }
}
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"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
modImplementation ("com.github.TeamMidnightDust:CullLeaves:${project.cull_leaves_version}"){
exclude module: "modmenu"
}
modImplementation ("com.github.LambdAurora:LambDynamicLights:${project.ldl_version}") {
exclude module: "modmenu"
exclude module: "sodium-fabric"
}
modImplementation ("com.github.LambdAurora:LambdaBetterGrass:${project.lbg_version}") {
exclude module: "modmenu"
}
modImplementation ("com.github.The-HyperZone:Iris:${project.iris_version}") {
exclude module: "modmenu"
}
modImplementation ("com.github.PepperCode1:ConnectedTexturesMod-Fabric:${project.ctmf_version}") {
exclude module: "modmenu"
}
modImplementation ("com.github.LambdAurora:LambdaControls:${project.lc_version}") {
exclude module: "modmenu"
}
}
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"
}
}
// 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
}
jar {
from "LICENSE"
}
// 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()
}
}

25
gradle.properties Executable file
View File

@@ -0,0 +1,25 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.6
loader_version=0.11.3
# Mod Properties
mod_version = 0.1.0
maven_group = eu.midnightdust
archives_base_name = puzzle
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.32.5+1.16
mod_menu_version = 1.16.9
cull_leaves_version = 2.1.0
ldl_version = 1.3.4-1.16
lbg_version = 1.0.3-1.16
lc_version = 1.6.0-1.16
iris_version = 807b026
ctmf_version = v0.4.0

BIN
gradle/wrapper/gradle-wrapper.jar vendored Executable file

Binary file not shown.

5
gradle/wrapper/gradle-wrapper.properties vendored Executable file
View File

@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
gradlew vendored Executable file
View File

@@ -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" "$@"

89
gradlew.bat vendored Executable file
View File

@@ -0,0 +1,89 @@
@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 execute
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 execute
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
: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 %*
: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

10
settings.gradle Executable file
View File

@@ -0,0 +1,10 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

View File

@@ -0,0 +1,19 @@
package eu.midnightdust.puzzle;
import eu.midnightdust.puzzle.screen.widget.PuzzleWidget;
import net.minecraft.text.Text;
import java.util.ArrayList;
import java.util.List;
public class PuzzleApi {
public static List<PuzzleWidget> GRAPHICS_OPTIONS = new ArrayList<>();
public static List<PuzzleWidget> MISC_OPTIONS = new ArrayList<>();
public static List<PuzzleWidget> PERFORMANCE_OPTIONS = new ArrayList<>();
public static List<PuzzleWidget> TEXTURE_OPTIONS = new ArrayList<>();
public static void addToGraphicsOptions(PuzzleWidget button) {GRAPHICS_OPTIONS.add(button);}
public static void addToMiscOptions(PuzzleWidget button) {MISC_OPTIONS.add(button);}
public static void addToPerformanceOptions(PuzzleWidget button) {PERFORMANCE_OPTIONS.add(button);}
public static void addToTextureOptions(PuzzleWidget button) {TEXTURE_OPTIONS.add(button);}
}

View File

@@ -0,0 +1,59 @@
package eu.midnightdust.puzzle;
import eu.midnightdust.cullleaves.config.CullLeavesConfig;
import eu.midnightdust.puzzle.screen.widget.PuzzleWidget;
import me.lambdaurora.lambdabettergrass.LBGConfig;
import me.lambdaurora.lambdabettergrass.LambdaBetterGrass;
import me.lambdaurora.lambdynlights.DynamicLightsConfig;
import me.lambdaurora.lambdynlights.LambDynLights;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import team.chisel.ctm.client.CTMClient;
import team.chisel.ctm.client.config.ConfigManager;
public class PuzzleClient implements ClientModInitializer {
public static final Text YES = new TranslatableText("gui.yes").formatted(Formatting.GREEN);
public static final Text NO = new TranslatableText("gui.no").formatted(Formatting.RED);
@Override
public void onInitializeClient() {
if (FabricLoader.getInstance().isModLoaded("cullleaves")) {
PuzzleApi.addToPerformanceOptions(new PuzzleWidget(Text.of("Cull Leaves"), (button) -> button.setMessage(CullLeavesConfig.enabled ? YES : NO), (button) -> {
CullLeavesConfig.enabled = !CullLeavesConfig.enabled;
CullLeavesConfig.write();
MinecraftClient.getInstance().worldRenderer.reload();
}));
}
if (FabricLoader.getInstance().isModLoaded("lambdynlights")) {
DynamicLightsConfig ldlConfig = LambDynLights.get().config;
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(new TranslatableText("lambdynlights.option.mode"), (button) -> button.setMessage(ldlConfig.getDynamicLightsMode().getTranslatedText()), (button) -> ldlConfig.setDynamicLightsMode(ldlConfig.getDynamicLightsMode().next())));
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(new TranslatableText("lambdynlights.option.mode").append(": ").append(new TranslatableText("lambdynlights.option.entities")), (button) -> button.setMessage(ldlConfig.hasEntitiesLightSource() ? YES : NO), (button) -> ldlConfig.setEntitiesLightSource(!ldlConfig.hasEntitiesLightSource())));
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(new TranslatableText("lambdynlights.option.mode").append(": ").append(new TranslatableText("lambdynlights.option.block_entities")), (button) -> button.setMessage(ldlConfig.hasBlockEntitiesLightSource() ? YES : NO), (button) -> ldlConfig.setBlockEntitiesLightSource(!ldlConfig.hasBlockEntitiesLightSource())));
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(new TranslatableText("lambdynlights.option.mode").append(": ").append(new TranslatableText("entity.minecraft.creeper")), (button) -> button.setMessage(ldlConfig.getCreeperLightingMode().getTranslatedText()), (button) -> ldlConfig.setCreeperLightingMode(ldlConfig.getCreeperLightingMode().next())));
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(new TranslatableText("lambdynlights.option.mode").append(": ").append(new TranslatableText("block.minecraft.tnt")), (button) -> button.setMessage(ldlConfig.getTntLightingMode().getTranslatedText()), (button) -> ldlConfig.setTntLightingMode(ldlConfig.getTntLightingMode().next())));
PuzzleApi.addToGraphicsOptions(new PuzzleWidget(new TranslatableText("lambdynlights.option.mode").append(": ").append(new TranslatableText("lambdynlights.option.water_sensitive")), (button) -> button.setMessage(ldlConfig.hasWaterSensitiveCheck() ? YES : NO), (button) -> ldlConfig.setWaterSensitiveCheck(!ldlConfig.hasWaterSensitiveCheck())));
}
if (FabricLoader.getInstance().isModLoaded("ctm")) {
ConfigManager ctmfConfigManager = CTMClient.getConfigManager();
ConfigManager.Config ctmfConfig = CTMClient.getConfigManager().getConfig();
PuzzleApi.addToTextureOptions(new PuzzleWidget(new TranslatableText("puzzle.option.ctm"), (button) -> button.setMessage(ctmfConfig.disableCTM ? NO : YES), (button) -> {
ctmfConfig.disableCTM = !ctmfConfig.disableCTM;
ctmfConfigManager.onConfigChange();
}));
PuzzleApi.addToTextureOptions(new PuzzleWidget(new TranslatableText("puzzle.option.inside_ctm"), (button) -> button.setMessage(ctmfConfig.connectInsideCTM ? YES : NO), (button) -> {
ctmfConfig.connectInsideCTM = !ctmfConfig.connectInsideCTM;
ctmfConfigManager.onConfigChange();
}));
}
if (FabricLoader.getInstance().isModLoaded("lambdabettergrass")) {
LBGConfig lbgConfig = LambdaBetterGrass.get().config;
PuzzleApi.addToTextureOptions(new PuzzleWidget(new TranslatableText("lambdabettergrass.option.mode"), (button) -> button.setMessage(lbgConfig.getMode().getTranslatedText()), (button) -> lbgConfig.setMode(lbgConfig.getMode().next())));
PuzzleApi.addToTextureOptions(new PuzzleWidget(new TranslatableText("lambdabettergrass.option.better_snow"), (button) -> button.setMessage(lbgConfig.hasBetterLayer() ? YES : NO), (button) -> lbgConfig.setBetterLayer(!lbgConfig.hasBetterLayer())));
}
}
}

View File

@@ -0,0 +1,340 @@
package eu.midnightdust.puzzle.config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import java.lang.annotation.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;
// MidnightConfig v0.1.2
// Changelog:
// - The config screen no longer shows the entries of all instances of MidnightConfig
// - Compatible with servers!
/** Based on https://github.com/Minenash/TinyConfig
* Credits to Minenash - CC0-1.0 */
@SuppressWarnings({"rawtypes", "unchecked"})
public class MidnightConfig {
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
private static final List<EntryInfo> entries = new ArrayList<>();
protected static class EntryInfo {
Field field;
Object widget;
int width;
Method dynamicTooltip;
Map.Entry<TextFieldWidget,Text> error;
Object defaultValue;
Object value;
String tempValue;
boolean inLimits = true;
String id;
}
private static final Map<String,Class> configClass = new HashMap();
private static String translationPrefix;
private static Path path;
private static final Gson gson = new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
.excludeFieldsWithModifiers(Modifier.PRIVATE)
.setPrettyPrinting()
.create();
public static void init(String modid, Class<?> config) {
translationPrefix = modid + ".midnightconfig.";
path = FabricLoader.getInstance().getConfigDir().resolve(modid + ".json");
configClass.put(modid, config);
for (Field field : config.getFields()) {
Class<?> type = field.getType();
EntryInfo info = new EntryInfo();
Entry e;
try { e = field.getAnnotation(Entry.class); }
catch (Exception ignored) { continue; }
info.width = e.width();
info.field = field;
info.id = modid;
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<Object,Text> func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(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<Object,Text> func = value -> new TranslatableText(translationPrefix + "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);
}
else
continue;
entries.add(info);
try { info.defaultValue = field.get(null); }
catch (IllegalAccessException ignored) {}
try {
info.dynamicTooltip = config.getMethod(e.dynamicTooltip());
info.dynamicTooltip.setAccessible(true);
} catch (Exception ignored) {}
}
try { gson.fromJson(Files.newBufferedReader(path), config); }
catch (Exception e) { write(modid); }
for (EntryInfo info : entries) {
try {
info.value = info.field.get(null);
info.tempValue = info.value.toString();
}
catch (IllegalAccessException ignored) {}
}
}
public static void initServer(String modid, Class<?> config) {
translationPrefix = modid + ".midnightconfig.";
path = FabricLoader.getInstance().getConfigDir().resolve(modid + ".json");
configClass.put(modid,config);
try { gson.fromJson(Files.newBufferedReader(path), config); }
catch (Exception e) { write(modid); }
for (EntryInfo info : entries) {
try {
info.value = info.field.get(null);
info.tempValue = info.value.toString();
}
catch (IllegalAccessException ignored) {}
}
}
private static void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
boolean isNumber = pattern != null;
info.widget = (BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) (t, b) -> s -> {
s = s.trim();
if (!(s.isEmpty() || !isNumber || pattern.matcher(s).matches()))
return false;
Number value = 0;
boolean inLimits = false;
System.out.println(((isNumber ^ s.isEmpty())));
System.out.println(!s.equals("-") && !s.equals("."));
info.error = null;
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
value = f.apply(s);
inLimits = value.doubleValue() >= min && value.doubleValue() <= max;
info.error = inLimits? null : new AbstractMap.SimpleEntry<>(t, new LiteralText(value.doubleValue() < min ?
"§cMinimum " + (isNumber? "value" : "length") + (cast? " is " + (int)min : " is " + min) :
"§cMaximum " + (isNumber? "value" : "length") + (cast? " is " + (int)max : " is " + max)));
}
info.tempValue = s;
t.setEditableColor(inLimits? 0xFFFFFFFF : 0xFFFF7777);
info.inLimits = inLimits;
b.active = entries.stream().allMatch(e -> e.inLimits);
if (inLimits)
info.value = isNumber? value : s;
return true;
};
}
public static void write(String modid) {
path = FabricLoader.getInstance().getConfigDir().resolve(modid + ".json");
try {
if (!Files.exists(path)) Files.createFile(path);
Files.write(path, gson.toJson(configClass.get(modid).newInstance()).getBytes());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void update(String modid, Class<?> config) {
write(modid);
try { gson.fromJson(Files.newBufferedReader(path), config); }
catch (Exception e) { write(modid); }
for (EntryInfo info : entries) {
try {
info.value = info.field.get(null);
info.tempValue = info.value.toString();
}
catch (IllegalAccessException ignored) {}
}
}
@Environment(EnvType.CLIENT)
public static Screen getScreen(Screen parent, String modid) {
return new TinyConfigScreen(parent, modid);
}
@Environment(EnvType.CLIENT)
private static class TinyConfigScreen extends Screen {
protected TinyConfigScreen(Screen parent, String modid) {
super(new TranslatableText(modid + ".midnightconfig." + "title"));
this.parent = parent;
this.modid = modid;
this.translationPrefix = modid + ".midnightconfig.";
}
private final Screen parent;
private final String modid;
private final String translationPrefix;
// Real Time config update //
@Override
public void tick() {
for (EntryInfo info : entries)
try { info.field.set(null, info.value); }
catch (IllegalAccessException ignore) {}
}
@Override
protected void init() {
super.init();
this.addButton(new ButtonWidget(this.width / 2 - 154, this.height - 28, 150, 20, ScreenTexts.CANCEL, button -> {
try { gson.fromJson(Files.newBufferedReader(path), configClass.get(modid)); }
catch (Exception e) { write(modid); }
for (EntryInfo info : entries) {
try {
info.value = info.field.get(null);
info.tempValue = info.value.toString();
}
catch (IllegalAccessException ignored) {}
}
Objects.requireNonNull(client).openScreen(parent);
}));
ButtonWidget done = this.addButton(new ButtonWidget(this.width / 2 + 4, this.height - 28, 150, 20, ScreenTexts.DONE, (button) -> {
for (EntryInfo info : entries)
if (info.id.equals(modid)) {
try {
info.field.set(null, info.value);
} catch (IllegalAccessException ignore) {
}
}
write(modid);
Objects.requireNonNull(client).openScreen(parent);
}));
int y = 45;
for (EntryInfo info : entries) {
if (info.id.equals(modid)) {
addButton(new ButtonWidget(width - 155, y, 40, 20, new LiteralText("Reset").formatted(Formatting.RED), (button -> {
info.value = info.defaultValue;
info.tempValue = info.value.toString();
Objects.requireNonNull(client).openScreen(this);
})));
if (info.widget instanceof Map.Entry) {
Map.Entry<ButtonWidget.PressAction, Function<Object, Text>> widget = (Map.Entry<ButtonWidget.PressAction, Function<Object, Text>>) info.widget;
addButton(new ButtonWidget(width - 110, y, info.width, 20, widget.getValue().apply(info.value), widget.getKey()));
} else {
TextFieldWidget widget = addButton(new TextFieldWidget(textRenderer, width - 110, y, info.width, 20, null));
widget.setText(info.tempValue);
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(widget, done);
widget.setTextPredicate(processor);
children.add(widget);
}
y += 25;
}
}
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
int stringWidth = (int) (title.getString().length() * 2.75f);
this.fillGradient(matrices, this.width / 2 - stringWidth, 10, this.width /2 + stringWidth, 29, -1072689136, -804253680);
this.fillGradient(matrices, 0, 35, width, this.height - 40, -1072689136, -804253680);
super.render(matrices, mouseX, mouseY, delta);
//renderTooltip(matrices, title, width/2 - stringWidth, 27);
drawCenteredText(matrices, textRenderer, title, width/2, 15, 0xFFFFFF);
int y = 40;
for (EntryInfo info : entries) {
if (info.id.equals(modid)) {
drawTextWithShadow(matrices, textRenderer, new TranslatableText(translationPrefix + info.field.getName()), 12, y + 10, 0xFFFFFF);
if (info.error != null && info.error.getKey().isMouseOver(mouseX, mouseY))
renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
else if (mouseY >= y && mouseY < (y + 25)) {
if (info.dynamicTooltip != null) {
try {
renderTooltip(matrices, (List<Text>) info.dynamicTooltip.invoke(null, entries), mouseX, mouseY);
y += 25;
continue;
} catch (Exception e) {
e.printStackTrace();
}
}
String key = translationPrefix + info.field.getName() + ".tooltip";
if (I18n.hasTranslation(key)) {
List<Text> list = new ArrayList<>();
for (String str : I18n.translate(key).split("\n"))
list.add(new LiteralText(str));
renderTooltip(matrices, list, mouseX, mouseY);
}
}
y += 25;
}
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Entry {
String dynamicTooltip() default "";
int width() default 100;
double min() default Double.MIN_NORMAL;
double max() default Double.MAX_VALUE;
}
}

View File

@@ -0,0 +1,16 @@
package eu.midnightdust.puzzle.config;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import eu.midnightdust.puzzle.screen.PuzzleOptionsScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return PuzzleOptionsScreen::new;
}
}

View File

@@ -0,0 +1,29 @@
package eu.midnightdust.puzzle.mixin;
import eu.midnightdust.puzzle.screen.PuzzleOptionsScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.options.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(OptionsScreen.class)
public class MixinOptionsScreen extends Screen {
protected MixinOptionsScreen(Text title) {
super(title);
}
@Inject(at = @At("TAIL"),method = "init")
public void init(CallbackInfo ci) {
PuzzleOptionsScreen puzzleScreen = new PuzzleOptionsScreen(this);
this.addButton(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 144 - 6, 150, 20, new TranslatableText("puzzle.screen.title").append("..."), (button) -> {
this.client.openScreen(puzzleScreen);
}));
}
}

View File

@@ -0,0 +1,70 @@
package eu.midnightdust.puzzle.screen;
import eu.midnightdust.puzzle.screen.page.GraphicsPage;
import eu.midnightdust.puzzle.screen.page.MiscPage;
import eu.midnightdust.puzzle.screen.page.PerformancePage;
import eu.midnightdust.puzzle.screen.page.TexturesPage;
import net.coderbot.iris.gui.ShaderPackScreen;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import org.apache.logging.log4j.LogManager;
import java.util.Objects;
public class PuzzleOptionsScreen extends Screen {
public PuzzleOptionsScreen(Screen parent) {
super(new TranslatableText("puzzle.screen.title"));
this.parent = parent;
}
private final Screen parent;
@Override
protected void init() {
super.init();
GraphicsPage graphicsPage = new GraphicsPage(this);
MiscPage miscPage = new MiscPage(this);
PerformancePage performancePage = new PerformancePage(this);
TexturesPage texturesPage = new TexturesPage(this);
this.addButton(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 48 - 6, 150, 20, graphicsPage.getTitle().copy().append("..."), (button) -> {
Objects.requireNonNull(client).openScreen(graphicsPage);
}));
this.addButton(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 48 - 6, 150, 20, texturesPage.getTitle().copy().append("..."), (button) -> {
Objects.requireNonNull(client).openScreen(texturesPage);
}));
this.addButton(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 72 - 6, 150, 20, performancePage.getTitle().copy().append("..."), (button) -> {
Objects.requireNonNull(client).openScreen(performancePage);
}));
this.addButton(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 72 - 6, 150, 20, miscPage.getTitle().copy().append("..."), (button) -> {
Objects.requireNonNull(client).openScreen(miscPage);
}));
if (FabricLoader.getInstance().isModLoaded("iris")) {
try {
ShaderPackScreen shaderPackPage = new ShaderPackScreen(this);
this.addButton(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 96 - 6, 150, 20, shaderPackPage.getTitle().copy().append("..."), (button) -> {
Objects.requireNonNull(client).openScreen(shaderPackPage);
}));
}
catch (NoClassDefFoundError e) {
LogManager.getLogger("Puzzle").info("The shaderpack selection screen is not present, not adding it.");
}
}
this.addButton(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> {
Objects.requireNonNull(client).openScreen(parent);
}));
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
super.render(matrices, mouseX, mouseY, delta);
drawCenteredText(matrices, textRenderer, title, width/2, 15, 0xFFFFFF);
}
}

View File

@@ -0,0 +1,46 @@
package eu.midnightdust.puzzle.screen.page;
import eu.midnightdust.puzzle.screen.widget.PuzzleOptionListWidget;
import eu.midnightdust.puzzle.screen.widget.PuzzleWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import java.util.List;
import java.util.Objects;
public abstract class AbstractPuzzleOptionsPage extends Screen {
private PuzzleOptionListWidget list;
private final List<PuzzleWidget> options;
public AbstractPuzzleOptionsPage(Screen parent, TranslatableText title, List<PuzzleWidget> options) {
super(title);
this.parent = parent;
this.options = options;
}
private final Screen parent;
@Override
protected void init() {
this.list = new PuzzleOptionListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
list.addAll(options);
this.children.add(this.list);
super.init();
this.addButton(new ButtonWidget(this.width / 2 - 100, this.height - 28, 200, 20, ScreenTexts.DONE, (button) -> {
Objects.requireNonNull(client).openScreen(parent);
}));
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
this.list.render(matrices, mouseX, mouseY, delta);
drawCenteredText(matrices, textRenderer, title, width/2, 15, 0xFFFFFF);
super.render(matrices, mouseX, mouseY, delta);
}
}

View File

@@ -0,0 +1,13 @@
package eu.midnightdust.puzzle.screen.page;
import eu.midnightdust.puzzle.PuzzleApi;
import eu.midnightdust.puzzle.screen.page.AbstractPuzzleOptionsPage;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;
public class GraphicsPage extends AbstractPuzzleOptionsPage {
public GraphicsPage(Screen parent) {
super(parent, new TranslatableText("puzzle.page.graphics"), PuzzleApi.GRAPHICS_OPTIONS);
}
}

View File

@@ -0,0 +1,12 @@
package eu.midnightdust.puzzle.screen.page;
import eu.midnightdust.puzzle.PuzzleApi;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;
public class MiscPage extends AbstractPuzzleOptionsPage {
public MiscPage(Screen parent) {
super(parent, new TranslatableText("puzzle.page.misc"), PuzzleApi.MISC_OPTIONS);
}
}

View File

@@ -0,0 +1,12 @@
package eu.midnightdust.puzzle.screen.page;
import eu.midnightdust.puzzle.PuzzleApi;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;
public class PerformancePage extends AbstractPuzzleOptionsPage {
public PerformancePage(Screen parent) {
super(parent, new TranslatableText("puzzle.page.performance"), PuzzleApi.PERFORMANCE_OPTIONS);
}
}

View File

@@ -0,0 +1,13 @@
package eu.midnightdust.puzzle.screen.page;
import eu.midnightdust.puzzle.PuzzleApi;
import eu.midnightdust.puzzle.screen.page.AbstractPuzzleOptionsPage;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;
public class TexturesPage extends AbstractPuzzleOptionsPage {
public TexturesPage(Screen parent) {
super(parent, new TranslatableText("puzzle.page.textures"), PuzzleApi.TEXTURE_OPTIONS);
}
}

View File

@@ -0,0 +1,5 @@
package eu.midnightdust.puzzle.screen.widget;
public enum ButtonType {
BUTTON, SLIDER, TEXT_FIELD
}

View File

@@ -0,0 +1,19 @@
package eu.midnightdust.puzzle.screen.widget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
public class PuzzleButtonWidget extends ButtonWidget {
private final PuzzleWidget.TextAction title;
public PuzzleButtonWidget(int x, int y, int width, int height, PuzzleWidget.TextAction title, PressAction onPress) {
super(x, y, width, height, Text.of(""), onPress);
this.title = title;
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
title.setTitle(this);
super.renderButton(matrices, mouseX, mouseY, delta);
}
}

View File

@@ -0,0 +1,94 @@
package eu.midnightdust.puzzle.screen.widget;
import com.google.common.collect.ImmutableMap;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ElementListWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.apache.logging.log4j.LogManager;
import java.util.*;
@Environment(EnvType.CLIENT)
public class PuzzleOptionListWidget extends ElementListWidget<PuzzleOptionListWidget.ButtonEntry> {
TextRenderer textRenderer;
public PuzzleOptionListWidget(MinecraftClient minecraftClient, int i, int j, int k, int l, int m) {
super(minecraftClient, i, j, k, l, m);
this.centerListVertically = false;
textRenderer = minecraftClient.textRenderer;
}
public void addButton(AbstractButtonWidget button, Text text) {
this.addEntry(ButtonEntry.create(button, text));
}
public void addAll(List<PuzzleWidget> buttons) {
for (int i = 0; i < buttons.size(); ++i) {
PuzzleWidget button = buttons.get(i);
if (button.buttonType == ButtonType.BUTTON) {
this.addButton(new PuzzleButtonWidget(this.width / 2 - 155 + 160, 0, 150, 20, button.buttonTextAction, button.onPress), button.descriptionText);
}
else if (button.buttonType == ButtonType.SLIDER) {
this.addButton(new PuzzleSliderWidget(button.min,button.max,this.width / 2 - 155 + 160, 0, 150, 20, ((TranslatableText) button.buttonText),1), button.descriptionText);
}
else if (button.buttonType == ButtonType.TEXT_FIELD) {
this.addButton(new PuzzleTextFieldWidget(textRenderer,this.width / 2 - 155 + 160, 0, 150, 20,null, button.buttonText), button.descriptionText);
}
else LogManager.getLogger("Puzzle").warn("Button " + button + " is missing the buttonType variable. This shouldn't happen!");
}
}
public int getRowWidth() {
return 400;
}
protected int getScrollbarPositionX() {
return super.getScrollbarPositionX() + 32;
}
public Optional<AbstractButtonWidget> getHoveredButton(double mouseX, double mouseY) {
for (ButtonEntry buttonEntry : this.children()) {
for (AbstractButtonWidget abstractButtonWidget : buttonEntry.buttons) {
if (abstractButtonWidget.isMouseOver(mouseX, mouseY)) {
return Optional.of(abstractButtonWidget);
}
}
}
return Optional.empty();
}
public static class ButtonEntry extends ElementListWidget.Entry<ButtonEntry> {
private static final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
private final List<AbstractButtonWidget> buttons;
private final Map<AbstractButtonWidget, Text> buttonsWithText;
private ButtonEntry(ImmutableMap<AbstractButtonWidget, Text> buttons) {
this.buttons = buttons.keySet().asList();
this.buttonsWithText = buttons;
}
public static ButtonEntry create(AbstractButtonWidget button, Text text) {
return new ButtonEntry(ImmutableMap.of(button, text));
}
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
this.buttonsWithText.forEach((button, text) -> {
button.y = y;
button.render(matrices, mouseX, mouseY, tickDelta);
drawTextWithShadow(matrices,textRenderer, text,x+15,y+5,0xFFFFFF);
});
}
public List<? extends Element> children() {
return buttons;
}
}
}

View File

@@ -0,0 +1,29 @@
package eu.midnightdust.puzzle.screen.widget;
import net.minecraft.client.gui.widget.SliderWidget;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
public class PuzzleSliderWidget extends SliderWidget {
private final int min;
private final double difference;
public PuzzleSliderWidget(int min, int max, int x, int y, int width, int height, TranslatableText label, double value) {
super(x,y,width,height,label,value);
this.updateMessage();
this.min = min;
this.difference = max - min;
}
@Override
protected void updateMessage() {
Text text = new LiteralText((int) (min + this.value * difference) + "");
this.setMessage(new TranslatableText("label").append(": ").append((Text) text));
}
@Override
protected void applyValue() {
}
}

View File

@@ -0,0 +1,17 @@
package eu.midnightdust.puzzle.screen.widget;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.SliderWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import org.jetbrains.annotations.Nullable;
public class PuzzleTextFieldWidget extends TextFieldWidget {
private TranslatableText label;
public PuzzleTextFieldWidget(TextRenderer textRenderer, int x, int y, int width, int height, @Nullable TextFieldWidget copyFrom, Text text) {
super(textRenderer, x, y, width, height, text);
}
}

View File

@@ -0,0 +1,58 @@
package eu.midnightdust.puzzle.screen.widget;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
public class PuzzleWidget {
public ButtonType buttonType;
public int min;
public int max;
public Text descriptionText;
public Text buttonText;
public TextAction buttonTextAction;
public ButtonWidget.PressAction onPress;
public PuzzleWidget.SaveAction onSave;
/**
* Puzzle Button Widget Container
* @param descriptionText Tells the user what the option does.
* @param getTitle Function to set the text on the button.
* @param onPress Function to call when the user presses the button.
*/
public PuzzleWidget(Text descriptionText, PuzzleWidget.TextAction getTitle, ButtonWidget.PressAction onPress) {
this.buttonType = ButtonType.BUTTON;
this.descriptionText = descriptionText;
this.buttonTextAction = getTitle;
this.onPress = onPress;
}
/**
* Puzzle Slider Widget Container (WIP - Doesn't work)
*/
public PuzzleWidget(int min, int max, Text descriptionText, TranslatableText buttonText) {
this.buttonType = ButtonType.SLIDER;
this.min = min;
this.max = max;
this.descriptionText = descriptionText;
this.buttonText = buttonText;
}
/**
* Puzzle Text Field Widget Container (WIP - Doesn't work)
*/
public PuzzleWidget(Text descriptionText, Text buttonText) {
this.buttonType = ButtonType.TEXT_FIELD;
this.descriptionText = descriptionText;
this.buttonText = buttonText;
}
@Environment(EnvType.CLIENT)
public interface SaveAction {
void onSave(AbstractButtonWidget button);
}
@Environment(EnvType.CLIENT)
public interface TextAction {
void setTitle(AbstractButtonWidget button);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -0,0 +1,9 @@
{
"puzzle.screen.title":"Puzzle Settings",
"puzzle.page.graphics":"Graphics Settings",
"puzzle.page.textures":"Texture Settings",
"puzzle.page.performance":"Performance Settings",
"puzzle.page.misc":"Miscellaneous Settings",
"puzzle.option.ctm":"Connected Textures",
"puzzle.option.inside_ctm":"Connect Inside Textures"
}

Binary file not shown.

View File

@@ -0,0 +1,38 @@
{
"schemaVersion": 1,
"id": "puzzle",
"version": "${version}",
"name": "Puzzle",
"description": "Unites optifine replacement mods in a clean & vanilla-style gui",
"authors": [
"Motschen",
"TeamMidnightDust"
],
"contact": {
"homepage": "https://www.midnightdust.eu/",
"sources": "https://github.com/TeamMidnightDust/Puzzle",
"issues": "https://github.com/TeamMidnightDust/Puzzle/issues"
},
"license": "MIT",
"icon": "assets/puzzle/icon.png",
"environment": "*",
"entrypoints": {
"client": [
"eu.midnightdust.puzzle.PuzzleClient"
],
"modmenu": [
"eu.midnightdust.puzzle.config.ModMenuIntegration"
]
},
"mixins": [
"puzzle.mixins.json"
],
"depends": {
"fabric": "*"
}
}

View File

@@ -0,0 +1,11 @@
{
"required": true,
"package": "eu.midnightdust.puzzle.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinOptionsScreen"
],
"injectors": {
"defaultRequire": 1
}
}