搬运一批Bedrock wiki内容,完善翻译
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: Creating Boats
|
||||
category: Tutorials
|
||||
title: 创建船只
|
||||
category: 教程
|
||||
tags:
|
||||
- recipe
|
||||
- intermediate
|
||||
- 配方
|
||||
- 进阶
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
@@ -11,25 +11,29 @@ mentions:
|
||||
- StealthyExpertX
|
||||
- TheItsNameless
|
||||
---
|
||||
:::warning Requires Format Version 1.16.100 or Lower
|
||||
|
||||
The behavior format version now requires 1.16.100 or lower for the `minecraft:behavior.rise_to_liquid_level` and `minecraft:buoyant` methods to work.
|
||||
If you find a new method that works in the newer format versions, you should consider helping to contribute by updating the wiki.
|
||||
# 创建船只
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
:::warning 需要格式版本1.16.100或更低
|
||||
|
||||
当前行为格式版本要求1.16.100或更低版本才能使`minecraft:behavior.rise_to_liquid_level`和`minecraft:buoyant`功能生效。
|
||||
如果您发现新格式版本中的替代实现方法,欢迎协助更新本Wiki内容。
|
||||
:::
|
||||
|
||||
## Using Runtime Identifiers
|
||||
## 使用运行时标识符
|
||||
|
||||
You can read more about runtime identifiers [here](/entities/runtime-identifier). Using runtime identifiers, you can implement most of the boat's hard-coded behaviors. However, your boat won't rotate with you, and it will always face North.
|
||||
详细内容请参阅[运行时标识符指南](/entities/runtime-identifier)。使用运行时标识符可以实现船只的大部分硬编码行为,但会导致船只无法随玩家转向且始终面向北方。
|
||||
|
||||
## Using Components
|
||||
## 利用组件系统实现
|
||||
|
||||
Currently, the best way to create a boat entity is by using components. 1.16 introduced new components that we can use to our advantage: `minecraft:behavior.rise_to_liquid_level` and `minecraft:buoyant`. Striders use the first one in vanilla to make them float on lava, but we can repurpose it for water as well.
|
||||
目前最佳的船只创建方案是通过组件系统实现。1.16版本新增的两个组件可资利用:`minecraft:behavior.rise_to_liquid_level`与`minecraft:buoyant`。官方设计中前者用于岩浆怪的岩浆漂浮特性,我们可以将其移植到水面上使用。
|
||||
|
||||
## 1st method: minecraft:behavior.rise_to_liquid_level
|
||||
## 第一种方法:minecraft:behavior.rise_to_liquid_level
|
||||
|
||||
<CodeHeader>BP/entities/bar</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/bar]
|
||||
{
|
||||
"minecraft:entity": {
|
||||
"format_version": "1.14.0",
|
||||
@@ -40,23 +44,23 @@ Currently, the best way to create a boat entity is by using components. 1.16 int
|
||||
"is_experimental": false
|
||||
},
|
||||
"components": {
|
||||
//This is the component that does the magic
|
||||
// 这是实现效果的核心组件
|
||||
"minecraft:behavior.rise_to_liquid_level": {
|
||||
"priority": 0,
|
||||
//This property can adjust how high your boat is above the water
|
||||
// 控制船体相对于水面的基准高度
|
||||
"liquid_y_offset": 0.5,
|
||||
//Positive vertical displacement, in other words, how much the boat will move up
|
||||
// 正垂直位移量,决定船体抬升幅度
|
||||
"rise_delta": 0.05,
|
||||
//Negative vertical displacement, in other words, how much the boat will move down
|
||||
// 负垂直位移量,决定船体下沉幅度
|
||||
"sink_delta": 0.05
|
||||
//Use rise_delta and sink_delta to simulate waves/bouncing effect
|
||||
// 通过升降参数可模拟波浪浮动效果
|
||||
},
|
||||
|
||||
//Sets the boat speed in water
|
||||
// 设置水上移动速率
|
||||
"minecraft:underwater_movement": {
|
||||
"value": 5
|
||||
},
|
||||
//This component is important, without it the boat will sink
|
||||
// 关键组件,移除会导致船体沉没
|
||||
"minecraft:navigation.walk": {
|
||||
"can_sink": false
|
||||
},
|
||||
@@ -68,17 +72,17 @@ Currently, the best way to create a boat entity is by using components. 1.16 int
|
||||
"position": [0, 0, 0]
|
||||
}
|
||||
},
|
||||
//Add this component if you want your boat to be controlled with WASD
|
||||
// 添加此组件实现WASD方向控制
|
||||
"minecraft:input_ground_controlled": {},
|
||||
"minecraft:health": {
|
||||
"value": 10,
|
||||
"max": 10
|
||||
},
|
||||
//Sets the boat speed on the ground (set this to zero if you don't want your boats to move on the ground)
|
||||
// 设置地面移动速度(设置为0可禁用地表移动)
|
||||
"minecraft:movement": {
|
||||
"value": 3
|
||||
},
|
||||
//This is to prevent the boat from not stopping whenever a player exits, said the boat
|
||||
// 防止玩家下船后无法停止移动
|
||||
"minecraft:movement.basic": {},
|
||||
"minecraft:collision_box": {
|
||||
"width": 1,
|
||||
@@ -89,12 +93,12 @@ Currently, the best way to create a boat entity is by using components. 1.16 int
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## 2nd method: minecraft:buoyant
|
||||
## 第二种方法:minecraft:buoyant
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json []
|
||||
{
|
||||
"minecraft:entity": {
|
||||
"format_version": "1.14.0",
|
||||
@@ -106,27 +110,27 @@ Currently, the best way to create a boat entity is by using components. 1.16 int
|
||||
},
|
||||
"components": {
|
||||
"minecraft:buoyant": {
|
||||
//Determines whether gravity should be taken into account (useful with waterfalls)
|
||||
// 是否受重力影响(处理瀑布场景很有用)
|
||||
"apply_gravity": true,
|
||||
//Range: 0-1. This controls how high the boat is above the water
|
||||
// 范围0-1,控制船体默认高度
|
||||
"base_buoyancy": 1.0,
|
||||
//A "wave" makes the entity bounce up and down. A big wave simply amplifies this effect. Note: setting simulate_waves to false won't make the effect go away completely.
|
||||
// 「浪涌」模拟船体上下波动效果(false也不会完全消除效果)
|
||||
"simulate_waves": true,
|
||||
//How likely a "big" wave will hit this boat
|
||||
// 产生「大浪」的概率
|
||||
"big_wave_probability": 0.03,
|
||||
//How strong the "big" wave will be
|
||||
// 「大浪」强度系数
|
||||
"big_wave_speed": 10.0,
|
||||
//How strong will the boat be dragged down in case this component is removed
|
||||
// 移除浮力后的下沉阻力
|
||||
"drag_down_on_buoyancy_removed": 0,
|
||||
//Blocks this entity can be buoyant in. Only actual liquids are allowed: lava and water
|
||||
// 支持浮力的液态方块(仅限水和岩浆)
|
||||
"liquid_blocks": ["water"]
|
||||
},
|
||||
|
||||
//Sets the boat speed in water
|
||||
// 设置水上移动速率
|
||||
"minecraft:underwater_movement": {
|
||||
"value": 5
|
||||
},
|
||||
//This component is important, without it the boat will sink
|
||||
// 关键组件,移除会导致船体沉没
|
||||
"minecraft:navigation.walk": {
|
||||
"can_sink": false
|
||||
},
|
||||
@@ -138,17 +142,17 @@ Currently, the best way to create a boat entity is by using components. 1.16 int
|
||||
"position": [0, 0, 0]
|
||||
}
|
||||
},
|
||||
//Add this component if you want your boat to be controlled with WASD
|
||||
// 添加此组件实现WASD方向控制
|
||||
"minecraft:input_ground_controlled": {},
|
||||
"minecraft:health": {
|
||||
"value": 10,
|
||||
"max": 10
|
||||
},
|
||||
//Sets the boat speed on the ground (set this to zero if you don't want your boats to move on the ground)
|
||||
// 设置地面移动速度(设置为0可禁用地表移动)
|
||||
"minecraft:movement": {
|
||||
"value": 3
|
||||
},
|
||||
//This is to prevent the boat from not stopping whenever a player exits the boat
|
||||
// 防止玩家下船后无法停止移动
|
||||
"minecraft:movement.basic": {},
|
||||
"minecraft:collision_box": {
|
||||
"width": 1,
|
||||
@@ -159,7 +163,8 @@ Currently, the best way to create a boat entity is by using components. 1.16 int
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## What method to use?
|
||||
## 方法选择建议
|
||||
|
||||
Both methods are suitable but have their pros and cons. If you want to disable the bouncing effect, use the first method. If you want more control over it, use the second method. I use the second method for static objects, such as buoys, and the first method for movable entities, such as boats, emulating the vanilla behavior.
|
||||
两种方式各有优劣。若需禁用波动效果建议采用第一种方式;若需要进行精细调控可选择第二种方法。开发实践中,第二种常用于浮标等静态物体,第一种则更适合船只等运动实体,能更好地还原原版特性。
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Detecting Other Entities
|
||||
category: Tutorials
|
||||
title: 侦测其他实体
|
||||
category: 教程
|
||||
tags:
|
||||
- intermediate
|
||||
- 中级
|
||||
mentions:
|
||||
- ANightDazingZoroark
|
||||
- SmokeyStack
|
||||
@@ -12,210 +12,189 @@ mentions:
|
||||
- TheItsNameless
|
||||
---
|
||||
|
||||
You might have thought about making your entities fire an event when other entities are nearby. This article details the various known ways to do so.
|
||||
# 侦测其他实体
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
当需要让实体在附近存在其他实体时触发事件,本文将详细介绍多种已知实现方式。
|
||||
|
||||
## minecraft:entity_sensor
|
||||
|
||||
This is probably the most basic way to detect other entities. The main issues is it only accepts one entry and testing if the entity is out of range can be very tricky. Because it's an entity component, you can just place into your entity behavior file and edit the Minecraft filters. Here's a demonstration:
|
||||
这是最基础的侦测方式。主要限制是只能接收单一条目,且检测实体退出范围较困难。作为实体组件,可直接植入实体行为文件并配置Minecraft过滤器:
|
||||
|
||||
<CodeHeader>BP/entities/my_entity.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/my_entity.json#components]
|
||||
"minecraft:entity_sensor": {
|
||||
"sensor_range": 2.5, //this is for the radius in blocks it will detect other entities in
|
||||
"relative_range": false, //if true, the sensor range is additive on top of the entity's hitbox size
|
||||
"require_all": true, //if true, all nearby entities must pass the filter conditions for the event to send
|
||||
"minimum_count": 1, //minimum amount of entities required for the event to fire. by default, it's 1
|
||||
"maximum_count": 4, //maximum amount of entities required for the event to fire. by default it's -1, which means infinity
|
||||
"event_filters": { //you can put any filter you want here, the one that's being used in this example just detects players
|
||||
"sensor_range": 2.5, //检测半径(格子数)
|
||||
"relative_range": false, //若为true,检测范围会叠加实体碰撞箱
|
||||
"require_all": true, //若为true,所有邻近实体需通过过滤条件才会触发事件
|
||||
"minimum_count": 1, //触发事件的最小实体数量(默认1)
|
||||
"maximum_count": 4, //触发事件的最大实体数量(默认-1表示无限)
|
||||
"event_filters": { //自定义过滤器(本例检测玩家)
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
},
|
||||
"event": "event:on_player_detected" //the event that fires when all the conditions in event_filters are met
|
||||
"event": "event:on_player_detected" //条件满足时触发的事件
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## `/execute`
|
||||
## `/execute` 命令
|
||||
|
||||
Using the new `/execute` command that has been introduced since 1.19.50, you can execute commands as long as another entity is nearby.
|
||||
使用1.19.50版本新增的`/execute`命令,可在附近存在实体时执行指令。以下示例使猪在检测到玩家时发出"oink oink"声(可自定义事件):
|
||||
|
||||
This example you'll be following will make pigs say "oink oink" upon detecting players, though you can replace those with whatever you want. First of all, copy-paste these BP animations.
|
||||
|
||||
<CodeHeader>BP/animations/detection_animation.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/animations/detection_animation.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animations": {
|
||||
"animation.pig.find_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"/execute as @s if entity @e[type=player, r=4] run event entity @s wiki:player_detected"
|
||||
]
|
||||
}
|
||||
"format_version": "1.10.0",
|
||||
"animations": {
|
||||
"animation.pig.find_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"/execute as @s if entity @e[type=player, r=4] run event entity @s wiki:player_detected"
|
||||
]
|
||||
}
|
||||
},
|
||||
"animation.pig.find_no_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"/execute as @s unless entity @e[type=player, r=4] run event entity @s wiki:no_player_detected"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
首个动画用于检测实体存在,第二个检测实体离开。可通过`/event`命令添加[虚拟组件](/entities/dummy-components)或更新[实体属性](https://learn.microsoft.com/zh-cn/minecraft/creator/documents/introductiontoentityproperties)。
|
||||
|
||||
::: code-group
|
||||
```json [BP/animation_controllers/pig_animation_controllers.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
"controller.animation.pig_find_player": {
|
||||
"initial_state": "default",
|
||||
"states": {
|
||||
"default": {
|
||||
"animations": ["find_player"],
|
||||
"transitions": [{
|
||||
"detected": "q.is_sheared"
|
||||
}]
|
||||
},
|
||||
"animation.pig.find_no_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"/execute as @s unless entity @e[type=player, r=4] run event entity @s wiki:no_player_detected"
|
||||
]
|
||||
}
|
||||
"detected": {
|
||||
"animations": ["find_no_player"],
|
||||
"transitions": [{
|
||||
"default": "!q.is_sheared"
|
||||
}],
|
||||
"on_entry": ["/say oink oink"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
The first one is for detecting if the entity is present, and the other for detecting if the entity is not present. The events used in the `/event` part of the `/execute` commands can be used for adding a [dummy component](/entities/dummy-components) or updating an [actor property](https://learn.microsoft.com/en-us/minecraft/creator/documents/introductiontoentityproperties).
|
||||
|
||||
Next of all, copy paste this BP animation controller. This assumes that you set up the `/event` parts of the `/execute` commands to add or remove `minecraft:is_sheared`.
|
||||
|
||||
<CodeHeader>BP/animation_controllers/pig_animation_controllers.json</CodeHeader>
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
"controller.animation.pig_find_player": {
|
||||
"initial_state": "default",
|
||||
"states": {
|
||||
"default": {
|
||||
"animations": ["find_player"],
|
||||
"transitions": [
|
||||
{
|
||||
"detected": "q.is_sheared"
|
||||
}
|
||||
]
|
||||
},
|
||||
"detected": {
|
||||
"animations": ["find_no_player"],
|
||||
"transitions": [
|
||||
{
|
||||
"default": "!q.is_sheared"
|
||||
}
|
||||
],
|
||||
"on_entry": ["/say oink oink"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Finally, copy-paste this snippet into the behavior file for the pig-like so. Make sure to insert this in `description`.
|
||||
|
||||
<CodeHeader>BP/entities/my_entity.json#description</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/my_entity.json#description]
|
||||
"animations": {
|
||||
"manage_find_player": "controller.animation.pig_find_player",
|
||||
"find_player": "animation.pig.find_player",
|
||||
"find_no_player": "animation.pig.find_no_player"
|
||||
"manage_find_player": "controller.animation.pig_find_player",
|
||||
"find_player": "animation.pig.find_player",
|
||||
"find_no_player": "animation.pig.find_no_player"
|
||||
},
|
||||
"scripts": {
|
||||
"animate": [
|
||||
"manage_find_player"
|
||||
]
|
||||
"animate": ["manage_find_player"]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## Molang, BP Animations & Animation Controllers
|
||||
## Molang、动画与动画控制器
|
||||
|
||||
The `for_each` function and `q.get_nearby_entities` or `q.get_nearby_entities_except_self` can also be used for detecting other entities. They are more effective than using `minecraft:entity_sensor` because they are better at detecting if the entity you want to detect goes away than with `minecraft:entity_sensor`. The only downside is that they're experimental.
|
||||
使用`for_each`函数配合`q.get_nearby_entities`或`q.get_nearby_entities_except_self`可更高效检测实体(实验性功能),能更好处理实体离开的情况。
|
||||
|
||||
Just like in the previous method we will make pigs say "oink oink" upon detecting players, though you can replace those with whatever you want. First of all, copy-paste this BP animation:
|
||||
|
||||
<CodeHeader>BP/animations/detection_animation.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/animations/detection_animation.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animations": {
|
||||
"animation.pig.find_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"v.x = 0.0; for_each(t.player, q.get_nearby_entities_except_self(16, 'minecraft:player'), { v.x = v.x + 1; }); return v.x > 0.0;"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
"format_version": "1.10.0",
|
||||
"animations": {
|
||||
"animation.pig.find_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"v.x = 0.0; for_each(t.player, q.get_nearby_entities_except_self(16, 'minecraft:player'), { v.x = v.x + 1; }); return v.x > 0.0;"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
The first parameter that `q.get_nearby_entities_except_self` needs to work is the radius in blocks it will detect other entities in. The other is the identifier of the mob you want to make it detect.
|
||||
若要检测具备特定Molang属性的实体:
|
||||
|
||||
Now that's good and all, but on the off chance, you want to make the pig detect players with some attribute that can be detected with Molang, use this.
|
||||
|
||||
<CodeHeader>BP/animations/detection_animation.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/animations/detection_animation.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animations": {
|
||||
"animation.pig.find_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"v.x = 0.0; for_each(t.player, q.get_nearby_entities_except_self(2, 'minecraft:player'), { v.x = v.x + (t.player -> q.is_sheared); }); return v.x > 0.0;"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
"format_version": "1.10.0",
|
||||
"animations": {
|
||||
"animation.pig.find_player": {
|
||||
"animation_length": 0.05,
|
||||
"loop": true,
|
||||
"timeline": {
|
||||
"0": [
|
||||
"v.x = 0.0; for_each(t.player, q.get_nearby_entities_except_self(2, 'minecraft:player'), { v.x = v.x + (t.player -> q.is_sheared); }); return v.x > 0.0;"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Next of all, copy paste this BP animation controller:
|
||||
|
||||
<CodeHeader>BP/animation_controllers/pig_animation_controllers.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/animation_controllers/pig_animation_controllers.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
"controller.animation.pig_find_player": {
|
||||
"initial_state": "default",
|
||||
"states": {
|
||||
"default": {
|
||||
"animations": ["find_player"],
|
||||
"transitions": [
|
||||
{
|
||||
"detected": "v.x > 0"
|
||||
}
|
||||
]
|
||||
},
|
||||
"detected": {
|
||||
"animations": ["find_player"],
|
||||
"transitions": [
|
||||
{
|
||||
"default": "v.x <= 0"
|
||||
}
|
||||
],
|
||||
"on_entry": ["/say oink oink"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
"controller.animation.pig_find_player": {
|
||||
"initial_state": "default",
|
||||
"states": {
|
||||
"default": {
|
||||
"animations": ["find_player"],
|
||||
"transitions": [{
|
||||
"detected": "v.x > 0"
|
||||
}]
|
||||
},
|
||||
"detected": {
|
||||
"animations": ["find_player"],
|
||||
"transitions": [{
|
||||
"default": "v.x <= 0"
|
||||
}],
|
||||
"on_entry": ["/say oink oink"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Finally, copy-paste this snippet into the behavior file for the pig-like so. Make sure to insert this in `description`.
|
||||
|
||||
<CodeHeader>BP/entities/my_entity.json#description</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/my_entity.json#description]
|
||||
"animations": {
|
||||
"manage_find_player": "controller.animation.pig_find_player",
|
||||
"find_player": "animation.pig.find_player"
|
||||
"manage_find_player": "controller.animation.pig_find_player",
|
||||
"find_player": "animation.pig.find_player"
|
||||
},
|
||||
"scripts": {
|
||||
"animate": [
|
||||
"manage_find_player"
|
||||
]
|
||||
"animate": ["manage_find_player"]
|
||||
}
|
||||
```
|
||||
:::
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Disabling Team-damage
|
||||
category: Tutorials
|
||||
title: 禁用团队伤害
|
||||
category: 教程
|
||||
tags:
|
||||
- intermediate
|
||||
- 中级
|
||||
mentions:
|
||||
- SirLich
|
||||
- solvedDev
|
||||
@@ -12,28 +12,32 @@ mentions:
|
||||
- TCLynx
|
||||
---
|
||||
|
||||
If you wish to disable team damage (so one cannot hurt their teammates), assign a tag with the team name to every teammate (I'm going to use `team1`, `team2`, `team3` and `team4` for this example).
|
||||
WARNING: This will NOT work on realms, the reason for this is that on realms there is a bug where modified player.json files in the behavior packs do not work, and the gmae just ignores them (This may be fixed in the future but as of 1.20.15 it is not fixed. (This also applies to older version of minecraft as well.))
|
||||
Now add this damage sensor component into your `player.json`s `"components": {}`. See comments for explanation.
|
||||
# 禁用团队伤害
|
||||
|
||||
<CodeHeader>BP/entities/player.json#components</CodeHeader>
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
```json
|
||||
若需禁用团队伤害(使玩家无法攻击队友),请为每位玩家分配带有队伍名称的标签(本教程将使用`team1`、`team2`、`team3`和`team4`作为示例)。
|
||||
警告:该方法在领域服(Realms)中**不可用**,原因是领域服存在一个漏洞会导致行为包中修改后的player.json文件失效,游戏会直接忽略这些修改(该问题可能在后续版本中修复,但在1.20.15版本中尚未解决。此问题也影响更早的Minecraft版本)。
|
||||
|
||||
现在将以下伤害感应器组件添加至你的`player.json`文件的`"components": {}`部分。查看注释以获取详细说明。
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/player.json#components]
|
||||
"minecraft:damage_sensor":{
|
||||
"triggers":[
|
||||
{ //if you already have a damage sensor, simply copy this object into the "triggers" array
|
||||
{ //若已有伤害感应器组件,只需将此对象复制到"triggers"数组中
|
||||
"on_damage":{
|
||||
"filters":{
|
||||
"any_of":[
|
||||
{
|
||||
"all_of":[
|
||||
{ "test":"has_tag", "value":"team1" }, //Does the player have this tag?
|
||||
{ "test":"has_tag", "subject":"other", "value":"team1" } //If so, does the entity they're trying to hurt have this tag?
|
||||
{ "test":"has_tag", "value":"team1" }, //该玩家是否拥有此标签?
|
||||
{ "test":"has_tag", "subject":"other", "value":"team1" } //被攻击实体是否拥有此标签?
|
||||
]
|
||||
},
|
||||
{
|
||||
"all_of":[
|
||||
{ "test":"has_tag", "value":"team2" }, //repeats for every team
|
||||
"all_of":[ //以下为重复结构,为每个队伍添加相同配置
|
||||
{ "test":"has_tag", "value":"team2" },
|
||||
{ "test":"has_tag", "subject":"other", "value":"team2" }
|
||||
]
|
||||
},
|
||||
@@ -58,30 +62,26 @@ Now add this damage sensor component into your `player.json`s `"components": {}`
|
||||
]
|
||||
}
|
||||
},
|
||||
"deals_damage":false //if any of these filters evaluate to true in the current attack interaction, the target will not be hurt.
|
||||
"deals_damage":false //若任意过滤器条件满足,本次攻击将不会造成伤害
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
```
|
||||
:::
|
||||
|
||||
### Projectiles
|
||||
### 抛射物处理
|
||||
|
||||
Due to the primitive filters used by projectile entities, you have to use a completely different method to achieve this.
|
||||
由于抛射物实体使用的原始滤镜系统,实现此功能需要完全不同的方法。该方案需要以下组件:
|
||||
- 标签(Tags)
|
||||
- 周期性检测(Ticking)
|
||||
- 条件伤害(Hurt on Condition)
|
||||
- 函数(Functions)
|
||||
|
||||
The process uses:
|
||||
- Tags
|
||||
- Ticking
|
||||
- Hurt on Condition
|
||||
- Functions
|
||||
|
||||
<CodeHeader>BP/entities/player.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
|
||||
//"components"
|
||||
"minecraft:timer": { //This is for applying teams to a projectile to nearby
|
||||
"time": [ //untagged projectiles, through an event.
|
||||
::: code-group
|
||||
```json [BP/entities/player.json#components]
|
||||
//"components"部分
|
||||
"minecraft:timer": { //用于通过事件给附近未标记的抛射物添加队伍标签
|
||||
"time": [
|
||||
0.0,
|
||||
0.1
|
||||
],
|
||||
@@ -91,9 +91,9 @@ The process uses:
|
||||
"target": "self"
|
||||
}
|
||||
},
|
||||
"minecraft:hurt_on_condition": { //The projectile will be unable to directly deal
|
||||
"damage_conditions": [ //damage, so instead we'll apply tags to the
|
||||
{ //player, which will trigger this . . .
|
||||
"minecraft:hurt_on_condition": { //使抛射物无法直接造成伤害
|
||||
"damage_conditions": [ //改为通过标签系统触发伤害
|
||||
{
|
||||
"filters": {
|
||||
"test": "has_tag",
|
||||
"value": "damage"
|
||||
@@ -103,9 +103,9 @@ The process uses:
|
||||
}
|
||||
]
|
||||
},
|
||||
"minecraft:damage_sensor": { //. . . which in turn, will trigger an event
|
||||
"triggers": { //to remove this tag, so the damage only
|
||||
"cause": "projectile", //happens once.
|
||||
"minecraft:damage_sensor": { //触发事件来移除damage标签
|
||||
"triggers": { //确保伤害只生效一次
|
||||
"cause": "projectile",
|
||||
"deals_damage": true,
|
||||
"on_damage": {
|
||||
"filters": {
|
||||
@@ -117,15 +117,15 @@ The process uses:
|
||||
}
|
||||
}
|
||||
|
||||
//"events"
|
||||
"wiki:projectile_team": { //The function here will apply tags depending on
|
||||
"run_command": { //which team tags the player has.
|
||||
//"events"部分
|
||||
"wiki:projectile_team": { //根据玩家队伍标签应用对应的抛射物标签
|
||||
"run_command": {
|
||||
"command": [
|
||||
"function wiki-apply_team"
|
||||
]
|
||||
}
|
||||
},
|
||||
"wiki:stop_damage": { //The event that simply removes the damage tag.
|
||||
"wiki:stop_damage": { //移除damage标签的事件
|
||||
"run_command": {
|
||||
"command": [
|
||||
"tag @s remove damage"
|
||||
@@ -133,23 +133,13 @@ The process uses:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader>BP/functions/wiki-apply_team.mcfunction</CodeHeader>
|
||||
::: code-group
|
||||
|
||||
```
|
||||
execute @s[tag=team1] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team1
|
||||
execute @s[tag=team2] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team2
|
||||
execute @s[tag=team3] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team3
|
||||
execute @s[tag=team4] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team4
|
||||
|
||||
```
|
||||
|
||||
<CodeHeader>BP/entities/arrow.json</CodeHeader>
|
||||
|
||||
```json
|
||||
|
||||
//"components"
|
||||
"on_hit": { //On_hit, trigger an event . . .
|
||||
```json [BP/entities/arrow.json]
|
||||
//"components"部分
|
||||
"on_hit": { //击中时触发事件...
|
||||
"definition_event": {
|
||||
"affect_projectile": true,
|
||||
"event_trigger": {
|
||||
@@ -160,25 +150,35 @@ execute @s[tag=team4] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team4
|
||||
"remove_on_hit": {}
|
||||
}
|
||||
|
||||
//"events"
|
||||
"wiki:hit": { //. . . which executes a function, applying
|
||||
"run_command": { //the damage tag to any players of a different team!
|
||||
//"events"部分
|
||||
"wiki:hit": { //...执行函数,为不同队伍玩家添加damage标签
|
||||
"run_command": {
|
||||
"command": [
|
||||
"function wiki-apply_damage"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader>BP/functions/wiki-apply_damage.mcfunction</CodeHeader>
|
||||
::: code-group
|
||||
|
||||
```mcfunction [BP/functions/wiki-apply_team.mcfunction]
|
||||
execute @s[tag=team1] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team1
|
||||
execute @s[tag=team2] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team2
|
||||
execute @s[tag=team3] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team3
|
||||
execute @s[tag=team4] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team4
|
||||
```
|
||||
:::
|
||||
|
||||
::: code-group
|
||||
|
||||
```mcfunction [BP/functions/wiki-apply_damage.mcfunction]
|
||||
execute @s[tag=team1] ~ ~ ~ tag @p[rm=0,r=1,tag=!team1] add damage
|
||||
execute @s[tag=team2] ~ ~ ~ tag @p[rm=0,r=1,tag=!team2] add damage
|
||||
execute @s[tag=team3] ~ ~ ~ tag @p[rm=0,r=1,tag=!team3] add damage
|
||||
execute @s[tag=team4] ~ ~ ~ tag @p[rm=0,r=1,tag=!team4] add damage
|
||||
|
||||
```
|
||||
:::
|
||||
|
||||
If you modify `arrow.json`, take into consideration the component groups.
|
||||
|
||||
> 注意:若修改`arrow.json`文件,请仔细考虑组件分组(component groups)的影响。
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Dummy Entities
|
||||
category: Tutorials
|
||||
title: 虚拟实体
|
||||
category: 教程
|
||||
tags:
|
||||
- beginner
|
||||
- 初学者
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
@@ -10,26 +10,29 @@ mentions:
|
||||
- aexer0e
|
||||
---
|
||||
|
||||
Dummy entities are invisible entities which are used behind the scenes for game-play purposes. Dummy entities are a very useful tool, and this document will cover some of the ways they are utilized, as well as showing how to set up the resource side of things.
|
||||
# 虚拟实体
|
||||
|
||||
## Using Dummies
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This is a non-exhaustive list of how dummies can be used:
|
||||
虚拟实体是游戏场景中不可见的幕后实用实体。本文将介绍这种多功能工具的使用场景,并展示如何配置资源文件。
|
||||
|
||||
- **For data storage**: by adding tags to the entity, we can use it as a "game manager", much like Armor Stands used to be used.
|
||||
- **As a named entity:** by name-tagging a dummy, and then using `execute` to select for it, you can make command-blocks `/say` with a pretty display name.
|
||||
- **As a location marker:** you can run `execute` commands located at a dummy to get relative coordinates at a location.
|
||||
- **As a waypoint:** by making entities which are aggressive to your dummy, you can pathfind entities to any location by placing a dummy there.
|
||||
## 核心用途
|
||||
|
||||
## Creating Dummies
|
||||
以下是虚拟实体的部分应用场景:
|
||||
|
||||
### Behavior Entity
|
||||
- **数据存储**:通过给实体添加标签,我们可以将其作为"游戏管理器"使用(类似过去盔甲架的用法)。
|
||||
- **命名实体**:通过命名标签标识虚拟实体,配合`execute`指令选中目标,可以用命令块实现带精美显示名称的`/say`命令。
|
||||
- **坐标标记**:通过`execute`指令跟踪虚拟实体位置,获取相对坐标系的基准点。
|
||||
- **路径向导**:使敌对生物将虚拟实体设为目标,即可将实体路径引导至虚拟实体所在位置。
|
||||
|
||||
You can use whatever behaviors you like, but here is a good template. The important aspects are: no damage, and can't be pushed.
|
||||
## 创建教程
|
||||
|
||||
<CodeHeader>BP/entities/dummy.json</CodeHeader>
|
||||
### 行为配置
|
||||
|
||||
```json
|
||||
这里提供一个标准模板(关键特性:免疫伤害且不可推动)。
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/dummy.json]
|
||||
{
|
||||
"format_version": "1.16.0",
|
||||
"minecraft:entity": {
|
||||
@@ -40,11 +43,11 @@ You can use whatever behaviors you like, but here is a good template. The import
|
||||
"is_experimental": false
|
||||
},
|
||||
"components": {
|
||||
"minecraft:breathable": { //Optional, allows the entity to breath underwater
|
||||
"minecraft:breathable": { // 可选,使实体能够在水中呼吸
|
||||
"breathes_water": true
|
||||
},
|
||||
"minecraft:physics": {
|
||||
"has_gravity": false, //Optional, allows the entity to not be affected by gravity or water
|
||||
"has_gravity": false, // 可选,使实体不受重力和水流影响
|
||||
"has_collision": false
|
||||
},
|
||||
"minecraft:custom_hit_test": {
|
||||
@@ -74,13 +77,12 @@ You can use whatever behaviors you like, but here is a good template. The import
|
||||
}
|
||||
```
|
||||
|
||||
If you want to disable collision at all (so you can place a block at it's position), you can use arrow runtime identifier, however, there can be some side effects.
|
||||
若要完全禁用碰撞(允许在其位置放置方块),可以使用弓箭runtime ID,但可能存在副作用。
|
||||
|
||||
### Resource Entity
|
||||
### 资源配置
|
||||
|
||||
<CodeHeader>RP/entity/dummy.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [RP/entity/dummy.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"minecraft:client_entity": {
|
||||
@@ -100,12 +102,12 @@ If you want to disable collision at all (so you can place a block at it's positi
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Geometry
|
||||
### 模型配置
|
||||
|
||||
<CodeHeader>RP/models/entity/dummy.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [RP/models/entity/dummy.json]
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
@@ -119,12 +121,12 @@ If you want to disable collision at all (so you can place a block at it's positi
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Render Controller (Optional)
|
||||
### 渲染控制器(可选)
|
||||
|
||||
<CodeHeader>RP/render_controllers/dummy.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [RP/render_controllers/dummy.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"render_controllers": {
|
||||
@@ -140,7 +142,8 @@ If you want to disable collision at all (so you can place a block at it's positi
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Texture (Optional)
|
||||
### 材质贴图(可选)
|
||||
|
||||
You can either leave the texture location blank, or open the model in blockbench and create a blank texture.
|
||||
可以选择留空材质路径,或者使用Blockbench创建空白材质文件。
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Entity Attacks
|
||||
category: Tutorials
|
||||
title: 实体攻击机制
|
||||
category: 教程
|
||||
mentions:
|
||||
- Luthorius
|
||||
- TheDoctor15
|
||||
@@ -9,43 +9,46 @@ mentions:
|
||||
- epxzzy
|
||||
- ThomasOrs
|
||||
tags:
|
||||
- intermediate
|
||||
- 中级
|
||||
---
|
||||
|
||||
Entity attacks are a complex subject that require many different things to work correctly:
|
||||
# 实体攻击机制
|
||||
|
||||
- Navigation and movement abilities to move towards its target
|
||||
- Targeting abilities to pick which entity to attack
|
||||
- Attack type, such as melee or ranged
|
||||
- Attack damage and effects
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
## Selecting Targets
|
||||
实体攻击需要多种系统协同工作才能正确运行:
|
||||
|
||||
### Movement
|
||||
- 导航及移动能力以接近目标
|
||||
- 目标选择能力以确定攻击对象
|
||||
- 攻击类型(如近战或远程)
|
||||
- 伤害数值及附加效果
|
||||
|
||||
Before a mob can attack, it will need various [movement components](/entities/entity-movement).
|
||||
## 目标选择
|
||||
|
||||
Before starting to create your entity attacks, you should ensure that your entity can walk around, and navigate its surroundings.
|
||||
### 移动机制
|
||||
|
||||
生物发起攻击前需要搭载多种[移动组件](/entities/entity-movement)。
|
||||
|
||||
在开始配置攻击行为前,请确保实体具备基础移动和路径规划能力。
|
||||
|
||||
:::warning
|
||||
Even if you are making an unmoving entity (like turret), you still need to add navigation component, so your entity can find the entity to shoot.
|
||||
即使要创建固定式防御单位(如炮塔),仍需要添加导航组件以便自动寻找射击目标。
|
||||
:::
|
||||
|
||||
### Triggering Hostility
|
||||
### 激活敌对行为
|
||||
|
||||
There are many ways to trigger hostility. The most common type `nearest_attackable_target`, is shown here. It generally allows you to define which entities this entity is interested in attacking:
|
||||
触发敌对状态有多种方式。以下为最常用的`nearest_attackable_target`组件示例,主要用于定义实体的主要攻击目标类型:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"minecraft:behavior.nearest_attackable_target": {
|
||||
"must_see": true, //If true, potential target must be in mob's line of sight
|
||||
"reselect_targets": true, //Allows mob to select new target, if one is closer than current
|
||||
"within_radius": 25.0, //Radius that potential target must be withing
|
||||
"must_see_forget_duration": 17.0, //If "must_see" = true, time before forgetting target
|
||||
"must_see": true, //如果为true,目标必须处于实体视线内
|
||||
"reselect_targets": true, //允许切换更近的目标
|
||||
"within_radius": 25.0, //有效搜索半径
|
||||
"must_see_forget_duration": 17.0, //目标消失视野后的记忆时间
|
||||
"entity_types": [
|
||||
{
|
||||
"filters": { //Entities to attack
|
||||
"filters": { //有效攻击目标筛选
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
@@ -55,25 +58,25 @@ There are many ways to trigger hostility. The most common type `nearest_attackab
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
For more fine control, you may also consider using one of the following components:
|
||||
如需更精细控制,可选用以下组件:
|
||||
|
||||
| Component | Note |
|
||||
| -------------------------------------------------------- | ------------------------------------------------------------ |
|
||||
| minecraft:behavior.nearest_attackable_target | Targets entity meeting the given requirements |
|
||||
| minecraft:behavior.nearest_prioritized_attackable_target | Allows for "priority": [integer] to be set after each filter |
|
||||
| minecraft:behavior.defend_trusted_target | Targets entity that hurts any entities specified in filters |
|
||||
| 组件 | 说明 |
|
||||
| ---------------------------------------------------- | ------------------------------------------------------------ |
|
||||
| minecraft:behavior.nearest_attackable_target | 定位符合筛选条件的实体 |
|
||||
| minecraft:behavior.nearest_prioritized_attackable_target | 可通过filter后设置"priority": [整数]定义优先级 |
|
||||
| minecraft:behavior.defend_trusted_target | 防御指定类型的友方单位 |
|
||||
|
||||
But there is also one more - `minecraft:lookat`
|
||||
另有特殊组件`minecraft:lookat`:
|
||||
|
||||
This last component is slightly different to the other three, as it is for detecting and targeting entities that attempt eye contact. It is structured like so:
|
||||
该组件与其他三种不同,用于检测与实体发生视线交互的目标。配置示例:
|
||||
|
||||
<CodeHeader>BP/entities/enderman.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/enderman.json]
|
||||
"minecraft:lookat": {
|
||||
"search_radius": 64.0,
|
||||
"set_target": true, //Becomes a valid target if true
|
||||
"set_target": true, //标记为有效目标
|
||||
"look_cooldown": 5.0,
|
||||
"filters": {
|
||||
"all_of": [
|
||||
@@ -87,24 +90,24 @@ This last component is slightly different to the other three, as it is for detec
|
||||
"domain": "head",
|
||||
"subject": "other",
|
||||
"operator": "not",
|
||||
"value": "carved_pumpkin" //All players not with carved_pumpkin equipped on head
|
||||
"value": "carved_pumpkin" //未装备雕刻南瓜的玩家
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Target selecting
|
||||
|
||||
:::tip
|
||||
This section shows you how to configure the "Targeting" components, explained above.
|
||||
:::
|
||||
|
||||
Mobs find targets by using [filters](https://bedrock.dev/docs/stable/Entities#Filters) can be used to determine which entities are a valid target, through `test`, `subject`, `operator`, and `value`.
|
||||
### 目标筛选机制
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
:::tip
|
||||
本节说明如何配置上述「目标定位」组件。
|
||||
:::
|
||||
|
||||
```json
|
||||
实体通过[筛选器](https://bedrock.dev/docs/stable/Entities#Filters)判定有效目标,使用`test`、`subject`、`operator`和`value`参数进行组合判断。
|
||||
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"entity_types":[
|
||||
{
|
||||
"filters":{
|
||||
@@ -121,7 +124,7 @@ Mobs find targets by using [filters](https://bedrock.dev/docs/stable/Entities#Fi
|
||||
"operator":"==",
|
||||
"value":"iron_golem"
|
||||
}
|
||||
//anything that is equal to either" snow_golem" or "iron_golem"
|
||||
//雪傀儡或铁傀儡
|
||||
]
|
||||
},
|
||||
"max_dist":24
|
||||
@@ -142,34 +145,34 @@ Mobs find targets by using [filters](https://bedrock.dev/docs/stable/Entities#Fi
|
||||
"operator":"=!",
|
||||
"value":"turtle_helmet"
|
||||
}
|
||||
//anything equal to player AND not wearing "turtle_helmet" on head
|
||||
//未装备海龟盔甲的玩家
|
||||
]
|
||||
},
|
||||
"max_dist":24
|
||||
}
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
This would only target `snow_golem`s, `iron_golem`s, and `player`s that are **not** wearing `turtle_helmet`s.
|
||||
该配置将锁定雪傀儡、铁傀儡及未佩戴海龟头盔的玩家。
|
||||
|
||||
## Types of Attack
|
||||
## 攻击类型
|
||||
|
||||
Here are the available attacks:
|
||||
可用攻击方式列表:
|
||||
|
||||
| Component | Note |
|
||||
| 组件 | 说明 |
|
||||
| ---------------------------------------------------- | -------------------------------------------------------- |
|
||||
| [minecraft:behavior.melee_attack](#melee) | Deals damage to a single target |
|
||||
| [minecraft:behavior.ranged_attack](#ranged) | Fires a projectile towards a target |
|
||||
| [minecraft:area_attack](#area) | Effectively melee attacks on anything withing range |
|
||||
| [minecraft:behavior.knockback_roar](#knockback-roar) | Similar to minecraft:area_attack, but much more flexible |
|
||||
| [minecraft:behavior.melee_attack](#近战攻击) | 单体近战攻击 |
|
||||
| [minecraft:behavior.ranged_attack](#远程攻击) | 发射弹射物 |
|
||||
| [minecraft:area_attack](#范围攻击) | 范围内全体打击 |
|
||||
| [minecraft:behavior.knockback_roar](#击退怒吼) | 高自定义度的冲击波攻击 |
|
||||
|
||||
### Melee
|
||||
### 近战攻击
|
||||
|
||||
Melee attacks are the most common type of attack, they cause knockback, and have a 100% success rate at accuracy.
|
||||
最常见的攻击类型,带有击退效果且必定命中。
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"wiki:melee_attack": {
|
||||
"minecraft:attack": {
|
||||
"damage": 3,
|
||||
@@ -178,81 +181,81 @@ Melee attacks are the most common type of attack, they cause knockback, and have
|
||||
},
|
||||
"minecraft:behavior.melee_attack": {
|
||||
"priority": 3,
|
||||
"melee_fov": 90.0, //The allowable FOV the actor will use to determine if it can make a valid melee attack
|
||||
"melee_fov": 90.0, //实体发动近战攻击时的有效视野角度
|
||||
"speed_multiplier": 1,
|
||||
"track_target": false,
|
||||
"require_complete_path": true
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Set the damage, choose a mob effect, and change some additional properties.
|
||||
可配置伤害数值、状态效果及攻击参数。
|
||||
|
||||
The value defined in components stating integers of damage can simply be a constant, or a string containing 2 numbers, for a range of possible values.
|
||||
伤害数值支持固定值或区间范围:
|
||||
|
||||
`"damage": 3` would result in 3 each time
|
||||
- `"damage": 3`:固定造成3点伤害
|
||||
- `"damage": [2, 6]`:随机造成2-6点伤害
|
||||
|
||||
`"damage": [ 2, 6 ]` would result in any integer between 2 and 6
|
||||
状态效果支持列表:
|
||||
|
||||
Both the mob effect and duration timer are optional, but when they are used, the available effects are as following:
|
||||
|
||||
| Effect Name |
|
||||
| 效果列表 |
|
||||
| --------------- |
|
||||
| speed |
|
||||
| slowness |
|
||||
| haste |
|
||||
| mining_fatigue |
|
||||
| strength |
|
||||
| instant_health |
|
||||
| instant_damage |
|
||||
| jump_boost |
|
||||
| nausea |
|
||||
| regeneration |
|
||||
| resistance |
|
||||
| fire_resistance |
|
||||
| water_breathing |
|
||||
| invisibility |
|
||||
| blindness |
|
||||
| night_vision |
|
||||
| hunger |
|
||||
| weakness |
|
||||
| poison |
|
||||
| wither |
|
||||
| health_boost |
|
||||
| absorption |
|
||||
| saturation |
|
||||
| levitation |
|
||||
| fatal_poison |
|
||||
| slow_falling |
|
||||
| conduit_power |
|
||||
| bad_omen |
|
||||
| village_hero |
|
||||
| darkness |
|
||||
| 速度 |
|
||||
| 缓慢 |
|
||||
| 急迫 |
|
||||
| 挖掘疲劳 |
|
||||
| 力量 |
|
||||
| 瞬间治疗 |
|
||||
| 瞬间伤害 |
|
||||
| 跳跃提升 |
|
||||
| 反胃 |
|
||||
| 生命恢复 |
|
||||
| 抗性提升 |
|
||||
| 防火 |
|
||||
| 水下呼吸 |
|
||||
| 隐身 |
|
||||
| 失明 |
|
||||
| 夜视 |
|
||||
| 饥饿 |
|
||||
| 虚弱 |
|
||||
| 中毒 |
|
||||
| 凋零 |
|
||||
| 生命提升 |
|
||||
| 伤害吸收 |
|
||||
| 饱和 |
|
||||
| 飘浮 |
|
||||
| 剧毒 |
|
||||
| 缓降 |
|
||||
| 潮涌能量 |
|
||||
| 不祥之兆 |
|
||||
| 村庄英雄 |
|
||||
| 黑暗 |
|
||||
|
||||
### Ranged
|
||||
### 远程攻击
|
||||
|
||||
Fires specified [projectiles](/documentation/projectiles) towards target at set intervals.
|
||||
按设定间隔发射指定[弹射物](/documentation/projectiles)。
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"wiki:ranged_attack": {
|
||||
"minecraft:behavior.ranged_attack": {
|
||||
"priority": 2,
|
||||
"ranged_fov": 90.0, //The allowable FOV the actor will use to determine if it can make a valid ranged attack
|
||||
"attack_interval_min": 1.0,
|
||||
"attack_interval_max": 3.0,
|
||||
"attack_radius": 15.0
|
||||
"ranged_fov": 90.0, //实体发动远程攻击时的有效视野角度
|
||||
"attack_interval_min": 1.0, //最小攻击间隔
|
||||
"attack_interval_max": 3.0, //最大攻击间隔
|
||||
"attack_radius": 15.0 //攻击范围
|
||||
},
|
||||
"minecraft:shooter": {
|
||||
"def": "wiki:projectile"
|
||||
"def": "wiki:projectile" //自定义弹射物定义
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
List of vanilla projectiles:
|
||||
原版弹射物类型:
|
||||
|
||||
| Vanilla Projectiles |
|
||||
| 原版弹射物 |
|
||||
| -------------------------------- |
|
||||
| minecraft:arrow |
|
||||
| minecraft:dragon_fireball |
|
||||
@@ -271,33 +274,32 @@ List of vanilla projectiles:
|
||||
| minecraft:wither_skull_dangerous |
|
||||
| minecraft:xp_bottle |
|
||||
|
||||
Only one item has an effect on an entity's ranged attacks. Crossbows. If one is equipped, it is first required for it to be "charged" before the entity can fire anything. Regardless of the projectile stated in `minecraft:shooter`, the item to charge the crossbow with should always be `minecraft:arrow`.
|
||||
弩类武器需先装填后发射:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"minecraft:behavior.charge_held_item": {
|
||||
"priority": 2,
|
||||
"items": [
|
||||
"minecraft:arrow"
|
||||
"minecraft:arrow" //弩的弹药类型固定为箭
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Once `minecraft:behavior.charge_held_item` has been achieved, the entity will be able to execute the process of `minecraft:behavior.ranged_attack`, and will then need to charge again.
|
||||
完成装填后方可触发`minecraft:behavior.ranged_attack`。
|
||||
|
||||
### Area
|
||||
### 范围攻击
|
||||
|
||||
These attacks damage all entities within a set radius. It is different to both ranged and melee in that this component doesn’t actually require a target. Regardless of the entities behaviour, _all_ entities will be affected by this. It appears to be similar to melee attacks, as it deals knockback in a similar manner, though dealing damage at a constant rate.
|
||||
对范围内的所有实体造成伤害。与常规攻击不同,无需特定目标即可触发。
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"minecraft:area_attack" : {
|
||||
"damage_range": 1, //distance in blocks
|
||||
"damage_per_tick": 2,
|
||||
"cause": "contact",
|
||||
"entity_filter": {
|
||||
"damage_range": 1, //伤害作用范围(方块)
|
||||
"damage_per_tick": 2, //每tick伤害量
|
||||
"cause": "contact", //伤害来源类型
|
||||
"entity_filter": { //有效目标筛选
|
||||
"any_of": [
|
||||
{
|
||||
"test": "is_family",
|
||||
@@ -313,58 +315,58 @@ These attacks damage all entities within a set radius. It is different to both r
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
[Entity damage sources](https://bedrock.dev/docs/stable/Addons#Entity%20Damage%20Source). It is important to take these into consideration, as certain items in vanilla can protect from some, like armour enchantments, and you can also make mobs immune to specific sources using `minecraft:damage_sensor`.
|
||||
需参考[实体伤害源类型](https://bedrock.dev/docs/stable/Addons#Entity%20Damage%20Source)进行配置,注意部分原版装备可减免特定类型伤害。
|
||||
|
||||
### Knockback Roar
|
||||
### 击退怒吼
|
||||
|
||||
Many similarities between this and `minecraft:area_attack`, this component though having much more flexibility.
|
||||
高灵活性范围攻击,可产生冲击波效果。
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"wiki:roar_attack": {
|
||||
"minecraft:behavior.knockback_roar":{
|
||||
"priority":2,
|
||||
"duration":0.7,
|
||||
"attack_time":0.2,
|
||||
"knockback_damage":1,
|
||||
"knockback_horizontal_strength":1,
|
||||
"knockback_vertical_strength":1,
|
||||
"knockback_range":5,
|
||||
"knockback_filters":{
|
||||
"duration":0.7, //技能总时长
|
||||
"attack_time":0.2, //实际造成伤害时间点
|
||||
"knockback_damage":1, //击退伤害
|
||||
"knockback_horizontal_strength":1, //水平击退力度
|
||||
"knockback_vertical_strength":1, //垂直击退力度
|
||||
"knockback_range":5, //作用范围
|
||||
"knockback_filters":{ //击退目标筛选
|
||||
"test":"is_family",
|
||||
"subject":"other",
|
||||
"operator":"==",
|
||||
"value":"player"
|
||||
},
|
||||
"damage_filters":{
|
||||
"damage_filters":{ //伤害目标筛选
|
||||
"test":"is_family",
|
||||
"subject":"other",
|
||||
"operator":"==",
|
||||
"value":"player"
|
||||
},
|
||||
"on_roar_end":{
|
||||
"on_roar_end":{ //技能结束触发事件
|
||||
"event":"wiki:other_event"
|
||||
},
|
||||
"cooldown_time":10
|
||||
"cooldown_time":10 //冷却时间
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
This is more like a shockwave of damage. Extremely versatile in uses. Produces a particle effect, which can be disabled by adding a modified version of `knockback_roar.json` to a resource pack's particles folder.
|
||||
若需要隐藏默认粒子效果,可在资源包中覆盖相关粒子文件。
|
||||
|
||||
## More on Attacks
|
||||
## 进阶攻击配置
|
||||
|
||||
Entity Attacks don't have to be as simple as Mob being hostile towards X target, doing X attack, dealing X damage.
|
||||
攻击行为可通过事件系统进行更高级的交互设计。
|
||||
|
||||
### Difficulty Dependant Attacks
|
||||
### 难度分级攻击
|
||||
|
||||
Express components and values to use for each difficulty.
|
||||
不同游戏难度配置不同攻击参数:
|
||||
|
||||
<CodeHeader>BP/entities/bee.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/bee.json]
|
||||
"easy_attack": {
|
||||
"minecraft:attack": {
|
||||
"damage": 2
|
||||
@@ -385,18 +387,23 @@ Express components and values to use for each difficulty.
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Switching Modes
|
||||
### 模式切换系统
|
||||
|
||||
You can use events to make your mob only attack under specific circumstances, or swap between the different types of attack. This can be achieved through simple usage of [events](/entities/entity-events) and component groups. Two prime examples being `minecraft:environment_sensor` and `minecraft:target_nearby_sensor`. The two are pretty similar in regards of structure, difference being that one is for sensing environments and the other for testing for target distance.
|
||||
通过[事件系统](/entities/entity-events)和组件组实现攻击模式切换。常用传感器组件:
|
||||
|
||||
#### Attacks
|
||||
| 传感器类型 | 说明 |
|
||||
| ---------------------- | ----------------------- |
|
||||
| minecraft:environment_sensor | 环境条件监测 |
|
||||
| minecraft:target_nearby_sensor | 目标距离监测 |
|
||||
|
||||
Component groups are required to define the different modes of attack, such as:
|
||||
#### 组件组示例
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
远程攻击配置组:
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"wiki:ranged_components": {
|
||||
"minecraft:shooter": {
|
||||
"def": "wiki:projectile"
|
||||
@@ -410,10 +417,12 @@ Component groups are required to define the different modes of attack, such as:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
近战攻击配置组:
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"wiki:melee_components": {
|
||||
"minecraft:attack": {
|
||||
"damage": 6
|
||||
@@ -423,85 +432,41 @@ Component groups are required to define the different modes of attack, such as:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Those are examples of your attack modes, but they are not the only ones you can use. `wiki:ranged_components` and `wiki:melee_components` are generic names for the components within them, they can have any name, but it's what's nested inside them that counts.
|
||||
#### 事件触发器
|
||||
|
||||
#### Events
|
||||
距离传感器示例:
|
||||
|
||||
These component groups won't actually do anything by themselves. Another component group is required, and some events to add/remove the attack modes.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"wiki:melee_swap": { //When triggered, adds component group for ranged and removes melee component group
|
||||
"remove": {
|
||||
"component_groups": [
|
||||
"wiki:ranged_components"
|
||||
]
|
||||
},
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"wiki:melee_components"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"wiki:ranged_swap": { //When triggered, adds component group for melee and removes ranged component group
|
||||
"remove": {
|
||||
"component_groups": [
|
||||
"wiki:melee_components"
|
||||
]
|
||||
},
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"wiki:ranged_components"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The events are effectively for just turning attack modes on and off, by adding and removing different component groups.
|
||||
|
||||
#### Sensors
|
||||
|
||||
To trigger the events, another component group is used. Sensors are components that can trigger events when certain conditions are fulfilled. Here are 2 examples of different sensors:
|
||||
|
||||
- For sensing the distance between the mob and target
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"wiki:switcher_range": {
|
||||
"minecraft:target_nearby_sensor": {
|
||||
"inside_range": 4.0,
|
||||
"outside_range": 5.0,
|
||||
"must_see": true,
|
||||
"on_inside_range": { //When target is within 4 blocks range, trigger "wiki:melee_swap" event
|
||||
"on_inside_range": { //4格内切换近战
|
||||
"event": "wiki:melee_swap",
|
||||
"target": "self"
|
||||
},
|
||||
"on_outside_range": { //When target is beyond 5 blocks range, trigger "wiki:ranged_swap" event
|
||||
"on_outside_range": { //5格外切换远程
|
||||
"event": "wiki:ranged_swap",
|
||||
"target": "self"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
- For sensing certain features of the environment of which the mob is exposed to
|
||||
环境传感器示例:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [原始CodeHeader的值]
|
||||
"wiki:switcher_environment": {
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": [
|
||||
{
|
||||
"filters": { //When underwater, trigger "wiki:melee_swap" event
|
||||
{ //水下转为近战
|
||||
"filters": {
|
||||
"test": "is_underwater",
|
||||
"subject": "self",
|
||||
"operator": "==",
|
||||
@@ -509,8 +474,8 @@ To trigger the events, another component group is used. Sensors are components t
|
||||
},
|
||||
"event": "wiki:melee_swap"
|
||||
},
|
||||
{
|
||||
"filters": { //When not underwater, trigger "wiki:ranged_swap" event
|
||||
{ //陆地转为远程
|
||||
"filters": {
|
||||
"test": "is_underwater",
|
||||
"subject": "self",
|
||||
"operator": "==",
|
||||
@@ -522,49 +487,39 @@ To trigger the events, another component group is used. Sensors are components t
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This uses `Filters`, similar to how the [target is initially selected](#target-selecting).
|
||||
|
||||
:::tip
|
||||
You aren't limited to just 2 attack types, you can have as many as you want! Just make sure to have the event's and sensors to compensate for them.
|
||||
:::
|
||||
|
||||
## Visual Animations
|
||||
:::tip
|
||||
攻击类型切换不限于两种模式,可根据需求扩展更多。
|
||||
:::
|
||||
|
||||
Attacks and animations go hand in hand. Within resource packs, the following 3 directories are required:
|
||||
## 动作表现配置
|
||||
|
||||
- animations (entityname.animation.json)
|
||||
- animation_controllers (entityname.animation_controller.json)
|
||||
- entity (entityname.json)
|
||||
攻击需配合动画系统实现完整表现。
|
||||
|
||||
Or as long as you know the names of vanilla animations and animation controllers, you can define them in the latter directory and folder.
|
||||
### 动画资源
|
||||
|
||||
### Animations
|
||||
建议使用[Blockbench](/guide/blockbench)制作动画,需在资源包中包含:
|
||||
|
||||
Animations are self explanatory. The files themselves contain all specific animations for the given entity. The recommended way to make animations is by using [blockbench](/guide/blockbench).
|
||||
- animations文件夹(实体动画定义)
|
||||
- animation_controllers文件夹(动画控制器)
|
||||
- entity文件夹(实体定义)
|
||||
|
||||
Though it is possible to create them in a simple text editor.
|
||||
|
||||
| Vanilla Attack Animations |
|
||||
| 原版攻击动画 |
|
||||
| -------------------------------------------- |
|
||||
| "animation.zombie.attack_bare_hand" |
|
||||
| "animation.skeleton.attack.v1.0" |
|
||||
| "animation.humanoid.bow_and_arrow.v1.0" |
|
||||
| "animation.humanoid.damage_nearby_mobs.v1.0" |
|
||||
|
||||
A few examples of Animations. Locate /vanilla_resource_pack/animations for all of them.
|
||||
### 动画控制器
|
||||
|
||||
### Animation Controllers
|
||||
控制动画的触发逻辑:
|
||||
|
||||
List of states that trigger animations.
|
||||
|
||||
| Vanilla Attack Animation Controllers |
|
||||
| 原版动画控制器 |
|
||||
| ---------------------------------------------- |
|
||||
| "controller.animation.zombie.attack_bare_hand" |
|
||||
| "controller.animation.skeleton.attack" |
|
||||
| "controller.animation.humanoid.bow_and_arrow" |
|
||||
| "controller.animation.humanoid.attack" |
|
||||
|
||||
A few examples of Animation Controllers. Locate /vanilla_resource_pack/animation_controllers for all of them
|
||||
|
||||
More information on animations can be found [here](https://bedrock.dev/docs/stable/Animations).
|
||||
更多动画系统细节请参考[官方文档](https://bedrock.dev/docs/stable/Animations)。
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Entity Holds Item
|
||||
category: Tutorials
|
||||
title: 实体手持物品
|
||||
category: 教程
|
||||
tags:
|
||||
- intermediate
|
||||
- 中等难度
|
||||
mentions:
|
||||
- pieterdefour
|
||||
- SirLich
|
||||
@@ -15,46 +15,49 @@ mentions:
|
||||
- 7dev7urandom
|
||||
---
|
||||
|
||||
# 实体手持物品
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
::: tip
|
||||
This tutorial assumes you have a basic understanding of entities, loot tables, and Blockbench.
|
||||
本教程假设您已对实体、战利品表和Blockbench有基本了解。
|
||||
:::
|
||||
|
||||
In this tutorial, you will learn to have an entity spawn with an item in its hand. I'll be using a custom `mandalorian_armorer` entity and a custom `hammer` item for the examples.
|
||||
在本教程中,您将学习如何让实体生成时手持物品。示例中将使用自定义实体 `mandalorian_armorer` 和自定义物品 `hammer`。
|
||||
|
||||
## Model
|
||||
## 模型
|
||||
|
||||
First of all, you'll need to have a model in Blockbench that has a map called `rightArm`. Within this map, there needs to be a submap called 'rightItem'.
|
||||
Now set the position of the pivot point of this submap, so it sits in the place you want the entity to hold the item at.
|
||||
首先需要在Blockbench中创建包含名为 `rightArm` 骨架的模型。该骨架内必须包含名为 `rightItem` 的子骨架。
|
||||
将该子骨架的枢轴点定位至您期望实体手持物品的位置。
|
||||
|
||||

|
||||
|
||||
## Behavior Pack-side
|
||||
## 行为包配置
|
||||
|
||||
Now you'll need to add a `minecraft:equipment` component in the component list for your entity and add a loot table with the desired item.
|
||||
接下来需在实体的组件列表中添加 `minecraft:equipment` 组件,并配置包含目标物品的战利品表。
|
||||
|
||||
In our example it will look like this:
|
||||
示例配置如下:
|
||||
|
||||
<CodeHeader>BP/entity/mandolorian.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entity/mandolorian.json#components]
|
||||
"minecraft:equipment": {
|
||||
"table": "loot_tables/entities/gear/mandolorian.json"
|
||||
}
|
||||
```
|
||||
|
||||
## Loot Table
|
||||
|
||||
Finally, add the loot table for your entity. It needs to be in `loot_tables/entities/<your_loot_table_name>.json` in the behavior pack. In our case, it's called `mandolorian.json`.
|
||||
|
||||
:::warning
|
||||
This isn't the same loot table as what it drops on death. So make sure it has a different name.
|
||||
:::
|
||||
|
||||
To have the entity always spawn with the same item, add the following loot table:
|
||||
## 战利品表配置
|
||||
|
||||
<CodeHeader>BP/loot_tables/entities/gear/mandolorian.json</CodeHeader>
|
||||
最后在行为包的 `loot_tables/entities/<你的战利品表名称>.json` 路径下添加对应战利品表。本示例中文件名为 `mandolorian.json`。
|
||||
|
||||
```json
|
||||
:::warning
|
||||
此战利品表与生物死亡掉落表不同,请确保使用不同命名。
|
||||
:::
|
||||
|
||||
要让实体始终持握特定物品,按照以下格式配置战利品表:
|
||||
|
||||
::: code-group
|
||||
```json [BP/loot_tables/entities/gear/mandolorian.json]
|
||||
{
|
||||
"pools": [
|
||||
{
|
||||
@@ -70,7 +73,8 @@ To have the entity always spawn with the same item, add the following loot table
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
If everything went well, you'd have something looking like this:
|
||||
成功配置后,效果应如下图所示:
|
||||
|
||||

|
||||

|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Entity Movement
|
||||
category: Tutorials
|
||||
title: 实体移动
|
||||
category: 教程
|
||||
mentions:
|
||||
- SirLich
|
||||
- sermah
|
||||
@@ -8,138 +8,126 @@ mentions:
|
||||
- TheDoctor15
|
||||
---
|
||||
|
||||
In Minecraft, entities have the ability to move through the world, either by walking, swimming or flying. To get these behaviors, your entity will generally need quite a few behaviors, broken out into various types.
|
||||
# 实体移动
|
||||
|
||||
As you read this tutorial, keep in mind that your entity will need at least:
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
- [A component that sets the entities movement speed.](#movement-speed)
|
||||
- [A component to set how the entity will move (walking, flying, etc)](#movement-type)
|
||||
- [A component to set the entities navigation abilities, so it can generate paths.](#navigation-abilities)
|
||||
- [A component that sets where/when the entity should move (AI Goals).](#ai)
|
||||
在Minecraft中,实体可以通过行走、游泳或飞行的方式在世界中移动。要为实体赋予这些行为能力,通常需要配置多种不同类型的组件。
|
||||
|
||||
阅读本教程时请注意,您的实体至少需要以下组件:
|
||||
|
||||
- [设置移动速度的基础组件](#移动速度)
|
||||
- [定义移动方式的组件(行走/飞行等)](#移动方式)
|
||||
- [设定导航能力的组件,用于生成移动路径](#导航能力)
|
||||
- [控制实体移动时机和方向的AI组件](#人工智能)
|
||||
|
||||
:::tip
|
||||
The best way to create a moving entity is by picking a similar entity from the vanilla behavior pack, and copying the components into your entity.
|
||||
创建移动实体的最佳方式是从原版行为包中找到类似实体,将其组件配置复制到您的实体中。
|
||||
|
||||
For example entities like Phantom, or Ghast, or Parrot are all flying entities, but have very different in-game behavior! Use the closest-matching entity as a template.
|
||||
例如像夜魅(Phantom)、恶魂(Ghast)或鹦鹉这类飞行实体,虽然具有完全不同的游戏行为,但它们都是通过基本相似的组件实现移动功能的。建议选择与目标实体最接近的原版生物作为模板。
|
||||
:::
|
||||
|
||||
## Movement Speed
|
||||
## 移动速度
|
||||
|
||||
The first thing your entity needs is a speed component. This sets how quickly your entity will move through the world.
|
||||
首先需要为实体配置移动速度组件,这些参数决定了实体在世界中的移动快慢。
|
||||
|
||||
| Component | Note |
|
||||
| ---------------------------------------------------------------------------------------------------------------- | -------------------------------- |
|
||||
| [minecraft:movement](/entities/vanilla-usage-components#movement) | Set movement speed (required) |
|
||||
| [minecraft:underwater_movement](/entities/vanilla-usage-components#underwater-movement) | Set movement speed in the water. |
|
||||
| [minecraft:flying_speed](/entities/vanilla-usage-components#flying-speed) | Set the speed in the air. |
|
||||
| 组件 | 说明 |
|
||||
| ---------------------------------------------------------------------------------------------------- | ----------------------------- |
|
||||
| [minecraft:movement](/entities/vanilla-usage-components#movement) | 设置基础移动速度(必需组件) |
|
||||
| [minecraft:underwater_movement](/entities/vanilla-usage-components#underwater-movement) | 设置水下移动速度 |
|
||||
| [minecraft:flying_speed](/entities/vanilla-usage-components#flying-speed) | 设置空中飞行速度 |
|
||||
|
||||
You should always include `minecraft:movement`. Add the other two as needed.
|
||||
所有实体必须包含`minecraft:movement`组件。其他两个组件按需添加。
|
||||
|
||||
All vanilla "swimming" entities like Dolphin include `underwater_movement`. Only some flying entities have `flying_speed`. It is not known why this is the case.
|
||||
原版水中生物(如海豚)都包含`underwater_movement`组件。部分飞行生物具有`flying_speed`组件(具体配置因生物而异)。
|
||||
|
||||
## Movement Type
|
||||
## 移动方式
|
||||
|
||||
Your entity will also need a movement type. Movement types set hard-coded behavior for _how_ your entity will move through the world.
|
||||
实体需要配置移动类型组件来定义其基础运动模式。注意每个实体只能选择一种移动类型,请根据实际需求选择最匹配的类型。
|
||||
|
||||
You may only include one movement type in your entity. Select the component that most closely matches your needs. Generally `basic`, `amphibious` and `fly` are good ones to use.
|
||||
| 组件 | 说明 |
|
||||
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
||||
| [minecraft:movement.amphibious](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.amphibious) | 两栖移动模式,允许同时在水中游泳和陆地行走 |
|
||||
| [minecraft:movement.basic](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.basic) | 基础移动模式 |
|
||||
| [minecraft:movement.fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.fly) | 飞行移动模式 |
|
||||
| [minecraft:movement.generic](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.generic) | 通用移动模式,支持多种移动能力 |
|
||||
| [minecraft:movement.hover](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.hover) | 悬停移动模式 |
|
||||
| [minecraft:movement.jump](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.jump) | 跳跃移动模式,可配置跳跃间隔时间 |
|
||||
| [minecraft:movement.skip](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.skip) | 蹦跳移动模式 |
|
||||
| [minecraft:movement.sway](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.sway) | 摆动移动模式,模拟水生生物游动姿态 |
|
||||
|
||||
| Component | Note |
|
||||
| --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
||||
| [minecraft:movement.amphibious](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.amphibious) | This move control allows the mob to swim in the water and walk on land. |
|
||||
| [minecraft:movement.basic](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.basic) | This component accents the movement of an entity. |
|
||||
| [minecraft:movement.fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.fly) | This move control causes the mob to fly. |
|
||||
| [minecraft:movement.generic](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.generic) | This move control allows a mob to fly, swim, climb, etc. |
|
||||
| [minecraft:movement.hover](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.hover) | This move control causes the mob to hover. |
|
||||
| [minecraft:movement.jump](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.jump) | Move control causes the mob to jump as it moves with a specified delay between jumps. |
|
||||
| [minecraft:movement.skip](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.skip) | This move control causes the mob to hop as it moves. |
|
||||
| [minecraft:movement.sway](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.sway) | This move control causes the mob to sway side to side, giving the impression it is swimming. |
|
||||
## 移动修正
|
||||
|
||||
## Movement Modifiers
|
||||
下列组件可为实体移动提供额外的物理效果调整,常规情况下不是必须组件,但需要了解其功能。
|
||||
|
||||
Movement modifiers provide additional information about how your entity will move through the world. These components are not required for normal entities, but you should be aware of them.
|
||||
| 组件 | 说明 |
|
||||
| ---------------------------------------------------------------------------------------------------- | ------------------------------------------ |
|
||||
| [minecraft:water_movement](https://bedrock.dev/docs/stable/Entities#minecraft%3Awater_movement) | 设置实体在水中的摩擦力 |
|
||||
| [minecraft:rail_movement](https://bedrock.dev/docs/stable/Entities#minecraft%3Arail_movement) | 使实体能够沿轨道移动(限轨道移动) |
|
||||
| [minecraft:friction_modifier](https://bedrock.dev/docs/stable/Entities#minecraft%3Afriction_modifier) | 设置实体陆地移动摩擦力 |
|
||||
|
||||
| Component | Note |
|
||||
| ----------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
|
||||
| [minecraft:water_movement](https://bedrock.dev/docs/stable/Entities#minecraft%3Awater_movement) | Sets the friction the entity experiences in water. |
|
||||
| [minecraft:rail_movement](https://bedrock.dev/docs/stable/Entities#minecraft%3Arail_movement) | Sets that the entity can move on rails (only). |
|
||||
| [minecraft:friction_modifier](https://bedrock.dev/docs/stable/Entities#minecraft%3Afriction_modifier) | Sets the friction the entity experiences on land. |
|
||||
## 导航能力
|
||||
|
||||
## Navigation
|
||||
|
||||
The next thing your entity needs is a navigation component. Navigation components have quite a few fields, like whether the entity can open doors or avoid sunlight. How you set these fields is generally more important than the navigation component you pick!
|
||||
|
||||
The reason there are so many navigation components is that each one gives a slightly different hard-coded behavior. Pick the navigation component whose name/description best matches the kind of navigation your entity will be doing.
|
||||
|
||||
You can only have one navigation component at any given time.
|
||||
导航组件定义了路径生成规则。每个导航组件都有独特的硬编码逻辑,需要根据实体的具体需求选择最匹配的类型。
|
||||
|
||||
:::tip
|
||||
This component is very important. You should check vanilla examples for inspiration on what fields and values to use.
|
||||
此组件对实体行为影响重大,建议参考原版生物的配置获取启发
|
||||
:::
|
||||
|
||||
| Component | Note |
|
||||
| ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
||||
| [minecraft:navigation.climb](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.climb) | Allows this entity to generate paths that include vertical walls like the vanilla Spiders do. |
|
||||
| [minecraft:navigation.float](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.float) | Allows this entity to generate paths by flying around the air like the regular Ghast. |
|
||||
| [minecraft:navigation.generic](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.generic) | Allows this entity to generate paths by walking, swimming, flying and climbing around, and jumping up and down a block. |
|
||||
| [minecraft:navigation.fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.fly) | Allows this entity to generate paths in the air as the vanilla Parrots do. |
|
||||
| [minecraft:navigation.swim](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.swim) | Allows this entity to generate paths that include water. |
|
||||
| [minecraft:navigation.walk](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.walk) | Allows this entity to generate paths by walking around and jumping up and down a block like regular mobs. |
|
||||
| 组件 | 说明 |
|
||||
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
||||
| [minecraft:navigation.climb](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.climb) | 允许生成墙面路径(类似蜘蛛的爬墙能力) |
|
||||
| [minecraft:navigation.float](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.float) | 允许空中漂浮移动(类似恶魂的移动方式) |
|
||||
| [minecraft:navigation.generic](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.generic) | 通用导航模式,支持行走、游泳、飞行和攀爬等多种路径生成 |
|
||||
| [minecraft:navigation.fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.fly) | 空中飞行导航(类似鹦鹉的飞行路径计算) |
|
||||
| [minecraft:navigation.swim](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.swim) | 水体环境导航 |
|
||||
| [minecraft:navigation.walk](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.walk) | 标准行走导航(类似普通生物的移动逻辑) |
|
||||
|
||||
## Navigation Abilities
|
||||
## 增强组件
|
||||
|
||||
On top of the movement and the navigation component, there exist many additional components to augment the abilities of your entity as they move through the world.
|
||||
以下是增强实体移动能力的可选组件:
|
||||
|
||||
| Component | Note |
|
||||
| ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [minecraft:annotation.break_door](https://bedrock.dev/docs/stable/Entities#minecraft%3Aannotation.break_door) | Allows entity to break doors. It must also be turned on in the navigation component. |
|
||||
| [minecraft:annotation.open_door](https://bedrock.dev/docs/stable/Entities#minecraft%3Aannotation.open_door) | Allows entity to open doors. It must also be turned on in the navigation component. |
|
||||
| [minecraft:buoyant](https://bedrock.dev/docs/stable/Entities#minecraft%3Abuoyant) | Specifies which liquids the entity can float in. |
|
||||
| [minecraft:can_climb](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_climb) | Allows this entity to climb up ladders. |
|
||||
| [minecraft:can_fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_fly) | Marks the entity as being able to fly. The pathfinder won't be restricted to paths where a solid block is required underneath it. |
|
||||
| [minecraft:can_power_jump](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_power_jump) | Allows the entity to power jump like the horse does in vanilla. |
|
||||
| [minecraft:floats_in_liquid](https://bedrock.dev/docs/stable/Entities#minecraft%3Afloats_in_liquid) | Sets that this entity can float in liquid blocks. |
|
||||
| [minecraft:jump.dynamic](https://bedrock.dev/docs/stable/Entities#minecraft%3Ajump.dynamic) | Defines a dynamic type jump control that will change jump properties based on the speed modifier of the mob. |
|
||||
| [minecraft:jump.static](https://bedrock.dev/docs/stable/Entities#minecraft%3Ajump.static) | Gives the entity the ability to jump. |
|
||||
| 组件 | 说明 |
|
||||
| -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
||||
| [minecraft:annotation.break_door](https://bedrock.dev/docs/stable/Entities#minecraft%3Aannotation.break_door) | 允许实体破坏门(需同时在导航组件中启用) |
|
||||
| [minecraft:annotation.open_door](https://bedrock.dev/docs/stable/Entities#minecraft%3Aannotation.open_door) | 允许实体开门(需同时在导航组件中启用) |
|
||||
| [minecraft:buoyant](https://bedrock.dev/docs/stable/Entities#minecraft%3Abuoyant) | 指定实体可以漂浮的液体类型 |
|
||||
| [minecraft:can_climb](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_climb) | 允许实体攀爬梯子 |
|
||||
| [minecraft:can_fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_fly) | 标记实体飞行能力(导航系统不会强制要求踏板支撑) |
|
||||
| [minecraft:can_power_jump](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_power_jump) | 允许进行强力跳跃(类似马匹的跳跃机制) |
|
||||
| [minecraft:floats_in_liquid](https://bedrock.dev/docs/stable/Entities#minecraft%3Afloats_in_liquid) | 使实体能够在液体中漂浮 |
|
||||
| [minecraft:jump.dynamic](https://bedrock.dev/docs/stable/Entities#minecraft%3Ajump.dynamic) | 根据移动速度自动调整跳跃属性 |
|
||||
| [minecraft:jump.static](https://bedrock.dev/docs/stable/Entities#minecraft%3Ajump.static) | 赋予实体基本的跳跃能力 |
|
||||
|
||||
There are also components like `minecraft:preferred_path`, which will modify navigation based on block-based path-cost.
|
||||
## 人工智能
|
||||
|
||||
## AI Goals
|
||||
导航组件定义了移动方式,而AI目标组件决定移动的时机和目的地。AI目标通过优先级系统(数值越低优先级越高)控制行为选择。
|
||||
|
||||
The navigation component tells the entity _how_ to generate paths, but it doesn't say _when_ or _where_ to generate paths. This is what the AI components are for.
|
||||
通常需要叠加多个不同优先级的AI组件来形成自然的行为模式。以下为部分常用AI组件示例:
|
||||
|
||||
AI Goals are prefixed with `behavior` and follow a priority system to pick which behavior to run. The lower priorities will be picked first.
|
||||
|
||||
In general, you should usually add quite a few AI components, with different priorities. Layered together, these will create realistic movement and behavior for your entity. As always, vanilla entities provide a good template for which components to add, and with what properties/priorities.
|
||||
|
||||
There are too many AI components that generate paths to list in this document. A few will be provided as examples:
|
||||
|
||||
| Component |
|
||||
| --------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 组件 |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [minecraft:behavior.random_stroll](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.random_stroll) |
|
||||
| [minecraft:behavior.follow_owner](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.follow_owner) |
|
||||
| [minecraft:behavior.move_to_water](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.move_to_water) |
|
||||
| [minecraft:behavior.stroll_towards_village](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.stroll_towards_village) |
|
||||
|
||||
For a full list, visit [bedrock.dev](https://bedrock.dev/docs/stable/Entities#AI%20Goals).
|
||||
完整列表请访问[基岩开发文档](https://bedrock.dev/docs/stable/Entities#AI%20Goals)。
|
||||
|
||||
### Pathfinding
|
||||
### 路径规划
|
||||
|
||||
Making entities go to specific places is one of the most common requests for Marketplace content.
|
||||
The best way to do pathfinding uses a second entity, which the first entity will be attracted to. I am going to call this secondary entity the **marker**. If you are confused on how to create a marker, visit the [Dummy Entities](/entities/dummy-entities) page.
|
||||
实现实体自动寻路是常用需求。推荐使用通过"诱饵实体"(Marker)进行引导的方案。若需要创建诱饵实体,请参考[虚拟实体教程](/entities/dummy-entities)。
|
||||
|
||||
#### Idea
|
||||
#### 实现思路
|
||||
|
||||
The way we are going to do pathfinding is actually fairly simple: Make our entity aggressive towards our marker, and then simply place our marker where we want our entity to path to. The hard part is knowing what components to add so we get really long-range pathing.
|
||||
基本原理是使主实体对诱饵实体产生敌对行为,通过放置诱饵实体引导主实体移动。关键点在于配置正确的组件参数以实现长距离寻路。
|
||||
|
||||
#### Components
|
||||
#### 组件配置
|
||||
|
||||
These components can be edited as needed to create good pathing. Make sure to update the `nearest_attackable_target` to point to your marker entity. This takes a `family_type`, so you should set one of those on your marker.
|
||||
以下配置中需要将`nearest_attackable_target`指向虚体诱饵(需要为诱饵实体设置family_type属性)。同时不要忘记添加常规的移动和导航组件。
|
||||
|
||||
Don't forget to add some basic movement and navigation components so your entity is able to move.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [标记目标锁定]
|
||||
"minecraft:behavior.nearest_attackable_target": {
|
||||
"priority": 0,
|
||||
"reselect_targets": true,
|
||||
@@ -172,14 +160,14 @@ Don't forget to add some basic movement and navigation components so your entity
|
||||
"max": 1000
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
#### Detecting a reached waypoint
|
||||
#### 航点到达检测
|
||||
|
||||
You can use `minecraft:target_nearby_sensor` to detect when you have reached the marker entity:
|
||||
使用目标临近传感器检测是否到达标记位置:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [临近传感器]
|
||||
"minecraft:target_nearby_sensor": {
|
||||
"inside_range": 2.0,
|
||||
"outside_range": 4.0,
|
||||
@@ -192,11 +180,12 @@ You can use `minecraft:target_nearby_sensor` to detect when you have reached the
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## Other
|
||||
## 其他技巧
|
||||
|
||||
:::tip
|
||||
You can trigger entity walking animation via command.
|
||||
可通过命令强制触发实体行走动画:
|
||||
`/execute as @e[type=...] at @s run tp @s ^^^0.1`
|
||||
This way you can control where entity goes and make it look natural.
|
||||
:::
|
||||
使用这种方式可以实现对实体移动路径的精确控制,并保持自然的动画效果。
|
||||
:::
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: Flying Entities
|
||||
category: Tutorials
|
||||
title: 飞行实体的控制方法
|
||||
category: 教程
|
||||
tags:
|
||||
- recipe
|
||||
- intermediate
|
||||
- 配方
|
||||
- 中级
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
@@ -16,39 +16,42 @@ mentions:
|
||||
- TheItsNameless
|
||||
---
|
||||
|
||||
Whether making a plane or a dragon, adding controllability to flying entities will probably challenge most devs who haven't dabbled around this concept. Since there is no "right" way of adding a piloting mechanic to flying entities, I'll showcase 3 main workaround ways you can use to achieve this.
|
||||
# 飞行实体的控制方法
|
||||
|
||||
## Great Jump, Slow Fall
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
While not exactly "flying", setting the entity's jumping power high and giving it slow falling & speed effects as it falls is probably the most straightforward method.
|
||||
无论是制作飞机还是飞龙,为飞行实体添加可控性对于未接触过此类概念的开发者来说都具有挑战性。由于没有"标准"方法来实现飞行操控,本文将展示三种主要的替代方案。
|
||||
|
||||
To achieve this, we will need to add the `"minecraft:horse.jump_strength"` component to our entity. Adding this will allow you to control its jumping power and disable dismounting when the player presses the jump button.
|
||||
## 高跳缓降法
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
虽然不算严格意义上的"飞行",但通过设置实体高跳跃能力并附加缓降和加速效果是最直接的方式。
|
||||
|
||||
```json
|
||||
需要给实体添加 `"minecraft:horse.jump_strength"` 组件,该组件可控制跳跃高度并禁用跳跃键下马功能。
|
||||
|
||||
::: code-group
|
||||
```json [组件配置]
|
||||
"minecraft:horse.jump_strength": {
|
||||
"value": 7
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
We can also use `"value"` as an object to utilize the **range bar** players will see when holding down the jump button.
|
||||
使用范围值对象可显示蓄力进度条:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [蓄力进度条配置]
|
||||
"minecraft:horse.jump_strength": {
|
||||
"value": { "range_min": 0.6, "range_max": 1.2 }
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Now we will give it slow falling and speed as it's falling so that it doesn't instantly fall. To do this, we will make an animation controller and give it those effects when it's not on the ground as so:
|
||||
通过动画控制器在空中时附加缓降和加速效果:
|
||||
|
||||
(You can read a tutorial on how to use animation controllers to execute commands [here](/animation-controllers/entity-commands).)
|
||||
(可参考[实体命令动画控制器教程](/animation-controllers/entity-commands))
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [动画控制器]
|
||||
"controller.animation.dragon.flying":{
|
||||
"states":{
|
||||
"default":{
|
||||
@@ -75,12 +78,12 @@ Now we will give it slow falling and speed as it's falling so that it doesn't in
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
We'll also need to hook it up to our entity as so:
|
||||
实体描述符需关联控制器:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [实体配置]
|
||||
"description":{
|
||||
"identifier":"wiki:dragon",
|
||||
"is_spawnable":true,
|
||||
@@ -96,20 +99,18 @@ We'll also need to hook it up to our entity as so:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Now, we should have a mechanic at least resemblant of flying. You can change the values like jump_strength and speed, but the entity will always fall using this method.
|
||||
通过调整跳跃力度和速度参数可改变飞行体验,但实体最终仍会下落。
|
||||
|
||||
## Controlling Through Looking
|
||||
## 视角控制法
|
||||
|
||||
This is probably the most popular method of piloting flying entities, and unlike the first method, this one gives players control over the vertical movement of the entity so that you don't always have to fall every time you jump, with the downside being you can't look around freely without changing the entity's vertical trajectory.
|
||||
这是最流行的飞行控制方式,通过检测玩家俯仰角来控制垂直运动。优点是可主动控制升降,缺点是视角转动会影响飞行轨迹。
|
||||
|
||||
This method detects the riding player's vertical rotation and applies levitation/slow_falling effects to the entity accordingly.
|
||||
使用命令方块检测玩家垂直视角并应用飘浮/缓降效果:
|
||||
|
||||
There are multiple ways of achieving that, but in this tutorial, we'll be using the target selectors `rym` (minimum y-rotation) and `ry` (maximum y-rotation) in a chain of repeating command-blocks to detect the player's pitch, and depending on the range, giving our entity levitation or slowly falling.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```
|
||||
::: code-group
|
||||
```mcfunction
|
||||
execute @a[rxm=-90,rx=-25] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 6 true
|
||||
execute @a[rxm=-25,rx=-15] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 3 true
|
||||
execute @a[rxm=-15,rx=-5] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 2 true
|
||||
@@ -117,17 +118,14 @@ execute @a[rxm=-5,rx=20] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 1 true
|
||||
execute @a[rxm=20,rx=35] ~~~ effect @e[type=wiki:dragon,r=1] slow_falling 1 1 true
|
||||
execute @a[rxm=35,rx=90] ~~~ effect @e[type=wiki:dragon,r=1] clear
|
||||
```
|
||||
:::
|
||||
|
||||
**Depending on how big your entity is and how far away the player's seat is from its pivot, you might need to change the radius `r` to a more significant value.**
|
||||
**注意:根据实体尺寸和坐骑点位置可能需要调整选择器半径 `r` 的数值**
|
||||
|
||||
After you run those commands in a repeating command block, you should control its vertical movement by looking up and down.
|
||||
or you may use a simple animation controller and link it to the entity, so it always plays the function.
|
||||
建议通过动画控制器关联玩家实现持续效果:
|
||||
|
||||
It's recommended that you link this animation controller to the player.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [玩家动画控制器]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
@@ -159,12 +157,12 @@ It's recommended that you link this animation controller to the player.
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
The entity will probably still be too slow when flying, so we'll borrow our animation controller from the first method with some changes to give the entity speed when it's flying.
|
||||
通过改良版动画控制器维持飞行速度:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [改良版速度控制器]
|
||||
"controller.animation.dragon.flying":{
|
||||
"states":{
|
||||
"default":{
|
||||
@@ -213,14 +211,12 @@ The entity will probably still be too slow when flying, so we'll borrow our anim
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
_Since the entity's effects might be cleared when it's being flown, we changed the animation controller to give the entity speed every tick it's not on the ground._
|
||||
添加骑乘检测标签来优化误触发问题:
|
||||
|
||||
You might also notice that the entity levitates when you go near it. We can fix this by giving the entity a tag when it's being ridden (removing it when it isn't being ridden) and only applying those effects when the entity has the tag by making and animating another animation controller and updating our commands.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [骑乘检测控制器]
|
||||
"controller.animation.dragon.test_rider":{
|
||||
"states":{
|
||||
"default":{
|
||||
@@ -246,10 +242,12 @@ You might also notice that the entity levitates when you go near it. We can fix
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
对应调整命令选择器:
|
||||
|
||||
```
|
||||
::: code-group
|
||||
```mcfunction
|
||||
execute @a[rxm=-90,rx=-25] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 6 true
|
||||
execute @a[rxm=-25,rx=-15] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 3 true
|
||||
execute @a[rxm=-15,rx=-5] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 2 true
|
||||
@@ -257,29 +255,27 @@ execute @a[rxm=-5,rx=20] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levit
|
||||
execute @a[rxm=20,rx=35] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] slow_falling 1 1 true
|
||||
execute @a[rxm=35,rx=90] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] clear
|
||||
```
|
||||
:::
|
||||
|
||||
## Controlling Through Jumping
|
||||
## 跳跃键控制法
|
||||
|
||||
A third method of controlling flying entities uses the player's jump button. The entity rises when the player is holding the jump button and falls when they release their jump button.
|
||||
通过跳跃键实现升降控制:按住跳跃上升,松开自动下降。
|
||||
|
||||
To do this, we need an animation controller attached to the player rather than the entity itself to detect when the player uses their jump button. We also need to disable dismounting when the player presses the jump button.
|
||||
首先禁用默认跳跃功能:
|
||||
|
||||
First, on the entity, disable dismounting and jumping:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [实体组件配置]
|
||||
"minecraft:horse.jump_strength": {
|
||||
"value": 0
|
||||
},
|
||||
"minecraft:can_power_jump": {}
|
||||
```
|
||||
:::
|
||||
|
||||
Next, we need an animation controller that causes the entity to levitate when the player uses their jump button and resets the levitation when they release their jump button.
|
||||
创建响应跳跃输入的动画控制器:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [跳跃键控制器]
|
||||
"controller.animation.fly_dragon":{
|
||||
"initial_state":"falling",
|
||||
"states":{
|
||||
@@ -306,12 +302,12 @@ Next, we need an animation controller that causes the entity to levitate when th
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Now, we need a copy of the player's behavior file, which we will modify slightly. You can find the player's behavior file in the vanilla behavior pack provided by Mojang (found [here](https://aka.ms/behaviorpacktemplate)). Once you have copied the player's behavior file to your own behavior pack, find their `"description"` object and add the animation controller. We also want to ensure that the entity will only respond to the player's jump input when the player is riding it, so we can use a Molang query in the player's behavior to only activate the animation controller when the player is riding.
|
||||
需修改玩家行为文件(需从[官方模板包](https://aka.ms/behaviorpacktemplate)获取)并添加控制器:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [玩家配置文件]
|
||||
"description":{
|
||||
"identifier":"minecraft:player",
|
||||
"is_spawnable":false,
|
||||
@@ -328,12 +324,12 @@ Now, we need a copy of the player's behavior file, which we will modify slightly
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
The entity can now be controlled with the jump key, but there's a bug. If the player dismounts the entity while holding the jump key, it will continue rising. We can fix this with an animation controller on the entity itself that resets the levitation whenever a player dismounts it.
|
||||
添加离鞍状态复位控制器:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [离鞍复位控制器]
|
||||
"controller.animation.reset_levitation":{
|
||||
"initial_state":"no_rider",
|
||||
"states":{
|
||||
@@ -357,3 +353,4 @@ The entity can now be controlled with the jump key, but there's a bug. If the pl
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
@@ -1,78 +1,82 @@
|
||||
---
|
||||
title: Introduction to AOE Clouds
|
||||
category: Tutorials
|
||||
title: AOE云区域效果介绍
|
||||
category: 教程
|
||||
tags:
|
||||
- intermediate
|
||||
- 中阶
|
||||
mentions:
|
||||
- Sprunkles137
|
||||
- MedicalJewel105
|
||||
---
|
||||
|
||||
**Area-of-effect clouds**, also known as AOE clouds and `minecraft:area_effect_cloud` internally, are special entities that have many unique properties. Normally these entities are created through throwing lingering potions, but with structures and some NBT editing magic we can manipulate them in very powerful ways for map-making.
|
||||
# AOE云区域效果介绍
|
||||
|
||||
## Overview
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Area-of-effect clouds have several special features we can take advantage of:
|
||||
**区域效果云**(Area-of-effect clouds),在内部也被称为AOE云或`minecraft:area_effect_cloud`,是一种具有独特属性的特殊实体。这些实体通常通过投掷滞留药水生成,但借助结构文件和NBT编辑魔法,我们可以在地图制作中以极其强大的方式操控它们。
|
||||
|
||||
- As [dummy entities](/entities/dummy-entities), they are highly performant and barely affect framerate, and they are also completely static and have no collision with the world. This makes them perfect for situations around players or where precise positioning is important.
|
||||
- It does not send the client updates. Once it spawns in, it will visually appear to be frozen in place until it despawns. However, it can still be moved around through commands just fine.
|
||||
- It can apply any potion effect in highly configurable ways. The duration can be set down to the tick, as well as whether or not the effect is ambient, or displays on the screen, if it emits particles, etc.
|
||||
- Entities with a runtime identifier of `minecraft:area_effect_cloud` inherit these same properties.
|
||||
## 概述
|
||||
|
||||
## Method 1: Projectile Component
|
||||
区域效果云具备以下可被利用的特性:
|
||||
|
||||
The projectile component supports spawning in area-of-effect clouds on hit. Minecraft uses this to spawn in AOE clouds from lingering potions.
|
||||
- 作为[虚拟实体](/entities/dummy-entities),它们在性能表现优异,几乎不影响帧率,且完全静态且不与世界发生碰撞。这使其非常适用于需要围绕玩家或精确定位的场景。
|
||||
- 不会向客户端发送更新。生成后视觉上会定格在初始位置直至消失,但仍可通过指令自由移动。
|
||||
- 能以高度可配置的方式施加任何药水效果(精准到游戏刻的持续时间设定,调节环境效果、屏幕提示显示、粒子发射等属性)。
|
||||
- 具有运行时标识符`minecraft:area_effect_cloud`的实体将继承相同属性。
|
||||
|
||||
[Projectiles Documentation](/documentation/projectiles#spawn-aoe-cloud)
|
||||
## 方法一:投射物组件
|
||||
|
||||
## Method 2: NBT Editing
|
||||
投射物组件支持在命中时生成区域效果云。Minecraft正是通过此机制实现投掷滞留药水生成AOE云。
|
||||
|
||||
Another way to spawn in these area-of-effect clouds is through structure files. This grants us finer control over the potion effects the cloud can have. So, our first order of business is getting a means to edit these structures.
|
||||
[投射物组件文档](/documentation/projectiles#spawn-aoe-cloud)
|
||||
|
||||
### NBT Editors
|
||||
## 方法二:NBT编辑
|
||||
|
||||
One of the following NBT editors are recommended:
|
||||
另一种方式是通过结构文件生成区域效果云。这使我们可以更精细控制云效果属性。首先需要准备合适的NBT编辑工具。
|
||||
|
||||
- [NBT Studio](https://github.com/tryashtar/nbt-studio) (a standalone program by tryashtar)
|
||||
- [NBT Viewer](https://marketplace.visualstudio.com/items?itemName=Misodee.vscode-nbt) (a Visual Studio Code extension by Misode)
|
||||
### NBT编辑器
|
||||
|
||||
### Structure file
|
||||
推荐使用以下任一NBT编辑器:
|
||||
|
||||
For convenience, this article contains a premade structure file you can download and use. Inside is an AOE cloud that exists for the maximum possible time.
|
||||
- [NBT Studio](https://github.com/tryashtar/nbt-studio)(由tryashtar开发的独立程序)
|
||||
- [NBT Viewer](https://marketplace.visualstudio.com/items?itemName=Misodee.vscode-nbt)(由Misode开发的VSCode扩展)
|
||||
|
||||
<BButton
|
||||
link="/assets/packs/entities/aec/aec.mcstructure" download
|
||||
color=blue
|
||||
>Download MCSTRUCTURE</BButton>
|
||||
### 结构文件
|
||||
|
||||
Refer to this article for editing structure files: [.mcstructure](/nbt/mcstructure)
|
||||
本文包含预制的结构文件可供下载使用。文件内设置了一个存在时间最大化的AOE云效果。
|
||||
|
||||
### NBT Format
|
||||
::: code-group
|
||||
```json [点击下载MCSTRUCTURE文件]
|
||||
```
|
||||
:::
|
||||
|
||||
| Tag | Type | Description |
|
||||
| --------------------- | ------- | ----------------- |
|
||||
| Duration | Integer | How long the cloud exists for before expiring, in ticks. |
|
||||
| DurationOnUse | Integer | How much the duration should change when effects are applied. |
|
||||
| InitialRadius | Float | The size of this cloud's radius when created. |
|
||||
| ParticleColor | Integer | The color of the particle effect, in decimal. |
|
||||
| ParticleId | Integer | The particle effect this cloud emits. 0 emits no particles. |
|
||||
| PotionId | Short | This cloud's potion effect ID when created. Has no effect. |
|
||||
| RadiusChangeOnPickup | Float | Unknown. |
|
||||
| RadiusOnUse | Float | How much the radius should change when effects are applied. |
|
||||
| RadiusPerTick | Float | How much the radius changes every tick. |
|
||||
| ReapplicationDelay | Integer | The interval at which effects can be applied, in ticks. |
|
||||
| mobEffects | List | Describes what potion effects should be applied. |
|
||||
结构文件编辑指南请参考:[.mcstructure文件解析](/nbt/mcstructure)
|
||||
|
||||
Below are the parameters for the `mobEffects` tag.
|
||||
### NBT数据格式
|
||||
|
||||
| Tag | Type | Description |
|
||||
| ------------------------------- | ------- | --------------- |
|
||||
| Ambient | Byte | Defines whether this effect's particles should be translucent or not. |
|
||||
| Amplifier | Byte | The strength of this potion effect. |
|
||||
| DisplayOnScreenTextureAnimation | Byte | Unknown. |
|
||||
| Duration | Integer | The amount of time this effect is applied for, in ticks. |
|
||||
| DurationEasy | Integer | Unknown, seemingly unused. |
|
||||
| DurationNormal | Integer | Unknown, seemingly unused. |
|
||||
| DurationHard | Integer | Unknown, seemingly unused. |
|
||||
| Id | Byte | The potion effect ID for this effect. |
|
||||
| ShowParticles | Byte | Defines whether this effect's particles should appear or not. |
|
||||
| 字段 | 类型 | 说明
|
||||
| --------------------- | ------- | -------------
|
||||
| Duration | 整型 | 效果云存在总时长(单位:刻)
|
||||
| DurationOnUse | 整型 | 应用效果后持续时间的增量
|
||||
| InitialRadius | 浮点型 | 初始生成时的半径
|
||||
| ParticleColor | 整型 | 粒子颜色(十进制数值)
|
||||
| ParticleId | 整型 | 发射的粒子类型ID(0表示无粒子)
|
||||
| PotionId | 短整型 | 药水效果ID(创建时使用,无实质效果)
|
||||
| RadiusChangeOnPickup | 浮点型 | (未知用途)
|
||||
| RadiusOnUse | 浮点型 | 应用效果后的半径变化量
|
||||
| RadiusPerTick | 浮点型 | 每刻半径的变化量
|
||||
| ReapplicationDelay | 整型 | 两次效果应用的最小间隔(刻)
|
||||
| mobEffects | 列表 | 实体携带的药水效果配置
|
||||
|
||||
以下是`mobEffects`标签的参数说明:
|
||||
|
||||
| 字段 | 类型 | 说明
|
||||
| ------------------------------- | ------- | -------------
|
||||
| Ambient | 字节 | 效果粒子是否为半透明形态
|
||||
| Amplifier | 字节 | 效果强度等级(0表示I级)
|
||||
| DisplayOnScreenTextureAnimation | 字节 | (未知用途)
|
||||
| Duration | 整型 | 效果持续时间(刻)
|
||||
| DurationEasy | 整型 | (未知用途,疑似未使用)
|
||||
| DurationNormal | 整型 | (未知用途,疑似未使用)
|
||||
| DurationHard | 整型 | (未知用途,疑似未使用)
|
||||
| Id | 字节 | 药水效果类型ID
|
||||
| ShowParticles | 字节 | 是否显示效果粒子
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Invulnerable Entities
|
||||
category: Tutorials
|
||||
title: 无敌实体
|
||||
category: 教程
|
||||
tags:
|
||||
- beginner
|
||||
mentions:
|
||||
@@ -10,58 +10,62 @@ mentions:
|
||||
- MedicalJewel105
|
||||
---
|
||||
|
||||
## Using Damage Sensor
|
||||
# 无敌实体
|
||||
|
||||
The best and most flexible way of disabling damage for entities is using the `minecraft:damage_sensor` component. The component allows us to use `filters` to determine which damage sources can damage our entity.
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
The best way to learn about this component is by using the vanilla examples for damage sensor or reading [documentation](https://bedrock.dev/docs/stable/Entities#minecraft:damage_sensor)
|
||||
## 使用伤害传感器组件
|
||||
|
||||
### Completely Invulnerable Entity
|
||||
禁用实体伤害的最佳且最灵活的方式是使用 `minecraft:damage_sensor` 组件。该组件允许我们通过 `filters` 过滤器来指定哪些伤害源可以作用于实体。
|
||||
|
||||
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
|
||||
了解这个组件的最好方法是查阅原版伤害传感器示例或阅读[官方文档](https://bedrock.dev/docs/stable/Entities#minecraft:damage_sensor)
|
||||
|
||||
```json
|
||||
### 完全无敌的实体
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/entity.json#minecraft:entity/components]
|
||||
"minecraft:damage_sensor": {
|
||||
"triggers": {
|
||||
"cause": "all",
|
||||
"deals_damage": false
|
||||
"cause": "all", // 捕捉全部伤害类型
|
||||
"deals_damage": false // 取消实际伤害效果
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Disable Damage from Player
|
||||
### 禁止玩家伤害
|
||||
|
||||
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/entity.json#minecraft:entity/components]
|
||||
"minecraft:damage_sensor": {
|
||||
"triggers": {
|
||||
"on_damage": {
|
||||
"filters": {
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
"on_damage": { // 当受到伤害时触发
|
||||
"filters": { // 过滤器配置
|
||||
"test": "is_family", // 检测对象类型
|
||||
"subject": "other", // 检测施加伤害的主体
|
||||
"value": "player" // 当伤害来源为玩家时生效
|
||||
}
|
||||
},
|
||||
"deals_damage": false
|
||||
"deals_damage": false // 取消实际伤害效果
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## Min Health
|
||||
## 最低生命值限制
|
||||
|
||||
The `min` property in the `minecraft:health` component allows us to make invincible entities that cannot die. This includes when using `/kill @e`. This is not considered a good solution because entities like this are hard to get rid of.
|
||||
通过 `minecraft:health` 组件中的 `min`(最小值)属性,我们可以创建无法自然死亡的无敌实体(即使使用 `/kill @e` 命令也无法清除)。需要注意的是该方案可能引发后续问题——这类实体会永久驻留世界。
|
||||
|
||||
If you choose to use this component, please make sure you have another method for killing the entity. Triggering `minecraft:instant_despawn` from something like an environment sensor, a timer, or an interact is a good solution. You also can call it using `/event`.
|
||||
如果使用此方案,**请务必配置备用清除机制**。例如通过环境传感器组件、计时器组件或互动组件触发的 `minecraft:instant_despawn` 事件实现清除,也可以通过执行 `/event` 命令手动触发。
|
||||
|
||||
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/entity.json#minecraft:entity/components]
|
||||
"minecraft:health": {
|
||||
"value": 1,
|
||||
"max": 1,
|
||||
"min": 1
|
||||
"value": 1, // 当前生命值
|
||||
"max": 1, // 最大生命值
|
||||
"min": 1 // 生命值下限(设置为与max相等将保持血量恒定)
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Note that setting it to 0 breaks some death and spawn animations/effects.
|
||||
> **技术提示**:将该值设置为0可能会导致部分死亡和重生动画/粒子效果无法正常显示。
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Look at Entity
|
||||
category: Tutorials
|
||||
title: 看向实体
|
||||
category: 教程
|
||||
tags:
|
||||
- intermediate
|
||||
- 中级
|
||||
mentions:
|
||||
- shanewolf38
|
||||
- MedicalJewel105
|
||||
@@ -10,35 +10,42 @@ mentions:
|
||||
- SmokeyStack
|
||||
---
|
||||
|
||||
The following tutorial provides a resource pack method to detect when the player is looking at an entity. The code below must be placed inside the entity that will be looked at by the player, and will provide a variable `v.look_at_entity` which returns true when the entity is being looked at.
|
||||
# 看向实体
|
||||
|
||||
## variable
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
<CodeHeader>RP/entity/mob.entity.json</CodeHeader>
|
||||
以下教程提供了一种资源包方法,用于检测玩家何时看向实体。下方代码必须放置在会被玩家注视的实体文件中,并通过变量`v.look_at_entity`返回true值来指示实体当前是否被注视。
|
||||
|
||||
```json
|
||||
## 变量
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/mob.entity.json]
|
||||
"pre_animation": [
|
||||
"v.look_at_entity = Math.abs(Math.abs(q.rotation_to_camera(1) - q.camera_rotation(1)) - 180) < (20 / q.distance_from_camera) && Math.abs(q.rotation_to_camera(0) + q.camera_rotation(0)) < (10 / q.distance_from_camera);"
|
||||
],
|
||||
```
|
||||
|
||||
:::tip
|
||||
Because the query `q.rotation_to_camera` is based at the origin of the entity (their feet), the vertical detection range will be based around the bottom of the entity. The code below creates a modified variable for the vertical angle which takes a positional offset into account to allow the vertical detection range to be based around the center of the entity.
|
||||
:::tip 补充说明
|
||||
由于查询参数`q.rotation_to_camera`基于实体的原点(脚部位置),垂直检测范围将围绕实体底部进行计算。下方代码通过创建经过位置偏移修正的垂直角度变量,使垂直检测范围能够基于实体中心进行计算。
|
||||
:::
|
||||
|
||||
<CodeHeader>RP/entity/mob.entity.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [RP/entity/mob.entity.json]
|
||||
"pre_animation": [
|
||||
"v.rotation_to_camera_0 = -Math.atan2(-q.distance_from_camera * Math.sin(q.rotation_to_camera(0)) - 1, q.distance_from_camera * Math.cos(q.rotation_to_camera(0)));",
|
||||
"v.look_at_entity = Math.abs(Math.abs(q.rotation_to_camera(1) - q.camera_rotation(1)) - 180) < (20 / q.distance_from_camera) && Math.abs(v.rotation_to_camera_0 + q.camera_rotation(0)) < (60 / q.distance_from_camera);"
|
||||
],
|
||||
```
|
||||
|
||||
## Modifying
|
||||
## 参数调整
|
||||
当前代码主要适配标准Minecraft生物规格(1×2方块)。如需适配不同尺寸的实体,需要调整以下参数:
|
||||
- 数值 `-1` 控制生物中心位置偏移量(负值向上,正值向下)
|
||||
- 数值 `20` 控制水平角度敏感度
|
||||
- 数值 `60` 控制垂直角度敏感度
|
||||
|
||||
The provided code is very accurate for the standard Minecraft mob size of 1 block wide and 2 blocks tall, but for entities of different sizes the parameters should be changed. The `- 1` controls the positional offset of the center of the mob (- is upward, + is downward), the `20` controls the horizontal angle sensitivity, and the `60` controls the vertical angle sensitivity.
|
||||
## 实现原理
|
||||
该变量的工作原理是检测两种旋转角度是否相反:
|
||||
1. 实体需要转向玩家的旋转角度
|
||||
2. 玩家需要转向实体的旋转角度
|
||||
|
||||
## Explanation
|
||||
|
||||
The variable detects when the player is looking at the entity by checking if the rotation angle required for the entity to look at the player is opposite the rotation angle required for the player to look at the entity. The horizontal and vertical angle sensitivity are modified by the distance of the entity from the camera to maintain accuracy.
|
||||
通过对比水平和垂直方向的角度差值(数值大小通过相机与实体的距离进行动态缩放),即可精确判定注视状态。
|
||||
@@ -1,48 +1,51 @@
|
||||
---
|
||||
title: Sleeping Entities
|
||||
category: Tutorials
|
||||
title: 睡眠实体
|
||||
category: 教程
|
||||
tags:
|
||||
- intermediate
|
||||
- 中级
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
- SirLich
|
||||
---
|
||||
|
||||
This tutorial will explain how to make entity sleep.
|
||||
# 睡眠实体
|
||||
|
||||
## Sleeping in beds
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
This behavior is inspired from villagers.
|
||||
本文将指导如何为实体添加睡眠功能。
|
||||
|
||||
### Features
|
||||
## 在床上睡眠
|
||||
|
||||
- Entity sleeps during the night and wakes up at day time.
|
||||
- Interaction with entity will wake it up and after a while it goes sleeping again.
|
||||
- If entity is hurt, it wakes up.
|
||||
该行为的灵感来源于村民设计。
|
||||
|
||||
### Behavior Pack
|
||||
### 特性
|
||||
|
||||
In this section behavior pack components will be discussed.
|
||||
- 实体在夜晚自动入睡,天亮时苏醒
|
||||
- 与实体互动可唤醒它,并在一段时间后重新入睡
|
||||
- 实体受到伤害时会立即清醒
|
||||
|
||||
#### Components
|
||||
### 行为包配置
|
||||
|
||||
Let's start with some basic components that you need to add to your entity.
|
||||
本节将解析行为包所需组件。
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
|
||||
#### 组件
|
||||
|
||||
```json
|
||||
首先在实体组件中添加基础元素:
|
||||
|
||||
::: code-group
|
||||
```json [行为包]
|
||||
"minecraft:dweller": {
|
||||
"dwelling_type": "village",
|
||||
"dweller_role": "inhabitant",
|
||||
"can_find_poi": true
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Undocumented, needed for entity to be able to sleep.
|
||||
此组件未经官方文档记载,但实体需要它以实现睡眠功能。
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [行为包]
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": [
|
||||
{
|
||||
@@ -55,21 +58,20 @@ Undocumented, needed for entity to be able to sleep.
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
This component is required for entity understand when to sleep.
|
||||
It runs event if it isn't day time.
|
||||
|
||||
:::warning
|
||||
You need some basic navigation components for your entity be able to move to bed.
|
||||
:::
|
||||
|
||||
#### Component Groups
|
||||
用于识别何时进入睡眠状态,会在非白天时段触发`sleep`事件。
|
||||
|
||||
Now you need some component groups for your entity with some components.
|
||||
:::warning
|
||||
注意:实体需具备基础导航组件才能移动到床上。
|
||||
:::
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#component_groups</CodeHeader>
|
||||
#### 组件组
|
||||
|
||||
```json
|
||||
接下来为实体配置复合组件组:
|
||||
|
||||
::: code-group
|
||||
```json [行为包]
|
||||
"sleeping": {
|
||||
"minecraft:behavior.sleep": {
|
||||
"priority": 0,
|
||||
@@ -118,26 +120,23 @@ Now you need some component groups for your entity with some components.
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
参数解析:
|
||||
- `minecraft:behavior.sleep`
|
||||
定义睡眠行为核心参数,优先级须设为`0`(最高级别)
|
||||
|
||||
Determines sleep details, priority needs to be at `0` (the biggest weight).
|
||||
|
||||
- `minecraft:damage_sensor``
|
||||
|
||||
Add it if you want your entity wake up if it is being attacked.
|
||||
- `minecraft:damage_sensor`
|
||||
实现受击苏醒功能
|
||||
|
||||
- `minecraft:environment_sensor`
|
||||
|
||||
Runs `wake_up` event when it is day time.
|
||||
白昼时触发`wake_up`事件
|
||||
|
||||
- `minecraft:interact`
|
||||
允许玩家无伤害唤醒实体
|
||||
|
||||
This makes player to be able wake up entity without hurting it.
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#component_groups</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [行为包]
|
||||
"sleep_timer": {
|
||||
"minecraft:timer": {
|
||||
"time": 15,
|
||||
@@ -147,17 +146,16 @@ This makes player to be able wake up entity without hurting it.
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
This component group is required for entity to fall asleep again (with some delay) after it was woken up.
|
||||
此组件组用于设置唤醒后的重新入睡延时。
|
||||
|
||||
#### Events
|
||||
#### 事件配置
|
||||
|
||||
Here you will find all events that you need.
|
||||
I don't really think it needs explanation.
|
||||
以下事件系统逻辑相对直观:
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#events</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [行为包]
|
||||
"sleep": {
|
||||
"add": {
|
||||
"component_groups": [
|
||||
@@ -197,18 +195,18 @@ I don't really think it needs explanation.
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Resource Pack
|
||||
### 资源包配置
|
||||
|
||||
Don't forget that you need to add sleeping animation and controller for it to your entity!
|
||||
请确保为实体添加睡眠动画和动画控制器!
|
||||
|
||||
#### Animation
|
||||
#### 动画配置
|
||||
|
||||
Just copy/paste it.
|
||||
直接复制以下配置:
|
||||
|
||||
<CodeHeader>RP/animations/sleeping_entity.animation.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [资源包]
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"animations": {
|
||||
@@ -228,14 +226,14 @@ Just copy/paste it.
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
#### Animation Controller
|
||||
#### 动画控制器
|
||||
|
||||
Again just copy/paste it if you need.
|
||||
推荐直接套用此模板:
|
||||
|
||||
<CodeHeader>RP/animations_controllers/ac.sleeping_entity.sleep.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [资源包]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
@@ -262,36 +260,32 @@ Again just copy/paste it if you need.
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Note that you will need to define animation in client entity like this:
|
||||
注意:需在客户端实体定义中关联动画:`"sleeping": "animation.sleeping_entity.sleep"`
|
||||
|
||||
`"sleeping": "animation.sleeping_entity.sleep"`
|
||||
|
||||
### Result
|
||||
### 效果演示
|
||||
|
||||

|
||||
|
||||
## Taking naps
|
||||
## 小憩系统
|
||||
|
||||
This behavior is inspired from foxes.
|
||||
此行为灵感来源于狐狸设计。
|
||||
|
||||
### Features
|
||||
### 特色功能
|
||||
|
||||
- Entity sleeps when feels safe, far from mobs or when the weather is not a thunderstorm.
|
||||
- Approaching the entity will make it wake up unless it's a trusted or sneaking player, or it's another entity with the family group `sleeping_entity`.
|
||||
- If entity is hurt, it wakes up.
|
||||
- 实体在安全环境(远离敌对生物且无雷暴天气)下进入小憩状态
|
||||
- 仅允许信任的潜行玩家或同族`sleeping_entity`实体靠近时不惊醒
|
||||
- 受击后自动苏醒
|
||||
|
||||
### Behavior Pack
|
||||
### 行为包配置
|
||||
|
||||
In this section behavior pack components will be discussed.
|
||||
#### 核心组件
|
||||
|
||||
#### Components
|
||||
仅需一个核心组件:
|
||||
|
||||
For this behavior you will need only one component:
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [行为包]
|
||||
"minecraft:behavior.nap": {
|
||||
"priority": 8,
|
||||
"cooldown_min": 2.0,
|
||||
@@ -350,22 +344,22 @@ For this behavior you will need only one component:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
If you want to also use the trusting mechanic, add:
|
||||
如需实现信任机制,可附加:
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [行为包]
|
||||
"minecraft:trust": {}
|
||||
```
|
||||
:::
|
||||
|
||||
### Resource Pack
|
||||
### 资源包配置
|
||||
|
||||
In our resource pack you can run an animation when entity starts to sleep.
|
||||
可通过动画控制器实现睡眠动画:
|
||||
|
||||
<CodeHeader>RP/animations_controllers/ac.sleeping_entity.sleep.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [资源包]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
@@ -392,5 +386,6 @@ In our resource pack you can run an animation when entity starts to sleep.
|
||||
}
|
||||
}
|
||||
```
|
||||
::>
|
||||
|
||||
The last thing, you will have to create and register a sleeping animation for you entity. If you don't know how to do it check out the [BlockBench page](/guide/blockbench.html#animating).
|
||||
最后需要为实体创建并注册睡眠动画,若存在制作难题可参考[BlockBench动画教程](/guide/blockbench.html#animating)。
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
title: Solid Entities
|
||||
category: Tutorials
|
||||
title: 实体碰撞体
|
||||
category: 教程
|
||||
tags:
|
||||
- recipe
|
||||
- intermediate
|
||||
- 配方指南
|
||||
- 中级
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
@@ -13,78 +13,82 @@ mentions:
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
Solid entities are entities that the player can bump into, step on, or otherwise physically interact with without passing through. Entities like this have many uses, such as emulating blocks.
|
||||
# 实体碰撞体
|
||||
|
||||
This page will discuss some of the ways that solid entities can be created.
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Not all techniques are ideal for all scenarios. Experiment, and figure out what works best for you.
|
||||
实体碰撞体是指玩家能够碰撞、踩踏或与之发生物理互动,而不会穿透的实体。这类实体有多种用途,例如模拟方块效果。
|
||||
|
||||
## Runtime Identifiers
|
||||
本页将探讨几种创建实体碰撞体的方法。
|
||||
|
||||
[Runtime identifiers](/entities/runtime-identifier) can be used to achieve solid entities, but currently only 2, each with a specific shape, and their own side effects. Neither collision shapes are possible to change or scale.
|
||||
并非所有技术都适用于所有场景。建议多加实验,找到最适合您需求的方案。
|
||||
|
||||
### Boat
|
||||
## 运行时标识符
|
||||
|
||||
<CodeHeader>BP/entities/entity_name.json</CodeHeader>
|
||||
通过[运行时标识符](/entities/runtime-identifier)可以实现实体碰撞效果。但目前仅支持两种预设形态,每种形态具有特定的碰撞箱及副作用。且两种模型的碰撞形状均不可调节或缩放。
|
||||
|
||||
```json
|
||||
### 船型实体
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/entity_name.json]
|
||||
{
|
||||
"format_version": "1.16.0",
|
||||
"minecraft:entity": {
|
||||
"description": {
|
||||
"identifier": "wiki:solid_entity",
|
||||
"runtime_identifier": "minecraft:boat"
|
||||
. . .
|
||||
// 此处省略其他配置...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
- Boat-shaped solid collision
|
||||
- Certain other boat-like effects
|
||||
- 采用船形的实体碰撞箱
|
||||
- 具备部分船只特有交互特性
|
||||
|
||||
### Shulker
|
||||
### 潜影贝型实体
|
||||
|
||||
<CodeHeader>BP/entities/entity_name.json</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/entity_name.json]
|
||||
{
|
||||
"format_version": "1.16.0",
|
||||
"minecraft:entity": {
|
||||
"description": {
|
||||
"identifier": "wiki:solid_entity",
|
||||
"runtime_identifier": "minecraft:shulker"
|
||||
. . .
|
||||
// 此处省略其他配置...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
- 1x1 block sized solid collision.
|
||||
- Sticks to block grid.
|
||||
- Teleports randomly when supporting block removed.
|
||||
- 1×1方块尺寸的实体碰撞箱
|
||||
- 固定于方块网格
|
||||
- 当支撑方块被移除时会随机瞬移
|
||||
|
||||
## minecraft:is_stackable
|
||||
## minecraft:is_stackable 组件
|
||||
|
||||
Add `minecraft:is_stackable` to your entity you want to be treated as being solid.
|
||||
**Note:** This requires editing `player.json` if you wish the entity to be solid for the player.
|
||||
通过给实体添加`minecraft:is_stackable`组件可使其具有实体碰撞属性。
|
||||
**注意:** 如果希望实体对玩家而言具有碰撞,需要修改`player.json`文件。
|
||||
|
||||
`"minecraft:is_stackable": {}`
|
||||
|
||||
You will also need to add `minecraft:push_through` and set its `value` parameter to 1.
|
||||
同时还需添加`minecraft:push_through`组件,并将其`value`参数设为1:
|
||||
|
||||
`"minecraft:push_through": 1`
|
||||
|
||||
(they should both go in `components`)
|
||||
(这两个组件都应置于`components`项下)
|
||||
|
||||
## Faking it with blocks
|
||||
## 模拟方块效果
|
||||
|
||||
In some scenarios, it's probably better to `/setblock` or `/fill` to place barrier blocks, either statically or dynamically. There needs to be both a way of placing the barriers, and removing them.
|
||||
某些情况下更适合使用`/setblock`或`/fill`命令静态或动态放置屏障方块。需配套提供屏障的放置与清除机制:
|
||||
|
||||
`/fill ~ ~ ~ ~ ~1 ~ barrier 0 replace air`
|
||||
Places barriers in a 1x1x2 area.
|
||||
在1×1×2区域生成屏障方块。
|
||||
|
||||
`/fill ~1 ~1 ~1 ~-1 ~-1 ~-1 air 0 replace barrier`
|
||||
Removes barriers within a 3x3x3 area.
|
||||
清除3×3×3范围内的屏障方块。
|
||||
|
||||
These [commands](/animation-controllers/entity-commands) will have to be triggering at a constant rate, for consistency. They can either be triggered through entity components, or animation controllers.
|
||||
为保证效果连贯性,这些[动画控制器实体指令](/animation-controllers/entity-commands)需要保持持续激活状态。可通过实体组件或动画控制器实现持续触发。
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Entity Timers
|
||||
category: Tutorials
|
||||
title: 实体计时器
|
||||
category: 教程
|
||||
tags:
|
||||
- intermediate
|
||||
- 中级
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
@@ -13,32 +13,36 @@ mentions:
|
||||
- zheaEvyline
|
||||
---
|
||||
|
||||
Time-based interactions are extremely useful tools for map making. This article hopes to provide an extensive list which details the many ways which timers can be made. For convenience, this page will be split up into two main sections: component-based timers and animation-based timers. Each has their own advantages and disadvantages, which will be outlined in their respective sections.
|
||||
You might also find useful [Scoreboard Timers](/commands/scoreboard-timers).
|
||||
# 实体计时器
|
||||
|
||||
## Component-based timers
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
Component-based timers are done inside the entity.json file of the behavior pack. They have the distinct advantage of persisting upon the entity being reloaded, but are limited by the number of timing components (duplicate components replace each other, which means defining multiple timers using the `minecraft:timer` component isn't possible).
|
||||
基于时间的交互是地图制作的超实用工具。本文旨在提供一份详尽的指南,详解多种创建计时器的方法。为方便阅读,本页将分为两大部分:组件计时器和动画计时器。每种方式都有其独特优劣,我们将在对应章节详细探讨。
|
||||
|
||||
### minecraft:timer
|
||||
你可能也会对[计分板计时器](/commands/scoreboard-timers)感兴趣。
|
||||
|
||||
This is the simplest but most effective component for triggering events after an elapsed amount of time. The component [minecraft:timer](https://bedrock.dev/docs/1.14.0.0/1.14.30.2/Entities#minecraft:timer) provides three main ways in which the amount of time before the event can be defined:
|
||||
## 基于组件的计时器
|
||||
|
||||
- Exact timing: an exact amount of time after which the event will fire is defined (e.g. 3.4 seconds)
|
||||
- Random interval: an interval is defined in which the event will fire at a random time inside that interval (e.g. between 3 to 5 seconds)
|
||||
- Weighted random choice: a number of times are defined and assigned weights, one of which will be chosen for the event to fire (e.g. a 20% chance for the event to fire at 5 seconds, and an 80% chance to fire at 20 seconds)
|
||||
组件计时器通过行为包的`entity.json`文件实现。其最大优点是实体重载时仍能保持计时状态,但受限于可用的计时组件数量(重复组件会互相覆盖,意味着无法通过`minecraft:timer`组件创建多个独立计时器)。
|
||||
|
||||
In the vanilla Behavior Pack, this component is used in all kinds of circumstances. For example:
|
||||
### minecraft:timer组件
|
||||
|
||||
- The dolphin can only spend 20 seconds on land before it dries out
|
||||
- Bees will perish between 10 and 60 seconds after stinging
|
||||
- The wandering trader will only stay for either 2400 or 3600 seconds
|
||||
这是最简单却最高效的延时触发事件组件。[minecraft:timer](https://bedrock.dev/docs/1.14.0.0/1.14.30.2/Entities#minecraft:timer)提供三种主要时间设定方式:
|
||||
|
||||
A simple example which triggers an event after 5.6 seconds:
|
||||
- **精确计时**:固定时间后触发事件(例如3.4秒)
|
||||
- **随机区间**:在指定时间区间内随机触发(例如3到5秒之间)
|
||||
- **权重随机选择**:定义多组时间选项配比权重,随机选择其中一个时间触发(例如20%概率5秒触发,80%概率20秒触发)
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
在官方行为包中,该组件被广泛应用。例如:
|
||||
|
||||
```json
|
||||
- 海豚在陆地超过20秒后会脱水
|
||||
- 蜜蜂在蜇人后10-60秒随机死亡
|
||||
- 流浪商人停留时间为2400秒或3600秒
|
||||
|
||||
基础示例(5.6秒后触发事件):
|
||||
|
||||
::: code-group
|
||||
```json [实体组件]
|
||||
"minecraft:timer": {
|
||||
"time": 5.6,
|
||||
"time_down_event": {
|
||||
@@ -46,31 +50,19 @@ A simple example which triggers an event after 5.6 seconds:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
A more complex example which triggers an event after a randomized amount of delay using weighted values:
|
||||
进阶示例(使用权重系统随机延时触发):
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [实体组件]
|
||||
"minecraft:timer": {
|
||||
"looping": false, //true will fires event after every execution, false will fire event only once.
|
||||
"looping": false, //true表示循环执行,false表示仅执行一次
|
||||
"random_time_choices": [
|
||||
{
|
||||
"weight": 25,
|
||||
"value": 0.5 //Half a second of delay
|
||||
},
|
||||
{
|
||||
"weight": 25,
|
||||
"value": 10 //Ten seconds of delay
|
||||
},
|
||||
{
|
||||
"weight": 25,
|
||||
"value": 30 //Thirty seconds of delay
|
||||
},
|
||||
{
|
||||
"weight": 25,
|
||||
"value": 120 //2 minutes of delay
|
||||
}
|
||||
{"weight":25, "value":0.5}, //0.5秒延时
|
||||
{"weight":25, "value":10}, //10秒延时
|
||||
{"weight":25, "value":30}, //30秒延时
|
||||
{"weight":25, "value":120} //2分钟延时
|
||||
],
|
||||
"time_down_event": {
|
||||
"event": "wiki:event",
|
||||
@@ -78,69 +70,59 @@ A more complex example which triggers an event after a randomized amount of dela
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
A particularly useful way to handle time events is using a single, looping `minecraft:timer` component and processing the events on each tick (or however often you decide to fire the timer). This is done by using the `randomize` parameter in events, where a weight may be used determine how often other events will be run. This can get you a lot of extra mileage out of a single timer component.
|
||||
高效利用技巧:通过循环触发`minecraft:timer`,配合事件中的`randomize`参数实现多样效果。这里通过权重控制事件触发频率:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [事件配置]
|
||||
"wiki:do_event": {
|
||||
"randomize": [
|
||||
{
|
||||
"weight": 1,
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"wiki:my_event"
|
||||
]
|
||||
}
|
||||
"weight": 1, //1/56概率触发稀有事件
|
||||
"add": {"component_groups":["wiki:my_event"]}
|
||||
},
|
||||
{
|
||||
"weight": 5,
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"wiki:my_more_frequent_event"
|
||||
]
|
||||
}
|
||||
"weight": 5, //5/56概率触发常见事件
|
||||
"add": {"component_groups":["wiki:my_more_frequent_event"]}
|
||||
},
|
||||
{
|
||||
"weight": 50 //Fires nothing
|
||||
"weight": 50 //50/56概率无事件触发
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### minecraft:environment_sensor
|
||||
### minecraft:environment_sensor组件
|
||||
|
||||
Another component ([minecraft:environment_sensor](https://bedrock.dev/docs/stable/Entities#minecraft:environment_sensor)) which can be very useful for time-based events is `minecraft:environment_sensor`. Pairing this sensor with the `hourly_clock_time` or `clock_time` filters can be used to trigger events based off in-game time.
|
||||
当结合`hourly_clock_time`或`clock_time`筛选器时,[minecraft:environment_sensor](https://bedrock.dev/docs/stable/Entities#minecraft:environment_sensor)可用于游戏内时间触发事件。
|
||||
|
||||
Here is an example which is used to fire an event 800 ticks after the start of the day (valid range is 0 to 24000):
|
||||
示例(每日开始800tick后触发事件):
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [实体组件]
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": [
|
||||
{
|
||||
"filters": {
|
||||
"test": "hourly_clock_time",
|
||||
"operator": "=",
|
||||
"value": 800
|
||||
},
|
||||
"event": "wiki:my_daily_event"
|
||||
}
|
||||
]
|
||||
"triggers": [{
|
||||
"filters": {
|
||||
"test": "hourly_clock_time",
|
||||
"operator": "=",
|
||||
"value": 800
|
||||
},
|
||||
"event": "wiki:my_daily_event"
|
||||
}]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### minecraft:ageable
|
||||
### minecraft:ageable组件
|
||||
|
||||
If this component ([minecraft:ageable](https://bedrock.dev/docs/stable/Entities#minecraft:ageable)) is not being used in the entity's behavior for a different purpose, it can be useful as an additional timer. It's important to note that it requires the `minecraft:is_baby` component to be defined in order to function.
|
||||
当行为包未占用[miinecraft:ageable](https://bedrock.dev/docs/stable/Entities#minecraft:ageable)时,可配合`minecraft:is_baby`组件实现计时功能。
|
||||
|
||||
Here is an example which fires an event after four seconds:
|
||||
示例(4秒后触发事件):
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [实体组件]
|
||||
"minecraft:is_baby": {},
|
||||
"minecraft:ageable": {
|
||||
"duration": 4,
|
||||
@@ -150,171 +132,138 @@ Here is an example which fires an event after four seconds:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Other dummy-timers:
|
||||
### 其他计时组件思路
|
||||
|
||||
Taking a peak at the docs suggest there are other components which can also can be used for timing. Essentially, you are looking for any component with a "time down event" or a "duration".
|
||||
查阅文档可发现更多具有"time_down_event"或"duration"参数的潜在组件,例如:
|
||||
|
||||
Non-exhaustive list of promising examples:
|
||||
- `minecraft:angry`(需要攻击目标,时间限定整数)
|
||||
- `minecraft.behavior.hide`
|
||||
- `minecraft:behavior.celebrate`
|
||||
|
||||
- `minecraft:angry` (requires the entity to have a target, time must be an integer)
|
||||
- `minecraft.behavior.hide`
|
||||
- `minecraft:behavior.celebrate`
|
||||
## 基于动画的计时器
|
||||
|
||||
## Animation-based timers
|
||||
行为包动画是实现定时事件的强力工具。其优势在于理论上可创造无限计时器,但存在重载实体时重置的局限(玩家退出世界或区块卸载后重新加载会重置计时器)。
|
||||
|
||||
Behavior pack animations are an extremely powerful tool for triggering time-based events. They have the distinct advantage of providing an "infinite" amount of timers, but are restarted upon an entity being reloaded (leaving and rejoining the world or the chunk containing the entity unloading will cause the timer to restart when the entity reloads).
|
||||
动画在行为包中的运作方式与资源包不同,建议通过官方文档或wiki其他页面了解基本机制。
|
||||
|
||||
Animations function differently in behavior packs than in resource packs. If you are unfamiliar with how they operate, it is recommended to learn more about them by checking out the official documentation or the other pages on this wiki.
|
||||
### 基础动画计时
|
||||
|
||||
### Simple timers
|
||||
通过动画控制器或直接执行时间线指令,可以实现精确时序触发:
|
||||
|
||||
By triggering animations from an animation controller or directly from the scripts section, you can execute specific events, commands, or molang expressions in a timed-sequence, called a timeline.
|
||||
|
||||
You can set up timelines like this:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [动画定义]
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"animations": {
|
||||
"animation.command.example_timeline": {
|
||||
"timeline": {
|
||||
"0.0": "/say this will trigger instantly",
|
||||
"3.0": "/say this will trigger after 3 seconds"
|
||||
"0.0": "/say 立即触发",
|
||||
"3.0": "/say 3秒后触发"
|
||||
},
|
||||
"animation_length": 3.1
|
||||
},
|
||||
"animation.command.example_timeline_2": {
|
||||
"timeline": {
|
||||
"100": "/say this will trigger after 100 seconds",
|
||||
"100": "/say 100秒后触发",
|
||||
"0.0": [
|
||||
"/say you can trigger multiple events at once",
|
||||
"/say by using timelines."
|
||||
"/say 同时触发多个指令",
|
||||
"/say 通过时间线组实现"
|
||||
],
|
||||
"55.55": "/say this will trigger after 55.55 seconds."
|
||||
"55.55": "/say 55.55秒后触发"
|
||||
},
|
||||
"animation_length": 100.1
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### Random interval
|
||||
### 随机间隔实现
|
||||
|
||||
A very useful feature of the timer component is its ability to define a random interval in which the event will be triggered. This functionality can be replicated using animations and a controller. Below is an example of an animation triggered by adding the `minecraft:is_sheared` component to an entity which randomly fires an event between 2 to 7 seconds after activation. Animation and controller version 1.10.0.
|
||||
通过动画控制器模拟`minecraft:timer`的随机区间功能。示例:实体被剪毛后2-7秒随机触发事件。
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [动画控制器]
|
||||
"controller.animation.shanewolf.random_interval": {
|
||||
"initial_state": "inactive",
|
||||
"states": {
|
||||
"inactive": {
|
||||
"transitions": [
|
||||
{
|
||||
"active": "q.is_sheared"
|
||||
}
|
||||
]
|
||||
"transitions": [{"active": "q.is_sheared"}]
|
||||
},
|
||||
"active": {
|
||||
"on_entry": [
|
||||
"v.random_interval = math.random(2, 7);",
|
||||
"/say random interval started"
|
||||
],
|
||||
"animations": [
|
||||
"wiki:animate_interval"
|
||||
],
|
||||
"transitions": [
|
||||
{
|
||||
"inactive": "q.anim_time >= v.random_interval"
|
||||
}
|
||||
"/say 随机计时开始"
|
||||
],
|
||||
"animations": ["wiki:animate_interval"],
|
||||
"transitions": [{
|
||||
"inactive": "q.anim_time >= v.random_interval"
|
||||
}],
|
||||
"on_exit": [
|
||||
"@s wiki:stop_random_interval",
|
||||
"/say random interval finished"
|
||||
"/say 随机计时结束"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [动画定义]
|
||||
"animation.shanewolf.random_interval": {
|
||||
"animation_length": 100
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Explanation: Upon entry into the state beginning the animation, a variable is given a random value between 2 and 7. The animation finishes when the current animation time is greater than or equal to the value of this v.
|
||||
实现逻辑:进入激活状态时生成2-7秒随机数变量,动画播放时间超过变量值时退出状态。
|
||||
|
||||
**Notes**:
|
||||
- The animation length can be set to any value greater than the maximum end of the time range (100 is used as a general template)
|
||||
- math.random(a, b) is used to trigger an event in the range [a, b]
|
||||
- math.floor(math.random(a, b.99)) may be used to end the timer at integer values (0.99 must be added to b)
|
||||
- Any events or commands to run when the animation is finished are put inside on_exit
|
||||
注意事项:
|
||||
- 动画总时长需大于最大可能值
|
||||
- 使用`math.floor(math.random(a, b.99))`可生成整数结果
|
||||
- 收尾指令写入on_exit事件
|
||||
|
||||
### Weighted random choice
|
||||
### 权重选择实现
|
||||
|
||||
Another useful feature of the timer component is its ability to trigger events at a time determined by a weighted list of values. This functionality can also be replicated using animations and a controller. Below is an example of an animation triggered by adding the `minecraft:is_charged` component to an entity which randomly fires an event at either 2, 5, or 9 seconds with weights of 30, 60, and 10, respectively. Animation and controller version 1.10.0.
|
||||
通过动画控制器模拟权重时间选择功能。示例:带电实体30%概率2秒、60%概率5秒、10%概率9秒触发事件。
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [动画控制器]
|
||||
"controller.animation.shanewolf.random_choices": {
|
||||
"initial_state": "inactive",
|
||||
"states": {
|
||||
"inactive": {
|
||||
"transitions": [
|
||||
{
|
||||
"active": "q.is_powered"
|
||||
}
|
||||
]
|
||||
"transitions": [{"active": "q.is_powered"}]
|
||||
},
|
||||
"active": {
|
||||
"on_entry": [
|
||||
"v.random_choices = math.random(0, 100);",
|
||||
"/say random interval started"
|
||||
],
|
||||
"animations": [
|
||||
"wiki:animate_choices"
|
||||
"/say 随机选择开始"
|
||||
],
|
||||
"animations": ["wiki:animate_choices"],
|
||||
"transitions": [
|
||||
{
|
||||
"inactive": "q.anim_time >= 2.0 && v.random_choices < 30"
|
||||
},
|
||||
{
|
||||
"inactive": "q.anim_time >= 5.0 && v.random_choices < 90"
|
||||
},
|
||||
{
|
||||
"inactive": "q.anim_time >= 9.0 && v.random_choices <= 100"
|
||||
}
|
||||
{"inactive": "q.anim_time >= 2.0 && v.random_choices < 30"},
|
||||
{"inactive": "q.anim_time >= 5.0 && v.random_choices < 90"},
|
||||
{"inactive": "q.anim_time >= 9.0 && v.random_choices <= 100"}
|
||||
],
|
||||
"on_exit": [
|
||||
"@s wiki:stop_random_choices",
|
||||
"/say random choices finished"
|
||||
"/say 随机选择结束"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
实现逻辑:生成0-100随机数变量,通过多个状态切换条件实现权重分段检查。
|
||||
|
||||
```json
|
||||
"animation.shanewolf.random_choices": {
|
||||
"animation_length": 100
|
||||
}
|
||||
```
|
||||
注意事项:
|
||||
- 时间段需从小到大排列
|
||||
- 通过权重累加值划分概率区间
|
||||
- 按规范处理收尾事件
|
||||
|
||||
Explanation: Upon entry into the state beginning the animation, a variable is given a random value between 0 and 100 (sum of the weights). The transitions are laid out with the list of values ordered from the smallest time to the largest time. This is done so multiple && operators are not required in the latter transitions to define the variable's range (the query for the smallest times return true first and have their weights checked before the others--flipping 2 and 5 would result in 2 mistakenly having a weight of 90 instead of 30). The animation finishes when the current animation time is greater than or equal to a time in the list and the value of the random variable falls within that time's defined weight range.
|
||||
|
||||
**Notes**:
|
||||
- The animation length can be set to any value greater than the maximum end of the time range (100 is used as a general template)
|
||||
- For this particular format to work, order the list of valid times from smallest to largest
|
||||
- To assign a weight to a time in the list, add the weight to the value the randomized variable must be less than in the list's previous entry (e.g. 5 seconds has a weight of 90 - 30 = 60)
|
||||
- Any events or commands to run when the animation is finished are put inside on_exit
|
||||
|
||||
Hopefully this spread some light on the subject of handling time in Minecraft Bedrock! As shown above, there are many possible ways it can be done, each with their own pros and cons. If you have any other useful methods for creating time-based events, please [contribute to the wiki](/contribute)!
|
||||
希望本指南能帮助你更好地掌握基岩版的时间管理技巧!如果你有其他巧妙的时间事件实现方法,欢迎[参与wiki编辑](/contribute)!
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Village Mechanic
|
||||
category: Tutorials
|
||||
title: 村庄机制
|
||||
category: 教程
|
||||
mentions:
|
||||
- AeroForta
|
||||
- MedicalJewel105
|
||||
@@ -11,15 +11,18 @@ mentions:
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
This article is for anyone who wants to try imitate the village mechanic for their entities
|
||||
# 村庄机制
|
||||
|
||||
## Navigation Behavior
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
First let's start with some basic navigation behavior.
|
||||
本文适用于想要为自定义实体实现村庄机制的开发者
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
## 导航行为
|
||||
|
||||
```json
|
||||
首先从基本导航行为开始。
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:preferred_path":{
|
||||
"max_fall_blocks":1,
|
||||
"jump_cost":5,
|
||||
@@ -48,12 +51,12 @@ First let's start with some basic navigation behavior.
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Allows entity to do random walk.
|
||||
允许实体进行随机移动。
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:behavior.random_stroll":{
|
||||
"priority":9,
|
||||
"speed_multiplier":0.55,
|
||||
@@ -61,83 +64,83 @@ Allows entity to do random walk.
|
||||
"y_dist":5
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Make entity return to inside dwelling bound, in this case inside a village border. Requiring minecraft:dweller component that will be explained below.
|
||||
使实体返回居所范围(在此案例中即村庄边界)。需要下文将解释的`minecraft:dweller`组件。
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:behavior.move_towards_dwelling_restriction": {
|
||||
"priority": 4,
|
||||
"speed_multiplier": 1.0
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Makes entity navigate around a village by creating a path to patrol. Used by Iron Golem.
|
||||
通过创建巡逻路径让实体在村庄周围移动。铁傀儡使用的机制。
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:behavior.move_through_village": {
|
||||
"priority": 3,
|
||||
"speed_multiplier": 0.6,
|
||||
"only_at_night": true
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Allows entity to enter a building and also take shelter when raining. Needs open door capabilities.
|
||||
允许实体进入建筑物并在下雨时寻找庇护所。需要开门能力。
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:behavior.move_indoors":{
|
||||
"priority":5
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Makes entity stay indoors while sun is down.
|
||||
使实体在日落时留在室内。
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:behavior.restrict_open_door":{
|
||||
"priority": 5
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Use in pair with:
|
||||
需搭配使用:
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:annotation.open_door":{
|
||||
"priority": 5
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:navigation.walk":{
|
||||
"can_pass_doors":true,
|
||||
"can_open_doors":true
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:behavior.open_door":{
|
||||
"priority":6,
|
||||
"close_door_after":true
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## Main Behavior
|
||||
## 核心行为
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [BP/entities/custom_villager.json#components]
|
||||
"minecraft:dweller": {
|
||||
"dwelling_type": "village",
|
||||
"dweller_role": "inhabitant",
|
||||
@@ -149,36 +152,34 @@ Use in pair with:
|
||||
"first_founding_reward": 5
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
- `dweller_role: inhabitant`
|
||||
Allows entity claim a bed and bell.
|
||||
`minecraft:behavior.sleep` needed.
|
||||
- `preferred_profession: farmer`
|
||||
Optional for `minecraft:behavior.work`
|
||||
- `can_find_poi`
|
||||
Add it so entity is able to find point of interest.
|
||||
Known POI types:
|
||||
- `dweller_role: inhabitant`\
|
||||
允许实体认领床和钟,需搭配`minecraft:behavior.sleep`。
|
||||
- `preferred_profession: farmer`\
|
||||
为`minecraft:behavior.work`的可选参数
|
||||
- `can_find_poi`\
|
||||
启用后实体可寻找兴趣点。已知兴趣点类型:
|
||||
|
||||
```
|
||||
bed
|
||||
jobsite
|
||||
meeting_area
|
||||
bed // 床
|
||||
jobsite // 工作站点
|
||||
meeting_area // 聚集点
|
||||
```
|
||||
|
||||
- `can_migrate`
|
||||
Defines if entity can migrate from one village to another or not.
|
||||
- `can_migrate`\
|
||||
定义实体是否能在不同村庄间迁移
|
||||
|
||||
### Sleep
|
||||
### 睡眠行为
|
||||
|
||||
You can find out how to make your entity sleep [here](/entities/sleeping-entities).
|
||||
可参考[睡眠实体指南](/entities/sleeping-entities)实现实体睡眠
|
||||
|
||||
### Work
|
||||
### 工作行为
|
||||
|
||||
Requires "dweller_role" set to be "inhabitant" also if "preferred_profession" doesn't exist the entity will try to move to the closest any job site.
|
||||
需要设置"dweller_role"为"inhabitant",若未设置"preferred_profession"则实体将移动到最近的工作站点。
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [空值]
|
||||
"minecraft:behavior.work": {
|
||||
"priority": 4,
|
||||
"active_time": 250,
|
||||
@@ -194,12 +195,12 @@ Requires "dweller_role" set to be "inhabitant" also if "preferred_profession" do
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 社交行为
|
||||
|
||||
### Gathering
|
||||
|
||||
Allows the entity to gather.
|
||||
Requires "dweller_role" set to be "inhabitant".
|
||||
允许实体进行社交活动。
|
||||
需要设置"dweller_role"为"inhabitant"。
|
||||
|
||||
```json
|
||||
"minecraft:behavior.mingle": {
|
||||
@@ -212,16 +213,14 @@ Requires "dweller_role" set to be "inhabitant".
|
||||
}
|
||||
```
|
||||
|
||||
## 日程系统
|
||||
|
||||
### Scheduler
|
||||
现在将所有机制整合到"minecraft:scheduler"中。
|
||||
首先创建简单配置。
|
||||
将工作行为放入组件组:
|
||||
|
||||
Now you know everything about needed mechanic, let's try to put all of this together in "minecraft:scheduler"
|
||||
First let's do something simple.
|
||||
Put work behavior in component group work like this:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [空值]
|
||||
"component_groups":{
|
||||
"work_schedule":{
|
||||
"minecraft:behavior.work":{
|
||||
@@ -251,12 +250,12 @@ Put work behavior in component group work like this:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Next, make your entity work.
|
||||
配置工作日程:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [空值]
|
||||
"minecraft:scheduler":{
|
||||
"min_delay_secs":0,
|
||||
"max_delay_secs":10,
|
||||
@@ -267,12 +266,12 @@ Next, make your entity work.
|
||||
{
|
||||
"test":"hourly_clock_time",
|
||||
"operator":">=",
|
||||
"value":0 //Morning
|
||||
"value":0 // 早晨
|
||||
},
|
||||
{
|
||||
"test":"hourly_clock_time",
|
||||
"operator":"<",
|
||||
"value":12000 //Evening
|
||||
"value":12000 // 傍晚
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -298,12 +297,12 @@ Next, make your entity work.
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
The events section looks something like this:
|
||||
事件部分配置示例:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
::: code-group
|
||||
```json [空值]
|
||||
"events":{
|
||||
"work":{
|
||||
"remove":{
|
||||
@@ -331,27 +330,28 @@ The events section looks something like this:
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
Open your world, spawn entity then put a bed and you should see green particle.
|
||||
进入游戏生成实体后放置床,应可见绿色粒子效果。
|
||||
|
||||
## Other Behavior
|
||||
## 其他行为
|
||||
|
||||
All of this is usable by custom entities:
|
||||
- `minecraft:behavior.move_to_village`
|
||||
Used by Pillager this may keep the entity to stay in the village.
|
||||
- `minecraft:behavior.stroll_towards_village`
|
||||
Used by fox to search a village and go there.
|
||||
- `minecraft:behavior.inspect_bookshelf`
|
||||
Used by librarian villager allows an entity to look at and inspect a bookshelf.
|
||||
- `minecraft:behavior.explore_outskirts`
|
||||
Allows entity to explore beyond the bounds of village (use schedule and component group to keep the entity return to the village).
|
||||
- `minecraft:behavior.defend_village_target`
|
||||
Use this on melee attack. Ranged attack can accidentally shoot any entity with inhabitant dwelling role.
|
||||
以下行为可供自定义实体使用:
|
||||
- `minecraft:behavior.move_to_village`\
|
||||
劫掠者使用该机制来留在村庄
|
||||
- `minecraft:behavior.stroll_towards_village`\
|
||||
狐狸使用该机制寻找并前往村庄
|
||||
- `minecraft:behavior.inspect_bookshelf`\
|
||||
管理员村民用于查看书架
|
||||
- `minecraft:behavior.explore_outskirts`\
|
||||
允许实体在村庄外探索(需搭配日程系统组件组保证返回)
|
||||
- `minecraft:behavior.defend_village_target`\
|
||||
用于近战攻击。远程攻击可能误伤具有"inhabitant" role的实体
|
||||
|
||||
All of this can be used by custom entities and have relation to villager or village:
|
||||
| Behavior | Uses | Note |
|
||||
| ------------------------------------------ | -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
||||
| `minecraft:behavior.defend_village_target` | Allows entity to attack other entity that hurt the entity who had "dweller_role": "inhabitant". | Recommended to use only on entities with melee attack. |
|
||||
| `minecraft:behavior.hide` | Used by villager to hide and stay at defined POI. | Currently, there is no documentation for the POI type that's why I recommend not to change `"poi_type": "bed"`. |
|
||||
| `minecraft:behavior.move_to_village` | Used by Illager and also witch. Allows entity to travel to a random x,y,z coordinate in a village. | - |
|
||||
| `"minecraft:behavior.nap"` | Used by Fox to take a nap. | Similar with sleep but offers more flexibility also has built-in wake up system by detecting specific entity. |
|
||||
可用行为对照表:
|
||||
| 行为名称 | 用途 | 备注 |
|
||||
| ----------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
||||
| `minecraft:behavior.defend_village_target` | 允许实体攻击伤害村民的敌人 | 建议仅用于近战攻击型实体 |
|
||||
| `minecraft:behavior.hide` | 村民用于在特定POI隐藏停留 | 当前POI类型文档不完整,建议保持`"poi_type": "bed"` |
|
||||
| `minecraft:behavior.move_to_village` | 劫掠者和女巫用于在村庄范围内随机移动 | - |
|
||||
| `minecraft:behavior.nap` | 狐狸用于小憩 | 类似睡眠但更灵活,内置感知特定实体自动唤醒系统 |
|
||||
@@ -1,11 +1,11 @@
|
||||
---
|
||||
title: Vanilla 可用 Components
|
||||
title: 所有可用 Components
|
||||
category: Documentation
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
---
|
||||
|
||||
# Vanilla 可用 Components
|
||||
# 所有可用 Components
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
---
|
||||
title: Vanilla 可用生成规则(Spawn Rules)
|
||||
title: 所有可用生成规则(Spawn Rules)
|
||||
category: Documentation
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
---
|
||||
|
||||
# Vanilla 可用生成规则(Spawn Rules)
|
||||
# 所有可用生成规则(Spawn Rules)
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
---
|
||||
title: Vanilla 可用 Components - 完整
|
||||
title: 所有可用 Components - 完整
|
||||
category: Documentation
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
hidden: true
|
||||
---
|
||||
|
||||
# Vanilla 可用 Components - 完整
|
||||
# 所有可用 Components - 完整
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
---
|
||||
title: Vanilla 可用 Spawn Rules - 完整
|
||||
title: 所有可用 Spawn Rules - 完整
|
||||
category: Documentation
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
hidden: true
|
||||
---
|
||||
|
||||
# Vanilla 可用 Spawn Rules - 完整
|
||||
# 所有可用 Spawn Rules - 完整
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user