mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 07:53:22 +02:00
Initial commit
This commit is contained in:
commit
ff1c9342ca
17 changed files with 1463 additions and 0 deletions
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# gradle
|
||||||
|
|
||||||
|
.gradle/
|
||||||
|
build/
|
||||||
|
out/
|
||||||
|
classes/
|
||||||
|
|
||||||
|
# eclipse
|
||||||
|
|
||||||
|
*.launch
|
||||||
|
|
||||||
|
# idea
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# vscode
|
||||||
|
|
||||||
|
.settings/
|
||||||
|
.vscode/
|
||||||
|
bin/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
|
||||||
|
# macos
|
||||||
|
|
||||||
|
*.DS_Store
|
||||||
|
|
||||||
|
# fabric
|
||||||
|
|
||||||
|
run/
|
||||||
|
|
||||||
|
# java
|
||||||
|
|
||||||
|
hs_err_*.log
|
||||||
|
replay_*.log
|
||||||
|
*.hprof
|
||||||
|
*.jfr
|
76
build.gradle
Normal file
76
build.gradle
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
plugins {
|
||||||
|
id 'fabric-loom' version '1.3-SNAPSHOT'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
version = project.mod_version
|
||||||
|
group = project.maven_group
|
||||||
|
|
||||||
|
base {
|
||||||
|
archivesName = project.archives_base_name
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "https://maven.terraformersmc.com/releases/" }
|
||||||
|
maven { url "https://maven.isxander.dev/releases" }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||||
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
|
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||||
|
modImplementation "dev.isxander.yacl:yet-another-config-lib-fabric:${project.yacl_version}"
|
||||||
|
|
||||||
|
// Uncomment the following line to enable the deprecated Fabric API modules.
|
||||||
|
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
|
||||||
|
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
inputs.property "version", project.version
|
||||||
|
|
||||||
|
filesMatching("fabric.mod.json") {
|
||||||
|
expand "version": project.version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
it.options.release = 17
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
// 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()
|
||||||
|
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
from("LICENSE") {
|
||||||
|
rename { "${it}_${project.base.archivesName.get()}"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
}
|
||||||
|
}
|
19
gradle.properties
Normal file
19
gradle.properties
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Done to increase the memory available to gradle.
|
||||||
|
org.gradle.jvmargs=-Xmx1G
|
||||||
|
org.gradle.parallel=true
|
||||||
|
|
||||||
|
# Fabric Properties
|
||||||
|
# check these on https://fabricmc.net/develop
|
||||||
|
minecraft_version=1.20.1
|
||||||
|
yarn_mappings=1.20.1+build.9
|
||||||
|
loader_version=0.14.21
|
||||||
|
|
||||||
|
# Mod Properties
|
||||||
|
mod_version=b0.0.1+1.20-1.20.1
|
||||||
|
maven_group=one.oth3r
|
||||||
|
archives_base_name=sit!
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
fabric_version=0.85.0+1.20.1
|
||||||
|
modmenu_version=7.0.0
|
||||||
|
yacl_version=3.0.0+1.20
|
248
gradlew
vendored
Normal file
248
gradlew
vendored
Normal file
|
@ -0,0 +1,248 @@
|
||||||
|
#!/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/HEAD/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
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
|
# 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
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
# 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"'
|
||||||
|
|
||||||
|
# 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 \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 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" "$@"
|
92
gradlew.bat
vendored
Normal file
92
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
@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=.
|
||||||
|
@rem This is normally unused
|
||||||
|
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% equ 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% equ 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!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
10
settings.gradle
Normal file
10
settings.gradle
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
}
|
||||||
|
mavenCentral()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
265
src/main/java/one/oth3r/sit/Events.java
Normal file
265
src/main/java/one/oth3r/sit/Events.java
Normal file
|
@ -0,0 +1,265 @@
|
||||||
|
package one.oth3r.sit;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
|
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
|
import net.minecraft.block.*;
|
||||||
|
import net.minecraft.block.enums.BlockHalf;
|
||||||
|
import net.minecraft.block.enums.SlabType;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityType;
|
||||||
|
import net.minecraft.entity.decoration.DisplayEntity;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.hit.HitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Box;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Events {
|
||||||
|
private static int tick;
|
||||||
|
public static HashMap<ServerPlayerEntity, Entity> entities = new HashMap<>();
|
||||||
|
public static HashMap<ServerPlayerEntity, Integer> checkPlayers = new HashMap<>();
|
||||||
|
public static boolean checkLogic(ServerPlayerEntity player) {
|
||||||
|
Item mainItem = player.getMainHandStack().getItem();
|
||||||
|
Item offItem = player.getOffHandStack().getItem();
|
||||||
|
if (player.isSneaking()) return false;
|
||||||
|
if (config.mainReq.equals(config.MainReq.empty) && !player.getMainHandStack().isEmpty()) return false;
|
||||||
|
if (config.mainReq.equals(config.MainReq.restrictive)) {
|
||||||
|
if (checkList(config.mainBlacklist,mainItem)) return false;
|
||||||
|
if (!checkList(config.mainWhitelist,mainItem)) {
|
||||||
|
if (config.mainBlock && (mainItem instanceof BlockItem)) return false;
|
||||||
|
if (config.mainFood && mainItem.isFood()) return false;
|
||||||
|
if (config.mainUsable && player.getMainHandStack().isUsedOnRelease()) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.offReq.equals(config.OffReq.empty) && !player.getOffHandStack().isEmpty()) return false;
|
||||||
|
if (config.offReq.equals(config.OffReq.restrictive)) {
|
||||||
|
if (checkList(config.offBlacklist,offItem)) return false;
|
||||||
|
if (!checkList(config.offWhitelist,offItem)) {
|
||||||
|
if (config.offBlock && (offItem instanceof BlockItem)) return false;
|
||||||
|
if (config.offFood && offItem.isFood()) return false;
|
||||||
|
if (config.offUsable && player.getOffHandStack().isUsedOnRelease()) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public static boolean checkList(List<String> list, Item item) {
|
||||||
|
String itemID = Registries.ITEM.getId(item).toString();
|
||||||
|
System.out.println(itemID);
|
||||||
|
return list.contains(itemID);
|
||||||
|
}
|
||||||
|
public static HashMap<String,HashMap<String,Object>> getCustomBlocks() {
|
||||||
|
HashMap<String,HashMap<String,Object>> map = new HashMap<>();
|
||||||
|
int i = 1;
|
||||||
|
for (String s:config.customBlocks) {
|
||||||
|
String[] split = s.split("\\|");
|
||||||
|
HashMap<String,Object> data = new HashMap<>();
|
||||||
|
data.put("block",split[0]);
|
||||||
|
data.put("height",split[1]);
|
||||||
|
data.put("hitbox",split[2]);
|
||||||
|
if (split.length==4) data.put("state",split[3]);
|
||||||
|
map.put(i+"",data);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static boolean checkBlocks(BlockPos pos, World world) {
|
||||||
|
BlockState blockState = world.getBlockState(pos);
|
||||||
|
Block block = blockState.getBlock();
|
||||||
|
BlockState blockStateAbove = world.getBlockState(pos.add(0,1,0));
|
||||||
|
Block blockAbove = blockStateAbove.getBlock();
|
||||||
|
System.out.println(blockState);
|
||||||
|
//not the biggest fan but ah well
|
||||||
|
if (blockStateAbove.isFullCube(world,pos.add(0,1,0)) && blockStateAbove.blocksMovement()) return false;
|
||||||
|
else if (blockAbove instanceof StairsBlock || blockAbove instanceof SlabBlock || blockAbove instanceof CarpetBlock) return false;
|
||||||
|
for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false;
|
||||||
|
if (block instanceof StairsBlock && config.stairsOn) return blockState.get(StairsBlock.HALF) == BlockHalf.BOTTOM;
|
||||||
|
if (block instanceof SlabBlock && config.slabsOn) return blockState.get(SlabBlock.TYPE) == SlabType.BOTTOM;
|
||||||
|
if (block instanceof CarpetBlock && config.carpetsOn) return true;
|
||||||
|
if (blockState.isFullCube(world,pos.add(0,1,0)) && config.fullBlocksOn) return true;
|
||||||
|
if (config.customOn && config.customBlocks.size() != 0) {
|
||||||
|
System.out.println("checking custom");
|
||||||
|
for (HashMap<String,Object> map:getCustomBlocks().values()) {
|
||||||
|
String blockID = Registries.BLOCK.getId(block).toString();
|
||||||
|
if (map.get("block").equals(blockID)) {
|
||||||
|
if (!map.containsKey("state")) return true;
|
||||||
|
String[] states = ((String) map.get("state")).split(",\\s*");
|
||||||
|
boolean matching = true;
|
||||||
|
for (String state:states) {
|
||||||
|
if (state.charAt(0) == '!')
|
||||||
|
if (blockState.toString().contains(state.substring(1))) matching = false;
|
||||||
|
else if (!blockState.toString().contains(state)) matching = false;
|
||||||
|
}
|
||||||
|
return matching;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static void setEntity(BlockPos pos, World world, Entity entity) {
|
||||||
|
Block block = world.getBlockState(pos).getBlock();
|
||||||
|
entity.setCustomName(Text.of(Sit.ENTITY_NAME));
|
||||||
|
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.47, pos.getZ() + 0.5, 0, 0);
|
||||||
|
entity.setInvulnerable(true);
|
||||||
|
if (block instanceof StairsBlock) {
|
||||||
|
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0);
|
||||||
|
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5));
|
||||||
|
}
|
||||||
|
if (block instanceof SlabBlock) {
|
||||||
|
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0);
|
||||||
|
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,1,1.5));
|
||||||
|
}
|
||||||
|
if (block instanceof CarpetBlock) {
|
||||||
|
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()-.17, pos.getZ() + 0.5, 0, 0);
|
||||||
|
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,0.125,1.5));
|
||||||
|
}
|
||||||
|
if (world.getBlockState(pos).isFullCube(world,pos.add(0,1,0))) {
|
||||||
|
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.78, pos.getZ() + 0.5, 0, 0);
|
||||||
|
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5));
|
||||||
|
}
|
||||||
|
if (config.customOn && config.customBlocks.size() != 0) {
|
||||||
|
System.out.println("checking custom sit height");
|
||||||
|
for (HashMap<String,Object> map:getCustomBlocks().values()) {
|
||||||
|
String blockID = Registries.BLOCK.getId(block).toString();
|
||||||
|
if (map.get("block").equals(blockID)) {
|
||||||
|
double input = Math.max(Math.min(Double.parseDouble((String) map.get("height")),1),0);
|
||||||
|
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+input-.22, pos.getZ() + 0.5, 0, 0);
|
||||||
|
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,Double.parseDouble((String) map.get("hitbox")),1.5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//change pitch based on if player is sitting below block height or not
|
||||||
|
if (entity.getY() <= pos.getY()+.35) entity.setPitch(90);
|
||||||
|
else entity.setPitch(-90);
|
||||||
|
}
|
||||||
|
public static void register() {
|
||||||
|
UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> {
|
||||||
|
ServerPlayerEntity player = Sit.server.getPlayerManager().getPlayer(pl.getUuid());
|
||||||
|
if (player == null) return ActionResult.PASS;
|
||||||
|
if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) {
|
||||||
|
BlockPos pos = hitResult.getBlockPos();
|
||||||
|
//todo idk find bugs and polish
|
||||||
|
if (!checkLogic(player)) return ActionResult.PASS;
|
||||||
|
if (checkBlocks(pos,world)) {
|
||||||
|
if (entities.containsKey(player)) {
|
||||||
|
if (!config.sitWhileSeated) return ActionResult.PASS;
|
||||||
|
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||||
|
entities.remove(player);
|
||||||
|
}
|
||||||
|
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
||||||
|
setEntity(pos,world,entity);
|
||||||
|
player.getServerWorld().spawnEntity(entity);
|
||||||
|
player.startRiding(entity);
|
||||||
|
entities.put(player,entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ActionResult.PASS;
|
||||||
|
});
|
||||||
|
ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp));
|
||||||
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
||||||
|
ServerPlayerEntity player = handler.player;
|
||||||
|
checkPlayers.put(player,2);
|
||||||
|
});
|
||||||
|
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
||||||
|
ServerPlayerEntity player = handler.player;
|
||||||
|
if (entities.containsKey(player)) {
|
||||||
|
if (!config.keepActive) {
|
||||||
|
player.dismountVehicle();
|
||||||
|
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||||
|
}
|
||||||
|
entities.remove(player);
|
||||||
|
}
|
||||||
|
checkPlayers.remove(player);
|
||||||
|
});
|
||||||
|
ServerLifecycleEvents.SERVER_STARTED.register(s -> {
|
||||||
|
Sit.server = s;
|
||||||
|
Sit.commandManager = s.getCommandManager();
|
||||||
|
});
|
||||||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SitCommand.register(dispatcher));
|
||||||
|
}
|
||||||
|
public static void cleanUp() {
|
||||||
|
tick++;
|
||||||
|
if (tick >= 5) {
|
||||||
|
tick = 0;
|
||||||
|
Iterator<Map.Entry<ServerPlayerEntity, Entity>> entityLoop = entities.entrySet().iterator();
|
||||||
|
while (entityLoop.hasNext()) {
|
||||||
|
Map.Entry<ServerPlayerEntity, Entity> entry = entityLoop.next();
|
||||||
|
ServerPlayerEntity player = entry.getKey();
|
||||||
|
Entity entity = entry.getValue();
|
||||||
|
if (player.getVehicle() == null || !player.getVehicle().equals(entity)) {
|
||||||
|
entity.setRemoved(Entity.RemovalReason.DISCARDED);
|
||||||
|
System.out.println("removed..");
|
||||||
|
entityLoop.remove();
|
||||||
|
} else {
|
||||||
|
BlockPos pos = new BlockPos(entity.getBlockX(),(int) Math.floor(player.getY()),entity.getBlockZ());
|
||||||
|
if (entity.getPitch() == 90) pos = new BlockPos(entity.getBlockX(),(int) Math.ceil(player.getY()),entity.getBlockZ());
|
||||||
|
BlockState blockState = player.getWorld().getBlockState(pos);
|
||||||
|
if (blockState.isAir()) {
|
||||||
|
System.out.println(pos);
|
||||||
|
System.out.println(entity.getY());
|
||||||
|
System.out.println("dismount");
|
||||||
|
player.teleport(player.getX(),player.getBlockY()+1,player.getZ());
|
||||||
|
entity.setRemoved(Entity.RemovalReason.DISCARDED);
|
||||||
|
entityLoop.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Iterator<Map.Entry<ServerPlayerEntity, Integer>> playerCheckLoop = checkPlayers.entrySet().iterator();
|
||||||
|
while (playerCheckLoop.hasNext()) {
|
||||||
|
Map.Entry<ServerPlayerEntity, Integer> entry = playerCheckLoop.next();
|
||||||
|
ServerPlayerEntity player = entry.getKey();
|
||||||
|
int i = entry.getValue();
|
||||||
|
checkPlayers.put(player,i-1);
|
||||||
|
if (i<0) {
|
||||||
|
System.out.println("fail");
|
||||||
|
playerCheckLoop.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
System.out.println("trying to add back");
|
||||||
|
if (player.getVehicle() != null) {
|
||||||
|
Entity entity = player.getVehicle();
|
||||||
|
if (entity.getName().getString().equals(Sit.ENTITY_NAME)) {
|
||||||
|
System.out.println("adding back");
|
||||||
|
setEntity(player.getBlockPos().add(0,1,0),player.getServerWorld(),entity);
|
||||||
|
entities.put(player,entity);
|
||||||
|
playerCheckLoop.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ServerPlayerEntity player:checkPlayers.keySet()) {
|
||||||
|
int i = checkPlayers.get(player);
|
||||||
|
checkPlayers.put(player,i-1);
|
||||||
|
if (i<0) {
|
||||||
|
System.out.println("fail");
|
||||||
|
checkPlayers.remove(player);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
System.out.println("trying to add back");
|
||||||
|
if (player.getVehicle() != null) {
|
||||||
|
Entity entity = player.getVehicle();
|
||||||
|
if (entity.getName().getString().equals(Sit.ENTITY_NAME)) {
|
||||||
|
System.out.println("adding back");
|
||||||
|
setEntity(player.getBlockPos().add(0,1,0),player.getServerWorld(),entity);
|
||||||
|
entities.put(player,entity);
|
||||||
|
checkPlayers.remove(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
100
src/main/java/one/oth3r/sit/LangReader.java
Normal file
100
src/main/java/one/oth3r/sit/LangReader.java
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
package one.oth3r.sit;
|
||||||
|
|
||||||
|
import net.minecraft.text.MutableText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TextContent;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class LangReader {
|
||||||
|
private static final Map<String, String> languageMap = new HashMap<>();
|
||||||
|
private final String translationKey;
|
||||||
|
private final Object[] placeholders;
|
||||||
|
public LangReader(String translationKey, Object... placeholders) {
|
||||||
|
this.translationKey = translationKey;
|
||||||
|
this.placeholders = placeholders;
|
||||||
|
}
|
||||||
|
public MutableText getTxT() {
|
||||||
|
String translated = getLanguageValue(translationKey);
|
||||||
|
if (placeholders != null && placeholders.length > 0) {
|
||||||
|
//removed all double \\ and replaces with \
|
||||||
|
translated = translated.replaceAll("\\\\\\\\", "\\\\");
|
||||||
|
String regex = "%\\d*\\$?[dfs]";
|
||||||
|
Matcher anyMatch = Pattern.compile(regex).matcher(translated);
|
||||||
|
Matcher endMatch = Pattern.compile(regex+"$").matcher(translated);
|
||||||
|
//Arraylist with all the %(#$)[dfs]
|
||||||
|
ArrayList<String> matches = new ArrayList<>();
|
||||||
|
while (anyMatch.find()) {
|
||||||
|
String match = anyMatch.group();
|
||||||
|
matches.add(match);
|
||||||
|
}
|
||||||
|
//SPLITS the text at each regex and remove the regex
|
||||||
|
String[] parts = translated.split(regex);
|
||||||
|
//if the last element of the array ends with regex, remove it and add an empty string to the end of the array
|
||||||
|
if (endMatch.find()) {
|
||||||
|
String[] newParts = Arrays.copyOf(parts, parts.length + 1);
|
||||||
|
newParts[parts.length] = "";
|
||||||
|
parts = newParts;
|
||||||
|
}
|
||||||
|
//if there are placeholders specified, and the split is more than 1, it will replace %(dfs) with the placeholder objects
|
||||||
|
if (parts.length > 1) {
|
||||||
|
MutableText txt = Text.empty();
|
||||||
|
int i = 0;
|
||||||
|
for (String match : matches) {
|
||||||
|
int get = i;
|
||||||
|
//if the match is numbered, change GET to the number it wants
|
||||||
|
if (match.contains("$")) {
|
||||||
|
match = match.substring(1,match.indexOf('$'));
|
||||||
|
get = Integer.parseInt(match)-1;
|
||||||
|
}
|
||||||
|
if (parts.length != i) txt.append(parts[i]);
|
||||||
|
//convert the obj into txt
|
||||||
|
Object obj = placeholders[get];
|
||||||
|
if (obj instanceof Text) txt.append((Text) obj);
|
||||||
|
else txt.append(String.valueOf(obj));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (parts.length != i) txt.append(parts[i]);
|
||||||
|
return txt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MutableText.of(TextContent.EMPTY).append(translated);
|
||||||
|
}
|
||||||
|
public static LangReader of(String translationKey, Object... placeholders) {
|
||||||
|
return new LangReader(translationKey, placeholders);
|
||||||
|
}
|
||||||
|
public static void loadLanguageFile() {
|
||||||
|
try {
|
||||||
|
ClassLoader classLoader = Sit.class.getClassLoader();
|
||||||
|
InputStream inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ config.lang+".json");
|
||||||
|
if (inputStream == null) {
|
||||||
|
inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+config.defaults.lang+".json");
|
||||||
|
config.lang = config.defaults.lang;
|
||||||
|
}
|
||||||
|
if (inputStream == null) throw new IllegalArgumentException("CANT LOAD THE LANGUAGE FILE. DIRECTIONHUD WILL BREAK.");
|
||||||
|
Scanner scanner = new Scanner(inputStream);
|
||||||
|
String currentLine;
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
currentLine = scanner.nextLine().trim();
|
||||||
|
if (currentLine.startsWith("{") || currentLine.startsWith("}")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] keyValue = currentLine.split(":", 2);
|
||||||
|
String key = keyValue[0].trim();
|
||||||
|
key = key.substring(1,key.length()-1).replace("\\","");
|
||||||
|
String value = keyValue[1].trim();
|
||||||
|
if (value.endsWith(",")) value = value.substring(0, value.length() - 1);
|
||||||
|
value = value.substring(1,value.length()-1).replace("\\","");
|
||||||
|
languageMap.put(key, value);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String getLanguageValue(String key) {
|
||||||
|
return languageMap.getOrDefault(key, key);
|
||||||
|
}
|
||||||
|
}
|
196
src/main/java/one/oth3r/sit/ModMenu.java
Normal file
196
src/main/java/one/oth3r/sit/ModMenu.java
Normal file
|
@ -0,0 +1,196 @@
|
||||||
|
package one.oth3r.sit;
|
||||||
|
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
import dev.isxander.yacl3.api.*;
|
||||||
|
import dev.isxander.yacl3.api.controller.BooleanControllerBuilder;
|
||||||
|
import dev.isxander.yacl3.api.controller.EnumControllerBuilder;
|
||||||
|
import dev.isxander.yacl3.api.controller.StringControllerBuilder;
|
||||||
|
import net.minecraft.text.MutableText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TextColor;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
|
|
||||||
|
public class ModMenu implements ModMenuApi {
|
||||||
|
private static MutableText lang(String key) {
|
||||||
|
return Text.translatable("config.sit."+key);
|
||||||
|
}
|
||||||
|
private static MutableText lang(String key, Object... args) {
|
||||||
|
return Text.translatable("config.sit."+key,args);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
|
return parent -> YetAnotherConfigLib.createBuilder()
|
||||||
|
.title(Text.of("Sit!"))
|
||||||
|
.category(ConfigCategory.createBuilder()
|
||||||
|
.name(lang("category.general"))
|
||||||
|
.tooltip(lang("category.general.tooltip"))
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("general.keep_active"))
|
||||||
|
.description(OptionDescription.of(lang("general.keep_active.description")))
|
||||||
|
.binding(config.defaults.keepActive, () -> config.keepActive, n -> config.keepActive = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("general.sit_while_seated"))
|
||||||
|
.description(OptionDescription.of(lang("general.sit_while_seated.description")))
|
||||||
|
.binding(config.defaults.sitWhileSeated, () -> config.sitWhileSeated, n -> config.sitWhileSeated = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.group(OptionGroup.createBuilder()
|
||||||
|
.name(lang("general.sittable"))
|
||||||
|
.description(OptionDescription.of(lang("general.sittable.description")))
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("general.sittable.stairs"))
|
||||||
|
.binding(config.defaults.stairsOn, () -> config.stairsOn, n -> config.stairsOn = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("general.sittable.slabs"))
|
||||||
|
.binding(config.defaults.slabsOn, () -> config.slabsOn, n -> config.slabsOn = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("general.sittable.carpets"))
|
||||||
|
.binding(config.defaults.carpetsOn, () -> config.carpetsOn, n -> config.carpetsOn = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("general.sittable.full_blocks"))
|
||||||
|
.binding(config.defaults.fullBlocksOn, () -> config.fullBlocksOn, n -> config.fullBlocksOn = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("general.sittable.custom"))
|
||||||
|
.description(OptionDescription.of(lang("general.sittable.custom.description")))
|
||||||
|
.binding(config.defaults.customOn, () -> config.customOn, n -> config.customOn = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.group(ListOption.<String>createBuilder()
|
||||||
|
.name(lang("general.sittable_blocks"))
|
||||||
|
.description(OptionDescription.of(
|
||||||
|
lang("general.sittable_blocks.description")
|
||||||
|
.append("\n\n").append(lang("general.sittable_blocks.description_2"))
|
||||||
|
.append(lang("general.sittable_blocks.description_3",
|
||||||
|
lang("general.sittable_blocks.description_3_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))),
|
||||||
|
lang("general.sittable_blocks.description_3_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))),
|
||||||
|
lang("general.sittable_blocks.description_3_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))),
|
||||||
|
lang("general.sittable_blocks.description_3_5").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GOLD)))).styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))
|
||||||
|
.append("\n\n").append(lang("general.sittable_blocks.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))))
|
||||||
|
.append("\n").append(lang("general.sittable_blocks.description_5").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))))
|
||||||
|
.append("\n").append(lang("general.sittable_blocks.description_6").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))))
|
||||||
|
.append("\n").append(lang("general.sittable_blocks.description_7").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GOLD))))
|
||||||
|
.append("\n\n").append(lang("general.sittable_blocks.description_8").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.YELLOW))))))
|
||||||
|
.binding(config.defaults.customBlocks, () -> config.customBlocks, n -> config.customBlocks = n)
|
||||||
|
.controller(StringControllerBuilder::create)
|
||||||
|
.initial("")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.category(ConfigCategory.createBuilder()
|
||||||
|
.name(lang("category.main_hand"))
|
||||||
|
.tooltip(lang("category.main_hand.tooltip"))
|
||||||
|
.option(Option.<config.MainReq>createBuilder()
|
||||||
|
.name(lang("hand.requirements"))
|
||||||
|
.description(OptionDescription.of(lang("hand.requirements.description")
|
||||||
|
.append("\n\n").append(lang("hand.requirements.description_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))))
|
||||||
|
.append("\n").append(lang("hand.requirements.description_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))))
|
||||||
|
.append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))))))
|
||||||
|
.binding(config.defaults.mainReq, () -> config.mainReq, n -> config.mainReq = n)
|
||||||
|
.controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.MainReq.class)
|
||||||
|
.valueFormatter(v -> Text.translatable("config.sit."+v.name().toLowerCase())))
|
||||||
|
.build())
|
||||||
|
.group(OptionGroup.createBuilder()
|
||||||
|
.name(lang("hand.restrictions"))
|
||||||
|
.description(OptionDescription.of(lang("hand.restrictions.description")))
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("hand.restrictions.blocks"))
|
||||||
|
.binding(config.defaults.mainBlock,()-> config.mainBlock,n -> config.mainBlock = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("hand.restrictions.food"))
|
||||||
|
.binding(config.defaults.mainFood,()-> config.mainFood,n -> config.mainFood = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("hand.restrictions.usable"))
|
||||||
|
.description(OptionDescription.of(lang("hand.restrictions.usable.description")))
|
||||||
|
.binding(config.defaults.mainUsable,()-> config.mainUsable,n -> config.mainUsable = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.group(ListOption.<String>createBuilder()
|
||||||
|
.name(lang("hand.whitelist"))
|
||||||
|
.description(OptionDescription.of(lang("hand.whitelist.description")
|
||||||
|
.append("\n\n").append(lang("hand.list.description"))
|
||||||
|
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||||
|
.binding(config.defaults.mainWhitelist, () -> config.mainWhitelist, n -> config.mainWhitelist = n)
|
||||||
|
.controller(StringControllerBuilder::create)
|
||||||
|
.initial("")
|
||||||
|
.build())
|
||||||
|
.group(ListOption.<String>createBuilder()
|
||||||
|
.name(lang("hand.blacklist"))
|
||||||
|
.description(OptionDescription.of(lang("hand.blacklist.description")
|
||||||
|
.append("\n\n").append(lang("hand.list.description"))
|
||||||
|
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||||
|
.binding(config.defaults.mainBlacklist, () -> config.mainBlacklist, n -> config.mainBlacklist = n)
|
||||||
|
.controller(StringControllerBuilder::create)
|
||||||
|
.initial("")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.category(ConfigCategory.createBuilder()
|
||||||
|
.name(lang("category.off_hand"))
|
||||||
|
.tooltip(lang("category.off_hand.tooltip"))
|
||||||
|
.option(Option.<config.OffReq>createBuilder()
|
||||||
|
.name(lang("hand.requirements"))
|
||||||
|
.description(OptionDescription.of(lang("hand.requirements.description")
|
||||||
|
.append("\n\n").append(lang("hand.requirements.description_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))))
|
||||||
|
.append("\n").append(lang("hand.requirements.description_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))))
|
||||||
|
.append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))))))
|
||||||
|
.binding(config.defaults.offReq, () -> config.offReq, n -> config.offReq = n)
|
||||||
|
.controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.OffReq.class)
|
||||||
|
.valueFormatter(v -> Text.translatable("config.sit."+v.name().toLowerCase())))
|
||||||
|
.build())
|
||||||
|
.group(OptionGroup.createBuilder()
|
||||||
|
.name(lang("hand.restrictions"))
|
||||||
|
.description(OptionDescription.of(lang("hand.restrictions.description")))
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("hand.restrictions.blocks"))
|
||||||
|
.binding(config.defaults.offBlock,()-> config.offBlock,n -> config.offBlock = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("hand.restrictions.food"))
|
||||||
|
.binding(config.defaults.offFood,()-> config.offFood,n -> config.offFood = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.option(Option.<Boolean>createBuilder()
|
||||||
|
.name(lang("hand.restrictions.usable"))
|
||||||
|
.description(OptionDescription.of(lang("hand.restrictions.usable.description")))
|
||||||
|
.binding(config.defaults.offUsable,()-> config.offUsable,n -> config.offUsable = n)
|
||||||
|
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.group(ListOption.<String>createBuilder()
|
||||||
|
.name(lang("hand.whitelist"))
|
||||||
|
.description(OptionDescription.of(lang("hand.whitelist.description")
|
||||||
|
.append("\n\n").append(lang("hand.list.description"))
|
||||||
|
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||||
|
.binding(config.defaults.offWhitelist, () -> config.offWhitelist, n -> config.offWhitelist = n)
|
||||||
|
.controller(StringControllerBuilder::create)
|
||||||
|
.initial("")
|
||||||
|
.build())
|
||||||
|
.group(ListOption.<String>createBuilder()
|
||||||
|
.name(lang("hand.blacklist"))
|
||||||
|
.description(OptionDescription.of(lang("hand.blacklist.description")
|
||||||
|
.append("\n\n").append(lang("hand.list.description"))
|
||||||
|
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||||
|
.binding(config.defaults.offBlacklist, () -> config.offBlacklist, n -> config.offBlacklist = n)
|
||||||
|
.controller(StringControllerBuilder::create)
|
||||||
|
.initial("")
|
||||||
|
.build())
|
||||||
|
.build())
|
||||||
|
.build().generateScreen(parent);
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/one/oth3r/sit/Sit.java
Normal file
31
src/main/java/one/oth3r/sit/Sit.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package one.oth3r.sit;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.command.CommandManager;
|
||||||
|
import net.minecraft.text.MutableText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class Sit implements ModInitializer {
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger("sit");
|
||||||
|
public static final String ENTITY_NAME = "-sit!-entity-";
|
||||||
|
public static MinecraftServer server;
|
||||||
|
public static CommandManager commandManager;
|
||||||
|
public static boolean isClient = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize() {
|
||||||
|
//todo future:
|
||||||
|
// make it so it updates the sitting height and pos based on the block so if it changed while offline it still works (or if stair changes shape)
|
||||||
|
// inner stair offset & custom support for that ig
|
||||||
|
config.load();
|
||||||
|
Events.register();
|
||||||
|
}
|
||||||
|
public static MutableText lang(String key, Object... args) {
|
||||||
|
if (isClient) return Text.translatable(key, args);
|
||||||
|
else return LangReader.of(key, args).getTxT();
|
||||||
|
}
|
||||||
|
}
|
66
src/main/java/one/oth3r/sit/SitCommand.java
Normal file
66
src/main/java/one/oth3r/sit/SitCommand.java
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package one.oth3r.sit;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.ParseResults;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import net.minecraft.server.command.CommandManager;
|
||||||
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.text.TextColor;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class SitCommand {
|
||||||
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||||
|
dispatcher.register(CommandManager.literal("sit")
|
||||||
|
.requires((commandSource) -> commandSource.hasPermissionLevel(2))
|
||||||
|
.executes((context2) -> command(context2.getSource(), context2.getInput()))
|
||||||
|
.then(CommandManager.argument("args", StringArgumentType.string())
|
||||||
|
.suggests(SitCommand::getSuggestions)
|
||||||
|
.executes((context2) -> command(context2.getSource(), context2.getInput()))));
|
||||||
|
}
|
||||||
|
public static CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
|
||||||
|
ServerPlayerEntity player = Objects.requireNonNull(context.getSource().getPlayer());
|
||||||
|
String[] args = context.getInput().split(" ");
|
||||||
|
builder.suggest("reload");
|
||||||
|
builder.suggest("purgeChairEntities");
|
||||||
|
return builder.buildFuture();
|
||||||
|
}
|
||||||
|
private static int command(ServerCommandSource source, String arg) {
|
||||||
|
ServerPlayerEntity player = source.getPlayer();
|
||||||
|
if (player == null) return 1;
|
||||||
|
//trim all the arguments before the command
|
||||||
|
String keyword = "sit";
|
||||||
|
int index = Integer.MAX_VALUE;
|
||||||
|
if (arg.contains(keyword)) index = arg.indexOf(keyword);
|
||||||
|
//trims the words before the text
|
||||||
|
if (index != Integer.MAX_VALUE) arg = arg.substring(index).trim();
|
||||||
|
String[] args = arg.split(" ");
|
||||||
|
if (args[0].equalsIgnoreCase("sit"))
|
||||||
|
args = arg.replaceFirst("sit ", "").split(" ");
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("reload")) {
|
||||||
|
config.load();
|
||||||
|
player.sendMessage(Sit.lang("key.sit.command.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))));
|
||||||
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("purgeChairEntities")) {
|
||||||
|
String cmd = "kill @e[type=minecraft:text_display,name=\""+Sit.ENTITY_NAME+"\"]";
|
||||||
|
try {
|
||||||
|
ParseResults<ServerCommandSource> parse =
|
||||||
|
Sit.commandManager.getDispatcher().parse(cmd, player.getCommandSource());
|
||||||
|
Sit.commandManager.getDispatcher().execute(parse);
|
||||||
|
player.sendMessage(Sit.lang("key.sit.command.purged"));
|
||||||
|
} catch (CommandSyntaxException e) {
|
||||||
|
player.sendMessage(Sit.lang("key.sit.command.purged"));
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
12
src/main/java/one/oth3r/sit/SitServer.java
Normal file
12
src/main/java/one/oth3r/sit/SitServer.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package one.oth3r.sit;
|
||||||
|
|
||||||
|
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||||
|
|
||||||
|
public class SitServer implements DedicatedServerModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeServer() {
|
||||||
|
Sit.isClient = false;
|
||||||
|
config.load();
|
||||||
|
LangReader.loadLanguageFile();
|
||||||
|
}
|
||||||
|
}
|
201
src/main/java/one/oth3r/sit/config.java
Normal file
201
src/main/java/one/oth3r/sit/config.java
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
package one.oth3r.sit;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.text.MutableText;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class config {
|
||||||
|
public static String lang = defaults.lang;
|
||||||
|
public static boolean keepActive = defaults.keepActive;
|
||||||
|
public static boolean sitWhileSeated = defaults.sitWhileSeated;
|
||||||
|
public static boolean stairsOn = defaults.stairsOn;
|
||||||
|
public static boolean slabsOn = defaults.slabsOn;
|
||||||
|
public static boolean carpetsOn = defaults.carpetsOn;
|
||||||
|
public static boolean fullBlocksOn = defaults.fullBlocksOn;
|
||||||
|
public static boolean customOn = defaults.customOn;
|
||||||
|
public static List<String> customBlocks = defaults.customBlocks;
|
||||||
|
enum MainReq {
|
||||||
|
empty,
|
||||||
|
restrictive,
|
||||||
|
none
|
||||||
|
}
|
||||||
|
public static MainReq mainReq = defaults.mainReq;
|
||||||
|
public static boolean mainBlock = defaults.mainBlock;
|
||||||
|
public static boolean mainFood = defaults.mainFood;
|
||||||
|
public static boolean mainUsable = defaults.mainUsable;
|
||||||
|
public static List<String> mainWhitelist = defaults.mainWhitelist;
|
||||||
|
public static List<String> mainBlacklist = defaults.mainBlacklist;
|
||||||
|
enum OffReq {
|
||||||
|
empty,
|
||||||
|
restrictive,
|
||||||
|
none
|
||||||
|
}
|
||||||
|
public static OffReq offReq = defaults.offReq;
|
||||||
|
public static boolean offBlock = defaults.offBlock;
|
||||||
|
public static boolean offFood = defaults.offFood;
|
||||||
|
public static boolean offUsable = defaults.offUsable;
|
||||||
|
public static List<String> offWhitelist = defaults.offWhitelist;
|
||||||
|
public static List<String> offBlacklist = defaults.offBlacklist;
|
||||||
|
public static void resetDefaults() {
|
||||||
|
lang = defaults.lang;
|
||||||
|
keepActive = defaults.keepActive;
|
||||||
|
sitWhileSeated = defaults.sitWhileSeated;
|
||||||
|
stairsOn = defaults.stairsOn;
|
||||||
|
slabsOn = defaults.slabsOn;
|
||||||
|
carpetsOn = defaults.carpetsOn;
|
||||||
|
fullBlocksOn = defaults.fullBlocksOn;
|
||||||
|
customOn = defaults.customOn;
|
||||||
|
customBlocks = defaults.customBlocks;
|
||||||
|
mainReq = defaults.mainReq;
|
||||||
|
mainBlock = defaults.mainBlock;
|
||||||
|
mainFood = defaults.mainFood;
|
||||||
|
mainUsable = defaults.mainUsable;
|
||||||
|
mainWhitelist = defaults.mainWhitelist;
|
||||||
|
mainBlacklist = defaults.mainBlacklist;
|
||||||
|
offReq = defaults.offReq;
|
||||||
|
offBlock = defaults.offBlock;
|
||||||
|
offFood = defaults.offFood;
|
||||||
|
offUsable = defaults.offUsable;
|
||||||
|
offWhitelist = defaults.offWhitelist;
|
||||||
|
offBlacklist = defaults.offBlacklist;
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
public static File configFile() {
|
||||||
|
return new File(FabricLoader.getInstance().getConfigDir().toFile()+"/Sit!.properties");
|
||||||
|
}
|
||||||
|
public static void load() {
|
||||||
|
if (!configFile().exists() || !configFile().canRead()) {
|
||||||
|
save();
|
||||||
|
load();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try (FileInputStream fileStream = new FileInputStream(configFile())) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.load(fileStream);
|
||||||
|
loadVersion(properties,(String) properties.computeIfAbsent("version", a -> defaults.version+""));
|
||||||
|
save();
|
||||||
|
} catch (Exception f) {
|
||||||
|
//read fail
|
||||||
|
f.printStackTrace();
|
||||||
|
resetDefaults();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void loadVersion(Properties properties, String version) {
|
||||||
|
Type mapType = new TypeToken<ArrayList<String>>() {}.getType();
|
||||||
|
lang = (String) properties.computeIfAbsent("lang", a -> defaults.lang+"");
|
||||||
|
//CONFIG
|
||||||
|
keepActive = Boolean.parseBoolean((String) properties.computeIfAbsent("keep-active", a -> defaults.keepActive+""));
|
||||||
|
sitWhileSeated = Boolean.parseBoolean((String) properties.computeIfAbsent("sit-while-seated", a -> defaults.sitWhileSeated+""));
|
||||||
|
stairsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("stairs", a -> defaults.stairsOn+""));
|
||||||
|
slabsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("slabs", a -> defaults.slabsOn+""));
|
||||||
|
carpetsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("carpets", a -> defaults.carpetsOn+""));
|
||||||
|
fullBlocksOn = Boolean.parseBoolean((String) properties.computeIfAbsent("full-blocks", a -> defaults.fullBlocksOn+""));
|
||||||
|
customOn = Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> defaults.customOn+""));
|
||||||
|
customBlocks = new Gson().fromJson((String)
|
||||||
|
properties.computeIfAbsent("custom-blocks", a -> defaults.customBlocks+""),mapType);
|
||||||
|
mainReq = MainReq.valueOf((String) properties.computeIfAbsent("main-hand-requirement", a -> defaults.mainReq+""));
|
||||||
|
mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> defaults.mainBlock+""));
|
||||||
|
mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> defaults.mainFood+""));
|
||||||
|
mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> defaults.mainUsable +""));
|
||||||
|
mainWhitelist = new Gson().fromJson((String)
|
||||||
|
properties.computeIfAbsent("main-hand-whitelist", a -> defaults.mainWhitelist+""),mapType);
|
||||||
|
mainBlacklist = new Gson().fromJson((String)
|
||||||
|
properties.computeIfAbsent("main-hand-blacklist", a -> defaults.mainBlacklist+""),mapType);
|
||||||
|
offReq = OffReq.valueOf((String) properties.computeIfAbsent("off-hand-requirement", a -> defaults.offReq+""));
|
||||||
|
offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> defaults.offBlock+""));
|
||||||
|
offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> defaults.offFood+""));
|
||||||
|
offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> defaults.offUsable +""));
|
||||||
|
offWhitelist = new Gson().fromJson((String)
|
||||||
|
properties.computeIfAbsent("off-hand-whitelist", a -> defaults.offWhitelist+""),mapType);
|
||||||
|
offBlacklist = new Gson().fromJson((String)
|
||||||
|
properties.computeIfAbsent("off-hand-blacklist", a -> defaults.offBlacklist+""),mapType);
|
||||||
|
}
|
||||||
|
public static MutableText lang(String key, Object... args) {
|
||||||
|
LangReader.loadLanguageFile();
|
||||||
|
return LangReader.of("config.sit."+key, args).getTxT();
|
||||||
|
}
|
||||||
|
public static void save() {
|
||||||
|
try (var file = new FileOutputStream(configFile(), false)) {
|
||||||
|
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||||
|
file.write("# Sit! Config\n".getBytes());
|
||||||
|
file.write(("version="+defaults.version).getBytes());
|
||||||
|
file.write(("\n# all available languages: en_us").getBytes());
|
||||||
|
file.write(("\nlang=" + lang).getBytes());
|
||||||
|
file.write(("\n\n# "+lang("general.keep_active.description").getString()).getBytes());
|
||||||
|
file.write(("\nkeep-active=" + keepActive).getBytes());
|
||||||
|
file.write(("\n# "+lang("general.sit_while_seated.description").getString()).getBytes());
|
||||||
|
file.write(("\nsit-while-seated=" + sitWhileSeated).getBytes());
|
||||||
|
file.write(("\n# "+lang("general.sittable.description").getString()).getBytes());
|
||||||
|
file.write(("\nstairs=" + stairsOn).getBytes());
|
||||||
|
file.write(("\nslabs=" + slabsOn).getBytes());
|
||||||
|
file.write(("\ncarpets=" + carpetsOn).getBytes());
|
||||||
|
file.write(("\nfull-blocks=" + fullBlocksOn).getBytes());
|
||||||
|
file.write(("\ncustom=" + customOn).getBytes());
|
||||||
|
file.write(("\n# "+lang("general.sittable_blocks.description")
|
||||||
|
.append("\n# ").append(lang("general.sittable_blocks.description_2"))
|
||||||
|
.append(lang("general.sittable_blocks.description_3",
|
||||||
|
lang("general.sittable_blocks.description_3_2"),
|
||||||
|
lang("general.sittable_blocks.description_3_3"),
|
||||||
|
lang("general.sittable_blocks.description_3_4"),
|
||||||
|
lang("general.sittable_blocks.description_3_5")))
|
||||||
|
.append("\n# ").append(lang("general.sittable_blocks.description_4"))
|
||||||
|
.append("\n# ").append(lang("general.sittable_blocks.description_5"))
|
||||||
|
.append("\n# ").append(lang("general.sittable_blocks.description_6"))
|
||||||
|
.append("\n# ").append(lang("general.sittable_blocks.description_7"))
|
||||||
|
.append("\n# ").append(lang("general.sittable_blocks.description_8")).getString()).getBytes());
|
||||||
|
file.write(("\ncustom-blocks="+gson.toJson(customBlocks)).getBytes());
|
||||||
|
file.write(("\n\n# "+lang("hand.requirements.description")
|
||||||
|
.append("\n# ").append(lang("hand.requirements.description_2"))
|
||||||
|
.append("\n# ").append(lang("hand.requirements.description_3"))
|
||||||
|
.append("\n# ").append(lang("hand.requirements.description_4")).getString()).getBytes());
|
||||||
|
file.write(("\nmain-hand-requirement=" + mainReq).getBytes());
|
||||||
|
file.write(("\nmain-hand-block=" + mainBlock).getBytes());
|
||||||
|
file.write(("\nmain-hand-food=" + mainFood).getBytes());
|
||||||
|
file.write(("\nmain-hand-usable=" + mainUsable).getBytes());
|
||||||
|
file.write(("\nmain-hand-whitelist="+gson.toJson(mainWhitelist)).getBytes());
|
||||||
|
file.write(("\nmain-hand-blacklist="+gson.toJson(mainBlacklist)).getBytes());
|
||||||
|
file.write(("\noff-hand-requirement=" + offReq).getBytes());
|
||||||
|
file.write(("\noff-hand-block=" + offBlock).getBytes());
|
||||||
|
file.write(("\noff-hand-food=" + offFood).getBytes());
|
||||||
|
file.write(("\noff-hand-usable=" + offUsable).getBytes());
|
||||||
|
file.write(("\noff-hand-whitelist="+gson.toJson(offWhitelist)).getBytes());
|
||||||
|
file.write(("\noff-hand-blacklist="+gson.toJson(offBlacklist)).getBytes());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static class defaults {
|
||||||
|
public static String version = "v1.0";
|
||||||
|
public static String lang = "en_us";
|
||||||
|
public static boolean keepActive = true;
|
||||||
|
public static boolean sitWhileSeated = true;
|
||||||
|
public static boolean stairsOn = true;
|
||||||
|
public static boolean slabsOn = true;
|
||||||
|
public static boolean carpetsOn = true;
|
||||||
|
public static boolean fullBlocksOn = false;
|
||||||
|
public static boolean customOn = false;
|
||||||
|
public static List<String> customBlocks = List.of("minecraft:campfire|.46|.5|lit=false","minecraft:soul_campfire|.46|.5|lit=false");
|
||||||
|
public static MainReq mainReq = MainReq.empty;
|
||||||
|
public static boolean mainBlock = false;
|
||||||
|
public static boolean mainFood = false;
|
||||||
|
public static boolean mainUsable = false;
|
||||||
|
public static List<String> mainWhitelist = new ArrayList<>();
|
||||||
|
public static List<String> mainBlacklist = new ArrayList<>();
|
||||||
|
public static OffReq offReq = OffReq.restrictive;
|
||||||
|
public static boolean offBlock = true;
|
||||||
|
public static boolean offFood = false;
|
||||||
|
public static boolean offUsable = true;
|
||||||
|
public static List<String> offWhitelist = List.of("minecraft:torch","minecraft:soul_torch");
|
||||||
|
public static List<String> offBlacklist = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
BIN
src/main/resources/assets/sit/icon.png
Normal file
BIN
src/main/resources/assets/sit/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
55
src/main/resources/assets/sit/lang/en_us.json
Normal file
55
src/main/resources/assets/sit/lang/en_us.json
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
{
|
||||||
|
"config.sit.empty": "Empty",
|
||||||
|
"config.sit.restrictive": "Restrictive",
|
||||||
|
"config.sit.none": "None",
|
||||||
|
"config.sit.category.general": "General",
|
||||||
|
"config.sit.category.general.tooltip": "General settings",
|
||||||
|
"config.sit.category.main_hand": "Main Hand",
|
||||||
|
"config.sit.category.main_hand.tooltip": "Main hand settings",
|
||||||
|
"config.sit.category.off_hand": "Off Hand",
|
||||||
|
"config.sit.category.off_hand.tooltip": "Off hand settings",
|
||||||
|
"config.sit.general.keep_active": "Keep Active",
|
||||||
|
"config.sit.general.keep_active.description": "Keeps the entities active even when logging off / shutting down",
|
||||||
|
"config.sit.general.sittable": "Sittable Blocks",
|
||||||
|
"config.sit.general.sittable.description": "Toggle the ability to sit on different block types.",
|
||||||
|
"config.sit.general.sit_while_seated": "Sit While Seated",
|
||||||
|
"config.sit.general.sit_while_seated.description": "Toggle the ability to sit on other blocks while already being seated on one.",
|
||||||
|
"config.sit.general.sittable.stairs": "Stairs",
|
||||||
|
"config.sit.general.sittable.slabs": "Slabs",
|
||||||
|
"config.sit.general.sittable.carpets": "Carpets",
|
||||||
|
"config.sit.general.sittable.full_blocks": "Full Blocks",
|
||||||
|
"config.sit.general.sittable.custom": "Custom",
|
||||||
|
"config.sit.general.sittable.custom.description": "Enables adding custom blocks to sit on.",
|
||||||
|
"config.sit.general.sittable_blocks": "Custom Sittable Blocks",
|
||||||
|
"config.sit.general.sittable_blocks.description": "Add custom sittable blocks!",
|
||||||
|
"config.sit.general.sittable_blocks.description_2": "Example: ",
|
||||||
|
"config.sit.general.sittable_blocks.description_3": "\"%s|%s|%s|%s\"",
|
||||||
|
"config.sit.general.sittable_blocks.description_3_2": "minecraft:campfire",
|
||||||
|
"config.sit.general.sittable_blocks.description_3_3": ".255",
|
||||||
|
"config.sit.general.sittable_blocks.description_3_4": "1",
|
||||||
|
"config.sit.general.sittable_blocks.description_3_5": "lit=false",
|
||||||
|
"config.sit.general.sittable_blocks.description_4": "First entry: custom block",
|
||||||
|
"config.sit.general.sittable_blocks.description_5": "Second entry: sitting height (number from 0-1 eg 0.52)",
|
||||||
|
"config.sit.general.sittable_blocks.description_6": "Third entry: hitbox size (where the player spawns above the entity when dismounting)",
|
||||||
|
"config.sit.general.sittable_blocks.description_7": "Fourth entry (optional): required blockstate to sit (Put a \"!\" to exclude blockstates)",
|
||||||
|
"config.sit.general.sittable_blocks.description_8": "Separate different entries with \"|\"!",
|
||||||
|
"config.sit.hand.requirements": "Requirements",
|
||||||
|
"config.sit.hand.requirements.description": "Hand requirements for sitting.",
|
||||||
|
"config.sit.hand.requirements.description_2": "Empty = hand has to be empty",
|
||||||
|
"config.sit.hand.requirements.description_3": "Restrictive = set restrictions for hand state",
|
||||||
|
"config.sit.hand.requirements.description_4": "None = can sit whenever",
|
||||||
|
"config.sit.hand.restrictions": "Restrictions",
|
||||||
|
"config.sit.hand.restrictions.description": "Toggle preset hand restrictions for sitting.",
|
||||||
|
"config.sit.hand.restrictions.blocks": "Blocks",
|
||||||
|
"config.sit.hand.restrictions.food": "Food",
|
||||||
|
"config.sit.hand.restrictions.usable": "Usable",
|
||||||
|
"config.sit.hand.restrictions.usable.description": "eg. bows, tridents, shield",
|
||||||
|
"config.sit.hand.whitelist": "Whitelist",
|
||||||
|
"config.sit.hand.whitelist.description": "Make a custom whitelist for items that the player can use to sit with.",
|
||||||
|
"config.sit.hand.blacklist": "Blacklist",
|
||||||
|
"config.sit.hand.blacklist.description": "Make a custom blacklist for items that the player can't use to sit with.",
|
||||||
|
"config.sit.hand.list.description": "Example: ",
|
||||||
|
"config.sit.hand.list.description_2": "\"minecraft:torch\"",
|
||||||
|
"key.sit.command.reloaded": "Reloaded the config!",
|
||||||
|
"key.sit.command.purged": "Purged all active chair entities!"
|
||||||
|
}
|
41
src/main/resources/fabric.mod.json
Normal file
41
src/main/resources/fabric.mod.json
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"id": "sit",
|
||||||
|
"version": "${version}",
|
||||||
|
"name": "Sit!",
|
||||||
|
"description": "Adds sitting to minecraft! Endless customizability for hand restrictions and sittable blocks.",
|
||||||
|
"authors": [
|
||||||
|
"Oth3r"
|
||||||
|
],
|
||||||
|
"contact": {
|
||||||
|
"homepage": "https://modrinth.com/mod/sit!",
|
||||||
|
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||||
|
},
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"icon": "assets/sit/icon.png",
|
||||||
|
"environment": "*",
|
||||||
|
"entrypoints": {
|
||||||
|
"main": [
|
||||||
|
"one.oth3r.sit.Sit"
|
||||||
|
],
|
||||||
|
"server": [
|
||||||
|
"one.oth3r.sit.SitServer"
|
||||||
|
],
|
||||||
|
"modmenu": [
|
||||||
|
"one.oth3r.sit.ModMenu"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mixins": [
|
||||||
|
"sit.mixins.json"
|
||||||
|
],
|
||||||
|
"depends": {
|
||||||
|
"fabricloader": ">=0.14.21",
|
||||||
|
"minecraft": "~1.20.1",
|
||||||
|
"java": ">=17",
|
||||||
|
"fabric-api": "*"
|
||||||
|
},
|
||||||
|
"suggests": {
|
||||||
|
"yet-another-config-lib": "*",
|
||||||
|
"modmenu": "*"
|
||||||
|
}
|
||||||
|
}
|
11
src/main/resources/sit.mixins.json
Normal file
11
src/main/resources/sit.mixins.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "one.oth3r.sit.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_17",
|
||||||
|
"mixins": [
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue