D's Better Schedule 是一个提供保持上下文的调度器的库。
它会记录当前上下文的执行者、位置、旋转和维度。
它还重点关注在执行时,如果执行实体处于离线、死亡或未加载状态时的行为。
使用方法
要使用调度器,首先将所需数据存入存储 dah.sch:new new。 字段如下:
run: #[command] string 要作为字符串执行的命令。无需斜杠。必填
time: int 在运行命令之前等待的刻数。必填
offline: string
如果在执行时未找到目标实体(离线、死亡或未加载),该如何处理。默认为 discard:
discard: 不执行任何操作并移除任务。
delay: 仅限玩家 当玩家离线时计时器继续计数,但仅在该玩家重新上线后才会执行
pause: 仅限玩家 当玩家离线时计时器暂停。
by_server: 由服务器代替执行该命令。
max_retry: int 如果 offline 设置为 discard 或 by_server,则在执行时如果未找到实体,任务将在下一刻重试,最多重试 max_retry 次。如果所有重试均失败,则根据 offline 的设置将其丢弃或由服务器执行。默认为 0。
flags: [string] 定义任务的额外行为。可能包括:
no_executer: 执行者不会包含在上下文中;命令将由服务器运行。
location_less: 位置和旋转不会包含在上下文中;命令将在世界出生点运行
debug: 向聊天输出调试信息。
in: #[id="dimension"] string 如果提供,则用给定的值覆盖上下文维度。
然后在所需的上下文中执行 function dah.sch:new 以调度命令。
示例:
# 1秒后将执行者传送到当前位置。
data modify storage dah.sch:new new set value {run:"tp ~ ~ ~",time:20}
function dah.sch:new
# 1秒后在当前位置放置石头,并输出调试信息。
data modify storage dah.sch:new new set value {run:"setblock ~ ~ ~ stone",time:20,flags:["debug"]}
function dah.sch:new
# 10秒后移除该玩家的属性修饰符。如果玩家在10秒内离线,则在其重新登录后再移除。
data modify storage dah.sch:new new set value {run:"attribute @s attack_damage modifier remove foo:bar",time:200,offline:"delay"}
function dah.sch:new
还提供了一个简化的宏版本调度器 function dah.sch:set。它只能接受 time 和 run 参数:
function dah.sch:set {run:'say 1', time: 20}
添加已知维度
如果上下文维度不是原版维度之一,该库会召唤一个猪灵蛮兵并从其 NBT 中读取维度信息。这会导致更多的性能开销。
您可以通过向函数标签 #dah.sch:known_dimensions 添加一个函数来将已知维度添加到系统中,运行类似以下内容的命令:execute if predicate {type:"location_check",predicate:{dimension:"foo:bar"}} run data modify storage dah.sch:task this.in set value "foo:bar"。
依赖文件
发布包中包含一个 DBS-Dependency.zip 文件。将此文件放在计算机的任何位置,然后通过在工作区根目录创建一个 spyglass.json 文件,Spyglass 扩展将为您需要编写的所有函数、存储和标签提供自动补全和错误检查功能,以便使用此库。
spyglass.json 文件的示例内容。更多详情请参阅 Spyglass 文档。
{
"env": {
"dependencies": [
"file:///C:/path/to/DBS-Dependency.zip",
"@vanilla-mcdoc",
"@vanilla-resourcepack",
"@vanilla-mcdoc"
],
"gameVersion": "26.3"
}
}
请记住重载 VSCode。如果出现问题,请让 Vs Code 运行 Spyglass: Reset Project Cahce 命令。
兼容性
该库本身不覆盖任何原版命名空间,不修改/创建/删除任何世界元素(方块、实体等),且所有 ID 均带有 dah.sch 前缀或命名空间。是的,这使得它遵循了 Smithed 和 essential MC Datapacks Discord Server Conventions 的规范。您无需担心其兼容性问题。
卸载
由于该库的实现方式,在其启用时无法卸载数据包数据。
因此,请先移除此数据包,重载游戏,然后您可以执行根文件夹中提供的 unload.mcfunction 文件中列出的命令来删除剩余数据。请按照该文件中的说明进行操作。
链接
包含了一个 gu 库用于转换 UUID。
仓库地址:
Modrinth:
D's Better Schedule is a library that provides a scheduler that keeps the context.
It will record the executor, location, rotation, and dimension of the current context.
It also focuses on the behavior when the executor entity is offline, dead, or unloaded at the time of execution.
How to Use
To use the scheduler, first put the required data in storage dah.sch:new new. Fields:
run: #[command] string The command to run as a string. No slash. REQUIRED
time: int The number of ticks to wait before running the command. REQUIRED
offline: string
What to do if the target entity is not found at the time of execution (offline, dead, or unloaded). Defaults to discard:
discard: Do nothing and remove the task.
delay: PLAYER ONLY The timer ticks when the player is offline, but only executes until the player go back online
pause: PLAYER ONLY Timer freezes when the player is offline.
by_server: The command will be executed by the server instead.
max_retry: int If offline is set to discard or by_server, then if entity is not found at execution time, the task will be re-attempted on the next tick, up to max_retry number of times. If all retries failed then it proceeds to be discarded or executed by server accroding to offline. Defaults to 0.
flags: [string] Defines extra behaviors for the task. May includes:
no_executer: The executor will not be included in the context; the command will be run by server.
location_less: The Location and Rotation will not be included in the context; command will be run at world spawn
debug: Output debug information to chat.
in: #[id="dimension"] string If provided, override the context dimension with the given one.
Then execute function dah.sch:new in the desired context to schdule the command.
Example:
# teleport the executor back to the current loction after 1s.
data modify storage dah.sch:new new set value {run:"tp ~ ~ ~",time:20}
function dah.sch:new
# setblock stone at current location after 1s, spit out debug info.
data modify storage dah.sch:new new set value {run:"setblock ~ ~ ~ stone",time:20,flags:["debug"]}
function dah.sch:new
# Remove this player's attribute modifier after 10s. If the player goes offline in 10s then remove it after they log back in.
data modify storage dah.sch:new new set value {run:"attribute @s attack_damage modifier remove foo:bar",time:200,offline:"delay"}
function dah.sch:new
A simple macro version of the schduler is also provided as function dah.sch:set. It can only take in the time and run parameter:
function dah.sch:set {run:'say 1', time: 20}
Adding Known Dimensions
If the context dimension is not one of the vanilla ones, the library will summon a piglin brute and read the dimension out of its NBT. This causes more performance.
You may add a known dimension to the system by adding a function to the function tag #dah.sch:known_dimensions, running something likeexecute if predicate {type:"location_check",predicate:{dimension:"foo:bar"}} run data modify storage dah.sch:task this.in set value "foo:bar".
Dependency File
A DBS-Dependency.zip is included in the release. Put this file anywhere on your computer, then by creating a spyglass.json file at the root of your workspace, the Spyglass extension will provides you the completion and error checking of all the functions, storages, and tags you need to write to use this library.
Example content of the spyglass.json file. See Spyglass Documentation for more.
{
"env": {
"dependencies": [
"file:///C:/path/to/DBS-Dependency.zip",
"@vanilla-mcdoc",
"@vanilla-resourcepack",
"@vanilla-mcdoc"
],
"gameVersion": "26.3"
}
}
Remeber to Reload Vscode. If something about this somehow goes wrong, make Vs Code run the Spyglass: Reset Project Cahce command.
Compatibility
This library, by itself, overrides no vanilla namespaces, does not modify/create/remove any world elements (blocks, entities, etc.), and all ids have the dah.sch prefix or namespace. Yes, this makes it follows the Smithed and essential MC Datapacks Discord Server Conventions. There should be zero worries about its compatibility.
Uninstall
Because of how this library is implemented, it is not possible to unload the datapack data while it is enabled.
Thus, first remove the datapack, reload, then you may execute the commands listed in the unload.mcfunction file provided in the root folder to delete the remaining data. Follow the instructions in that file.
Links
A gu library is included to convert UUIDs
Repository:
Modrinth:
评论 0
登录后参与评分
还没有评论,来抢沙发吧