diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d68846 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# gradle + +.gradle/ +build/ +out/ +classes/ + +# eclipse + +*.launch + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# macos + +*.DS_Store + +# fabric + +run/ +/logs/ +/minecraft/ +/minecraft/* +/minepkg-lock.toml diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..3e9eb93 --- /dev/null +++ b/build.gradle @@ -0,0 +1,77 @@ +plugins { + alias libs.plugins.loom + id 'maven-publish' +} +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 + +archivesBaseName = project.archives_base_name +version = project.version +group = project.maven_group + +repositories { + maven { url "https://maven.shedaniel.me/" } + maven { url = "https://maven.terraformersmc.com/"} +} + +dependencies { + minecraft libs.minecraft + mappings variantOf(libs.yarn) { classifier 'v2' } + modImplementation libs.fabricloader + modImplementation libs.fabric + + // ModMenu + modCompileOnly modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { + exclude group: "net.fabricmc.fabric-api" + } + modCompileOnly modRuntimeOnly ("com.terraformersmc:modmenu:${project.mod_menu_version}") { + exclude group: "net.fabricmc.fabric-api" + } + + } + +processResources { + inputs.property "version", version + inputs.property "minecraft_version", libs.minecraft + inputs.property "loader_version", libs.fabricloader + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": version, + "minecraft_version": libs.minecraft, + "loader_version": libs.fabricloader + } +} + +def targetJavaVersion = 17 +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + it.options.release = targetJavaVersion + } +} + +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } + archivesBaseName = project.archives_base_name + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } +} + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } + repositories {} +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..79431d4 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,11 @@ +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx2G + +# Mod Properties +version = 5.8-1.19.2 +maven_group = com.dainxt +archives_base_name = WeaponThrow + +# Dependencies +cloth_config_version=8.2.88 +mod_menu_version=4.0.6 \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..b9575a2 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,18 @@ +[versions] +minecraft = "1.19.2" +yarn= "1.19.2+build.28" +fabricloader= "0.14.12" +fabric="0.76.0+1.19.2" + +[libraries] +minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } +yarn = { module = "net.fabricmc:yarn", version.ref = "yarn" } +fabricloader = { module = "net.fabricmc:fabric-loader", version.ref = "fabricloader" } +fabric = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric" } + +# If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". +[bundles] +fabricapi = ["fabricloader", "fabric"] + +[plugins] +loom = { id = "fabric-loom", version = "1.1-SNAPSHOT" } \ 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..943f0cb 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..0c85a1f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..65dcd68 --- /dev/null +++ b/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /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. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..f91a4fe --- /dev/null +++ b/settings.gradle @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/ClientMod.java b/src/main/java/com/dainxt/weaponthrow/ClientMod.java index 9f3bd70..8986ebd 100644 --- a/src/main/java/com/dainxt/weaponthrow/ClientMod.java +++ b/src/main/java/com/dainxt/weaponthrow/ClientMod.java @@ -1,24 +1,24 @@ -package com.dainxt.weaponthrow; - -import com.dainxt.weaponthrow.handlers.EventsHandler; -import com.dainxt.weaponthrow.handlers.KeyBindingHandler; -import com.dainxt.weaponthrow.handlers.PacketHandler; -import com.dainxt.weaponthrow.handlers.RenderRegistry; - -import net.fabricmc.api.ClientModInitializer; - -public class ClientMod implements ClientModInitializer{ - - @Override - public void onInitializeClient() { - - EventsHandler.registerClientEvents(); - - RenderRegistry.registerRenderers(); - - PacketHandler.registerClientListeners(); - - KeyBindingHandler.registerKeyBindings(); - } - -} +package com.dainxt.weaponthrow; + +import com.dainxt.weaponthrow.handlers.EventsHandler; +import com.dainxt.weaponthrow.handlers.KeyBindingHandler; +import com.dainxt.weaponthrow.handlers.PacketHandler; +import com.dainxt.weaponthrow.handlers.RenderRegistry; + +import net.fabricmc.api.ClientModInitializer; + +public class ClientMod implements ClientModInitializer{ + + @Override + public void onInitializeClient() { + + EventsHandler.registerClientEvents(); + + RenderRegistry.registerRenderers(); + + PacketHandler.registerClientListeners(); + + KeyBindingHandler.registerKeyBindings(); + } + +} diff --git a/src/main/java/com/dainxt/weaponthrow/ModMenuIntegration.java b/src/main/java/com/dainxt/weaponthrow/ModMenuIntegration.java index 812daaa..3ec971a 100644 --- a/src/main/java/com/dainxt/weaponthrow/ModMenuIntegration.java +++ b/src/main/java/com/dainxt/weaponthrow/ModMenuIntegration.java @@ -1,19 +1,18 @@ -package com.dainxt.weaponthrow; - -import com.dainxt.weaponthrow.config.WeaponThrowConfig; -import com.terraformersmc.modmenu.api.ConfigScreenFactory; -import com.terraformersmc.modmenu.api.ModMenuApi; - -import me.shedaniel.autoconfig.AutoConfig; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; - -@Environment(EnvType.CLIENT) -public class ModMenuIntegration implements ModMenuApi{ - - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parent -> AutoConfig.getConfigScreen(WeaponThrowConfig.class, parent).get(); - } - -} +package com.dainxt.weaponthrow; + +import com.dainxt.weaponthrow.config.WeaponThrowConfig; +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; + +import me.shedaniel.autoconfig.AutoConfig; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +@Environment(EnvType.CLIENT) +public class ModMenuIntegration implements ModMenuApi{ + + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parent -> AutoConfig.getConfigScreen(WeaponThrowConfig.class, parent).get(); + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/capabilities/PlayerThrowData.java b/src/main/java/com/dainxt/weaponthrow/capabilities/PlayerThrowData.java index 15a62b4..916279e 100644 --- a/src/main/java/com/dainxt/weaponthrow/capabilities/PlayerThrowData.java +++ b/src/main/java/com/dainxt/weaponthrow/capabilities/PlayerThrowData.java @@ -1,65 +1,65 @@ -package com.dainxt.weaponthrow.capabilities; - -import com.dainxt.weaponthrow.WeaponThrow; -import com.dainxt.weaponthrow.handlers.ConfigRegistry; -import com.dainxt.weaponthrow.packets.CPacketThrow; -import com.dainxt.weaponthrow.packets.CPacketThrow.State; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.MathHelper; - -public class PlayerThrowData { - - //Client - public int MAX_CHARGE = -1; - - //Both - CPacketThrow.State action = CPacketThrow.State.NONE; - - //Server - int chargeTime = -1; - - ItemStack item = ItemStack.EMPTY; - - PlayerEntity user; - - public PlayerThrowData(PlayerEntity player) { - this.user = player; - } - - public void setAction(CPacketThrow.State action) { - this.action = action; - } - - public State getAction() { - return this.action; - } - - public int getChargeTime() { - return chargeTime; - } - - public void startCharging(ItemStack stack) { - this.item=stack.copy(); - chargeTime = PlayerThrowData.getMaximumCharge(user); - } - - public ItemStack getChargingStack() { - return item; - } - - public void resetCharging() { - this.action = this.action.equals(State.DURING) ? State.FINISH : this.action; - this.item = ItemStack.EMPTY; - chargeTime = -1; - } - - public void setChargeTime(int ticks) { - chargeTime = ticks; - } - - public static int getMaximumCharge(PlayerEntity player) { - return MathHelper.floor(player.getAttackCooldownProgressPerTick()*ConfigRegistry.COMMON.get().times.castTimeMuliplier); - } -} +package com.dainxt.weaponthrow.capabilities; + +import com.dainxt.weaponthrow.WeaponThrow; +import com.dainxt.weaponthrow.handlers.ConfigRegistry; +import com.dainxt.weaponthrow.packets.CPacketThrow; +import com.dainxt.weaponthrow.packets.CPacketThrow.State; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; + +public class PlayerThrowData { + + //Client + public int MAX_CHARGE = -1; + + //Both + CPacketThrow.State action = CPacketThrow.State.NONE; + + //Server + int chargeTime = -1; + + ItemStack item = ItemStack.EMPTY; + + PlayerEntity user; + + public PlayerThrowData(PlayerEntity player) { + this.user = player; + } + + public void setAction(CPacketThrow.State action) { + this.action = action; + } + + public State getAction() { + return this.action; + } + + public int getChargeTime() { + return chargeTime; + } + + public void startCharging(ItemStack stack) { + this.item=stack.copy(); + chargeTime = PlayerThrowData.getMaximumCharge(user); + } + + public ItemStack getChargingStack() { + return item; + } + + public void resetCharging() { + this.action = this.action.equals(State.DURING) ? State.FINISH : this.action; + this.item = ItemStack.EMPTY; + chargeTime = -1; + } + + public void setChargeTime(int ticks) { + chargeTime = ticks; + } + + public static int getMaximumCharge(PlayerEntity player) { + return MathHelper.floor(player.getAttackCooldownProgressPerTick()*ConfigRegistry.COMMON.get().times.castTimeMuliplier); + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/config/WeaponThrowConfig.java b/src/main/java/com/dainxt/weaponthrow/config/WeaponThrowConfig.java index cb495a8..feb34e3 100644 --- a/src/main/java/com/dainxt/weaponthrow/config/WeaponThrowConfig.java +++ b/src/main/java/com/dainxt/weaponthrow/config/WeaponThrowConfig.java @@ -71,7 +71,7 @@ public static class Multipliers implements ConfigData { @ConfigEntry.Gui.CollapsibleObject public ToolMultipliers tools = new ToolMultipliers(); - public class ToolMultipliers implements ConfigData { + public static class ToolMultipliers implements ConfigData { public double pickaxeMultiplier = 0.8D; public double axeMultiplier = 1.2D; public double swordMultiplier = 1.D; @@ -82,7 +82,7 @@ public class ToolMultipliers implements ConfigData { @ConfigEntry.Gui.CollapsibleObject public DamageMultipliers damages = new DamageMultipliers(); - public class DamageMultipliers implements ConfigData { + public static class DamageMultipliers implements ConfigData { public double baseDamageMultiplier = 0.25D; public double stackDamageMultiplier = 0.0D; public double modifiedDamageMultiplier = 0.50D; @@ -91,7 +91,7 @@ public class DamageMultipliers implements ConfigData { @ConfigEntry.Gui.CollapsibleObject public VelocityMultipliers velocities = new VelocityMultipliers(); - public class VelocityMultipliers implements ConfigData { + public static class VelocityMultipliers implements ConfigData { public double baseVelocityMultiplier = 0.25D; public double stackVelocityMultiplier = 0.005D; public double modifiedVelocityMultiplier = 0.4D; @@ -100,7 +100,7 @@ public class VelocityMultipliers implements ConfigData { @ConfigEntry.Gui.CollapsibleObject public ExhaustionMultipliers exhaustions = new ExhaustionMultipliers(); - public class ExhaustionMultipliers implements ConfigData { + public static class ExhaustionMultipliers implements ConfigData { public double baseExhaustionMultiplier = 0.075D; public double stackExhaustionMultiplier = 0.01D; public double modifiedExhaustionMultiplier = 2.0D; diff --git a/src/main/java/com/dainxt/weaponthrow/enchantment/ConccusionEnchantment.java b/src/main/java/com/dainxt/weaponthrow/enchantment/ConccusionEnchantment.java index 1e59c5a..f966e4c 100644 --- a/src/main/java/com/dainxt/weaponthrow/enchantment/ConccusionEnchantment.java +++ b/src/main/java/com/dainxt/weaponthrow/enchantment/ConccusionEnchantment.java @@ -9,34 +9,25 @@ import net.minecraft.item.ItemStack; public class ConccusionEnchantment extends Enchantment { - public ConccusionEnchantment(Enchantment.Rarity rarityIn, EquipmentSlot... slots) { super(rarityIn, EnchantmentTarget.WEAPON, slots); } - public int getMinPower(int enchantmentLevel) { return 30; } - - public int getMaxPower(int enchantmentLevel) { return this.getMinPower(enchantmentLevel) + 30; } - - /** - * Returns the maximum level that the enchantment can have. - */ + // Returns the maximum level that the enchantment can have. public int getMaxLevel() { return 2; } - - @Override public boolean isAcceptableItem(ItemStack stack) { boolean enchantAll = ConfigRegistry.COMMON.getConfig().enchantments.enchantAllWeapons; boolean isAxe = stack.getItem() instanceof AxeItem; boolean canApply = super.isAcceptableItem(stack); - return isAxe || canApply || enchantAll ? ConfigRegistry.COMMON.getConfig().enchantments.enableConccusion : false; + return (isAxe || canApply || enchantAll) && ConfigRegistry.COMMON.getConfig().enchantments.enableConccusion; } } diff --git a/src/main/java/com/dainxt/weaponthrow/enchantment/GravityEnchantment.java b/src/main/java/com/dainxt/weaponthrow/enchantment/GravityEnchantment.java index da9bfb1..ad4c8cc 100644 --- a/src/main/java/com/dainxt/weaponthrow/enchantment/GravityEnchantment.java +++ b/src/main/java/com/dainxt/weaponthrow/enchantment/GravityEnchantment.java @@ -38,6 +38,6 @@ public boolean isAcceptableItem(ItemStack stack) { boolean enchantAll = ConfigRegistry.COMMON.getConfig().enchantments.enchantAllWeapons; boolean isAxe = stack.getItem() instanceof AxeItem; boolean canApply = super.isAcceptableItem(stack); - return isAxe || canApply || enchantAll ? ConfigRegistry.COMMON.getConfig().enchantments.enableGravity : false; + return (isAxe || canApply || enchantAll) && ConfigRegistry.COMMON.getConfig().enchantments.enableGravity; } } diff --git a/src/main/java/com/dainxt/weaponthrow/enchantment/GroundedEdgeEnchantment.java b/src/main/java/com/dainxt/weaponthrow/enchantment/GroundedEdgeEnchantment.java index 1dee356..45af653 100644 --- a/src/main/java/com/dainxt/weaponthrow/enchantment/GroundedEdgeEnchantment.java +++ b/src/main/java/com/dainxt/weaponthrow/enchantment/GroundedEdgeEnchantment.java @@ -14,9 +14,7 @@ public GroundedEdgeEnchantment(Enchantment.Rarity rarityIn, EquipmentSlot... slo super(rarityIn, EnchantmentTarget.WEAPON, slots); } - /** - * Returns the minimal value of enchantability needed on the enchantment level passed. - */ + // Returns the minimal value of enchantability needed on the enchantment level passed. public int getMinEnchantability(int enchantmentLevel) { return 25; } @@ -24,10 +22,7 @@ public int getMinEnchantability(int enchantmentLevel) { public int getMaxEnchantability(int enchantmentLevel) { return this.getMinEnchantability(enchantmentLevel) + 40; } - - /** - * Returns the maximum level that the enchantment can have. - */ + // Returns the maximum level that the enchantment can have. public int getMaxLevel() { return 3; } @@ -37,6 +32,6 @@ public boolean isAcceptableItem(ItemStack stack) { boolean enchantAll = ConfigRegistry.COMMON.getConfig().enchantments.enchantAllWeapons; boolean isAxe = stack.getItem() instanceof AxeItem; boolean canApply = super.isAcceptableItem(stack); - return isAxe || canApply || enchantAll ? ConfigRegistry.COMMON.getConfig().enchantments.enableGroundedEdge : false; + return (isAxe || canApply || enchantAll) && ConfigRegistry.COMMON.getConfig().enchantments.enableGroundedEdge; } } diff --git a/src/main/java/com/dainxt/weaponthrow/enchantment/ReturnEnchantment.java b/src/main/java/com/dainxt/weaponthrow/enchantment/ReturnEnchantment.java index f669a68..4a87705 100644 --- a/src/main/java/com/dainxt/weaponthrow/enchantment/ReturnEnchantment.java +++ b/src/main/java/com/dainxt/weaponthrow/enchantment/ReturnEnchantment.java @@ -9,26 +9,17 @@ import net.minecraft.item.ItemStack; public class ReturnEnchantment extends Enchantment { - - public ReturnEnchantment(Rarity rarityIn, EquipmentSlot... mainhand) { super(rarityIn, EnchantmentTarget.WEAPON, mainhand); } - - /** - * Returns the minimal value of enchantability needed on the enchantment level passed. - */ + // Returns the minimal value of enchantability needed on the enchantment level passed. public int getMinPower(int enchantmentLevel) { return 5 + enchantmentLevel * 7; } - public int getMaxPower(int enchantmentLevel) { return 50; } - - /** - * Returns the maximum level that the enchantment can have. - */ + // Returns the maximum level that the enchantment can have. public int getMaxLevel() { return 1; } @@ -38,7 +29,7 @@ public boolean isAcceptableItem(ItemStack stack) { boolean enchantAll = ConfigRegistry.COMMON.getConfig().enchantments.enchantAllWeapons; boolean isAxe = stack.getItem() instanceof AxeItem; boolean canApply = super.isAcceptableItem(stack); - return isAxe || canApply || enchantAll ? ConfigRegistry.COMMON.getConfig().enchantments.enableReturn : false; + return (isAxe || canApply || enchantAll) && ConfigRegistry.COMMON.getConfig().enchantments.enableReturn; } } diff --git a/src/main/java/com/dainxt/weaponthrow/enchantment/ThrowEnchantment.java b/src/main/java/com/dainxt/weaponthrow/enchantment/ThrowEnchantment.java index 2650873..52de6e8 100644 --- a/src/main/java/com/dainxt/weaponthrow/enchantment/ThrowEnchantment.java +++ b/src/main/java/com/dainxt/weaponthrow/enchantment/ThrowEnchantment.java @@ -13,21 +13,14 @@ public class ThrowEnchantment extends Enchantment { public ThrowEnchantment(Enchantment.Rarity rarityIn, EquipmentSlot... slots) { super(rarityIn, EnchantmentTarget.WEAPON, slots); } - - /** - * Returns the minimal value of enchantability needed on the enchantment level passed. - */ + // Returns the minimal value of enchantability needed on the enchantment level passed. public int getMinPower(int enchantmentLevel) { return 10; } - public int getMaxPower(int enchantmentLevel) { return this.getMinPower(enchantmentLevel) + 40; } - - /** - * Returns the maximum level that the enchantment can have. - */ + // Returns the maximum level that the enchantment can have. public int getMaxLevel() { return 3; } @@ -37,6 +30,6 @@ public boolean isAcceptableItem(ItemStack stack) { boolean enchantAll = ConfigRegistry.COMMON.getConfig().enchantments.enchantAllWeapons; boolean isAxe = stack.getItem() instanceof AxeItem; boolean canApply = super.isAcceptableItem(stack); - return isAxe || canApply || enchantAll ? ConfigRegistry.COMMON.getConfig().enchantments.enableThrow : false; + return (isAxe || canApply || enchantAll) && ConfigRegistry.COMMON.getConfig().enchantments.enableThrow; } } diff --git a/src/main/java/com/dainxt/weaponthrow/entity/render/WeaponThrowRenderer.java b/src/main/java/com/dainxt/weaponthrow/entity/render/WeaponThrowRenderer.java index 97a4389..ff784b9 100644 --- a/src/main/java/com/dainxt/weaponthrow/entity/render/WeaponThrowRenderer.java +++ b/src/main/java/com/dainxt/weaponthrow/entity/render/WeaponThrowRenderer.java @@ -45,9 +45,6 @@ public void render(WeaponThrowEntity entityIn, float entityYaw, float partialTic this.itemRenderer.renderItem(entityIn.getStack(), ModelTransformation.Mode.FIXED, packedLightIn, OverlayTexture.DEFAULT_UV, matrixStackIn, bufferIn, entityIn.getId()); } - matrixStackIn.pop(); - } - } \ No newline at end of file diff --git a/src/main/java/com/dainxt/weaponthrow/events/OnApplySlow.java b/src/main/java/com/dainxt/weaponthrow/events/OnApplySlow.java index f52f9c8..04a3f26 100644 --- a/src/main/java/com/dainxt/weaponthrow/events/OnApplySlow.java +++ b/src/main/java/com/dainxt/weaponthrow/events/OnApplySlow.java @@ -1,19 +1,17 @@ -package com.dainxt.weaponthrow.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.player.PlayerEntity; - -public interface OnApplySlow { - - Event EVENT = EventFactory.createArrayBacked(OnApplySlow.class, - (listeners) -> (player) -> { - boolean result = false; - for (OnApplySlow listener : listeners) { - result = listener.interact(player) || result; - } - return result; - }); - - boolean interact(PlayerEntity player); -} +package com.dainxt.weaponthrow.events; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.minecraft.entity.player.PlayerEntity; + +public interface OnApplySlow { + Event EVENT = EventFactory.createArrayBacked(OnApplySlow.class, + (listeners) -> (player) -> { + boolean result = false; + for (OnApplySlow listener : listeners) { + result = listener.interact(player) || result; + } + return result; + }); + boolean interact(PlayerEntity player); +} diff --git a/src/main/java/com/dainxt/weaponthrow/events/OnFOVUpdate.java b/src/main/java/com/dainxt/weaponthrow/events/OnFOVUpdate.java index f082c25..e31ae78 100644 --- a/src/main/java/com/dainxt/weaponthrow/events/OnFOVUpdate.java +++ b/src/main/java/com/dainxt/weaponthrow/events/OnFOVUpdate.java @@ -1,23 +1,20 @@ -package com.dainxt.weaponthrow.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.player.PlayerEntity; - -public interface OnFOVUpdate { - - Event EVENT = EventFactory.createArrayBacked(OnFOVUpdate.class, - (listeners) -> (player, amount) -> { - for (OnFOVUpdate listener : listeners) { - float result = listener.interact(player, amount); - - if(result != 0) { - return result; - } - - } - return 0; - }); - - float interact(PlayerEntity entity, float fov); -} +package com.dainxt.weaponthrow.events; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.minecraft.entity.player.PlayerEntity; + +public interface OnFOVUpdate { + Event EVENT = EventFactory.createArrayBacked(OnFOVUpdate.class, + (listeners) -> (player, amount) -> { + for (OnFOVUpdate listener : listeners) { + float result = listener.interact(player, amount); + if(result != 0) { + return result; + } + + } + return 0; + }); + float interact(PlayerEntity entity, float fov); +} diff --git a/src/main/java/com/dainxt/weaponthrow/events/OnHeldItemRender.java b/src/main/java/com/dainxt/weaponthrow/events/OnHeldItemRender.java index 0decfaa..69b5b68 100644 --- a/src/main/java/com/dainxt/weaponthrow/events/OnHeldItemRender.java +++ b/src/main/java/com/dainxt/weaponthrow/events/OnHeldItemRender.java @@ -1,25 +1,20 @@ -package com.dainxt.weaponthrow.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.PlayerEntityRenderer; -import net.minecraft.client.render.item.HeldItemRenderer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; - -public interface OnHeldItemRender { - - Event EVENT = EventFactory.createArrayBacked(OnHeldItemRender.class, - (listeners) -> (renderer, player, tickDelta, pitch, hand, swingProgress, item, equipProgress, matrices, vertexConsumers, light) -> { - for (OnHeldItemRender listener : listeners) { - listener.interact(renderer, player, tickDelta, pitch, hand, swingProgress, item, equipProgress, matrices, vertexConsumers, light); - } - - }); - - void interact(HeldItemRenderer renderer , AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light); -} +package com.dainxt.weaponthrow.events; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.item.HeldItemRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; + +public interface OnHeldItemRender { + Event EVENT = EventFactory.createArrayBacked(OnHeldItemRender.class, + (listeners) -> (renderer, player, tickDelta, pitch, hand, swingProgress, item, equipProgress, matrices, vertexConsumers, light) -> { + for (OnHeldItemRender listener : listeners) { + listener.interact(renderer, player, tickDelta, pitch, hand, swingProgress, item, equipProgress, matrices, vertexConsumers, light); + } + }); + void interact(HeldItemRenderer renderer , AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light); +} diff --git a/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerRender.java b/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerRender.java index 428818a..1fc8d57 100644 --- a/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerRender.java +++ b/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerRender.java @@ -1,19 +1,17 @@ -package com.dainxt.weaponthrow.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.client.render.entity.PlayerEntityRenderer; -import net.minecraft.entity.player.PlayerEntity; - -public interface OnStartPlayerRender { - - Event EVENT = EventFactory.createArrayBacked(OnStartPlayerRender.class, - (listeners) -> (renderer, player) -> { - for (OnStartPlayerRender listener : listeners) { - listener.interact(renderer, player); - } - - }); - - void interact(PlayerEntityRenderer renderer, PlayerEntity entity); -} +package com.dainxt.weaponthrow.events; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.minecraft.client.render.entity.PlayerEntityRenderer; +import net.minecraft.entity.player.PlayerEntity; + +public interface OnStartPlayerRender { + Event EVENT = EventFactory.createArrayBacked(OnStartPlayerRender.class, + (listeners) -> (renderer, player) -> { + for (OnStartPlayerRender listener : listeners) { + listener.interact(renderer, player); + } + + }); + void interact(PlayerEntityRenderer renderer, PlayerEntity entity); +} diff --git a/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerTick.java b/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerTick.java index 8a5000b..a76d305 100644 --- a/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerTick.java +++ b/src/main/java/com/dainxt/weaponthrow/events/OnStartPlayerTick.java @@ -1,18 +1,17 @@ -package com.dainxt.weaponthrow.events; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.entity.player.PlayerEntity; - -public interface OnStartPlayerTick { - - Event EVENT = EventFactory.createArrayBacked(OnStartPlayerTick.class, - (listeners) -> (player) -> { - for (OnStartPlayerTick listener : listeners) { - listener.interact(player); - } - - }); - - void interact(PlayerEntity entity); -} +package com.dainxt.weaponthrow.events; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.minecraft.entity.player.PlayerEntity; + +public interface OnStartPlayerTick { + + Event EVENT = EventFactory.createArrayBacked(OnStartPlayerTick.class, + (listeners) -> (player) -> { + for (OnStartPlayerTick listener : listeners) { + listener.interact(player); + } + + }); + void interact(PlayerEntity entity); +} diff --git a/src/main/java/com/dainxt/weaponthrow/handlers/ConfigRegistry.java b/src/main/java/com/dainxt/weaponthrow/handlers/ConfigRegistry.java index abf795c..77f7b7d 100644 --- a/src/main/java/com/dainxt/weaponthrow/handlers/ConfigRegistry.java +++ b/src/main/java/com/dainxt/weaponthrow/handlers/ConfigRegistry.java @@ -1,18 +1,16 @@ -package com.dainxt.weaponthrow.handlers; - -import com.dainxt.weaponthrow.config.WeaponThrowConfig; - -import me.shedaniel.autoconfig.AutoConfig; -import me.shedaniel.autoconfig.ConfigHolder; -import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; - -public class ConfigRegistry { - - public static ConfigHolder COMMON; - - public static void registerConfig() { - - COMMON = AutoConfig.register(WeaponThrowConfig.class, GsonConfigSerializer::new); - } - -} +package com.dainxt.weaponthrow.handlers; + +import com.dainxt.weaponthrow.config.WeaponThrowConfig; + +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.ConfigHolder; +import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; + +public class ConfigRegistry { + + public static ConfigHolder COMMON; + + public static void registerConfig() { + COMMON = AutoConfig.register(WeaponThrowConfig.class, GsonConfigSerializer::new); + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/handlers/EnchantmentHandler.java b/src/main/java/com/dainxt/weaponthrow/handlers/EnchantmentHandler.java index 99565cb..42d1346 100644 --- a/src/main/java/com/dainxt/weaponthrow/handlers/EnchantmentHandler.java +++ b/src/main/java/com/dainxt/weaponthrow/handlers/EnchantmentHandler.java @@ -20,8 +20,5 @@ public class EnchantmentHandler { public static final Enchantment GRAVITY = Registry.register(Registry.ENCHANTMENT, new Identifier(WeaponThrow.MODID, "gravity"), new GravityEnchantment(Enchantment.Rarity.VERY_RARE, EquipmentSlot.MAINHAND)); public static final Enchantment RETURN = Registry.register(Registry.ENCHANTMENT, new Identifier(WeaponThrow.MODID, "return"), new ReturnEnchantment(Enchantment.Rarity.RARE, EquipmentSlot.MAINHAND)); - public static void registerEnchantments() { - - } - + public static void registerEnchantments() {} } diff --git a/src/main/java/com/dainxt/weaponthrow/handlers/EntityRegistry.java b/src/main/java/com/dainxt/weaponthrow/handlers/EntityRegistry.java index 3c4bfbd..db6a376 100644 --- a/src/main/java/com/dainxt/weaponthrow/handlers/EntityRegistry.java +++ b/src/main/java/com/dainxt/weaponthrow/handlers/EntityRegistry.java @@ -1,25 +1,22 @@ -package com.dainxt.weaponthrow.handlers; - -import com.dainxt.weaponthrow.WeaponThrow; -import com.dainxt.weaponthrow.projectile.WeaponThrowEntity; - -import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnGroup; -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; - -public class EntityRegistry { - - public static final EntityType WEAPONTHROW = Registry.register( - Registry.ENTITY_TYPE, - new Identifier(WeaponThrow.MODID, "weaponthrow"), - FabricEntityTypeBuilder.create(SpawnGroup.MISC, WeaponThrowEntity::new).trackRangeBlocks(4).trackedUpdateRate(20).dimensions(EntityDimensions.fixed(0.5F, 0.5F)).build() - ); - - public static void registerEntities() { - - } -} +package com.dainxt.weaponthrow.handlers; + +import com.dainxt.weaponthrow.WeaponThrow; +import com.dainxt.weaponthrow.projectile.WeaponThrowEntity; + +import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +public class EntityRegistry { + public static final EntityType WEAPONTHROW = Registry.register( + Registry.ENTITY_TYPE, + new Identifier(WeaponThrow.MODID, "weaponthrow"), + FabricEntityTypeBuilder.create(SpawnGroup.MISC, WeaponThrowEntity::new).trackRangeBlocks(4).trackedUpdateRate(20).dimensions(EntityDimensions.fixed(0.5F, 0.5F)).build() + ); + public static void registerEntities() { + + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/handlers/EventsHandler.java b/src/main/java/com/dainxt/weaponthrow/handlers/EventsHandler.java index 29246d9..e031760 100644 --- a/src/main/java/com/dainxt/weaponthrow/handlers/EventsHandler.java +++ b/src/main/java/com/dainxt/weaponthrow/handlers/EventsHandler.java @@ -41,29 +41,25 @@ public class EventsHandler{ public static boolean wasPressed = false; - - //public static int clientSideCharge = 0; - + public static void onThrowItem(ServerPlayerEntity serverplayer, CPacketThrow.State action){ - - - - PlayerEntity player = (PlayerEntity) serverplayer; + + ServerWorld world = serverplayer.getWorld(); - ItemStack stack = player.getMainHandStack(); + ItemStack stack = serverplayer.getMainHandStack(); boolean isThrowable = ConfigRegistry.COMMON.get().experimental.shouldThrowItemsToo; Multimap multimap = stack.getAttributeModifiers(EquipmentSlot.MAINHAND); boolean haveAttributes = multimap.containsKey(EntityAttributes.GENERIC_ATTACK_DAMAGE) || multimap.containsKey(EntityAttributes.GENERIC_ATTACK_SPEED); - PlayerThrowData data = ((IPlayerEntityMixin)player).getThrowPower(); + PlayerThrowData data = ((IPlayerEntityMixin) serverplayer).getThrowPower(); if ((isThrowable || haveAttributes) && !stack.isEmpty()) { boolean cdConfig = ConfigRegistry.COMMON.get().general.notUseWhenCooldown; - if(!(player.getItemCooldownManager().getCooldownProgress(stack.getItem(), 1.0F) > 0 && cdConfig)) { + if(!(serverplayer.getItemCooldownManager().getCooldownProgress(stack.getItem(), 1.0F) > 0 && cdConfig)) { data.setAction(action); @@ -75,13 +71,10 @@ public static void onThrowItem(ServerPlayerEntity serverplayer, CPacketThrow.Sta float baseThrow = 0; float baseExhaustion = 0.05F; - - //float modThrow = 1.F - (data.getChargeTime()/(float)PlayerThrowData.getMaximumCharge(player)); - float modThrow = 1.0F; - if(Math.signum(PlayerThrowData.getMaximumCharge(player)) != 0.0F) { - modThrow = 1.F - (data.getChargeTime()/(float)PlayerThrowData.getMaximumCharge(player)); + if(Math.signum(PlayerThrowData.getMaximumCharge(serverplayer)) != 0.0F) { + modThrow = 1.F - (data.getChargeTime()/(float)PlayerThrowData.getMaximumCharge(serverplayer)); } data.resetCharging(); @@ -93,21 +86,18 @@ public static void onThrowItem(ServerPlayerEntity serverplayer, CPacketThrow.Sta } if(haveAttributes) { - baseThrow = 20/player.getAttackCooldownProgressPerTick(); - baseExhaustion = player.getAttackCooldownProgressPerTick()/20; + baseThrow = 20/ serverplayer.getAttackCooldownProgressPerTick(); + baseExhaustion = serverplayer.getAttackCooldownProgressPerTick()/20; } if(baseThrow>0) { boolean shouldDestroy = modThrow > 0.99; double baseDamage = ConfigRegistry.COMMON.get().defaults.baseDamageDefault; - double toolMultiplier = 0.0D; - - if(haveAttributes) { - baseDamage = (float) player.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE); + baseDamage = (float) serverplayer.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE); int types = 0; if(stack.getItem() instanceof AxeItem) { @@ -139,7 +129,7 @@ public static void onThrowItem(ServerPlayerEntity serverplayer, CPacketThrow.Sta toolMultiplier = 1.0F; } - int size = player.isSneaking() ? stack.getCount() : 1; + int size = serverplayer.isSneaking() ? stack.getCount() : 1; double bDamageMul = ConfigRegistry.COMMON.get().multipliers.damages.baseDamageMultiplier; double sDamageMul = ConfigRegistry.COMMON.get().multipliers.damages.stackDamageMultiplier; @@ -159,39 +149,27 @@ public static void onThrowItem(ServerPlayerEntity serverplayer, CPacketThrow.Sta double totalExhaustion = (baseExhaustion)*(1*bExhaustionMul + modThrow*mExhaustionMul) + (size*sExhaustionMul); totalExhaustion*=toolMultiplier; - WeaponThrowEntity throwedEntity = new WeaponThrowEntity(world, player, shouldDestroy, (float) totalDamage, stack.split(size)); - throwedEntity.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, (float) totalVelocity, 1.0F); - player.addExhaustion((float) totalExhaustion); - + WeaponThrowEntity throwedEntity = new WeaponThrowEntity(world, serverplayer, shouldDestroy, (float) totalDamage, stack.split(size)); + throwedEntity.setVelocity(serverplayer, serverplayer.getPitch(), serverplayer.getYaw(), 0.0F, (float) totalVelocity, 1.0F); + serverplayer.addExhaustion((float) totalExhaustion); world.spawnEntity(throwedEntity); SoundEvent soundevent = SoundEvents.ENTITY_EGG_THROW; throwedEntity.playSound(soundevent, 1.0F, 0.5F); - } } - - ((IPlayerEntityMixin)player).setThrowPower(data); - + ((IPlayerEntityMixin) serverplayer).setThrowPower(data); } - } - - /*if(stack.isEmpty() || !data.getChargingStack().equals(stack)) { - data.resetCharging(); - }*/ - } - - public static void registerEvents(){ OnStartPlayerTick.EVENT.register((player)->{ if(!player.world.isClient()) { PlayerThrowData cap = ((IPlayerEntityMixin)player).getThrowPower(); - boolean attacked = player.getAttackCooldownProgress(0.0F) < 1.0F ? true : false; + boolean attacked = player.getAttackCooldownProgress(0.0F) < 1.0F; boolean cdConfig = ConfigRegistry.COMMON.get().general.notUseWhenCooldown; boolean changedItem = !ItemStack.areEqual(cap.getChargingStack(), player.getMainHandStack()); @@ -204,7 +182,6 @@ public static void registerEvents(){ cap.setChargeTime(cap.getChargeTime() - 1); } - if(cap.getAction().equals(CPacketThrow.State.START) || cap.getAction().equals(CPacketThrow.State.FINISH)) { PacketHandler.sendToAll(player, new SPacketThrow(player.getUuid(), PlayerThrowData.getMaximumCharge(player), cap.getAction().equals(CPacketThrow.State.START))); @@ -219,14 +196,13 @@ public static void registerEvents(){ if(cap.getChargeTime() > 0) { cap.setChargeTime(cap.getChargeTime()-1); } - - //clientSideCharge = cap.getAction().equals(State.DURING)? clientSideCharge+1 : 0; } }); } public static void onSeverUpdate(UUID playerUUID, int maxChargeTime, boolean isCharging) { + assert MinecraftClient.getInstance().world != null; PlayerEntity playerentity = MinecraftClient.getInstance().world.getPlayerByUuid(playerUUID); if(playerentity != null) { @@ -249,24 +225,18 @@ public static void registerClientEvents() { if(cap.getAction().equals(State.DURING)) { - //float progress = MathHelper.clamp((float)(EventsHandler.clientSideCharge+tickDelta)/cap.MAX_CHARGE, 0.F, 1.0F); - float preProgress = 1.0F; - - /*if(Math.signum(cap.MAX_CHARGE) != 0.0F) { - preProgress = (float)(EventsHandler.clientSideCharge+tickDelta)/cap.MAX_CHARGE; - }*/ - + if(Math.signum(cap.MAX_CHARGE) != 0.0F && cap.getChargeTime() > 0) { float lerp = MathHelper.lerp(tickDelta, cap.getChargeTime()+1, cap.getChargeTime()); - preProgress = 1.F-(float)(lerp)/cap.MAX_CHARGE; + preProgress = 1.F- lerp /cap.MAX_CHARGE; } float progress = MathHelper.clamp(preProgress, 0.F, 1.0F); - - matrices.translate(0.0D, 0.0F, (double)((float)progress * 0.50F)); - matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion((float)progress * 10.0F)); - matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion((float)progress * 40.0F)); + + matrices.translate(0.0D, 0.0F, progress * 0.50F); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(progress * 10.0F)); + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(progress * 40.0F)); } }); @@ -276,7 +246,7 @@ public static void registerClientEvents() { PlayerThrowData cap = ((IPlayerEntityMixin)player).getThrowPower(); if(cap.getAction().equals(State.DURING)) { if(player instanceof AbstractClientPlayerEntity) { - Arm hand = ((AbstractClientPlayerEntity)player).getMainArm(); + Arm hand = player.getMainArm(); if(hand == Arm.RIGHT) renderer.getModel().rightArmPose = BipedEntityModel.ArmPose.THROW_SPEAR; else @@ -302,23 +272,13 @@ public static void registerClientEvents() { float f = amount; if(isCharging) { - - - //int i = (int) (EventsHandler.clientSideCharge); - - //float f1 = (float)i / maxChargeTime; - + float f1 = 1.0F; - /*if(Math.signum(maxChargeTime) != 0.0F) { - f1 =(float)i / maxChargeTime; - }*/ - if(Math.signum(maxChargeTime) != 0.0F && chargeTime > 0) { float lerp = MathHelper.lerp(MinecraftClient.getInstance().getTickDelta(), chargeTime+1, chargeTime); - f1 = MathHelper.clamp(1.0F-(float)lerp / maxChargeTime, 0.F, 1.0F); + f1 = MathHelper.clamp(1.0F- lerp / maxChargeTime, 0.F, 1.0F); } - if (f1 > 1.0F) { f1 = 1.0F; } else { @@ -326,9 +286,7 @@ public static void registerClientEvents() { } f *= 1.0F + f1 * 0.15F; - } - return f; }); @@ -343,12 +301,8 @@ public static void registerClientEvents() { PacketHandler.sendToServer(new CPacketThrow(CPacketThrow.State.FINISH)); EventsHandler.wasPressed = false; } - }); - } - - } diff --git a/src/main/java/com/dainxt/weaponthrow/handlers/KeyBindingHandler.java b/src/main/java/com/dainxt/weaponthrow/handlers/KeyBindingHandler.java index 59736a0..4befeea 100644 --- a/src/main/java/com/dainxt/weaponthrow/handlers/KeyBindingHandler.java +++ b/src/main/java/com/dainxt/weaponthrow/handlers/KeyBindingHandler.java @@ -1,17 +1,10 @@ package com.dainxt.weaponthrow.handlers; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import org.lwjgl.glfw.GLFW; -import com.google.common.collect.Lists; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; diff --git a/src/main/java/com/dainxt/weaponthrow/handlers/PacketHandler.java b/src/main/java/com/dainxt/weaponthrow/handlers/PacketHandler.java index c4e80e1..9c3f2c4 100644 --- a/src/main/java/com/dainxt/weaponthrow/handlers/PacketHandler.java +++ b/src/main/java/com/dainxt/weaponthrow/handlers/PacketHandler.java @@ -40,5 +40,4 @@ public static void sendToAll(Entity entity, BasePacket packet) { ServerPlayNetworking.send(player, packet.getIdentifier(), packet.getBuf()); } } - } diff --git a/src/main/java/com/dainxt/weaponthrow/handlers/RenderRegistry.java b/src/main/java/com/dainxt/weaponthrow/handlers/RenderRegistry.java index f1db129..754087c 100644 --- a/src/main/java/com/dainxt/weaponthrow/handlers/RenderRegistry.java +++ b/src/main/java/com/dainxt/weaponthrow/handlers/RenderRegistry.java @@ -1,13 +1,13 @@ -package com.dainxt.weaponthrow.handlers; - -import com.dainxt.weaponthrow.entity.render.WeaponThrowRenderer; - -import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; - -public class RenderRegistry { - - public static void registerRenderers() { - EntityRendererRegistry.register(EntityRegistry.WEAPONTHROW, WeaponThrowRenderer::new); - - } -} +package com.dainxt.weaponthrow.handlers; + +import com.dainxt.weaponthrow.entity.render.WeaponThrowRenderer; + +import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; + +public class RenderRegistry { + + public static void registerRenderers() { + EntityRendererRegistry.register(EntityRegistry.WEAPONTHROW, WeaponThrowRenderer::new); + + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/interfaces/IPlayerEntityMixin.java b/src/main/java/com/dainxt/weaponthrow/interfaces/IPlayerEntityMixin.java index 5e0e23d..8d4c207 100644 --- a/src/main/java/com/dainxt/weaponthrow/interfaces/IPlayerEntityMixin.java +++ b/src/main/java/com/dainxt/weaponthrow/interfaces/IPlayerEntityMixin.java @@ -1,9 +1,8 @@ -package com.dainxt.weaponthrow.interfaces; - -import com.dainxt.weaponthrow.capabilities.PlayerThrowData; - -public interface IPlayerEntityMixin { - public void setThrowPower(PlayerThrowData value); - - public PlayerThrowData getThrowPower(); -} +package com.dainxt.weaponthrow.interfaces; + +import com.dainxt.weaponthrow.capabilities.PlayerThrowData; + +public interface IPlayerEntityMixin { + void setThrowPower(PlayerThrowData value); + PlayerThrowData getThrowPower(); +} diff --git a/src/main/java/com/dainxt/weaponthrow/mixin/PlayerEntityRendererMixin.java b/src/main/java/com/dainxt/weaponthrow/mixin/PlayerEntityRendererMixin.java deleted file mode 100644 index 2f5ee0c..0000000 --- a/src/main/java/com/dainxt/weaponthrow/mixin/PlayerEntityRendererMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.dainxt.weaponthrow.mixin; - -import java.util.Arrays; -import java.util.List; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.gen.Accessor; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -import com.dainxt.weaponthrow.capabilities.PlayerThrowData; -import com.dainxt.weaponthrow.events.OnFOVUpdate; -import com.dainxt.weaponthrow.events.OnStartPlayerRender; -import com.dainxt.weaponthrow.events.OnStartPlayerTick; -import com.dainxt.weaponthrow.handlers.KeyBindingHandler; -import com.dainxt.weaponthrow.interfaces.IPlayerEntityMixin; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.option.GameOptions; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.render.entity.PlayerEntityRenderer; -import net.minecraft.entity.player.PlayerEntity; - -@Mixin(PlayerEntityRenderer.class) -public class PlayerEntityRendererMixin{ - - @Inject(method = "setModelPose", at = @At("TAIL")) - private void setModelPose(AbstractClientPlayerEntity player, CallbackInfo info) { - OnStartPlayerRender.EVENT.invoker().interact(((PlayerEntityRenderer)(Object)this), player); - } -} diff --git a/src/main/java/com/dainxt/weaponthrow/mixin/IPlayerEntityMixin.java b/src/main/java/com/dainxt/weaponthrow/mixins/IPlayerEntityMixin.java similarity index 80% rename from src/main/java/com/dainxt/weaponthrow/mixin/IPlayerEntityMixin.java rename to src/main/java/com/dainxt/weaponthrow/mixins/IPlayerEntityMixin.java index d9f123d..63be274 100644 --- a/src/main/java/com/dainxt/weaponthrow/mixin/IPlayerEntityMixin.java +++ b/src/main/java/com/dainxt/weaponthrow/mixins/IPlayerEntityMixin.java @@ -1,9 +1,9 @@ -package com.dainxt.weaponthrow.mixin; - -import com.dainxt.weaponthrow.capabilities.PlayerThrowData; - -public interface IPlayerEntityMixin { - public void setThrowPower(PlayerThrowData value); - - public PlayerThrowData getThrowPower(); -} +package com.dainxt.weaponthrow.mixins; + +import com.dainxt.weaponthrow.capabilities.PlayerThrowData; + +public interface IPlayerEntityMixin { + public void setThrowPower(PlayerThrowData value); + + public PlayerThrowData getThrowPower(); +} diff --git a/src/main/java/com/dainxt/weaponthrow/mixin/PlayerEntityMixin.java b/src/main/java/com/dainxt/weaponthrow/mixins/PlayerEntityMixin.java similarity index 69% rename from src/main/java/com/dainxt/weaponthrow/mixin/PlayerEntityMixin.java rename to src/main/java/com/dainxt/weaponthrow/mixins/PlayerEntityMixin.java index ddd68e2..de5b72d 100644 --- a/src/main/java/com/dainxt/weaponthrow/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/dainxt/weaponthrow/mixins/PlayerEntityMixin.java @@ -1,28 +1,17 @@ -package com.dainxt.weaponthrow.mixin; - -import java.util.Arrays; -import java.util.List; +package com.dainxt.weaponthrow.mixins; +import com.dainxt.weaponthrow.capabilities.PlayerThrowData; +import com.dainxt.weaponthrow.events.OnStartPlayerTick; +import com.dainxt.weaponthrow.interfaces.IPlayerEntityMixin; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.dainxt.weaponthrow.capabilities.PlayerThrowData; -import com.dainxt.weaponthrow.events.OnFOVUpdate; -import com.dainxt.weaponthrow.events.OnStartPlayerTick; -import com.dainxt.weaponthrow.handlers.KeyBindingHandler; -import com.dainxt.weaponthrow.interfaces.IPlayerEntityMixin; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.GameOptions; -import net.minecraft.client.option.KeyBinding; import net.minecraft.entity.player.PlayerEntity; @Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin implements IPlayerEntityMixin{ +public abstract class PlayerEntityMixin implements IPlayerEntityMixin { public PlayerThrowData throwPower = new PlayerThrowData((PlayerEntity)(Object) this); diff --git a/src/main/java/com/dainxt/weaponthrow/mixin/AbstractClientPlayerEntityMixin.java b/src/main/java/com/dainxt/weaponthrow/mixins/client/AbstractClientPlayerEntityMixin.java similarity index 89% rename from src/main/java/com/dainxt/weaponthrow/mixin/AbstractClientPlayerEntityMixin.java rename to src/main/java/com/dainxt/weaponthrow/mixins/client/AbstractClientPlayerEntityMixin.java index a31c52b..c54b256 100644 --- a/src/main/java/com/dainxt/weaponthrow/mixin/AbstractClientPlayerEntityMixin.java +++ b/src/main/java/com/dainxt/weaponthrow/mixins/client/AbstractClientPlayerEntityMixin.java @@ -1,12 +1,11 @@ -package com.dainxt.weaponthrow.mixin; +package com.dainxt.weaponthrow.mixins.client; +import com.dainxt.weaponthrow.events.OnFOVUpdate; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.dainxt.weaponthrow.events.OnFOVUpdate; - import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.entity.player.PlayerEntity; @@ -17,7 +16,7 @@ public abstract class AbstractClientPlayerEntityMixin{ private void getSpeed(CallbackInfoReturnable info) { PlayerEntity player = (PlayerEntity) (Object) this; - float amount = info.getReturnValue().floatValue(); + float amount = info.getReturnValue(); float result = OnFOVUpdate.EVENT.invoker().interact(player, amount); diff --git a/src/main/java/com/dainxt/weaponthrow/mixin/ClientPlayerEntityMixin.java b/src/main/java/com/dainxt/weaponthrow/mixins/client/ClientPlayerEntityMixin.java similarity index 63% rename from src/main/java/com/dainxt/weaponthrow/mixin/ClientPlayerEntityMixin.java rename to src/main/java/com/dainxt/weaponthrow/mixins/client/ClientPlayerEntityMixin.java index e51d813..a90826d 100644 --- a/src/main/java/com/dainxt/weaponthrow/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/com/dainxt/weaponthrow/mixins/client/ClientPlayerEntityMixin.java @@ -1,22 +1,12 @@ -package com.dainxt.weaponthrow.mixin; - -import java.util.Arrays; -import java.util.List; +package com.dainxt.weaponthrow.mixins.client; +import com.dainxt.weaponthrow.events.OnApplySlow; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.dainxt.weaponthrow.events.OnApplySlow; -import com.dainxt.weaponthrow.handlers.KeyBindingHandler; - -import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.option.GameOptions; -import net.minecraft.client.option.KeyBinding; import net.minecraft.entity.player.PlayerEntity; @Mixin(ClientPlayerEntity.class) diff --git a/src/main/java/com/dainxt/weaponthrow/mixin/HeldItemRendererMixin.java b/src/main/java/com/dainxt/weaponthrow/mixins/client/HeldItemRendererMixin.java similarity index 56% rename from src/main/java/com/dainxt/weaponthrow/mixin/HeldItemRendererMixin.java rename to src/main/java/com/dainxt/weaponthrow/mixins/client/HeldItemRendererMixin.java index 6abe7d1..6944132 100644 --- a/src/main/java/com/dainxt/weaponthrow/mixin/HeldItemRendererMixin.java +++ b/src/main/java/com/dainxt/weaponthrow/mixins/client/HeldItemRendererMixin.java @@ -1,35 +1,15 @@ -package com.dainxt.weaponthrow.mixin; - -import java.util.Arrays; -import java.util.List; +package com.dainxt.weaponthrow.mixins.client; +import com.dainxt.weaponthrow.events.OnHeldItemRender; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -import com.dainxt.weaponthrow.capabilities.PlayerThrowData; -import com.dainxt.weaponthrow.events.OnFOVUpdate; -import com.dainxt.weaponthrow.events.OnHeldItemRender; -import com.dainxt.weaponthrow.events.OnStartPlayerRender; -import com.dainxt.weaponthrow.events.OnStartPlayerTick; -import com.dainxt.weaponthrow.handlers.KeyBindingHandler; -import com.dainxt.weaponthrow.interfaces.IPlayerEntityMixin; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.option.GameOptions; -import net.minecraft.client.option.KeyBinding; import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.PlayerEntityRenderer; import net.minecraft.client.render.item.HeldItemRenderer; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; diff --git a/src/main/java/com/dainxt/weaponthrow/mixins/client/PlayerEntityRendererMixin.java b/src/main/java/com/dainxt/weaponthrow/mixins/client/PlayerEntityRendererMixin.java new file mode 100644 index 0000000..2ccd587 --- /dev/null +++ b/src/main/java/com/dainxt/weaponthrow/mixins/client/PlayerEntityRendererMixin.java @@ -0,0 +1,19 @@ +package com.dainxt.weaponthrow.mixins.client; + +import com.dainxt.weaponthrow.events.OnStartPlayerRender; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.render.entity.PlayerEntityRenderer; + +@Mixin(PlayerEntityRenderer.class) +public class PlayerEntityRendererMixin{ + + @Inject(method = "setModelPose", at = @At("TAIL")) + private void setModelPose(AbstractClientPlayerEntity player, CallbackInfo info) { + OnStartPlayerRender.EVENT.invoker().interact(((PlayerEntityRenderer)(Object)this), player); + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/packets/BasePacket.java b/src/main/java/com/dainxt/weaponthrow/packets/BasePacket.java index 3a3b7da..e8aa170 100644 --- a/src/main/java/com/dainxt/weaponthrow/packets/BasePacket.java +++ b/src/main/java/com/dainxt/weaponthrow/packets/BasePacket.java @@ -1,25 +1,25 @@ -package com.dainxt.weaponthrow.packets; - -import io.netty.buffer.Unpooled; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; - -public abstract class BasePacket { - - private Identifier identifier; - - protected PacketByteBuf buf; - - public BasePacket(Identifier id) { - this.identifier = id; - this.buf = new PacketByteBuf(Unpooled.buffer()); - } - - public PacketByteBuf getBuf() { - return this.buf; - } - - public Identifier getIdentifier() { - return this.identifier; - } -} +package com.dainxt.weaponthrow.packets; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.util.Identifier; + +public abstract class BasePacket { + + private Identifier identifier; + + protected PacketByteBuf buf; + + public BasePacket(Identifier id) { + this.identifier = id; + this.buf = new PacketByteBuf(Unpooled.buffer()); + } + + public PacketByteBuf getBuf() { + return this.buf; + } + + public Identifier getIdentifier() { + return this.identifier; + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/packets/EntitySpawnPacket.java b/src/main/java/com/dainxt/weaponthrow/packets/EntitySpawnPacket.java index 8bdb4e8..0e9ee9f 100644 --- a/src/main/java/com/dainxt/weaponthrow/packets/EntitySpawnPacket.java +++ b/src/main/java/com/dainxt/weaponthrow/packets/EntitySpawnPacket.java @@ -1,138 +1,136 @@ -package com.dainxt.weaponthrow.packets; - -import java.util.UUID; - -import com.dainxt.weaponthrow.WeaponThrow; -import com.dainxt.weaponthrow.handlers.PacketHandler; - -import io.netty.buffer.Unpooled; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.network.Packet; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.registry.Registry; - -public class EntitySpawnPacket { - - public static Packet create(Entity e) { - if (e.world.isClient) - throw new IllegalStateException("SpawnPacketUtil.create called on the logical client!"); - PacketByteBuf byteBuf = new PacketByteBuf(Unpooled.buffer()); - byteBuf.writeVarInt(Registry.ENTITY_TYPE.getRawId(e.getType())); - byteBuf.writeUuid(e.getUuid()); - byteBuf.writeVarInt(e.getId()); - - PacketBufUtil.writeVec3d(byteBuf, e.getPos()); - PacketBufUtil.writeAngle(byteBuf, e.getPitch()); - PacketBufUtil.writeAngle(byteBuf, e.getYaw()); - return ServerPlayNetworking.createS2CPacket(PacketHandler.SPAWN_PACKET, byteBuf); - } - - - public static final class PacketBufUtil { - - /** - * Packs a floating-point angle into a {@code byte}. - * - * @param angle - * angle - * @return packed angle - */ - public static byte packAngle(float angle) { - return (byte) MathHelper.floor(angle * 256 / 360); - } - - /** - * Unpacks a floating-point angle from a {@code byte}. - * - * @param angleByte - * packed angle - * @return angle - */ - public static float unpackAngle(byte angleByte) { - return (angleByte * 360) / 256f; - } - - /** - * Writes an angle to a {@link PacketByteBuf}. - * - * @param byteBuf - * destination buffer - * @param angle - * angle - */ - public static void writeAngle(PacketByteBuf byteBuf, float angle) { - byteBuf.writeByte(packAngle(angle)); - } - - /** - * Reads an angle from a {@link PacketByteBuf}. - * - * @param byteBuf - * source buffer - * @return angle - */ - public static float readAngle(PacketByteBuf byteBuf) { - return unpackAngle(byteBuf.readByte()); - } - - /** - * Writes a {@link Vec3d} to a {@link PacketByteBuf}. - * - * @param byteBuf - * destination buffer - * @param vec3d - * vector - */ - public static void writeVec3d(PacketByteBuf byteBuf, Vec3d vec3d) { - byteBuf.writeDouble(vec3d.x); - byteBuf.writeDouble(vec3d.y); - byteBuf.writeDouble(vec3d.z); - } - - /** - * Reads a {@link Vec3d} from a {@link PacketByteBuf}. - * - * @param byteBuf - * source buffer - * @return vector - */ - public static Vec3d readVec3d(PacketByteBuf byteBuf) { - double x = byteBuf.readDouble(); - double y = byteBuf.readDouble(); - double z = byteBuf.readDouble(); - return new Vec3d(x, y, z); - } - } - - public static void register() { - ClientPlayNetworking.registerGlobalReceiver(PacketHandler.SPAWN_PACKET, (client, handler, buf, responseSender) -> { - EntityType et = Registry.ENTITY_TYPE.get(buf.readVarInt()); - UUID uuid = buf.readUuid(); - int entityId = buf.readVarInt(); - Vec3d pos = EntitySpawnPacket.PacketBufUtil.readVec3d(buf); - float pitch = EntitySpawnPacket.PacketBufUtil.readAngle(buf); - float yaw = EntitySpawnPacket.PacketBufUtil.readAngle(buf); - client.execute(() -> { - if (MinecraftClient.getInstance().world == null) - throw new IllegalStateException("Tried to spawn entity in a null world!"); - Entity e = et.create(MinecraftClient.getInstance().world); - if (e == null) - throw new IllegalStateException("Failed to create instance of entity \"" + Registry.ENTITY_TYPE.getId(et) + "\"!"); - e.updateTrackedPosition(pos); - e.setPos(pos.x, pos.y, pos.z); - e.setPitch(pitch); - e.setYaw(yaw); - e.setId(entityId); - e.setUuid(uuid); - MinecraftClient.getInstance().world.addEntity(entityId, e); - }); - }); - } -} +package com.dainxt.weaponthrow.packets; + +import java.util.UUID; + +import com.dainxt.weaponthrow.handlers.PacketHandler; + +import io.netty.buffer.Unpooled; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.network.Packet; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.registry.Registry; + +public class EntitySpawnPacket { + + public static Packet create(Entity e) { + if (e.world.isClient) + throw new IllegalStateException("SpawnPacketUtil.create called on the logical client!"); + PacketByteBuf byteBuf = new PacketByteBuf(Unpooled.buffer()); + byteBuf.writeVarInt(Registry.ENTITY_TYPE.getRawId(e.getType())); + byteBuf.writeUuid(e.getUuid()); + byteBuf.writeVarInt(e.getId()); + + PacketBufUtil.writeVec3d(byteBuf, e.getPos()); + PacketBufUtil.writeAngle(byteBuf, e.getPitch()); + PacketBufUtil.writeAngle(byteBuf, e.getYaw()); + return ServerPlayNetworking.createS2CPacket(PacketHandler.SPAWN_PACKET, byteBuf); + } + + + public static final class PacketBufUtil { + + /** + * Packs a floating-point angle into a {@code byte}. + * + * @param angle + * angle + * @return packed angle + */ + public static byte packAngle(float angle) { + return (byte) MathHelper.floor(angle * 256 / 360); + } + + /** + * Unpacks a floating-point angle from a {@code byte}. + * + * @param angleByte + * packed angle + * @return angle + */ + public static float unpackAngle(byte angleByte) { + return (angleByte * 360) / 256f; + } + + /** + * Writes an angle to a {@link PacketByteBuf}. + * + * @param byteBuf + * destination buffer + * @param angle + * angle + */ + public static void writeAngle(PacketByteBuf byteBuf, float angle) { + byteBuf.writeByte(packAngle(angle)); + } + + /** + * Reads an angle from a {@link PacketByteBuf}. + * + * @param byteBuf + * source buffer + * @return angle + */ + public static float readAngle(PacketByteBuf byteBuf) { + return unpackAngle(byteBuf.readByte()); + } + + /** + * Writes a {@link Vec3d} to a {@link PacketByteBuf}. + * + * @param byteBuf + * destination buffer + * @param vec3d + * vector + */ + public static void writeVec3d(PacketByteBuf byteBuf, Vec3d vec3d) { + byteBuf.writeDouble(vec3d.x); + byteBuf.writeDouble(vec3d.y); + byteBuf.writeDouble(vec3d.z); + } + + /** + * Reads a {@link Vec3d} from a {@link PacketByteBuf}. + * + * @param byteBuf + * source buffer + * @return vector + */ + public static Vec3d readVec3d(PacketByteBuf byteBuf) { + double x = byteBuf.readDouble(); + double y = byteBuf.readDouble(); + double z = byteBuf.readDouble(); + return new Vec3d(x, y, z); + } + } + + public static void register() { + ClientPlayNetworking.registerGlobalReceiver(PacketHandler.SPAWN_PACKET, (client, handler, buf, responseSender) -> { + EntityType et = Registry.ENTITY_TYPE.get(buf.readVarInt()); + UUID uuid = buf.readUuid(); + int entityId = buf.readVarInt(); + Vec3d pos = EntitySpawnPacket.PacketBufUtil.readVec3d(buf); + float pitch = EntitySpawnPacket.PacketBufUtil.readAngle(buf); + float yaw = EntitySpawnPacket.PacketBufUtil.readAngle(buf); + client.execute(() -> { + if (MinecraftClient.getInstance().world == null) + throw new IllegalStateException("Tried to spawn entity in a null world!"); + Entity e = et.create(MinecraftClient.getInstance().world); + if (e == null) + throw new IllegalStateException("Failed to create instance of entity \"" + Registry.ENTITY_TYPE.getId(et) + "\"!"); + e.updateTrackedPosition(pos.getX(),pos.getY(),pos.getZ()); + e.setPos(pos.x, pos.y, pos.z); + e.setPitch(pitch); + e.setYaw(yaw); + e.setId(entityId); + e.setUuid(uuid); + MinecraftClient.getInstance().world.addEntity(entityId, e); + }); + }); + } +} diff --git a/src/main/java/com/dainxt/weaponthrow/projectile/WeaponThrowEntity.java b/src/main/java/com/dainxt/weaponthrow/projectile/WeaponThrowEntity.java index 6bd3b30..ff78f95 100644 --- a/src/main/java/com/dainxt/weaponthrow/projectile/WeaponThrowEntity.java +++ b/src/main/java/com/dainxt/weaponthrow/projectile/WeaponThrowEntity.java @@ -1,6 +1,7 @@ package com.dainxt.weaponthrow.projectile; import java.util.List; +import java.util.Objects; import org.jetbrains.annotations.Nullable; @@ -104,21 +105,21 @@ public void setItemStack(ItemStack stack) { this.getDataTracker().set(COMPOUND_STACK, stack.writeNbt(new NbtCompound())); } public ItemStack getItemStack() { - return ItemStack.fromNbt(((NbtCompound)this.getDataTracker().get(COMPOUND_STACK))); + return ItemStack.fromNbt(this.getDataTracker().get(COMPOUND_STACK)); } public void shouldDestroy(boolean stack) { this.getDataTracker().set(SHOULD_DESTROY, stack); } public boolean shouldDestroy() { - return ((Boolean)this.getDataTracker().get(SHOULD_DESTROY)); + return this.getDataTracker().get(SHOULD_DESTROY); } public void setDestroyedBlock(BlockPos pos) { this.getDataTracker().set(DESTROYED_BLOCK, pos); } public BlockPos getDestroyedBlock() { - return ((BlockPos)this.getDataTracker().get(DESTROYED_BLOCK)); + return this.getDataTracker().get(DESTROYED_BLOCK); } @@ -129,22 +130,19 @@ public void tick() { } if(!this.getDestroyedBlock().equals(BlockPos.ZERO) && !this.world.isClient) { - - this.doInteractions(() -> { - SoundEvent event = this.world.getBlockState(this.getDestroyedBlock()).getSoundGroup().getBreakSound(); - boolean destroyed = ((ServerPlayerEntity)this.getOwner()).interactionManager.tryBreakBlock(this.getDestroyedBlock()); - if(destroyed) { - this.world.playSound(null, this.getDestroyedBlock(), event , SoundCategory.AMBIENT, 10, 1.0F); - } - }); - - this.setDestroyedBlock(BlockPos.ORIGIN); + + this.doInteractions(() -> { + SoundEvent event = this.world.getBlockState(this.getDestroyedBlock()).getSoundGroup().getBreakSound(); + boolean destroyed = ((ServerPlayerEntity) Objects.requireNonNull(this.getOwner())).interactionManager.tryBreakBlock(this.getDestroyedBlock()); + if(destroyed) { + this.world.playSound(null, this.getDestroyedBlock(), event , SoundCategory.AMBIENT, 10, 1.0F); + } + }); + this.setDestroyedBlock(BlockPos.ORIGIN); } - int gravityWorld = ConfigRegistry.COMMON.get().enchantments.enableGravity ? EnchantmentHelper.getLevel(EnchantmentHandler.GRAVITY, this.getItemStack()) : 0; - if(gravityWorld > 0) { - this.setNoGravity(true); + if(gravityWorld > 0) {this.setNoGravity(true); if(this.world.isOutOfHeightLimit(this.getBlockPos())) { this.setVelocity(this.getVelocity().multiply(1, 0, 1)); } @@ -154,31 +152,20 @@ public void tick() { } } - - - /*if(this.inGround && MathHelper.abs(this.getPitch()) < 45 && this.getItemStack().getItem() instanceof BlockItem) { - if(!(Math.abs(this.getVelocity().getX()) < 0.1 && Math.abs(this.getVelocity().getZ()) < 0.1)) { - this.setVelocity(this.getVelocity().multiply(-0.5F)); - this.counterClockwiseBounce = !this.counterClockwiseBounce; - this.inGround = false; - } - }*/ Entity entity = this.getOwner(); - - + int i = ConfigRegistry.COMMON.get().enchantments.enableReturn ? this.dataTracker.get(LOYALTY_LEVEL) : 0; if (i > 0 && (this.dealtDamage || this.isNoClip()) && entity != null) { if (!this.shouldReturnToThrower()) { - if (!this.world.isClient && this.pickupType == PersistentProjectileEntity.PickupPermission.ALLOWED) { this.dropStack(this.getItemStack(), 0.1F); } this.remove(RemovalReason.DISCARDED); - } else if (i > 0) { + } else { this.setNoClip(true); Vec3d Vec3d = entity.getEyePos().subtract(this.getPos()); this.setPos(this.getX(), this.getY() + Vec3d.y * 0.015D * (double)i, this.getZ()); @@ -224,15 +211,14 @@ protected void onEntityHit(EntityHitResult p_213868_1_) { Entity entity = p_213868_1_.getEntity(); float f = this.attackDamage; - if (entity instanceof LivingEntity) { - LivingEntity livingentity = (LivingEntity)entity; + if (entity instanceof LivingEntity livingentity) { - f += ConfigRegistry.COMMON.get().enchantments.enableThrow ? EnchantmentHelper.getLevel(EnchantmentHandler.THROW, this.getItemStack())*1F : 0; + f += ConfigRegistry.COMMON.get().enchantments.enableThrow ? EnchantmentHelper.getLevel(EnchantmentHandler.THROW, this.getItemStack())*1F : 0; f += EnchantmentHelper.getAttackDamage(this.getItemStack(), livingentity.getGroup()); } Entity entity1 = this.getOwner(); - DamageSource damagesource = DamageSource.thrownProjectile(this, (Entity)(entity1 == null ? this : entity1)); + DamageSource damagesource = DamageSource.thrownProjectile(this, entity1 == null ? this : entity1); @@ -245,11 +231,10 @@ protected void onEntityHit(EntityHitResult p_213868_1_) { return; } - if (entity instanceof LivingEntity) { - LivingEntity livingentity1 = (LivingEntity)entity; - - - int contusionWorld = ConfigRegistry.COMMON.get().enchantments.enableConccusion ? EnchantmentHelper.getLevel(EnchantmentHandler.CONCCUSION, this.getItemStack()) : 0; + if (entity instanceof LivingEntity livingentity1) { + + + int contusionWorld = ConfigRegistry.COMMON.get().enchantments.enableConccusion ? EnchantmentHelper.getLevel(EnchantmentHandler.CONCCUSION, this.getItemStack()) : 0; if (contusionWorld > 0) { livingentity1.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 20*2*contusionWorld, 5)); @@ -263,14 +248,12 @@ protected void onEntityHit(EntityHitResult p_213868_1_) { List nearEntities = world.getNonSpectatingEntities(LivingEntity.class, this.getBoundingBox().expand(1.0D)); if(!nearEntities.isEmpty()) { - for(LivingEntity nearEntity: nearEntities) { - if(nearEntity.getRandom().nextInt(3) == 0) { - nearEntity.setOnFireFor(fireTime); - } - if(true) { - nearEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.WEAKNESS, 80, groundedWorld-1)); - } - } + for(LivingEntity nearEntity: nearEntities) { + if(nearEntity.getRandom().nextInt(3) == 0) { + nearEntity.setOnFireFor(fireTime); + } + nearEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.WEAKNESS, 80, groundedWorld - 1)); + } } } @@ -282,23 +265,22 @@ protected void onEntityHit(EntityHitResult p_213868_1_) { this.onHit(livingentity1); if(this.getItemStack().getItem() instanceof BlockItem) { - Block blockItem = Block.getBlockFromItem(this.getItemStack().getItem()); - + Block blockItem = Block.getBlockFromItem(this.getItemStack().getItem()); if(blockItem instanceof SandBlock) { - if(livingentity1.getRandom().nextInt(10) == 0) livingentity1.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 60, 3)); + if(livingentity1.getRandom().nextInt(10) == 0) livingentity1.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, 60, 3)); } else if (blockItem instanceof TorchBlock){ - if(livingentity1.getRandom().nextInt(5) == 0) livingentity1.setOnFireFor(1); + if(livingentity1.getRandom().nextInt(5) == 0) livingentity1.setOnFireFor(1); } else if (blockItem instanceof AnvilBlock){ - livingentity1.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 60, 3)); - livingentity1.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 60, 5)); + livingentity1.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 60, 3)); + livingentity1.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 60, 5)); } }else { - Item itemThrowed = this.getItemStack().getItem(); - if(itemThrowed.equals(Items.BLAZE_ROD) || itemThrowed.equals(Items.BLAZE_POWDER)) { - livingentity1.setOnFireFor(1); - } + Item itemThrowed = this.getItemStack().getItem(); + if(itemThrowed.equals(Items.BLAZE_ROD) || itemThrowed.equals(Items.BLAZE_POWDER)) { + livingentity1.setOnFireFor(1); + } } } @@ -323,7 +305,7 @@ public void onPlayerCollision(PlayerEntity entityIn) { Entity entity = this.getOwner(); if (entity == null || entity.getUuid() == entityIn.getUuid() || this.inGroundTime > (ConfigRegistry.COMMON.get().times.ticksUntilWeaponLoseOwner)) { - super.onPlayerCollision(entityIn); + super.onPlayerCollision(entityIn); } } @@ -333,7 +315,7 @@ public void readCustomDataFromNbt(NbtCompound compound) { this.dealtDamage = compound.getBoolean("DealtDamage"); if (compound.contains("Stack", 10)) { - this.setItemStack(ItemStack.fromNbt(compound.getCompound("Stack"))); + this.setItemStack(ItemStack.fromNbt(compound.getCompound("Stack"))); } this.dataTracker.set(LOYALTY_LEVEL, (byte)WeaponThrowEntity.getReturnOrLoyaltyEnchantment(this.getItemStack())); @@ -346,7 +328,7 @@ public void writeCustomDataToNbt(NbtCompound compound) { compound.put("Stack", this.getDataTracker().get(COMPOUND_STACK)); compound.putBoolean("DealtDamage", this.dealtDamage); if (this.lastState != null) { - compound.put("inBlockState", NbtHelper.fromBlockState(this.lastState)); + compound.put("inBlockState", NbtHelper.fromBlockState(this.lastState)); } } @@ -376,40 +358,29 @@ protected void onCollision(HitResult result) { this.onEntityHit((EntityHitResult)result); } else if (raytraceresult$type == HitResult.Type.BLOCK) { - - BlockPos stickBlockPos = ((BlockHitResult)result).getBlockPos(); - BlockState state = this.world.getBlockState(stickBlockPos); - - - - /*!WeaponThrowConfig.COMMON.blackList.get().contains(state.getBlock()) && */ - - if(!state.getBlock().equals(Blocks.BEDROCK) && this.shouldDestroy()) { - - boolean canBreak = ConfigRegistry.COMMON.get().interactions.canBreakBlocks; - - boolean canHarvest = this.getItemStack().isSuitableFor(state) && canBreak; - - if(canHarvest) { - - if(!world.isClient && this.lastState == null) { - this.setDestroyedBlock(stickBlockPos); - } - } - } - - this.onBlockHit((BlockHitResult)result); + BlockPos stickBlockPos = ((BlockHitResult)result).getBlockPos(); + BlockState state = this.world.getBlockState(stickBlockPos); + if(!state.getBlock().equals(Blocks.BEDROCK) && this.shouldDestroy()) { + boolean canBreak = ConfigRegistry.COMMON.get().interactions.canBreakBlocks; + + boolean canHarvest = this.getItemStack().isSuitableFor(state) && canBreak; + if(canHarvest) { + if(!world.isClient && this.lastState == null) { + this.setDestroyedBlock(stickBlockPos); + } + + } + } + this.onBlockHit((BlockHitResult)result); } } - - @Override protected void onBlockHit(BlockHitResult blockHitResult) { this.lastState = this.world.getBlockState(blockHitResult.getBlockPos()); Vec3d Vec3d = blockHitResult.getPos().subtract(this.getX(), this.getY(), this.getZ()); this.setVelocity(Vec3d); - Vec3d Vec3d1 = Vec3d.normalize().multiply((double)0.05F); + Vec3d Vec3d1 = Vec3d.normalize().multiply(0.05F); this.setPos(this.getX() - Vec3d1.x, this.getY() - Vec3d1.y, this.getZ() - Vec3d1.z); SoundEvent event = SoundEvents.ITEM_TRIDENT_HIT_GROUND; @@ -433,28 +404,22 @@ protected void onBlockHit(BlockHitResult blockHitResult) { void applyBounce() { if(this.inGround && this.getItemStack().getItem() instanceof BlockItem ) { - - if(!(Math.abs(this.getVelocity().x) < 0.05 && Math.abs(this.getVelocity().z) < 0.05)) { - - Vec3d vec3 = this.getVelocity().multiply(0.9F); - - BlockPos landingPos = getLandingPos(); - - if(!this.world.getBlockState(landingPos.down()).isAir() || !this.world.getBlockState(landingPos.up()).isAir()) { - this.setVelocity(vec3.x, -vec3.y, vec3.z); - } - else if(!this.world.getBlockState(landingPos.west()).isAir() || !this.world.getBlockState(landingPos.east()).isAir()){ - this.setVelocity(-vec3.x, vec3.y, vec3.z); - } - else if(!this.world.getBlockState(landingPos.north()).isAir() || !this.world.getBlockState(landingPos.south()).isAir()){ - this.setVelocity(vec3.x, vec3.y, -vec3.z); - } - - this.counterClockwiseBounce = !this.counterClockwiseBounce; - - - this.inGround = false; - } + if(!(Math.abs(this.getVelocity().x) < 0.05 && Math.abs(this.getVelocity().z) < 0.05)) { + + Vec3d vec3 = this.getVelocity().multiply(0.9F); + BlockPos landingPos = getSteppingPos(); + + if(!this.world.getBlockState(landingPos.down()).isAir() || !this.world.getBlockState(landingPos.up()).isAir()) { + this.setVelocity(vec3.x, -vec3.y, vec3.z); + } + else if(!this.world.getBlockState(landingPos.west()).isAir() || !this.world.getBlockState(landingPos.east()).isAir()){ + this.setVelocity(-vec3.x, vec3.y, vec3.z); + } + else if(!this.world.getBlockState(landingPos.north()).isAir() || !this.world.getBlockState(landingPos.south()).isAir()){ + this.setVelocity(vec3.x, vec3.y, -vec3.z); + } + this.counterClockwiseBounce = !this.counterClockwiseBounce; + this.inGround = false;} } } @@ -462,24 +427,19 @@ else if(!this.world.getBlockState(landingPos.north()).isAir() || !this.world.get public ItemStack getStack() { return this.getItemStack(); } - - + @Override public Packet createSpawnPacket() { return super.createSpawnPacket(); - //return EntitySpawnPacket.create(this); } public void doInteractions(Runnable action) { - ItemStack originalStack = ((PlayerEntity)this.getOwner()).getStackInHand(Hand.MAIN_HAND); + ItemStack originalStack = ((PlayerEntity) Objects.requireNonNull(this.getOwner())).getStackInHand(Hand.MAIN_HAND); ((PlayerEntity) this.getOwner()).setStackInHand(Hand.MAIN_HAND, this.getItemStack()); - action.run(); - - //((PlayerEntity) this.getOwner()).setStackInHand(Hand.MAIN_HAND, originalStack); - + ItemStack newStack = ((PlayerEntity) this.getOwner()).getStackInHand(Hand.MAIN_HAND); if (!newStack.isEmpty()) { @@ -488,15 +448,14 @@ public void doInteractions(Runnable action) { this.world.playSound(null, this.getBlockPos(), SoundEvents.ENTITY_ITEM_BREAK, SoundCategory.AMBIENT, 0.8F, 10F); - this.spawnItemParticles(this.getItemStack(), 5); + this.spawnItemParticles(this.getItemStack()); this.remove(RemovalReason.DISCARDED); } - } - private void spawnItemParticles(ItemStack stack, int count) { - for(int i = 0; i < count; ++i) { + private void spawnItemParticles(ItemStack stack) { + for(int i = 0; i < 5; ++i) { Vec3d vec3d = new Vec3d(((double)this.random.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D); vec3d = vec3d.rotateX(-this.getPitch() * 0.017453292F); vec3d = vec3d.rotateY(-this.getYaw() * 0.017453292F); @@ -510,7 +469,6 @@ private void spawnItemParticles(ItemStack stack, int count) { else this.world.addParticle(new ItemStackParticleEffect(ParticleTypes.ITEM, stack), vec3d2.x, vec3d2.y, vec3d2.z, vec3d.x, vec3d.y + 0.05D, vec3d.z); } - } public static int getReturnOrLoyaltyEnchantment(ItemStack stack) { @@ -521,10 +479,7 @@ public static int getReturnOrLoyaltyEnchantment(ItemStack stack) { @Environment(EnvType.CLIENT) public float getRotationAnimation(float partialTicks) { - if(!this.inGround) { - clientSideRotation = (this.counterClockwiseBounce? 1:-1)*(this.age+partialTicks)*50F; - } + if(!this.inGround) {clientSideRotation = (this.counterClockwiseBounce? 1:-1)*(this.age+partialTicks)*50F;} return this.clientSideRotation; } - } diff --git a/src/main/resources/assets/weaponthrow/lang/en_us.json b/src/main/resources/assets/weaponthrow/lang/en_us.json index b4a2b01..851704e 100644 --- a/src/main/resources/assets/weaponthrow/lang/en_us.json +++ b/src/main/resources/assets/weaponthrow/lang/en_us.json @@ -1,92 +1,92 @@ -{ - "key.weaponthrow": "Throw", - "enchantment.weaponthrow.throw": "Throw", - "enchantment.weaponthrow.throw.desc": "Increase throwing damage", - "enchantment.weaponthrow.groundededge": "Grounded Edge", - "enchantment.weaponthrow.groundededge.desc": "Apply weakness in area", - "enchantment.weaponthrow.conccusion": "Concussion", - "enchantment.weaponthrow.conccusion.desc": "Apply nausea and slowness", - "enchantment.weaponthrow.gravity": "Curse of Gravity", - "enchantment.weaponthrow.gravity.desc": "Your weapon defies gravity, at a cost", - "enchantment.weaponthrow.return": "Return", - "enchantment.weaponthrow.return.desc": "Your weapons come back", - "weaponthrow.pmmo.requirementThrowing": "You need combat level %d to throw that weapon", - "weaponthrow.pmmo.requirementLoyalty": "You need combat level %d to use loyalty", - - //Tetra Enchantment Integration - "tetra.improvement.enchantment/weaponthrow_throw.name": "Throw", - "tetra.improvement.enchantment/weaponthrow_throw.description": "Increase throwing damage", - "tetra.improvement.destabilized/weaponthrow_throw.name": "Destabilized: Throw", - "tetra.improvement.destabilized/weaponthrow_throw.description": "Reduces the effect of the Throw enchantment", - "tetra.improvement.enchantment/weaponthrow_groundededge.name": "Grounded Edge", - "tetra.improvement.enchantment/weaponthrow_groundededge.description": "Apply weakness in area", - "tetra.improvement.destabilized/weaponthrow_groundededge.name": "Destabilized: Grounded Edge", - "tetra.improvement.destabilized/weaponthrow_groundededge.description": "Reduces the effect of the Grounded Edge enchantment", - "tetra.improvement.enchantment/weaponthrow_conccusion.name": "Concussion", - "tetra.improvement.enchantment/weaponthrow_conccusion.description": "Apply nausea and slowness", - "tetra.improvement.destabilized/weaponthrow_conccusion.name": "Destabilized: Concussion", - "tetra.improvement.destabilized/weaponthrow_conccusion.description": "Reduces the effect of the Concussion enchantment", - "tetra.improvement.enchantment/weaponthrow_gravity.name": "Curse of Gravity", - "tetra.improvement.enchantment/weaponthrow_gravity.description": "Your weapon defies gravity, at a cost", - "tetra.improvement.enchantment/weaponthrow_return.name": "Return", - "tetra.improvement.enchantment/weaponthrow_return.description": "Your weapons come back", - "tetra.improvement.destabilized/weaponthrow_return.name": "Destabilized: Return", - "tetra.improvement.destabilized/weaponthrow_return.description": "Reduces the effect of the Return enchantment", - - //ModMenu Gui Integration - - "text.autoconfig.weaponthrow.title": "Weapon Throw Config", - - "text.autoconfig.weaponthrow.category.general": "General", - "text.autoconfig.weaponthrow.option.general.creativeSpamming": "Creative Spamming", - "text.autoconfig.weaponthrow.option.general.notUseWhenCooldown": "Not use when cooldown", - - "text.autoconfig.weaponthrow.category.defaults": "Defaults", - "text.autoconfig.weaponthrow.option.defaults.baseDamageDefault": "Default base damage for non weapons", - "text.autoconfig.weaponthrow.option.defaults.velocityDefault": "Default base velocity for non weapons", - - "text.autoconfig.weaponthrow.category.enchantments": "Enchantments", - "text.autoconfig.weaponthrow.option.enchantments.enchantAllWeapons": "All weapons can be enchanted", - "text.autoconfig.weaponthrow.option.enchantments.enableThrow": "Enable Throw Enchantment", - "text.autoconfig.weaponthrow.option.enchantments.enableConccusion": "Enable Concussion Enchantment", - "text.autoconfig.weaponthrow.option.enchantments.enableGroundedEdge": "Enable Grounded Edge Enchantment", - "text.autoconfig.weaponthrow.option.enchantments.enableGravity": "Enable Gravity Enchantment", - "text.autoconfig.weaponthrow.option.enchantments.enableReturn": "Enable Return Enchantment", - - "text.autoconfig.weaponthrow.category.experimental": "Experimental", - "text.autoconfig.weaponthrow.option.experimental.shouldThrowItemsToo": "Can throw any Items", - - "text.autoconfig.weaponthrow.category.interactions": "Interactions", - "text.autoconfig.weaponthrow.option.interactions.canBreakBlocks": "Can break blocks", - - "text.autoconfig.weaponthrow.category.multipliers": "Multipliers", - - "text.autoconfig.weaponthrow.option.multipliers.tools": "Tools Multipliers", - "text.autoconfig.weaponthrow.option.multipliers.tools.pickaxeMultiplier": "Pickaxe Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.tools.axeMultiplier": "Axe Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.tools.swordMultiplier": "Sword Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.tools.hoeMultiplier": "Hoe Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.tools.shovelMultiplier": "Shovel Multiplier", - - "text.autoconfig.weaponthrow.option.multipliers.damages": "Damage Multipliers", - "text.autoconfig.weaponthrow.option.multipliers.damages.baseDamageMultiplier": "Base Damage Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.damages.stackDamageMultiplier": "Stack Damage Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.damages.modifiedDamageMultiplier": "Modified Damage Multiplier", - - "text.autoconfig.weaponthrow.option.multipliers.velocities": "Velocity Multipliers", - "text.autoconfig.weaponthrow.option.multipliers.velocities.baseVelocityMultiplier": "Base Velocity Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.velocities.stackVelocityMultiplier": "Stack Velocity Multiplierr", - "text.autoconfig.weaponthrow.option.multipliers.velocities.modifiedVelocityMultiplier": "Modified Velocity Multiplier", - - "text.autoconfig.weaponthrow.option.multipliers.exhaustions": "Exhaustion Multipliers", - "text.autoconfig.weaponthrow.option.multipliers.exhaustions.baseExhaustionMultiplier": "Base Exhaustion Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.exhaustions.stackExhaustionMultiplier": "Stack Exhaustion Multiplier", - "text.autoconfig.weaponthrow.option.multipliers.exhaustions.modifiedExhaustionMultiplier": "Modified Exhaustion Multiplier", - - - "text.autoconfig.weaponthrow.category.times": "Times", - "text.autoconfig.weaponthrow.option.times.despawnTime": "Despawn Time", - "text.autoconfig.weaponthrow.option.times.castTimeMuliplier": "Cast Time Multiplier", - "text.autoconfig.weaponthrow.option.times.ticksUntilWeaponLoseOwner": "Ticks until weapon lose owner" - +{ + "key.weaponthrow": "Throw", + "enchantment.weaponthrow.throw": "Throw", + "enchantment.weaponthrow.throw.desc": "Increase throwing damage", + "enchantment.weaponthrow.groundededge": "Grounded Edge", + "enchantment.weaponthrow.groundededge.desc": "Apply weakness in area", + "enchantment.weaponthrow.conccusion": "Concussion", + "enchantment.weaponthrow.conccusion.desc": "Apply nausea and slowness", + "enchantment.weaponthrow.gravity": "Curse of Gravity", + "enchantment.weaponthrow.gravity.desc": "Your weapon defies gravity, at a cost", + "enchantment.weaponthrow.return": "Return", + "enchantment.weaponthrow.return.desc": "Your weapons come back", + "weaponthrow.pmmo.requirementThrowing": "You need combat level %d to throw that weapon", + "weaponthrow.pmmo.requirementLoyalty": "You need combat level %d to use loyalty", + + //Tetra Enchantment Integration + "tetra.improvement.enchantment/weaponthrow_throw.name": "Throw", + "tetra.improvement.enchantment/weaponthrow_throw.description": "Increase throwing damage", + "tetra.improvement.destabilized/weaponthrow_throw.name": "Destabilized: Throw", + "tetra.improvement.destabilized/weaponthrow_throw.description": "Reduces the effect of the Throw enchantment", + "tetra.improvement.enchantment/weaponthrow_groundededge.name": "Grounded Edge", + "tetra.improvement.enchantment/weaponthrow_groundededge.description": "Apply weakness in area", + "tetra.improvement.destabilized/weaponthrow_groundededge.name": "Destabilized: Grounded Edge", + "tetra.improvement.destabilized/weaponthrow_groundededge.description": "Reduces the effect of the Grounded Edge enchantment", + "tetra.improvement.enchantment/weaponthrow_conccusion.name": "Concussion", + "tetra.improvement.enchantment/weaponthrow_conccusion.description": "Apply nausea and slowness", + "tetra.improvement.destabilized/weaponthrow_conccusion.name": "Destabilized: Concussion", + "tetra.improvement.destabilized/weaponthrow_conccusion.description": "Reduces the effect of the Concussion enchantment", + "tetra.improvement.enchantment/weaponthrow_gravity.name": "Curse of Gravity", + "tetra.improvement.enchantment/weaponthrow_gravity.description": "Your weapon defies gravity, at a cost", + "tetra.improvement.enchantment/weaponthrow_return.name": "Return", + "tetra.improvement.enchantment/weaponthrow_return.description": "Your weapons come back", + "tetra.improvement.destabilized/weaponthrow_return.name": "Destabilized: Return", + "tetra.improvement.destabilized/weaponthrow_return.description": "Reduces the effect of the Return enchantment", + + //ModMenu Gui Integration + + "text.autoconfig.weaponthrow.title": "Weapon Throw Config", + + "text.autoconfig.weaponthrow.category.general": "General", + "text.autoconfig.weaponthrow.option.general.creativeSpamming": "Creative Spamming", + "text.autoconfig.weaponthrow.option.general.notUseWhenCooldown": "Not use when cooldown", + + "text.autoconfig.weaponthrow.category.defaults": "Defaults", + "text.autoconfig.weaponthrow.option.defaults.baseDamageDefault": "Default base damage for non weapons", + "text.autoconfig.weaponthrow.option.defaults.velocityDefault": "Default base velocity for non weapons", + + "text.autoconfig.weaponthrow.category.enchantments": "Enchantments", + "text.autoconfig.weaponthrow.option.enchantments.enchantAllWeapons": "All weapons can be enchanted", + "text.autoconfig.weaponthrow.option.enchantments.enableThrow": "Enable Throw Enchantment", + "text.autoconfig.weaponthrow.option.enchantments.enableConccusion": "Enable Concussion Enchantment", + "text.autoconfig.weaponthrow.option.enchantments.enableGroundedEdge": "Enable Grounded Edge Enchantment", + "text.autoconfig.weaponthrow.option.enchantments.enableGravity": "Enable Gravity Enchantment", + "text.autoconfig.weaponthrow.option.enchantments.enableReturn": "Enable Return Enchantment", + + "text.autoconfig.weaponthrow.category.experimental": "Experimental", + "text.autoconfig.weaponthrow.option.experimental.shouldThrowItemsToo": "Can throw any Items", + + "text.autoconfig.weaponthrow.category.interactions": "Interactions", + "text.autoconfig.weaponthrow.option.interactions.canBreakBlocks": "Can break blocks", + + "text.autoconfig.weaponthrow.category.multipliers": "Multipliers", + + "text.autoconfig.weaponthrow.option.multipliers.tools": "Tools Multipliers", + "text.autoconfig.weaponthrow.option.multipliers.tools.pickaxeMultiplier": "Pickaxe Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.tools.axeMultiplier": "Axe Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.tools.swordMultiplier": "Sword Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.tools.hoeMultiplier": "Hoe Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.tools.shovelMultiplier": "Shovel Multiplier", + + "text.autoconfig.weaponthrow.option.multipliers.damages": "Damage Multipliers", + "text.autoconfig.weaponthrow.option.multipliers.damages.baseDamageMultiplier": "Base Damage Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.damages.stackDamageMultiplier": "Stack Damage Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.damages.modifiedDamageMultiplier": "Modified Damage Multiplier", + + "text.autoconfig.weaponthrow.option.multipliers.velocities": "Velocity Multipliers", + "text.autoconfig.weaponthrow.option.multipliers.velocities.baseVelocityMultiplier": "Base Velocity Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.velocities.stackVelocityMultiplier": "Stack Velocity Multiplierr", + "text.autoconfig.weaponthrow.option.multipliers.velocities.modifiedVelocityMultiplier": "Modified Velocity Multiplier", + + "text.autoconfig.weaponthrow.option.multipliers.exhaustions": "Exhaustion Multipliers", + "text.autoconfig.weaponthrow.option.multipliers.exhaustions.baseExhaustionMultiplier": "Base Exhaustion Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.exhaustions.stackExhaustionMultiplier": "Stack Exhaustion Multiplier", + "text.autoconfig.weaponthrow.option.multipliers.exhaustions.modifiedExhaustionMultiplier": "Modified Exhaustion Multiplier", + + + "text.autoconfig.weaponthrow.category.times": "Times", + "text.autoconfig.weaponthrow.option.times.despawnTime": "Despawn Time", + "text.autoconfig.weaponthrow.option.times.castTimeMuliplier": "Cast Time Multiplier", + "text.autoconfig.weaponthrow.option.times.ticksUntilWeaponLoseOwner": "Ticks until weapon lose owner" + } \ No newline at end of file diff --git a/src/main/resources/assets/weaponthrow/lang/zh_cn.json b/src/main/resources/assets/weaponthrow/lang/zh_cn.json index fbad7c4..f10d7dd 100644 --- a/src/main/resources/assets/weaponthrow/lang/zh_cn.json +++ b/src/main/resources/assets/weaponthrow/lang/zh_cn.json @@ -1,12 +1,12 @@ -{ - "weaponthrow.categories.throw": "武器投掷", - "weaponthrow.throw": "投掷", - "enchantment.weaponthrow.throw": "投掷", - "enchantment.weaponthrow.throw.desc": "增加武器投掷伤害", - "enchantment.weaponthrow.groundededge": "撼地", - "enchantment.weaponthrow.groundededge.desc": "给予范围内的生物虚弱效果", - "enchantment.weaponthrow.conccusion": "震荡", - "enchantment.weaponthrow.conccusion.desc": "给予反胃和缓慢效果", - "enchantment.weaponthrow.gravity": "反重力", - "enchantment.weaponthrow.gravity.desc": "你投出去的武器无视重力效果" +{ + "weaponthrow.categories.throw": "武器投掷", + "weaponthrow.throw": "投掷", + "enchantment.weaponthrow.throw": "投掷", + "enchantment.weaponthrow.throw.desc": "增加武器投掷伤害", + "enchantment.weaponthrow.groundededge": "撼地", + "enchantment.weaponthrow.groundededge.desc": "给予范围内的生物虚弱效果", + "enchantment.weaponthrow.conccusion": "震荡", + "enchantment.weaponthrow.conccusion.desc": "给予反胃和缓慢效果", + "enchantment.weaponthrow.gravity": "反重力", + "enchantment.weaponthrow.gravity.desc": "你投出去的武器无视重力效果" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ecaa519..9024e48 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -35,9 +35,9 @@ ], "depends": { - "fabricloader": ">=0.11.3", + "fabricloader": ">=0.14.12+", "fabric": "*", - "minecraft": "1.18.x", + "minecraft": "1.19.2", "java": ">=17" }, "suggests": { diff --git a/src/main/resources/weaponthrow.mixins.json b/src/main/resources/weaponthrow.mixins.json index bc2536d..1e3af85 100644 --- a/src/main/resources/weaponthrow.mixins.json +++ b/src/main/resources/weaponthrow.mixins.json @@ -1,16 +1,16 @@ { "required": true, "minVersion": "0.8", - "package": "com.dainxt.weaponthrow.mixin", + "package": "com.dainxt.weaponthrow.mixins", "compatibilityLevel": "JAVA_16", "mixins": [ "PlayerEntityMixin" ], "client": [ - "ClientPlayerEntityMixin", - "HeldItemRendererMixin", - "PlayerEntityRendererMixin", - "AbstractClientPlayerEntityMixin" + "client.ClientPlayerEntityMixin", + "client.HeldItemRendererMixin", + "client.PlayerEntityRendererMixin", + "client.AbstractClientPlayerEntityMixin" ], "injectors": { "defaultRequire": 1