完整版BedrockWiki镜像!
This commit is contained in:
@@ -1,54 +1,57 @@
|
||||
---
|
||||
title: MBE - Max's Block Entity
|
||||
category: Techniques
|
||||
title: MBE - Max的方块实体
|
||||
category: 技术
|
||||
mention:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
tags:
|
||||
- system
|
||||
- 系统
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# MBE - Max的方块实体
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This method, developed by Reddit user [u/Maxed_Out10](https://www.reddit.com/user/Maxed_Out10/) allows you to create near-perfect entity replications of any Minecraft block using armour stands and some sequential `/playanimation` commands.
|
||||
## 简介
|
||||
|
||||
To preserve credits to the creator, the community termed this method as "Max's Block Entity" or MBE for short.
|
||||
[源自Bedrock Commands社区Discord](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
### Points to Note
|
||||
此方法由Reddit用户[u/Maxed_Out10](https://www.reddit.com/user/Maxed_Out10/)开发,通过使用盔甲架和连续的`/playanimation`命令,可以近乎完美地复刻Minecraft中任意方块的实体形态。
|
||||
|
||||
1. This method uses 1 armour stand per block entity. Therefore, too many armour stands (like any entity) can contribute to server lag.
|
||||
2. Players will still be able to pass through them as well as interact with them if not restricted.
|
||||
3. While the block entity may appear in one spot, it's actual hitbox will have a slight offset.
|
||||
为保留原创者荣誉,社区将此方法命名为"Max's Block Entity"(简称MBE)。
|
||||
|
||||
## Video Demonstration
|
||||
### 注意事项
|
||||
|
||||
1. 每个方块实体需使用1个盔甲架,过多盔甲架(如同其他实体)可能导致服务器卡顿
|
||||
2. 玩家仍可穿过未加限制的MBE实体并进行交互
|
||||
3. 方块实体的实际碰撞箱会与视觉位置存在细微偏移
|
||||
|
||||
## 视频演示
|
||||
|
||||
<YouTubeEmbed
|
||||
id="kb8rz9ItE_M"
|
||||
/>
|
||||
|
||||
## Setup
|
||||
## 设置步骤
|
||||
|
||||
*To be typed in chat:*
|
||||
*在聊天栏输入:*
|
||||
1. `/summon armor_stand Grumm`
|
||||
- It is necessary to name it 'Grumm' to avoid inverted block textures.
|
||||
- 必须命名为'Grumm'以避免纹理倒置
|
||||
2. `/execute as @e [type= armor_stand, name=Grumm, c=1] at @s run tp @s ~~~ 260`
|
||||
- This will align the MBE to the normal Minecraft block grid.
|
||||
- 用于将MBE对齐标准方块网格
|
||||
ㅤ
|
||||
:::tip
|
||||
- Crouch & right-click (on mcpe: long press) the armor stand 6 times to place it in Pose 7
|
||||
- Doing this negates the need to use the 2nd command in the system.
|
||||
- **Only use this if you wish to reduce one command from the system.**
|
||||
- 潜行并右键点击(手机版长按)盔甲架6次进入Pose 7
|
||||
- 此操作可替代系统中的第二条命令
|
||||
- **仅在需要精简系统命令时使用**
|
||||
:::
|
||||
|
||||
## System
|
||||
## 系统命令
|
||||
|
||||
> Note: adding a delay of 100-200 ticks is recommended.
|
||||
> 注意:建议添加100-200 Tick的延迟
|
||||
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [mcfunction]
|
||||
/effect @e [type= armor_stand, name=Grumm] invisibility 999999 1 true
|
||||
/playanimation @e [type= armor_stand, name=Grumm] animation.armor_stand.entertain_pose null 0 "0" align.arms
|
||||
/playanimation @e [type= armor_stand, name=Grumm] animation.player.move.arms.zombie null 0 "0" size.mini_block
|
||||
@@ -56,118 +59,119 @@ To preserve credits to the creator, the community termed this method as "Max's B
|
||||
/playanimation @e [type= armor_stand, name=Grumm] animation.fireworks_rocket.move null 0 "0" align.full_block
|
||||
/execute as @e [type= armor_stand, name=Grumm] at @s run tp ~~~
|
||||
```
|
||||
:::
|
||||
|
||||

|
||||
|
||||
### Purpose Of Each Command
|
||||
1. Hides the armour stand body.
|
||||
2. Automatically sets the armour stand pose to 7 for arms alignment. Skip this command you prefer to do it manually.
|
||||
3. __Required command__. Increases size to present as mini-block.
|
||||
4. *Optional command.* Increases size to present as full-block.
|
||||
5. *Optional command.* Aligns the full-block size MBE properly.
|
||||
- Skip 4 & 5 if you do not need full-block size MBE.
|
||||
6. Locks in place to prevent fall in case block underneath is removed.
|
||||
### 命令功能解析
|
||||
1. 隐藏盔甲架本体
|
||||
2. 自动设置盔甲架为Pose 7(手臂对齐),手动设置时可跳过
|
||||
3. __必要命令__ 调整为迷你方块尺寸
|
||||
4. *可选命令* 调整为完整方块尺寸
|
||||
5. *可选命令* 对齐完整方块尺寸
|
||||
- 若不需要完整方块尺寸可跳过4、5
|
||||
6. 锁定位置防止下方方块被破坏时坠落
|
||||
|
||||
## Rotations & Alignments
|
||||
## 旋转与对齐
|
||||
|
||||
> Note: These rotation commands are to be executed only once through a command block.
|
||||
> 注意:以下旋转命令应通过命令方块单次执行
|
||||
|
||||
<Spoiler title="Full MBE">
|
||||
<Spoiler title="完整方块MBE">
|
||||
|
||||
```yaml
|
||||
# Face North
|
||||
# 朝北
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.2260 ~-0.097 81
|
||||
|
||||
# Face South
|
||||
# 朝南
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.2260 ~0.097 260
|
||||
|
||||
# Face East
|
||||
# 朝东
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.2260 ~-1.1245 171
|
||||
|
||||
# Face West
|
||||
# 朝西
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.2260 ~1.1245 350
|
||||
```
|
||||
|
||||
</Spoiler>
|
||||
|
||||
|
||||
<Spoiler title="Mini MBE">
|
||||
<Spoiler title="迷你方块MBE">
|
||||
|
||||
```yaml
|
||||
# Face North
|
||||
# 朝北
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.417~-0.5 ~-0.035 81
|
||||
|
||||
# Face South
|
||||
# 朝南
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.417 ~-0.5 ~0.035 260
|
||||
|
||||
# Face East
|
||||
# 朝东
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.035 ~-0.5 ~-0.417 171
|
||||
|
||||
# Face West
|
||||
# 朝西
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.035 ~-0.5 ~0.417 350
|
||||
```
|
||||
|
||||
</Spoiler>
|
||||
|
||||
<Spoiler title="Stair MBE">
|
||||
<Spoiler title="阶梯MBE">
|
||||
|
||||
```yaml
|
||||
# Face North
|
||||
# 朝北
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.2325 ~1.1245 350
|
||||
|
||||
# Face South
|
||||
# 朝南
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.2325 ~-1.1245 171
|
||||
|
||||
# Face East
|
||||
# 朝东
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.2325 ~-0.097 81
|
||||
|
||||
# Face West
|
||||
# 朝西
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.2325 ~0.097 260
|
||||
```
|
||||
|
||||
</Spoiler>
|
||||
|
||||
<Spoiler title="Bottom Slab MBE">
|
||||
<Spoiler title="下半砖MBE">
|
||||
|
||||
```yaml
|
||||
# Face North
|
||||
# 朝北
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.2325 ~1.1245 350
|
||||
|
||||
# Face South
|
||||
# 朝南
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.2325 ~-1.1245 171
|
||||
|
||||
# Face East
|
||||
# 朝东
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.2325 ~-0.097 81
|
||||
|
||||
# Face West
|
||||
# 朝西
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.2325 ~0.097 260
|
||||
```
|
||||
|
||||
</Spoiler>
|
||||
|
||||
<Spoiler title="Top Slab MBE">
|
||||
<Spoiler title="上半砖MBE">
|
||||
|
||||
```yaml
|
||||
# Face North
|
||||
# 朝北
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.484 ~-0.097 81
|
||||
|
||||
# Face South
|
||||
# 朝南
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.484 ~0.097 260
|
||||
|
||||
# Face East
|
||||
# 朝东
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.484 ~-1.1245 171
|
||||
|
||||
# Face West
|
||||
# 朝西
|
||||
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.484 ~1.1245 350
|
||||
```
|
||||
|
||||
</Spoiler>
|
||||
|
||||
## Saving & Loading MBE
|
||||
## 保存与加载MBE
|
||||
|
||||
1. To save run:
|
||||
1. 保存命令:
|
||||
- `/execute as @e [type=armor_stand, name=Grumm, c=1] at @s run structure save MBE ~~~ ~~~`
|
||||
|
||||
2. To load run:
|
||||
- `/structure load MBE <coordinates>`
|
||||
2. 加载命令:
|
||||
- `/structure load MBE <坐标>`
|
||||
|
||||
> Note: structure name `MBE` can be changed to your preference.
|
||||
> 注意:结构名称`MBE`可根据需要更改
|
||||
@@ -1,118 +1,125 @@
|
||||
---
|
||||
title: Block States
|
||||
category: General
|
||||
title: 方块状态
|
||||
category: 基础
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
- SmokeyStack
|
||||
- ThomasOrs
|
||||
tags:
|
||||
- info
|
||||
- 信息
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 方块状态
|
||||
|
||||
[Sourced by Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Block States or Block Properties are additional data that defines how the block appears or behaves. Such as the direction it is facing, it's color, it's variant, whether it is powered or unpowered and so on.
|
||||
## 引言
|
||||
|
||||
This is used in a multitude of commands such as `/clone`, `/execute`, `/fill`, `/setblock` and `/testforblock`
|
||||
[由Bedrock Commands社区Discord提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
In Bedrock Edition we used Aux values (also known as Metadata) to define a block. However; as of 1.19.70 and beyond this is no longer supported and have been fully replaced with Block States instead.
|
||||
方块状态(Block States)或方块属性(Block Properties)是用于定义方块外观或行为的附加数据。例如方块的朝向、颜色、变种、是否充能等特性。
|
||||
|
||||
<CodeHeader>example</CodeHeader>
|
||||
这些数据被广泛应用于多个命令中,包括但不限于:
|
||||
- `/clone`
|
||||
- `/execute`
|
||||
- `/fill`
|
||||
- `/setblock`
|
||||
- `/testforblock`
|
||||
|
||||
```yaml
|
||||
#Aux Value Example:
|
||||
在基岩版中,我们曾使用辅助值(Aux Values,也称元数据)来定义方块。然而自1.19.70版本起,该机制已被全面弃用,并由方块状态完全取代。
|
||||
|
||||
::: code-group
|
||||
```yaml [辅助值]
|
||||
#辅助值示例:
|
||||
/setblock ~ ~ ~ wool 1
|
||||
#It's Block State equivalent:
|
||||
#等效的方块状态写法:
|
||||
/setblock ~ ~ ~ wool ["color"="orange"]
|
||||
```
|
||||
:::
|
||||
|
||||
- Any command block using aux values will continue to function as it is however block states will need to be adopted when updating them.
|
||||
- Similarly any commands using aux values in behaviour or function packs with `min_engine_version` 1.19.63 or below will also continue to function however block states must be adopted if the `min_engine_version` is updated to 1.19.70 or above.
|
||||
- 使用辅助值的命令方块仍可继续工作,但在更新时需要改用方块状态
|
||||
- 同理,在行为包或功能包中使用辅助值的命令,若`min_engine_version`设置为1.19.63或更低版本仍可正常工作,但若将最低引擎版本更新至1.19.70或更高则必须改用方块状态
|
||||
|
||||
## Block State Examples & Syntax
|
||||
## 方块状态示例与语法
|
||||
|
||||
<CodeHeader>Examples</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [示例]
|
||||
/setblock ~ ~ ~ wool ["color"="white"]
|
||||
/setblock ~ ~ ~ wheat ["growth"=0]
|
||||
/setblock ~ ~ ~ wood ["wood_type"="birch","stripped_bit"=true]
|
||||
/setblock ~ ~ ~ wool []
|
||||
```
|
||||
:::
|
||||
|
||||
- Block states are enclosed in square brackets ` [ ] `
|
||||
- When specifying multiple block states a comma ` , ` is used to separate them.
|
||||
- Quotation marks ` " " ` are used around strings such as `"birch", "spruce" etc..`
|
||||
- Integer values `0, 1, 2..` and boolean values `true/false` do not use quotation marks.
|
||||
- Leaving the brackets blank is also a correct syntax, it will simply default to 0.
|
||||
- `wool 0` is white wool hence you may simply write it as `wool []` instead of `wool ["color"="white"]`
|
||||
- 方块状态需用方括号 `[ ]` 包裹
|
||||
- 多个状态间用逗号 `,` 分隔
|
||||
- 字符串值需使用双引号包裹,如 `"birch"`、`"spruce"` 等
|
||||
- 整数值 `0, 1, 2...` 和布尔值 `true/false` 无需引号
|
||||
- 空括号 `[]` 是有效语法,表示使用默认值0
|
||||
- `wool 0` 对应白色羊毛,因此可简写为 `wool []` 替代 `wool ["color"="white"]`
|
||||
|
||||
### Notes For Beginners
|
||||
### 新手须知
|
||||
|
||||
- **Integers** are whole numbers. They are used to define a block from a 'range' of values.
|
||||
- Example: Redstone power 1 to 15
|
||||
- `["redstone_power"=10]`
|
||||
- **整数(Integer)**:用于定义数值范围
|
||||
- 示例:红石信号强度1-15
|
||||
- `["redstone_power"=10]`
|
||||
|
||||
- **Boolean** is a programming term which refers to `true/false` values. You can simply understand it as yes or no questions.
|
||||
- Is this piston powered? `yes/no`
|
||||
- Is this button pressed? `yes/no`
|
||||
- Is this log stripped? `yes/no`
|
||||
- `["stripped_bit"=true]`
|
||||
- **布尔值(Boolean)**:表示二值状态(真/假)
|
||||
- 是否被激活?是否被按下?是否去皮?
|
||||
- `["stripped_bit"=true]`
|
||||
|
||||
- **Strings** are unique 'text' inputs. You can simply understand it as multiple choice questions.
|
||||
- What color is this wool? `"white"`, `"orange"`, `"brown"` etc..
|
||||
- What wood type is this log? `"spruce"`, `"birch"`, `"acacia"` etc..
|
||||
- `["wood_type"="spruce"]`
|
||||
|
||||
|
||||
## Block States List
|
||||
A list of all the block states currently available within Bedrock can be found at:
|
||||
- **字符串(String)**:用于多选类型
|
||||
- 羊毛颜色?原木种类?
|
||||
- `["wood_type"="spruce"]`
|
||||
|
||||
## 方块状态列表
|
||||
完整方块状态清单可访问微软官方文档:
|
||||
https://learn.microsoft.com/en-us/minecraft/creator/reference/content/blockreference/examples/blockstateslist
|
||||
|
||||
Note: In the site block states may be written as one word but make sure to separate them with underscores `_` when typing in commands.
|
||||
注意:文档中可能出现连写的状态名称,但在命令中需使用下划线 `_` 分隔
|
||||
|
||||
Example: `buttonPressedBit` → `"button_pressed_bit"`
|
||||
示例:`buttonPressedBit` → `"button_pressed_bit"`
|
||||
|
||||
## Converting Aux Values to Block States
|
||||
For your convenience; download any of the excel sheet below to find the full list of block IDs, their aux values and equivalent block states in Bedrock. *Shared by kayla@Mojang*
|
||||
## 辅助值与方块状态转换
|
||||
可通过下方表格下载完整转换对照表(由kayla@Mojang提供):
|
||||
|
||||
<BButton
|
||||
link="https://github.com/BedrockCommands/bedrockcommands.github.io/files/10987839/Aux-Value_to_Block-States_Map.xlsx"
|
||||
color=white
|
||||
>Download Sheet 1</BButton>
|
||||
>下载表格1</BButton>
|
||||
|
||||
Note: the above sheet was quickly generated and contains some minor errors. Boolean values `0` should be replaced with `false` and `1` should be replaced with `true` since the game doesn't recognize the syntax otherwise.
|
||||
注意:此表格为快速生成版本,布尔值需手动将`0`改为`false`,`1`改为`true`
|
||||
|
||||
Alternate sheet: *Shared by @ItsRichHeart*
|
||||
替代表格(由@ItsRichHeart提供):
|
||||
|
||||
<BButton
|
||||
link="https://github.com/BedrockCommands/bedrockcommands.github.io/files/11069804/All.Block-Item.List.Bedrock.pdf"
|
||||
color=white
|
||||
>Download Sheet 2</BButton>
|
||||
>下载表格2</BButton>
|
||||
|
||||
You may also use this [Lookup Table](https://auxval-to-blockstates.netlify.app/) instead not needing to download any files.
|
||||
也可使用在线[查询工具](https://auxval-to-blockstates.netlify.app/)免下载转换
|
||||
|
||||
## Known Issue
|
||||
## 已知问题
|
||||
|
||||
Detecting blocks using commands such as `/execute` or `/testforblock` requires __all__ or __none__ of the block states specified else the command returns an error.
|
||||
使用 `/execute` 或 `/testforblock` 检测方块时,必须指定全部或完全不指定方块状态,否则会报错
|
||||
|
||||
Example; detecting a pressed stone button on ground facing up:
|
||||
<CodeHeader></CodeHeader>
|
||||
示例:检测朝上方向被按下的石质按钮:
|
||||
|
||||
::: code-group
|
||||
```yaml
|
||||
#✅ Accepted:
|
||||
#✅ 有效写法:
|
||||
/execute if block ~~~ stone_button [“button_pressed_bit”=true,”facing_direction”=1] run say success
|
||||
/execute if block ~~~ stone_button run say success
|
||||
|
||||
# ❌ Not Accepted:
|
||||
# ❌ 无效写法:
|
||||
/execute if block ~~~ stone_button [“button_pressed_bit”=true] run say success
|
||||
/execute if block ~~~ stone_button [“facing_direction”=1] run say success
|
||||
```
|
||||
Though block states have replaced aux values, we still cannot detect blocks based on specific filters yet like we do with selector arguments.
|
||||
:::
|
||||
|
||||
### Related Bug Reports
|
||||
虽然方块状态已取代辅助值,但目前仍无法像选择器参数那样进行精确过滤
|
||||
|
||||
### 相关漏洞报告
|
||||
- [MCPE-133360](https://bugs.mojang.com/browse/MCPE-133360)
|
||||
- [MCPE-168391](https://bugs.mojang.com/browse/MCPE-168391)
|
||||
- [MCPE-168391](https://bugs.mojang.com/browse/MCPE-168391)
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Damage
|
||||
category: Commands
|
||||
title: 伤害指令
|
||||
category: 命令
|
||||
tags:
|
||||
- info
|
||||
- 信息
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- cda94581
|
||||
@@ -10,87 +10,100 @@ mentions:
|
||||
- zheaEvyline
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 伤害指令
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Introduced in Minecraft Release `1.18.10`, the /damage command deals precise damage to specified entities. With this change, the clunky methods like using `/effect` command to damage entities are rendered obsolete, making maps and other creations more powerful.
|
||||
## 概述
|
||||
|
||||
## Syntax
|
||||
[源自Bedrock Commands社区Discord](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
- There are two ways the damage command can be used:
|
||||
- `/damage <Target> <Amount> [Cause]`
|
||||
- `/damage <Target> <Amount> <Cause> entity <Damager>`
|
||||
`/damage` 指令于Minecraft基岩版 `1.18.10` 版本加入,可对指定实体造成精确伤害。这一改进使得原先使用 `/effect` 指令等笨拙的伤害方式成为历史,为地图制作和其他创作提供了更强大的工具。
|
||||
|
||||
## Arguments
|
||||
## 语法结构
|
||||
|
||||
- Phrases not contained in angle <> or square [] brackets instruct you to type it as-is.
|
||||
- Phrases contained within brackets are variables, these need to be replaced:
|
||||
- **` <> `** Angle brackets mean the variable is required.
|
||||
- **` [] `** Square brackets mean the variable is optional.
|
||||
- 该指令有两种使用方式:
|
||||
- `/damage <目标> <伤害值> [伤害原因]`
|
||||
- `/damage <目标> <伤害值> <伤害原因> entity <伤害源实体>`
|
||||
|
||||
## Variables
|
||||
## 参数说明
|
||||
|
||||
- **` Target `** This is your typical entity selector, such as `@s` , `@e` , or `"cda94581"` . Multiple entities may be selected at a time to deal the damage to multiple targets.
|
||||
- 未包含在尖括号 `<>` 或方括号 `[]` 中的短语需按原样输入
|
||||
- 括号内内容为可变参数,需要替换为实际值:
|
||||
- **` <> `** 尖括号表示必填参数
|
||||
- **` [] `** 方括号表示可选参数
|
||||
|
||||
- **` Amount `** This is a whole number, which specifies the amount of damage to deal to the targets. The minimum value is `0` and the maximum value is `2147483647`, or the signed 32-bit integer limit.
|
||||
## 参数详解
|
||||
|
||||
- **` Cause `** This specifies the "reason" the damage was dealt. This cause will appear in death messages (`X hit the ground too hard for cause: fall`) be used in damage calculation with armor (`the value dealt in Amount may be different depending on the worn armor`), and used in a large variety of other things, such as in Behavior Pack/Add-ons. A full list of all the damage causes can be found [below](/commands/damage#damage-cause-list)
|
||||
- **` 目标 `**
|
||||
常规实体选择器,如 `@s`、`@e` 或 `"cda94581"`。支持同时选择多个实体进行群体伤害。
|
||||
|
||||
- **` Damager `** If Cause was something to do with entities `(such as entity_attack)`, this specifies where the damage came from `(the entity that dealt the attack)`. This is limited to only 1 target. An error will be thrown if multiple targets are found from the selector.
|
||||
- **` 伤害值 `**
|
||||
整数类型,指定造成的伤害数值。最小值为 `0`,最大值为32位有符号整数上限 `2147483647`。
|
||||
|
||||
> Note: the `<Cause> entity <Damager>` is only required when the Cause has to do with another entity `(entity_attack)`. Otherwise, follow the first syntax.
|
||||
- **` 伤害原因 `**
|
||||
决定伤害来源类型。该参数将影响:
|
||||
- 死亡提示信息(如 `X因坠落伤害而亡`)
|
||||
- 护甲减伤计算(实际伤害值会根据护甲属性变化)
|
||||
- 行为包/附加包中的伤害处理逻辑
|
||||
完整伤害原因列表详见[下方章节](/wiki/commands/damage#damage-cause-list)
|
||||
|
||||
## Examples
|
||||
- **` 伤害源实体 `**
|
||||
当伤害原因与实体相关时(如 `entity_attack`),此参数指定伤害来源实体。该选择器仅支持单个目标,若返回多个实体会报错。
|
||||
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
```yaml
|
||||
#Deal 4 damage to all players
|
||||
> 注意:`<伤害原因> entity <伤害源实体>` 语法仅在伤害原因涉及其他实体时使用(如实体攻击)。其他情况请使用基础语法。
|
||||
|
||||
## 使用示例
|
||||
|
||||
::: code-group
|
||||
```yaml [mcfunction]
|
||||
# 对所有玩家造成4点伤害
|
||||
/damage @a 4
|
||||
|
||||
#Deal 3 'fire' damage to all entities of type 'sheep'
|
||||
/damage @e [type=sheep] 3 fire
|
||||
# 对所有绵羊造成3点火焰伤害
|
||||
/damage @e[type=sheep] 3 fire
|
||||
|
||||
#Deal 40 'entity attack' damage from a random player to all entities of type 'sheep'
|
||||
/damage @a 40 entity_attack entity @r [type=sheep]
|
||||
# 让随机玩家对所有绵羊造成40点实体攻击伤害
|
||||
/damage @e[type=sheep] 40 entity_attack entity @r
|
||||
```
|
||||
:::
|
||||
|
||||
## Damage Cause List
|
||||
## 伤害原因列表
|
||||
|
||||
Listed below are all the 'damage sources' in MCBE for the `/damage` command currently available:
|
||||
```
|
||||
anvil
|
||||
attack
|
||||
block_explosion
|
||||
charging
|
||||
contact
|
||||
drowning
|
||||
entity_attack
|
||||
entity_explosion
|
||||
fall
|
||||
falling_block
|
||||
fatal
|
||||
fire
|
||||
fire_tick
|
||||
fireworks
|
||||
fly_into_wall
|
||||
freezing
|
||||
lava
|
||||
lightning
|
||||
magic
|
||||
magma
|
||||
none
|
||||
override
|
||||
piston
|
||||
projectile
|
||||
sonic_boom
|
||||
stalactite
|
||||
stalagmite
|
||||
starve
|
||||
suffocation
|
||||
suicide
|
||||
temperature
|
||||
thorns
|
||||
void
|
||||
wither
|
||||
以下是MCBE中 `/damage` 指令当前支持的所有伤害原因:
|
||||
```
|
||||
anvil # 铁砧
|
||||
attack # 普通攻击
|
||||
block_explosion # 方块爆炸
|
||||
charging # 冲锋(如幻翼)
|
||||
contact # 接触伤害(如仙人掌)
|
||||
drowning # 溺水
|
||||
entity_attack # 实体攻击
|
||||
entity_explosion # 实体爆炸
|
||||
fall # 坠落
|
||||
falling_block # 下坠方块
|
||||
fatal # 致命伤害
|
||||
fire # 火焰
|
||||
fire_tick # 燃烧伤害
|
||||
fireworks # 烟花
|
||||
fly_into_wall # 飞行撞墙(鞘翅)
|
||||
freezing # 冰冻
|
||||
lava # 岩浆
|
||||
lightning # 闪电
|
||||
magic # 魔法
|
||||
magma # 岩浆块
|
||||
none # 无来源
|
||||
override # 强制覆盖
|
||||
piston # 活塞
|
||||
projectile # 弹射物
|
||||
sonic_boom # 监守者音波
|
||||
stalactite # 钟乳石
|
||||
stalagmite # 石笋
|
||||
starve # 饥饿
|
||||
suffocation # 窒息
|
||||
suicide # 自杀
|
||||
temperature # 温度伤害
|
||||
thorns # 荆棘
|
||||
void # 虚空
|
||||
wither # 凋零
|
||||
```
|
||||
@@ -1,77 +1,83 @@
|
||||
---
|
||||
title: Entity Counter
|
||||
category: Scoreboard Systems
|
||||
title: 实体计数器
|
||||
category: 计分板系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
nav_order: 3
|
||||
tags:
|
||||
- system
|
||||
- 系统
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 实体计数器
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system allows you to track how many players/entities are there on your world and run your desired commands based on the values obtained.
|
||||
## 前言
|
||||
|
||||
> Note: you cannot track entities in unloaded chunks though players can still be tracked regardless.
|
||||
[源自Bedrock Commands社区Discord](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
## Setup
|
||||
本系统可用于追踪世界中玩家/实体的数量,并根据获取的数值执行自定义命令。
|
||||
|
||||
*To be typed in Chat:*
|
||||
> 注意:无法追踪未加载区块中的实体,但玩家无论是否在加载区块中都可被追踪。
|
||||
|
||||
## 初始化设置
|
||||
|
||||
*在聊天栏输入:*
|
||||
|
||||
`/scoreboard objectives add total dummy`
|
||||
|
||||
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
|
||||
若希望在世界初始化时自动添加该计分项,请参照[首次世界加载](/wiki/commands/on-first-world-load)中的流程进行设置。
|
||||
|
||||
## System
|
||||
## 核心系统
|
||||
|
||||
<CodeHeader>BP/functions/entity_counter.mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [BP/functions/entity_counter.mcfunction]
|
||||
scoreboard players set onlinePlayers total 0
|
||||
execute as @e [type=player] run scoreboard players add onlinePlayers total 1
|
||||
|
||||
#Your Commands Here (examples)
|
||||
execute if score onlinePlayers total matches 4.. run title @a actionbar Enough players to start game.
|
||||
execute if score onlinePlayers total matches ..3 run title @a actionbar Not enough players.
|
||||
# 在此处添加你的命令(示例)
|
||||
execute if score onlinePlayers total matches 4.. run title @a actionbar 玩家数量已满足游戏条件。
|
||||
execute if score onlinePlayers total matches ..3 run title @a actionbar 玩家数量不足。
|
||||
|
||||
```
|
||||
:::
|
||||
|
||||

|
||||
|
||||
本示例使用名为`onlinePlayers`的虚拟玩家分数,通过选择器`@e [type=player]`追踪当前在线玩家数量。您可以根据需求使用任意虚拟玩家名称和实体类型,例如`@e [type=creeper]`来追踪苦力怕数量。
|
||||
|
||||
Here we have used a FakePlayer name `onlinePlayers` and targeting `@e [type=player]` to track how many players are currently on the world. However you may use any FakePlayer name and target any entity you might need. Such as `@e [type=creeper]`
|
||||
示例中使用的`/title`命令演示了两种条件判断:
|
||||
- a) 当玩家数≥4时触发 `4..`
|
||||
- b) 当玩家数≤3时触发 `..3`
|
||||
|
||||
Similarly we're running a `/title` command as an example:
|
||||
- a) when there are 4 or more players `4..`
|
||||
- b) when there are 3 players or less `..3`
|
||||
您可根据实际需求修改这些条件。
|
||||
|
||||
You can edit this as well to suit your need.
|
||||
## 系统原理
|
||||
|
||||
## Explanation
|
||||
- 系统中的前两条命令将虚拟玩家分数(此处为`onlinePlayers`)重置为0,然后通过遍历每个已加载的目标实体(此处为`type=player`)来累计分数
|
||||
|
||||
- The first two commands in the system sets the FakePlayer name's score to 0 (here `onlinePlayers`) and from each loaded entity we want to track (here `type=player`) it will add a score to the specified FakePlayer name (here `onlinePlayers`)
|
||||
通过获取的数值,我们可以使用`/execute if score`命令在满足特定条件时执行自定义操作:
|
||||
- **` n `** 精确匹配数值n
|
||||
- **` n.. `** 数值≥n时触发
|
||||
- **` ..n `** 数值≤n时触发
|
||||
- **` n1..n2 `** 数值在n1到n2区间时触发
|
||||
|
||||
Now based on the values obtained we can use the `/execute if score` command to run our desired commands when certain values are met.
|
||||
- **` n `** any number n
|
||||
- **` n.. `** any number n and above
|
||||
- **` ..n `** any number n and below
|
||||
- **` n1..n2 `** any number n1 to any number n2.
|
||||
## 循环执行配置
|
||||
|
||||
## Tick JSON
|
||||
若使用函数替代命令方块,需将`entity_counter`函数添加至`tick.json`以实现循环持续执行。通过在字符串后添加逗号分隔,可将多个文件添加至`tick.json`。更多信息请参考[函数文档](/wiki/commands/mcfunctions#tick-json)。
|
||||
|
||||
If you are using functions instead of command blocks, the ` entity_counter ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"entity_counter"
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
If using functions, your pack folder structure will be be as follows:
|
||||
使用函数时,资源包文件夹结构如下所示:
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -84,6 +90,6 @@ If using functions, your pack folder structure will be be as follows:
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the scoreboard names (in this case: 'total') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
|
||||
> - ` total_0fe678 `
|
||||
> - ` entity_counter_0fe678.mcfunction `
|
||||
> **注意:** 计分项名称(本例中的'total')可能被他人重复使用。建议在名称后追加`_`和随机字符组合来降低冲突概率,此方法同样适用于`.mcfunction`文件名。例如:
|
||||
> - `total_0fe678`
|
||||
> - `entity_counter_0fe678.mcfunction`
|
||||
@@ -1,14 +1,14 @@
|
||||
---
|
||||
title: Commands
|
||||
title: 命令 Commands
|
||||
categories:
|
||||
- title: General
|
||||
- title: 基础
|
||||
color: green
|
||||
- title: Commands
|
||||
- title: 命令
|
||||
color: green
|
||||
- title: On Event Systems
|
||||
- title: 事件系统
|
||||
color: blue
|
||||
- title: Scoreboard Systems
|
||||
- title: 计分板系统
|
||||
color: blue
|
||||
- title: Techniques
|
||||
- title: 技术
|
||||
color: orange
|
||||
---
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Intro to Command Blocks
|
||||
category: General
|
||||
title: 命令方块入门
|
||||
category: 基础
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
@@ -10,132 +10,122 @@ tags:
|
||||
- info
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 命令方块入门
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Command Blocks are special blocks in Minecraft. The same commands (cheats) you type in chat can be run automatically using command blocks and it can be reused without needing to type all over again.
|
||||
## 简介
|
||||
|
||||
They can only be placed or destroyed by a player with the Operator permission level in gamemode Creative.
|
||||
[由 Bedrock Commands 社区 Discord 提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
## Obtaining
|
||||
命令方块是 Minecraft 中的特殊方块。通过在聊天栏输入的指令(作弊命令)可以通过命令方块自动执行,无需重复输入即可复用。
|
||||
|
||||
1. Open your world settings.
|
||||
2. Under Cheats, toggle "Activate Cheats" setting ON.
|
||||
3. Run `/give @s command_block` command in chat.
|
||||
只有拥有操作员权限的创造模式玩家才能放置或破坏命令方块。
|
||||
|
||||
## Command Block UI
|
||||
## 获取方式
|
||||
|
||||
1. 打开世界设置
|
||||
2. 在「作弊」选项下启用「激活作弊」
|
||||
3. 在聊天栏输入 `/give @s command_block`
|
||||
|
||||
## 命令方块界面
|
||||
|
||||

|
||||
|
||||
## Command Block Types
|
||||
## 命令方块类型
|
||||
|
||||
 **Impulse** runs the command __once__ each time it is powered.
|
||||
 **脉冲型** 在被激活时__单次__执行命令
|
||||
|
||||
 **Chain** runs the command in a sequence, ie. only after the previous command block it is connecting from was run.
|
||||
 **连锁型** 按顺序执行命令,即仅在前置方块执行后触发
|
||||
|
||||
 **Repeat** runs the command every game tick. There are approximately 20 ticks per second. A delay can be applied to adjust how often the command is executed, explained [below](/commands/intro-to-command-blocks#command-block-tick-delay).
|
||||
 **循环型** 每游戏刻执行一次命令(每秒约20刻)。可通过[下文](#命令方块刻延迟)介绍的延迟设置调整执行频率
|
||||
|
||||
## Command Block Conditions
|
||||
## 命令方块条件
|
||||
|
||||
**Conditional** command blocks will run the command only if the previous command block it was connecting from had an output that was `true` (successful)
|
||||
> Conditional command block states are shown by a small indent into the command block's texture, as shown below:
|
||||
> -  Impulse Conditional Command Block
|
||||
> -  Chain Conditional Command Block
|
||||
> -  Repeating Conditional Command Block
|
||||
**条件制约型** 仅当连接的前置方块输出结果为`true`(成功)时执行命令
|
||||
> 条件制约型方块在材质上会显示凹陷箭头标识:
|
||||
> -  脉冲条件制约型
|
||||
> -  连锁条件制约型
|
||||
> -  循环条件制约型
|
||||
|
||||
**Unconditional** command blocks will run the command regardless. Whether the previous command block it was connecting from had an output that was `true` (succesful), `false` (failed) or even if it came with a syntax error the command block will still run the command.
|
||||
**无条件型** 无论前置方块输出结果如何都会执行命令(包括`true`成功、`false`失败甚至语法错误)
|
||||
|
||||
## Command Block Redstone States
|
||||
## 命令方块红石状态
|
||||
|
||||
**Needs Redstone** command block can only be activated with redstone power. Using buttons, levers, redstone torch etc..
|
||||
**需要红石** 必须通过红石信号激活(按钮、拉杆、红石火把等)
|
||||
|
||||
**Always Active** command block will be activated as soon as you close the command block UI.
|
||||
**保持开启** 关闭命令方块界面后立即持续激活
|
||||
|
||||
## Command Block Tick Delay
|
||||
## 命令方块刻延迟
|
||||
|
||||
In this option you may specify how much delay you want there to be before the command block runs the command.
|
||||
|
||||
The ticks refer to Minecraft game ticks. A **tick** is simply a unit of measure for time in games. 1 second in real life is approximately 20 game ticks in Minecraft.
|
||||
设置命令执行前的延迟时间。刻(Tick)是 Minecraft 的时间单位,现实1秒约等于20游戏刻。
|
||||
|
||||
:::tip
|
||||

|
||||
:::
|
||||
|
||||
## Command Block Hover Note
|
||||
## 悬浮提示文本
|
||||
|
||||
This option allows you to put a hovering text on your command blocks. It's useful for giving short-names for easy identification when working with many command blocks.
|
||||
可为命令方块添加悬浮备注,便于在多命令方块系统中快速识别。
|
||||
|
||||
When a command is run, the hover note will be displayed with the output in chat if gamerule `commandblockoutput` is enabled.
|
||||
当`commandblockoutput`游戏规则启用时,命令执行后会在聊天栏显示备注信息。
|
||||

|
||||
|
||||
## Paste Button
|
||||
## 粘贴按钮
|
||||
|
||||

|
||||
|
||||
The paste button allows you to paste commands from your clipboard to the 'Command Input' box.
|
||||
支持将剪贴板内容粘贴至命令输入框
|
||||
|
||||
## Command Block Output
|
||||
## 命令输出管理
|
||||
|
||||
- Toggle the 'Previous Output' button in the command block UI to see command output and block details.
|
||||
- 通过界面中的「上一个输出」按钮查看执行记录
|
||||
- 命令方块中无需输入开头的`/`符号(输入也不会报错)
|
||||
- 红石比较器可读取输出强度(成功时输出1-15信号)
|
||||
- 在聊天栏测试命令:红色文字表示`false`或语法错误,白色表示`true`
|
||||
- 也可通过实际效果判断命令是否成功
|
||||
- 输出值`0`通常表示失败
|
||||
|
||||
- The ` / ` you type before the whole command is not required in a command block but doing so won't cause any errors.
|
||||
### 禁用命令提示
|
||||
在聊天栏输入:
|
||||
- `/gamerule commandblockoutput false` 关闭命令方块提示
|
||||
- `/gamerule sendcommandfeedback false` 关闭聊天指令反馈
|
||||
|
||||
- A redstone comparator can read command blocks outputs. If output is true, it will send anywhere from 1 to 15 redstone signals depending on the output value.
|
||||
## 命令方块布局技巧
|
||||
|
||||
- You can check if a command output is `true`/`false` by running it in chat. A red output will be a `false` output or a syntax error. A white output means command was run successfully.
|
||||
搭建连锁系统时,确保箭头方向正确连接。箭头朝向可通过方块材质判断。
|
||||
|
||||
- You can also tell if a command was `true`/`false` by checking whether action was performed or not.
|
||||
|
||||
- An output with a value of `0` is usually a false output.
|
||||
|
||||
### Disabling Command Messages In Chat
|
||||
Run in Chat:
|
||||
- `/gamerule commandblockoutput false` to disable command block messages in chat.
|
||||
- `/gamerule sendcommandfeedback false` to disable feedback from commands entered in chat.
|
||||
|
||||
## Command Block Placement
|
||||
|
||||
When placing command blocks in a line (arranged to work together) for any system, make sure the consecutive command blocks connect/start from the head of the arrow.
|
||||
|
||||
The arrow/facing direction can be observed from the command block texture.
|
||||
|
||||
**✅ Correct Placement**
|
||||
**✅ 正确布局**
|
||||

|
||||
|
||||
**❌ Incorrect Placement**
|
||||
**❌ 错误布局**
|
||||

|
||||
|
||||
## Troubleshooting Command Blocks
|
||||
## 故障排除指南
|
||||
|
||||
- In world settings, under **Cheats**, make sure command blocks have not been disabled.
|
||||
- 检查世界设置中是否禁用命令方块
|
||||
- 确保`maxcommandchainlength`游戏规则不为0
|
||||
- 排除意外红石信号干扰(红石线、拉杆、火把等)
|
||||
- 切换「需要红石」与「保持开启」模式
|
||||
- 仔细检查方块类型、条件和命令语法,重新激活后查看输出
|
||||
- 确保区块已加载(可使用[常加载区域](/wiki/commands/tickingarea))
|
||||
|
||||
- Make sure gamerule `maxcommandchainlength` is **not** set to 0
|
||||
若仍无法解决,可尝试拆除并重新放置命令方块
|
||||
|
||||
- Make sure there are no unwanted redstone power that is interfering with the command block. It can be from redstone dust, lever, redstone torch etc..
|
||||
## 学习要点
|
||||
|
||||
- Try switching between Always Active & Needs Redstone.
|
||||
|
||||
- Double check the block type, condition & the command syntax. Check 'Previous Output' after powering it once again.
|
||||
|
||||
- Just like redstone, command blocks must also be in loaded chunks for them to work. You can use a tickingarea to keep them loaded when players are not nearby. Refer to [/tickingarea](https://learn.microsoft.com/en-us/minecraft/creator/documents/tickingareacommand) command documentation for more info.
|
||||
|
||||
If nothing seems to work simply break and place that command block again.
|
||||
|
||||
## What you have learned
|
||||
|
||||
:::tip What you have learned:
|
||||
- How to obtain a command block in game.
|
||||
- How the different types of command blocks behave and what they look like.
|
||||
- What the different command block options are (including conditional, state and delay.)
|
||||
- How command blocks output data by redstone and chat messages.
|
||||
- How to properly place command block chains.
|
||||
- How to resolve 'command block not working'
|
||||
:::tip 学习要点:
|
||||
- 游戏内获取命令方块的方法
|
||||
- 各类命令方块的特性与外观识别
|
||||
- 条件设置、红石状态与延迟配置
|
||||
- 通过红石与聊天信息获取输出数据
|
||||
- 正确排列命令方块链的技巧
|
||||
- 常见故障解决方案
|
||||
:::
|
||||
|
||||
To put what you have learned into practice, try making this simple [Entity Counter](/commands/entity-counter) system.
|
||||
> Note: when setting up command block systems, always the first command will be  **`Unconditional Always Active`** and the rest will be  **`Unconditional Always Active`** (all 0 ticks delay) *unless specified otherwise.*
|
||||
实践建议:尝试制作简易的[实体计数器系统](/wiki/commands/entity-counter)
|
||||
> 注意:常规命令链的首个方块应为 **无条件保持开启**,后续使用 **无条件保持开启**(默认0刻延迟)
|
||||
>
|
||||
> 
|
||||
|
||||
**(Recommended) Read Next: [Understanding Selectors](/commands/selectors)**
|
||||
**(推荐延伸阅读)[选择器详解](/wiki/commands/selectors)**
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Functions
|
||||
category: General
|
||||
title: 函数 mcfunction
|
||||
category: 基础
|
||||
mentions:
|
||||
- Bedrock Commands
|
||||
- cda94581
|
||||
@@ -8,19 +8,24 @@ mentions:
|
||||
- jordanparki7
|
||||
nav_order: 3
|
||||
tags:
|
||||
- info
|
||||
- 信息
|
||||
---
|
||||
## Introduction
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
# 函数 mcfunction
|
||||
|
||||
Functions are `.mcfunction` files which contain multiple lines of commands. They are run with the `/function` command in-game.
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Functions are created in a **Behavior Pack**, nested within the **functions** folder. A function pack creates a system using solely function files.
|
||||
## 简介
|
||||
|
||||
Functions are useful in many ways to reduce the time spent going from command block to command block debugging a system. They also help with packaging systems for use in multiple worlds and provide many functions that can change how everything works.
|
||||
[源自 Bedrock Commands 社区 Discord](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
## Function Pack Folder Structure
|
||||
函数是包含多行命令的 `.mcfunction` 文件,可通过游戏中的 `/function` 命令运行。
|
||||
|
||||
函数需要创建在**行为包**的 **functions** 文件夹内。纯函数包系统完全由函数文件构成。
|
||||
|
||||
函数在多个方面非常有用,可以减少逐个命令方块调试系统所花费的时间。同时也便于将系统打包用于多个世界,并提供了许多可以改变整体运行方式的函数。
|
||||
|
||||
## 函数包目录结构
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -34,47 +39,46 @@ Functions are useful in many ways to reduce the time spent going from command bl
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
## Notes For Beginners
|
||||
## 新手须知
|
||||
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
#Spawn Effects
|
||||
::: code-group
|
||||
```yaml [mcfunction]
|
||||
#生成效果
|
||||
effect @a [tag=atSpawn] regeneration 12 255 true
|
||||
effect @a [tag=atSpawn] saturation 12 255 true
|
||||
effect @a [tag=atSpawn] weakness 12 255 true
|
||||
```
|
||||
- Each new line in a function file represents a new command. You may start a line with # to add comments. Commands in a function do not need to begin with a slash `/`, however doing so will not cause any errors.
|
||||
:::
|
||||
|
||||
- All commands in a function are run in the *same tick*. Because of this, a function which causes large changes may cause a sudden lag spike and it is helpful to delegate some commands across multiple ticks, if possible.
|
||||
Commands in a function are still run in the same order, however.
|
||||
- 函数文件中每一新行代表一个新命令。可以使用 `#` 开头添加注释。函数内的命令不需要以斜杠 `/` 开头,但添加了也不会报错。
|
||||
|
||||
- Minecraft can **not** run more than 10,000 lines of commands in one function file. This includes any other function files that are executed inside of the original file.
|
||||
- 函数中的所有命令会在**同一游戏刻**内执行。因此,包含大量变更操作的函数可能导致突然的卡顿,建议尽可能将命令分摊到多个游戏刻中执行。但函数内的命令仍会按顺序依次运行。
|
||||
|
||||
- It is not possible to run conditional commands. Those will still need to utilize command blocks in some way, or could utilize the 1.19.50 execute syntax.
|
||||
- Minecraft **无法**在一个函数文件中运行超过10,000行命令,这包括原始文件中调用的其他函数文件。
|
||||
|
||||
- Running commands with a specified delay in a function would involve using scoreboard timers to incrementally count up every tick (to a certain point), and executing at certain scores along the file. You may refer to [Scoreboard Timers](/commands/scoreboard-timers) system to learn how to set it up.
|
||||
- 无法执行条件型命令。这类命令仍需通过命令方块实现,或使用1.19.50版本的execute语法。
|
||||
|
||||
## Creating a Function
|
||||
- 要在函数中实现延迟执行命令,需使用计分板计时器逐刻计数(达到指定值),并在特定分数时执行命令。可参考[计分板计时器](/wiki/commands/scoreboard-timers)系统了解设置方法。
|
||||
|
||||
1. Locate the `📁 com.mojang` folder and navigate to `📁 development_behavior_packs`
|
||||
- The development folders are used for quick reloading of packs, as the packs aren't cached to the world files.
|
||||
## 创建函数
|
||||
|
||||
2. Create a folder (of any name) for the function pack. This will be referred to as Behavior Pack or BP.
|
||||
1. 找到 `📁 com.mojang` 文件夹并进入 `📁 development_behavior_packs`
|
||||
- 开发文件夹用于快速重载资源包,因为这些包不会被缓存到世界文件中。
|
||||
|
||||
3. Create a `📄 manifest.json` file and a `🖼 pack_icon.png` file (optional) within the BP folder.
|
||||
- A manifest file contains all the information needed to register a pack, while a pack icon displays visually in the pack menu. A pack icon is typically a 128x128 or a 256x256 image, though any power-of-2 resolution will do, they will be upscaled and downscaled accordingly.
|
||||
2. 为函数包创建任意名称的文件夹(称为行为包或BP)。
|
||||
|
||||
<Spoiler title="Sample 📄 manifest.json">
|
||||
3. 在BP文件夹内创建 `📄 manifest.json` 文件和 `🖼 pack_icon.png` 文件(可选)
|
||||
- 清单文件包含注册资源包所需的所有信息,包图标则用于在资源包菜单中显示。包图标建议使用128x128或256x256分辨率(支持2次幂分辨率,会自动缩放)。
|
||||
|
||||
<CodeHeader>BP/manifest.json</CodeHeader>
|
||||
<Spoiler title="示例 📄 manifest.json">
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/manifest.json]
|
||||
{
|
||||
"format_version": 2,
|
||||
"header": {
|
||||
"description": "Write Your Pack Description Here",
|
||||
"name": "Write Your Pack Name Here",
|
||||
"description": "在此填写资源包描述",
|
||||
"name": "在此填写资源包名称",
|
||||
"uuid": "00000000-0000-0000-0000-000000000000",
|
||||
"version": [ 1, 0, 0 ],
|
||||
"min_engine_version": [ 1, 19, 73 ]
|
||||
@@ -89,45 +93,44 @@ Commands in a function are still run in the same order, however.
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Note that the uuid field needs to be replaced with an actual uuid, and the two generated must be different from one another. You can generate a uuid at https://uuidgenerator.net/
|
||||
注意:uuid字段需要替换为实际值,且两个uuid必须不同。可通过 https://uuidgenerator.net/ 生成
|
||||
|
||||
</Spoiler>
|
||||
<Spoiler title="Sample 🖼 pack_icon.png">
|
||||
<Spoiler title="示例 🖼 pack_icon.png">
|
||||
|
||||
Sample A:
|
||||
示例A:
|
||||
|
||||

|
||||
|
||||
Sample B:
|
||||
示例B:
|
||||
|
||||

|
||||
|
||||
</Spoiler>
|
||||
|
||||
4. Create a `📁 functions` folder. Any file within this folder that ends with **.mcfunction** will be registered as a function in-game, which can be run with `/function <function_name>`.
|
||||
- Nested functions are allowed, simply list the file path in relation to the functions folder as shown in the function pack folder structure.
|
||||
4. 创建 `📁 functions` 文件夹。该文件夹内所有以 **.mcfunction** 结尾的文件都将注册为游戏内可用的函数,可通过 `/function <函数名称>` 运行。
|
||||
- 支持嵌套函数,只需按函数包目录结构示例中的方式组织文件路径即可。
|
||||
|
||||
5. Apply the behavior pack in-game and try out the functions. Function file changes can be reflected in the world by running `/reload` or by simply relogging.
|
||||
5. 在游戏中应用行为包并测试函数。修改函数文件后可通过执行 `/reload` 或重新登录来刷新改动。
|
||||
|
||||
:::tip NOTE
|
||||
Functions are versioned; therefore, they will run in the version listed in the `📄 manifest.json`, such as:
|
||||
- `min_engine_version` 1.19.50 or above will adopt the new execute syntax.
|
||||
- `min_engine_version` 1.19.70 or above will require aux values be replaced with block states.
|
||||
:::tip 注意
|
||||
函数具有版本依赖性,将运行在 `📄 manifest.json` 中声明的版本环境下:
|
||||
- `min_engine_version` 1.19.50+ 将采用新版execute语法
|
||||
- `min_engine_version` 1.19.70+ 需将aux值替换为方块状态
|
||||
:::
|
||||
|
||||
## Execution
|
||||
## 执行方式
|
||||
|
||||
Functions can be executed in-game by typing `/function name_of_function`. This will execute all the commands in the function file, all in a single tick.
|
||||
|
||||
Nested functions, for example `BP/functions/lobby/items/1.mcfunction` can be run using the nested folder path, in this case `/function lobby/items/1`
|
||||
在游戏中输入 `/function 函数名称` 即可执行函数文件内的所有命令(同一游戏刻内完成)。例如嵌套函数 `BP/functions/lobby/items/1.mcfunction` 需使用路径 `/function lobby/items/1` 调用。
|
||||
|
||||
## tick.json
|
||||
|
||||
The final file within a function is the **tick.json** file. This specifies functions to run server-side on every game tick, (similar to a repeating command block.) It is located in the `BP/functions` folder. By default, functions running in this file execute at origin `0, 0, 0` in the overworld.
|
||||
**tick.json** 是函数包中的特殊文件,用于指定服务器每游戏刻自动运行的函数(类似循环命令方块)。该文件位于 `BP/functions` 文件夹中,默认在主世界原点坐标 `0, 0, 0` 处执行。
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"function_1",
|
||||
@@ -135,24 +138,26 @@ The final file within a function is the **tick.json** file. This specifies funct
|
||||
]
|
||||
}
|
||||
```
|
||||
> Note: functions in this file are run as soon as the world is *initialized*, regardless of whether or not the player has been *loaded*. This may cause unintended behavior if used incorrectly.
|
||||
:::
|
||||
|
||||
## Sample Function Pack
|
||||
> 注意:该文件中的函数会在世界初始化后立即运行(无论玩家是否加载完毕),使用不当可能导致意外行为。
|
||||
|
||||
## 示例函数包
|
||||
|
||||
<CardLink
|
||||
imgsrcLight="assets/images/commands/BClogo.png"
|
||||
title="Download Sample Function Pack"
|
||||
title="下载示例函数包"
|
||||
link="https://github.com/Bedrock-OSS/wiki-addon/releases/download/download/functions_sample.mcpack"
|
||||
/>
|
||||
|
||||
## Troubleshooting Functions
|
||||
## 函数排错指南
|
||||
|
||||
Your functions may not appear within the command suggestions when using `/function`. This is normally due to an error with one or more commands in the function.
|
||||
使用 `/function` 时若未出现命令建议,通常是由于函数中存在错误命令导致。
|
||||
|
||||
Enabling the [Content Log](/guide/troubleshooting#content-log) in creator settings will allow you to see if there are any errors in your function pack, in which function the error is in, at which line and exactly what the syntax error for that command is.
|
||||
在创作者设置中启用[内容日志](/wiki/guide/troubleshooting#content-log)可查看函数包中的具体错误信息,包括错误所在函数、行号及语法问题。
|
||||
|
||||
The list of errors will be generated every time you load a world or run `/reload` to reflect changes after editing files. The list can be viewed on-screen for a few seconds as well as in the content log history in settings.
|
||||
每次加载世界或执行 `/reload` 后都会生成错误列表,可在屏幕上短暂查看或通过设置中的内容日志历史记录查阅。
|
||||
|
||||

|
||||
|
||||

|
||||

|
||||
File diff suppressed because one or more lines are too long
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: New Execute
|
||||
category: Commands
|
||||
title: 全新execute命令
|
||||
category: 命令
|
||||
tags:
|
||||
- easy
|
||||
- 简单
|
||||
mentions:
|
||||
- JaylyDev
|
||||
- Sprunkles137
|
||||
@@ -12,236 +12,243 @@ mentions:
|
||||
- zheaEvyline
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 全新execute命令
|
||||
|
||||
With the release of 1.19.50, the `/execute` command was given a syntax overhaul. While the syntax is now more verbose and longer to write, it allows much finer control over the contextual components of commands and adds support for conditions to commands, superseding the use of commands like `/testfor`, `/testforblock`, and `/testforblocks`.
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Before we dive into the syntax and how to write it, we need to understand how the old `/execute` command worked, and what changed and why. This will make explaining the concepts found in the syntax easier.
|
||||
## 引言
|
||||
|
||||
## Understanding Execution Context
|
||||
随着1.19.50版本的发布,`/execute`命令迎来了语法革新。虽然新语法需要书写更长的指令,但它能更精细地控制命令的上下文组件,并为命令添加了条件支持,从而取代了`/testfor`、`/testforblock`和`/testforblocks`等命令。
|
||||
|
||||
For both beginners to commands and those well versed in how old `/execute` behaved, it may be a good idea to review the concept of a command's **execution context**.
|
||||
在深入解析语法细节之前,我们需要理解旧版`/execute`的工作原理及其演变逻辑,这将有助于更好地理解新语法中的概念。
|
||||
|
||||
In short, these are the parameters that affects how a command runs. Who the command will run as, also known as its executor; where the command will run, and in which dimension; and the rotation applied to the command are all parameters that can be changed.
|
||||
## 理解执行上下文
|
||||
|
||||
Every command has this context applied to it, and this context changes depending on how the command runs. Commands fired from command blocks do not have an executor, and the position is set to that command block; commands ran from chat define the executor as the player, and it runs at the player's position.
|
||||
无论是命令新手还是熟悉旧版`/execute`的开发者,都有必要重新审视命令的**执行上下文**概念。
|
||||
|
||||
## Execute, and Why it Changed
|
||||
简而言之,这些参数决定了命令的运行方式:命令的执行者(即由谁执行)、执行位置、所在维度以及执行时的视角旋转角度等。
|
||||
|
||||
The `/execute` command executes a command on behalf of one or more entities. The old syntax used to be this:
|
||||
每个命令都携带这样的上下文,且上下文会根据命令的运行方式动态变化。从命令方块触发的命令没有明确执行者,位置固定在命令方块处;通过聊天框执行的命令则以玩家为执行者,并在玩家当前位置运行。
|
||||
|
||||
## Execute命令的演变逻辑
|
||||
|
||||
`/execute`命令允许通过一个或多个实体代理执行命令。旧版语法结构如下:
|
||||
|
||||
```
|
||||
/execute <target> <position> <command>
|
||||
/execute <target> <position> detect <position> <block> <data value> <command>
|
||||
/execute <目标> <位置> <命令>
|
||||
/execute <目标> <位置> detect <位置> <方块> <数据值> <命令>
|
||||
```
|
||||
|
||||
You specified a target to execute as, then the command's context would change to run as that target, and at that target. Any position changes were then always relative to that target.
|
||||
旧语法指定目标后,命令的上下文将切换至该目标的位置执行。所有位置偏移都默认相对于该目标。
|
||||
|
||||
While this is useful in most cases, it also forces the fact that a command's target and its position are always tied together (unless you were to manually insert world coordinates in place of `<position>`). It is also not very malleable in regards to making conditional statements, as you have to execute as an entity every time.
|
||||
虽然这在多数情况下很实用,但也强制绑定了命令目标与执行位置(除非手动输入世界坐标)。同时,在构建条件语句时缺乏灵活性,因为每次都需要通过实体执行。
|
||||
|
||||
Back in the Summer of 2017 during the Update Aquatic's development, the developers of Minecraft: Java Edition were getting feedback from the community on how they can improve the `/execute` command's syntax, and the basic concept that was conceived is this: `/execute` takes an unlimited number of **subcommands** that manipulate certain aspects of the command in the order you specify, then a "run" subcommand is placed at the end to fire a command.
|
||||
在2017年夏季水域更新的开发阶段,Minecraft Java版开发团队收集了社区反馈后,提出了全新设计理念:`/execute`可以串联无限个**子命令**来按序调整命令的不同上下文维度,最后通过"run"子命令触发实际命令。
|
||||
|
||||
This allows for much greater control for what `/execute` can do to a command, and allows splitting up the executor and the command's position.
|
||||
这种设计大幅提升了`/execute`的上下文控制能力,实现了执行者与执行位置的分离。
|
||||
|
||||
## New Syntax
|
||||
## 新语法解析
|
||||
|
||||
Now, let us review the new `/execute` syntax. They are as follows:
|
||||
现在让我们系统梳理新版`/execute`语法结构:
|
||||
|
||||
### `/execute as`
|
||||
|
||||
Changes the executor of the command, or what the target selector `@s` will select.
|
||||
更改命令执行者,即影响目标选择器`@s`的指向。
|
||||
|
||||
```
|
||||
/execute as <origin: target> -> execute
|
||||
/execute as <origin: 目标> -> execute
|
||||
```
|
||||
|
||||
This does not change the position, rotation, or dimension context of the command.
|
||||
此命令不会改变执行位置、视角或维度上下文。
|
||||
|
||||
If multiple targets are specified then a command is ran once for each target, where `@s` selects each entity in turn.
|
||||
若指定多个目标,则依次以每个目标为`@s`执行命令。
|
||||
|
||||
### `/execute at`
|
||||
|
||||
Changes where the command runs, setting the command's position, rotation, and dimension context to the entity.
|
||||
更改命令执行位置,将命令的坐标、视角和维度同步至目标实体。
|
||||
|
||||
```
|
||||
/execute at <origin: target> -> execute
|
||||
/execute at <origin: 目标> -> execute
|
||||
```
|
||||
|
||||
This does not change the executor of the command, so `@s` will remain as whoever was targeted last.
|
||||
此命令不会改变执行者身份,故`@s`仍指向最近一次指定的目标。
|
||||
|
||||
If multiple targets are specified then a command is ran once for each target, setting the position, rotation, and dimension context to each target.
|
||||
若指定多个目标,则依次在目标位置执行命令。
|
||||
|
||||
### `/execute in`
|
||||
|
||||
Sets the dimension in which the command should run.
|
||||
设置命令执行的维度环境。
|
||||
|
||||
```
|
||||
/execute in <dimension: string> -> execute
|
||||
/execute in <dimension: 字符串> -> execute
|
||||
```
|
||||
|
||||
Currently accepted values are `overworld`, `nether`, and `the_end`.
|
||||
当前可用维度标识符为`overworld`、`nether`和`the_end`。
|
||||
|
||||
This change in dimension will respect that dimension's scale; going from the Overworld to The Nether will apply a scale of x0.125 to the position, and vice versa will apply a x8 scale to the position.
|
||||
维度切换时会自动换算坐标比例(如主世界至下界应用x0.125缩放,反之则x8放大)。
|
||||
|
||||
### `/execute positioned`
|
||||
|
||||
Directly sets the position context of the command.
|
||||
直接设定命令执行坐标。
|
||||
|
||||
```
|
||||
/execute positioned <position: x y z> -> execute
|
||||
```
|
||||
|
||||
Sets the position of the command to specific values. [Relative and local coordinates](/commands/relative-coordinates) are based around the current position of the command.
|
||||
将命令位置设为指定坐标。[相对坐标与局部坐标](/wiki/commands/relative-coordinates)基于当前命令位置计算。
|
||||
|
||||
```
|
||||
/execute positioned as <origin: target> -> execute
|
||||
/execute positioned as <origin: 目标> -> execute
|
||||
```
|
||||
|
||||
Sets the position of the command to a target's location. This is similar to how `/execute at` works, but it only sets the command's position and not its rotation or dimension.
|
||||
将命令位置同步至目标坐标。功能类似`/execute at`,但仅改变位置不改变视角与维度。
|
||||
|
||||
If multiple targets are specified then a command is ran once for each target, setting the position context to the target's position.
|
||||
若指定多个目标,则依次在目标位置执行命令。
|
||||
|
||||
### `/execute align`
|
||||
|
||||
Aligns the current position of the command to the block grid.
|
||||
将当前命令位置对齐至方块网格。
|
||||
|
||||
```
|
||||
/execute align <axes: swizzle> -> execute
|
||||
/execute align <axes: 轴组合> -> execute
|
||||
```
|
||||
|
||||
Aligning a position will floor it. This subcommand accepts any non-repeating combination of the letters "x", "y", and "z", and will floor the position along each axis specified.
|
||||
对齐操作将坐标向下取整。本子命令接受由"x"、"y"、"z"组成的非重复组合,对指定轴进行取整。
|
||||
|
||||
### `/execute anchored`
|
||||
|
||||
Sets the anchor of the command to the executor's feet or eyes. Changing the anchor will affect the position where local coordinates will start at.
|
||||
设置命令的锚点位置(脚部或眼部),影响局部坐标基准。
|
||||
|
||||
```
|
||||
/execute anchored (eyes|feet) -> execute
|
||||
```
|
||||
|
||||
The default anchor when executing at a target is their feet.
|
||||
默认锚点为脚部。
|
||||
|
||||
When the anchor is set to `eyes`, the command's local position is offset by some amount corresponding to the "eye height" of the current executor.
|
||||
当锚点设为`eyes`时,命令的局部坐标会根据执行者的"眼高"进行偏移。
|
||||
|
||||
This offset should only apply to local coordinates, but it currently affects relative coordinates due to a bug: [MCPE-162681](https://bugs.mojang.com/browse/MCPE-162681).
|
||||
注意:由于漏洞[MCPE-162681](https://bugs.mojang.com/browse/MCPE-162681),当前该设置会影响相对坐标。
|
||||
|
||||
### `/execute rotated`
|
||||
|
||||
Directly sets the rotation context of the command.
|
||||
直接设定命令执行视角。
|
||||
|
||||
```
|
||||
/execute rotated <yaw: value> <pitch: value> -> execute
|
||||
/execute rotated <yaw: 值> <pitch: 值> -> execute
|
||||
```
|
||||
|
||||
Sets the rotation of the command to specific values. Relative and local coordinates are based around the current rotation of the command. This defaults to 0 for both pitch and yaw, unless the rotation was changed prior.
|
||||
设置具体视角参数。相对坐标与局部坐标基于当前视角计算,默认值为0(若未变更过视角)。
|
||||
|
||||
```
|
||||
/execute rotated as <origin: target> -> execute
|
||||
/execute rotated as <origin: 目标> -> execute
|
||||
```
|
||||
|
||||
Sets the rotation of the command to a target's rotation.
|
||||
同步目标实体的视角参数。
|
||||
|
||||
If multiple targets are specified then a command is ran once for each target, setting the rotation context to the target's rotation.
|
||||
若指定多个目标,则依次应用目标视角执行命令。
|
||||
|
||||
### `/execute facing`
|
||||
|
||||
Sets the rotation of the command to face some position. This rotation is calculated based on the current position of the command.
|
||||
设置命令视角朝向特定坐标或实体部位。
|
||||
|
||||
```
|
||||
/execute facing <position: x y z> -> execute
|
||||
```
|
||||
|
||||
Sets the rotation to face a block position. Relative and local coordinates are based around the current position of the command.
|
||||
使命令视角朝向指定方块坐标,基于当前命令位置计算。
|
||||
|
||||
```
|
||||
/execute facing entity <origin: target> (eyes|feet) -> execute
|
||||
/execute facing entity <origin: 目标> (eyes|feet) -> execute
|
||||
```
|
||||
|
||||
Sets the rotation to face a target's position. Setting the anchor to `feet` will aim the rotation to face where they are currently standing, while setting the anchor to `eyes` will aim the command up at the "eye position" of that target (see [`/execute anchored`](/commands/new-execute#execute-anchored)).
|
||||
使命令视角朝向目标实体部位。选择`feet`锚点将瞄准脚部位置,`eyes`则瞄准眼部(参考[`/execute anchored`](/wiki/commands/new-execute#execute-anchored))。
|
||||
|
||||
If multiple targets are specified then a command is ran once for each target, setting the rotation context to face that target.
|
||||
若指定多个目标,则依次应用目标朝向执行命令。
|
||||
|
||||
### `/execute (if|unless)`
|
||||
|
||||
Prevents running a command based on a condition. If the condition is true then the command will continue, or stop otherwise.
|
||||
|
||||
`/execute unless` acts as the opposite, testing if the condition is false in order to continue.
|
||||
根据条件判断是否执行命令。`if`在条件为真时继续,`unless`则相反。
|
||||
|
||||
```
|
||||
/execute if entity <target: target> -> execute
|
||||
/execute if entity <target: 目标> -> execute
|
||||
```
|
||||
|
||||
Acts like `/testfor`. Returns true if the targets exist.
|
||||
类似`/testfor`,检测目标是否存在。
|
||||
|
||||
```
|
||||
/execute if block <position: x y z> <block: string> -> execute
|
||||
/execute if block <position: x y z> <block: 字符串> -> execute
|
||||
```
|
||||
|
||||
Acts like `/testforblock`. Returns true if the block at the specified location exists.
|
||||
类似`/testforblock`,检测指定位置方块。
|
||||
|
||||
A data value or block state may additionally be specified, otherwise it ignores block states (acts as if it were set to `-1`).
|
||||
可附加数据值或方块状态参数,否则忽略状态(等效于`-1`)。
|
||||
|
||||
```
|
||||
/execute if blocks <begin: x y z> <end: x y z> <destination: x y z> (all|masked) -> execute
|
||||
```
|
||||
|
||||
Acts like `/testforblocks`. It constructs a volume between the beginning and end positions, and returns true if the volume at the destination matches the original volume.
|
||||
类似`/testforblocks`,比对源区域与目标区域的方块布局。
|
||||
|
||||
The parameter `all` tests that all blocks must match, while `masked` will ignore air blocks.
|
||||
`all`参数要求完全匹配,`masked`忽略空气方块。
|
||||
|
||||
```
|
||||
/execute if score <target: target> <objective: string> matches <range: integer range> -> execute
|
||||
/execute if score <target: 目标> <objective: 字符串> matches <range: 整数范围> -> execute
|
||||
```
|
||||
|
||||
Tests if a specified score is a certain value. This uses the integer range syntax.
|
||||
检测指定分数是否符合数值范围(使用整数区间语法)。
|
||||
|
||||
```
|
||||
/execute if score <target: target> <objective: string> (=|<|<=|>|>=) <source: target> <objective: string> -> execute
|
||||
/execute if score <target: 目标> <objective: 字符串> (=|<|<=|>|>=) <source: 目标> <objective: 字符串> -> execute
|
||||
```
|
||||
|
||||
Tests if a specified score matches some logical comparison to another score. Operators are equals (`=`), greater than (`>`), greater than or equal to (`>=`), less than (`<`), and less than or equal to (`<=`).
|
||||
比对两个分数的逻辑关系,支持等于(`=`)、大于(`>`)、大于等于(`>=`)、小于(`<`)、小于等于(`<=`)。
|
||||
|
||||
### `/execute run`
|
||||
|
||||
```
|
||||
/execute run <command: command>
|
||||
/execute run <command: 命令>
|
||||
```
|
||||
|
||||
Runs a command using all of the currently applied context modifications. This subcommand always goes last in one `/execute` command.
|
||||
应用所有上下文修改后执行指定命令。本子命令必须作为`/execute`链的末尾。
|
||||
|
||||
This subcommand is not always required however; an `/execute` command ending with an `if` or `unless` subcommand is valid too, and will return the success of the test it performed.
|
||||
注意:当`/execute`链以`if`或`unless`结尾时,可不带`run`直接返回检测结果。
|
||||
|
||||
## Examples and Upgrading Old Commands
|
||||
## 实例解析与旧指令升级
|
||||
|
||||
Since subcommands can be chained limitlessly, there really is a nearly infinite combination of arguments for an `/execute` command and they cannot all be listed. Instead, listed here are some common examples of commands.
|
||||
由于子命令可无限串联,实际组合方式近乎无限。以下列举典型应用场景:
|
||||
|
||||
The old functionality of `/execute` can be replicated with `as <target> at @s`. If you need a positional offset relative to the entity, add `positioned`. If you want to detect if a block is present, add `if block`. Here are some equivalents:
|
||||
旧版`/execute`功能可通过`as <目标> at @s`复现。如需相对位置偏移,添加`positioned`;如需方块检测,添加`if block`。示例如下:
|
||||
|
||||
```
|
||||
# Teleport with an offset
|
||||
::: code-group
|
||||
```mcfunction [旧版偏移传送]
|
||||
/execute @p ~ ~1.62 ~ teleport @s ^ ^ ^3
|
||||
|
||||
```
|
||||
```mcfunction [新版等效]
|
||||
/execute as @p at @s positioned ~ ~1.62 ~ run teleport @s ^ ^ ^3
|
||||
```
|
||||
:::
|
||||
|
||||
```
|
||||
# Chaining multiple '/execute's
|
||||
::: code-group
|
||||
```mcfunction [旧版链式检测]
|
||||
/execute @e[type=sheep] ~ ~ ~ execute @e[type=item,r=5] ~ ~ ~ detect ~ ~-1 ~ stone 0 kill @s
|
||||
|
||||
```
|
||||
```mcfunction [新版等效]
|
||||
/execute at @e[type=sheep] as @e[type=item,r=5] at @s if block ~ ~-1 ~ stone 0 run kill @s
|
||||
```
|
||||
:::
|
||||
|
||||
(Note that we do not use `as @e[type=sheep] at @s` because we do not need to execute as the sheep; only the position here is required.)
|
||||
(注意此处使用`at @e[type=sheep]`而非`as`,因为只需位置信息)
|
||||
|
||||
Now for some examples of things that were not possible to do in one command, or were more difficult to perform before the new syntax was introduced.
|
||||
新版语法还支持许多旧版难以实现的功能:
|
||||
|
||||
```
|
||||
# Testing a fake player's score
|
||||
/execute if score game_settings var matches 3.. run say [Game] Difficulty set to Hard.
|
||||
::: code-group
|
||||
```mcfunction [检测虚拟玩家分数]
|
||||
/execute if score game_settings var matches 3.. run say [游戏] 难度已设为困难。
|
||||
|
||||
# Comparing if two scores are equal
|
||||
/execute as @a if score @s x = @s y run say My X is equal to my Y.
|
||||
```mcfunction [分数比对]
|
||||
/execute as @a if score @s x = @s y run say 我的X值等于Y值。
|
||||
|
||||
# Test for an entity without targeting it
|
||||
```mcfunction [非选中实体检测]
|
||||
/execute as @a at @s if entity @e[type=armor_stand,r=10] run gamemode survival @s
|
||||
```
|
||||
:::
|
||||
@@ -1,61 +1,64 @@
|
||||
---
|
||||
title: On First Join
|
||||
category: On Event Systems
|
||||
title: 首次进入时
|
||||
category: 事件系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
- SmokeyStack
|
||||
nav_order: 1
|
||||
tags:
|
||||
- system
|
||||
- 系统
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 首次进入时
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system will run your desired commands on the event that a player joins the world for the first time.
|
||||
## 简介
|
||||
|
||||
[由Bedrock Commands社区Discord提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
本系统将在玩家首次进入世界时执行你预设的命令。
|
||||
|
||||
## System
|
||||
<CodeHeader>BP/functions/on_first_join.mcfunction</CodeHeader>
|
||||
## 系统实现
|
||||
|
||||
```yaml
|
||||
#Your Commands Here (examples)
|
||||
give @a [tag=!joined] stone_pickaxe
|
||||
give @a [tag=!joined] bread 16 1
|
||||
tag @a [tag=!joined] add joined
|
||||
::: code-group
|
||||
```yaml [BP/functions/on_first_join.mcfunction]
|
||||
# 在此处输入你的命令(示例)
|
||||
give @a[tag=!joined] stone_pickaxe
|
||||
give @a[tag=!joined] bread 16 1
|
||||
tag @a[tag=!joined] add joined
|
||||
```
|
||||
:::
|
||||
|
||||

|
||||

|
||||
|
||||
我们以两个`give`命令为例,你可以根据需求使用任意命令组合。请确保遵循以下要点:
|
||||
- 保持示例中的执行顺序
|
||||
- 在选择器参数中正确添加`tag=!joined`条件
|
||||
|
||||
Here we have used 2 `give` commands as example but you can use any command you prefer and as many as you require.
|
||||
## 原理说明
|
||||
|
||||
Just make sure to follow the given order and properly add the selector argument ` tag=!joined ` as shown for your desired commands.
|
||||
当玩家首次加入世界时,他们不会携带`joined`标签。系统通过检测未拥有该标签的玩家执行预设命令后,会立即为其添加标签以防止重复执行。
|
||||
|
||||
## Explanation
|
||||
若需要重置玩家状态,可通过以下命令移除标签:
|
||||
`tag <玩家名> remove joined`
|
||||
|
||||
When the player joins the world for the first time, they will not have the joined tag.
|
||||
## 时钟函数配置
|
||||
|
||||
Once we run our desired commands for players without the tag, they will be given the tag immediately and the commands will not repeat for them again unless we remove their tag with:
|
||||
`tag <player> remove joined`
|
||||
若使用函数替代命令方块,需将`on_first_join`函数添加至`tick.json`以实现循环检测。多个函数可通过逗号分隔添加,详见[函数文档](/wiki/commands/mcfunctions#tick-json)。
|
||||
|
||||
## Tick JSON
|
||||
|
||||
If you are using functions instead of command blocks, the ` on_first_join ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"on_first_join"
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
If using functions, your pack folder structure will be be as follows:
|
||||
使用函数时资源包结构如下:
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -68,6 +71,6 @@ If using functions, your pack folder structure will be be as follows:
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the tag names (in this case: 'joined') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
|
||||
> - ` joined_0fe678 `
|
||||
> - ` on_first_join_0fe678.mcfunction `
|
||||
> **注意:** 标签名称(如本例中的'joined')可能与其他开发者重复。建议在名称后追加`_`和随机字符组合来降低冲突概率,此方法同样适用于函数文件名。例如:
|
||||
> - `joined_0fe678`
|
||||
> - `on_first_join_0fe678.mcfunction`
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: On First World Load
|
||||
category: On Event Systems
|
||||
title: 首次世界加载时
|
||||
category: 事件系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
@@ -8,59 +8,62 @@ mentions:
|
||||
- cda94581
|
||||
nav_order: 6
|
||||
tags:
|
||||
- system
|
||||
- 系统
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 首次世界加载时
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system will run your desired commands on the event that the world is loaded for the first time.
|
||||
> **Note:** a [Function](/commands/mcfunctions) Pack is required to achieve this system since it is the `tick.json` file which allows us to run commands as soon as the world is initialised.
|
||||
[由Bedrock Commands社区提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
此系统将在世界首次加载时运行你指定的命令。
|
||||
> **注意:** 实现本系统需要[函数包](/wiki/commands/mcfunctions),因为需要依赖 `tick.json` 文件在游戏初始化时立即执行命令。
|
||||
|
||||
## Tick Json
|
||||
## Tick配置文件
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"initialise"
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## System
|
||||
## 系统实现
|
||||
|
||||
<CodeHeader>BP/functions/initialise.mcfunction</CodeHeader>
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [BP/functions/initialise.mcfunction]
|
||||
scoreboard objectives add world dummy
|
||||
scoreboard players add initialised world 0
|
||||
|
||||
|
||||
#Your Commands Here (example)
|
||||
execute if score initialised world matches 0 run say New world created!
|
||||
# 在此处添加你的命令(示例)
|
||||
execute if score initialised world matches 0 run say 新世界已创建!
|
||||
|
||||
|
||||
scoreboard players set initialised world 1
|
||||
```
|
||||
:::
|
||||
|
||||
Here we have used an `execute - say` command as an example but you can use any command you prefer and as many as you require.
|
||||
示例中使用的是 `execute - say` 命令组合,你可以根据需求自由替换为任意命令,并添加任意数量的命令。
|
||||
|
||||
Just make sure to follow the given order and properly use the `execute if score` command as shown to run the commands you need.
|
||||
请确保遵循给定的命令顺序,并正确使用示例中演示的 `execute if score` 条件判断来执行你的命令。
|
||||
|
||||
## Explanation
|
||||
## 运行原理
|
||||
|
||||
- **` initialised=0 `** this means the world has just initialised and we are yet to run the initlisation commands.
|
||||
- **` initialised=1 `** this means the world has been initialised and we have already run the initialisation commands.
|
||||
- **`initialised=0`** 表示世界刚刚初始化,尚未执行初始化命令
|
||||
- **`initialised=1`** 表示世界已完成初始化,且初始化命令已执行完毕
|
||||
|
||||
An objective of the name `world` is added for us to save scores to it so that we can track whether the world has been initialised or not. This also allows us to structure our commands to only execute at world initialisation.
|
||||
我们通过名为 `world` 的计分板目标来存储分数值,以此追踪世界是否已经过初始化。这种机制可以确保初始化命令仅在首次加载时执行。
|
||||
|
||||
Following the creation of the objective, a score of `0` is added to the FakePlayer name `initialised`. This will register it to the objective and enable us to use the `execute if score` command structure to run our desired commands.
|
||||
创建计分板目标后,我们为虚拟玩家 `initialised` 设置初始分数 `0`。这会将虚拟玩家注册到计分板中,便于后续使用 `execute if score` 条件判断。
|
||||
|
||||
Finally the score for `initialised` is set to 1 after all the commands are run in order to prevent it from executing more than once.
|
||||
最后在所有命令执行完毕后,将 `initialised` 的分数设置为 `1`,防止初始化命令重复执行。
|
||||
|
||||
## Folder Structure
|
||||
## 文件结构
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -73,6 +76,6 @@ Finally the score for `initialised` is set to 1 after all the commands are run i
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the scoreboard names (in this case: 'world') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
|
||||
> - ` world_0fe678 `
|
||||
> - ` initialise_0fe678.mcfunction `
|
||||
> **注意:** 计分板名称(本例中的'world')可能与其他开发者重复。建议在名称后追加 `_` 和随机字符组合来降低冲突概率,此技巧同样适用于 `.mcfunction` 文件名。例如:
|
||||
> - `world_0fe678`
|
||||
> - `initialise_0fe678.mcfunction`
|
||||
@@ -1,75 +1,77 @@
|
||||
---
|
||||
title: On Player Death
|
||||
category: On Event Systems
|
||||
title: 玩家死亡事件
|
||||
category: 事件系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
nav_order: 4
|
||||
tags:
|
||||
- system
|
||||
- 系统
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 玩家死亡事件
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system will run your desired commands on the event that a player dies.
|
||||
## 系统介绍
|
||||
|
||||
## Setup
|
||||
[由Bedrock Commands社区Discord提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
*To be typed in Chat:*
|
||||
本系统将在玩家死亡时执行你预设的命令。
|
||||
|
||||
## 系统配置
|
||||
|
||||
*在聊天栏输入以下指令:*
|
||||
|
||||
`/scoreboard objectives add alive dummy`
|
||||
|
||||
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
|
||||
若希望在世界初始化时自动创建计分板,请参考[首次世界加载事件](/wiki/commands/on-first-world-load)中的操作流程。
|
||||
|
||||
## System
|
||||
## 系统实现
|
||||
|
||||
<CodeHeader>BP/functions/on_player_death.mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [BP/functions/on_player_death.mcfunction]
|
||||
scoreboard players set @a [scores={alive=!2}] alive 0
|
||||
scoreboard players set @e [type=player] alive 1
|
||||
|
||||
|
||||
#Your Commands Here (example)
|
||||
execute as @a [scores={alive=0}] run say I died
|
||||
#在此处添加你的命令(示例)
|
||||
execute as @a [scores={alive=0}] run say 我死了
|
||||
|
||||
|
||||
scoreboard players set @a [scores={alive=0}] alive 2
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
我们以`/execute - say`指令为例,你可以根据需求替换为任意指令并自由扩展数量。
|
||||
|
||||
请严格遵循给定顺序,并确保在目标指令中正确添加选择器参数`scores={alive=0}`。
|
||||
|
||||
## 系统原理
|
||||
|
||||
- **`alive=0`** 表示玩家处于死亡状态
|
||||
- **`alive=1`** 表示玩家处于存活状态
|
||||
- **`alive=2`** 表示已对死亡玩家执行过预设命令
|
||||
|
||||
|
||||
Here we have used an `/execute - say` command as an example but you can use any command you prefer and as many as you require.
|
||||
|
||||
Just make sure to follow the given order and properly add the selector argument ` scores={alive=0} ` as shown for your desired commands.
|
||||
|
||||
## Explanation
|
||||
|
||||
- **` alive=0 `** this means player is dead.
|
||||
- **` alive=1 `** this means player is alive.
|
||||
- **` alive=2 `** this means player is dead and we have run our desired commands on/from them.
|
||||
- **`@a`** 选择器会选中所有玩家(无论生死),因此我们用它将所有玩家标记为0(死亡)
|
||||
- 注意:需要排除已标记为2的玩家,否则会导致命令在死亡玩家身上重复执行
|
||||
|
||||
|
||||
- **` @a `** selector will target all players alive/dead so we use it to mark everyone as 0 'dead.'
|
||||
- Note: we will ignore 2 or it will end up making the commands execute on dead players again. We only want our commands to execute once.
|
||||
- **`@e`** 选择器仅会选中存活玩家,因此我们用它将所有存活玩家标记为1(存活)
|
||||
|
||||
|
||||
- **` @e `** selector on the other hand will only target players who are alive, so we can use this to mark all alive players 1 'alive.'
|
||||
- 通过上述标记,我们可以在死亡玩家(标记0)身上执行预设命令
|
||||
- 执行后需将其分数设为2,否则命令会在玩家复活前持续执行
|
||||
|
||||
|
||||
- Now that dead players are 0 and alive players are 1 we can use this knowledge to run our desired commands on the dead players.
|
||||
- Keep in mind we need to set their score to 2 after or otherwise the commands will keep executing till they respawn.
|
||||
## 循环执行配置
|
||||
|
||||
若使用函数实现,需将`on_player_death`函数添加至`tick.json`以实现循环执行。多个函数可通过逗号分隔添加,详见[函数文档](/wiki/commands/mcfunctions#tick-json)。
|
||||
|
||||
## Tick JSON
|
||||
|
||||
If you are using functions instead of command blocks, the ` on_player_death ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"on_player_death"
|
||||
@@ -77,7 +79,7 @@ If you are using functions instead of command blocks, the ` on_player_death ` fu
|
||||
}
|
||||
```
|
||||
|
||||
If using functions, your pack folder structure will be be as follows:
|
||||
使用函数时,资源包文件夹结构如下:
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -90,6 +92,6 @@ If using functions, your pack folder structure will be be as follows:
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the scoreboard names (in this case: 'alive') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
|
||||
> - ` alive_0fe678 `
|
||||
> - ` on_player_death_0fe678.mcfunction `
|
||||
> **注意:** 计分板名称(如本例中的'alive')可能被他人重复使用。建议在名称后追加`_`和随机字符来降低冲突概率,函数文件名也可采用相同策略。例如:
|
||||
> - `alive_0fe678`
|
||||
> - `on_player_death_0fe678.mcfunction`
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: On Player Join
|
||||
category: On Event Systems
|
||||
title: 玩家加入事件响应
|
||||
category: 事件系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
@@ -9,66 +9,72 @@ tags:
|
||||
- system
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 玩家加入事件响应
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system will run your desired commands on the event that a players joins the world.
|
||||
## 简介
|
||||
|
||||
## Setup
|
||||
[由Bedrock Commands社区Discord提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
*To be typed in Chat:*
|
||||
本系统可在玩家加入世界时触发预设命令的执行。
|
||||
|
||||
## 设置
|
||||
|
||||
*在聊天栏输入以下指令:*
|
||||
|
||||
`/scoreboard objectives add joined dummy`
|
||||
|
||||
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
|
||||
若需实现世界初始化时自动创建记分板项,请参照[首次世界加载事件响应](/wiki/commands/on-first-world-load)的操作流程。
|
||||
|
||||
## System
|
||||
## 系统实现
|
||||
|
||||
<CodeHeader>BP/functions/on_player_join.mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [BP/functions/on_player_join.mcfunction]
|
||||
scoreboard players add @a joined 0
|
||||
|
||||
|
||||
#Your Commands Here (example)
|
||||
#在此处添加你的命令(示例)
|
||||
tp @a[scores={joined=0}] 0 65 0
|
||||
|
||||
|
||||
scoreboard players reset * joined
|
||||
scoreboard players set @a joined 1
|
||||
```
|
||||
:::
|
||||
|
||||

|
||||

|
||||
|
||||
示例中使用了`tp`传送命令,您可以根据实际需求替换为任意命令,并自由扩展命令数量。
|
||||
|
||||
Here we have used a `tp` command as an example but you can use any command you prefer and as many as you require.
|
||||
请确保保持现有执行顺序,并为目标命令正确添加选择器参数 `scores={joined=0}`。
|
||||
|
||||
Just make sure to follow the given order and properly add the selector argument ` scores={joined=0} ` as shown for your desired commands.
|
||||
## 原理说明
|
||||
|
||||
## Explanation
|
||||
当玩家加入时,系统会为其记分板项赋初始值0,这使我们能够通过`scores`选择器参数定位新加入玩家。
|
||||
|
||||
When the player joins, a 0 is added to their objective, this allows us to run commands from them using the 'scores' selector argument.
|
||||
在命令执行完毕后立即执行以下操作:
|
||||
1. 使用通配符`*`重置所有玩家的记分板值
|
||||
2. 为保持在线状态的玩家设置值1
|
||||
|
||||
Immediately after the commands are run, we reset all the scores on the objective using wildcard **` * `** and only players who stayed online will have their score set to 1.
|
||||
|
||||
And this way, since our commands only target players with the score 0, the commands won't repeat again for the players who stayed unless they leave and rejoin or if we run:
|
||||
通过这种机制,由于所有命令仅针对记分板值为0的玩家,已在线玩家不会重复触发响应,除非他们退出后重新加入,或手动执行:
|
||||
`/scoreboard players set <player> joined 0`
|
||||
|
||||
## Tick JSON
|
||||
## 时钟函数配置
|
||||
|
||||
If you are using functions instead of command blocks, the ` on_player_join ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
|
||||
若使用函数替代命令方块,需将`on_player_join`函数添加至`tick.json`以实现循环执行。多个函数可通过逗号分隔添加,详见[函数文档](/wiki/commands/mcfunctions#tick-json)。
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"on_player_join"
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
If using functions, your pack folder structure will be be as follows:
|
||||
使用函数时资源包目录结构如下:
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -81,6 +87,6 @@ If using functions, your pack folder structure will be be as follows:
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the scoreboard names (in this case: 'joined') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
|
||||
> - ` joined_0fe678 `
|
||||
> - ` on_player_join_0fe678.mcfunction `
|
||||
> **注意:** 记分板名称(本例中的'joined')可能与其他开发者重复使用。建议在名称后追加`_`和随机字符组合以降低冲突概率,函数文件名也可采用类似处理方式。例如:
|
||||
> - `joined_0fe678`
|
||||
> - `on_player_join_0fe678.mcfunction`
|
||||
@@ -1,87 +1,89 @@
|
||||
---
|
||||
title: On Player Leave
|
||||
category: On Event Systems
|
||||
title: 玩家离开事件系统
|
||||
category: 事件系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
nav_order: 3
|
||||
tags:
|
||||
- system
|
||||
- 系统
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 玩家离开事件系统
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system will run your desired commands on the event that a player leaves the world.
|
||||
## 简介
|
||||
|
||||
> **Note:** you cannot execute commands on the *players* that leave using selectors. However; you may use the [On Player Join](/commands/on-player-join) system to execute when they join back.
|
||||
[由 Bedrock Commands 社区 Discord 提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
## Setup
|
||||
本系统可在玩家离开世界时运行你指定的命令。
|
||||
|
||||
*To be typed in Chat:*
|
||||
> **注意:** 无法通过选择器对离开的玩家本体执行命令。但你可以使用[玩家加入事件系统](/wiki/commands/on-player-join)在他们重新加入时执行命令。
|
||||
|
||||
## 系统搭建
|
||||
|
||||
*在聊天栏输入以下指令:*
|
||||
|
||||
`/scoreboard objectives add total dummy`
|
||||
|
||||
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
|
||||
若希望在世界初始化时自动添加计分项,请参照[首次世界加载事件系统](/wiki/commands/on-first-world-load)的操作流程。
|
||||
|
||||
## System
|
||||
## 系统核心
|
||||
|
||||
<CodeHeader>BP/functions/on_player_leave.mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [BP/functions/on_player_leave.mcfunction]
|
||||
scoreboard players reset new total
|
||||
execute as @a run scoreboard players add new total 1
|
||||
scoreboard players operation new total -= old total
|
||||
|
||||
|
||||
#Your Commands Here (example)
|
||||
execute if score new total matches ..-1 run say a player has left the world
|
||||
#在此处输入你的命令(示例)
|
||||
execute if score new total matches ..-1 run say 有玩家离开了世界
|
||||
|
||||
|
||||
scoreboard players reset old total
|
||||
execute as @a run scoreboard players add old total 1
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
Here we have used a **`/say`** command as an example but you can use any command you prefer and as many as you require.
|
||||
此处我们以 **`/say`** 命令作为示例,你可以根据需要替换为任意命令并自由扩展。
|
||||
|
||||
Just make sure to follow the given order and properly use the `/execute if score` command as shown to run the commands you need.
|
||||
请严格按照给定顺序排列命令,并正确使用示例中的 `/execute if score` 命令结构来触发你的自定义命令。
|
||||
|
||||
## Explanation
|
||||
## 原理说明
|
||||
|
||||
- **` new `** this FakePlayer name means the total number of players on the world in the current game tick.
|
||||
- **` old `** this FakePlayer name means the total number of players that were on the world in the previous game tick but also saves the values to be used in the *next* game tick.
|
||||
- **` new `** 这个虚拟玩家名称表示当前游戏刻中世界内的玩家总数
|
||||
- **` old `** 这个虚拟玩家名称表示前一游戏刻的玩家总数,同时会将数值保存供下一游戏刻使用
|
||||
|
||||
These values are obtained using the [Entity Counter](/commands/entity-counter) system. It may be beneficial to refer to that doc for better understanding this one.
|
||||
这些数值通过[实体计数系统](/wiki/commands/entity-counter)获取,建议结合该文档以获得更深入的理解。
|
||||
|
||||
By subtracting 'old' total from 'new' total we will be able to identify if player count has:
|
||||
- decreased ` ..-1 `
|
||||
- increased ` 1.. `
|
||||
- or if it's unchanged ` 0 `
|
||||
通过从'new'总数中减去'old'总数,我们可以判断玩家数量是否发生:
|
||||
- 减少 ` ..-1 `
|
||||
- 增加 ` 1.. `
|
||||
- 或保持不变 ` 0 `
|
||||
|
||||
If it has decreased; we know that 1 or more players have left the game.
|
||||
With this knowledge we can run our desired commands from 'new' if it's score is -1 or less.
|
||||
- ie, if there were 10 players and someone leaves:
|
||||
- that is ` new - old `
|
||||
- which is ` 9 - 10 = -1 `
|
||||
- hence we will detect by ` ..-1 `
|
||||
当检测到数值减少时(即得分为-1或更低),我们就能确定有1名或更多玩家离开了游戏。
|
||||
- 示例:原有10名玩家时有人离开
|
||||
- 计算式为 ` new - old `
|
||||
- 即 ` 9 - 10 = -1 `
|
||||
- 因此通过 ` ..-1 ` 条件检测
|
||||
|
||||
- The 'new' total value is obtained first, subtraction is performed after that to run your desired commands and lastly the 'old' total value is obtained to be used in the next game tick.
|
||||
- 系统首先获取'new'总数,执行减法运算后运行你的自定义命令,最后获取'old'总数供下一游戏刻使用
|
||||
|
||||
:::tip
|
||||
All commands involved in a command-block-chain or function will only run in a sequence one after the other but it all still happens in the same tick regardless of the number of commands involved. We are able to achieve this system due to the fact that commands run along the end of a game tick after all events such as player log in, log out, death etc.. occur.
|
||||
:::tip 游戏刻解析
|
||||
所有在命令方块链或函数中运行的指令都会在同一游戏刻内按顺序依次执行。由于命令执行发生在游戏刻的末端(包含所有玩家登录、登出、死亡等事件之后),本系统得以精准运作。
|
||||
|
||||

|
||||

|
||||
:::
|
||||
|
||||
## Tick JSON
|
||||
## Tick JSON 配置
|
||||
|
||||
If you are using functions instead of command blocks, the ` on_player_leave ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
|
||||
若使用函数替代命令方块,需将 ` on_player_leave ` 函数添加至 ` tick.json ` 以实现循环执行。通过在字符串后添加逗号分隔,可将多个文件添加至 ` tick.json `。更多信息请参考[函数文档](/wiki/commands/mcfunctions#tick-json)。
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"on_player_leave"
|
||||
@@ -89,7 +91,7 @@ If you are using functions instead of command blocks, the ` on_player_leave ` fu
|
||||
}
|
||||
```
|
||||
|
||||
If using functions, your pack folder structure will be be as follows:
|
||||
使用函数时,资源包文件夹结构如下:
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -102,6 +104,6 @@ If using functions, your pack folder structure will be be as follows:
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the scoreboard names (in this case: 'total') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
|
||||
> **注意:** 计分项名称(本例中的'total')可能与他人重复。建议在名称后追加 ` _ ` 和随机字符组合来降低冲突概率,此技巧同样适用于 ` .mcfunction ` 文件名。例如:
|
||||
> - ` total_0fe678 `
|
||||
> - ` on_player_leave_0fe678.mcfunction `
|
||||
> - ` on_player_leave_0fe678.mcfunction `
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: On Player Respawn
|
||||
category: On Event Systems
|
||||
title: 玩家重生事件
|
||||
category: 事件系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
@@ -9,66 +9,71 @@ tags:
|
||||
- system
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 玩家重生事件
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system will run your desired commands on the event that a player respawns from death state.
|
||||
## 前言
|
||||
|
||||
## Setup
|
||||
[由Bedrock Commands社区Discord提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
*To be typed in Chat:*
|
||||
当玩家从死亡状态重生时,该系统将执行您指定的命令。
|
||||
|
||||
## 初始化设置
|
||||
|
||||
*在聊天栏输入以下指令:*
|
||||
|
||||
`/scoreboard objectives add respawn dummy`
|
||||
|
||||
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
|
||||
若希望在世界初始化时自动添加计分板,请参照[首次世界加载](/wiki/commands/on-first-world-load)指南操作。
|
||||
|
||||
## System
|
||||
## 系统实现
|
||||
|
||||
<CodeHeader>on_player_respawn.mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
#Your Commands Here (example)
|
||||
execute as @e [scores={respawn=1}] run say I died and respawned.
|
||||
::: code-group
|
||||
```yaml [on_player_respawn.mcfunction]
|
||||
# 在此处添加你的命令(示例)
|
||||
execute as @e [scores={respawn=1}] run say 我已死亡并重生。
|
||||
|
||||
|
||||
scoreboard players set @a respawn 1
|
||||
scoreboard players set @e [type=player] respawn 0
|
||||
```
|
||||

|
||||
:::
|
||||
|
||||

|
||||
|
||||
Here we have used an `/execute - say` command as an example but you can use any command you prefer and as many as you require.
|
||||
本例中使用`/execute - say`指令作为示例,您可以根据需求替换为任意指令,数量不限。
|
||||
|
||||
Just make sure to follow the given order and properly use the selector argument ` @e [scores={respawn=1}] ` as shown for your desired commands.
|
||||
请严格遵循指令顺序,并正确使用选择器参数` @e [scores={respawn=1}] `来定位目标玩家。
|
||||
|
||||
## Explanation
|
||||
## 运行原理
|
||||
|
||||
- **` respawn=0 `** this means the player is alive or had already respawned.
|
||||
- **` respawn=1 `** this means the player died and is now respawning, ie. respawned *just now*, in the current gametick.
|
||||
- **` @a `** selector will target all players alive/dead so we use it to mark everyone as 1 'respawning'
|
||||
- **` @e `** selector on the other hand will only target players who are alive, so we can use this to mark all alive players 0 'respawned'
|
||||
- **` respawn=0 `** 表示玩家存活或已完成重生
|
||||
- **` respawn=1 `** 表示玩家死亡且正在重生(即当前游戏刻内刚触发重生)
|
||||
- **` @a `** 选择器将定位所有玩家(包括存活/死亡),用于标记全体玩家为1(正在重生状态)
|
||||
- **` @e `** 选择器仅定位存活玩家,用于重置存活玩家为0(已完成重生状态)
|
||||
|
||||
Now that *respawning* players are 1 and *respawned* players are 0 we can use this knowledge to run our desired commands on the players respawning.
|
||||
通过此机制,我们可以精准捕捉到刚刚重生的玩家(分数为1的玩家)来执行指定命令。
|
||||
|
||||
In the system, your desired commands must come before the other 2 commands because players change from death state to alive state along the start of the gametick before commands are run.
|
||||
在系统文件中,自定义命令必须放置在最后两条计分板操作指令之前,因为玩家状态会在游戏刻开始时立即从死亡转为存活。
|
||||
|
||||
Hence; if we were to put them at the end then the other 2 commands would set respawning players score to 0 first and then the commands you want to run won't be able to select those players as our selector argument is ` @e [scores={respawn=1}] ` not 0. Using 0 would not work as then it would repeat endlessly even on players who have already respawned.
|
||||
若将自定义命令置于末尾,计分板操作会先将重生玩家的分数重置为0,此时通过` @e [scores={respawn=1}] `选择器将无法定位到目标玩家。若使用分数0作为条件,则会导致指令在已重生玩家身上重复触发。
|
||||
|
||||
## Tick JSON
|
||||
## 游戏刻函数配置
|
||||
|
||||
If you are using functions instead of command blocks, the ` on_player_respawn ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
|
||||
若使用函数而非命令方块,需将` on_player_respawn `函数添加至` tick.json `以实现循环检测。多个函数可通过逗号分隔添加,详见[函数文档](/wiki/commands/mcfunctions#tick-json)。
|
||||
|
||||
<CodeHeader>BP/functions/tick.json</CodeHeader>
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/functions/tick.json]
|
||||
{
|
||||
"values": [
|
||||
"on_player_respawn"
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
If using functions, your pack folder structure will be be as follows:
|
||||
函数包的文件结构如下所示:
|
||||
|
||||
<FolderView
|
||||
:paths="[
|
||||
@@ -81,6 +86,6 @@ If using functions, your pack folder structure will be be as follows:
|
||||
]"
|
||||
></FolderView>
|
||||
|
||||
> **Note:** the scoreboard names (in this case: 'respawn') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
|
||||
> **注意:** 计分板名称(本例中的'respawn')可能与其他开发者冲突。建议在名称后追加` _ `和随机字符组合来降低重复概率,函数文件名也可采用相同策略。例如:
|
||||
> - ` respawn_0fe678 `
|
||||
> - ` on_player_respawn_0fe678.mcfunction `
|
||||
> - ` on_player_respawn_0fe678.mcfunction `
|
||||
@@ -1,79 +1,84 @@
|
||||
---
|
||||
title: Playsound
|
||||
category: Commands
|
||||
title: 播放音效
|
||||
category: 命令
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
- jordanparki7
|
||||
tags:
|
||||
- info
|
||||
- 信息
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 播放音效
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
You can use the `/playsound` command to play sound effects to players present anywhere in the world whenever you like.
|
||||
## 简介
|
||||
|
||||
## Syntax
|
||||
[由 Bedrock Commands 社区 Discord 提供](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
你可以使用`/playsound`命令在世界任意位置为玩家播放音效。
|
||||
|
||||
## 语法
|
||||
|
||||
`/playsound <sound> [player] [position] [volume] [pitch] [minimumVolume]`
|
||||
|
||||
## Definitions
|
||||
## 参数定义
|
||||
|
||||
### Sound
|
||||
### sound
|
||||
|
||||
- It is the sound effect you wish to play.
|
||||
- You can find the list of sound IDs currently available at:
|
||||
- 需要播放的音效ID
|
||||
- 当前可用音效列表可参考:
|
||||
- https://www.digminecraft.com/lists/sound_list_pe.php
|
||||
|
||||
### Player
|
||||
### player
|
||||
|
||||
- This is an optional argument.
|
||||
- It refers to your typical target selectors (whom you want to play the sound to) ` @a `, ` @r `, ` @p `, ` Technoblade `, etc..
|
||||
- 可选参数
|
||||
- 目标选择器参数(接收音效的玩家)` @a `, ` @r `, ` @p `, ` Technoblade ` 等
|
||||
|
||||
### Position
|
||||
### position
|
||||
|
||||
- This is an optional argument.
|
||||
- It refers to the `x y z` position from where the sound will be played, ie. the center of the playsound radius.
|
||||
- 可选参数
|
||||
- 音效播放的坐标 `x y z`,即音效可听范围的圆心坐标
|
||||
|
||||
### Volume
|
||||
### volume
|
||||
|
||||
- This is an optional argument.
|
||||
- It determines the size of the sphere in which the sound effect can be heard.
|
||||
- ` 0.0 ` is the minimum size.
|
||||
- Sound & audible sphere size increases as `volume` value is increased.
|
||||
- Playaound volume of `1` is equal to an audible sphere of radius 16 blocks.
|
||||
- Similarly; volume of `4` would be equal to 64 blocks.
|
||||
- 可选参数
|
||||
- 决定音效可听范围的半径
|
||||
- 最小值是 `0.0`
|
||||
- 该值越大,音效传播范围越广
|
||||
- 音量 `1` 对应半径16方块的球形范围
|
||||
- 音量 `4` 对应半径64方块的球形范围
|
||||
|
||||
### Pitch
|
||||
### pitch
|
||||
|
||||
- This is an optional aegument.
|
||||
- It determines the pitch for the sound effect.
|
||||
- It can be a value between ` 0.0 ` and ` 256.0 `
|
||||
- The higher the value, the higher the pitch.
|
||||
- Values less than or equal to `0.0` makes the sound inaudible.
|
||||
- 可选参数
|
||||
- 控制音效的音调高低
|
||||
- 取值范围 `0.0` 至 `256.0`
|
||||
- 数值越高音调越尖锐
|
||||
- 数值小于等于 `0.0` 时音效不可闻
|
||||
|
||||
> Note: pitch affects the speed at which the audio is played. For example, a pitch of `0.5` would mean the audio is played at ` 0.5× ` speed.
|
||||
> 注意:音调参数会影响音频播放速度。例如音调 `0.5` 表示以 0.5 倍速播放音频
|
||||
|
||||
### Minimum Volume
|
||||
### minimumVolume
|
||||
|
||||
- This is an optional argument.
|
||||
- It determines the minimum volume at which the sound will be heard outside of the audible sphere.
|
||||
- It can be a value between ` 0.0 ` and ` 1.0 `
|
||||
- 可选参数
|
||||
- 设置可听范围外的最小音量
|
||||
- 取值范围 `0.0` 至 `1.0`
|
||||
|
||||
## Examples
|
||||
## 使用示例
|
||||
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
```yaml
|
||||
#Play a random explosion sound effect to closest player.
|
||||
::: code-group
|
||||
```yaml [mcfunction]
|
||||
# 对最近的玩家播放随机爆炸音效
|
||||
/playsound random.explode @p
|
||||
|
||||
#Play a random orb sound effect to all players at their relative position with a volume of 10000
|
||||
# 为所有玩家在其当前位置播放随机经验球音效(音量范围10000)
|
||||
/execute as @a at @s playsound random.orb @s ~ ~ ~ 10000
|
||||
```
|
||||
:::
|
||||
|
||||
Note: since the playsound command is positonal, it is helpful to use an execute command structure as shown in the second example to prevent the sound effect from cutting off in special cases such as playing a sound effect following a `/tp` command. You may increase volume when covering large distances to reduce failures.
|
||||
注意:由于播放音效命令具有位置依赖性,在特殊场景(如使用`/tp`传送后)建议采用第二个示例中的`execute`命令结构来避免音效中断。当需要覆盖远距离时,可以适当增大音量参数来确保播放效果。
|
||||
|
||||
|
||||
**(Recommended) Read Next: [Sounds](/concepts/sounds)**
|
||||
**(推荐)延伸阅读:[声音系统](/wiki/concepts/sounds)**
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Coordinate System
|
||||
category: General
|
||||
title: 坐标系系统
|
||||
category: 基础
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
- Sprunkles137
|
||||
@@ -9,38 +9,55 @@ mentions:
|
||||
- TheItsNameless
|
||||
---
|
||||
|
||||
## The Coordinate System
|
||||
# 坐标系系统
|
||||
|
||||
Minecraft stores the locations of blocks and entities in the world using a system of three-dimensional coordinates, each representing a value in a one-dimensional axis. They are stored in the format of X, then Y, and lastly Z. Whether you are placing structures and blocks, or teleporting and summoning entities, you can, and are sometimes required to, put in coordinates. They don't need to always be real values however; you can substitute world coordinates for relative values, either based in world space or local space.
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||

|
||||
## 坐标系基础
|
||||
|
||||
_You may already be familiar with coordinates if you've enabled the Show Coordinates world option!_
|
||||
Minecraft使用三维坐标系来存储世界中方块和实体的位置,每个坐标代表一维轴上的数值。坐标以X、Y、Z的顺序存储。无论是放置结构方块,还是传送/召唤实体,你都可以(有时必须)使用坐标值。不过坐标不限于绝对数值,你可以使用相对坐标系——既可以选择基于世界空间的相对坐标,也可以选择基于局部空间的本地坐标。
|
||||
|
||||
## Relative Coordinates (~)
|
||||

|
||||
|
||||
Relative coordinates are represented using tildes in place of real coordinates, and represent a position that is relative to the world coordinates its located at. You may insert numbers after a tilde to add an offset to the current position. These can be mixed with world coordinates, but cannot be mixed with local coordinates.
|
||||
_如果你启用了"显示坐标"世界选项,可能已经对坐标系统有所了解!_
|
||||
|
||||
Examples:
|
||||
- `~ ~ ~`: Current position with no changes.
|
||||
- `~5 ~-2 ~`: Current position with a 5-block X offset and a negative 2-block Y offset.
|
||||
## 相对坐标 (~)
|
||||
|
||||
### Rotations
|
||||
相对坐标使用波浪符号`~`代替具体数值,表示相对于当前所处世界坐标的位置。在波浪符后添加数字可以指定偏移量。相对坐标可与世界坐标混合使用,但不能与局部坐标混用。
|
||||
|
||||
Relative coordinates can also be used in the context of rotations, where they represent a rotation that is relative to the current rotation it inherits from. These may also accept numbers after the tilde to add an offset to the current rotation.
|
||||
示例:
|
||||
- `~ ~ ~`: 保持当前位置不变
|
||||
- `~5 ~-2 ~`: 当前位置X轴正方向偏移5格,Y轴负方向偏移2格
|
||||
|
||||
Example: `~90 ~` will add 90° to the current yaw (y-rotation) value.
|
||||
### 旋转角度中的应用
|
||||
|
||||
## Local Coordinates (^)
|
||||
相对坐标也可用于表示旋转角度,这时表示相对于当前继承的旋转角度。同样可以在波浪符后添加数字来指定偏移量。
|
||||
|
||||
Local coordinates are similar to relative coordinates, but represent a position in local space, where the axes are based off of rotation. They take the form `^left ^up ^forward`; you can think of this as `~x ~y ~z` if both your yaw and pitch rotations are 0 (facing straight ahead, due south).
|
||||
示例:`~90 ~` 表示在当前偏航角(Y轴旋转)基础上增加90度
|
||||
|
||||
Like relative coordinates, you can insert numbers to produce an offset of the current position, in local space. If there is no entity to copy rotation from, the x- and y-rotations are assumed to be 0.
|
||||
## 局部坐标 (^)
|
||||
|
||||
Examples:
|
||||
- `^10 ^ ^`: Current position with a 10-block offset to the left.
|
||||
- `^ ^1.5 ^1`: Current position with a 1.5-block offset upward and a 1-block offset forward.
|
||||
局部坐标与相对坐标类似,但表示基于实体朝向的局部空间坐标,采用`^左 ^上 ^前`的格式。当实体偏航角和俯仰角均为0(面朝正南平视)时,可以将其理解为`~x ~y ~z`坐标系。
|
||||
|
||||
## Additional Notes
|
||||
与相对坐标类似,可以添加数字来指定局部空间中的偏移量。如果没有可供参考旋转角度的实体,则默认X/Y旋转角度为0。
|
||||
|
||||
- The player's eye level is 1.62 blocks above their feet. (~ ~1.62 ~)
|
||||
示例:
|
||||
- `^10 ^ ^`: 当前位置左侧偏移10格
|
||||
- `^ ^1.5 ^1`: 当前位置上方偏移1.5格,前方偏移1格
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 玩家眼部高度位于脚部上方1.62格处(对应相对坐标`~ ~1.62 ~`)
|
||||
|
||||
::: code-group
|
||||
```json [示例配置]
|
||||
// 此处保持代码原样,仅翻译注释
|
||||
// 玩家传送指令示例
|
||||
{
|
||||
"command": "tp @s ~ ~5 ~", // 将玩家垂直提升5格
|
||||
"comment": "使用相对坐标进行垂直传送"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
_注意:本地坐标(^)系统在实体具有复杂旋转角度时会产生非直观的位移效果,建议在建筑类命令中使用世界相对坐标(~)系统,在实体局部操作时使用本地坐标系。_
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Scoreboard Operations
|
||||
category: General
|
||||
title: 记分板操作
|
||||
category: 基础
|
||||
mentions:
|
||||
- Sprunkles137
|
||||
- Luthorius
|
||||
@@ -8,128 +8,131 @@ mentions:
|
||||
- Hatchibombotar
|
||||
---
|
||||
|
||||
Scoreboards can be used to perform complex operations, similar to [Molang](/concepts/molang). Operations come in two flavors: mathematical, and logical.
|
||||
# 记分板操作
|
||||
|
||||
## Overview
|
||||
Operations are performed using the `/scoreboard players operation` command. The full syntax is laid out below:
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
记分板可用于执行复杂运算,其功能类似于[Molang](/wiki/concepts/molang)。运算分为两类:数学运算和逻辑运算。
|
||||
|
||||
## 概述
|
||||
使用`/scoreboard players operation`命令执行运算。完整语法如下:
|
||||
```
|
||||
/scoreboard players operation <targetScore> <objective> <operation> <sourceScore> <objective>
|
||||
/scoreboard players operation <目标分数> <记分项> <运算符> <源分数> <记分项>
|
||||
```
|
||||
The command consists of two score holders: The target score, and the source score. The target score is the value being operated on, and the source score is the value affecting the operation. The result of the operation is written into the target score, and the source score's value is not touched, save for [one operation](/commands/scoreboard-operations#swap-operator).
|
||||
该命令包含两个分数持有者:目标分数和源分数。目标分数是被操作的值,源分数是参与运算的值。运算结果将写入目标分数,源分数的值不会被修改(除[交换运算符](/wiki/commands/scoreboard-operations#swap-operator)外)。
|
||||
|
||||
## Mathematical Operators
|
||||
Mathematical operators use arithmetic to affect the target score. There are five mathematical operations available: addition, subtraction, multiplication, floor division, and floor modulo division.
|
||||
## 数学运算符
|
||||
数学运算符通过算术运算影响目标分数。共有五种数学运算:加法、减法、乘法、向下取整除法和向下取整模除。
|
||||
|
||||
For each of the following examples below, assume that score holder `A var` equals 25, and `B var` equals 10.
|
||||
以下示例均假设分数持有者`A var`的值为25,`B var`的值为10。
|
||||
|
||||
### Addition
|
||||
Operator: **+=**
|
||||
### 加法
|
||||
运算符:**+=**
|
||||
|
||||
This operation adds the target score and source scores together, then stores the sum into the target score.
|
||||
将目标分数与源分数相加,结果存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var += B var
|
||||
```
|
||||
`A = A + B`, and as such `25 + 10 = 35`.
|
||||
即`A = A + B`,运算结果为`25 + 10 = 35`。
|
||||
|
||||
### Subtraction
|
||||
Operator: **-=**
|
||||
### 减法
|
||||
运算符:**-=**
|
||||
|
||||
This operation subtracts the target score by the source score, then stores the difference into the target score.
|
||||
从目标分数中减去源分数,结果存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var -= B var
|
||||
```
|
||||
`A = A - B`, and as such `25 - 10 = 15`.
|
||||
即`A = A - B`,运算结果为`25 - 10 = 15`。
|
||||
|
||||
### Multiplication
|
||||
Operator: **\*=**
|
||||
### 乘法
|
||||
运算符:***=**
|
||||
|
||||
This operation multiplies the target score by the source score, then stores the product into the target score.
|
||||
将目标分数乘以源分数,结果存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var *= B var
|
||||
```
|
||||
`A = A * B`, and as such `25 * 10 = 250`.
|
||||
即`A = A * B`,运算结果为`25 * 10 = 250`。
|
||||
|
||||
### Floored Division
|
||||
Operator: **/=**
|
||||
### 向下取整除法
|
||||
运算符:**/=**
|
||||
|
||||
This operation divides the target score by the source score, then stores the quotient into the target score. Because score values can only be integers, the value is floored, or rounded down.
|
||||
将目标分数除以源分数,结果向下取整后存入目标分数(由于分数值只能是整数)。
|
||||
```
|
||||
/scoreboard players operation A var /= B var
|
||||
```
|
||||
`A = floor(A / B)`, and as such `floor(25 / 10) = 2`.
|
||||
即`A = floor(A / B)`,运算结果为`floor(25 / 10) = 2`。
|
||||
|
||||
### Floored Modulo Division
|
||||
Operator: **%=**
|
||||
### 向下取整模除
|
||||
运算符:**%=**
|
||||
|
||||
This operation also divides the target score by the source score, but instead returns the remainder after the division into the target score. This is also floored.
|
||||
将目标分数除以源分数后取余数,结果向下取整后存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var %= B var
|
||||
```
|
||||
`A = floor(mod(A, B))`, and as such `floor(mod(25, 10)) = 5`.
|
||||
即`A = floor(mod(A, B))`,运算结果为`floor(mod(25, 10)) = 5`。
|
||||
|
||||
## Logical Operators
|
||||
Logical operations use logic gates and assignments to affect the target score. There are four logical operations available: assignment, less than, greater than, and swap.
|
||||
## 逻辑运算符
|
||||
逻辑运算符使用逻辑门和赋值操作来影响目标分数。共有四种逻辑运算:赋值、最小值、最大值和交换。
|
||||
|
||||
Similar to the above, assume that score holder `A var` equals 25, and `B var` equals 10.
|
||||
同样假设分数持有者`A var`的值为25,`B var`的值为10。
|
||||
|
||||
### Assignment Operator
|
||||
Operator: **=**
|
||||
### 赋值运算符
|
||||
运算符:**=**
|
||||
|
||||
This operation sets the target score equal to the source score.
|
||||
将目标分数设置为源分数的值。
|
||||
```
|
||||
/scoreboard players operation A var = B var
|
||||
```
|
||||
`A = B`, and as such the result is `10`.
|
||||
即`A = B`,运算结果为`10`。
|
||||
|
||||
### Minimum Operator
|
||||
Operator: **<**
|
||||
### 最小值运算符
|
||||
运算符:**<**
|
||||
|
||||
This operation returns the smallest of the input scores, and stores it into the target score.
|
||||
比较两个分数后,将较小值存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var < B var
|
||||
```
|
||||
`A = min(A, B)`, and as such `min(25, 10) = 10`.
|
||||
即`A = min(A, B)`,运算结果为`min(25, 10) = 10`。
|
||||
|
||||
### Maximum Operator
|
||||
Operator: **>**
|
||||
### 最大值运算符
|
||||
运算符:**>**
|
||||
|
||||
This operation returns the largest of the input scores, and stores it into the target score.
|
||||
比较两个分数后,将较大值存入目标分数。
|
||||
```
|
||||
/scoreboard players operation A var > B var
|
||||
```
|
||||
`A = max(A, B)`, and as such `max(25, 10) = 25`.
|
||||
即`A = max(A, B)`,运算结果为`max(25, 10) = 25`。
|
||||
|
||||
### Swap Operator
|
||||
Operator: **><**
|
||||
### 交换运算符
|
||||
运算符:**><**
|
||||
|
||||
This operation swaps the target score and source scores with each other. This is the only operation that affects the source score.
|
||||
交换目标分数和源分数的值。这是唯一会影响源分数的运算符。
|
||||
```
|
||||
/scoreboard players operation A var >< B var
|
||||
```
|
||||
The above command would swap the values of A and B e.g.
|
||||
执行上述命令后,A和B的值将互换:
|
||||
|
||||
Before: A = 10; B = 25;
|
||||
执行前:A = 10;B = 25;
|
||||
|
||||
After: A = 25; B = 10;
|
||||
执行后:A = 25;B = 10;
|
||||
|
||||
This can be seen as three operations: `temp = A; A = B; B = temp;`, and as such `A var = 10` and `B var = 25`.
|
||||
该操作等效于三步操作:`temp = A; A = B; B = temp;`,最终`A var = 10`且`B var = 25`。
|
||||
|
||||
## Useful Creations
|
||||
## 实用案例
|
||||
|
||||
#### Check If Values are Equal
|
||||
#### 检查数值是否相等
|
||||
|
||||
If you want to check in scoreboard, whether one value equals another value, you can copy first value to temporary value, subtract the other and compare temporary value to zero. Given values A and B:
|
||||
若要通过记分板检查两个值是否相等,可将第一个值复制到临时变量,再减去第二个值后比较临时变量是否为0。假设有值A和B:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```
|
||||
::: code-group
|
||||
```json [实体标签]
|
||||
scoreboard objectives add temp dummy
|
||||
scoreboard players operation @e temp = @s A
|
||||
scoreboard players operation @e temp -= @s B
|
||||
execute @e[scores={temp=0}] ~~~ say A equals B
|
||||
execute @e[scores={temp=0}] ~~~ say A等于B
|
||||
scoreboard objectives remove temp
|
||||
```
|
||||
|
||||
#### Scoreboard Initialization
|
||||
#### 记分板初始化
|
||||
|
||||
If you want to initialize a scoreboard value to 0, but only if it doesn't exists, you can use `scoreboard players add <selector> <name> 0`. It will set the value to 0, if it doesn't exist on the entity and do nothing, if it already exist.
|
||||
若要将记分板值初始化为0(仅当该值不存在时),可使用`scoreboard players add <选择器> <名称> 0`。此命令会在实体不存在该分数时设为0,若已存在则不做任何操作。
|
||||
@@ -1,200 +1,176 @@
|
||||
---
|
||||
title: Scoreboard Timers
|
||||
category: Scoreboard Systems
|
||||
title: 记分板计时器
|
||||
category: 计分板系统
|
||||
mentions:
|
||||
- BedrockCommands
|
||||
- zheaEvyline
|
||||
nav_order: 5
|
||||
tags:
|
||||
- system
|
||||
- 系统
|
||||
---
|
||||
|
||||
## Introduction
|
||||
# 记分板计时器
|
||||
|
||||
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This system allows you to run your desired commands at specific intervals with any amount of delay that you wish to add.
|
||||
## 简介
|
||||
|
||||
- **Some Examples:**
|
||||
- Sending a message in chat every 2 hours.
|
||||
- Running a 'lag clear' function every 10 minutes.
|
||||
- Effecting players with 'speed' every 30 seconds.
|
||||
|
||||
This system is especially useful when you need to set up multiple timers on your world. When working with command blocks, you may use the [Tick Delay](/commands/intro-to-command-blocks#command-block-tick-delay) option to delay the time taken for your commands to run. However, when working with functions you will need to use a system like this.
|
||||
[源自 Bedrock Commands 社区 Discord](https://discord.gg/SYstTYx5G5)
|
||||
|
||||
It is recommended to use this system while working with command blocks, as well if you wish to run all your timers in sync with one another, ie. with the same start time.
|
||||
|
||||
## Setup
|
||||
本系统允许你在指定时间间隔内运行自定义指令,延迟时长可根据需求自由设定。
|
||||
|
||||
*To be typed in chat:*
|
||||
<CodeHeader></CodeHeader>
|
||||
- **应用场景示例:**
|
||||
- 每2小时在聊天栏发送消息
|
||||
- 每10分钟执行一次"清除延迟"函数
|
||||
- 每30秒给玩家施加速度效果
|
||||
|
||||
```yaml
|
||||
当需要在世界中设置多个计时器时,本系统尤为实用。使用命令方块时可通过[Tick 延迟](/wiki/commands/intro-to-command-blocks#command-block-tick-delay)选项来延迟指令执行,但在函数中则需要依赖此类系统。
|
||||
|
||||
推荐在命令方块中也使用本系统,以便让所有计时器保持同步启动。
|
||||
|
||||
## 初始设置
|
||||
|
||||
*在聊天栏输入以下指令:*
|
||||
::: code-group
|
||||
```yaml [初始化]
|
||||
scoreboard objectives add ticks dummy
|
||||
scoreboard objectives add events dummy
|
||||
```
|
||||
|
||||
Once you have created these two objectives, you will need to define the interval for each repeating event you need on your world in the `ticks` objective.
|
||||
创建这两个记分项后,需要在`ticks`记分项中为每个重复事件定义间隔时间。
|
||||
|
||||
To do that, first you must know that **1 second is approximately 20 game ticks in Minecraft**. Based on this knowledge, you will need to do some basic calculations to obtain the ticks equivalent for each interval you want to define.
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```yaml
|
||||
# 2h = 20(t) × 60(s) × 60(m) × 2(h) = 144000t
|
||||
需注意**Minecraft中1秒约等于20游戏刻**,可通过基础运算换算所需时间对应的刻数。
|
||||
::: code-group
|
||||
```yaml [时间换算]
|
||||
# 2小时 = 20(t) × 60(秒) × 60(分) × 2(小时) = 144000刻
|
||||
scoreboard players set 2h ticks 144000
|
||||
|
||||
#10m = 20(t) × 60(s) × 10(m) = 12000t
|
||||
#10分钟 = 20(t) × 60(秒) × 10(分) = 12000刻
|
||||
scoreboard players set 10m ticks 12000
|
||||
|
||||
#30s = 20(t) × 30(s) = 600t
|
||||
#30秒 = 20(t) × 30(秒) = 600刻
|
||||
scoreboard players set 30s ticks 600
|
||||
```
|
||||
We will now use this scoreboard data to make our timers function.
|
||||
:::
|
||||
|
||||
## System
|
||||
## 系统实现
|
||||
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
::: code-group
|
||||
```yaml [计时系统.mcfunction]
|
||||
scoreboard players add timer ticks 1
|
||||
scoreboard players operation * events = timer ticks
|
||||
|
||||
#Chat Message (every 2h)
|
||||
# 聊天消息(每2小时)
|
||||
scoreboard players operation chatMessage events %= 2h ticks
|
||||
execute if score chatMessage events matches 0 run say Technoblade never dies!
|
||||
execute if score chatMessage events matches 0 run say 技术之刃永世长存!
|
||||
|
||||
#Lag Clear (every 10m)
|
||||
# 延迟清理(每10分钟)
|
||||
scoreboard players operation lagClear events %= 10m ticks
|
||||
execute if score lagClear events matches 0 run function clear_lag
|
||||
|
||||
#Speed Effect (every 30s)
|
||||
# 速度效果(每30秒)
|
||||
scoreboard players operation speedEffect events %= 30s ticks
|
||||
execute if score speedEffect events matches 0 run effect @a speed 10 2 true
|
||||
```
|
||||

|
||||
|
||||
Here we have taken 3 examples to give you an idea on how to do it, but you can add any timer you need and as many as you require.
|
||||
|
||||
Just make sure to follow the given order and properly use the `/execute if score` command as shown to run the commands you need.
|
||||
|
||||
## Explanation
|
||||
|
||||
- **` events `** on this objective we label all the repeating events we want on our world.
|
||||
- `chatMessage`
|
||||
- `lagClear`
|
||||
- `speedEffect`
|
||||
- **` ticks `** on this objective we define all the intervals for our events and also run our scoreboard timer.
|
||||
- ` 2h` interval (static score 144000)
|
||||
- `10m` interval (static score 12000)
|
||||
- `30s` interval (static score 600)
|
||||
- `timer` clock (variable score n+1)
|
||||
|
||||
|
||||
- **Command 1:** this command adds +1 score every tick to FakePlayer name `timer` indicating a tick has passed in the game. This is basically our scoreboard timer/clock which we will use for all the repeating events on our world.
|
||||
|
||||
|
||||
- **Command 2:** here we copy `timer` score to all our events using the ` * ` wildcard selector. This will allow us to perform operations to determine if the interval has been reached to run the commands for that particular event. Example:
|
||||
- If `timer` score is 1200 that means 1200 game ticks have passed.
|
||||
- And this command makes it so all our events FakePlayer names: `chatMessage`, `lagClear`, `speedEffect` scores are also 1200.
|
||||
|
||||
|
||||
- **Command 3:** we will use the ` %= ` modulo operation to check if our event score is divisible by it's corresponding interval. A number is said to be divisible when the remainder is 0.
|
||||
- Chat Message: `1200/144000` Q=0, R=1200, *hence interval not reached.*
|
||||
- Lag Clear: `1200/12000` Q=0, R=1200, *hence interval not reached.*
|
||||
- Speed Effect: `1200/600` Q=2, R=0, *hence interval has reached and event commands can be executed.*
|
||||
Here we can note that the first 2 events are yet to happen but the 3rd event is happening for the second time.
|
||||
:::tip
|
||||
In Minecraft; scoreboard division is only calculated up to whole numbers and decimal values are ignored.
|
||||

|
||||
:::
|
||||
|
||||

|
||||
|
||||
- **Command 4:** the remainder value obtained from the calculation is applied to the corresponding event FakePlayer name. Based on this knowledge we can run our command if it's score is equal to 0.
|
||||
本示例展示了三种计时器的实现方法,您可根据需求扩展更多计时器。请严格按照顺序编写指令,并正确使用`/execute if score`条件判断。
|
||||
|
||||
The rest of the commands are identical in structure and only the event labels and interval values are changed.
|
||||
## 系统解析
|
||||
|
||||
## Defining Events With Limited Intervals
|
||||
- **`events`记分项:** 用于标记所有需要重复执行的事件
|
||||
- `chatMessage` - 聊天消息
|
||||
- `lagClear` - 延迟清理
|
||||
- `speedEffect` - 速度效果
|
||||
- **`ticks`记分项:** 存储事件间隔参数与计时器数值
|
||||
- `2h`间隔(固定值144000)
|
||||
- `10m`间隔(固定值12000)
|
||||
- `30s`间隔(固定值600)
|
||||
- `timer`计时器(动态累加值)
|
||||
|
||||
To limit how many times an event occurs, you will need to create a new objective called `intervals` and define how many times the event should occur like so:
|
||||
<CodeHeader></CodeHeader>
|
||||
**指令详解:**
|
||||
1. **计时累加:** 每游戏刻为`timer`虚拟玩家分数+1,作为全局时间基准
|
||||
2. **数值同步:** 将`timer`数值复制到所有事件虚拟玩家,建立时间参照
|
||||
3. **模运算检测:** 使用` %= `运算符计算余数,当余数为0时触发事件
|
||||
4. **事件触发:** 根据模运算结果执行对应指令
|
||||
|
||||
```yaml
|
||||
scoreboard objectives set chatMessage intervals 5
|
||||
scoreboard objectives set speedEffect intervals 10
|
||||
:::tip 模运算原理
|
||||
Minecraft中的分数除法仅保留整数部分,余数通过模运算获取。当余数为0时表示达到设定间隔。
|
||||

|
||||
:::
|
||||
|
||||
## 有限次数事件
|
||||
|
||||
如需限制事件触发次数,可创建`intervals`记分项来设置剩余触发次数:
|
||||
::: code-group
|
||||
```yaml [次数限制]
|
||||
scoreboard players set chatMessage intervals 5
|
||||
scoreboard players set speedEffect intervals 10
|
||||
```
|
||||
|
||||
Once you have done that, modify your system from above like so:
|
||||
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
修改系统函数如下:
|
||||
::: code-group
|
||||
```yaml [有限次数版.mcfunction]
|
||||
scoreboard players add timer ticks 1
|
||||
scoreboard players operation * events = timer ticks
|
||||
|
||||
#Chat Message (every 10m)
|
||||
# 聊天消息(每2小时)
|
||||
scoreboard players operation chatMessage events %= 2h ticks
|
||||
execute if score chatMessage events matches 0 if score chatMessage intervals matches 1.. run say Technoblade never dies!
|
||||
execute if score chatMessage events matches 0 if score chatMessage intervals matches 1.. run say 技术之刃永世长存!
|
||||
execute if score chatMessage events matches 0 if score chatMessage intervals matches 1.. run scoreboard players remove chatMessage intervals 1
|
||||
|
||||
#Speed Effect (every 30s)
|
||||
# 速度效果(每30秒)
|
||||
scoreboard players operation speedEffect events %= 30s ticks
|
||||
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run effect @a speed 10 2 true
|
||||
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run scoreboard players remove speedEffect intervals 1
|
||||
```
|
||||

|
||||
:::
|
||||
|
||||
## Executing Commands During Timeframe
|
||||
## 时段内持续执行
|
||||
|
||||
To run commands during the timeframe between intervals for a particular system you may do something like this:
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
#Speed Effect (every 30s) + Particle (every tick)
|
||||
若需要在计时过程中持续执行指令(而不仅是在触发时刻):
|
||||
::: code-group
|
||||
```yaml [持续效果.mcfunction]
|
||||
# 速度效果(每30秒) + 持续粒子效果
|
||||
scoreboard players operation speedEffect events %= 30s ticks
|
||||
execute if score speedEffect intervals matches 1.. as @a at @s run particle minecraft:shulker_bullet ~~~
|
||||
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run effect @a speed 10 2 true
|
||||
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run scoreboard players remove speedEffect intervals 1
|
||||
```
|
||||
As shown in line 3; to run commands while the timer is running, all you need to do is remove the "if score" testing if the interval has been reached. And instead, only test if *any* interval is left, to run our commands.
|
||||
:::
|
||||
|
||||
Let's say we had set the intervals for this event to 10, then that means players would also have particle trails for 300 seconds since `10*30s=300s`
|
||||
如设置触发次数为10次,粒子效果将持续300秒(10 × 30秒)。
|
||||
|
||||
## Entity Timers
|
||||
## 实体独立计时器
|
||||
|
||||
In some cases such as an entity despawn event you will need to run timers for each entity individually rather than a synchronised timer which could cause the event to trigger too soon. In such cases an Async Timer can be helpful.
|
||||
|
||||
Let's say we want to:
|
||||
- kill all entities named "station" 5 minutes after they've been summoned.
|
||||
- play a shulker particle around them during that timeframe.
|
||||
- play a flame particle around them in the first 10 seconds.
|
||||
- play a pling sound to nearby players when the timer reaches half way.
|
||||
- stop the timer if a passive mob is nearby.
|
||||
- loop the timer if a hostile mob is nearby.
|
||||
|
||||
<CodeHeader>mcfunction</CodeHeader>
|
||||
|
||||
```yaml
|
||||
#Clock
|
||||
对于需要单独计时的实体(如定时消失),可使用异步计时系统:
|
||||
::: code-group
|
||||
```yaml [实体计时器.mcfunction]
|
||||
# 计时核心
|
||||
scoreboard players add @e [name=station, scores={ticks=0..}] ticks 1
|
||||
|
||||
#Executing Commands while timer is running
|
||||
# 持续粒子效果
|
||||
execute as @e [name=station, scores={ticks=0..}] at @s run particle minecraft:shulker_bullet ~~~
|
||||
|
||||
#Executing commands within a timeframe
|
||||
# 前10秒火焰粒子
|
||||
execute as @e [name=station, scores={ticks=0..200}] at @s run particle minecraft:basic_flame_particle ~~~
|
||||
|
||||
#Executing commands at specific intervals
|
||||
# 中途提示音效
|
||||
execute as @e [name=station, scores={ticks=3600}] at @s run playsound note.pling @a [r=10]
|
||||
|
||||
#Stopping the timer
|
||||
# 暂停计时条件
|
||||
execute as @e [name=station] at @s if entity @e [family=pacified, r=10, c=1] run scoreboard players set @s ticks -1
|
||||
|
||||
#Looping the timer
|
||||
# 循环计时条件
|
||||
execute as @e [name=station, scores={ticks=6000}] at @s if entity @e [family=monster, r=10, c=1] run scoreboard players set @s ticks 0
|
||||
|
||||
#End
|
||||
# 最终执行
|
||||
kill @e [name=station, scores={ticks=6000}]
|
||||
```
|
||||

|
||||
:::
|
||||
|
||||
As shown; setting the score to 0 when it completes the timeframe will loop the timer and setting the score to -1 will stop/disable it. You can still set the score to 0 to start the timer again.
|
||||

|
||||
|
||||
通过将分数设为0可实现循环计时,设为-1可停止计时。实体将在6000刻(5分钟)后被清除。
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Understanding Selectors
|
||||
category: General
|
||||
title: 选择器详解
|
||||
category: 基础
|
||||
mentions:
|
||||
- Science-geek42
|
||||
- Brougud
|
||||
@@ -10,208 +10,286 @@ mentions:
|
||||
- Hatchibombotar
|
||||
---
|
||||
|
||||
Target selectors are used in commands to target who you want to execute a command on without explicitly setting a target, such as a player's name. A target selector is comprised of a selector variable, and optionally a list of selector arguments.
|
||||
# 选择器详解
|
||||
|
||||
## Selector Variables
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
The selector variable defines the broad list of entities to select. There are six selector variables to choose from:
|
||||
- `@a` - Target all players
|
||||
- `@p` - Target the nearest player
|
||||
- `@r` - Target a random player
|
||||
- `@e` - Target all entities
|
||||
- `@s` - Target the executor
|
||||
- `@initiator` - Target the player interacting with an NPC
|
||||
目标选择器用于在命令中动态指定执行对象,无需明确设置目标(例如玩家名称)。选择器由选择器变量和可选的选择器参数组成。
|
||||
|
||||
## Selector Arguments
|
||||
## 选择器变量
|
||||
|
||||
Selector arguments can narrow down a list of target candidates to those who meet certain conditions. In order to use selector arguments, you must first have a selector variable. To start with selector arguments you must add square brackets `[]` to the end of the chosen target selector like this: `kill @e[]`. Multiple selector arguments can be used by separating them with commas.
|
||||
选择器变量定义了基本的实体筛选范围。共有六种选择器变量可选:
|
||||
- `@a` - 选择所有玩家
|
||||
- `@p` - 选择最近的玩家
|
||||
- `@r` - 随机选择玩家
|
||||
- `@e` - 选择所有实体
|
||||
- `@s` - 选择命令执行者自身
|
||||
- `@initiator` - 选择与NPC交互的玩家
|
||||
|
||||
### Type
|
||||
Limits the selection of targets by their identifier. Negating the argument selects entities without that identifier. This argument cannot be repeated unless negated, since a given entity can only have one identifier. This argument can be used with the selector `@r` to select entities randomly.
|
||||
## 选择器参数
|
||||
|
||||
- `type=<identifier>`—Include only entities with the given identifier.
|
||||
- `type=!<identifier>`—Exclude any entities with the given identifier.
|
||||
选择器参数可进一步缩小候选目标范围。使用参数时需先指定选择器变量,并在其后添加方括号`[]`,例如:`kill @e[]`。多个参数之间用逗号分隔。
|
||||
|
||||
Examples:
|
||||
### Type(类型)
|
||||
根据实体标识符筛选目标。否定参数将排除指定类型的实体。由于每个实体只能有一个标识符,除非使用否定参数,否则该参数不可重复。可与`@r`选择器配合进行随机筛选。
|
||||
|
||||
Affect all pigs with levitation:
|
||||
- `/effect @e[type=pig] levitation`
|
||||
- `type=<标识符>`——仅包含指定类型的实体
|
||||
- `type=!<标识符>`——排除指定类型的实体
|
||||
|
||||
Kill all entities that are not arrows and snowballs:
|
||||
- `/kill @e[type=!arrow,type=!snowball]`
|
||||
示例:
|
||||
|
||||
### Count
|
||||
Limits the number of selected entities, following selector sorting rules.
|
||||
对所有猪施加漂浮效果:
|
||||
::: code-group
|
||||
```json [pig]
|
||||
/effect @e[type=pig] levitation
|
||||
```
|
||||
|
||||
The selectors `@a`, `@p`, and `@e` sort by increasing distance, while `@r` sorts randomly. For the variables `@p` and `@r`, this argument defaults to 1. Negating this argument reverses the sorting order; random sorting cannot be negated.
|
||||
清除所有非箭矢和非雪球的实体:
|
||||
```json [non-arrow/snowball]
|
||||
/kill @e[type=!arrow,type=!snowball]
|
||||
```
|
||||
:::
|
||||
|
||||
- `c=<count>`—Select up to `<count>` entities.
|
||||
### Count(数量)
|
||||
根据排序规则限制选中实体数量。
|
||||
|
||||
Examples:
|
||||
`@a`、`@p`和`@e`按距离升序排列,`@r`随机排列。`@p`和`@r`默认值为1。否定参数将反转排序方向(随机排序不可否定)。
|
||||
|
||||
Clear stone from the closest five players:
|
||||
- `/clear @a[c=5] stone`
|
||||
- `c=<数量>`——选择最多`<数量>`个实体
|
||||
|
||||
Damage the furthest two skeletons:
|
||||
- `/damage @e[type=skeleton,c=-2] 2`
|
||||
示例:
|
||||
|
||||
### Position
|
||||
Changes the position a selector starts its search at. It also modifies where the distance and volume arguments are positioned. Leaving any undefined defaults to the command's current position.
|
||||
清除最近五名玩家背包中的石头:
|
||||
::: code-group
|
||||
```json [5 players]
|
||||
/clear @a[c=5] stone
|
||||
```
|
||||
|
||||
[Relative coordinates](/commands/relative-coordinates#relative-coordinates) can be used to define a relative offset from the command's position.
|
||||
对最远的两只骷髅造成伤害:
|
||||
```json [skeletons]
|
||||
/damage @e[type=skeleton,c=-2] 2
|
||||
```
|
||||
:::
|
||||
|
||||
- `x=<value>`, `y=<value>`, and `z=<value>`—Defines a position for the target selector.
|
||||
### Position(位置)
|
||||
设定选择器的搜索起点,同时影响距离和体积参数的判定基准。未定义时默认使用命令执行位置。
|
||||
|
||||
Examples:
|
||||
可使用[相对坐标](/wiki/commands/relative-coordinates#相对坐标)来设置偏移量。
|
||||
|
||||
Teleport the closest player to (140, 64, -200) ten blocks up:
|
||||
- `/teleport @p[x=140, y=64, z=-200] ~ ~10 ~`
|
||||
- `x=<值>`, `y=<值>`, `z=<值>`——定义选择器的基准坐标
|
||||
|
||||
### Distance
|
||||
Limits the selection of targets by their spherical distance from the selector. This selects entities by their feet.
|
||||
示例:
|
||||
|
||||
- `rm=<value>` and `r=<value>`—Selects entities between the minimum and maximum number of blocks away, inclusive and respectively.
|
||||
将(140,64,-200)处最近的玩家向上传送10格:
|
||||
::: code-group
|
||||
```json [teleport]
|
||||
/teleport @p[x=140, y=64, z=-200] ~ ~10 ~
|
||||
```
|
||||
:::
|
||||
|
||||
Examples:
|
||||
### Distance(距离)
|
||||
根据实体脚部的球面距离筛选目标。
|
||||
|
||||
Kill all chickens between two and six blocks away:
|
||||
- `/kill @e[type=chicken, rm=2, r=6]`
|
||||
- `rm=<值>`和`r=<值>`——分别设置最小和最大距离(包含边界值)
|
||||
|
||||
Enchant the held item with Sharpness for all players within one block of (0, 100, 0):
|
||||
- `/enchant @a[x=0, y=100, z=0, r=1] sharpness`
|
||||
示例:
|
||||
|
||||
### Volume
|
||||
Limits the selection of targets to those inside of a cuboid volume aligned to the block grid. There are three arguments, each determining the size of the box along their respective axes. If at least one argument is defined, any remaining arguments left undefined are assumed to be 0. This selects entities by their feet.
|
||||
清除2到6格范围内的所有鸡:
|
||||
::: code-group
|
||||
```json [chicken]
|
||||
/kill @e[type=chicken, rm=2, r=6]
|
||||
```
|
||||
|
||||
The general formula for calculating the volume between two positions can be viewed as: `dx = x2 - x1; dy = y2 - y1; dz = z2 - z1`.
|
||||
在(0,100,0)1格范围内所有玩家的手持物品附魔锋利:
|
||||
```json [enchant]
|
||||
/enchant @a[x=0, y=100, z=0, r=1] sharpness
|
||||
```
|
||||
:::
|
||||
|
||||
- `dx=<value>`, `dy=<value>`, and `dz=<value>`—Selects entities inside the given bounding box.
|
||||
### Volume(体积)
|
||||
筛选位于方块坐标系对齐的立方体内的实体。三个参数分别定义各轴长度,未定义参数默认为0。以实体脚部为判定点。
|
||||
|
||||
Examples:
|
||||
体积计算公式:`dx = x2 - x1; dy = y2 - y1; dz = z2 - z1`
|
||||
|
||||
List all entities within a 12x30x2 box:
|
||||
- `/say @e[dx=12, dz=30, dy=2]`
|
||||
- `dx=<值>`, `dy=<值>`, `dz=<值>`——定义立方体区域
|
||||
|
||||
Add the "lobby" tag to all players between (-400, 0, -350) and (-150, 256, 50):
|
||||
- `/tag @a[x=-400, y=0, z=-350, dx=250, dy=256, dz=400] add lobby`
|
||||
示例:
|
||||
|
||||
### Scores
|
||||
Limits the selection of targets by their score value. This argument is represented as an object, with key-value pairs for a scoreboard objective and a value. The value can represent a range of numbers, using the range syntax. The value of a score can be negated to test if the entity does not have a score value within that range.
|
||||
列出12x30x2区域内的所有实体:
|
||||
::: code-group
|
||||
```json [say]
|
||||
/say @e[dx=12, dz=30, dy=2]
|
||||
```
|
||||
|
||||
- `scores={<objective>=<value>}`—Selects entities whose score under the given objective matches the given value.
|
||||
为(-400,0,-350)到(-150,256,50)区域内的玩家添加"lobby"标签:
|
||||
```json [tag]
|
||||
/tag @a[x=-400, y=0, z=-350, dx=250, dy=256, dz=400] add lobby
|
||||
```
|
||||
:::
|
||||
|
||||
The range syntax works as follows:
|
||||
- `N..` is any number greater than or equal to N.
|
||||
- `..N` is any number less than or equal to N.
|
||||
- `N..M` is any number between N and M, inclusive.
|
||||
### Scores(计分板)
|
||||
根据计分板分数筛选目标。参数格式为对象,包含计分项与数值的键值对。数值可使用范围语法。否定参数将排除分数范围内的实体。
|
||||
|
||||
Examples:
|
||||
- `scores={<计分项>=<数值>}`——筛选符合分数条件的实体
|
||||
|
||||
Set the "points" score for all players with a "points" score of ten to 0:
|
||||
- `/scoreboard players set @p[scores={points=10}] points 0`
|
||||
范围语法说明:
|
||||
- `N..`:大于等于N的数值
|
||||
- `..N`:小于等于N的数值
|
||||
- `N..M`:介于N到M之间的数值(包含边界)
|
||||
|
||||
Add the "start" tag to armor stands with both a "started" score of one, and a "timer" score of 20 or less:
|
||||
- `/tag @e[type=armor_stand, scores={started=1, timer=..20}] add start`
|
||||
示例:
|
||||
|
||||
### Name
|
||||
Limits the selection of targets by name. Negating the argument selects entities whose name does not match.
|
||||
将"points"分数为10的玩家分数重置为0:
|
||||
::: code-group
|
||||
```json [points]
|
||||
/scoreboard players set @p[scores={points=10}] points 0
|
||||
```
|
||||
|
||||
- `name=<name>`—Include only entities with the given name.
|
||||
- `name=!<name>`—Exclude any entities with the given name.
|
||||
为同时满足"started=1"且"timer≤20"的盔甲架添加"start"标签:
|
||||
```json [armor_stand]
|
||||
/tag @e[type=armor_stand, scores={started=1, timer=..20}] add start
|
||||
```
|
||||
:::
|
||||
|
||||
Examples:
|
||||
### Name(名称)
|
||||
根据实体名称筛选目标。否定参数将排除指定名称的实体。
|
||||
|
||||
List all zombies named Shadow:
|
||||
- `/say @e[type=zombie, name=Shadow]`
|
||||
- `name=<名称>`——仅包含指定名称的实体
|
||||
- `name=!<名称>`——排除指定名称的实体
|
||||
|
||||
Give one level to players both not named Steve and not named Alex:
|
||||
- `/xp 1L @a[name=!Steve, name=!Alex]`
|
||||
示例:
|
||||
|
||||
### Tag
|
||||
Limits the selection of targets by their tags. This argument can be repeated to test for multiple tags, and all filters must pass for an entity to be selected. Negating this argument selects entities without that tag.
|
||||
列出所有名为Shadow的僵尸:
|
||||
::: code-group
|
||||
```json [zombie]
|
||||
/say @e[type=zombie, name=Shadow]
|
||||
```
|
||||
|
||||
- `tag=<tag>`—Include only entities with the given tag.
|
||||
- `tag=!<tag>`—Exclude any entities with the given tag.
|
||||
给非Steve和非Alex的玩家提升1级:
|
||||
```json [xp]
|
||||
/xp 1L @a[name=!Steve, name=!Alex]
|
||||
```
|
||||
:::
|
||||
|
||||
Examples:
|
||||
### Tag(标签)
|
||||
根据实体标签筛选目标。可重复使用多个标签参数,所有条件需同时满足。否定参数将排除具有指定标签的实体。
|
||||
|
||||
Kill all mobs with the tag "marked", and without the tag "exempt":
|
||||
- `/kill @e[tag=marked, tag=!exempt]`
|
||||
- `tag=<标签>`——仅包含具有指定标签的实体
|
||||
- `tag=!<标签>`——排除具有指定标签的实体
|
||||
|
||||
### Family
|
||||
Limits the selection of targets by type family. This argument can be repeated to test for multiple families, and all filters must pass for an entity to be selected. Negating this argument selects entities whose type family does not match.
|
||||
示例:
|
||||
|
||||
- `family=<family>`—Include only entities with the given type family.
|
||||
- `family=!<family>`—Exclude any entities with the given type family.
|
||||
清除所有带"marked"标签且无"exempt"标签的生物:
|
||||
::: code-group
|
||||
```json [marked]
|
||||
/kill @e[tag=marked, tag=!exempt]
|
||||
```
|
||||
:::
|
||||
|
||||
Examples:
|
||||
### Family(族群)
|
||||
根据实体族群类型筛选目标。可重复使用多个族群参数,所有条件需同时满足。否定参数将排除指定族群的实体。
|
||||
|
||||
Affect all entities in the "monster" family with Regeneration:
|
||||
- `/effect @e[family=monster] regeneration`
|
||||
- `family=<族群>`——仅包含指定族群的实体
|
||||
- `family=!<族群>`——排除指定族群的实体
|
||||
|
||||
### Rotation
|
||||
Limits the selection of targets by their rotation. There are two types of rotation: x-rotation, which is vertical rotation around the x-axis; and y-rotation, which is horizontal rotation around the y-axis. X-rotation ranges between -90 and 90 (180° total), going from looking up to down; and y-rotation ranges between -180 and 180 (360° total), starting and ending at North, wrapping around clockwise.
|
||||
示例:
|
||||
|
||||
对"monster"族群的所有实体施加再生效果:
|
||||
::: code-group
|
||||
```json [monster]
|
||||
/effect @e[family=monster] regeneration
|
||||
```
|
||||
:::
|
||||
|
||||
### Rotation(旋转角度)
|
||||
根据实体视角筛选目标。分为垂直视角(x轴旋转,范围-90~90)和水平视角(y轴旋转,范围-180~180)。
|
||||
|
||||
- `rxm=<value>` and `rx=<value>`—Selects entities whose x-rotation is between the minimum and maximum values, inclusive and respectively.
|
||||
- `rym=<value>` and `ry=<value>`—Selects entities whose y-rotation is between the minimum and maximum values, inclusive and respectively.
|
||||
- `rxm=<值>`和`rx=<值>`——垂直视角范围
|
||||
- `rym=<值>`和`ry=<值>`——水平视角范围
|
||||
|
||||
Examples:
|
||||
示例:
|
||||
|
||||
Affect all players looking at or above the horizon with Blindness for one second:
|
||||
- `/effect @a[rx=0] blindness 1` (0 or less)
|
||||
|
||||
Damage all players facing generally south:
|
||||
- `/damage @a[rym=-45, ry=45] 1`
|
||||
|
||||
### Level
|
||||
Limits the selection of targets by experience levels. Only players can have EXP, so this filters out non-player targets.
|
||||
|
||||
- `lm=<amount>` and `l=<amount>`—Selects players whose EXP levels are between the minimum and maximum values specified, inclusive and respectively.
|
||||
|
||||
Examples:
|
||||
|
||||
Give all players who have between three and eight levels a diamond:
|
||||
- `/give @a[lm=3, l=8] diamond`
|
||||
|
||||
### Game mode
|
||||
Limits the selection of targets by game mode. Only players can use game mode, so this filters out non-player targets. Negating the argument selects targets whose game mode does not match.
|
||||
|
||||
- `m=<gamemode>`—Selects players by their game mode.
|
||||
|
||||
Possible values include:
|
||||
* `0`, `s`, or `survival` for Survival mode
|
||||
* `1`, `c`, or `creative` for Creative mode
|
||||
* `2`, `a`, or `adventure` for Adventure mode
|
||||
* `spectator` for Spectator mode
|
||||
* `d` or `default` for the default game mode
|
||||
|
||||
Examples:
|
||||
|
||||
List all players in Creative mode:
|
||||
- `/say @a[m=creative]`
|
||||
|
||||
Set the game mode to Creative mode for players both not in Survival mode, and not in Adventure mode:
|
||||
- `/gamemode creative @a[m=!survival, m=!adventure]`
|
||||
|
||||
### Items
|
||||
Limits the selection of targets by what items they have in their inventory. This argument is represented as an object, or an array of objects, with up to one each of the following parameters:
|
||||
|
||||
- `item=<string>`—The identifier of the item to test for, and the only required argument. This can accept custom identifiers too.
|
||||
- `quantity=<int>`—The amount of the item to test for. Accepts a [range](/commands/selectors#scores) for a value. This argument can also be negated.
|
||||
- `data=<int>`—The data value of the item to test for. Defaults to -1. **Currently not functional:** [MCPE-151920](https://bugs.mojang.com/browse/MCPE-151920)
|
||||
- `location=<string>`—The slot the item should be located in. Accepts the same arguments as the slotType argument in the `/replaceitem` command.
|
||||
- `slot=<int>`—The index of the slot used in the "location" argument, and can only be used with "location". Accepts a range for a value. This argument can be negated.
|
||||
|
||||
Examples:
|
||||
|
||||
Checks for players who have a netherite sword in their inventory:
|
||||
- `/testfor @a[hasitem={item=netherite_sword}]`
|
||||
|
||||
Clears 2 apples for players that have four or more apples:
|
||||
- `/clear @a[hasitem={item=apple,quantity=4..}] apple 2`
|
||||
|
||||
Checks for players who have two sticks and two diamonds:
|
||||
- `/testfor @a[hasitem=[{item=diamond,quantity=2},{item=stick,quantity=2}]]`
|
||||
|
||||
Checks for players who doesn't have a stick:
|
||||
- `/testfor @a[hasitem=[{item=stick,quantity=0}]`
|
||||
对仰角≥0度(平视或俯视)的玩家施加1秒失明:
|
||||
::: code-group
|
||||
```json [blindness]
|
||||
/effect @a[rx=0] blindness 1
|
||||
```
|
||||
|
||||
对朝南方向(-45°~45°)的玩家造成伤害:
|
||||
```json [damage]
|
||||
/damage @a[rym=-45, ry=45] 1
|
||||
```
|
||||
:::
|
||||
|
||||
### Level(经验等级)
|
||||
根据玩家经验等级筛选目标(仅限玩家)。
|
||||
|
||||
- `lm=<数值>`和`l=<数值>`——分别设置最低和最高等级(包含边界)
|
||||
|
||||
示例:
|
||||
|
||||
给3-8级的玩家发放钻石:
|
||||
::: code-group
|
||||
```json [diamond]
|
||||
/give @a[lm=3, l=8] diamond
|
||||
```
|
||||
:::
|
||||
|
||||
### Game mode(游戏模式)
|
||||
根据游戏模式筛选玩家目标。否定参数将排除指定模式的玩家。
|
||||
|
||||
- `m=<模式>`——筛选指定游戏模式
|
||||
|
||||
可用模式值:
|
||||
* `0`、`s`或`survival`:生存模式
|
||||
* `1`、`c`或`creative`:创造模式
|
||||
* `2`、`a`或`adventure`:冒险模式
|
||||
* `spectator`:旁观模式
|
||||
* `d`或`default`:默认模式
|
||||
|
||||
示例:
|
||||
|
||||
列出所有创造模式玩家:
|
||||
::: code-group
|
||||
```json [creative]
|
||||
/say @a[m=creative]
|
||||
```
|
||||
|
||||
将非生存和非冒险模式的玩家设为创造模式:
|
||||
```json [gamemode]
|
||||
/gamemode creative @a[m=!survival, m=!adventure]
|
||||
```
|
||||
:::
|
||||
|
||||
### Items(物品)
|
||||
根据物品栏内容筛选目标。参数格式为对象或对象数组,支持以下参数:
|
||||
|
||||
- `item=<字符串>`——物品标识符(必填)
|
||||
- `quantity=<整数>`——物品数量(支持范围语法,可否定)
|
||||
- `data=<整数>`——物品数据值(默认-1,**当前不可用**:[MCPE-151920](https://bugs.mojang.com/browse/MCPE-151920))
|
||||
- `location=<字符串>`——物品所在栏位(与`/replaceitem`的slotType参数一致)
|
||||
- `slot=<整数>`——栏位索引(需配合location使用,支持范围语法,可否定)
|
||||
|
||||
示例:
|
||||
|
||||
检测携带下界合金剑的玩家:
|
||||
::: code-group
|
||||
```json [netherite_sword]
|
||||
/testfor @a[hasitem={item=netherite_sword}]
|
||||
```
|
||||
|
||||
清除拥有≥4个苹果的玩家2个苹果:
|
||||
```json [apple]
|
||||
/clear @a[hasitem={item=apple,quantity=4..}] apple 2
|
||||
```
|
||||
|
||||
检测携带2钻石+2木棍的玩家:
|
||||
```json [multiple]
|
||||
/testfor @a[hasitem=[{item=diamond,quantity=2},{item=stick,quantity=2}]]
|
||||
```
|
||||
|
||||
检测未携带木棍的玩家:
|
||||
```json [negation]
|
||||
/testfor @a[hasitem=[{item=stick,quantity=0}]
|
||||
```
|
||||
:::
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Tellraw
|
||||
category: Commands
|
||||
title: tellraw命令
|
||||
category: 命令
|
||||
mentions:
|
||||
- SirLich
|
||||
- Dreamedc2015
|
||||
@@ -13,120 +13,110 @@ mentions:
|
||||
- SmokeyStack
|
||||
---
|
||||
|
||||
tellraw sends a JSON message to selected or all players being useful for sending plain messages to players ingame
|
||||
# tellraw命令
|
||||
|
||||
**The titleraw command follows the same theme**
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
`tellraw` 用于向指定或所有玩家发送JSON格式消息,适用于在游戏中向玩家发送纯文本信息
|
||||
|
||||
**titleraw命令遵循相同的设计理念**
|
||||
|
||||

|
||||
|
||||
## 格式规范
|
||||
|
||||
## Format
|
||||
|
||||
this is how the tell raw command is formatted
|
||||
`tellraw`命令的基础语法结构如下:
|
||||
|
||||
```
|
||||
tellraw <target: target> <raw json message: json>
|
||||
tellraw <目标: 目标> <原始JSON消息: json>
|
||||
```
|
||||
|
||||
- ` <target: target>`: The target is expressed as a playername or player groups such as `@a` `@r` `@s` `@p`
|
||||
- `<raw json message: json>`: This is a json schema that tells how the message is structured or constructed. expressed with for example:
|
||||
- ` <目标: 目标>`: 目标可以表示为玩家名称或玩家组,例如`@a` `@r` `@s` `@p`
|
||||
- `<原始JSON消息: json>`: 用于定义消息结构的JSON格式,例如:
|
||||
`{"rawtext":[{"text":""}]}`
|
||||
|
||||
## 基础示例
|
||||
|
||||
## Examples
|
||||
发送引号内的文字内容
|
||||
|
||||
This sends the words in the last set of quotes
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [命令]
|
||||
/tellraw @a {"rawtext":[{"text":"Hello"}]}
|
||||
```
|
||||
:::
|
||||
|
||||
## 转义字符处理
|
||||
|
||||
## Escaping Characters
|
||||
在消息中使用引号时,需在引号左侧添加反斜杠进行转义
|
||||
|
||||
To use quotations in a tellraw message place a backslash to the left side of the quotation mark.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [命令]
|
||||
/tellraw @a {"rawtext":[{"text":"Quote me: \"I am here\"."}]}
|
||||
```
|
||||
:::
|
||||
|
||||
## 换行处理
|
||||
|
||||
## Line breaks
|
||||
使用`\n`实现文本换行
|
||||
|
||||
To insert a line break use `\n`
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [命令]
|
||||
/tellraw @a { "rawtext": [ { "text":"I am line one\nI am line two" } ] }
|
||||
```
|
||||
:::
|
||||
|
||||
## 显示实体/玩家信息
|
||||
|
||||
## Displaying entities / player
|
||||
通过选择器显示实体名称的用法示例
|
||||
|
||||
You can use the following to use selector to display names.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [命令]
|
||||
/tellraw @a {"rawtext": [{"text": "§6The winner is: §a"}, {"selector": "@a[r=5,c=1]"}]}
|
||||
```
|
||||
:::
|
||||
|
||||
## 显示计分板数值
|
||||
|
||||
## Displaying scores
|
||||
显示玩家计分板数值的复合用法
|
||||
|
||||
You can use the following to use selector to display names.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [命令]
|
||||
/tellraw @a {"rawtext": [{"text": "§6The winner is: §a"}, {"selector": "@a[r=5,c=1]"}, {"text": "§6With a score of: "}, {"score":{"name": "@s","objective": "value"}}]}
|
||||
```
|
||||
:::
|
||||
|
||||
## 多语言文本翻译
|
||||
|
||||
## Translate text
|
||||
使用translate组件配合[翻译键](/wiki/concepts/text-and-translations)实现多语言支持。注意需在对应语言的.lang文件中配置翻译内容
|
||||
|
||||
To have a language dependant text you can use the translate component and [translation keys](/concepts/text-and-translations). please note you will need relevant information in each of the desired .lang files for this to work.
|
||||
|
||||
|
||||
<CodeHeader>RP/texts/en_US.lang</CodeHeader>
|
||||
|
||||
```
|
||||
::: code-group
|
||||
```json [RP/texts/en_US.lang]
|
||||
example.langcode.1=I am line one
|
||||
```
|
||||
|
||||
<CodeHeader>RP/texts/de_DE.lang</CodeHeader>
|
||||
|
||||
```
|
||||
```json [RP/texts/de_DE.lang]
|
||||
example.langcode.1=Ich bin Zeile eins
|
||||
```
|
||||
:::
|
||||
|
||||
对应命令:
|
||||
|
||||
The command:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [命令]
|
||||
/tellraw @a { "rawtext": [ { "translate": "example.langcode.1" } ] }
|
||||
```
|
||||
:::
|
||||
|
||||
## 复合型翻译模板
|
||||
|
||||
## Translate text with selectors/scores
|
||||
多语言文件配置:
|
||||
|
||||
language files:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```
|
||||
::: code-group
|
||||
```json [示例]
|
||||
example.langcode.2=The winner is: %s. With a score of %s
|
||||
```
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
```json [命令]
|
||||
/tellraw @a {"rawtext":[{"translate":"example.langcode.2","with":{"rawtext":[{"selector":"@a[r=5,c=1]"},{"text":"§6With a score of: "},{"score":{"name":"@s","objective":"value"}}]}}]}
|
||||
```
|
||||
:::
|
||||
Reference in New Issue
Block a user