完整版BedrockWiki镜像!
This commit is contained in:
@@ -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`
|
||||
Reference in New Issue
Block a user