DoubleJumpLib
一个适用于 Minecraft 1.21.8+ 的简单数据包库,提供空中二段跳检测功能。
如果遇到错误、需要故障排除或帮助,请在 Discord 上联系 @sadanmastermode,或在 GitHub 上提交 Issue 请求。
功能特性
- 自动检测用户在空中按下空格键的情况,并激活相应的函数标签(function tag)。
- 确保用户在初始跳跃后先释放再按下空格键,从而避免在初始跳跃输入时触发任何调用。
- 支持无限次的空中空格输入,但默认每次跳跃最多只允许 1 次。
- 易于配置,并通过包内的大量错误处理机制提高稳定性。
- 兼容多人游戏环境。
- 卸载非常简单,只需通过单次函数调用即可移除所有的记分板和存储数据。
- 包含精简版的二段跳检测代码,位于
__base_code__ 命名空间下。
文档
下载
要下载该数据包,您可以点击页面顶部的下载按钮,或者访问 Releases 标签页。这将下载数据包文件。下载完成后,您可以解压并将其放入世界文件夹中的 datapacks 文件夹中以导入该库。
请注意,该数据包仅在 1.21.8 及更高版本中经过测试。在较低版本中可能会导致问题,请谨慎使用。
安装
当数据包已放入您的世界中时,您必须运行 /function doublejumplib:__install__。这将正确设置包内的所有记分板配置。
如果您尝试在未安装的情况下运行函数,将会出现错误,且数据包无法正常运行。
添加回调函数
DoubleJumpLib 可以通过将各种 API 端点设置为所需的值来进行配置。这些端点的名称由一对下划线包围,例如 __install__ 或 __help__。请勿有意运行任何不带双下划线的函数。
API 端点的一个示例是函数回调。当检测到用户在空气中执行跳跃输入时,此数据包会调用一个函数标签。该函数标签位于 #doublejumplib:__on_double_jump__,相对路径为 doublejumplib/tags/function/__on_double_jump__.json。将您数据包中的函数添加到此标签中,以允许数据包运行它。
在回调函数内部,执行者和位置会被设置为执行二段跳的玩家。此外,为了查找当前的二段跳次数(即当前跳跃中已经进行了多少次二段跳),它会设置玩家的 djl.jumpCount 分数。
例如,若要检查玩家在当前跳跃中是否已经二段跳了两次,您可以使用:execute if score @s djl.jumpCount matches 2 run say I jumped twice!。
若要测试数据包是否正确安装,您可以尝试将 doublejumplib:__test__ 添加到函数标签中。如果一切安装正确,那么在空中跳跃时会在聊天栏发送一条 tellraw 消息,提供有关跳跃的一些信息。请勿从聊天栏运行此函数,它是设计用于通过函数标签运行的。
配置库
有两个主要变量可以通过记分板进行更改:
| 玩家名 |
目标 (Objective) |
功能 |
默认值 |
| $djl.maxJumps |
djl.jumpCount |
管理玩家在触地前可以执行多少次二段跳 |
1 |
| $djl.enabled |
djl.debug |
管理数据包是否正在 ticking,进而决定数据包是否启用。 |
1 (已启用) |
这些是全局设置,意味着任何其他使用 DoubleJumpLib 的数据包也将使用相同的设置。
重要提示:
为了保持跨数据包的兼容性,建议检查玩家当前的 djl.jumpCount 以确定玩家处于第几次跳跃,以防其他数据包增加了限制。
例如,如果您的数据包旨在仅在跳跃期间激活一次,并通过 gravity 属性给予玩家向上的动量增益,而另一个数据包将 djl.maxJumps 限制增加到 3,那么您的数据包将无法按预期工作。因此,在您自己的数据包中至关重要的一点是在反转重力之前,通过 execute if score @s djl.jumpCount matches 1 检查玩家是否处于当前跳跃的第一次二段跳,除非您希望其他数据包允许玩家在每次跳跃中违背重力 3 次而不是 1 次。
有 4 个主要的可调用函数端点供您使用。
| 函数名称 |
用途 |
__help__ |
显示指向此处 README 的链接。 |
__install__ |
通过设置记分板等,将库安装到世界中。 |
__uninstall__ |
通过移除所创建的记分板和存储,卸载库。 |
__test__ |
设计用于在函数标签中使用,这是一个简单的测试文件,以确保库能正常工作。 |
将库添加到您的数据包中
要将库添加到您的数据包中,只需将 doublejumplib 命名空间复制粘贴到您的 data 文件夹中。同时,请确保在 minecraft/tags/function 目录下的 tick.json 中添加以下条目:"doublejumplib:internal/_tick"
本数据包采用 MIT 许可证,这意味着几乎没有任何限制。如果您在数据包中使用了此内容,若能给予适当的署名,我们将不胜感激。
如果您想在不包含所有库冗余代码的情况下使用此数据包的主要逻辑,可以使用 __base_code__ 命名空间,其中包含一个 README.md 文件,提供了关于该命名空间内容的信息。它主要包含用于实现二段跳检测的精简版代码。
工作原理
这使用了 type_specific 谓词中的“新” input 谓词,以及 on_ground 标志。
主要逻辑如下。您可以在玩家刚离开地面时(使用 on_ground 标志)标记玩家,并在他们落地时取消标记。同样,只要他们按住空格键就标记他们(当然,松开时取消标记)。
假设玩家同时拥有这两个标签(处于空中且按住跳跃键),则在上一刻检查以下内容:
- 如果他们在上一刻既处于空中又没有按住跳跃键,那么他们执行了二段跳(这是因为他们在首次跳跃后释放了跳跃输入)
- 如果他们在上一刻处于空中且按住跳跃键,则不执行任何操作(这可能是原始的跳跃输入)
- 当然,如果他们上一刻什么都没做(不在空中且未按住空格键),那么他们只是刚开始跳跃,无需进行额外处理
这是该数据包的基本逻辑。实际实现略有不同,但我已尽量记录大部分内容并保持代码可读性。如果您直接联系我,我可以对此做更详细的解释。
贡献指南
尽管这是一个非常简单的库,但我始终欢迎贡献。无论是优化还是逻辑改进,请随时提交 Pull Request 或通过 Discord 与我联系讨论此库。
许可证
根据 MIT 许可证,只要我为原作署名,您被允许重新分发、修改和使用 DoubleJumpLib。
DoubleJumpLib
A simple Minecraft datapack library which has double jump detection for Minecraft 1.21.8+
For any errors, troubleshooting or help, please contact @sadanmastermode on Discord, or open an issue request on GitHub
Features
- Automatically detects when the user presses space midair, and activates a function tag.
- Makes sure the user first releases and then presses space after the initial jump so that nothing is called on the initial jump input.
- Supports unlimited midair space inputs, though is defaulted at a max of 1 every jump.
- Easily configurable with a lot of error handling through the pack
- Multiplayer compatible
- Very simple to uninstall, removing all scoreboards and storages through a single function call.
- Stripped-down code for double-jump detection is included too under the
__base_code__ namespace
Documentation
Downloading
To download the pack, you can click on the download button near the top of the page, or visit the releases tab. This will download the pack. Once downloaded, you can unzip it and put it in your datapacks folder in your world folder to import the library.
Note that the pack has only been tested in 1.21.8 and higher. This pack may break in lower versions, please exercise caution
Installing
When the pack is in your world, you must run /function doublejumplib:__install__. This will properly set up all scoreboards and configs in the pack.
If you try to run functions without installing the pack, errors will come up and the pack won't run correctly.
Adding a callback
DoubleJumpLib can be configured by setting a variety of API endpoints to values you wish. These endpoints are denoted by a pair of underscores around the name, like __install__ or __help__. Do not intentionally run any functions without the pair of double underscores.
One such example of an API endpoint is the function callback. This pack will call a function tag when it detects a user has pressed a jump input in the air. The function tag is located at #doublejumplib:__on_double_jump__, and the relative path would be found at doublejumplib/tags/function/__on_double_jump__.json. Add a function from your pack into this tag to allow the pack to run it.
Inside of a callback function, the executor and position is set to the player who double-jumped. Additionally, to find the current double-jump number (how many times they've double-jumped in the current jump), it is set the player's djl.jumpCount score.
For example, to check if the player has double-jumped twice in the current jump, you can use: execute if score @s djl.jumpCount matches 2 run say I jumped twice!.
To test if the pack was installed correctly, you can try adding doublejumplib:__test__ to the function tag. If you properly installed everything, then jumping midair will send a tellraw message in chat giving some info about the jump. Do not run this function from chat, it is intended to be ran through the function tag.
Configuring the library
There are 2 main variables you can change, via scoreboards:
| Playername |
Objective |
Function |
Default |
| $djl.maxJumps |
djl.jumpCount |
Manages how many double-jumps the player can perform in a single jump before touching the ground |
1 |
| $djl.enabled |
djl.debug |
Manages whether the pack is ticking, and therefor whether the pack is enabled. |
1 (enabled) |
These are global settings, meaning any other pack using DoubleJumpLib will use these same settings too.
IMPORTANT:
To maintain compatibility across packs, it is recommended to add checks for the player's current djl.jumpCount to see what jump the player is on, in case another pack increases the limit.
For example, if your pack is intended to only activate once in a jump and gives the player a boost of upwards momentum via the gravity attribute, and another pack increases the djl.maxJumps limit to 3, then your pack will not work as intended. It is crucial in your pack to check if the player is on their first double-jump of the current jump via execute if score @s djl.jumpCount matches 1 before inversing their gravity, unless you want the other pack to allow the player to defy gravity 3 times a jump instead of 1.
There are 4 main callable function endpoints you can use.
| Function Name |
Use |
__help__ |
Displays the link to the README here. |
__install__ |
Installs the library to the world by setting up the scoreboards and all. |
__uninstall__ |
Uninstalls the library by removing all the scoreboards and storages that were made. |
__test__ |
Intended to be used in the function tag, this is a simple testing file to make sure the library works. |
Adding the library to your pack
To add the library to your pack, simply copy-paste the doublejumplib namespace into your data folder. Make sure you also add the following entry into the tick.json under the minecraft/tags/function directory: "doublejumplib:internal/_tick"
This pack is under the MIT license, which means theres almost no restrictions. It would be very much appreciated for proper credit if you do use this in your pack.
If you do want to use the main logic of this pack without all the library-slop, there is the __base_code__ namespace which holds a README.md containing info about the contents of this namespace. It mostly just contains the stripped-down code for a double-jump detection for you to implement.
How does it work?
This uses the 'new' input predicate for the type_specific predicate, as well as the on_ground flag.
The main logic is as follows. You can 'tag' the player when they're first off the ground (using the on_ground flag) and untag them when they land on the ground. Also tag them whenever they're holding space (and of course remove it when they're not)
Assuming the player has both tags (is off the ground and is holding jump), then check for some things in the previous tick:
- If they were both off the ground and NOT holding jump, then they double jumped (this is because they released the jump input after jumping first)
- If they were off the ground and holding jump, then you don't do anything (this could be the original input for jumping)
- And of course if they weren't doing anything (not off the ground and not holding space) then they just started jumping and you don't need to do anything
This is the basic thinking for the pack. The implementation was a bit different, though I tried to document most of it and keep it all readable. I can always explain this more if you contact me directly.
Contributing
Although this is a very very simple library, I am always welcome to contribution. Whether it be optimizations or logic improvements, please feel free to open a pull request or contact me on Discord about this library.
License
As per the MIT License, you are allowed to redistribute, modify and use DoubleJumpLib as long as I am credited for the original work.
评论 0
登录后参与评分
还没有评论,来抢沙发吧