Initial commit
This commit is contained in:
commit
231c0e3b8f
118
.gitignore
vendored
Normal file
118
.gitignore
vendored
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
# 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
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2023 CameronReed
|
||||||
|
|
||||||
|
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.
|
86
build.gradle
Normal file
86
build.gradle
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
plugins {
|
||||||
|
id 'fabric-loom' version '1.1-SNAPSHOT'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
version = project.mod_version
|
||||||
|
group = project.maven_group
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Add repositories to retrieve artifacts from in here.
|
||||||
|
// You should only use this when depending on other mods because
|
||||||
|
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||||
|
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||||
|
// for more information about repositories.
|
||||||
|
maven {
|
||||||
|
name = 'TerraformersMC'
|
||||||
|
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}"
|
||||||
|
modCompileOnly "com.terraformersmc:modmenu:4.1.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
inputs.property "version", project.version
|
||||||
|
filteringCharset "UTF-8"
|
||||||
|
|
||||||
|
filesMatching("fabric.mod.json") {
|
||||||
|
expand "version": project.version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def targetJavaVersion = 17
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
// 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
|
||||||
|
// If Javadoc is generated, this must be specified in that task too.
|
||||||
|
it.options.encoding = "UTF-8"
|
||||||
|
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||||
|
it.options.release = targetJavaVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
|
if (JavaVersion.current() < javaVersion) {
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||||
|
}
|
||||||
|
archivesBaseName = project.archives_base_name
|
||||||
|
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||||
|
// if it is present.
|
||||||
|
// If you remove this line, sources will not be generated.
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from("LICENSE") {
|
||||||
|
rename { "${it}_${project.archivesBaseName}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure the maven publication
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
mavenJava(MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||||
|
repositories {
|
||||||
|
// Add repositories to publish to here.
|
||||||
|
// Notice: This block does NOT have the same function as the block in the top level.
|
||||||
|
// The repositories here will be used for publishing your artifact, not for
|
||||||
|
// retrieving dependencies.
|
||||||
|
}
|
||||||
|
}
|
14
gradle.properties
Normal file
14
gradle.properties
Normal file
|
@ -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.19.3
|
||||||
|
yarn_mappings=1.19.3+build.5
|
||||||
|
loader_version=0.14.13
|
||||||
|
# Mod Properties
|
||||||
|
mod_version=1.0.0
|
||||||
|
maven_group=cmods
|
||||||
|
archives_base_name=cmods
|
||||||
|
# Dependencies
|
||||||
|
# check this on https://modmuss50.me/fabric.html
|
||||||
|
fabric_version=0.73.0+1.19.3
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
234
gradlew
vendored
Executable file
234
gradlew
vendored
Executable file
|
@ -0,0 +1,234 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original 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 POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=${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 "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# 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 ;; #(
|
||||||
|
MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command;
|
||||||
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal 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
|
9
settings.gradle
Normal file
9
settings.gradle
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
}
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
9
src/main/java/cmods/cmods/api/ButtonBuilder.java
Normal file
9
src/main/java/cmods/cmods/api/ButtonBuilder.java
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package cmods.cmods.api;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
|
||||||
|
public interface ButtonBuilder {
|
||||||
|
ButtonWidget build(Screen screen, MinecraftClient client);
|
||||||
|
}
|
25
src/main/java/cmods/cmods/api/HudRenderCallback.java
Normal file
25
src/main/java/cmods/cmods/api/HudRenderCallback.java
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package cmods.cmods.api;
|
||||||
|
|
||||||
|
import cmods.cmods.client.ui.Line;
|
||||||
|
import net.minecraft.util.Pair;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public interface HudRenderCallback {
|
||||||
|
|
||||||
|
ArrayList<Pair<Consumer<ArrayList<Line>>, Integer>> callbacks = new ArrayList<>();
|
||||||
|
|
||||||
|
static void addCallback(Consumer<ArrayList<Line>> callback, int precedence) {
|
||||||
|
Pair<Consumer<ArrayList<Line>>, Integer> renderCallback = new Pair<>(callback, precedence);
|
||||||
|
|
||||||
|
for (int i = 0; i < callbacks.size(); i++) {
|
||||||
|
if (callbacks.get(i).getRight() > precedence) {
|
||||||
|
callbacks.add(i, renderCallback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callbacks.add(renderCallback);
|
||||||
|
}
|
||||||
|
}
|
49
src/main/java/cmods/cmods/api/Module.java
Normal file
49
src/main/java/cmods/cmods/api/Module.java
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package cmods.cmods.api;
|
||||||
|
|
||||||
|
import cmods.cmods.client.options.CmodsOptions;
|
||||||
|
import cmods.cmods.client.ui.CmodsOptionsScreen;
|
||||||
|
import cmods.cmods.client.ui.Line;
|
||||||
|
import cmods.cmods.client.ui.UIOptionsScreen;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class Module {
|
||||||
|
private final int precedence;
|
||||||
|
|
||||||
|
private final ModuleOptions options;
|
||||||
|
|
||||||
|
private final ArrayList<ButtonBuilder> optionButtons;
|
||||||
|
|
||||||
|
private final ArrayList<ButtonBuilder> uiOptions;
|
||||||
|
|
||||||
|
private final Consumer<ArrayList<Line>> hudDrawCallback;
|
||||||
|
|
||||||
|
public Module(int precedence, @Nullable ModuleOptions options, @Nullable ArrayList<ButtonBuilder> optionButtons,
|
||||||
|
@Nullable ArrayList<ButtonBuilder> uiOptions, Consumer<ArrayList<Line>> hudDrawCallback) {
|
||||||
|
this.precedence = precedence;
|
||||||
|
this.options = options;
|
||||||
|
this.optionButtons = optionButtons;
|
||||||
|
this.uiOptions = uiOptions;
|
||||||
|
this.hudDrawCallback = hudDrawCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void register() {
|
||||||
|
if (options != null) {
|
||||||
|
CmodsOptions.addOptions(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hudDrawCallback != null) {
|
||||||
|
HudRenderCallback.addCallback(hudDrawCallback, precedence);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uiOptions != null) {
|
||||||
|
UIOptionsScreen.addButtons(uiOptions, precedence);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optionButtons != null) {
|
||||||
|
CmodsOptionsScreen.addExtraButtons(optionButtons, precedence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/main/java/cmods/cmods/api/ModuleOptions.java
Normal file
10
src/main/java/cmods/cmods/api/ModuleOptions.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package cmods.cmods.api;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public abstract class ModuleOptions {
|
||||||
|
public abstract void save(Properties properties);
|
||||||
|
public abstract void load(@Nullable Properties properties);
|
||||||
|
}
|
22
src/main/java/cmods/cmods/client/CmodsClient.java
Normal file
22
src/main/java/cmods/cmods/client/CmodsClient.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package cmods.cmods.client;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public class CmodsClient implements ClientModInitializer {
|
||||||
|
public static String MOD_ID = "cmods";
|
||||||
|
public static String version = "Unknown";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
Optional<ModContainer> modContainer = FabricLoader.getInstance().getModContainer(MOD_ID);
|
||||||
|
modContainer.ifPresentOrElse(container -> version = container.getMetadata().getVersion().getFriendlyString(),
|
||||||
|
() -> System.out.println("Cmods: Could not get mod version"));
|
||||||
|
}
|
||||||
|
}
|
13
src/main/java/cmods/cmods/client/ModMenuConfig.java
Normal file
13
src/main/java/cmods/cmods/client/ModMenuConfig.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package cmods.cmods.client;
|
||||||
|
|
||||||
|
import cmods.cmods.client.ui.CmodsOptionsScreen;
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
|
||||||
|
public class ModMenuConfig implements ModMenuApi {
|
||||||
|
@Override
|
||||||
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
|
return (ConfigScreenFactory<Screen>) CmodsOptionsScreen::new;
|
||||||
|
}
|
||||||
|
}
|
11
src/main/java/cmods/cmods/client/options/BooleanOption.java
Normal file
11
src/main/java/cmods/cmods/client/options/BooleanOption.java
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package cmods.cmods.client.options;
|
||||||
|
|
||||||
|
public class BooleanOption extends Option<Boolean> {
|
||||||
|
public BooleanOption(Boolean default_value) {
|
||||||
|
super(default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean toggle() {
|
||||||
|
return value = !value;
|
||||||
|
}
|
||||||
|
}
|
112
src/main/java/cmods/cmods/client/options/CmodsOptions.java
Normal file
112
src/main/java/cmods/cmods/client/options/CmodsOptions.java
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
package cmods.cmods.client.options;
|
||||||
|
|
||||||
|
import cmods.cmods.api.ModuleOptions;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public final class CmodsOptions {
|
||||||
|
private static CmodsOptions instance = null;
|
||||||
|
|
||||||
|
private static final Path properties_file = FabricLoader.getInstance().getConfigDir().resolve("Cmods.properties");
|
||||||
|
|
||||||
|
public final UIOptions uiOptions;
|
||||||
|
private static final ArrayList<ModuleOptions> moduleOptions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
public static CmodsOptions getInstance() {
|
||||||
|
if (instance == null)
|
||||||
|
instance = new CmodsOptions();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CmodsOptions() {
|
||||||
|
uiOptions = new UIOptions();
|
||||||
|
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addOptions(ModuleOptions options) {
|
||||||
|
getInstance().load(options);
|
||||||
|
moduleOptions.add(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
try (FileReader reader = new FileReader(properties_file.toFile())) {
|
||||||
|
properties.load(reader);
|
||||||
|
} catch (IOException e) {
|
||||||
|
properties = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sub category properties
|
||||||
|
uiOptions.load(properties);
|
||||||
|
|
||||||
|
for (ModuleOptions options : moduleOptions) {
|
||||||
|
options.load(properties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load(ModuleOptions options) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
try(FileReader reader = new FileReader(properties_file.toFile())) {
|
||||||
|
properties.load(reader);
|
||||||
|
} catch (IOException e) {
|
||||||
|
properties = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
options.load(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
|
||||||
|
// Sub category properties
|
||||||
|
uiOptions.save(properties);
|
||||||
|
|
||||||
|
for (ModuleOptions options: moduleOptions) {
|
||||||
|
options.save(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
properties.store(new FileWriter(properties_file.toFile()), "Cmods Properties");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("[Cmods]: Failed to save properties");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean getBooleanProperty(@Nullable Properties properties, String key, Boolean default_value) {
|
||||||
|
if (properties == null)
|
||||||
|
return default_value;
|
||||||
|
return Boolean.parseBoolean(properties.getProperty(key, default_value.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class UIOptions {
|
||||||
|
private final String PREFIX = "ui.";
|
||||||
|
|
||||||
|
public BooleanOption enabled = new BooleanOption(true);
|
||||||
|
public BooleanOption show_coordinates = new BooleanOption(true);
|
||||||
|
|
||||||
|
|
||||||
|
UIOptions() { }
|
||||||
|
|
||||||
|
|
||||||
|
void load(@Nullable Properties properties) {
|
||||||
|
enabled.value = getBooleanProperty(properties, PREFIX + "enabled", true);
|
||||||
|
show_coordinates.value = getBooleanProperty(properties, PREFIX + "show_coordinates", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void save(Properties properties) {
|
||||||
|
properties.setProperty(PREFIX + "enabled", enabled.value.toString());
|
||||||
|
properties.setProperty(PREFIX + "show_coordinates", show_coordinates.value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/main/java/cmods/cmods/client/options/IntegerOption.java
Normal file
23
src/main/java/cmods/cmods/client/options/IntegerOption.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package cmods.cmods.client.options;
|
||||||
|
|
||||||
|
public class IntegerOption extends Option<Integer> {
|
||||||
|
public IntegerOption(Integer default_value) {
|
||||||
|
super(default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer inc() {
|
||||||
|
return inc(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer inc(int amount) {
|
||||||
|
return value += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer dec() {
|
||||||
|
return dec(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer dec(int amount) {
|
||||||
|
return value -= amount;
|
||||||
|
}
|
||||||
|
}
|
17
src/main/java/cmods/cmods/client/options/Option.java
Normal file
17
src/main/java/cmods/cmods/client/options/Option.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package cmods.cmods.client.options;
|
||||||
|
|
||||||
|
public class Option<T> {
|
||||||
|
public T value;
|
||||||
|
|
||||||
|
public Option(T default_value) {
|
||||||
|
value = default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(T new_value) {
|
||||||
|
value = new_value;
|
||||||
|
}
|
||||||
|
}
|
84
src/main/java/cmods/cmods/client/ui/CmodsOptionsScreen.java
Normal file
84
src/main/java/cmods/cmods/client/ui/CmodsOptionsScreen.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
package cmods.cmods.client.ui;
|
||||||
|
|
||||||
|
import cmods.cmods.api.ButtonBuilder;
|
||||||
|
import cmods.cmods.client.CmodsClient;
|
||||||
|
import cmods.cmods.client.options.CmodsOptions;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.GridWidget;
|
||||||
|
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.screen.ScreenTexts;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Pair;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static cmods.cmods.client.ui.Constants.*;
|
||||||
|
|
||||||
|
public class CmodsOptionsScreen extends Screen {
|
||||||
|
private final CmodsOptions options = CmodsOptions.getInstance();
|
||||||
|
private final Screen parent;
|
||||||
|
|
||||||
|
private static final ArrayList<Pair<ArrayList<ButtonBuilder>, Integer>> extraWidgets = new ArrayList<>();
|
||||||
|
|
||||||
|
public CmodsOptionsScreen(Screen parent) {
|
||||||
|
super(Text.translatable("cmods.options.title"));
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init() {
|
||||||
|
if (client == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
|
||||||
|
|
||||||
|
GridWidget grid = new GridWidget();
|
||||||
|
grid.getMainPositioner().marginX(5).marginBottom(4).alignHorizontalCenter();
|
||||||
|
GridWidget.Adder adder = grid.createAdder(2);
|
||||||
|
|
||||||
|
adder.add(ButtonWidget.builder(Text.translatable("cmods.options.ui"),
|
||||||
|
button -> this.client.setScreen(new UIOptionsScreen(this))).build());
|
||||||
|
|
||||||
|
for (Pair<ArrayList<ButtonBuilder>, Integer> buttons : extraWidgets) {
|
||||||
|
for (ButtonBuilder buttonBuilder : buttons.getLeft()) {
|
||||||
|
adder.add(buttonBuilder.build(this, client));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent))
|
||||||
|
.width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement));
|
||||||
|
|
||||||
|
grid.recalculateDimensions();
|
||||||
|
SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f);
|
||||||
|
addDrawableChild(grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addExtraButtons(ArrayList<ButtonBuilder> buttons, int precedence) {
|
||||||
|
Pair<ArrayList<ButtonBuilder>, Integer> newPair = new Pair<>(buttons, precedence);
|
||||||
|
|
||||||
|
for (int i = 0; i < extraWidgets.size(); i++) {
|
||||||
|
if (extraWidgets.get(i).getRight() > precedence) {
|
||||||
|
extraWidgets.add(i, newPair);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extraWidgets.add(newPair);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
renderBackground(matrices);
|
||||||
|
Text versionText = Text.literal("v" + CmodsClient.version);
|
||||||
|
|
||||||
|
|
||||||
|
drawCenteredText(matrices, textRenderer, title, this.width / 2, 15, 0xffffff);
|
||||||
|
drawTextWithShadow(matrices, textRenderer, versionText, this.width - textRenderer.getWidth(versionText) - 2,
|
||||||
|
this.height - textRenderer.fontHeight - 2, 0xffffff);
|
||||||
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removed() {
|
||||||
|
options.save();
|
||||||
|
}
|
||||||
|
}
|
14
src/main/java/cmods/cmods/client/ui/Constants.java
Normal file
14
src/main/java/cmods/cmods/client/ui/Constants.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package cmods.cmods.client.ui;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
public static final int buttonWidth = 150;
|
||||||
|
public static final int buttonHeight = 20;
|
||||||
|
public static final int column1_offset = -5 - buttonWidth;
|
||||||
|
public static final int column2_offset = 5;
|
||||||
|
public static final float startHeight_multiplier = 1.0f / 6.0f;
|
||||||
|
public static final int rowIncrement = buttonHeight + 5;
|
||||||
|
|
||||||
|
public static final int doneButtonWidth = buttonWidth + buttonWidth / 3;
|
||||||
|
public static final int doneButtonX_offset = -(doneButtonWidth / 2);
|
||||||
|
public static final int doneButtonRowIncrement = rowIncrement + 4;
|
||||||
|
}
|
80
src/main/java/cmods/cmods/client/ui/IntegerAdjustWidget.java
Normal file
80
src/main/java/cmods/cmods/client/ui/IntegerAdjustWidget.java
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
package cmods.cmods.client.ui;
|
||||||
|
|
||||||
|
import cmods.cmods.client.options.IntegerOption;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||||
|
import net.minecraft.client.gui.widget.WrapperWidget;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class IntegerAdjustWidget extends WrapperWidget {
|
||||||
|
private final ArrayList<ButtonWidget> children;
|
||||||
|
private final IntegerOption option;
|
||||||
|
private final int delta;
|
||||||
|
|
||||||
|
public IntegerAdjustWidget(Text text, IntegerOption option) {
|
||||||
|
this(text, option, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegerAdjustWidget(Text text, IntegerOption option, int delta) {
|
||||||
|
super(0, 0, 150, 20, text);
|
||||||
|
this.option = option;
|
||||||
|
this.delta = delta;
|
||||||
|
children = new ArrayList<>(3);
|
||||||
|
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<? extends ClickableWidget> wrappedWidgets() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWidth(int width) {
|
||||||
|
super.setWidth(width);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setX(int x) {
|
||||||
|
super.setX(x);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setY(int y) {
|
||||||
|
super.setY(y);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPos(int x, int y) {
|
||||||
|
super.setPos(x, y);
|
||||||
|
refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshDimensions() {
|
||||||
|
final int button_width = 25;
|
||||||
|
final String labelStr = getMessage().getString() + ": ";
|
||||||
|
|
||||||
|
children.clear();
|
||||||
|
|
||||||
|
ButtonWidget middle = ButtonWidget.builder(Text.literal(labelStr + option.get()), button -> {})
|
||||||
|
.dimensions(getX() + button_width - 1, getY(),width - (button_width * 2) + 2, height).build();
|
||||||
|
|
||||||
|
ButtonWidget sub = ButtonWidget.builder(Text.literal("-"),
|
||||||
|
button -> middle.setMessage(Text.literal(labelStr + option.dec(delta))))
|
||||||
|
.dimensions(getX(), getY(), button_width, height).build();
|
||||||
|
|
||||||
|
ButtonWidget add = ButtonWidget.builder(Text.literal("+"),
|
||||||
|
button -> middle.setMessage(Text.literal(labelStr + option.inc(delta))))
|
||||||
|
.dimensions(getX() + width - button_width + 1, getY(), button_width, height).build();
|
||||||
|
|
||||||
|
children.add(sub);
|
||||||
|
children.add(middle);
|
||||||
|
children.add(add);
|
||||||
|
}
|
||||||
|
}
|
5
src/main/java/cmods/cmods/client/ui/Line.java
Normal file
5
src/main/java/cmods/cmods/client/ui/Line.java
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package cmods.cmods.client.ui;
|
||||||
|
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public record Line(Text text, int color, int indent) { }
|
43
src/main/java/cmods/cmods/client/ui/ToggleButton.java
Normal file
43
src/main/java/cmods/cmods/client/ui/ToggleButton.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package cmods.cmods.client.ui;
|
||||||
|
|
||||||
|
import cmods.cmods.client.options.BooleanOption;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.apache.http.util.TextUtils;
|
||||||
|
|
||||||
|
public class ToggleButton extends ButtonWidget {
|
||||||
|
private final String name;
|
||||||
|
private final BooleanOption option;
|
||||||
|
|
||||||
|
private final String enabledText = Text.translatable("cmods.state.enabled").getString();
|
||||||
|
private final String disabledText = Text.translatable("cmods.state.disabled").getString();
|
||||||
|
|
||||||
|
|
||||||
|
public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option) {
|
||||||
|
this(x, y, width, height, name, option, ButtonWidget.DEFAULT_NARRATION_SUPPLIER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option,
|
||||||
|
NarrationSupplier narrationSupplier) {
|
||||||
|
super(x, y, width, height, name, b -> {}, narrationSupplier);
|
||||||
|
this.name = !TextUtils.isEmpty(name.getString()) ? name.getString() + ": " : "";
|
||||||
|
this.option = option;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateText() {
|
||||||
|
setMessage(Text.literal(name + (option.get() ? enabledText : disabledText)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPress() {
|
||||||
|
option.toggle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
updateText();
|
||||||
|
super.renderButton(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
}
|
81
src/main/java/cmods/cmods/client/ui/UIOptionsScreen.java
Normal file
81
src/main/java/cmods/cmods/client/ui/UIOptionsScreen.java
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package cmods.cmods.client.ui;
|
||||||
|
|
||||||
|
import cmods.cmods.api.ButtonBuilder;
|
||||||
|
import cmods.cmods.client.options.CmodsOptions;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.GridWidget;
|
||||||
|
import net.minecraft.client.gui.widget.SimplePositioningWidget;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.screen.ScreenTexts;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Pair;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static cmods.cmods.client.ui.Constants.*;
|
||||||
|
|
||||||
|
public class UIOptionsScreen extends Screen {
|
||||||
|
private final Screen parent;
|
||||||
|
private final CmodsOptions options = CmodsOptions.getInstance();
|
||||||
|
|
||||||
|
private static final ArrayList<Pair<ArrayList<ButtonBuilder>, Integer>> extraButtons = new ArrayList<>();
|
||||||
|
|
||||||
|
public UIOptionsScreen(Screen parent) {
|
||||||
|
super(Text.translatable("cmods.options.ui.title"));
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init() {
|
||||||
|
if (client == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
|
||||||
|
|
||||||
|
GridWidget grid = new GridWidget();
|
||||||
|
grid.getMainPositioner().marginX(5).marginBottom(4).alignHorizontalCenter();
|
||||||
|
GridWidget.Adder adder = grid.createAdder(2);
|
||||||
|
|
||||||
|
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||||
|
Text.translatable("cmods.options.ui.hud_enabled"), options.uiOptions.enabled));
|
||||||
|
|
||||||
|
adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight,
|
||||||
|
Text.translatable("cmods.options.ui.show_coordinates"), options.uiOptions.show_coordinates));
|
||||||
|
|
||||||
|
for (Pair<ArrayList<ButtonBuilder>, Integer> buttonArray : extraButtons) {
|
||||||
|
for (ButtonBuilder buttonBuilder : buttonArray.getLeft()) {
|
||||||
|
adder.add(buttonBuilder.build(this, client));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent))
|
||||||
|
.width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement));
|
||||||
|
|
||||||
|
grid.recalculateDimensions();
|
||||||
|
SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f);
|
||||||
|
addDrawableChild(grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addButtons(ArrayList<ButtonBuilder> buttons, int precedence) {
|
||||||
|
Pair<ArrayList<ButtonBuilder>, Integer> newPair = new Pair<>(buttons, precedence);
|
||||||
|
|
||||||
|
for (int i = 0; i < extraButtons.size(); i++) {
|
||||||
|
if (extraButtons.get(i).getRight() > precedence) {
|
||||||
|
extraButtons.add(i, newPair);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extraButtons.add(newPair);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
this.renderBackground(matrices);
|
||||||
|
drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 0xffffff);
|
||||||
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removed() {
|
||||||
|
options.save();
|
||||||
|
}
|
||||||
|
}
|
74
src/main/java/cmods/cmods/mixin/HudMixin.java
Normal file
74
src/main/java/cmods/cmods/mixin/HudMixin.java
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
package cmods.cmods.mixin;
|
||||||
|
|
||||||
|
import cmods.cmods.client.options.CmodsOptions;
|
||||||
|
import cmods.cmods.api.HudRenderCallback;
|
||||||
|
import cmods.cmods.client.ui.Line;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.font.TextRenderer;
|
||||||
|
import net.minecraft.client.gui.DrawableHelper;
|
||||||
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Pair;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@Mixin(InGameHud.class)
|
||||||
|
public abstract class HudMixin extends DrawableHelper {
|
||||||
|
|
||||||
|
@Shadow @Final private MinecraftClient client;
|
||||||
|
@Shadow public abstract TextRenderer getTextRenderer();
|
||||||
|
|
||||||
|
|
||||||
|
@Inject(at = @At("TAIL"), method = "render")
|
||||||
|
private void render(MatrixStack matrices, float tickDelta, CallbackInfo ci) {
|
||||||
|
CmodsOptions options = CmodsOptions.getInstance();
|
||||||
|
|
||||||
|
if (this.client.options.debugEnabled || this.client.isPaused() || client.player == null ||
|
||||||
|
!options.uiOptions.enabled.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextRenderer textRenderer = this.getTextRenderer();
|
||||||
|
ArrayList<Line> lines = new ArrayList<>();
|
||||||
|
|
||||||
|
int x = 5;
|
||||||
|
int y = 5;
|
||||||
|
|
||||||
|
int white = 0xffffff;
|
||||||
|
|
||||||
|
|
||||||
|
if (options.uiOptions.show_coordinates.get()) {
|
||||||
|
BlockPos pos = client.player.getBlockPos();
|
||||||
|
String coordinate_string = String.format("X: %d, Y: %d, Z: %d", pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
lines.add(new Line(Text.literal(coordinate_string), white, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Pair<Consumer<ArrayList<Line>>, Integer> callback: HudRenderCallback.callbacks) {
|
||||||
|
callback.getLeft().accept(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
|
Line line = lines.get(i);
|
||||||
|
|
||||||
|
if (i > 0 && lines.get(i - 1).indent() > line.indent()) {
|
||||||
|
y += 3;
|
||||||
|
} else if (i > 0 && lines.get(i - 1).indent() < line.indent()) {
|
||||||
|
y += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawableHelper.drawTextWithShadow(matrices, textRenderer, line.text(), x + (5 * line.indent()), y,
|
||||||
|
line.color());
|
||||||
|
y += textRenderer.fontHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
src/main/java/cmods/cmods/mixin/OptionsMixin.java
Normal file
29
src/main/java/cmods/cmods/mixin/OptionsMixin.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package cmods.cmods.mixin;
|
||||||
|
|
||||||
|
import cmods.cmods.client.ui.CmodsOptionsScreen;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
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 OptionsMixin extends Screen {
|
||||||
|
|
||||||
|
protected OptionsMixin(Text title) {
|
||||||
|
super(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("TAIL"), method = "init")
|
||||||
|
private void init(CallbackInfo ci) {
|
||||||
|
if (client == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
addDrawableChild(ButtonWidget.builder(Text.translatable("cmods.options"),
|
||||||
|
button -> client.setScreen(new CmodsOptionsScreen(this)))
|
||||||
|
.position(20, 20).width(100).build());
|
||||||
|
}
|
||||||
|
}
|
30
src/main/java/cmods/cmods/mixin/PauseMixin.java
Normal file
30
src/main/java/cmods/cmods/mixin/PauseMixin.java
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package cmods.cmods.mixin;
|
||||||
|
|
||||||
|
|
||||||
|
import cmods.cmods.client.ui.CmodsOptionsScreen;
|
||||||
|
import net.minecraft.client.gui.screen.GameMenuScreen;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
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(GameMenuScreen.class)
|
||||||
|
public class PauseMixin extends Screen {
|
||||||
|
|
||||||
|
protected PauseMixin(Text title) {
|
||||||
|
super(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("TAIL"), method = "init")
|
||||||
|
public void init(CallbackInfo ci) {
|
||||||
|
if (client == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
addDrawableChild(ButtonWidget.builder(Text.translatable("cmods.options"),
|
||||||
|
button -> client.setScreen(new CmodsOptionsScreen(this)))
|
||||||
|
.position(20, 20).width(100).build());
|
||||||
|
}
|
||||||
|
}
|
BIN
src/main/resources/assets/cmods/icon.png
Normal file
BIN
src/main/resources/assets/cmods/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
14
src/main/resources/assets/cmods/lang/en_us.json
Normal file
14
src/main/resources/assets/cmods/lang/en_us.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"cmods.state.on": "On",
|
||||||
|
"cmods.state.off": "Off",
|
||||||
|
"cmods.state.enabled": "Enabled",
|
||||||
|
"cmods.state.disabled": "Disabled",
|
||||||
|
|
||||||
|
"cmods.options": "Cmods",
|
||||||
|
"cmods.options.title": "Cmods Options",
|
||||||
|
|
||||||
|
"cmods.options.ui": "UI",
|
||||||
|
"cmods.options.ui.title": "UI Options",
|
||||||
|
"cmods.options.ui.hud_enabled": "Show HUD",
|
||||||
|
"cmods.options.ui.show_coordinates": "Show Coordinates"
|
||||||
|
}
|
16
src/main/resources/cmods.mixins.json
Normal file
16
src/main/resources/cmods.mixins.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "cmods.cmods.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_17",
|
||||||
|
"mixins": [
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"HudMixin",
|
||||||
|
"OptionsMixin",
|
||||||
|
"PauseMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
28
src/main/resources/fabric.mod.json
Normal file
28
src/main/resources/fabric.mod.json
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "cmods",
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "Cmods",
|
||||||
|
"description": "<description>",
|
||||||
|
"authors": [
|
||||||
|
"CameronReed"
|
||||||
|
],
|
||||||
|
"contact": {
|
||||||
|
"repo": "https://gitea.cam123.dev/"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"icon": "assets/cmods/icon.png",
|
||||||
|
"environment": "client",
|
||||||
|
"entrypoints": {
|
||||||
|
"client": ["cmods.cmods.client.CmodsClient"],
|
||||||
|
"modmenu": ["cmods.cmods.client.ModMenuConfig"]
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"cmods.mixins.json"
|
||||||
|
],
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": ">=0.14.11",
|
||||||
|
"fabric": "*",
|
||||||
|
"minecraft": "1.19.3"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user