TVOL 触发体积
TVOL Trigger Volumes 添加了易于使用的触发体积,可以通过单一命令生成,并配置为在进入、离开或每刻(tick)内部时运行命令和函数。
使用方法
召唤一个标记实体(理论上允许任何实体类型,因此你可以将体积附加到移动实体等),添加所需的形状和目标检测标签,配置大小,并定义事件命令和/或函数。
语法:
/summon marker ~ ~ ~ {Tags:["tvol.<shape>.<target_type>"],data:{tvol:{<shape-dependant size args>,condition:<condition>,<callbacks>}}}
你可以通过以下命令切换视觉轮廓:
/function tvol:toggle_outline
支持的形状
sphere:球体体积
box:立方体体积(仅限完整方块)
- 大小参数:
dx、dy 和 dz:描述 x、y 和 z 方向的大小,这些值分别直接传递给目标选择器的 dx、dy 和 dz,且可以为负值。
目标类型
player:仅检测玩家
entity:可检测任意类型的实体
条件(可选)
条件通过宏传递给现有的实体 @e[](或 @a[])目标选择器,因此可以包含任何自定义选择器参数,但最有用的是限制实体类型,例如使用 type=minecraft:cow 将检测限制为牛。
默认值为 type=!#tvol:ignored,默认情况下排除标记、盔甲架、物品显示、方块显示、文本显示和交互实体。
回调(可选)
你可以指定任意数量的回调。使用事件名称作为键,并指定一个包含要运行的函数和/或命令的复合标签。
示例:on_enter:{command:"say hi",function:"my_datapack:area_entered"},on_exit:{command:"say bye"},on_stay:{function:"my_datapack:area_stay"}
如果你不打算使用某个事件,则完全不需要指定它,并且你可以同时使用命令和函数(命令将在函数之前执行)。
示例
带有进入和退出命令的玩家检测球体
/summon marker ~ ~ ~ {Tags:["tvol.sphere.player"],data:{tvol:{radius:7.5,on_enter:{command:"say enter sphere"},on_exit:{command:"say exit sphere"}}}}
带有发光牛的立方体
/summon marker ~ ~ ~ {Tags:["tvol.box.entity"],data:{tvol:{dx:15,dy:3,dz:5,condition:"type=cow",on_stay:{command:"effect give @s minecraft:glowing 1 0 true"}}}}
实体检测立方体
/summon marker ~ ~ ~ {Tags:["tvol.box.entity"],data:{tvol:{dx:20,dy:5,dz:20,on_enter:{command:"say I entered the box",function:"my_datapack:enter_box"},on_exit:{function:"my_datapack:exit_box"}}}}
实用函数
有一些实用函数:
/function tvol:count {id:<id>}:返回当前位于内部的实体数量(未缓存,但它使用 @e[tag=...] 来计算所有已被计算为在内部并被赋予该标签的实体,因此不会进行新的坐标检查)
/execute as @n[tag=tvol.volume] run function tvol:identify:返回立方体或球体体积的 ID。必须作为需要获取 ID 的体积执行
还有一些用于创建简单立方体或球体的函数,它们没有设置任何事件监听器。
TVOL Trigger Volumes
TVOL Trigger Volumes adds easy-to-use trigger volumes that can be spawned with a single command and configured to run commands and functions on enter, exit or every tick inside.
How to use
Summon a marker entity (technically any entity type is allowed, so you could attach volumes to moving entities etc.), add the tag for the shape and target detection you need, configure size and define event commands and/or functions.
Syntax:
/summon marker ~ ~ ~ {Tags:["tvol.<shape>.<target_type>"],data:{tvol:{<shape-dependant size args>,condition:<condition>,<callbacks>}}}
You can toggle visual outlines with
/function tvol:toggle_outline
Supported Shapes
sphere: Sphere Volume
- Size Arg:
radius: The sphere's radius. Only positive values allowed.
box: Box Volume (full blocks only)
- Size Args:
dx, dy and dz: Describe size in x, y and z directions, these are fed directly into a target selector dx, dy and dz respectively and can be negative.
Target Types
player: Only detects players
entity: May detect any kind of entity
Conditions (optional)
Conditions are passed into an existing entity @e[] (or @a[]) target selector through a macro and may therefore include any custom selector arguments, but it is most useful to restrict entity types, e.g. with type=minecraft:cow to restrict detection to cows.
Defaults to type=!#tvol:ignored, which excludes markers, armor stands, item displays, block displays, text displays and interaction entities by default.
Callbacks (optional)
You may specify any number of callbacks. Use the event name as a key and a compound tag with a function and/or command to run specified.
Example: on_enter:{command:"say hi",function:"my_datapack:area_entered"},on_exit:{command:"say bye"},on_stay:{function:"my_datapack:area_stay"}
If you don't intend on using an event, you don't need to specify it at all and you may use both a command and a function at the same time (command will execute before function).
Examples
Player-detection sphere with enter and exit command
/summon marker ~ ~ ~ {Tags:["tvol.sphere.player"],data:{tvol:{radius:7.5,on_enter:{command:"say enter sphere"},on_exit:{command:"say exit sphere"}}}}
Box with glowing cows
/summon marker ~ ~ ~ {Tags:["tvol.box.entity"],data:{tvol:{dx:15,dy:3,dz:5,condition:"type=cow",on_stay:{command:"effect give @s minecraft:glowing 1 0 true"}}}}
Entity-detection box
/summon marker ~ ~ ~ {Tags:["tvol.box.entity"],data:{tvol:{dx:20,dy:5,dz:20,on_enter:{command:"say I entered the box",function:"my_datapack:enter_box"},on_exit:{function:"my_datapack:exit_box"}}}}
Utility Functions
There are a couple of utility functions:
/function tvol:count {id:<id>}: Returns amount of entities currently inside (not cached, but it uses @e[tag=...] to count all entities with that were already calculated to be inside and given the tag, so it doesn't do any new coordinate checks)
/execute as @n[tag=tvol.volume] run function tvol:identify: Returns the id of a box or sphere volume. Must be executed as the volume you need the id of
There are also functions for creating simple boxes or spheres which do not have any event listeners set up.
评论 0
登录后参与评分
还没有评论,来抢沙发吧