diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b01da52 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +# Automatically build the project and run any configured tests for every push +# and submitted pull request. This can help catch issues that only occur on +# certain platforms or Java versions, and provides a first line of defence +# against bad commits. + +name: build +on: [pull_request, push] + +jobs: + build: + strategy: + matrix: + # Use these Java versions + java: [ + 21, # Current Java LTS + ] + runs-on: ubuntu-22.04 + steps: + - name: checkout repository + uses: actions/checkout@v4 + - name: validate gradle wrapper + uses: gradle/wrapper-validation-action@v2 + - name: setup jdk ${{ matrix.java }} + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java }} + distribution: 'microsoft' + - name: make gradle wrapper executable + run: chmod +x ./gradlew + - name: build + run: ./gradlew build + - name: capture build artifacts + if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java + uses: actions/upload-artifact@v4 + with: + name: Artifacts + path: build/libs/ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c476faf --- /dev/null +++ b/.gitignore @@ -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 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1625c17 --- /dev/null +++ b/LICENSE @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..75cf199 --- /dev/null +++ b/build.gradle @@ -0,0 +1,88 @@ +plugins { + id 'fabric-loom' version '1.7-SNAPSHOT' + id 'maven-publish' +} + +version = project.mod_version +group = project.maven_group + +base { + archivesName = project.archives_base_name +} + +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. +} + +loom { + splitEnvironmentSourceSets() + + mods { + "damageindicatorreborn" { + sourceSet sourceSets.main + sourceSet sourceSets.client + } + } + +} + +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}" + +} + +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 { + create("mavenJava", MavenPublication) { + artifactId = project.archives_base_name + 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. + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..19ab944 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,17 @@ +# 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.19.2 +yarn_mappings=1.19.2+build.28 +loader_version=0.15.11 + +# Mod Properties +mod_version=1.0.0 +maven_group=com.hamusuke.damageindicatorreborn +archives_base_name=damageindicatorreborn + +# Dependencies +fabric_version=0.77.0+1.19.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e644113 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a441313 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..b740cf1 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/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/platforms/jvm/plugins-application/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##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && 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=SC2039,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=SC2039,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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -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. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +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 diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..75c4d72 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + mavenCentral() + gradlePluginPortal() + } +} \ No newline at end of file diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/DamageIndicatorRebornClient.java b/src/client/java/com/hamusuke/damageindicatorreborn/DamageIndicatorRebornClient.java new file mode 100644 index 0000000..3b3223a --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/DamageIndicatorRebornClient.java @@ -0,0 +1,130 @@ +package com.hamusuke.damageindicatorreborn; + +import com.google.common.collect.Lists; +import com.google.common.collect.Queues; +import com.hamusuke.damageindicatorreborn.command.DamageIndicatorRebornCommand; +import com.hamusuke.damageindicatorreborn.config.ClientConfig; +import com.hamusuke.damageindicatorreborn.gui.screen.ConfigScreen; +import com.hamusuke.damageindicatorreborn.math.MthH; +import com.hamusuke.damageindicatorreborn.network.DamageIndicatorPacket; +import com.hamusuke.damageindicatorreborn.network.NetworkManager; +import com.hamusuke.damageindicatorreborn.renderer.IndicatorRenderer; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.entity.LivingEntity; +import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; +import net.minecraft.text.Text; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.RaycastContext; +import net.minecraft.world.RaycastContext.FluidHandling; +import net.minecraft.world.RaycastContext.ShapeType; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.glfw.GLFW; + +import java.util.List; +import java.util.Queue; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.hamusuke.damageindicatorreborn.DamageIndicatorReborn.MOD_ID; + +@Environment(EnvType.CLIENT) +public class DamageIndicatorRebornClient implements ClientModInitializer { + private static final Logger LOGGER = LogManager.getLogger(); + public static final Queue queue = Queues.newLinkedBlockingDeque(); + public static final ClientConfig clientConfig = new ClientConfig(FabricLoader.getInstance().getConfigDir().resolve(MOD_ID + "/config.json").toFile()); + private static final KeyBinding OPEN_CONFIG = KeyBindingHelper.registerKeyBinding(new KeyBinding("key." + MOD_ID + ".openConfig", GLFW.GLFW_KEY_V, "key." + MOD_ID + ".category.indicator")); + private static final KeyBinding HIDE_INDICATOR = KeyBindingHelper.registerKeyBinding(new KeyBinding("key." + MOD_ID + ".hideIndicator.desc", GLFW.GLFW_KEY_B, "key." + MOD_ID + ".category.indicator")); + private static final Text HOW_TO_OPEN_CONFIG_SCREEN = Text.translatable(MOD_ID + ".howToOpenConfigScreen"); + public static final AtomicBoolean SERVER_SIDED = new AtomicBoolean(); + private static final float MAX_DAMAGE = 9999999.0F; + + @Override + public void onInitializeClient() { + clientConfig.load(); + + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> DamageIndicatorRebornCommand.register(dispatcher)); + + ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { + if (!clientConfig.disableMessageWhenJoined.get()) { + client.player.sendMessage(HOW_TO_OPEN_CONFIG_SCREEN); + } + + SERVER_SIDED.set(false); + handler.sendPacket(new CustomPayloadC2SPacket(NetworkManager.SYN_PACKET_ID, PacketByteBufs.empty())); + }); + + ClientPlayNetworking.registerGlobalReceiver(NetworkManager.ACK_PACKET_ID, (client, handler, buf, responseSender) -> { + if (SERVER_SIDED.get()) { + return; + } + + SERVER_SIDED.set(true); + LOGGER.info("This mod is installed on the server! You may retrieve accurate damage value!"); + }); + + ClientPlayNetworking.registerGlobalReceiver(NetworkManager.DAMAGE_PACKET_ID, (client, handler, buf, responseSender) -> { + var packet = new DamageIndicatorPacket(buf); + if (!packet.isSourcePlayer() && clientConfig.onlyRenderDamagePlayersAttacked.get()) { + return; + } + + client.send(() -> addRenderer(packet.entityId(), packet.value(), packet.source(), packet.crit())); + }); + + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (!client.isPaused()) { + List list = Lists.newArrayList(); + queue.forEach(indicatorRenderer -> { + indicatorRenderer.tick(); + if (!indicatorRenderer.isAlive()) { + list.add(indicatorRenderer); + } + }); + + queue.removeAll(list); + } + + while (OPEN_CONFIG.wasPressed()) { + client.setScreen(new ConfigScreen(client.currentScreen)); + } + + while (HIDE_INDICATOR.wasPressed()) { + clientConfig.hideIndicator.toggle(); + clientConfig.save(); + } + }); + } + + public static void addRenderer(int entityId, float value, String source, boolean crit) { + var mc = MinecraftClient.getInstance(); + if (mc.world != null && mc.player != null && mc.getEntityRenderDispatcher().camera != null) { + var clientEntity = mc.world.getEntityById(entityId); + + if (clientEntity instanceof LivingEntity livingEntity) { + double x = clientEntity.getParticleX(0.5D); + double y = clientEntity.getY() + MathHelper.nextDouble(livingEntity.getRandom(), 0.0D, 1.0D); + double z = clientEntity.getParticleZ(0.5D); + var vec3 = new Vec3d(x, y, z); + float distance = (float) mc.getEntityRenderDispatcher().camera.getPos().distanceTo(vec3); + var result = mc.world.raycast(new RaycastContext(mc.player.getPos(), vec3, ShapeType.COLLIDER, FluidHandling.NONE, mc.player)); + if ((clientConfig.forciblyRenderIndicator.get() || result.getType() == HitResult.Type.MISS) && distance <= (float) clientConfig.renderDistance.get()) { + value = Math.min(value, MAX_DAMAGE); + queue.add(new IndicatorRenderer(x, y, z, (source.equalsIgnoreCase("heal") ? "+" : "") + (clientConfig.showFloatingPoint.get() ? String.format("%.1f", value) : String.format("%d", MthH.toInt(value))), source, crit, distance)); + } + } + } + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/command/DamageIndicatorRebornCommand.java b/src/client/java/com/hamusuke/damageindicatorreborn/command/DamageIndicatorRebornCommand.java new file mode 100644 index 0000000..160428b --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/command/DamageIndicatorRebornCommand.java @@ -0,0 +1,31 @@ +package com.hamusuke.damageindicatorreborn.command; + +import com.hamusuke.damageindicatorreborn.gui.screen.ConfigScreen; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; + +import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; + +@Environment(EnvType.CLIENT) +public class DamageIndicatorRebornCommand { + public static void register(CommandDispatcher dispatcher) { + dispatcher.register( + literal("damageindicatorreborn") + .then(literal("config") + .executes(DamageIndicatorRebornCommand::openConfig)) + ); + } + + private static int openConfig(CommandContext context) { + var client = context.getSource().getClient(); + if (client.currentScreen instanceof ConfigScreen) { // should never happen. + return 0; + } + + client.send(() -> client.setScreen(new ConfigScreen(client.currentScreen))); + return 1; + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/config/ClientConfig.java b/src/client/java/com/hamusuke/damageindicatorreborn/config/ClientConfig.java new file mode 100644 index 0000000..abc770f --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/config/ClientConfig.java @@ -0,0 +1,139 @@ +package com.hamusuke.damageindicatorreborn.config; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; +import com.hamusuke.damageindicatorreborn.config.values.*; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.List; + +@Environment(EnvType.CLIENT) +public class ClientConfig { + private static final Gson GSON = new Gson(); + private static final Logger LOGGER = LogManager.getLogger(); + private final File configFile; + private final List> configRegistry = Lists.newArrayList(); + public final BooleanValue hideIndicator = this.registerConfig("hide_indicator"); + public final BooleanValue forciblyRenderIndicator = this.registerConfig("forcibly_render_indicator"); + public final DoubleValue fontSize = this.registerConfig("font_size", 1.0D, 0.0D, 1.0D); + public final IntValue renderDistance = this.registerConfig("render_distance", 64, 0, 1024); + public final BooleanValue changeColorWhenCrit = this.registerConfig("change_color_when_crit"); + public final BooleanValue showFloatingPoint = this.registerConfig("show_floating_point"); + public final BooleanValue disableBiggerFontSizeWhenCrit = this.registerConfig("disable_bigger_font_size_when_crit"); + public final BooleanValue disableMessageWhenJoined = this.registerConfig("disable_message_when_joined"); + public final BooleanValue onlyRenderDamagePlayersAttacked = this.registerConfig("only_render_damage_players_attacked"); + private final List rgbConfigRegistry = Lists.newArrayList(); + + public ClientConfig(File configFile) { + this.configFile = configFile; + + this.registerRGBConfig("in_fire_damage", 255, 150, 0); + this.registerRGBConfig("lightning_bolt_damage", 255, 80, 255); + this.registerRGBConfig("on_fire_damage", 255, 150, 0); + this.registerRGBConfig("lava_damage", 255, 150, 0); + this.registerRGBConfig("hot_floor_damage", 255, 150, 0); + this.registerRGBConfig("in_wall_damage", 255, 225, 0); + this.registerRGBConfig("cramming_damage", 255, 225, 0); + this.registerRGBConfig("drown_damage", 0, 20, 255); + this.registerRGBConfig("starve_damage", 150, 100, 0); + this.registerRGBConfig("cactus_damage", 0, 255, 0); + this.registerRGBConfig("fall_damage", 255, 225, 0); + this.registerRGBConfig("fly_into_wall_damage", 255, 225, 0); + this.registerRGBConfig("out_of_world_damage", 0, 0, 0); + this.registerRGBConfig("generic_damage"); + this.registerRGBConfig("magic_damage", 0, 255, 160); + this.registerRGBConfig("wither_damage", 25, 25, 25); + this.registerRGBConfig("anvil_damage", 255, 225, 0); + this.registerRGBConfig("falling_block_damage", 255, 225, 0); + this.registerRGBConfig("dragon_breath_damage"); + this.registerRGBConfig("dry_out_damage"); + this.registerRGBConfig("sweet_berry_bush_damage"); + this.registerRGBConfig("freeze_damage", 0, 255, 255); + this.registerRGBConfig("falling_stalactite_damage", 255, 225, 0); + this.registerRGBConfig("stalagmite_damage", 255, 225, 0); + this.registerRGBConfig("critical", 255, 255, 0); + this.registerRGBConfig("heal", 85, 255, 85); + } + + public synchronized void save() { + var parent = this.configFile.getParentFile(); + if (!parent.exists()) { + parent.mkdirs(); + } + + try (var writer = new JsonWriter(new OutputStreamWriter(new FileOutputStream(this.configFile), StandardCharsets.UTF_8))) { + writer.setIndent("\t"); + writer.beginObject(); + for (var abstractConfig : this.configRegistry) { + abstractConfig.write(writer); + } + writer.endObject(); + writer.flush(); + } catch (Exception e) { + LOGGER.warn("Error occurred while saving config.", e); + } + } + + public synchronized void load() { + if (this.configFile.exists()) { + try { + var jsonObject = GSON.fromJson(new InputStreamReader(new FileInputStream(this.configFile), StandardCharsets.UTF_8), JsonObject.class); + for (var abstractConfig : this.configRegistry) { + abstractConfig.read(jsonObject); + } + } catch (Exception e) { + LOGGER.warn("Error occurred while loading config.", e); + } + } + } + + public ImmutableList getRGBConfigs() { + return ImmutableList.copyOf(this.rgbConfigRegistry); + } + + public int getRGBFromDamageSource(String source) { + for (var rgb : this.rgbConfigRegistry) { + if (rgb.getName().replace("_", "").replace("damage", "").equalsIgnoreCase(source)) { + return rgb.get().toRGB(); + } + } + + return 16777215; + } + + private BooleanValue registerConfig(String name) { + var booleanValue = new BooleanValue(name); + this.configRegistry.add(booleanValue); + return booleanValue; + } + + private DoubleValue registerConfig(String name, double defaultValue, double min, double max) { + var doubleValue = new DoubleValue(name, defaultValue, min, max); + this.configRegistry.add(doubleValue); + return doubleValue; + } + + private IntValue registerConfig(String name, int defaultValue, int min, int max) { + var intValue = new IntValue(name, defaultValue, min, max); + this.configRegistry.add(intValue); + return intValue; + } + + private void registerRGBConfig(String name) { + this.registerRGBConfig(name, 255, 255, 255); + } + + private void registerRGBConfig(String name, int red, int green, int blue) { + var rgbValue = new RGBValue(name, red, green, blue); + this.configRegistry.add(rgbValue); + this.rgbConfigRegistry.add(rgbValue); + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/config/values/AbstractConfig.java b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/AbstractConfig.java new file mode 100644 index 0000000..d4148a0 --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/AbstractConfig.java @@ -0,0 +1,31 @@ +package com.hamusuke.damageindicatorreborn.config.values; + +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +public abstract class AbstractConfig { + protected final String name; + protected V value; + + public AbstractConfig(String name) { + this.name = name; + } + + public abstract void write(JsonWriter jsonWriter) throws IOException; + + public abstract void read(JsonObject jsonObject) throws Exception; + + public String getName() { + return this.name; + } + + public V get() { + return this.value; + } + + public void set(V value) { + this.value = value; + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/config/values/BooleanValue.java b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/BooleanValue.java new file mode 100644 index 0000000..20fcc48 --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/BooleanValue.java @@ -0,0 +1,33 @@ +package com.hamusuke.damageindicatorreborn.config.values; + +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +public class BooleanValue extends AbstractConfig { + public BooleanValue(String name) { + this(name, false); + } + + public BooleanValue(String name, boolean defaultValue) { + super(name); + this.value = defaultValue; + } + + @Override + public void write(JsonWriter jsonWriter) throws IOException { + jsonWriter.name(this.name).value(this.value); + } + + @Override + public void read(JsonObject jsonObject) { + if (jsonObject.has(this.name)) { + this.value = jsonObject.get(this.name).getAsBoolean(); + } + } + + public void toggle() { + this.set(!this.get()); + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/config/values/DoubleValue.java b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/DoubleValue.java new file mode 100644 index 0000000..8e24fac --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/DoubleValue.java @@ -0,0 +1,55 @@ +package com.hamusuke.damageindicatorreborn.config.values; + +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; +import net.minecraft.util.math.MathHelper; + +import java.io.IOException; + +public class DoubleValue extends AbstractConfig { + protected final double min; + protected final double max; + + public DoubleValue(String name, double defaultValue, double min, double max) { + super(name); + this.value = defaultValue; + this.min = min; + this.max = max; + this.clamp(); + } + + @Override + public void write(JsonWriter jsonWriter) throws IOException { + jsonWriter.name(this.name).value(this.clamp()); + } + + @Override + public void read(JsonObject jsonObject) { + if (jsonObject.has(this.name)) { + this.set(jsonObject.get(this.name).getAsDouble()); + } + } + + protected double clamp() { + return this.value = MathHelper.clamp(this.value, this.min, this.max); + } + + @Override + public Double get() { + return this.clamp(); + } + + @Override + public void set(Double value) { + this.value = value; + this.clamp(); + } + + public double getMax() { + return this.max; + } + + public double getMin() { + return this.min; + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/config/values/IntValue.java b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/IntValue.java new file mode 100644 index 0000000..18e34d5 --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/IntValue.java @@ -0,0 +1,55 @@ +package com.hamusuke.damageindicatorreborn.config.values; + +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; +import net.minecraft.util.math.MathHelper; + +import java.io.IOException; + +public class IntValue extends AbstractConfig { + protected final int min; + protected final int max; + + public IntValue(String name, int defaultValue, int min, int max) { + super(name); + this.value = defaultValue; + this.min = min; + this.max = max; + this.clamp(); + } + + @Override + public void write(JsonWriter jsonWriter) throws IOException { + jsonWriter.name(this.name).value(this.clamp()); + } + + @Override + public void read(JsonObject jsonObject) { + if (jsonObject.has(this.name)) { + this.set(jsonObject.get(this.name).getAsInt()); + } + } + + protected int clamp() { + return this.value = MathHelper.clamp(this.value, this.min, this.max); + } + + @Override + public Integer get() { + return this.clamp(); + } + + @Override + public void set(Integer value) { + this.value = value; + this.clamp(); + } + + public int getMax() { + return this.max; + } + + public int getMin() { + return this.min; + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/config/values/RGBValue.java b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/RGBValue.java new file mode 100644 index 0000000..8dc589b --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/config/values/RGBValue.java @@ -0,0 +1,87 @@ +package com.hamusuke.damageindicatorreborn.config.values; + +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; +import net.minecraft.util.math.MathHelper; + +import java.io.IOException; + +public class RGBValue extends AbstractConfig { + public RGBValue(String name, int red, int green, int blue) { + super(name); + this.value = new RGB(red, green, blue); + } + + @Override + public void write(JsonWriter jsonWriter) throws IOException { + jsonWriter.name(this.name).beginObject(); + this.value.write(jsonWriter); + jsonWriter.endObject(); + } + + @Override + public void read(JsonObject jsonObject) { + if (jsonObject.has(this.name) && jsonObject.get(this.name).isJsonObject()) { + var rgb = jsonObject.getAsJsonObject(this.name); + this.value.read(rgb); + } + } + + public static class RGB { + private final IntValue red; + private final IntValue green; + private final IntValue blue; + + public RGB(int red, int green, int blue) { + this.red = new IntValue("red", red, 0, 255); + this.green = new IntValue("green", green, 0, 255); + this.blue = new IntValue("blue", blue, 0, 255); + } + + public void write(JsonWriter writer) throws IOException { + writer.name(this.red.name).value(this.getRed()).name(this.green.name).value(this.getGreen()).name(this.blue.name).value(this.getBlue()); + } + + public void read(JsonObject jsonObject) { + if (jsonObject.has(this.red.name)) { + this.setRed(jsonObject.get(this.red.name).getAsInt()); + } + + if (jsonObject.has(this.green.name)) { + this.setGreen(jsonObject.get(this.green.name).getAsInt()); + } + + if (jsonObject.has(this.blue.name)) { + this.setBlue(jsonObject.get(this.blue.name).getAsInt()); + } + } + + public int getRed() { + return this.red.get(); + } + + public void setRed(int red) { + this.red.set(red); + } + + public int getGreen() { + return this.green.get(); + } + + public void setGreen(int green) { + this.green.set(green); + } + + public int getBlue() { + return this.blue.get(); + } + + public void setBlue(int blue) { + this.blue.set(blue); + } + + public int toRGB() { + return MathHelper.packRgb(this.getRed(), this.getGreen(), this.getBlue()); + } + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/gui/screen/ConfigScreen.java b/src/client/java/com/hamusuke/damageindicatorreborn/gui/screen/ConfigScreen.java new file mode 100644 index 0000000..5d368de --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/gui/screen/ConfigScreen.java @@ -0,0 +1,225 @@ +package com.hamusuke.damageindicatorreborn.gui.screen; + +import com.hamusuke.damageindicatorreborn.DamageIndicatorReborn; +import com.hamusuke.damageindicatorreborn.config.values.RGBValue; +import com.hamusuke.damageindicatorreborn.gui.widget.ComponentList; +import com.hamusuke.damageindicatorreborn.gui.widget.Slider; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.CyclingButtonWidget; +import net.minecraft.client.gui.widget.ElementListWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.Text; +import net.minecraft.util.math.MathHelper; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; + +import static com.hamusuke.damageindicatorreborn.DamageIndicatorReborn.MOD_ID; +import static com.hamusuke.damageindicatorreborn.DamageIndicatorRebornClient.clientConfig; + +@Environment(EnvType.CLIENT) +public class ConfigScreen extends Screen { + private static final Text HIDE_INDICATOR = Text.translatable("options." + MOD_ID + ".hideIndicator"); + private static final Text FORCE_INDICATOR_RENDERING = Text.translatable("options." + MOD_ID + ".forceindicatorrendering"); + private static final Text CHANGE_COLOR_WHEN_CRIT = Text.translatable("options." + MOD_ID + ".changeColorWhenCrit"); + private static final Text SHOW_FLOATING_POINT = Text.translatable("options." + MOD_ID + ".showFloatingPoint"); + private static final Text DISABLE_BIGGER_FONT_WHEN_CRIT = Text.translatable("options." + MOD_ID + ".disableBiggerFontWhenCrit"); + private static final Text FONT_SIZE = Text.translatable("options." + MOD_ID + ".fontsize"); + private static final Text DISPLAY_DISTANCE = Text.translatable("options." + MOD_ID + ".displayDistance"); + private static final Text DISABLE_MESSAGE_WHEN_JOINED = Text.translatable("options." + MOD_ID + ".disableMessageWhenJoined"); + private static final Text ONLY_RENDER_DAMAGE_PLAYERS_ATTACKED = Text.translatable("options." + MOD_ID + ".onlyRenderDamagePlayersAttacked"); + private final Screen parent; + private ComponentList list; + + public ConfigScreen(Screen parent) { + super(Text.translatable("options.title")); + this.parent = parent; + } + + @Override + protected void init() { + double scroll = this.list == null ? 0.0D : this.list.getScrollAmount(); + this.list = this.addDrawableChild(new ComponentList(this.client, this.width, this.height - 40, 20, this.height - 20, 20)); + this.list.setScrollAmount(scroll); + + this.list.addButton(CyclingButtonWidget.onOffBuilder(clientConfig.hideIndicator.get()).build(0, 0, 0, 20, HIDE_INDICATOR, (cycleButton, aBoolean) -> { + clientConfig.hideIndicator.set(aBoolean); + })); + + this.list.addButton(CyclingButtonWidget.onOffBuilder(clientConfig.forciblyRenderIndicator.get()).build(0, 0, 0, 20, FORCE_INDICATOR_RENDERING, (cycleButton, aBoolean) -> { + clientConfig.forciblyRenderIndicator.set(aBoolean); + })); + + this.list.addButton(CyclingButtonWidget.onOffBuilder(clientConfig.showFloatingPoint.get()).build(0, 0, 0, 20, SHOW_FLOATING_POINT, (cycleButton, aBoolean) -> { + clientConfig.showFloatingPoint.set(aBoolean); + })); + + this.list.addButton(CyclingButtonWidget.onOffBuilder(clientConfig.changeColorWhenCrit.get()).build(0, 0, 0, 20, CHANGE_COLOR_WHEN_CRIT, (cycleButton, aBoolean) -> { + clientConfig.changeColorWhenCrit.set(aBoolean); + })); + + this.list.addButton(CyclingButtonWidget.onOffBuilder(clientConfig.disableBiggerFontSizeWhenCrit.get()).build(0, 0, 0, 20, DISABLE_BIGGER_FONT_WHEN_CRIT, (cycleButton, aBoolean) -> { + clientConfig.disableBiggerFontSizeWhenCrit.set(aBoolean); + })); + + this.list.addButton(CyclingButtonWidget.onOffBuilder(clientConfig.disableMessageWhenJoined.get()).build(0, 0, 0, 20, DISABLE_MESSAGE_WHEN_JOINED, (button, value) -> { + clientConfig.disableMessageWhenJoined.set(value); + })); + + this.list.addButton(CyclingButtonWidget.onOffBuilder(clientConfig.onlyRenderDamagePlayersAttacked.get()).build(0, 0, 0, 20, ONLY_RENDER_DAMAGE_PLAYERS_ATTACKED, (button, value) -> { + clientConfig.onlyRenderDamagePlayersAttacked.set(value); + })); + + this.list.addButton(new Slider(0, 0, 0, 20, FONT_SIZE, clientConfig.fontSize.getMin(), clientConfig.fontSize.getMax(), clientConfig.fontSize.get(), slider -> clientConfig.fontSize.set(slider.getValue())) { + @Override + protected void updateMessage() { + this.setMessage(ScreenTexts.composeGenericOptionText(FONT_SIZE, Text.literal(Math.round(clientConfig.fontSize.get() * 100.0D) + "%"))); + } + }); + this.list.addButton(new Slider(0, 0, 0, 20, DISPLAY_DISTANCE, clientConfig.renderDistance.getMin(), clientConfig.renderDistance.getMax(), clientConfig.renderDistance.get(), slider -> clientConfig.renderDistance.set(slider.getIntValue()))); + + this.list.addButton(new ButtonWidget(this.width / 4, this.height / 2 + 30, this.width / 2, 20, Text.translatable(DamageIndicatorReborn.MOD_ID + ".config.colorConfig.title"), p_onPress_1_ -> this.client.setScreen(new ColorSettingsScreen(this)))); + + this.addDrawableChild(new ButtonWidget(0, this.height - 20, this.width / 2, 20, ScreenTexts.CANCEL, button -> this.close())); + this.addDrawableChild(new ButtonWidget(this.width / 2, this.height - 20, this.width / 2, 20, ScreenTexts.DONE, p_onPress_1_ -> { + clientConfig.save(); + this.close(); + })); + } + + @Override + public void render(MatrixStack p_96562_, int p_96563_, int p_96564_, float p_96565_) { + this.renderBackground(p_96562_); + super.render(p_96562_, p_96563_, p_96564_, p_96565_); + drawCenteredText(p_96562_, this.textRenderer, this.getTitle(), this.width / 2, 10, 16777215); + } + + @Override + public void close() { + this.client.setScreen(this.parent); + } + + @Environment(EnvType.CLIENT) + private static class ColorSettingsScreen extends Screen { + @Nullable + private final Screen parent; + private ColorList list; + + private ColorSettingsScreen(@Nullable Screen parent) { + super(Text.translatable(MOD_ID + ".config.colorConfig.title")); + this.parent = parent; + } + + @Override + protected void init() { + super.init(); + double amount = this.list != null ? this.list.getScrollAmount() : 0.0D; + this.list = this.addDrawableChild(new ColorList()); + this.list.setScrollAmount(amount); + this.addDrawableChild(new ButtonWidget(this.width / 2 - this.width / 4, this.height - 20, this.width / 2, 20, ScreenTexts.DONE, p_onPress_1_ -> this.close())); + } + + @Override + public void render(MatrixStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) { + this.renderBackground(p_230430_1_); + super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_); + } + + @Override + public void close() { + this.client.setScreen(this.parent); + } + + @Environment(EnvType.CLIENT) + private static class ColorMixingScreen extends Screen { + @Nullable + private final Screen parent; + private final RGBValue rgb; + private Slider red; + private Slider green; + private Slider blue; + + private ColorMixingScreen(@Nullable Screen parent, RGBValue rgb) { + super(Text.translatable(MOD_ID + ".config.color." + rgb.getName())); + this.parent = parent; + this.rgb = rgb; + } + + @Override + protected void init() { + super.init(); + + this.red = this.addDrawableChild(new Slider(this.width / 4, this.height / 2 - 70, this.width / 2, 20, Text.of("Red: "), 0.0D, 255.0D, this.rgb.get().getRed(), slider -> { + })); + this.green = this.addDrawableChild(new Slider(this.width / 4, this.height / 2 - 45, this.width / 2, 20, Text.of("Green: "), 0.0D, 255.0D, this.rgb.get().getGreen(), slider -> { + })); + this.blue = this.addDrawableChild(new Slider(this.width / 4, this.height / 2 - 20, this.width / 2, 20, Text.of("Blue: "), 0.0D, 255.0D, this.rgb.get().getBlue(), slider -> { + })); + this.addDrawableChild(new ButtonWidget(0, this.height - 20, this.width / 2, 20, ScreenTexts.CANCEL, button -> this.close())); + this.addDrawableChild(new ButtonWidget(this.width / 2, this.height - 20, this.width / 2, 20, ScreenTexts.DONE, p_onPress_1_ -> { + this.rgb.get().setRed(this.red.getIntValue()); + this.rgb.get().setGreen(this.green.getIntValue()); + this.rgb.get().setBlue(this.blue.getIntValue()); + clientConfig.save(); + this.close(); + })); + } + + @Override + public void render(MatrixStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) { + this.renderBackground(p_230430_1_); + super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_); + drawCenteredText(p_230430_1_, this.textRenderer, this.title, this.width / 2, 5, 16777215); + int color = MathHelper.packRgb(this.red.getIntValue(), this.green.getIntValue(), this.blue.getIntValue()) + (255 << 24); + this.fillGradient(p_230430_1_, this.width / 4, this.height / 2 + 5, this.width * 3 / 4, this.height - 25, color, color); + } + + @Override + public void close() { + this.client.setScreen(this.parent); + } + } + + @Environment(EnvType.CLIENT) + private class ColorList extends ElementListWidget { + public ColorList() { + super(ColorSettingsScreen.this.client, ColorSettingsScreen.this.width, ColorSettingsScreen.this.height, 20, ColorSettingsScreen.this.height - 20, 20); + for (RGBValue rgb : clientConfig.getRGBConfigs()) { + this.addEntry(new Color(rgb)); + } + } + + @Environment(EnvType.CLIENT) + private class Color extends ElementListWidget.Entry { + private final ButtonWidget button; + + private Color(RGBValue rgbConfig) { + this.button = new ButtonWidget(ColorSettingsScreen.this.width / 4, 0, ColorSettingsScreen.this.width / 2, 20, Text.translatable(DamageIndicatorReborn.MOD_ID + ".config.color." + rgbConfig.getName()), p_onPress_1_ -> ColorSettingsScreen.this.client.setScreen(new ColorMixingScreen(ColorSettingsScreen.this, rgbConfig))); + } + + @Override + public void render(MatrixStack p_230432_1_, int p_230432_2_, int p_230432_3_, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) { + this.button.y = p_230432_3_; + this.button.render(p_230432_1_, p_230432_7_, p_230432_8_, p_230432_10_); + } + + @Override + public List children() { + return Collections.singletonList(this.button); + } + + @Override + public List selectableChildren() { + return Collections.singletonList(this.button); + } + } + } + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/gui/widget/ComponentList.java b/src/client/java/com/hamusuke/damageindicatorreborn/gui/widget/ComponentList.java new file mode 100644 index 0000000..f686d42 --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/gui/widget/ComponentList.java @@ -0,0 +1,86 @@ +package com.hamusuke.damageindicatorreborn.gui.widget; + +import com.hamusuke.damageindicatorreborn.gui.widget.ComponentList.Entry; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; +import net.minecraft.client.gui.widget.ClickableWidget; +import net.minecraft.client.gui.widget.ElementListWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.Text; + +import java.util.Collections; +import java.util.List; + +@Environment(EnvType.CLIENT) +public class ComponentList extends ElementListWidget { + public ComponentList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int itemHeight) { + super(minecraftClient, width, height, top, bottom, itemHeight); + } + + public void addString(Text text) { + this.addEntry(new StringEntry(text)); + } + + public B addButton(B button) { + this.addEntry(new ButtonEntry(button)); + return button; + } + + @Environment(EnvType.CLIENT) + public static class Entry extends ElementListWidget.Entry { + @Override + public List selectableChildren() { + return Collections.emptyList(); + } + + @Override + public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + } + + @Override + public List children() { + return Collections.emptyList(); + } + } + + @Environment(EnvType.CLIENT) + public class StringEntry extends Entry { + final Text name; + private final int width; + + public StringEntry(Text p_193886_) { + this.name = p_193886_; + this.width = ComponentList.this.client.textRenderer.getWidth(this.name); + } + + @Override + public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + drawCenteredText(matrices, ComponentList.this.client.textRenderer, this.name, ComponentList.this.client.currentScreen.width / 2 - this.width / 2, y + height - 9 - 1, 16777215); + } + } + + @Environment(EnvType.CLIENT) + public static class ButtonEntry extends Entry { + final ClickableWidget button; + + public ButtonEntry(ClickableWidget button) { + this.button = button; + } + + @Override + public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + this.button.x = x; + this.button.y = y; + this.button.setWidth(entryWidth); + this.button.render(matrices, mouseX, mouseY, tickDelta); + } + + @Override + public List children() { + return List.of(this.button); + } + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/gui/widget/Slider.java b/src/client/java/com/hamusuke/damageindicatorreborn/gui/widget/Slider.java new file mode 100644 index 0000000..812bd09 --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/gui/widget/Slider.java @@ -0,0 +1,45 @@ +package com.hamusuke.damageindicatorreborn.gui.widget; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.widget.SliderWidget; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.Text; + +import java.util.function.Consumer; +import java.util.function.Function; + +@Environment(EnvType.CLIENT) +public class Slider extends SliderWidget { + protected final Text prefix; + protected final double maxValue; + protected final double minValue; + protected final Consumer applier; + + public Slider(int x, int y, int width, int height, Text prefix, double minValue, double maxValue, double currentValue, Consumer applier) { + super(x, y, width, height, Text.empty(), (currentValue - minValue) / (maxValue - minValue)); + this.maxValue = maxValue; + this.minValue = minValue; + this.applier = applier; + this.prefix = prefix; + this.updateMessage(); + } + + public int getIntValue() { + return (int) Math.round(this.getValue()); + } + + public double getValue() { + return this.value * (this.maxValue - this.minValue) + this.minValue; + } + + @Override + protected void updateMessage() { + this.setMessage(ScreenTexts.composeGenericOptionText(this.prefix, Text.of("" + this.getIntValue()))); + } + + @Override + protected void applyValue() { + this.applier.accept(this); + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/DataTrackerMixin.java b/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/DataTrackerMixin.java new file mode 100644 index 0000000..6ae7db8 --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/DataTrackerMixin.java @@ -0,0 +1,43 @@ +package com.hamusuke.damageindicatorreborn.mixin.client; + +import com.hamusuke.damageindicatorreborn.DamageIndicatorRebornClient; +import com.hamusuke.damageindicatorreborn.invoker.LivingEntityInvoker; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.entity.data.DataTracker.Entry; +import net.minecraft.util.math.MathHelper; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Environment(EnvType.CLIENT) +@Mixin(DataTracker.class) +public abstract class DataTrackerMixin { + @Shadow + @Final + private Entity trackedEntity; + + @Inject(method = "copyToFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/data/DataTracker$Entry;set(Ljava/lang/Object;)V", shift = Shift.BEFORE)) + private void assignValue(Entry _to, Entry from, CallbackInfo ci) { + if (from.get() instanceof Float f && this.trackedEntity instanceof LivingEntity living && this.trackedEntity.world.isClient && this.trackedEntity instanceof LivingEntityInvoker invoker && invoker.getDataHealth().getId() == from.getData().getId() && !DamageIndicatorRebornClient.SERVER_SIDED.get()) { + if (invoker.isFirstTick() || living.isDead()) { + return; + } + + float value = living.getHealth() - f; + if (value == 0.0F) { + return; + } + + boolean heal = value < 0.0F; + DamageIndicatorRebornClient.addRenderer(this.trackedEntity.getId(), MathHelper.abs(value), heal ? "heal" : "generic", false); + } + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/LivingEntityMixin.java b/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/LivingEntityMixin.java new file mode 100644 index 0000000..a9eee32 --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/LivingEntityMixin.java @@ -0,0 +1,31 @@ +package com.hamusuke.damageindicatorreborn.mixin.client; + +import com.hamusuke.damageindicatorreborn.DamageIndicatorRebornClient; +import com.hamusuke.damageindicatorreborn.mixin.EntityMixin; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.entity.LivingEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Environment(EnvType.CLIENT) +@Mixin(LivingEntity.class) +public abstract class LivingEntityMixin extends EntityMixin { + @Shadow + public abstract float getHealth(); + + @Inject(method = "setHealth", at = @At("HEAD")) + private void setHealth(float p_21154_, CallbackInfo ci) { + if (this.world.isClient && !DamageIndicatorRebornClient.SERVER_SIDED.get() && !this.isFirstTick()) { + float value = this.getHealth() - p_21154_; + if (value <= 0.0F) { + return; + } + + DamageIndicatorRebornClient.addRenderer(this.getId(), value, "generic", false); + } + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/WorldRendererMixin.java b/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/WorldRendererMixin.java new file mode 100644 index 0000000..8345dae --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/mixin/client/WorldRendererMixin.java @@ -0,0 +1,39 @@ +package com.hamusuke.damageindicatorreborn.mixin.client; + +import com.hamusuke.damageindicatorreborn.DamageIndicatorRebornClient; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.LightmapTextureManager; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.math.Matrix4f; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Environment(EnvType.CLIENT) +@Mixin(WorldRenderer.class) +public abstract class WorldRendererMixin { + @Shadow + @Final + private MinecraftClient client; + + @Inject(method = "render", at = @At("TAIL")) + private void render(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci) { + if (!DamageIndicatorRebornClient.clientConfig.hideIndicator.get() && !DamageIndicatorRebornClient.queue.isEmpty()) { + this.client.getProfiler().push("damage indicator rendering"); + var impl = this.client.getBufferBuilders().getEntityVertexConsumers(); + matrices.push(); + DamageIndicatorRebornClient.queue.forEach(indicatorRenderer -> indicatorRenderer.render(matrices, impl, this.client.getEntityRenderDispatcher().camera, tickDelta)); + matrices.pop(); + impl.draw(); + this.client.getProfiler().pop(); + } + } +} diff --git a/src/client/java/com/hamusuke/damageindicatorreborn/renderer/IndicatorRenderer.java b/src/client/java/com/hamusuke/damageindicatorreborn/renderer/IndicatorRenderer.java new file mode 100644 index 0000000..b11921e --- /dev/null +++ b/src/client/java/com/hamusuke/damageindicatorreborn/renderer/IndicatorRenderer.java @@ -0,0 +1,177 @@ +package com.hamusuke.damageindicatorreborn.renderer; + +import com.hamusuke.damageindicatorreborn.math.MthH; +import com.mojang.blaze3d.systems.RenderSystem; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Util; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3f; + +import static com.hamusuke.damageindicatorreborn.DamageIndicatorRebornClient.clientConfig; + +@Environment(EnvType.CLIENT) +public class IndicatorRenderer { + protected static final int maxAge = 20; + protected static final float NORMAL = 1.0F; + protected static final float CRITICAL = 2.5F; + private static final MinecraftClient mc = MinecraftClient.getInstance(); + protected double prevPosX; + protected double prevPosY; + protected double prevPosZ; + protected double x; + protected double y; + protected double z; + protected final String source; + protected boolean dead; + protected int age; + protected final String text; + protected final boolean crit; + protected float velocity; + protected int color; + protected int textWidth = -1; + protected long startedTickingTimeMs; + protected final float distance; + protected final float scaleMultiplier; + protected float currentScale = Float.NaN; + protected boolean paused; + protected long passedTimeMs; + + public IndicatorRenderer(double x, double y, double z, String text, String source, boolean crit, float distance) { + this.setPos(x, y, z); + this.prevPosX = x; + this.prevPosY = y; + this.prevPosZ = z; + this.text = text; + this.source = source; + this.crit = crit; + this.syncIndicatorColor(); + this.distance = distance; + this.scaleMultiplier = this.crit && !clientConfig.disableBiggerFontSizeWhenCrit.get() ? CRITICAL : NORMAL; + this.startedTickingTimeMs = Util.getMeasuringTimeMs(); + } + + public void tick() { + this.prevPosX = this.x; + this.prevPosY = this.y; + this.prevPosZ = this.z; + + if (this.age++ >= maxAge) { + this.markDead(); + } else if (this.age > maxAge / 2) { + this.velocity += 0.008F; + this.velocity *= 0.98F; + this.moveOnHypotenuse3d(this.velocity); + } else { + if (this.currentScale != this.currentScale) { + this.calculateScale(mc.isPaused()); + } + + this.moveOnHypotenuse3d(this.currentScale * (10.0F / (float) maxAge)); + } + } + + private void moveOnHypotenuse3d(float lengthOfHypotenuseToMove) { + if (mc.getEntityRenderDispatcher().camera == null) { + this.markDead(); + } else { + float phi = -mc.getEntityRenderDispatcher().camera.getYaw() * 0.017453292F; + float theta = mc.getEntityRenderDispatcher().camera.getPitch() * 0.017453292F; + float hypotenuse2d = lengthOfHypotenuseToMove * MathHelper.sin(theta); + this.setPos(this.x + hypotenuse2d * MathHelper.sin(phi), this.y + lengthOfHypotenuseToMove * MathHelper.cos(theta), this.z + hypotenuse2d * MathHelper.cos(phi)); + } + } + + public void render(MatrixStack matrix, VertexConsumerProvider vertexConsumers, Camera camera, float tickDelta) { + TextRenderer textRenderer = mc.textRenderer; + + if (this.textWidth < 0) { + this.textWidth = textRenderer.getWidth(this.text); + } + + if (this.textWidth == 0) { + this.markDead(); + } else { + float scale = this.calculateScale(mc.isPaused()); + scale *= clientConfig.fontSize.get(); + double x = MathHelper.lerp(tickDelta, this.prevPosX, this.x); + double y = MathHelper.lerp(tickDelta, this.prevPosY, this.y); + double z = MathHelper.lerp(tickDelta, this.prevPosZ, this.z); + Vec3d camPos = camera.getPos(); + double camX = camPos.x; + double camY = camPos.y; + double camZ = camPos.z; + + matrix.push(); + matrix.translate(x - camX, y - camY, z - camZ); + matrix.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-camera.getYaw())); + matrix.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(camera.getPitch())); + matrix.scale(-scale, -scale, scale); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.enableDepthTest(); + RenderSystem.depthMask(false); + + int alpha = 255; + if (this.age > maxAge / 2) { + alpha = (int) ((((float) (maxAge + 1) / (float) this.age) - 1.0F) * 255.0F); + } + alpha = MathHelper.clamp(alpha, 0, 255); + + int color = this.color; + if (this.age <= 3) { + color = MthH.lerpColor((Util.getMeasuringTimeMs() - this.startedTickingTimeMs) / (7.5F * (float) maxAge), color); + } + + textRenderer.draw(this.text, -textRenderer.getWidth(this.text) / 2.0F, -textRenderer.fontHeight / 2.0F, color + (alpha << 24), false, matrix.peek().getPositionMatrix(), vertexConsumers, true, 0, 15728880); + RenderSystem.disableBlend(); + RenderSystem.disableDepthTest(); + RenderSystem.depthMask(true); + matrix.pop(); + } + } + + protected float calculateScale(boolean isPaused) { + long timeDelta = Util.getMeasuringTimeMs() - this.startedTickingTimeMs; + float scale = MthH.convexUpwardQuadraticFunction(MathHelper.clamp(timeDelta / (12.5F * (float) maxAge), 0.0F, 1.0F), this.crit ? -0.2F : -0.5F, this.crit ? 2.0F : 0.5F, 0.00375F * this.distance * 1.732050807F * this.scaleMultiplier, 0.0075F * this.distance * 1.732050807F * this.scaleMultiplier * this.scaleMultiplier * (this.crit ? 1.0F : 0.8F)); + scale -= 0.00025F * this.textWidth; + scale = MathHelper.clamp(scale, 0.0001F, Float.MAX_VALUE); + + if (isPaused && !this.paused) { + this.passedTimeMs = timeDelta; + this.paused = true; + } else if (isPaused) { + return this.currentScale; + } else if (this.paused) { + this.startedTickingTimeMs = Util.getMeasuringTimeMs() - this.passedTimeMs; + this.paused = false; + return this.calculateScale(false); + } + + return this.currentScale = scale; + } + + public void markDead() { + this.dead = true; + } + + public void syncIndicatorColor() { + this.color = clientConfig.getRGBFromDamageSource(clientConfig.changeColorWhenCrit.get() && this.crit ? "critical" : this.source); + } + + public void setPos(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public boolean isAlive() { + return !this.dead; + } +} diff --git a/src/client/resources/damageindicatorreborn.client.mixins.json b/src/client/resources/damageindicatorreborn.client.mixins.json new file mode 100644 index 0000000..e1847a3 --- /dev/null +++ b/src/client/resources/damageindicatorreborn.client.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "com.hamusuke.damageindicatorreborn.mixin.client", + "compatibilityLevel": "JAVA_17", + "client": [ + "DataTrackerMixin", + "LivingEntityMixin", + "WorldRendererMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/DamageIndicatorReborn.java b/src/main/java/com/hamusuke/damageindicatorreborn/DamageIndicatorReborn.java new file mode 100644 index 0000000..e8e83e3 --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/DamageIndicatorReborn.java @@ -0,0 +1,36 @@ +package com.hamusuke.damageindicatorreborn; + +import com.hamusuke.damageindicatorreborn.invoker.EntityInvoker; +import com.hamusuke.damageindicatorreborn.network.NetworkManager; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.PersistentProjectileEntity; +import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; + +public class DamageIndicatorReborn implements ModInitializer { + public static final String MOD_ID = "damageindicatorreborn"; + + @Override + public void onInitialize() { + ServerPlayNetworking.registerGlobalReceiver(NetworkManager.SYN_PACKET_ID, (server, player, handler, buf, responseSender) -> { + player.networkHandler.sendPacket(new CustomPayloadS2CPacket(NetworkManager.ACK_PACKET_ID, PacketByteBufs.empty())); + }); + + ServerLivingEntityEvents.ALLOW_DAMAGE.register((entity, source, amount) -> { + if (!entity.world.isClient && entity instanceof EntityInvoker invoker) { + boolean crit = invoker.isCrit(); + if (source.getSource() instanceof PersistentProjectileEntity arrow) { + crit = arrow.isCritical(); + } + + invoker.setCrit(false); + invoker.sendDamageValue(amount, source.getName(), crit, source.getAttacker() instanceof PlayerEntity); + } + + return true; + }); + } +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/invoker/EntityInvoker.java b/src/main/java/com/hamusuke/damageindicatorreborn/invoker/EntityInvoker.java new file mode 100644 index 0000000..f8311f5 --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/invoker/EntityInvoker.java @@ -0,0 +1,11 @@ +package com.hamusuke.damageindicatorreborn.invoker; + +public interface EntityInvoker { + void sendDamageValue(float value, String source, boolean crit, boolean isSourcePlayer); + + void setCrit(boolean crit); + + boolean isCrit(); + + boolean isFirstTick(); +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/invoker/LivingEntityInvoker.java b/src/main/java/com/hamusuke/damageindicatorreborn/invoker/LivingEntityInvoker.java new file mode 100644 index 0000000..cbcbe52 --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/invoker/LivingEntityInvoker.java @@ -0,0 +1,7 @@ +package com.hamusuke.damageindicatorreborn.invoker; + +import net.minecraft.entity.data.TrackedData; + +public interface LivingEntityInvoker extends EntityInvoker { + TrackedData getDataHealth(); +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/math/MthH.java b/src/main/java/com/hamusuke/damageindicatorreborn/math/MthH.java new file mode 100644 index 0000000..cff333c --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/math/MthH.java @@ -0,0 +1,22 @@ +package com.hamusuke.damageindicatorreborn.math; + +import net.minecraft.util.math.MathHelper; + +public class MthH { + public static int toInt(float value) { + if (value > (float) Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } + + return MathHelper.ceil(value); + } + + public static int lerpColor(float delta, int rgb) { + float multiplier = MathHelper.clampedLerp(0.5F, 1.0F, delta); + return MathHelper.packRgb((((rgb >> 16) & 0xFF) / 255.0F) * multiplier, (((rgb >> 8) & 0xFF) / 255.0F) * multiplier, ((rgb & 0xFF) / 255.0F) * multiplier); + } + + public static float convexUpwardQuadraticFunction(float delta, float minX, float maxX, float minY, float maxY) { + return (float) (((minY - maxY) / Math.pow(MathHelper.absMax(minX, maxX), 2)) * Math.pow(MathHelper.lerp(delta, minX, maxX), 2) + maxY); + } +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/mixin/EntityMixin.java b/src/main/java/com/hamusuke/damageindicatorreborn/mixin/EntityMixin.java new file mode 100644 index 0000000..9ad55e0 --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/mixin/EntityMixin.java @@ -0,0 +1,52 @@ +package com.hamusuke.damageindicatorreborn.mixin; + +import com.hamusuke.damageindicatorreborn.invoker.EntityInvoker; +import com.hamusuke.damageindicatorreborn.network.DamageIndicatorPacket; +import com.hamusuke.damageindicatorreborn.network.NetworkManager; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.minecraft.entity.Entity; +import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(Entity.class) +public abstract class EntityMixin implements EntityInvoker { + @Shadow + public World world; + + @Shadow + public abstract int getId(); + + @Shadow + protected boolean firstUpdate; + @Shadow + public int age; + @Unique + protected boolean crit; + + @Override + public void sendDamageValue(float value, String source, boolean crit, boolean isSourcePlayer) { + if (this.world instanceof ServerWorld serverWorld) { + var packet = new DamageIndicatorPacket(this.getId(), value, source, crit, isSourcePlayer); + serverWorld.getPlayers().forEach(player -> player.networkHandler.sendPacket(new CustomPayloadS2CPacket(NetworkManager.DAMAGE_PACKET_ID, packet.write(PacketByteBufs.create())))); + } + } + + @Override + public void setCrit(boolean crit) { + this.crit = crit; + } + + @Override + public boolean isCrit() { + return this.crit; + } + + @Override + public boolean isFirstTick() { + return this.firstUpdate || this.age < 10; + } +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/mixin/LivingEntityMixin.java b/src/main/java/com/hamusuke/damageindicatorreborn/mixin/LivingEntityMixin.java new file mode 100644 index 0000000..9ea2111 --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/mixin/LivingEntityMixin.java @@ -0,0 +1,43 @@ +package com.hamusuke.damageindicatorreborn.mixin; + +import com.hamusuke.damageindicatorreborn.invoker.EntityInvoker; +import com.hamusuke.damageindicatorreborn.invoker.LivingEntityInvoker; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.data.TrackedData; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LivingEntity.class) +public abstract class LivingEntityMixin extends EntityMixin implements LivingEntityInvoker { + @Shadow + @Final + private static TrackedData HEALTH; + + @Shadow + public abstract float getMaxHealth(); + + @Shadow + public abstract float getHealth(); + + @Shadow + public abstract boolean isDead(); + + @Override + public TrackedData getDataHealth() { + return HEALTH; + } + + @Inject(method = "heal", at = @At("HEAD")) + private void heal(float amount, CallbackInfo ci) { + if (!this.isDead() && (LivingEntity) (Object) this instanceof EntityInvoker invoker) { + amount = Math.min(this.getMaxHealth() - this.getHealth(), amount); + if (!this.world.isClient && amount > 0.0F) { + invoker.sendDamageValue(amount, "heal", false, true); + } + } + } +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/mixin/PlayerMixin.java b/src/main/java/com/hamusuke/damageindicatorreborn/mixin/PlayerMixin.java new file mode 100644 index 0000000..d4d06fe --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/mixin/PlayerMixin.java @@ -0,0 +1,21 @@ +package com.hamusuke.damageindicatorreborn.mixin; + +import com.hamusuke.damageindicatorreborn.invoker.EntityInvoker; +import com.hamusuke.damageindicatorreborn.invoker.LivingEntityInvoker; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(PlayerEntity.class) +public abstract class PlayerMixin extends LivingEntityMixin implements LivingEntityInvoker { + @ModifyVariable(method = "attack", at = @At("STORE"), ordinal = 2) + private boolean attack$bl3(boolean bl3, Entity entity) { + if (bl3 && entity instanceof EntityInvoker invoker) { + invoker.setCrit(true); + } + + return bl3; + } +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/network/DamageIndicatorPacket.java b/src/main/java/com/hamusuke/damageindicatorreborn/network/DamageIndicatorPacket.java new file mode 100644 index 0000000..f044ff3 --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/network/DamageIndicatorPacket.java @@ -0,0 +1,18 @@ +package com.hamusuke.damageindicatorreborn.network; + +import net.minecraft.network.PacketByteBuf; + +public record DamageIndicatorPacket(int entityId, float value, String source, boolean crit, boolean isSourcePlayer) { + public DamageIndicatorPacket(PacketByteBuf buf) { + this(buf.readVarInt(), buf.readFloat(), buf.readString(), buf.readBoolean(), buf.readBoolean()); + } + + public PacketByteBuf write(PacketByteBuf packetByteBuf) { + packetByteBuf.writeVarInt(this.entityId); + packetByteBuf.writeFloat(this.value); + packetByteBuf.writeString(this.source); + packetByteBuf.writeBoolean(this.crit); + packetByteBuf.writeBoolean(this.isSourcePlayer); + return packetByteBuf; + } +} diff --git a/src/main/java/com/hamusuke/damageindicatorreborn/network/NetworkManager.java b/src/main/java/com/hamusuke/damageindicatorreborn/network/NetworkManager.java new file mode 100644 index 0000000..e46c2ed --- /dev/null +++ b/src/main/java/com/hamusuke/damageindicatorreborn/network/NetworkManager.java @@ -0,0 +1,10 @@ +package com.hamusuke.damageindicatorreborn.network; + +import com.hamusuke.damageindicatorreborn.DamageIndicatorReborn; +import net.minecraft.util.Identifier; + +public class NetworkManager { + public static final Identifier SYN_PACKET_ID = new Identifier(DamageIndicatorReborn.MOD_ID, "syn"); + public static final Identifier ACK_PACKET_ID = new Identifier(DamageIndicatorReborn.MOD_ID, "ack"); + public static final Identifier DAMAGE_PACKET_ID = new Identifier(DamageIndicatorReborn.MOD_ID, "damage_packet"); +} diff --git a/src/main/resources/assets/damageindicatorreborn/icon.png b/src/main/resources/assets/damageindicatorreborn/icon.png new file mode 100644 index 0000000..d2dc9da Binary files /dev/null and b/src/main/resources/assets/damageindicatorreborn/icon.png differ diff --git a/src/main/resources/assets/damageindicatorreborn/lang/en_us.json b/src/main/resources/assets/damageindicatorreborn/lang/en_us.json new file mode 100644 index 0000000..a5de40c --- /dev/null +++ b/src/main/resources/assets/damageindicatorreborn/lang/en_us.json @@ -0,0 +1,44 @@ +{ + "damageindicatorreborn.indicator.immune": "Immune", + "damageindicatorreborn.howToOpenConfigScreen": "Type '/damageindicatorreborn config' to open the config screen. This message can be disabled by config.", + "key.damageindicatorreborn.hideIndicator.desc": "Hide Damage Indicator", + "key.damageindicatorreborn.openConfig": "Open Config Screen", + "key.damageindicatorreborn.category.indicator": "Damage Indicator", + "options.damageindicatorreborn.hideIndicator": "Hide Damage Indicator", + "options.damageindicatorreborn.forceindicatorrendering": "Forcibly Render Indicator", + "options.damageindicatorreborn.fontsize": "Font Size", + "options.damageindicatorreborn.changeColorWhenCrit": "Change color when critical", + "options.damageindicatorreborn.displayDistance": "Max distance to render indicator", + "damageindicatorreborn.config.colorConfig.title": "Color Settings", + "damageindicatorreborn.config.color.in_fire_damage": "In Fire Damage", + "damageindicatorreborn.config.color.lightning_bolt_damage": "Lightning Bolt Damage", + "damageindicatorreborn.config.color.on_fire_damage": "On Fire Damage", + "damageindicatorreborn.config.color.lava_damage": "Lava Damage", + "damageindicatorreborn.config.color.hot_floor_damage": "Hot Floor Damage", + "damageindicatorreborn.config.color.in_wall_damage": "In Wall Damage", + "damageindicatorreborn.config.color.cramming_damage": "Cramming Damage", + "damageindicatorreborn.config.color.drown_damage": "Drown Damage", + "damageindicatorreborn.config.color.starve_damage": "Starve Damage", + "damageindicatorreborn.config.color.cactus_damage": "Cactus Damage", + "damageindicatorreborn.config.color.fall_damage": "Fall Damage", + "damageindicatorreborn.config.color.fly_into_wall_damage": "Fly Into Wall Damage", + "damageindicatorreborn.config.color.out_of_world_damage": "Out of World Damage", + "damageindicatorreborn.config.color.generic_damage": "Generic Damage", + "damageindicatorreborn.config.color.magic_damage": "Magic Damage", + "damageindicatorreborn.config.color.wither_damage": "Wither Damage", + "damageindicatorreborn.config.color.anvil_damage": "Anvil Damage", + "damageindicatorreborn.config.color.falling_block_damage": "Falling Block Damage", + "damageindicatorreborn.config.color.dragon_breath_damage": "Dragon Breath Damage", + "damageindicatorreborn.config.color.dry_out_damage": "Dry Out Damage", + "damageindicatorreborn.config.color.sweet_berry_bush_damage": "Sweet Berry Bush Damage", + "damageindicatorreborn.config.color.freeze_damage": "Freeze Damage", + "damageindicatorreborn.config.color.falling_stalactite_damage": "Falling Stalactite Damage", + "damageindicatorreborn.config.color.stalagmite_damage": "Stalagmite Damage", + "damageindicatorreborn.config.color.critical": "Critical", + "damageindicatorreborn.config.color.heal": "Heal", + "damageindicatorreborn.config.color.immune": "Immune", + "options.damageindicatorreborn.showFloatingPoint": "Show Floating Point", + "options.damageindicatorreborn.disableBiggerFontWhenCrit": "Disable Bigger Font Size When Critical", + "options.damageindicatorreborn.disableMessageWhenJoined": "Disable message when you joined", + "options.damageindicatorreborn.onlyRenderDamagePlayersAttacked": "Only Render Damage Because of Players" +} \ No newline at end of file diff --git a/src/main/resources/assets/damageindicatorreborn/lang/ja_jp.json b/src/main/resources/assets/damageindicatorreborn/lang/ja_jp.json new file mode 100644 index 0000000..961deaf --- /dev/null +++ b/src/main/resources/assets/damageindicatorreborn/lang/ja_jp.json @@ -0,0 +1,44 @@ +{ + "damageindicatorreborn.indicator.immune": "\u7121\u52B9", + "damageindicatorreborn.howToOpenConfigScreen": "'/damageindicatorreborn config'と打つことで設定画面を開けます。このメッセージは設定で非表示にできます。", + "key.damageindicatorreborn.hideIndicator.desc": "\u30C0\u30E1\u30FC\u30B8\u30A4\u30F3\u30B8\u30B1\u30FC\u30BF\u30FC\u3092\u96A0\u3059", + "key.damageindicatorreborn.openConfig": "\u8A2D\u5B9A\u753B\u9762\u3092\u958B\u304F", + "key.damageindicatorreborn.category.indicator": "\u30C0\u30E1\u30FC\u30B8\u30A4\u30F3\u30B8\u30B1\u30FC\u30BF\u30FC", + "options.damageindicatorreborn.hideIndicator": "\u30C0\u30E1\u30FC\u30B8\u30A4\u30F3\u30B8\u30B1\u30FC\u30BF\u30FC\u3092\u96A0\u3059", + "options.damageindicatorreborn.forceindicatorrendering": "\u5F37\u5236\u7684\u306B\u30C0\u30E1\u30FC\u30B8\u30A4\u30F3\u30B8\u30B1\u30FC\u30BF\u30FC\u3092\u63CF\u753B\u3059\u308B", + "options.damageindicatorreborn.fontsize": "\u30D5\u30A9\u30F3\u30C8\u30B5\u30A4\u30BA", + "options.damageindicatorreborn.changeColorWhenCrit": "\u30AF\u30EA\u30C6\u30A3\u30AB\u30EB\u30D2\u30C3\u30C8\u306E\u6642\u306B\u8272\u3092\u5909\u3048\u308B", + "options.damageindicatorreborn.displayDistance": "\u30C0\u30E1\u30FC\u30B8\u30A4\u30F3\u30B8\u30B1\u30FC\u30BF\u30FC\u306E\u6700\u5927\u8868\u793A\u8DDD\u96E2", + "damageindicatorreborn.config.colorConfig.title": "\u8272\u306E\u8A2D\u5B9A", + "damageindicatorreborn.config.color.in_fire_damage": "In Fire Damage", + "damageindicatorreborn.config.color.lightning_bolt_damage": "Lightning Bolt Damage", + "damageindicatorreborn.config.color.on_fire_damage": "On Fire Damage", + "damageindicatorreborn.config.color.lava_damage": "Lava Damage", + "damageindicatorreborn.config.color.hot_floor_damage": "Hot Floor Damage", + "damageindicatorreborn.config.color.in_wall_damage": "In Wall Damage", + "damageindicatorreborn.config.color.cramming_damage": "Cramming Damage", + "damageindicatorreborn.config.color.drown_damage": "Drown Damage", + "damageindicatorreborn.config.color.starve_damage": "Starve Damage", + "damageindicatorreborn.config.color.cactus_damage": "Cactus Damage", + "damageindicatorreborn.config.color.fall_damage": "Fall Damage", + "damageindicatorreborn.config.color.fly_into_wall_damage": "Fly Into Wall Damage", + "damageindicatorreborn.config.color.out_of_world_damage": "Out of World Damage", + "damageindicatorreborn.config.color.generic_damage": "Generic Damage", + "damageindicatorreborn.config.color.magic_damage": "Magic Damage", + "damageindicatorreborn.config.color.wither_damage": "Wither Damage", + "damageindicatorreborn.config.color.anvil_damage": "Anvil Damage", + "damageindicatorreborn.config.color.falling_block_damage": "Falling Block Damage", + "damageindicatorreborn.config.color.dragon_breath_damage": "Dragon Breath Damage", + "damageindicatorreborn.config.color.dry_out_damage": "Dry Out Damage", + "damageindicatorreborn.config.color.sweet_berry_bush_damage": "Sweet Berry Bush Damage", + "damageindicatorreborn.config.color.freeze_damage": "Freeze Damage", + "damageindicatorreborn.config.color.falling_stalactite_damage": "Falling Stalactite Damage", + "damageindicatorreborn.config.color.stalagmite_damage": "Stalagmite Damage", + "damageindicatorreborn.config.color.critical": "\u30AF\u30EA\u30C6\u30A3\u30AB\u30EB", + "damageindicatorreborn.config.color.heal": "Heal", + "damageindicatorreborn.config.color.immune": "\u7121\u52B9", + "options.damageindicatorreborn.showFloatingPoint": "小数点を表示する", + "options.damageindicatorreborn.disableBiggerFontWhenCrit": "クリティカルヒットの時にフォントサイズを大きくしない", + "options.damageindicatorreborn.disableMessageWhenJoined": "ワールドに入ったときのメッセージを表示しない", + "options.damageindicatorreborn.onlyRenderDamagePlayersAttacked": "プレイヤーが与えたダメージのみ表示する" +} \ No newline at end of file diff --git a/src/main/resources/damageindicatorreborn.mixins.json b/src/main/resources/damageindicatorreborn.mixins.json new file mode 100644 index 0000000..12cb5e9 --- /dev/null +++ b/src/main/resources/damageindicatorreborn.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "com.hamusuke.damageindicatorreborn.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "EntityMixin", + "LivingEntityMixin", + "PlayerMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..329928f --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "damageindicatorreborn", + "version": "${version}", + "name": "Damage Indicator Reborn", + "description": "A simple damage indicator", + "authors": [ + "hamusuke2303" + ], + "license": "CC0-1.0", + "icon": "assets/damageindicatorreborn/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "com.hamusuke.damageindicatorreborn.DamageIndicatorReborn" + ], + "client": [ + "com.hamusuke.damageindicatorreborn.DamageIndicatorRebornClient" + ] + }, + "mixins": [ + "damageindicatorreborn.mixins.json", + { + "config": "damageindicatorreborn.client.mixins.json", + "environment": "client" + } + ], + "depends": { + "fabricloader": ">=0.15.11", + "minecraft": "~1.19.2", + "java": ">=17", + "fabric-api": "*" + }, + "suggests": { + "another-mod": "*" + } +} \ No newline at end of file