├── .github ├── icon.png └── logo2.png ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── java │ └── ca │ └── atlasengine │ └── projectiles │ ├── AbstractProjectile.java │ ├── BowModule.java │ ├── Projectile.java │ └── entities │ ├── ArrowProjectile.java │ ├── FireballProjectile.java │ ├── FollowProjectile.java │ └── ThrownItemProjectile.java └── test └── java └── Main.java /.github/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtlasEngineCa/AtlasProjectiles/71bb500cdf425dc2f5b2ab488054075ef395dd80/.github/icon.png -------------------------------------------------------------------------------- /.github/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtlasEngineCa/AtlasProjectiles/71bb500cdf425dc2f5b2ab488054075ef395dd80/.github/logo2.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.nar 19 | *.ear 20 | *.zip 21 | *.tar.gz 22 | *.rar 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | 27 | ### Gradle template 28 | **/.gradle 29 | **/build/ 30 | 31 | # Ignore Gradle GUI config 32 | gradle-app.setting 33 | 34 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 35 | !gradle-wrapper.jar 36 | 37 | # Cache of project 38 | .gradletasknamecache 39 | 40 | # IDEA files 41 | .idea/ 42 | **/out/ 43 | 44 | src/test/resources/resourcepack/ 45 | src/test/resources/model_mappings.json 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2024] [Alexander Parent] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 12 | [![Contributors][contributors-shield]][contributors-url] 13 | [![Forks][forks-shield]][forks-url] 14 | [![Stargazers][stars-shield]][stars-url] 15 | [![Issues][issues-shield]][issues-url] 16 | [![APACHE-2.0 License][license-shield]][license-url] 17 | 18 | 19 |
20 |
21 | 22 | Logo 23 | 24 | 25 |

26 | 27 |

28 |
29 |
30 |
31 | Report Bug 32 | · 33 | Request Feature 34 |

35 |
36 | 37 | 38 | ## About The Project 39 | This is a library to add projectiles. 40 | Currently support projectiles: 41 | - Arrows 42 | - Fireballs 43 | - Items (snowball, enderpearl, etc) 44 | - Shulker Bullets 45 | 46 | The goal is to make the projectiles act similarly to vanilla, but not all projectiles will be identical. 47 | Contributions are welcome! 48 | 49 | 50 | ## Getting Started 51 | 52 | A full, runnable example server can be found [here](https://github.com/AtlasEngineCa/AtlasProjectiles/blob/main/src/test/java/Main.java) 53 | 54 | ## Credits 55 | - [hapily04](https://github.com/hapily04) Initial bow and arrow projectile code 56 | 57 | ### Adding as a dependency 58 | 59 | Add the following to your `build.gradle.kts` file: 60 | 61 | ``` 62 | repositories { 63 | maven("https://reposilite.atlasengine.ca/public") 64 | } 65 | ``` 66 | 67 | Add the library as a dependency 68 | ``` 69 | dependencies { 70 | implementation("ca.atlasengine:atlas-projectiles:") 71 | } 72 | ``` 73 | 74 | The lastest version number can be found [here](https://reposilite.atlasengine.ca/#/public/ca/atlasengine/atlas-projectiles) 75 | 76 |

(back to top)

