diff --git a/.gitignore b/.gitignore index 288cac5..00bc0b9 100755 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,9 @@ out/ # fabric run/ -classes/ \ No newline at end of file +classes/ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/build.gradle b/build.gradle index 7f68b93..afab2e9 100755 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,96 @@ plugins { - id 'fabric-loom' version "0.5-SNAPSHOT" + id 'fabric-loom' version '1.3.1' + id 'maven-publish' } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +version = project.mod_version +group = project.maven_group -archivesBaseName = "CustomSelectionBox" -version = "5.0.2" +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. -minecraft { + maven { + url "https://maven.terraformersmc.com/releases/" + content { + includeGroup "com.terraformersmc" + } + } } -repositories { - maven { url "https://dl.bintray.com/shedaniel/legacy-yarn-updated" } +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}" + + // modmenu API + modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}") { + transitive(false) + } + modApi("com.terraformersmc:modmenu:${project.modmenu_version}") { + transitive(false) + } } processResources { - filesMatching('fabric.mod.json') { - expand 'version': project.version - } - inputs.property "version", project.version + inputs.property "version", project.version + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": project.version + } } -dependencies { - minecraft "com.mojang:minecraft:1.16.2" - mappings "me.shedaniel:legacy-yarn:1.16.2+build.9+legacy.20w09a+build.8:v2" - modCompile "net.fabricmc:fabric-loader:0.9.2+build.206" +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. + } } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..d6127a3 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,15 @@ +# 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.20.1 +yarn_mappings=1.20.1+build.10 +loader_version=0.14.22 +# Mod Properties +mod_version=fabric-1.20.1 +maven_group=me.shedaniel +archives_base_name=csb +# Dependencies +# check this on https://modmuss50.me/fabric.html +fabric_version=0.86.1+1.20.1 +modmenu_version=7.2.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index deedc7f..033e24c 100755 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5c57504..62f495d 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Fri Dec 28 12:18:45 HKT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/gradlew b/gradlew index 9aa616c..fcb6fca 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,126 @@ -#!/usr/bin/env bash +#!/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 UN*X -## +# +# 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 -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +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 -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# 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" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +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 - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +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" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,89 +129,120 @@ 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. + 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +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 -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# 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" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + 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 - i=$((i+1)) + # 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 - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then - cd "$(dirname "$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"' + +# 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 -exec "$JAVACMD" "${JVM_OPTS[@]}" -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" "$@" diff --git a/gradlew.bat b/gradlew.bat index f955316..93e3f59 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@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 @@ -9,19 +25,23 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +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= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +55,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,38 +65,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%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 +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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +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 diff --git a/settings.gradle b/settings.gradle index 683b201..f91a4fe 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1,9 +1,8 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' - url = 'http://maven.fabricmc.net/' + url = 'https://maven.fabricmc.net/' } gradlePluginPortal() } diff --git a/src/main/java/me/shedaniel/csb/CSB.java b/src/main/java/me/shedaniel/csb/CSB.java index 5f1b6aa..3b7c1dd 100644 --- a/src/main/java/me/shedaniel/csb/CSB.java +++ b/src/main/java/me/shedaniel/csb/CSB.java @@ -16,7 +16,7 @@ public class CSB implements ClientModInitializer { public static final List RENDERERS = new ArrayList<>(); public static void openSettingsGUI(MinecraftClient client, Screen parent) { - client.openScreen(new CSBSettingsScreen(parent)); + client.setScreen(new CSBSettingsScreen(parent)); } @Override diff --git a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java b/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java index de2e836..951dcc1 100644 --- a/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java +++ b/src/main/java/me/shedaniel/csb/CSBDefaultRenderer.java @@ -2,39 +2,39 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; -import me.shedaniel.csb.api.CSBRenderer; +import me.shedaniel.csb.api.CSBRenderer ; import net.minecraft.block.*; import net.minecraft.block.enums.BedPart; import net.minecraft.block.enums.PistonType; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.EntityContext; import net.minecraft.util.ActionResult; +import net.minecraft.util.Identifier; import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.*; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; import org.lwjgl.opengl.GL11; + public class CSBDefaultRenderer implements CSBRenderer { @Override public double getPriority() { return 1050d; } - + + + private static final Identifier WHITE = new Identifier("textures/misc/white.png"); + @Override - public ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitResult, float delta) { + public ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitResult) { GL11.glEnable(GL11.GL_LINE_SMOOTH); BlockPos blockPos = hitResult.getBlockPos(); BlockState blockState = world.getBlockState(blockPos); Vec3d cameraPos = camera.getPos(); - VoxelShape shape = blockState.getOutlineShape(world, blockPos, EntityContext.of(camera.getFocusedEntity())); + VoxelShape shape = blockState.getOutlineShape(world, blockPos, ShapeContext.of(camera.getFocusedEntity())); if (CSBConfig.isAdjustBoundingBoxByLinkedBlocks()) shape = adjustShapeByLinkedBlocks(world, blockState, blockPos, shape); drawOutlinedBoundingBox(shape, blockPos.getX() - cameraPos.getX(), blockPos.getY() - cameraPos.getY(), blockPos.getZ() - cameraPos.getZ(), getOutlineRed(), getOutlineGreen(), getOutlineBlue(), getOutlineAlpha()); @@ -42,26 +42,36 @@ public ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitR GL11.glDisable(GL11.GL_LINE_SMOOTH); return ActionResult.SUCCESS; } - + private void drawOutlinedBoundingBox(VoxelShape voxelShapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder vertexConsumer = tessellator.getBuffer(); - RenderSystem.pushMatrix(); RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); - RenderSystem.depthMask(false); - RenderSystem.color4f(red, green, blue, alpha); - RenderSystem.defaultAlphaFunc(); - RenderSystem.enableAlphaTest(); + RenderSystem.depthMask(MinecraftClient.isFabulousGraphicsOrBetter()); + MatrixStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.push(); + RenderSystem.applyModelViewMatrix(); + RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); RenderSystem.disableCull(); - RenderSystem.disableTexture(); RenderSystem.lineWidth(getOutlineThickness()); - vertexConsumer.begin(1, VertexFormats.POSITION); - voxelShapeIn.forEachEdge((k, l, m, n, o, p) -> { - vertexConsumer.vertex( (float)(k + xIn), (float)(l + yIn), (float)(m + zIn)).next(); - vertexConsumer.vertex( (float)(n + xIn), (float)(o + yIn), (float)(p + zIn)).next(); + vertexConsumer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES); + voxelShapeIn.forEachEdge((minX, minY, minZ, maxX, maxY, maxZ) -> { + float k = (float)(maxX - minX); + float l = (float)(maxY - minY); + float m = (float)(maxZ - minZ); + float n = MathHelper.sqrt(k * k + l * l + m * m); + k /= n; + l /= n; + m /= n; + vertexConsumer.vertex((float)(minX + xIn), (float)(minY + yIn), (float)(minZ + zIn)).color(red, green, blue, alpha).normal(k, l, m).next(); + vertexConsumer.vertex((float)(maxX + xIn), (float)(maxY + yIn), (float)(maxZ + zIn)).color(red, green, blue, alpha).normal(k, l, m).next(); }); +// voxelShapeIn.forEachEdge((k, l, m, n, o, p) -> { +// vertexConsumer.vertex( (float)(k + xIn), (float)(l + yIn), (float)(m + zIn)).next(); +// vertexConsumer.vertex( (float)(n + xIn), (float)(o + yIn), (float)(p + zIn)).next(); +// }); tessellator.draw(); // for (Box box : voxelShapeIn.getBoundingBoxes()) { // vertexConsumer.begin(1, VertexFormats.POSITION); @@ -114,95 +124,106 @@ private void drawOutlinedBoundingBox(VoxelShape voxelShapeIn, double xIn, double // tessellator.draw(); // } RenderSystem.enableCull(); - RenderSystem.disableAlphaTest(); - RenderSystem.enableAlphaTest(); RenderSystem.disableBlend(); + RenderSystem.defaultBlendFunc(); + matrixStack.pop(); + RenderSystem.applyModelViewMatrix(); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.depthMask(true); - RenderSystem.popMatrix(); } - + private void drawBlinkingBlock(VoxelShape voxelShapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder vertexConsumer = tessellator.getBuffer(); - RenderSystem.pushMatrix(); + RenderSystem.enableBlend(); RenderSystem.enableDepthTest(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); - RenderSystem.depthMask(false); - RenderSystem.color4f(red, green, blue, alpha); - RenderSystem.defaultAlphaFunc(); - RenderSystem.enableAlphaTest(); + RenderSystem.setShaderTexture(0, WHITE); + RenderSystem.depthMask(MinecraftClient.isFabulousGraphicsOrBetter()); + MatrixStack matrixStack = RenderSystem.getModelViewStack(); + matrixStack.push(); + RenderSystem.applyModelViewMatrix(); + RenderSystem.setShaderColor(red, green, blue, alpha); + RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.disableCull(); - RenderSystem.disableTexture(); VoxelShape shape = voxelShapeIn.getBoundingBoxes().stream() .map(box -> box.expand(0.005, 0.005, 0.005)) .map(VoxelShapes::cuboid) .reduce(VoxelShapes::union) .orElse(VoxelShapes.empty()).simplify(); for (Box box : shape.getBoundingBoxes()) { - box(tessellator, vertexConsumer, box.x1, box.y1, box.z1, box.x2, box.y2, box.z2, xIn, yIn, zIn); + box(tessellator, vertexConsumer, box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, xIn, yIn, zIn); } RenderSystem.enableCull(); - RenderSystem.disableAlphaTest(); - RenderSystem.enableAlphaTest(); RenderSystem.disableBlend(); + RenderSystem.defaultBlendFunc(); + matrixStack.pop(); + RenderSystem.applyModelViewMatrix(); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.depthMask(true); - RenderSystem.popMatrix(); } - + private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x1, double y1, double z1, double x2, double y2, double z2, double xIn, double yIn, double zIn) { +// 1 for min and 2 for max // x1 -= 0.005; // y1 -= 0.005; // z1 -= 0.005; // x2 += 0.005; // y2 += 0.005; // z2 += 0.005; - vertexConsumer.begin(7, VertexFormats.POSITION); +// vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); tessellator.draw(); - + //Down - vertexConsumer.begin(7, VertexFormats.POSITION); +// vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); tessellator.draw(); - + //North - vertexConsumer.begin(7, VertexFormats.POSITION); +// vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); tessellator.draw(); - + //South - vertexConsumer.begin(7, VertexFormats.POSITION); +// vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); tessellator.draw(); - + //West - vertexConsumer.begin(7, VertexFormats.POSITION); +//// vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); tessellator.draw(); - + //East - vertexConsumer.begin(7, VertexFormats.POSITION); +// vertexConsumer.begin(7, VertexFormats.POSITION); + vertexConsumer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z1 + zIn)).next(); vertexConsumer.vertex((float) (x2 + xIn), (float) (y2 + yIn), (float) (z2 + zIn)).next(); @@ -210,7 +231,7 @@ private void box(Tessellator tessellator, BufferBuilder vertexConsumer, double x vertexConsumer.vertex((float) (x2 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).next(); tessellator.draw(); } - + private VoxelShape adjustShapeByLinkedBlocks(ClientWorld world, BlockState blockState, BlockPos blockPos, VoxelShape shape) { try { if (blockState.getBlock() instanceof ChestBlock) { @@ -259,7 +280,7 @@ private VoxelShape adjustShapeByLinkedBlocks(ClientWorld world, BlockState block return VoxelShapes.union(shape, otherState.getOutlineShape(world, blockPos).offset(direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ())); } else if (blockState.getBlock() instanceof PistonHeadBlock) { // Piston Arm - Block block = blockState.getBlock(); +// Block block = blockState.getBlock(); Direction direction = blockState.get(FacingBlock.FACING); BlockState otherState = world.getBlockState(blockPos.offset(direction.getOpposite())); if (otherState.getBlock() instanceof PistonBlock && direction == otherState.get(FacingBlock.FACING) && otherState.get(PistonBlock.EXTENDED)) diff --git a/src/main/java/me/shedaniel/csb/CSBUpdateModMenuAPI.java b/src/main/java/me/shedaniel/csb/CSBUpdateModMenuAPI.java new file mode 100644 index 0000000..d746be7 --- /dev/null +++ b/src/main/java/me/shedaniel/csb/CSBUpdateModMenuAPI.java @@ -0,0 +1,15 @@ +package me.shedaniel.csb; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import me.shedaniel.csb.gui.CSBSettingsScreen; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +@Environment(EnvType.CLIENT) +public class CSBUpdateModMenuAPI implements ModMenuApi{ + @Override + public ConfigScreenFactory getModConfigScreenFactory(){ + return CSBSettingsScreen::new; + } +} diff --git a/src/main/java/me/shedaniel/csb/api/CSBRenderer.java b/src/main/java/me/shedaniel/csb/api/CSBRenderer.java index 985bf60..8c36695 100644 --- a/src/main/java/me/shedaniel/csb/api/CSBRenderer.java +++ b/src/main/java/me/shedaniel/csb/api/CSBRenderer.java @@ -72,5 +72,5 @@ default float getInnerAlpha() { return getInfo().getInnerAlpha(); } - ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitResult, float delta); + ActionResult render(ClientWorld world, Camera camera, BlockHitResult hitResult); } diff --git a/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java b/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java index 1d627a5..c33b241 100644 --- a/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java +++ b/src/main/java/me/shedaniel/csb/gui/CSBSettingsScreen.java @@ -1,11 +1,11 @@ package me.shedaniel.csb.gui; import me.shedaniel.csb.CSBConfig; +import me.shedaniel.csb.updateapi.UpdateButtonWidgetApi; import me.shedaniel.csb.utils.ConfigCache; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import java.io.FileNotFoundException; @@ -13,63 +13,63 @@ import static me.shedaniel.csb.CSBConfig.*; public class CSBSettingsScreen extends Screen { - + private final Screen parent; private ConfigCache configCache; - + public CSBSettingsScreen(Screen parent) { - super(new LiteralText("Custom Selection Box")); + super(Text.translatable("gui.csb.title")); this.parent = parent; } - + @Override public boolean keyPressed(int int_1, int int_2, int int_3) { if (int_1 == 256 && this.shouldCloseOnEsc()) { - onClose(); - client.openScreen(parent); + close(); + client.setScreen(parent); return true; } return super.keyPressed(int_1, int_2, int_3); } - + @Override protected void init() { this.configCache = new ConfigCache(enabled, red, green, blue, alpha, thickness, blinkAlpha, blinkSpeed, disableDepthBuffer, rainbow, adjustBoundingBoxByLinkedBlocks); - this.buttons.clear(); + this.clearChildren(); // left - addButton(new CSBSliderWidget(1, 4, this.height / 2 - 62, getRed())); - addButton(new CSBSliderWidget(2, 4, this.height / 2 - 38, getGreen())); - addButton(new CSBSliderWidget(3, 4, this.height / 2 - 14, getBlue())); - addButton(new CSBSliderWidget(4, 4, this.height / 2 + 10, getAlpha())); - addButton(new CSBSliderWidget(5, 4, this.height / 2 + 34, getThickness() / 7.0F)); - + addDrawableChild(new CSBSliderWidget(1, 4, this.height / 2 - 62, getRed())); + addDrawableChild(new CSBSliderWidget(2, 4, this.height / 2 - 38, getGreen())); + addDrawableChild(new CSBSliderWidget(3, 4, this.height / 2 - 14, getBlue())); + addDrawableChild(new CSBSliderWidget(4, 4, this.height / 2 + 10, getAlpha())); + addDrawableChild(new CSBSliderWidget(5, 4, this.height / 2 + 34, getThickness() / 7.0F)); + // right - addButton(new CSBSliderWidget(7, this.width - 154, this.height / 2 - 14, getBlinkAlpha())); - addButton(new CSBSliderWidget(8, this.width - 154, this.height / 2 + 10, getBlinkSpeed())); - addButton(new ButtonWidget(this.width - 154, this.height / 2 - 38, 150, 20, new LiteralText("Chroma: " + (usingRainbow() ? "ON" : "OFF")), widget -> { + addDrawableChild(new CSBSliderWidget(7, this.width - 154, this.height / 2 - 14, getBlinkAlpha())); + addDrawableChild(new CSBSliderWidget(8, this.width - 154, this.height / 2 + 10, getBlinkSpeed())); + addDrawableChild(new UpdateButtonWidgetApi(this.width - 154, this.height / 2 - 38, 150, 20, Text.translatable("gui.csb.chroma", (usingRainbow() ? Text.translatable("gui.csb.on") : Text.translatable("gui.csb.off"))), widget -> { setIsRainbow(!usingRainbow()); - widget.setMessage(new LiteralText("Chroma: " + (usingRainbow() ? "ON" : "OFF"))); + widget.setMessage(Text.translatable("gui.csb.chroma", (usingRainbow() ? Text.translatable("gui.csb.on") : Text.translatable("gui.csb.off")))); })); - addButton(new ButtonWidget(this.width - 154, this.height / 2 + 34, 150, 20, new LiteralText("Link Blocks: " + (isAdjustBoundingBoxByLinkedBlocks() ? "ON" : "OFF")), widget -> { + addDrawableChild(new UpdateButtonWidgetApi(this.width - 154, this.height / 2 + 34, 150, 20, Text.translatable("gui.csb.link_blocks", (isAdjustBoundingBoxByLinkedBlocks() ? Text.translatable("gui.csb.on") : Text.translatable("gui.csb.off"))), widget -> { setAdjustBoundingBoxByLinkedBlocks(!isAdjustBoundingBoxByLinkedBlocks()); - widget.setMessage(new LiteralText("Link Blocks: " + (isAdjustBoundingBoxByLinkedBlocks() ? "ON" : "OFF"))); + widget.setMessage(Text.translatable("gui.csb.link_blocks", (isAdjustBoundingBoxByLinkedBlocks() ? Text.translatable("gui.csb.on") : Text.translatable("gui.csb.off")))); })); - + //below - addButton(new ButtonWidget(this.width / 2 - 100, this.height - 48, 95, 20, new LiteralText("Enabled: " + (isEnabled() ? "True" : "False")), widget -> { + addDrawableChild(new UpdateButtonWidgetApi(this.width / 2 - 100, this.height - 48, 95, 20, Text.translatable("gui.csb.enabled", (isEnabled() ? Text.translatable("gui.csb.true") : Text.translatable("gui.csb.false"))), widget -> { setEnabled(!isEnabled()); - widget.setMessage(new LiteralText("Enabled: " + (isEnabled() ? "True" : "False"))); + widget.setMessage(Text.translatable("gui.csb.enabled", (isEnabled() ? Text.translatable("gui.csb.true") : Text.translatable("gui.csb.false")))); })); - addButton(new ButtonWidget(this.width / 2 + 5, this.height - 48, 95, 20, new LiteralText("Save"), widget -> { + addDrawableChild(new UpdateButtonWidgetApi(this.width / 2 + 5, this.height - 48, 95, 20, Text.translatable("gui.csb.save"), widget -> { try { saveConfig(); configCache = new ConfigCache(CSBConfig.enabled, red, green, blue, alpha, thickness, blinkAlpha, blinkSpeed, disableDepthBuffer, rainbow, adjustBoundingBoxByLinkedBlocks); } catch (FileNotFoundException e) { e.printStackTrace(); } - client.openScreen(parent); + client.setScreen(parent); })); - addButton(new ButtonWidget(this.width / 2 - 100, this.height - 24, 95, 20, new LiteralText("CSB defaults"), widget -> { + addDrawableChild(new UpdateButtonWidgetApi(this.width / 2 - 100, this.height - 24, 95, 20, Text.translatable("gui.csb.csb_defaults"), widget -> { try { reset(false); saveConfig(); @@ -79,7 +79,7 @@ protected void init() { } openSettingsGUI(client, parent); })); - addButton(new ButtonWidget(this.width / 2 + 5, this.height - 24, 95, 20, new LiteralText("MC defaults"), widget -> { + addDrawableChild(new UpdateButtonWidgetApi(this.width / 2 + 5, this.height - 24, 95, 20, Text.translatable("gui.csb.mc_defaults"), widget -> { try { reset(true); saveConfig(); @@ -90,30 +90,31 @@ protected void init() { openSettingsGUI(client, parent); })); } - + @Override - public void render(MatrixStack matrices, int par1, int par2, float par3) { + public void render(DrawContext context, int par1, int par2, float par3) { if (this.client.world == null) - this.renderBackgroundTexture(0); - fillGradient(matrices, 0, 0, this.width, 48 - 4, -1072689136, -804253680); // top - fillGradient(matrices, 0, this.height / 2 - 67, 158, this.height / 2 + 59, -1072689136, -804253680); // left - fillGradient(matrices, this.width - 158, this.height / 2 - 43, this.width, this.height / 2 + 59, -1072689136, -804253680); // right - fillGradient(matrices, 0, this.height - 48 - 4, this.width, this.height, -1072689136, -804253680); // bottom - - drawCenteredText(matrices, this.textRenderer, getTitle(), this.width / 2, (this.height - (this.height + 4 - 48)) / 2 - 4, 16777215); - - super.render(matrices, par1, par2, par3); + this.renderBackgroundTexture(context); +// this.renderBackgroundTexture(0); + context.fillGradient(0, 0, this.width, 48 - 4, -1072689136, -804253680); // top + context.fillGradient(0, this.height / 2 - 67, 158, this.height / 2 + 59, -1072689136, -804253680); // left + context.fillGradient(this.width - 158, this.height / 2 - 43, this.width, this.height / 2 + 59, -1072689136, -804253680); // right + context.fillGradient(0, this.height - 48 - 4, this.width, this.height, -1072689136, -804253680); // bottom + + context.drawCenteredTextWithShadow(this.textRenderer, getTitle(), this.width / 2, (this.height - (this.height + 4 - 48)) / 2 - 4, 16777215); + + super.render(context, par1, par2, par3); } - + @Override - public boolean isPauseScreen() { + public boolean shouldPause() { return false; } - + @Override - public void onClose() { + public void close() { configCache.save(); this.configCache = new ConfigCache(enabled, red, green, blue, alpha, thickness, blinkAlpha, blinkSpeed, disableDepthBuffer, rainbow, adjustBoundingBoxByLinkedBlocks); } - + } \ No newline at end of file diff --git a/src/main/java/me/shedaniel/csb/gui/CSBSliderWidget.java b/src/main/java/me/shedaniel/csb/gui/CSBSliderWidget.java index ecb785f..c4edae0 100644 --- a/src/main/java/me/shedaniel/csb/gui/CSBSliderWidget.java +++ b/src/main/java/me/shedaniel/csb/gui/CSBSliderWidget.java @@ -2,7 +2,7 @@ import me.shedaniel.csb.CSBConfig; import net.minecraft.client.gui.widget.SliderWidget; -import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import static me.shedaniel.csb.CSBConfig.*; @@ -11,68 +11,47 @@ public class CSBSliderWidget extends SliderWidget { private final int id; CSBSliderWidget(int i, int x, int y, float f) { - super(x, y, 150, 20, LiteralText.EMPTY, f); + super(x, y, 150, 20, Text.empty(), f); this.id = i; - this.setMessage(new LiteralText(getDisplayString(i))); + this.setMessage(getDisplayString(i)); } @Override protected void updateMessage() { - setMessage(new LiteralText(getDisplayString(id))); + setMessage(getDisplayString(id)); } @Override protected void applyValue() { updateValue(id); } - + private void updateValue(int id) { switch (id) { - case 1: - setRed(getValue()); - break; - case 2: - setGreen(getValue()); - break; - case 3: - setBlue(getValue()); - break; - case 4: - CSBConfig.setAlpha(getValue()); - break; - case 5: - setThickness(getValue() * 7); - break; - case 7: - setBlinkAlpha(getValue()); - break; - case 8: - setBlinkSpeed(getValue()); + case 1 -> setRed(getValue()); + case 2 -> setGreen(getValue()); + case 3 -> setBlue(getValue()); + case 4 -> CSBConfig.setAlpha(getValue()); + case 5 -> setThickness(getValue() * 7); + case 7 -> setBlinkAlpha(getValue()); + case 8 -> setBlinkSpeed(getValue()); } } - + private float getValue() { return (float) value; } - - private String getDisplayString(int id) { - switch (id) { - case 1: - return "Red: " + Math.round(getValue() * 255.0F); - case 2: - return "Green: " + Math.round(getValue() * 255.0F); - case 3: - return "Blue: " + Math.round(getValue() * 255.0F); - case 4: - return "Outline Alpha: " + Math.round(getValue() * 255.0F); - case 5: - return "Outline Thickness: " + Math.round(getValue() * 7.0F); - case 7: - return "Blink Alpha: " + Math.round(getValue() * 255.0F); - case 8: - return "Blink Speed: " + Math.round(getValue() * 100.0F); - } - return "Option Error?! (" + id + ")"; + + private Text getDisplayString(int id) { + return switch (id) { + case 1 -> Text.translatable("gui.csb.red" , Math.round(getValue() * 255.0F)); + case 2 -> Text.translatable("gui.csb.green" , Math.round(getValue() * 255.0F)); + case 3 -> Text.translatable("gui.csb.blue" , Math.round(getValue() * 255.0F)); + case 4 -> Text.translatable("gui.csb.outline_alpha" , Math.round(getValue() * 255.0F)); + case 5 -> Text.translatable("gui.csb.outline_thickness" , Math.round(getValue() * 7.0F)); + case 7 -> Text.translatable("gui.csb.blink_alpha" , Math.round(getValue() * 255.0F)); + case 8 -> Text.translatable("gui.csb.blink_speed" , Math.round(getValue() * 100.0F)); + default -> Text.of("Option Error?! (" + id + ")"); + }; } - } \ No newline at end of file diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java b/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java index 9b788fb..28c8351 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinChatScreen.java @@ -21,7 +21,7 @@ protected MixinChatScreen(Text title) { } @Inject(method = "keyPressed", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;openScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 1), + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V", ordinal = 1), cancellable = true) public void keyPressed(int int_1, int int_2, int int_3, CallbackInfoReturnable ci) { String[] split = this.chatField.getText().trim().toLowerCase().split(" "); diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java index 5edc249..e6ee625 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayNetworkHandler.java @@ -5,9 +5,11 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.ServerInfo; +import net.minecraft.client.util.telemetry.WorldSession; import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket; -import net.minecraft.server.command.CommandSource; +import net.minecraft.command.CommandSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -22,7 +24,7 @@ public class MixinClientPlayNetworkHandler { @Shadow private CommandDispatcher commandDispatcher; @Inject(method = "", at = @At("RETURN")) - private void init(MinecraftClient client, Screen screen, ClientConnection connection, GameProfile profile, CallbackInfo ci) { + private void init(MinecraftClient client, Screen screen, ClientConnection connection, ServerInfo serverInfo, GameProfile profile, WorldSession worldSession, CallbackInfo ci) { commandDispatcher.register(literal("csbconfig")); } diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java index 5e3439a..3eba2d2 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinClientPlayerEntity.java @@ -3,7 +3,7 @@ import me.shedaniel.csb.gui.CSBSettingsScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.network.ClientPlayNetworkHandler; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -11,16 +11,16 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ClientPlayerEntity.class) +@Mixin(ClientPlayNetworkHandler.class) public class MixinClientPlayerEntity { - @Shadow @Final protected MinecraftClient client; + @Shadow @Final private MinecraftClient client; - @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) + @Inject(method = "sendChatCommand", at = @At("HEAD"), cancellable = true) public void sendChatMessage(String message, CallbackInfo ci) { String[] split = message.toLowerCase().split(" "); - if (split.length > 0 && split[0].contentEquals("/csbconfig")) { - client.openScreen(new CSBSettingsScreen(client.currentScreen instanceof ChatScreen ? null : client.currentScreen)); + if (split.length > 0 && split[0].contentEquals("csbconfig")) { + client.setScreen(new CSBSettingsScreen(client.currentScreen instanceof ChatScreen ? null : client.currentScreen)); ci.cancel(); } } diff --git a/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java b/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java index 5092284..6f8587d 100644 --- a/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java +++ b/src/main/java/me/shedaniel/csb/mixin/MixinWorldRenderer.java @@ -8,11 +8,10 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityContext; import net.minecraft.util.ActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Matrix4f; +import org.joml.Matrix4f; import net.minecraft.util.shape.VoxelShape; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -40,11 +39,10 @@ public abstract class MixinWorldRenderer implements CSBInfo { @Unique private float a = 0f; @Unique private float blinkingAlpha = 0f; @Shadow private ClientWorld world; - - @Shadow - private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer vertexConsumer, VoxelShape voxelShape, double d, double e, double f, float g, float h, float i, float j) { - } - + + @Shadow protected abstract void drawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos pos, BlockState state); + + @Shadow @Final private MinecraftClient client; @Redirect(method = "render", at = @At(value = "INVOKE", @@ -52,8 +50,7 @@ private static void drawShapeOutline(MatrixStack matrixStack, VertexConsumer ver ordinal = 0)) private void onDrawShapeOutline(WorldRenderer worldRenderer, MatrixStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos blockPos, BlockState blockState) { if (!isEnabled()) { - drawShapeOutline(matrixStack, vertexConsumer, blockState.getOutlineShape(world, blockPos, EntityContext.of(entity)), blockPos.getX() - d, blockPos.getY() - e, blockPos.getZ() - f, 0.0F, 0.0F, 0.0F, 0.4F); - return; + drawBlockOutline(matrixStack, vertexConsumer, entity, d, e, f, blockPos, blockState); return; } render = true; } @@ -78,7 +75,7 @@ private void renderWorldBorder(MatrixStack matrices, float delta, long limitTime BlockHitResult hitResult = (BlockHitResult) client.crosshairTarget; BlockPos blockPos = hitResult.getBlockPos(); for (CSBRenderer renderer : RENDERERS) { - ActionResult result = Objects.requireNonNull(renderer.render(world, camera, hitResult, delta)); + ActionResult result = Objects.requireNonNull(renderer.render(world, camera, hitResult)); if (result != ActionResult.PASS) break; } diff --git a/src/main/java/me/shedaniel/csb/updateapi/UpdateButtonWidgetApi.java b/src/main/java/me/shedaniel/csb/updateapi/UpdateButtonWidgetApi.java new file mode 100644 index 0000000..49fbc12 --- /dev/null +++ b/src/main/java/me/shedaniel/csb/updateapi/UpdateButtonWidgetApi.java @@ -0,0 +1,10 @@ +package me.shedaniel.csb.updateapi; + +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.text.Text; + +public class UpdateButtonWidgetApi extends ButtonWidget{ + public UpdateButtonWidgetApi(int x, int y, int width, int height, Text message, PressAction onPress/*, NarrationSupplier narrationSupplier*/) { + super(x,y,width,height,message,onPress,DEFAULT_NARRATION_SUPPLIER); + } +} diff --git a/src/main/resources/assets/csb/lang/en_us.json b/src/main/resources/assets/csb/lang/en_us.json new file mode 100644 index 0000000..a0abc05 --- /dev/null +++ b/src/main/resources/assets/csb/lang/en_us.json @@ -0,0 +1,20 @@ +{ + "gui.csb.chroma": "Chroma: %s", + "gui.csb.title": "Custom Selection Box", + "gui.csb.on": "ON", + "gui.csb.off": "OFF", + "gui.csb.link_blocks": "Link Blocks: %s", + "gui.csb.enabled": "Enabled: %s", + "gui.csb.true": "True", + "gui.csb.false": "False", + "gui.csb.save": "Save", + "gui.csb.csb_defaults": "CSB defaults", + "gui.csb.mc_defaults": "MC defaults", + "gui.csb.red": "Red: %d", + "gui.csb.green": "Green: %d", + "gui.csb.blue": "Blue: %d", + "gui.csb.outline_alpha": "Outline Alpha: %d", + "gui.csb.outline_thickness": "Outline Thickness: %d", + "gui.csb.blink_alpha": "Blink Alpha: %d", + "gui.csb.blink_speed": "Blink Speed: %d" +} \ No newline at end of file diff --git a/src/main/resources/assets/csb/lang/zh_cn.json b/src/main/resources/assets/csb/lang/zh_cn.json new file mode 100644 index 0000000..f9ab5cc --- /dev/null +++ b/src/main/resources/assets/csb/lang/zh_cn.json @@ -0,0 +1,20 @@ +{ + "gui.csb.chroma": "彩虹选择框(Chroma): %s", + "gui.csb.title": "自定义选择框", + "gui.csb.on": "开启", + "gui.csb.off": "关闭", + "gui.csb.link_blocks": "相连方块同框: %s", + "gui.csb.enabled": "已启动: %s", + "gui.csb.true": "是", + "gui.csb.false": "否", + "gui.csb.save": "保存配置", + "gui.csb.csb_defaults": "CSB默认配置", + "gui.csb.mc_defaults": "MC默认配置", + "gui.csb.red": "红色: %d", + "gui.csb.green": "绿色: %d", + "gui.csb.blue": "蓝色: %d", + "gui.csb.outline_alpha": "外框线强度(alpha): %d", + "gui.csb.outline_thickness": "外框线宽度: %d", + "gui.csb.blink_alpha": "表面闪烁光效强度(alpha): %d", + "gui.csb.blink_speed": "表面闪烁光效频率: %d" +} \ No newline at end of file diff --git a/src/main/resources/csb.mixins.json b/src/main/resources/csb.mixins.json index 7d0cb11..6fe1e55 100644 --- a/src/main/resources/csb.mixins.json +++ b/src/main/resources/csb.mixins.json @@ -1,7 +1,7 @@ { "required": true, "package": "me.shedaniel.csb.mixin", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_17", "client": [ "MixinWorldRenderer", "MixinClientPlayerEntity", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 684b2e3..15fa2a9 100755 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,6 +12,9 @@ ], "csb_renderers": [ "me.shedaniel.csb.CSBDefaultRenderer" + ], + "modmenu": [ + "me.shedaniel.csb.CSBUpdateModMenuAPI" ] }, "contact": {