完整文档请参见 此处。
数据包库 (Datapack library)
DPlib 是一个使用 mcfunction 开发的数据包库。它旨在让你能够直接将所需的模块包含在你的数据包中,无需担心性能或兼容性问题,也无需创建依赖关系。该库注重性能与简洁性,可在任何需要简单或复杂功能的数据包中使用,并尽可能实现高速运行。
本库包含以下内容:
- dplib.math
- 数论与表示法
- 幂运算与对数
- 三角函数
- 随机数生成器 (RNG) 与线性同余生成器 (LCG)
- 其他各种函数
- dplib.datetime
- 现实世界的日期与时间
- 本地时间
- 时间与时长计算
- 时间转换
- dplib.threading
- 基于上下文实体的代码多线程
- 分层多线程
- 计分板 ID
- dplib.benchmark
工作原理
你只需将所需模块(它们独立工作)导入到数据包的 data 文件夹中,然后需要在你的数据包加载文件开头执行以下命令来加载它:
function dplib.<module>:load
你可能还需要在 tick 文件中启用模块的计时器,如果是这样,请在你的 tick 文件开头添加以下内容:
function dplib.<module>:tick
为确保正确卸载,你必须在卸载文件中包含以下行:
function dplib.<module>:uninstall
通常,参数的输入计分板为 dplib.<module>.in,输出计分板为 dplib.<module>.out。自动管理的变量位于 dplib.<module>.main
例如,你可以计算离你最近的牛有多远:
# 将玩家的坐标放入函数的参数中
execute as Someone store result score $x1 dplib.math.in run data get entity @s Pos[0]
execute as Someone store result score $y1 dplib.math.in run data get entity @s Pos[1]
execute as Someone store result score $z1 dplib.math.in run data get entity @s Pos[2]
# 将最近的牛的坐标放入函数的参数中
execute at Someone as @e[sort=nearest,type=cow,limit=1] store result score $x2 dplib.math.in run data get entity @s Pos[0]
execute at Someone as @e[sort=nearest,type=cow,limit=1] store result score $y2 dplib.math.in run data get entity @s Pos[1]
execute at Someone as @e[sort=nearest,type=cow,limit=1] store result score $z2 dplib.math.in run data get entity @s Pos[2]
# 使用此库提供的工具计算距离
function dplib.math:tools/distance
# 在玩家快捷栏上方显示结果
title Someone actionbar [{"text":"Nearest Cow : ","color":"red"},{"score":{"name":"$out","objective":"dplib.math.out"},"color":"yellow"},{"text":"m","color":"yellow"}]
或者你可以直接获取实时真实世界时间戳:
scoreboard players get unix_timestamp dplib.datetime.main
本库旨在与 Data-pack Helper Plus 扩展配合使用,借助扩展提供的自动补全功能和别名库,可以更方便地查找函数。
完整文档请参见 此处。
建议注明项目来源:
此数据包使用了 DPlib
https://github.com/Z0rillac/DPlib
The complete documentation can be found here.
Datapack library
DPlib is a library for datapack developed in mcfunction. It is designed so that you can directly include the module you want in your datapack, without worrying about performance or compatibility and without creating dependencies. It is designed for performance and simplicity, it can be used in any datapack requiring simple or complex functions while being as fast as possible.
This library contains:
- dplib.math
- Number-theoretic and representation
- Power and logarithm
- Trigonometry
- RNG and LCG
- Other various functions
- dplib.datetime
- Real world date and time
- Local time
- Time and duration calculation
- Time conversion
- dplib.threading
- Code threading with contextual entities
- Hierarchical threading
- Scoreboard ID
- dplib.benchmark
- Benchmarking for development only
How it works
You just need to import the module(s) you need (they work independently) into the data folder of your datapack, you then need to load it by executing this command at the beginning of your datapack load file :
function dplib.<module>:load
You may also need to tick the module, if so add this to the beginning of your tick file :
function dplib.<module>:tick
To ensure proper de-installation, you must include this line in the uninstallation file :
function dplib.<module>:uninstall
In general, the input scoreboard for parameters is dplib.<module>.in and the output scoreboard is dplib.<module>.in. The automatically managed variables are in dplib.<module>.main
For example, you can calculate how far away the nearest cow is:
# Puts the player's coordinates in parameters of the function
execute as Someone store result score $x1 dplib.math.in run data get entity @s Pos[0]
execute as Someone store result score $y1 dplib.math.in run data get entity @s Pos[1]
execute as Someone store result score $z1 dplib.math.in run data get entity @s Pos[2]
# Puts the nearest cow coordinates in parameters of the function
execute at Someone as @e[sort=nearest,type=cow,limit=1] store result score $x2 dplib.math.in run data get entity @s Pos[0]
execute at Someone as @e[sort=nearest,type=cow,limit=1] store result score $y2 dplib.math.in run data get entity @s Pos[1]
execute at Someone as @e[sort=nearest,type=cow,limit=1] store result score $z2 dplib.math.in run data get entity @s Pos[2]
# Calculates the distance using a tool provided by this library
function dplib.math:tools/distance
# Displays the result above the player's hotbar
title Someone actionbar [{"text":"Nearest Cow : ","color":"red"},{"score":{"name":"$out","objective":"dplib.math.out"},"color":"yellow"},{"text":"m","color":"yellow"}]
Or you can simply get the real world timestamp live:
scoreboard players get unix_timestamp dplib.datetime.main
This library is made to be used with Data-pack Helper Plus extension, it is easier to find the functions thanks to the auto completion provided by the extension and a library of aliases.
The complete documentation can be found here.
It is advisable to credit the project :
This datapack uses DPlib
https://github.com/Z0rillac/DPlib
评论 0
登录后参与评分
还没有评论,来抢沙发吧