77 | 78 | 79 | 80 | [contributors-shield]: https://img.shields.io/github/contributors/AtlasEngineCa/AtlasProjectiles.svg?style=for-the-badge 81 | [contributors-url]: https://github.com/AtlasEngineCa/AtlasProjectiles/graphs/contributors 82 | [forks-shield]: https://img.shields.io/github/forks/AtlasEngineCa/AtlasProjectiles.svg?style=for-the-badge 83 | [forks-url]: https://github.com/othneildrew/Best-README-Template/network/members 84 | [stars-shield]: https://img.shields.io/github/stars/AtlasEngineCa/AtlasProjectiles.svg?style=for-the-badge 85 | [stars-url]: https://github.com/AtlasEngineCa/AtlasProjectiles/stargazers 86 | [issues-shield]: https://img.shields.io/github/issues/AtlasEngineCa/AtlasProjectiles.svg?style=for-the-badge 87 | [issues-url]: https://github.com/AtlasEngineCa/AtlasProjectiles/issues 88 | [license-shield]: https://img.shields.io/github/license/AtlasEngineCa/AtlasProjectiles?style=for-the-badge 89 | [license-url]: https://github.com/AtlasEngineCa/AtlasProjectiles/blob/master/LICENSE 90 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java") 3 | `maven-publish` 4 | signing 5 | } 6 | 7 | java { 8 | sourceCompatibility = JavaVersion.VERSION_21 9 | targetCompatibility = JavaVersion.VERSION_21 10 | 11 | withSourcesJar() 12 | withJavadocJar() 13 | } 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | 19 | publishing { 20 | publications.create("maven") { 21 | groupId = "ca.atlasengine" 22 | artifactId = "atlas-projectiles" 23 | version = "1.0.2" 24 | 25 | from(components["java"]) 26 | } 27 | 28 | repositories { 29 | maven { 30 | name = "WorldSeed" 31 | url = uri("https://reposilite.worldseed.online/public") 32 | credentials(PasswordCredentials::class) 33 | authentication { 34 | create("basic") 35 | } 36 | } 37 | } 38 | } 39 | 40 | dependencies { 41 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1") 42 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1") 43 | 44 | compileOnly("net.minestom:minestom-snapshots:c96413678c") 45 | testImplementation("net.minestom:minestom-snapshots:c96413678c") 46 | } 47 | 48 | tasks.getByName("test") { 49 | useJUnitPlatform() 50 | } 51 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AtlasEngineCa/AtlasProjectiles/71bb500cdf425dc2f5b2ab488054075ef395dd80/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat May 18 14:50:15 EDT 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'MinestomProjectiles' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/ca/atlasengine/projectiles/AbstractProjectile.java: -------------------------------------------------------------------------------- 1 | package ca.atlasengine.projectiles; 2 | 3 | import net.minestom.server.MinecraftServer; 4 | import net.minestom.server.ServerFlag; 5 | import net.minestom.server.collision.*; 6 | import net.minestom.server.coordinate.Point; 7 | import net.minestom.server.coordinate.Pos; 8 | import net.minestom.server.coordinate.Vec; 9 | import net.minestom.server.entity.Entity; 10 | import net.minestom.server.entity.EntityType; 11 | import net.minestom.server.event.EventDispatcher; 12 | import net.minestom.server.event.entity.EntityTickEvent; 13 | import net.minestom.server.event.entity.projectile.ProjectileCollideWithBlockEvent; 14 | import net.minestom.server.event.entity.projectile.ProjectileCollideWithEntityEvent; 15 | import net.minestom.server.instance.Chunk; 16 | import net.minestom.server.instance.block.Block; 17 | import net.minestom.server.instance.block.BlockHandler; 18 | import net.minestom.server.utils.chunk.ChunkCache; 19 | import net.minestom.server.utils.chunk.ChunkUtils; 20 | import org.jetbrains.annotations.NotNull; 21 | 22 | public abstract class AbstractProjectile extends Entity implements Projectile { 23 | protected final Entity shooter; 24 | protected PhysicsResult previousPhysicsResult; 25 | protected Pos previousPosition; 26 | protected boolean inBlock = false; 27 | 28 | public AbstractProjectile(EntityType type, Entity shooter) { 29 | super(type); 30 | this.shooter = shooter; 31 | } 32 | 33 | @Override 34 | public void tick(long time) { 35 | if (removed || inBlock) return; 36 | updatePosition(time); 37 | 38 | if (!callEntityCollision()) { 39 | callBlockCollision(); 40 | } 41 | } 42 | 43 | @Override 44 | public void shoot(Point from, double power, double spread) { 45 | var to = from.add(shooter.getPosition().direction()); 46 | shoot(from, to, power, spread); 47 | } 48 | 49 | protected PhysicsResult computePhysics(@NotNull Pos entityPosition, @NotNull Vec currentVelocity, @NotNull Block.Getter blockGetter, @NotNull Aerodynamics aerodynamics) { 50 | var newVelocity = updateVelocity(entityPosition, currentVelocity, blockGetter, aerodynamics, true, false, onGround, false); 51 | 52 | var newPhysicsResult = CollisionUtils.handlePhysics( 53 | blockGetter, 54 | this.boundingBox, 55 | entityPosition, newVelocity, 56 | previousPhysicsResult, true 57 | ); 58 | 59 | previousPhysicsResult = newPhysicsResult; 60 | return newPhysicsResult; 61 | } 62 | 63 | @Override 64 | protected void movementTick() { 65 | this.gravityTickCount = onGround ? 0 : gravityTickCount + 1; 66 | if (vehicle != null) return; 67 | 68 | this.previousPosition = position; 69 | final Block.Getter chunkCache = new ChunkCache(instance, currentChunk, Block.STONE); 70 | PhysicsResult result = computePhysics( 71 | position, velocity.div(ServerFlag.SERVER_TICKS_PER_SECOND), 72 | chunkCache, getAerodynamics()); 73 | 74 | Chunk finalChunk = ChunkUtils.retrieve(instance, currentChunk, result.newPosition()); 75 | if (!ChunkUtils.isLoaded(finalChunk)) return; 76 | 77 | onGround = result.isOnGround(); 78 | 79 | if (!result.hasCollision()) { 80 | velocity = previousPhysicsResult.newVelocity().mul(ServerFlag.SERVER_TICKS_PER_SECOND).mul(0.99); 81 | } 82 | 83 | refreshPosition(result.newPosition(), true, false); 84 | if (hasVelocity()) sendPacketToViewers(getVelocityPacket()); 85 | } 86 | 87 | protected void callBlockCollision() { 88 | if (previousPhysicsResult.hasCollision()) { 89 | Block hitBlock = null; 90 | Point hitPoint = null; 91 | if (previousPhysicsResult.collisionShapes()[0] instanceof ShapeImpl) { 92 | hitBlock = instance.getBlock(previousPhysicsResult.collisionPoints()[0].sub(0, Vec.EPSILON, 0), Block.Getter.Condition.TYPE); 93 | hitPoint = previousPhysicsResult.collisionPoints()[0]; 94 | } 95 | if (previousPhysicsResult.collisionShapes()[1] instanceof ShapeImpl) { 96 | hitBlock = instance.getBlock(previousPhysicsResult.collisionPoints()[1].sub(0, Vec.EPSILON, 0), Block.Getter.Condition.TYPE); 97 | hitPoint = previousPhysicsResult.collisionPoints()[1]; 98 | } 99 | if (previousPhysicsResult.collisionShapes()[2] instanceof ShapeImpl) { 100 | hitBlock = instance.getBlock(previousPhysicsResult.collisionPoints()[2].sub(0, Vec.EPSILON, 0), Block.Getter.Condition.TYPE); 101 | hitPoint = previousPhysicsResult.collisionPoints()[2]; 102 | } 103 | 104 | if (hitBlock == null) return; 105 | handleBlockCollision(hitBlock, hitPoint, previousPosition); 106 | } 107 | } 108 | 109 | protected void callBlockCollisionEvent(@NotNull Pos pos, Block hitBlock) { 110 | var e = new ProjectileCollideWithBlockEvent(this, pos, hitBlock); 111 | EventDispatcher.call(e); 112 | } 113 | 114 | protected boolean callEntityCollisionEvent(@NotNull Pos pos, @NotNull Entity entity) { 115 | ProjectileCollideWithEntityEvent e = new ProjectileCollideWithEntityEvent(this, pos, entity); 116 | EventDispatcher.call(e); 117 | if (!e.isCancelled()) { 118 | remove(); 119 | return true; 120 | } 121 | 122 | return false; 123 | } 124 | 125 | protected boolean callEntityCollision() { 126 | return callEntityCollision(boundingBox); 127 | } 128 | 129 | protected boolean callEntityCollision(BoundingBox boundingBox) { 130 | if (previousPhysicsResult == null) return false; 131 | var diff = previousPhysicsResult.newPosition().sub(previousPosition).asVec(); 132 | 133 | var collidedEntities = CollisionUtils.checkEntityCollisions(instance, boundingBox, previousPosition, diff, diff.length(), 134 | entity -> entity != shooter && entity != this, previousPhysicsResult); 135 | 136 | var arr = collidedEntities.stream().sorted().toList(); 137 | if (!arr.isEmpty()) { 138 | for (var collision : arr) { 139 | if (handleEntityCollision(collision, previousPhysicsResult.newPosition(), previousPosition)) { 140 | return true; 141 | } 142 | } 143 | } 144 | 145 | return false; 146 | } 147 | 148 | protected void updatePosition(long time) { 149 | if (instance == null || isRemoved() || !ChunkUtils.isLoaded(currentChunk)) return; 150 | 151 | movementTick(); 152 | super.update(time); 153 | EventDispatcher.call(new EntityTickEvent(this)); 154 | } 155 | 156 | protected void handleBlockCollision(Block hitBlock, Point hitPos, Pos posBefore) { 157 | velocity = Vec.ZERO; 158 | setNoGravity(true); 159 | inBlock = true; 160 | 161 | // if the value is zero, it will be unlit. If the value is more than 0.01, there will be noticeable pitch change visually 162 | position = new Pos(hitPos.x(), hitPos.y(), hitPos.z(), posBefore.yaw(), posBefore.pitch()); 163 | MinecraftServer.getSchedulerManager().scheduleNextTick(this::synchronizePosition); // required as in rare situations there will be a slight disagreement with the client and server on if it hit or not | also scheduling next tick so it doesn't jump to the hit position until it has actually hit 164 | 165 | callBlockCollisionEvent(Pos.fromPoint(hitPos), hitBlock); 166 | 167 | BlockHandler blockHandler = hitBlock.handler(); 168 | if (blockHandler == null) return; 169 | blockHandler.onTouch(new BlockHandler.Touch(hitBlock, instance, hitPos, this)); 170 | } 171 | 172 | /** 173 | * Handle entity collision 174 | * @param result the entity that was hit 175 | * @param hitPos the position where the entity was hit 176 | * @param posBefore the position before the collision 177 | * @return true if block collisions should be ignored (i.e. the entity was removed while handling entity collision during the same tick) 178 | */ 179 | protected boolean handleEntityCollision(EntityCollisionResult result, Point hitPos, Pos posBefore) { 180 | return callEntityCollisionEvent(Pos.fromPoint(hitPos), result.entity()); 181 | } 182 | 183 | protected abstract @NotNull Vec updateVelocity(@NotNull Pos entityPosition, @NotNull Vec currentVelocity, @NotNull Block.@NotNull Getter blockGetter, @NotNull Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity); 184 | } 185 | -------------------------------------------------------------------------------- /src/main/java/ca/atlasengine/projectiles/BowModule.java: -------------------------------------------------------------------------------- 1 | package ca.atlasengine.projectiles; 2 | 3 | import ca.atlasengine.projectiles.entities.ArrowProjectile; 4 | import net.kyori.adventure.sound.Sound; 5 | import net.minestom.server.coordinate.Pos; 6 | import net.minestom.server.entity.Player; 7 | import net.minestom.server.event.EventNode; 8 | import net.minestom.server.event.item.PlayerBeginItemUseEvent; 9 | import net.minestom.server.event.item.PlayerCancelItemUseEvent; 10 | import net.minestom.server.event.trait.EntityEvent; 11 | import net.minestom.server.item.ItemStack; 12 | import net.minestom.server.item.Material; 13 | import net.minestom.server.sound.SoundEvent; 14 | import net.minestom.server.tag.Tag; 15 | import org.jetbrains.annotations.NotNull; 16 | 17 | import java.util.concurrent.ThreadLocalRandom; 18 | import java.util.function.BiFunction; 19 | 20 | // https://gist.github.com/hapily04/82fe9bdd6ddd757664701ba2f45ac474 21 | public class BowModule { 22 | private static final Tag CHARGE_SINCE_TAG = Tag.Long("bow_charge_since").defaultValue(Long.MAX_VALUE); 23 | private static final Tag BOW_POWER = Tag.Double("bow_power").defaultValue(0.0); 24 | 25 | public BowModule(@NotNull EventNode node, BiFunction arrowSupplier) { 26 | node.addListener(PlayerBeginItemUseEvent.class, event -> { 27 | if (event.getItemStack().material() != Material.BOW) return; 28 | event.getPlayer().setTag(CHARGE_SINCE_TAG, System.currentTimeMillis()); 29 | }); 30 | node.addListener(PlayerCancelItemUseEvent.class, event -> { 31 | if (event.getItemStack().material() != Material.BOW) return; 32 | Player player = event.getPlayer(); 33 | long duration = System.currentTimeMillis()-player.getTag(CHARGE_SINCE_TAG); 34 | double power = getPower(duration); 35 | 36 | if (power < 0.1) return; 37 | event.getPlayer().setTag(BOW_POWER, power); 38 | 39 | var projectile = arrowSupplier.apply(player, event.getItemStack()); 40 | if (projectile instanceof ArrowProjectile arrow && power == 1) arrow.setCritical(true); 41 | 42 | Pos shootPosition = player.getPosition().add(0, player.getEyeHeight()-0.1, 0); 43 | projectile.shoot(shootPosition.asVec(), power*3, 1f); // this method already sets the instance 44 | player.getInstance().playSound(Sound.sound(SoundEvent.ENTITY_ARROW_SHOOT, Sound.Source.PLAYER, 1f, getRandomPitchFromPower(power)), player); 45 | }); 46 | } 47 | 48 | private double getPower(long duration) { 49 | double secs = duration/1000.0; 50 | double pow = (secs * secs + secs * 2.0) / 3.0; 51 | if (pow > 1) { 52 | pow = 1; 53 | } 54 | return pow; 55 | } 56 | 57 | private float getRandomPitchFromPower(double power) { 58 | return (float) (1.0f / (ThreadLocalRandom.current().nextFloat() * 0.4f + 1.2f) + power * 0.5f); 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/ca/atlasengine/projectiles/Projectile.java: -------------------------------------------------------------------------------- 1 | package ca.atlasengine.projectiles; 2 | 3 | import net.minestom.server.coordinate.Point; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public interface Projectile { 7 | void shoot(@NotNull Point from, double power, double spread); 8 | void shoot(@NotNull Point from, @NotNull Point to, double power, double spread); 9 | } -------------------------------------------------------------------------------- /src/main/java/ca/atlasengine/projectiles/entities/ArrowProjectile.java: -------------------------------------------------------------------------------- 1 | package ca.atlasengine.projectiles.entities; 2 | 3 | import ca.atlasengine.projectiles.AbstractProjectile; 4 | import net.minestom.server.ServerFlag; 5 | import net.minestom.server.collision.Aerodynamics; 6 | import net.minestom.server.collision.BoundingBox; 7 | import net.minestom.server.coordinate.Point; 8 | import net.minestom.server.coordinate.Pos; 9 | import net.minestom.server.coordinate.Vec; 10 | import net.minestom.server.entity.Entity; 11 | import net.minestom.server.entity.EntityType; 12 | import net.minestom.server.entity.metadata.projectile.AbstractArrowMeta; 13 | import net.minestom.server.entity.metadata.projectile.ProjectileMeta; 14 | import net.minestom.server.event.EventDispatcher; 15 | import net.minestom.server.event.entity.EntityShootEvent; 16 | import net.minestom.server.instance.block.Block; 17 | import org.jetbrains.annotations.NotNull; 18 | 19 | import java.util.Random; 20 | import java.util.concurrent.ThreadLocalRandom; 21 | 22 | // https://gist.github.com/hapily04/a463cbed41d2cfba04a58ecc62fa61f9 23 | public class ArrowProjectile extends AbstractProjectile { 24 | private static final BoundingBox SMALL_BOUNDING_BOX = new BoundingBox(0.01, 0.01, 0.01); 25 | private static final BoundingBox REGULAR_BOUNDING_BOX = EntityType.ARROW.registry().boundingBox(); 26 | 27 | private boolean critical = false; 28 | private boolean firstTick = true; 29 | 30 | public boolean isCritical() { 31 | return critical; 32 | } 33 | 34 | public void setCritical(boolean critical) { 35 | this.critical = critical; 36 | if (getEntityMeta() instanceof AbstractArrowMeta arrowMeta) { 37 | arrowMeta.setCritical(true); 38 | } 39 | } 40 | 41 | public ArrowProjectile(EntityType type, Entity shooter) { 42 | super(type, shooter); 43 | setup(); 44 | this.setBoundingBox(SMALL_BOUNDING_BOX); 45 | } 46 | 47 | private void setup() { 48 | this.collidesWithEntities = false; 49 | if (getEntityMeta() instanceof ProjectileMeta projectileMeta) { 50 | projectileMeta.setShooter(this.shooter); 51 | } 52 | } 53 | 54 | @Override 55 | public void tick(long time) { 56 | if (removed || inBlock) return; 57 | 58 | final Pos posBefore = getPosition(); 59 | updatePosition(time); 60 | final Pos posNow = getPosition(); 61 | 62 | Vec diff = Vec.fromPoint(posNow.sub(posBefore)); 63 | float yaw = (float) Math.toDegrees(Math.atan2(diff.x(), diff.z())); 64 | float pitch = (float) Math.toDegrees(Math.atan2(diff.y(), Math.sqrt(diff.x() * diff.x() + diff.z() * diff.z()))); 65 | this.position = posNow.withView(yaw, pitch); 66 | 67 | if (firstTick) { 68 | firstTick = false; 69 | setView(yaw, pitch); 70 | } 71 | 72 | if (!callEntityCollision(REGULAR_BOUNDING_BOX)) 73 | callBlockCollision(); 74 | } 75 | 76 | public void shoot(@NotNull Point from, @NotNull Point to, double power, double spread) { 77 | var instance = shooter.getInstance(); 78 | if (instance == null) return; 79 | 80 | float yaw = -shooter.getPosition().yaw(); 81 | float originalPitch = -shooter.getPosition().pitch(); 82 | float pitch = originalPitch - 35f; 83 | 84 | double pitchDiff = pitch - 45; 85 | if (pitchDiff == 0) pitchDiff = 0.0001; 86 | double pitchAdjust = pitchDiff * 0.002145329238474369D; 87 | 88 | double dx = to.x() - from.x(); 89 | double dy = to.y() - from.y() + pitchAdjust; 90 | double dz = to.z() - from.z(); 91 | if (!hasNoGravity()) { 92 | final double xzLength = Math.sqrt(dx * dx + dz * dz); 93 | dy += xzLength * 0.20000000298023224D; 94 | } 95 | 96 | final double length = Math.sqrt(dx * dx + dy * dy + dz * dz); 97 | dx /= length; 98 | dy /= length; 99 | dz /= length; 100 | Random random = ThreadLocalRandom.current(); 101 | spread *= 0.007499999832361937D; 102 | dx += random.nextGaussian() * spread; 103 | dy += random.nextGaussian() * spread; 104 | dz += random.nextGaussian() * spread; 105 | 106 | final EntityShootEvent shootEvent = new EntityShootEvent(this.shooter, this, from, power, spread); 107 | EventDispatcher.call(shootEvent); 108 | if (shootEvent.isCancelled()) { 109 | remove(); 110 | return; 111 | } 112 | 113 | final double mul = ServerFlag.SERVER_TICKS_PER_SECOND * power; 114 | Vec v = new Vec(dx * mul, dy * mul * 0.9, dz * mul); 115 | 116 | this.setInstance(instance, new Pos(from.x(), from.y(), from.z(), yaw, originalPitch)).whenComplete((result, throwable) -> { 117 | if (throwable != null) { 118 | throwable.printStackTrace(); 119 | } else { 120 | synchronizePosition(); // initial synchronization, required to be 100% precise 121 | setVelocity(v); 122 | } 123 | }); 124 | } 125 | 126 | protected @NotNull Vec updateVelocity(@NotNull Pos entityPosition, @NotNull Vec currentVelocity, @NotNull Block.@NotNull Getter blockGetter, @NotNull Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity) { 127 | if (!positionChanged) { 128 | return entityFlying ? Vec.ZERO : new Vec(0.0, entityNoGravity ? 0.0 : -aerodynamics.gravity() * aerodynamics.verticalAirResistance(), 0.0); 129 | } else { 130 | double drag = entityOnGround ? blockGetter.getBlock(entityPosition.sub(0.0, 0.5000001, 0.0)).registry().friction() * aerodynamics.horizontalAirResistance() : aerodynamics.horizontalAirResistance(); 131 | double gravity = entityFlying ? 0.0 : aerodynamics.gravity(); 132 | double gravityDrag = entityFlying ? 0.6 : aerodynamics.verticalAirResistance(); 133 | double x = currentVelocity.x() * drag; 134 | double y = entityNoGravity ? currentVelocity.y() : (currentVelocity.y() - gravity) * gravityDrag; 135 | double z = currentVelocity.z() * drag; 136 | return new Vec(Math.abs(x) < 1.0E-6 ? 0.0 : x, Math.abs(y) < 1.0E-6 ? 0.0 : y, Math.abs(z) < 1.0E-6 ? 0.0 : z); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/ca/atlasengine/projectiles/entities/FireballProjectile.java: -------------------------------------------------------------------------------- 1 | package ca.atlasengine.projectiles.entities; 2 | 3 | import ca.atlasengine.projectiles.AbstractProjectile; 4 | import net.minestom.server.ServerFlag; 5 | import net.minestom.server.collision.Aerodynamics; 6 | import net.minestom.server.coordinate.Point; 7 | import net.minestom.server.coordinate.Pos; 8 | import net.minestom.server.coordinate.Vec; 9 | import net.minestom.server.entity.Entity; 10 | import net.minestom.server.entity.EntityType; 11 | import net.minestom.server.event.EventDispatcher; 12 | import net.minestom.server.event.entity.EntityShootEvent; 13 | import net.minestom.server.instance.block.Block; 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | import java.util.Random; 17 | import java.util.concurrent.ThreadLocalRandom; 18 | 19 | public class FireballProjectile extends AbstractProjectile { 20 | public FireballProjectile(EntityType type, Entity shooter) { 21 | super(type, shooter); 22 | this.setNoGravity(true); 23 | } 24 | 25 | @Override 26 | public void shoot(@NotNull Point from, @NotNull Point to, double power, double spread) { 27 | var instance = shooter.getInstance(); 28 | if (instance == null) return; 29 | 30 | float yaw = -shooter.getPosition().yaw(); 31 | float originalPitch = -shooter.getPosition().pitch(); 32 | 33 | double pitchDiff = originalPitch; 34 | if (pitchDiff == 0) pitchDiff = 0.0001; 35 | double pitchAdjust = pitchDiff * 0.002145329238474369D; 36 | 37 | double dx = to.x() - from.x(); 38 | double dy = to.y() - from.y() + pitchAdjust; 39 | double dz = to.z() - from.z(); 40 | if (!hasNoGravity()) { 41 | final double xzLength = Math.sqrt(dx * dx + dz * dz); 42 | dy += xzLength * 0.20000000298023224D; 43 | } 44 | 45 | final double length = Math.sqrt(dx * dx + dy * dy + dz * dz); 46 | dx /= length; 47 | dy /= length; 48 | dz /= length; 49 | Random random = ThreadLocalRandom.current(); 50 | spread *= 0.007499999832361937D; 51 | dx += random.nextGaussian() * spread; 52 | dy += random.nextGaussian() * spread; 53 | dz += random.nextGaussian() * spread; 54 | 55 | final EntityShootEvent shootEvent = new EntityShootEvent(this.shooter, this, from, power, spread); 56 | EventDispatcher.call(shootEvent); 57 | if (shootEvent.isCancelled()) { 58 | remove(); 59 | return; 60 | } 61 | 62 | final double mul = ServerFlag.SERVER_TICKS_PER_SECOND * power; 63 | Vec v = new Vec(dx * mul, dy * mul * 0.9, dz * mul); 64 | 65 | this.setInstance(instance, new Pos(from.x(), from.y() - this.boundingBox.height()/2, from.z(), yaw, originalPitch)).whenComplete((result, throwable) -> { 66 | if (throwable != null) { 67 | throwable.printStackTrace(); 68 | } else { 69 | synchronizePosition(); // initial synchronization, required to be 100% precise 70 | setVelocity(v); 71 | } 72 | }); 73 | } 74 | 75 | protected @NotNull Vec updateVelocity(@NotNull Pos entityPosition, @NotNull Vec currentVelocity, @NotNull Block.@NotNull Getter blockGetter, @NotNull Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity) { 76 | double x = currentVelocity.x(); 77 | double y = currentVelocity.y(); 78 | double z = currentVelocity.z(); 79 | return new Vec(Math.abs(x) < 1.0E-6 ? 0.0 : x, Math.abs(y) < 1.0E-6 ? 0.0 : y, Math.abs(z) < 1.0E-6 ? 0.0 : z); 80 | } 81 | } -------------------------------------------------------------------------------- /src/main/java/ca/atlasengine/projectiles/entities/FollowProjectile.java: -------------------------------------------------------------------------------- 1 | package ca.atlasengine.projectiles.entities; 2 | 3 | import ca.atlasengine.projectiles.AbstractProjectile; 4 | import net.minestom.server.ServerFlag; 5 | import net.minestom.server.collision.Aerodynamics; 6 | import net.minestom.server.coordinate.Point; 7 | import net.minestom.server.coordinate.Pos; 8 | import net.minestom.server.coordinate.Vec; 9 | import net.minestom.server.entity.Entity; 10 | import net.minestom.server.entity.EntityType; 11 | import net.minestom.server.event.EventDispatcher; 12 | import net.minestom.server.event.entity.EntityShootEvent; 13 | import net.minestom.server.instance.block.Block; 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | import java.util.Random; 17 | import java.util.concurrent.ThreadLocalRandom; 18 | 19 | public class FollowProjectile extends AbstractProjectile { 20 | private final Entity target; 21 | private final float attractionAcceleration; 22 | private final float attractionVelocity; 23 | 24 | private long ticks = 0; 25 | 26 | public FollowProjectile(EntityType type, Entity shooter, Entity target, float attractionVelocity, float attractionAcceleration) { 27 | super(type, shooter); 28 | setNoGravity(true); 29 | this.target = target; 30 | this.attractionVelocity = attractionVelocity; 31 | this.attractionAcceleration = attractionAcceleration; 32 | } 33 | 34 | @Override 35 | public void tick(long time) { 36 | super.tick(time); 37 | ticks++; 38 | } 39 | 40 | @Override 41 | public long getAliveTicks() { 42 | return ticks; 43 | } 44 | 45 | @Override 46 | public void shoot(@NotNull Point from, @NotNull Point to, double power, double spread) { 47 | var instance = shooter.getInstance(); 48 | if (instance == null) return; 49 | 50 | float yaw = -shooter.getPosition().yaw(); 51 | float originalPitch = -shooter.getPosition().pitch(); 52 | 53 | double pitchDiff = originalPitch - 45f; 54 | if (pitchDiff == 0) pitchDiff = 0.0001; 55 | double pitchAdjust = pitchDiff * 0.002145329238474369D; 56 | 57 | double dx = to.x() - from.x(); 58 | double dy = to.y() - from.y() + pitchAdjust; 59 | double dz = to.z() - from.z(); 60 | 61 | if (!hasNoGravity()) { 62 | final double xzLength = Math.sqrt(dx * dx + dz * dz); 63 | dy += xzLength * 0.20000000298023224D; 64 | } 65 | 66 | final double length = Math.sqrt(dx * dx + dy * dy + dz * dz); 67 | dx /= length; 68 | dy /= length; 69 | dz /= length; 70 | Random random = ThreadLocalRandom.current(); 71 | spread *= 0.007499999832361937D; 72 | dx += random.nextGaussian() * spread; 73 | dy += random.nextGaussian() * spread; 74 | dz += random.nextGaussian() * spread; 75 | 76 | final EntityShootEvent shootEvent = new EntityShootEvent(this.shooter, this, from, power, spread); 77 | EventDispatcher.call(shootEvent); 78 | if (shootEvent.isCancelled()) { 79 | remove(); 80 | return; 81 | } 82 | 83 | final double mul = ServerFlag.SERVER_TICKS_PER_SECOND * power; 84 | Vec v = new Vec(dx * mul, dy * mul * 0.9, dz * mul); 85 | 86 | this.setInstance(instance, new Pos(from.x(), from.y() - this.boundingBox.height()/2, from.z(), yaw, originalPitch)).whenComplete((result, throwable) -> { 87 | if (throwable != null) { 88 | throwable.printStackTrace(); 89 | } else { 90 | synchronizePosition(); // initial synchronization, required to be 100% precise 91 | setVelocity(v); 92 | } 93 | }); 94 | } 95 | 96 | protected @NotNull Vec updateVelocity(@NotNull Pos entityPosition, @NotNull Vec currentVelocity, @NotNull Block.@NotNull Getter blockGetter, @NotNull Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity) { 97 | Vec directionVector = entityPosition.sub(target.getPosition().add(0, target.getEyeHeight(), 0)).asVec().normalize().mul(attractionVelocity + attractionAcceleration * this.getAliveTicks()); 98 | 99 | double x = currentVelocity.x() - directionVector.x(); 100 | double y = currentVelocity.y() - directionVector.y(); 101 | double z = currentVelocity.z() - directionVector.z(); 102 | 103 | return new Vec(Math.abs(x) < 1.0E-6 ? 0.0 : x, Math.abs(y) < 1.0E-6 ? 0.0 : y, Math.abs(z) < 1.0E-6 ? 0.0 : z); 104 | } 105 | } -------------------------------------------------------------------------------- /src/main/java/ca/atlasengine/projectiles/entities/ThrownItemProjectile.java: -------------------------------------------------------------------------------- 1 | package ca.atlasengine.projectiles.entities; 2 | 3 | import ca.atlasengine.projectiles.AbstractProjectile; 4 | import net.minestom.server.ServerFlag; 5 | import net.minestom.server.collision.Aerodynamics; 6 | import net.minestom.server.coordinate.Point; 7 | import net.minestom.server.coordinate.Pos; 8 | import net.minestom.server.coordinate.Vec; 9 | import net.minestom.server.entity.Entity; 10 | import net.minestom.server.entity.EntityType; 11 | import net.minestom.server.event.EventDispatcher; 12 | import net.minestom.server.event.entity.EntityShootEvent; 13 | import net.minestom.server.instance.block.Block; 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | import java.util.Random; 17 | import java.util.concurrent.ThreadLocalRandom; 18 | 19 | public class ThrownItemProjectile extends AbstractProjectile { 20 | public ThrownItemProjectile(EntityType type, Entity shooter) { 21 | super(type, shooter); 22 | } 23 | 24 | @Override 25 | public void shoot(@NotNull Point from, @NotNull Point to, double power, double spread) { 26 | var instance = shooter.getInstance(); 27 | if (instance == null) return; 28 | 29 | float yaw = -shooter.getPosition().yaw(); 30 | float originalPitch = -shooter.getPosition().pitch(); 31 | 32 | double pitchDiff = originalPitch - 45f; 33 | if (pitchDiff == 0) pitchDiff = 0.0001; 34 | double pitchAdjust = pitchDiff * 0.002145329238474369D; 35 | 36 | double dx = to.x() - from.x(); 37 | double dy = to.y() - from.y() + pitchAdjust; 38 | double dz = to.z() - from.z(); 39 | 40 | if (!hasNoGravity()) { 41 | final double xzLength = Math.sqrt(dx * dx + dz * dz); 42 | dy += xzLength * 0.20000000298023224D; 43 | } 44 | 45 | final double length = Math.sqrt(dx * dx + dy * dy + dz * dz); 46 | dx /= length; 47 | dy /= length; 48 | dz /= length; 49 | Random random = ThreadLocalRandom.current(); 50 | spread *= 0.007499999832361937D; 51 | dx += random.nextGaussian() * spread; 52 | dy += random.nextGaussian() * spread; 53 | dz += random.nextGaussian() * spread; 54 | 55 | final EntityShootEvent shootEvent = new EntityShootEvent(this.shooter, this, from, power, spread); 56 | EventDispatcher.call(shootEvent); 57 | if (shootEvent.isCancelled()) { 58 | remove(); 59 | return; 60 | } 61 | 62 | final double mul = ServerFlag.SERVER_TICKS_PER_SECOND * power; 63 | Vec v = new Vec(dx * mul, dy * mul * 0.9, dz * mul); 64 | 65 | this.setInstance(instance, new Pos(from.x(), from.y() - this.boundingBox.height()/2, from.z(), yaw, originalPitch)).whenComplete((result, throwable) -> { 66 | if (throwable != null) { 67 | throwable.printStackTrace(); 68 | } else { 69 | synchronizePosition(); // initial synchronization, required to be 100% precise 70 | setVelocity(v); 71 | } 72 | }); 73 | } 74 | 75 | protected @NotNull Vec updateVelocity(@NotNull Pos entityPosition, @NotNull Vec currentVelocity, @NotNull Block.@NotNull Getter blockGetter, @NotNull Aerodynamics aerodynamics, boolean positionChanged, boolean entityFlying, boolean entityOnGround, boolean entityNoGravity) { 76 | double x = currentVelocity.x(); 77 | double y = currentVelocity.y() - 0.03; 78 | double z = currentVelocity.z(); 79 | return new Vec(Math.abs(x) < 1.0E-6 ? 0.0 : x, Math.abs(y) < 1.0E-6 ? 0.0 : y, Math.abs(z) < 1.0E-6 ? 0.0 : z); 80 | } 81 | } -------------------------------------------------------------------------------- /src/test/java/Main.java: -------------------------------------------------------------------------------- 1 | import ca.atlasengine.projectiles.BowModule; 2 | import ca.atlasengine.projectiles.entities.ArrowProjectile; 3 | import ca.atlasengine.projectiles.entities.FollowProjectile; 4 | import net.kyori.adventure.text.Component; 5 | import net.kyori.adventure.text.format.NamedTextColor; 6 | import net.kyori.adventure.text.format.TextColor; 7 | import net.minestom.server.MinecraftServer; 8 | import net.minestom.server.adventure.audience.Audiences; 9 | import net.minestom.server.command.CommandManager; 10 | import net.minestom.server.coordinate.Pos; 11 | import net.minestom.server.entity.*; 12 | import net.minestom.server.event.GlobalEventHandler; 13 | import net.minestom.server.event.player.*; 14 | import net.minestom.server.event.server.ServerTickMonitorEvent; 15 | import net.minestom.server.extras.lan.OpenToLAN; 16 | import net.minestom.server.instance.InstanceContainer; 17 | import net.minestom.server.instance.InstanceManager; 18 | import net.minestom.server.instance.LightingChunk; 19 | import net.minestom.server.instance.block.Block; 20 | import net.minestom.server.item.ItemComponent; 21 | import net.minestom.server.item.ItemStack; 22 | import net.minestom.server.item.Material; 23 | import net.minestom.server.monitoring.TickMonitor; 24 | import net.minestom.server.timer.TaskSchedule; 25 | import net.minestom.server.utils.MathUtils; 26 | import net.minestom.server.world.DimensionType; 27 | 28 | import java.util.Collection; 29 | import java.util.List; 30 | import java.util.concurrent.atomic.AtomicReference; 31 | 32 | public class Main { 33 | public static void main(String[] args) { 34 | MinecraftServer minecraftServer = MinecraftServer.init(); 35 | 36 | InstanceManager instanceManager = MinecraftServer.getInstanceManager(); 37 | InstanceContainer lobby = instanceManager.createInstanceContainer(DimensionType.OVERWORLD); 38 | lobby.setChunkSupplier(LightingChunk::new); 39 | lobby.enableAutoChunkLoad(true); 40 | lobby.setGenerator(unit -> unit.modifier().fillHeight(0, 1, Block.STONE)); 41 | lobby.setTimeRate(0); 42 | instanceManager.registerInstance(lobby); 43 | 44 | Entity zombie = new LivingEntity(EntityType.ZOMBIE); 45 | zombie.setInstance(lobby, new Pos(0.5, 16, 0.5)); 46 | 47 | // Commands 48 | { 49 | CommandManager manager = MinecraftServer.getCommandManager(); 50 | manager.setUnknownCommandCallback((sender, c) -> sender.sendMessage("Command not found.")); 51 | } 52 | 53 | // Events 54 | { 55 | GlobalEventHandler handler = MinecraftServer.getGlobalEventHandler(); 56 | 57 | // Login 58 | handler.addListener(AsyncPlayerConfigurationEvent.class, event -> { 59 | final Player player = event.getPlayer(); 60 | player.setRespawnPoint(new Pos(0.5, 16, 0.5)); 61 | event.setSpawningInstance(lobby); 62 | }); 63 | 64 | handler.addListener(PlayerSpawnEvent.class, event -> { 65 | if (!event.isFirstSpawn()) return; 66 | final Player player = event.getPlayer(); 67 | 68 | var bow = ItemStack.builder(Material.BOW) 69 | .set(ItemComponent.CHARGED_PROJECTILES, List.of(ItemStack.of(Material.ARROW))) 70 | .build(); 71 | 72 | player.setItemInMainHand(bow); 73 | 74 | player.setGameMode(GameMode.CREATIVE); 75 | player.setEnableRespawnScreen(false); 76 | player.getInventory().addItemStack(ItemStack.of(Material.ARROW, 64)); 77 | player.getInventory().addItemStack(ItemStack.of(Material.FIRE_CHARGE, 64)); 78 | 79 | Audiences.all().sendMessage(Component.text( 80 | player.getUsername() + " has joined", 81 | NamedTextColor.GREEN 82 | )); 83 | 84 | player.eventNode().addListener(PlayerUseItemEvent.class, e -> { 85 | if (e.getHand() != PlayerHand.MAIN) return; 86 | if (e.getItemStack().material() == Material.FIRE_CHARGE) { 87 | new FollowProjectile(EntityType.SNOWBALL, e.getPlayer(), e.getPlayer(), 0.04f, 0.001f).shoot(e.getPlayer().getPosition().add(0, e.getPlayer().getEyeHeight(), 0).asVec(), 1, 1); 88 | } 89 | }); 90 | 91 | new BowModule(player.eventNode(), (p, i) -> new ArrowProjectile(EntityType.ARROW, p)); 92 | }); 93 | 94 | // Logout 95 | handler.addListener(PlayerDisconnectEvent.class, event -> Audiences.all().sendMessage(Component.text( 96 | event.getPlayer().getUsername() + " has left", 97 | NamedTextColor.RED 98 | ))); 99 | 100 | // Chat 101 | handler.addListener(PlayerChatEvent.class, chatEvent -> { 102 | chatEvent.setFormattedMessage(Component.text(chatEvent.getEntity().getUsername()) 103 | .append(Component.text(" | ", NamedTextColor.DARK_GRAY) 104 | .append(Component.text(chatEvent.getRawMessage(), NamedTextColor.WHITE)))); 105 | }); 106 | 107 | // Monitoring 108 | AtomicReference lastTick = new AtomicReference<>(); 109 | handler.addListener(ServerTickMonitorEvent.class, event -> lastTick.set(event.getTickMonitor())); 110 | 111 | // Header/footer 112 | MinecraftServer.getSchedulerManager().scheduleTask(() -> { 113 | Collection players = MinecraftServer.getConnectionManager().getOnlinePlayers(); 114 | if (players.isEmpty()) return; 115 | 116 | final Runtime runtime = Runtime.getRuntime(); 117 | final TickMonitor tickMonitor = lastTick.get(); 118 | final long ramUsage = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024; 119 | 120 | final Component header = Component.newline() 121 | .append(Component.text("RAM USAGE: " + ramUsage + " MB", NamedTextColor.GRAY).append(Component.newline()) 122 | .append(Component.text("TICK TIME: " + MathUtils.round(tickMonitor.getTickTime(), 2) + "ms", NamedTextColor.GRAY))).append(Component.newline()); 123 | 124 | final Component footer = Component.newline() 125 | .append(Component.text(" Projectile Demo ") 126 | .color(TextColor.color(57, 200, 73)) 127 | .append(Component.newline())); 128 | 129 | Audiences.players().sendPlayerListHeaderAndFooter(header, footer); 130 | }, TaskSchedule.tick(10), TaskSchedule.tick(10)); 131 | } 132 | 133 | OpenToLAN.open(); 134 | 135 | minecraftServer.start("0.0.0.0", 25565); 136 | System.out.println("Server startup done!"); 137 | } 138 | } 139 | --------------------------------------------------------------------------------