添加了部分来自于BedrockWiki的文章!
This commit is contained in:
273
docs/wiki/3-实体/1-基础/entity-events.md
Normal file
273
docs/wiki/3-实体/1-基础/entity-events.md
Normal file
@@ -0,0 +1,273 @@
|
||||
---
|
||||
title: 实体事件
|
||||
category: 综合
|
||||
mentions:
|
||||
- ChibiMango
|
||||
- SirLich
|
||||
- Joelant05
|
||||
- MedicalJewel105
|
||||
- aexer0e
|
||||
- SmokeyStack
|
||||
- ThomasOrs
|
||||
tags:
|
||||
- 新手
|
||||
---
|
||||
|
||||
# 实体事件
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
实体事件是行为系统中与组件(Component)和组件组(Component Group)并列的基础构建模块之一。它们作为组件组的控制中枢,可以通过组件、动画(Animation)、动画控制器(Animation Controller)及其他事件进行调用。本文旨在详解实体内部及跨实体事件调用的方法,以及事件的基本格式结构。
|
||||
|
||||
## 事件结构
|
||||
|
||||
事件允许我们在特定条件满足时,通过添加或移除组件组来改变实体的行为模式。我们称之为"事件(Event)",因为它们可以被战斗倒计时结束、玩家交互、环境变化等情景所触发。当事件激活时,会根据预定义指令处理组件组的增删操作。
|
||||
|
||||
每个事件可包含七个核心指令键,分别用于执行组件组增删、条件判断、事件触发及属性设置:
|
||||
- add(添加)
|
||||
- remove(移除)
|
||||
- randomize(随机化)
|
||||
- sequence(序列)
|
||||
- filters(过滤器)
|
||||
- trigger(触发器)
|
||||
- set_property(属性设置)
|
||||
|
||||
### 添加/移除
|
||||
|
||||
事件最基础的功能是通过add/remove键直接增删组件组。如下示例中的`wiki:ranged_attacker`事件:
|
||||
|
||||
::: code-group
|
||||
```json [示例]
|
||||
"wiki:ranged_attacker":{
|
||||
"add":{
|
||||
"component_groups":[
|
||||
"attacker",
|
||||
"ranged"
|
||||
]
|
||||
},
|
||||
"remove":{
|
||||
"component_groups":[
|
||||
"standby",
|
||||
"melee"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
:::tip 组件覆盖规则
|
||||
当添加组件组时,若现有活跃组件组中已包含同名组件,后添加的组件组会覆盖原有组件。
|
||||
:::
|
||||
|
||||
### 随机化
|
||||
|
||||
randomize参数允许根据权重概率随机执行组件组操作。原版牛的生成事件即使用该机制,实现95%概率生成成年牛,5%概率生成幼崽:
|
||||
|
||||
::: code-group
|
||||
```json [牛生成逻辑]
|
||||
"minecraft:entity_spawned":{
|
||||
"randomize":[
|
||||
{
|
||||
"weight":95,
|
||||
"add":{
|
||||
"component_groups":[
|
||||
"minecraft:cow_adult"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"weight":5,
|
||||
"add":{
|
||||
"component_groups":[
|
||||
"minecraft:cow_baby"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
:::warning 注意
|
||||
随机化配置中对每组权重进行归一化处理,最终不同选项的选择概率与其权重值占总权重的比例相关。
|
||||
:::
|
||||
|
||||
### 序列/过滤器
|
||||
|
||||
通过sequence参数可实现条件分支逻辑。原版僵尸的溺水转换事件根据是否是幼体执行不同操作:
|
||||
|
||||
::: code-group
|
||||
```json [僵尸溺水转换]
|
||||
"minecraft:convert_to_drowned":{
|
||||
"sequence":[
|
||||
{
|
||||
"filters":{
|
||||
"test":"has_component",
|
||||
"operator":"!=",
|
||||
"value":"minecraft:is_baby"
|
||||
},
|
||||
"add":["minecraft:convert_to_drowned"],
|
||||
"remove":["minecraft:start_drowned_transformation"]
|
||||
},
|
||||
{
|
||||
"filters":{
|
||||
"test":"has_component",
|
||||
"value":"minecraft:is_baby"
|
||||
},
|
||||
"add":["minecraft:convert_to_baby_drowned"],
|
||||
"remove":["minecraft:start_drowned_transformation"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
:::tip 序列执行机制
|
||||
序列中的每个分支会依次检查执行,通过过滤器的分支都会被执行而无互斥性。若无过滤器则默认执行,但不影响后续分支的判断。
|
||||
:::
|
||||
|
||||
下面这个整合多条件的攻击序列示例展示了复杂逻辑的实现:
|
||||
|
||||
::: spoiler title="复杂攻击序列示例"
|
||||
|
||||
::: code-group
|
||||
```json [攻击逻辑]
|
||||
"wiki:on_hit":{
|
||||
"randomize":[
|
||||
{
|
||||
"weight":60 //60%概率无操作
|
||||
},
|
||||
{
|
||||
"weight":40,
|
||||
"sequence":[
|
||||
{"trigger":"attack_event"},
|
||||
{
|
||||
"filters":["!minecraft:is_sheared"],
|
||||
"sequence":[...]
|
||||
},
|
||||
{
|
||||
"filters":["minecraft:is_sheared"],
|
||||
"sequence":[...]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
:::
|
||||
|
||||
### 事件触发
|
||||
|
||||
通过trigger参数可以在事件中调用其他事件,结合target参数可实现跨实体交互。以玩家与猪互动事件为例:
|
||||
|
||||
::: code-group
|
||||
```json [互动事件]
|
||||
"wiki:on_interact": {
|
||||
"trigger": {
|
||||
"filters":{
|
||||
"test":"is_family",
|
||||
"subject":"self",
|
||||
"value":"pig"
|
||||
},
|
||||
"event":"wiki:interacted",
|
||||
"target":"other"
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
:::tip 目标上下文
|
||||
事件的执行需要明确的实体上下文。例如互动事件中,"other"指代互动发起者。若无对应上下文时,"target"指令将失效。
|
||||
:::
|
||||
|
||||
## 事件调用方式
|
||||
|
||||
事件可通过以下五种途径触发:
|
||||
1. 组件系统调用(如环境传感器)
|
||||
2. 动画时间轴调用
|
||||
3. 动画控制器状态切换
|
||||
4. 其他事件链式调用
|
||||
5. 控制台命令 `/event`
|
||||
|
||||
以下示例展示不同调用方式:
|
||||
|
||||
### 组件系统调用
|
||||
|
||||
僵尸的水下转换事件通过环境传感器触发:
|
||||
|
||||
::: code-group
|
||||
```json [僵尸转换]
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": {
|
||||
"filters":["is_underwater"],
|
||||
"event":"minecraft:start_transforming"
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 动画调用
|
||||
|
||||
在动画时间轴中按时间节点触发扑击事件:
|
||||
|
||||
::: code-group
|
||||
```json [动画事件]
|
||||
"animation.entity.pounce_timer": {
|
||||
"timeline": {
|
||||
"10.0": "@s wiki:start_pouncing"
|
||||
},
|
||||
"animation_length":10.1
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 跨实体事件调用
|
||||
|
||||
唤魔者的特殊技能通过发送事件到特定实体:
|
||||
|
||||
::: code-group
|
||||
```json [唤魔者技能]
|
||||
"minecraft:behavior.send_event":{
|
||||
"event_choices":[{
|
||||
"filters":["is_family:sheep"],
|
||||
"sequence":[{
|
||||
"event":"wololo",
|
||||
"target":"other"
|
||||
}]
|
||||
}]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 内置事件
|
||||
|
||||
系统级自动触发事件需特别注意:
|
||||
|
||||
| 事件名称 | 触发条件 |
|
||||
|------------------------------|--------------------------|
|
||||
| minecraft:entity_spawned | 实体生成时 |
|
||||
| minecraft:entity_born | 繁殖产生新实体时 |
|
||||
| minecraft:entity_transformed | 实体形态转换完成时 |
|
||||
| minecraft:on_prime | 爆炸物引信燃尽准备爆炸时 |
|
||||
|
||||
::: code-group
|
||||
```json [牛实体配置示例]
|
||||
"events": {
|
||||
"minecraft:entity_spawned": {
|
||||
"randomize":[
|
||||
{"weight":95, "add":["minecraft:cow_adult"]},
|
||||
{"weight":5, "add":["minecraft:cow_baby"]}
|
||||
]
|
||||
},
|
||||
"minecraft:entity_born":{
|
||||
"add":["minecraft:cow_baby"]
|
||||
},
|
||||
"minecraft:entity_transformed":{
|
||||
"add":["minecraft:cow_adult"]
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
通过合理组合这些功能模块,开发者可以创建出丰富复杂的实体行为逻辑。建议配合动画控制器文档以构建更高级的行为系统。
|
||||
178
docs/wiki/3-实体/1-基础/entity-intro-bp.md
Normal file
178
docs/wiki/3-实体/1-基础/entity-intro-bp.md
Normal file
@@ -0,0 +1,178 @@
|
||||
---
|
||||
title: 实体行为包入门指南
|
||||
category: 基础知识
|
||||
nav_order: 1
|
||||
tags:
|
||||
- 指南
|
||||
- 新手入门
|
||||
mentions:
|
||||
- SirLich
|
||||
- solvedDev
|
||||
- stirante
|
||||
- Joelant05
|
||||
- destruc7ion
|
||||
- MedicalJewel105
|
||||
- ChibiMango
|
||||
- SmokeyStack
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
# 实体行为包入门指南
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
构成行为包实体文件基础的三个主要结构如下:本文将解释它们的含义及使用方法。
|
||||
|
||||
组件组(component group)与组件(components)的混淆是常见的错误来源,请特别注意区分两者的区别。
|
||||
|
||||
## 组件(Components)
|
||||
|
||||
组件是构成Minecraft实体的逻辑构建模块。所有组件均由Mojang开发并提供给开发者使用。组件可实现多种功能,例如设置实体尺寸或赋予游泳能力等。完整组件列表可参考[官方文档](https://bedrock.dev/docs/stable/Entities)。
|
||||
|
||||
_无法_创建自定义组件。所有组件列表由微软硬编码实现并对外提供。
|
||||
|
||||
需要为实体添加行为时,可通过在`minecraft:entity`对象的`components`属性中插入组件。例如要给实体添加攀爬能力,可插入组件:`"minecraft:can_climb": {}`。
|
||||
|
||||
组件统一采用`"minecraft:<组件名称>": { <参数设置> }`格式。不同类型组件需要设置不同参数。
|
||||
|
||||
以下是实体内的组件应用范例:
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/example.json#minecraft:entity]
|
||||
"components": {
|
||||
"minecraft:type_family": {
|
||||
"family": [
|
||||
"player"
|
||||
]
|
||||
},
|
||||
"minecraft:collision_box": {
|
||||
"width": 0.6,
|
||||
"height": 1.8
|
||||
},
|
||||
"minecraft:can_climb": {},
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
(注意`components`列表_仅_包含组件)
|
||||
|
||||
## 组件组(Component Groups)
|
||||
|
||||
组件组用于整理归类多个组件。通过`事件(events)`可动态添加或移除组件组,从而实现定制化游戏玩法。
|
||||
|
||||
应用示例:
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/example.json#minecraft:entity]
|
||||
"component_groups": {
|
||||
|
||||
//组件组名称
|
||||
"minecraft:cat_persian": {
|
||||
|
||||
//合法的组件列表(可添加多项)
|
||||
"minecraft:variant": {
|
||||
"value": 6
|
||||
},
|
||||
"minecraft:physics": {}
|
||||
},
|
||||
|
||||
//第二个组件组名称
|
||||
"wiki:example_group": {
|
||||
"minecraft:type_family": {
|
||||
"family": [
|
||||
"wiki_is_awesome!"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
所有组件组均为自定义创建,不可直接引用其他实体的组件组。
|
||||
|
||||
在原版Minecraft实体中,组件组使用`minecraft:`前缀命名(如示例中的`minecraft:cat_persian`)。但需特别注意这些_并非_组件。开发者可自由使用任意命名规则,例如上文中的`wiki:example_group`。更多命名空间信息请参阅[此文档](/concepts/namespaces)。
|
||||
|
||||
放在组件组中的组件不会自动生效,必须通过事件激活才能影响实体行为。多个组件组可同时生效。
|
||||
|
||||
## 事件(Events)
|
||||
|
||||
事件是一种特殊语法,用于在满足条件时通过组件触发添加/移除组件组的操作,从而实现实体的动态行为。
|
||||
|
||||
示例结构:
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/example.json#minecraft:entity#events]
|
||||
"minecraft:ageable_grow_up": { //事件名称
|
||||
"remove": { //需要移除的组件组列表
|
||||
"component_groups": [
|
||||
"minecraft:cat_baby"
|
||||
]
|
||||
},
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"minecraft:cat_adult" //需要添加的组件组列表
|
||||
]
|
||||
}
|
||||
},
|
||||
```
|
||||
:::
|
||||
|
||||
事件与组件组相同,均为完全自定义内容。不可直接照搬其他实体的事件名称(例如`"minecraft:ageable_grow_up"`)。若需类似功能,应自主设计组件组和事件。
|
||||
|
||||
_仅能对组件组进行添加/移除操作_,无法直接操作单个组件。
|
||||
|
||||
当满足某些条件时,特定组件会触发事件。下方示例演示交互功能实现:
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/example.json#minecraft:entity]
|
||||
"components": {
|
||||
"minecraft:interact": {
|
||||
"interactions": [
|
||||
{
|
||||
"on_interact": {
|
||||
"filters": [ //触发条件筛选器
|
||||
{
|
||||
"test":"is_family",
|
||||
"subject": "other",
|
||||
"value": "player" //被交互对象属于玩家
|
||||
}
|
||||
],
|
||||
"target": "self", //作用目标为实体自身
|
||||
"event": "wiki:on_interact" //触发指定事件
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"component_groups": {
|
||||
"wiki:interacted": {
|
||||
"minecraft:scale": { //缩放组件
|
||||
"value": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"events":{
|
||||
"wiki:on_interact":{ //事件定义
|
||||
"add": {
|
||||
"component_groups": [ "wiki:interacted" ] //添加组件组
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
当玩家与该实体交互时,将触发`"wiki:on_interact"`事件,添加`"wiki:interacted"`组件组,从而激活缩放效果。
|
||||
|
||||
想深入了解事件的更多用法,请参阅[实体事件](/entities/entity-events)页面。
|
||||
|
||||
<BButton link="/entities/entity-events">实体事件详解</BButton>
|
||||
|
||||
## 原版应用案例
|
||||
|
||||
组件组与事件是原版实体实现自定义行为的核心工具。以下列举部分原版特性应用:
|
||||
|
||||
- 僵尸在水下停留过久后会通过事件转变为溺尸(drowned)
|
||||
|
||||
- 狐狸根据生成环境的不同,采用`minecraft:fox_red`与`minecraft:fox_active`组件组实现毛色变化
|
||||
|
||||
- 末影人使用事件机制实现被注视时进行攻击
|
||||
273
docs/wiki/3-实体/1-基础/entity-intro-rp.md
Normal file
273
docs/wiki/3-实体/1-基础/entity-intro-rp.md
Normal file
@@ -0,0 +1,273 @@
|
||||
---
|
||||
title: 实体资源包入门指南
|
||||
category: 基础指南
|
||||
nav_order: 2
|
||||
tags:
|
||||
- 新手教程
|
||||
- 入门指南
|
||||
mentions:
|
||||
- SirLich
|
||||
- MedicalJewel105
|
||||
- Overload1252
|
||||
- ChibiMango
|
||||
- Luthorius
|
||||
- TheItsNameless
|
||||
- SmokeyStack
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
# 实体资源包入门指南
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
资源包中的实体文件定义了构成实体视觉效果的各种资源引用,同时包含了如何渲染这些视觉元素的详细逻辑。
|
||||
|
||||
本文将分解实体文件的每个组成部分并进行详细说明。如需创建自定义实体的完整指引,请参考我们的[新手教程](/guide/custom-entity)。
|
||||
|
||||
## 文件大纲
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"minecraft:client_entity": {
|
||||
"description": {
|
||||
"identifier": "wiki:example",
|
||||
"materials": {...},
|
||||
"textures": {...},
|
||||
"geometry": {...},
|
||||
"render_controllers": [...],
|
||||
|
||||
"animations": {...},
|
||||
"scripts": {...},
|
||||
|
||||
"sound_effects": {...},
|
||||
"particle_effects": {...},
|
||||
|
||||
"spawn_egg": {...},
|
||||
"enable_attachables": false,
|
||||
"hide_armor": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
尽管看起来复杂,文件中大部分内容都采用**简称定义**模式。简称定义允许我们将资源路径(如材质纹理)或几何体ID等元素映射为简短名称以便后续引用。这种设计既方便后续资源路径变更时集中修改,也使代码保持简洁。
|
||||
|
||||
## 材质系统
|
||||
材质(Materials)决定了纹理的渲染方式。例如骷髅使用透明材质,而末影人的眼睛材质具有自发光特性。大部分情况下可以直接使用预设材质而无需自定义。
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/spider.entity.json#minecraft:client_entity/description]
|
||||
"materials": {
|
||||
"default": "spider",
|
||||
"invisible": "spider_invisible"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
这里的`default`和`invisible`是简称,分别指向`spider`和`spider_invisible`材质。需要注意的是单纯的简称定义并不会告知实体何时使用不同材质。
|
||||
|
||||
[预置材质列表](/documentation/materials)可供参考。[自定义材质教程](/visuals/materials)适合进阶开发者。
|
||||
|
||||
## 纹理配置
|
||||
纹理(Textures)是映射到模型表面的图像文件。此部分同样使用简称定义系统:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/bee.entity.json#minecraft:client_entity/description]
|
||||
"textures": {
|
||||
"default": "textures/entity/bee/bee",
|
||||
"angry": "textures/entity/bee/bee_angry",
|
||||
"nectar": "textures/entity/bee/bee_nectar",
|
||||
"angry_nectar": "textures/entity/bee/bee_angry_nectar"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
支持定义多状态纹理(如蜜蜂的不同状态),也可叠加纹理层(参考村民的生物群系基底+职业层组合)。详细应用技巧参见[渲染控制器章节](/entities/render-controllers)。
|
||||
|
||||
## 几何体格式
|
||||
几何体(Geometry)由Blockbench等建模工具生成的骨骼模型文件构成:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/creeper.entity.json#minecraft:client_entity/description]
|
||||
"geometry": {
|
||||
"default": "geometry.creeper",
|
||||
"charged": "geometry.creeper.charged"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
这里的简称指向几何体文件的唯一标识符(JSON文件中的`identifier`字段)。以苦力怕为例,充电与普通状态使用不同模型:
|
||||
|
||||
::: tip
|
||||
模型显示异常时,首要检查简称定义是否存在拼写错误。
|
||||
:::
|
||||
|
||||
## 渲染控制器
|
||||
渲染控制器(Render Controllers)是控制实体渲染方式的核心组件,负责协调材质、纹理和模型的搭配使用:
|
||||
|
||||
::: code-group
|
||||
```json [RP/render_controllers/example.rc.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"render_controllers": {
|
||||
"controller.render.example": {
|
||||
"geometry": "geometry.default",
|
||||
"materials": [{ "*": "material.default" }],
|
||||
"textures": ["texture.default"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
该示例始终使用"default"标识的各类资源。进阶用法可支持动态切换纹理与隐藏模型部件,详情参阅[渲染控制器指南](/entities/render-controllers)。
|
||||
|
||||
在实体文件中通过标识符指定渲染控制器:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"render_controllers": ["controller.render.example"]
|
||||
```
|
||||
:::
|
||||
|
||||
最低限度的实体文件须包含材质、纹理、几何体、渲染控制器四个基础模块。
|
||||
|
||||
## 动画系统
|
||||
动画(Animations)定义模型骨骼的运动逻辑,涵盖行走、攻击、视线追踪等交互行为:
|
||||
|
||||
::: code-group
|
||||
```json [RP/animations/example.a.json]
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"animations": {
|
||||
"animation.example.walk": {...},
|
||||
"animation.example.attack": {...}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
实体文件中需配置动画简称以便调用:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"animations": {
|
||||
"walk": "animation.example.walk",
|
||||
"attack": "animation.example.attack",
|
||||
"attack_controller": "controller.animation.example"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
::: warning 重要提示
|
||||
单单定义动画简称并不能启动动画,需通过脚本系统主动调用。
|
||||
:::
|
||||
|
||||
## 脚本逻辑
|
||||
脚本(Scripts)通过Molang表达式协调动画播放、变量设置、模型缩放等动态行为:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"scripts": {
|
||||
"initialize": [...],
|
||||
"pre_animation": [...],
|
||||
"animate": [...],
|
||||
"scale": "1"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 初始化脚本
|
||||
实体生成或加载时执行,适合设置初始变量。
|
||||
|
||||
### 预动画脚本
|
||||
每帧渲染前运行,用于计算动画参数。
|
||||
|
||||
### 动画脚本
|
||||
每帧执行动画控制器和播放逻辑:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"animate": [
|
||||
"attack_controller",
|
||||
{ "walk": "q.modified_move_speed" }
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
`q.modified_move_speed`将行走速度映射为动画播放速率。数值`2`表示双倍播放,动态公式使动画与实体速度保持同步。
|
||||
|
||||
### 模型缩放
|
||||
`scale`参数支持通过Molang表达式调整模型尺寸:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"scripts": {
|
||||
"scale": "q.variant",
|
||||
"scaleX": 2,
|
||||
"scaleY": 0.5
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
该示例:
|
||||
- Y轴方向缩放0.5倍
|
||||
- X轴放大2倍
|
||||
- 整体尺寸由变体值决定(`minecraft:variant`组件)
|
||||
|
||||
::: tip 随机尺寸案例
|
||||
`math.random_integer(1,5)`可在初始化时生成1-5的随机缩放系数。
|
||||
:::
|
||||
|
||||
## 音效配置
|
||||
音效简称便于在动画事件中调用:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"sound_effects": {
|
||||
"attack_1": "mob.entity.attack_1",
|
||||
"attack_2": "mob.entity.attack_2",
|
||||
"attack_3": "mob.entity.attack_3"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## 粒子系统
|
||||
粒子简称用于动画事件触发:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"particle_effects": {
|
||||
"smoke": "wiki:smoke_particle"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
[自定义粒子教程](/particles/particles) | [动画效果应用](/visuals/animation-effects)
|
||||
|
||||
## 生成蛋设置
|
||||
生成蛋(Spawn Egg)支持纯色或自定义纹理两种风格:
|
||||
|
||||
::: code-group 纯色风格
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"spawn_egg": {
|
||||
"base_color": "#db7500",
|
||||
"overlay_color": "#242222"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
::: code-group 定制纹理
|
||||
```json [RP/entity/example.json#minecraft:client_entity/description]
|
||||
"spawn_egg": {
|
||||
"texture": "wiki.example"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## 特殊参数
|
||||
- `enable_attachables`(启用配件):控制实体能否持握工具
|
||||
- `hide_armor`(隐藏护甲):允许穿装备但不显示外观
|
||||
236
docs/wiki/3-实体/1-基础/entity-properties.md
Normal file
236
docs/wiki/3-实体/1-基础/entity-properties.md
Normal file
@@ -0,0 +1,236 @@
|
||||
---
|
||||
title: 实体属性
|
||||
category: 常规
|
||||
tags:
|
||||
- 实验性
|
||||
mentions:
|
||||
- SirLich
|
||||
- sermah
|
||||
- MedicalJewel105
|
||||
- Luthorius
|
||||
- stirante
|
||||
- TheItsNameless
|
||||
---
|
||||
|
||||
# 实体属性
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
:::warning
|
||||
本文档包含过时信息及实验性内容。如需最新稳定版信息,请查阅[微软官方文档](https://learn.microsoft.com/en-us/minecraft/creator/documents/introductiontoentityproperties)。
|
||||
:::
|
||||
|
||||
本文档介绍在Minecraft基岩版1.16.230.52测试版中加入的新实体属性系统(又称Actor Properties)。实体属性的实现目的是在实体服务端(行为包)高效保存数据或存储数值,无需使用组件或属性(例如"minecraft:variant"),其运作原理类似方块属性。
|
||||
|
||||
## 实体属性定义
|
||||
|
||||
### 定义实体属性
|
||||
|
||||
实体属性定义示例:
|
||||
|
||||
::: code-group
|
||||
```json [实体定义]
|
||||
{
|
||||
"minecraft:entity":{
|
||||
"description":{
|
||||
"identifier":"entity:properties_example",
|
||||
"properties":{
|
||||
"property:number_range_example":{
|
||||
"values":{
|
||||
"min":0,
|
||||
"max":100
|
||||
}
|
||||
},
|
||||
"property:number_enum_example":{
|
||||
"values":[
|
||||
1,
|
||||
2
|
||||
]
|
||||
},
|
||||
"property:string_enum_example":{
|
||||
"values":[
|
||||
"first",
|
||||
"second",
|
||||
"third"
|
||||
]
|
||||
},
|
||||
"property:boolean_enum_example":{
|
||||
"values":[
|
||||
true,
|
||||
false
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 实体属性字段说明
|
||||
|
||||
#### `values`
|
||||
|
||||
:::warning
|
||||
`values`字段为必填项,缺失此字段可能导致属性注册失败。
|
||||
:::
|
||||
|
||||
`values`字段可接受枚举值数组或数值区间(注意当前版本中整数、浮点和布尔枚举最多支持两个值):
|
||||
|
||||
::: code-group
|
||||
```json [数值范围模式]
|
||||
"property:range_example": {
|
||||
"values": {
|
||||
"min": 0,
|
||||
"max": 5
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```json [枚举模式]
|
||||
"property:enum_example":{
|
||||
"values":[
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
#### `default`
|
||||
|
||||
可通过属性对象内的`default`字段设置属性默认值(默认使用枚举数组的第一个元素):
|
||||
|
||||
::: code-group
|
||||
```json [默认值设置]
|
||||
"property:default_value_example":{
|
||||
"values":[
|
||||
true,
|
||||
false
|
||||
],
|
||||
"default":false
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
如示例所示,当实体生成时该属性会默认为`false`而非`true`。
|
||||
|
||||
#### `client_sync`
|
||||
|
||||
通过设置`client_sync`字段为`true`,可将属性同步到客户端资源包(Resource Pack)使用。默认值为`false`。
|
||||
|
||||
::: code-group
|
||||
```json [客户端同步示例]
|
||||
"property:client_sync_example": {
|
||||
"values": {
|
||||
"min": 0,
|
||||
"max": 20
|
||||
},
|
||||
"client_sync": true
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 操作与访问实体属性
|
||||
|
||||
可通过以下Molang查询访问实体属性:
|
||||
- `q.actor_property`
|
||||
- `q.has_actor_property`
|
||||
|
||||
:::warning
|
||||
这些Molang查询属于实验性功能
|
||||
:::
|
||||
|
||||
可通过`set_actor_property`事件响应设置实体属性值:
|
||||
|
||||
::: code-group
|
||||
```json [事件响应示例]
|
||||
"events":{
|
||||
"event:set_entity_property":{
|
||||
"set_actor_property":{
|
||||
"property:number_enum_example":2,
|
||||
"property:string_enum_example":"'second'",
|
||||
"property:boolean_enum_example":"!q.actor_property('property:boolean_enum_example')"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## 实体别名系统
|
||||
|
||||
可通过定义实体别名(aliases),在`summon`指令中调用自定义标识符生成带预置属性的实体:
|
||||
|
||||
::: code-group
|
||||
```json [别名定义]
|
||||
{
|
||||
"format_version": "1.16.0",
|
||||
"minecraft:entity": {
|
||||
"description": {
|
||||
"identifier": "entity:properties_example",
|
||||
"is_spawnable": true,
|
||||
"is_summonable": true,
|
||||
"is_experimental": false,
|
||||
"properties": {
|
||||
"property:property_index": {
|
||||
"client_sync": true,
|
||||
"values": {
|
||||
"min": 0,
|
||||
"max": 2
|
||||
},
|
||||
"default": 0
|
||||
}
|
||||
},
|
||||
"aliases": {
|
||||
"entity:default_alias": {},
|
||||
"entity:first_alias": {
|
||||
"property:property_index": 1
|
||||
},
|
||||
"entity:second_alias": {
|
||||
"property:property_index": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
现在通过`/summon entity:first_alias`指令可生成带有`property:property_index=1`属性的实体。
|
||||
|
||||
## 实体动态组件
|
||||
|
||||
实体动态组件(Entity Permutations)可根据属性条件在每个Tick动态应用组件集合。需在`minecraft:entity`对象内与`components`同级添加`permutations`数组:
|
||||
|
||||
::: code-group
|
||||
```json [动态组件示例]
|
||||
"permutations":[
|
||||
{
|
||||
"condition":"q.actor_property('property:string_enum_example') == 'first'",
|
||||
"components":{
|
||||
"minecraft:scale":{
|
||||
"value":1.0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"condition":"q.actor_property('property:string_enum_example') == 'second'",
|
||||
"components":{
|
||||
"minecraft:scale":{
|
||||
"value":2.0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"condition":"q.actor_property('property:string_enum_example') == 'third'",
|
||||
"components":{
|
||||
"minecraft:scale":{
|
||||
"value":3.0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
当`property:string_enum_example`属性为"first"时,实体会应用1倍缩放,为"second"时应用2倍缩放,为"third"时则应用3倍缩放。
|
||||
337
docs/wiki/3-实体/1-基础/npc-dialogs.md
Normal file
337
docs/wiki/3-实体/1-基础/npc-dialogs.md
Normal file
@@ -0,0 +1,337 @@
|
||||
---
|
||||
title: NPC 对话框
|
||||
category: 通用
|
||||
tags:
|
||||
- 中级
|
||||
参与贡献:
|
||||
- kyleplo
|
||||
- StuartDA
|
||||
- MedicalJewel105
|
||||
- SirLich
|
||||
- solvedDev
|
||||
- omuhu
|
||||
- Sprunkles137
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
# NPC 对话框
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
非玩家角色(NPC)是类似村民的实体,可通过对话框显示消息并提供多个交互按钮。最初设计用于冒险地图,随着 `/dialogue` 命令的引入,现在也能在常规附加包中使用。
|
||||
|
||||
## 对话框文件
|
||||
|
||||
NPC 对话数据存储于行为包根目录下 `dialogue` 文件夹内的 `.diag.json` 文件中。基础模板示例如下:
|
||||
|
||||
::: code-group
|
||||
```json [dialogue/example.diag.json]
|
||||
{
|
||||
"format_version": "1.17",
|
||||
"minecraft:npc_dialogue": {
|
||||
"scenes": [
|
||||
{
|
||||
"scene_tag": "example",
|
||||
"npc_name": "Steve",
|
||||
"text": "你好"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
每个场景包含以下可配置参数:
|
||||
|
||||
#### scene_tag
|
||||
|
||||
场景唯一标识符,用于指定具体场景。
|
||||
|
||||
#### npc_name
|
||||
|
||||
NPC 显示名称。若省略,则使用 NPC 实体名称(默认为`§eNPC`)。
|
||||
|
||||
#### text
|
||||
|
||||
显示在对话框中的文本(可选)。
|
||||
|
||||
#### on_open_commands
|
||||
|
||||
打开对话框时执行的命令列表(可选)。
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"on_open_commands": [
|
||||
"/say 你好"
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
#### on_close_commands
|
||||
|
||||
关闭对话框时执行的命令列表(可选)。
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"on_close_commands": [
|
||||
"/say 再见"
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
#### buttons
|
||||
|
||||
对话框中显示的按钮配置(可选)。
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"buttons": [
|
||||
{
|
||||
"name": "按钮一",
|
||||
"commands": [
|
||||
"/say 按钮一被点击了!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "按钮二",
|
||||
"commands": [
|
||||
"/say 按钮二被点击了!",
|
||||
"/say 第二段命令示例"
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
## 玩家选择器
|
||||
|
||||
在 `on_open_commands`、`on_close_commands` 和各按钮的 `commands` 中可使用本地选择器 `@p`,但会以 NPC 实体为中心选择。特殊选择器 `@initiator` 可始终指向触发对话框的玩家。
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"buttons": [
|
||||
{
|
||||
"name": "获得漂浮效果",
|
||||
"commands": [
|
||||
"/effect @initiator levitation"
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
注意:`@initiator` 专用于 NPC 对话框,不可在其他场景使用。
|
||||
|
||||
## 文本本地化
|
||||
|
||||
可通过翻译键实现多语言支持:
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"npc_name": {
|
||||
"rawtext": [
|
||||
{
|
||||
"translate": "entity.endermite.name"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
需在资源包语言文件中定义对应翻译键,例如 `entity.endermite.name` 对应中文为"末影螨"。
|
||||
|
||||
## 打开对话框
|
||||
|
||||
使用 `/dialogue` 命令开启对话框:
|
||||
```
|
||||
/dialogue open <npc: 目标> <player: 目标> [场景名称:string]
|
||||
```
|
||||
- `<npc: 目标>`:需携带 `minecraft:npc` 组件的实体(如原版 NPC)
|
||||
- `<player: 目标>`:目标玩家
|
||||
- `[场景名称:string]`:指定 `scene_tag`(若省略则显示上一个场景)
|
||||
|
||||
示例命令:
|
||||
```
|
||||
/dialogue open @e[type=npc,c=1] @p example
|
||||
```
|
||||
|
||||
## 切换对话框
|
||||
|
||||
使用以下语法变更 NPC 默认对话框:
|
||||
```
|
||||
/dialogue change <npc: 目标> <场景名称:string> [player: 目标]
|
||||
```
|
||||
- `<场景名称:string>`:指定新场景的 `scene_tag`
|
||||
- `[player: 目标]`:指定生效玩家(若省略则影响所有人)
|
||||
|
||||
示例命令:
|
||||
```
|
||||
/dialogue change @e[type=npc,c=1] example @r
|
||||
```
|
||||
|
||||
## 完整范例
|
||||
|
||||
本节演示创建具有传送功能的道具和对话系统(完整源码可参见[GitHub](https://github.com/Llama-Studios/dialog-demo))。
|
||||
|
||||
### 创建 NPC 实体
|
||||
|
||||
即使隐藏 NPC,也需要通过常加载区域保持存在:
|
||||
|
||||
::: code-group
|
||||
```mcfunction [functions/setup.mcfunction]
|
||||
tickingarea add 0 1 0 0 2 0
|
||||
summon npc "§r" 0 1 0
|
||||
```
|
||||
:::
|
||||
|
||||
:::tip
|
||||
可通过玩家实体触发对话框:
|
||||
1. 为玩家添加 `minecraft:npc` 组件
|
||||
2. 映射行为包对话框场景
|
||||
3. 执行以下命令:
|
||||
```
|
||||
/dialogue open @s @s <scene_tag>
|
||||
```
|
||||
#### 优劣分析
|
||||
`+` 无需维护隐藏 NPC<br/>
|
||||
`+` 无需管理常加载区域<br/>
|
||||
`-` 非正常使用可能导致稳定性问题<br/>
|
||||
`-` 其他玩家点击该玩家时会显示对话框<br/>
|
||||
|
||||
可通过添加交互组件避免问题:
|
||||
::: code-group
|
||||
```json
|
||||
"minecraft:interact": {
|
||||
"interactions": [
|
||||
{
|
||||
"on_interact": {
|
||||
"filters": {
|
||||
"all_of": [
|
||||
{
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
:::
|
||||
:::
|
||||
|
||||
### 对话文件配置
|
||||
|
||||
::: code-group
|
||||
```json [dialogue/example.diag.json]
|
||||
{
|
||||
"format_version":"1.17",
|
||||
"minecraft:npc_dialogue":{
|
||||
"scenes":[
|
||||
{
|
||||
"scene_tag":"main_teleport_menu",
|
||||
"npc_name":"传送菜单",
|
||||
"text":"选择传送目的地",
|
||||
"buttons":[
|
||||
{
|
||||
"name":"区域传送",
|
||||
"commands":[
|
||||
"/dialogue open @e[type=npc,c=1] @initiator districts_teleport_menu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"个人基地",
|
||||
"commands":[
|
||||
"/tp @initiator -20 4 -20"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"世界出生点",
|
||||
"commands":[
|
||||
"/tp @initiator 0 4 0"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"scene_tag":"districts_teleport_menu",
|
||||
"npc_name":"区域传送",
|
||||
"text":"请选择目标区域",
|
||||
"buttons":[
|
||||
{
|
||||
"name":"< 返回",
|
||||
"commands":[
|
||||
"/dialogue open @e[type=npc,c=1] @initiator main_teleport_menu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"商业区",
|
||||
"commands":[
|
||||
"/tp @initiator 20 4 20"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"娱乐区",
|
||||
"commands":[
|
||||
"/tp @initiator 20 4 -20"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 创建传送物品
|
||||
|
||||
::: code-group
|
||||
```json [items/teleport_menu.json]
|
||||
{
|
||||
"format_version": "1.16.100",
|
||||
"minecraft:item": {
|
||||
"description": {
|
||||
"identifier": "dialog:teleport_menu",
|
||||
"category": "物品"
|
||||
},
|
||||
"components": {
|
||||
"minecraft:on_use": {
|
||||
"on_use": {
|
||||
"event": "open_menu",
|
||||
"target": "self"
|
||||
}
|
||||
},
|
||||
"minecraft:foil": true,
|
||||
"minecraft:icon": {
|
||||
"texture": "ender_pearl"
|
||||
},
|
||||
"minecraft:display_name": {
|
||||
"value": "传送菜单"
|
||||
}
|
||||
},
|
||||
"events": {
|
||||
"open_menu": {
|
||||
"run_command": {
|
||||
"command": [
|
||||
"dialogue open @e[type=npc,c=1] @s main_teleport_menu"
|
||||
],
|
||||
"target": "player"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 测试步骤
|
||||
1. 在超平坦世界启用实验性玩法
|
||||
2. 执行 `/function setup` 创建 NPC
|
||||
3. 获取道具:`/give @s dialog:teleport_menu`
|
||||
4. 切换生存模式使用道具
|
||||
|
||||
## 版权声明
|
||||
|
||||
本教程改编自 [Minecraft 创作者文档](https://docs.microsoft.com/en-us/minecraft/creator/documents/npcdialogue)。
|
||||
310
docs/wiki/3-实体/1-基础/render-controllers.md
Normal file
310
docs/wiki/3-实体/1-基础/render-controllers.md
Normal file
@@ -0,0 +1,310 @@
|
||||
---
|
||||
title: 渲染控制器
|
||||
category: 常规
|
||||
tags:
|
||||
- beginner
|
||||
mentions:
|
||||
- SirLich
|
||||
- MedicalJewel105
|
||||
- Overload252
|
||||
- ChibiMango
|
||||
---
|
||||
|
||||
# 渲染控制器
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
渲染控制器是资源包中常被误解的部分。但您无需畏惧!您可以将渲染控制器视为逻辑包,它们接收来自资源包实体文件中的短名称定义,并决定这些资源在游戏中如何组合/分层/渲染。
|
||||
|
||||
## 定义短名称
|
||||
|
||||
渲染控制器基于资源包实体文件中的短名称定义运作。短名称是我们在资源包实体文件中定义的本地标识符,可供渲染控制器(及其他地方)调用。我们可以在实体中定义`geometry`(几何体)、`materials`(材质)和`textures`(纹理)等变量。
|
||||
|
||||
让我们看看蜘蛛资源包实体文件的简化版本:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/spider.json]
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"minecraft:client_entity": {
|
||||
"description": {
|
||||
"identifier": "minecraft:cave_spider",
|
||||
"materials": {
|
||||
"default": "spider",
|
||||
"invisible": "spider_invisible"
|
||||
},
|
||||
"textures": {
|
||||
"default": "textures/entity/spider/cave_spider"
|
||||
},
|
||||
"geometry": {
|
||||
"default": "geometry.spider.v1.8"
|
||||
},
|
||||
"render_controllers": ["controller.render.spider"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
此示例中创建了四个短名称定义:
|
||||
- `default`(材质数组)
|
||||
- `invisible`(材质数组)
|
||||
- `default`(纹理数组)
|
||||
- `default`(几何体数组)
|
||||
|
||||
您可以在每个数组中定义多个短名称(如上方的材质示例)。将短名称定义视为_导入_所需资源的操作。在此阶段,您在定义实体要使用的纹理、几何体和材质。在渲染控制器阶段不会导入新内容,而是使用已导入的资源来构建最终渲染的实体。
|
||||
|
||||
## 简单渲染控制器
|
||||
|
||||
一个基础渲染控制器示例如下:
|
||||
|
||||
::: code-group
|
||||
```json [RP/render_controllers/cow.render.json]
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"render_controllers": {
|
||||
"controller.render.cow": {
|
||||
"geometry": "Geometry.default",
|
||||
"materials": [
|
||||
{
|
||||
"*": "Material.default"
|
||||
}
|
||||
],
|
||||
"textures": ["Texture.default"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
该控制器从实体文件获取短名称定义并进行_渲染_。例如`"textures": [ "Texture.default"]`表达:"采用default纹理并应用于实体"。渲染控制器本身并不知晓default纹理的具体内容,只是执行应用指令。
|
||||
|
||||
## 复用渲染控制器
|
||||
|
||||
由于渲染控制器基于短名称工作,您可以在所有实体中复用同一个渲染控制器。对于只含单一材质、单一纹理和单一几何体的简单实体,无需创建自定义渲染控制器。
|
||||
|
||||
例如上方示例的控制器用于`minecraft:cow`实体。若要在自定义包中使用此控制器,只需在实体文件中声明:`"render_controllers": [ "controller.render.cow" ]`。
|
||||
|
||||
:::warning 注意!
|
||||
渲染控制器基于短名称工作。若使用牛的渲染控制器,必须提供其所需的短名称:
|
||||
- `default`几何体
|
||||
- `default`纹理
|
||||
- `default`材质
|
||||
:::
|
||||
|
||||
## 创建自定义渲染控制器
|
||||
|
||||
当我们需要更精细控制实体渲染时(如分层纹理、多重几何体、不同骨骼应用不同材质),可通过复制原版渲染控制器到`render_controllers`文件夹进行定制化修改。
|
||||
|
||||
## 纹理分层
|
||||
|
||||
通过纹理分层技术可为自定实体创建叠加纹理。基础思路是通过多个纹理的透明像素区域实现叠加显示。
|
||||
|
||||
假设一个**画框**实体:框架固定但画面可变。虽然可以复制10个框架纹理并制作10幅画作,但修改框架时需要改动所有文件。采用分层纹理方案时,首先放置框架纹理,再叠加画作纹理,即可实现框架的集中管理。
|
||||
|
||||
### 通过渲染控制器实现
|
||||
|
||||
若对渲染控制器不熟悉,建议参考原版案例。例如含有多个纹理的`horse`实体具有典型参考价值。
|
||||
|
||||
#### 渲染控制器
|
||||
|
||||
::: code-group
|
||||
```json [RP/render_controllers/controller.render.texture_layering.json]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"render_controllers": {
|
||||
"controller.render.texture_layering": {
|
||||
"geometry": "Geometry.default",
|
||||
"materials": [
|
||||
{
|
||||
"*": "Material.default"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
// 你可以添加任意数量的图层,按从上到下的顺序叠加
|
||||
"Texture.bottom_layer",
|
||||
"Texture.top_layer"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
#### 实体配置
|
||||
|
||||
需要定义所有纹理并使用`villager_v2_masked`材质:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/my_entity.json]
|
||||
"materials": {
|
||||
"default": "villager_v2_masked"
|
||||
},
|
||||
"textures": {
|
||||
"top_layer": "textures/top",
|
||||
"bottom_layer": "textures/bottom"
|
||||
// 在此添加更多纹理短名称定义
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 动态变体分层
|
||||
|
||||
通过动态索引实现纹理切换能创造更灵活的效果:
|
||||
|
||||
#### 实体配置
|
||||
|
||||
定义多个顶部纹理以供索引:
|
||||
|
||||
::: code-group
|
||||
```json [RP/entity/my_entity.json#description]
|
||||
"textures": {
|
||||
"top_1": "textures/top_1",
|
||||
"top_2": "textures/top_2",
|
||||
"top_3": "textures/top_3",
|
||||
"bottom_layer": "textures/bottom"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
#### 渲染控制器
|
||||
|
||||
::: code-group
|
||||
```json [RP/render_controllers/controller.render.wool_only]
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"render_controllers": {
|
||||
"controller.render.wool_only": {
|
||||
"arrays": {
|
||||
"textures": {
|
||||
"Array.top": [
|
||||
"Texture.top_1",
|
||||
"Texture.top_2",
|
||||
"Texture.top_3"
|
||||
]
|
||||
}
|
||||
},
|
||||
"geometry": "Geometry.default",
|
||||
"materials": [
|
||||
{
|
||||
"*": "Material.default"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
"Texture.bottom", // 静态底层纹理
|
||||
"Array.top[q.variant]" // 根据实体变体选择顶部纹理
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
通过数组和`q.variant`查询,可根据实体variant值动态选择顶部纹理。
|
||||
|
||||
#### 设置变体值
|
||||
|
||||
要使分层显示生效,需在实体中设置variant组件:
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/my_entity.json#components]
|
||||
"minecraft:variant": {
|
||||
"value": 0
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
注意组件参数采用零索引制,`0`对应第一个纹理,`1`和`2`对应后续纹理。
|
||||
|
||||
#### 动态更换纹理
|
||||
|
||||
如需在游戏中动态更换纹理,只需修改`variant`值。可通过组件组和事件系统实现此功能。
|
||||
|
||||
#### 动态分层进阶
|
||||
|
||||
通过添加更多纹理数组和使用虚拟组件(dummy components)作为索引,可实现更复杂的动态分层效果。关于虚拟组件的详细信息请参阅[此文档](/entities/dummy-components)。
|
||||
|
||||
### 动态几何体切换
|
||||
|
||||
动态切换几何体的原理与纹理类似:
|
||||
|
||||
以下示例展示如何根据variant值切换不同几何体。注意几何体不可分层叠加,因此不需要基础层定义,但仍需使用`villager_v2_masked`材质。
|
||||
|
||||
::: code-group
|
||||
```json [RP/render_controllers/controller.render.player.third_person.json]
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"render_controllers": {
|
||||
"controller.render.player.third_person": {
|
||||
"materials": [
|
||||
{
|
||||
"*": "Material.default"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
"Texture.bottom",
|
||||
"Array.top[q.variant]"
|
||||
],
|
||||
"arrays": {
|
||||
"geometries": {
|
||||
"Array.geo": [
|
||||
"Geometry.default",
|
||||
"Geometry.custom_1",
|
||||
"Geometry.custom_2"
|
||||
]
|
||||
},
|
||||
"textures": {
|
||||
"Array.top": [
|
||||
"Texture.bottom",
|
||||
"Texture.top_1",
|
||||
"Texture.top_2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"geometry": "Array.geo[q.variant]"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
#### 实体配置
|
||||
|
||||
确保在实体文件中包含对应几何体变体:
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"geometry": {
|
||||
"default": "geometry.entity.default",
|
||||
"custom_1": "geometry.entity.custom_1",
|
||||
"custom_2": "geometry.entity.custom_2"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## 常见错误
|
||||
|
||||
在渲染控制器中:
|
||||
- 可引用多个纹理但只能引用一个几何体(数组形式亦适用)
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"arrays": {
|
||||
"textures": {
|
||||
"array.skin": [],
|
||||
"array.dress": []
|
||||
},
|
||||
"geometries": {
|
||||
"array.geo": []
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
"textures": [
|
||||
"array.skin[q.variant]",
|
||||
"array.dress[q.skin_id]"
|
||||
],
|
||||
"geometry": "array.geo[q.mark_variant]"
|
||||
```
|
||||
:::
|
||||
159
docs/wiki/3-实体/1-基础/spawn-rules.md
Normal file
159
docs/wiki/3-实体/1-基础/spawn-rules.md
Normal file
@@ -0,0 +1,159 @@
|
||||
---
|
||||
title: 实体生成规则
|
||||
category: 常规
|
||||
mentions:
|
||||
- SirLich
|
||||
- solvedDev
|
||||
- MedicalJewel105
|
||||
- aexer0e
|
||||
- Ciosciaa
|
||||
- FrankyRay
|
||||
- Luthorius
|
||||
- TheItsNameless
|
||||
- SmokeyStack
|
||||
---
|
||||
|
||||
# 实体生成规则
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
生成规则定义了实体如何自然生成到世界中。当您希望自定义实体像原版实体一样自然生成时,应该使用生成规则。通过不同的组件可以定义实体生成的时间、地点和方式。
|
||||
|
||||
通常情况下,可以让您的自定义实体采用与原版实体类似的生成方式。例如:像牛一样群生成、像原版僵尸一样仅在夜间生成,或是像鱼类只在水下生成。
|
||||
|
||||
## 生成规则示例
|
||||
|
||||
以下是一个包含字段说明的生成规则示例:
|
||||
|
||||
::: code-group
|
||||
```json [BP/spawn_rules/zombie.json]
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"minecraft:spawn_rules": {
|
||||
"description": {
|
||||
"identifier": "minecraft:zombie",
|
||||
"population_control": "monster"
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"minecraft:spawns_on_surface": {},
|
||||
"minecraft:spawns_underground": {},
|
||||
"minecraft:brightness_filter": {
|
||||
"min": 0,
|
||||
"max": 7,
|
||||
"adjust_for_weather": true
|
||||
},
|
||||
"minecraft:difficulty_filter": {
|
||||
"min": "easy",
|
||||
"max": "hard"
|
||||
},
|
||||
"minecraft:weight": {
|
||||
"default": 100
|
||||
},
|
||||
"minecraft:herd": {
|
||||
"min_size": 2,
|
||||
"max_size": 4
|
||||
},
|
||||
"minecraft:permute_type": [
|
||||
{
|
||||
"weight": 95
|
||||
},
|
||||
{
|
||||
"weight": 5,
|
||||
"entity_type": "minecraft:zombie_villager"
|
||||
}
|
||||
],
|
||||
"minecraft:biome_filter": {
|
||||
"test": "has_biome_tag",
|
||||
"operator": "==",
|
||||
"value": "monster"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
- `description`→`identifier`: 要生成的实体
|
||||
- `population_control`: 控制生成与消失的数量。可选值:`animal`(动物)、`underwater_animal`(水生动物)、`monster`(怪物)、`ambient`(环境生物)
|
||||
- `conditions`: 必须满足的条件列表,生成尝试才会成功
|
||||
- `minecraft:spawns_on_surface`(地表生成)、`minecraft:spawns_underground`(地下生成)和`minecraft:spawns_underwater`(水下生成)控制实体生成的高度范围
|
||||
- `minecraft:brightness_filter`(亮度过滤)取值范围 0-15,控制生成所需光照条件。`adjust_for_weather`选项用于雨天/雷暴天气下是否自动降低有效光照值
|
||||
- `minecraft:difficulty_filter`(难度过滤)设置启用生成的游戏难度范围
|
||||
- `minecraft:herd`(群体生成)设置基于同个生成规则一起生成的实体数量
|
||||
- `minecraft:permute_type`(类型置换)通过`weight`权重和`entity_type`实体类型设置生成实体变异的概率
|
||||
- `minecraft:biome_filter`(生物群系过滤)测试特定生物群系标签。具体过滤器语法和生物群系标签列表请参考官方文档,或查看原版示例资源包
|
||||
|
||||
## 全部已知组件
|
||||
|
||||
以下是所有已知组件列表(随着我们对使用方法的理解加深,将持续补充说明文档):
|
||||
|
||||
```
|
||||
minecraft:weight
|
||||
minecraft:density_limit
|
||||
minecraft:spawns_on_block_filter
|
||||
minecraft:spawns_on_block_prevented_filter
|
||||
minecraft:spawns_above_block_filter
|
||||
minecraft:herd
|
||||
minecraft:permute_type
|
||||
minecraft:brightness_filter
|
||||
minecraft:height_filter
|
||||
minecraft:spawns_on_surface
|
||||
minecraft:spawns_underground
|
||||
minecraft:spawns_underwater
|
||||
minecraft:disallow_spawns_in_bubble
|
||||
minecraft:spawns_lava
|
||||
minecraft:biome_filter
|
||||
minecraft:difficulty_filter
|
||||
minecraft:distance_filter
|
||||
minecraft:is_experimental
|
||||
minecraft:world_age_filter
|
||||
minecraft:delay_filter
|
||||
minecraft:mob_event_filter
|
||||
minecraft:is_persistent
|
||||
minecraft:player_in_village_filter
|
||||
```
|
||||
|
||||
## 组件文档
|
||||
|
||||
### minecraft:herd
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"minecraft:herd": {
|
||||
"min_size": 1,
|
||||
"max_size": 2,
|
||||
"event":"minecraft:entity_born",
|
||||
"event_skip_count": 1
|
||||
},
|
||||
```
|
||||
:::
|
||||
|
||||
- `minecraft:herd`可通过此配置使第二个生成的实体(在此场景中)携带`minecraft:entity_born`事件(表现为幼体)。`event_skip_count`: 2`表示前两个生成的实体不会触发事件,之后生成的都会携带该事件。该功能适用于任意事件类型
|
||||
|
||||
### minecraft:spawns_above_block_filter
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"minecraft:spawns_above_block_filter": {
|
||||
"blocks": "minecraft:stone",
|
||||
"distance": 10
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
- `minecraft:spawns_above_block_filter`(上方方块过滤)会检测垂直方向设定距离内的方块,当条件满足时允许实体生成
|
||||
|
||||
### minecraft:spawns_on_block_prevented_filter
|
||||
|
||||
::: code-group
|
||||
```json
|
||||
"minecraft:spawns_on_block_prevented_filter": [
|
||||
"minecraft:nether_wart_block",
|
||||
"minecraft:shroomlight"
|
||||
]
|
||||
```
|
||||
:::
|
||||
|
||||
- `minecraft:spawns_on_block_prevented_filter`(禁止生成方块过滤)与上方组件功能相反。该数组包含实体永远无法生成于其上的方块标识符
|
||||
158
docs/wiki/3-实体/1-基础/troubleshooting-entities.md
Normal file
158
docs/wiki/3-实体/1-基础/troubleshooting-entities.md
Normal file
@@ -0,0 +1,158 @@
|
||||
---
|
||||
title: 实体问题排查指南
|
||||
category: 常规
|
||||
nav_order: 3
|
||||
tags:
|
||||
- help
|
||||
mentions:
|
||||
- SirLich
|
||||
- BlueFrog130
|
||||
- SmokeyStack
|
||||
- MedicalJewel105
|
||||
- aexer0e
|
||||
- ChibiMango
|
||||
- RonarsCorruption
|
||||
---
|
||||
|
||||
# 实体问题排查指南
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
:::tip
|
||||
本页面包含关于_实体_的疑难解答信息。在继续阅读前,请务必先查阅[全局问题排查指南](/guide/troubleshooting)。
|
||||
:::
|
||||
|
||||
:::warning
|
||||
请始终记得检查内容日志!
|
||||
:::
|
||||
|
||||
## 0.0.0 - 确认问题存在
|
||||
|
||||
承认吧,某个地方肯定出错了。_任何_水平的开发者在_任何_阶段都可能出现这些疏漏,所以不要觉得被冒犯而想着"我当然会注意这些!",然后跳过必要的检查步骤!
|
||||
|
||||
<BButton color="blue" link="#_1-0-0-are-both-packs-active">继续</BButton>
|
||||
|
||||
|
||||
## 1.0.0 - 确保两个包都已启用
|
||||
|
||||
确认资源包和行为包在世界中都已激活(一个绝佳的防错方法是在两个包的manifest.json文件中互相设置依赖,这样添加或移除其中一个包时会自动同步处理)
|
||||
|
||||
<BButton color="blue" link="#_2-0-0-determine-whether-the-issue-is-in-the-rp-or-the-bp">继续</BButton>
|
||||
|
||||
## 2.0.0 - 确定问题出现在资源包还是行为包
|
||||
|
||||
通过观察实体生成蛋在创造模式物品栏中的显示状态,可以有效定位问题范围。即使您不打算为实体添加生成蛋,请暂时按照以下步骤添加以便定位问题:
|
||||
|
||||
### 在资源包中
|
||||
|
||||
确保.entity文件包含自定义spawn_egg配置:
|
||||
|
||||
::: code-group
|
||||
```json [RP]
|
||||
"spawn_egg":{
|
||||
"base_color": "#FF0000",
|
||||
"overlay_color": "#FFFF00"
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
(建议选择除"#000000"以外的配色以方便排查)
|
||||
|
||||
### 在行为包中
|
||||
|
||||
确保description对象中开启`is_spawnable`和`is_summonable`,并将`is_experimental`设为false:
|
||||
|
||||
::: code-group
|
||||
```json [BP]
|
||||
"description":{
|
||||
"identifier": "wiki:example_entity",
|
||||
"is_spawnable": true,
|
||||
"is_summonable": true,
|
||||
"is_experimental": false
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
### 现象分析
|
||||
|
||||
完全看不到生成蛋:<BButton color="blue" link="#_3-1-0-bp">前往排查</BButton>
|
||||
|
||||
能看到生成蛋但颜色全黑且无法生成实体:<BButton color="blue" link="#step-3-2-0-rp-entity">前往排查</BButton>
|
||||
|
||||
生成蛋显示正常颜色但仍旧无法生成实体:<BButton color="blue" link="#step-3-3-0-rp-resources-still-writing-because-this-is-going-to-be-extensive">前往排查</BButton>
|
||||
|
||||
## 3.0.0 - 定位具体问题
|
||||
|
||||
## 3.1.0 - 行为包问题
|
||||
|
||||
_即使已在行为文件中设置"is_spawnable": true,在创造模式物品栏中依然无法找到生成蛋_
|
||||
|
||||
这通常表示游戏未能正确识别实体行为文件。常见原因包括:
|
||||
|
||||
- Json语法错误
|
||||
- 文件夹命名错误
|
||||
|
||||
### 3.1.1 - 语法错误
|
||||
|
||||
单个语法错误会导致整个json文件失效。建议使用[JSON验证工具](https://jsonlint.com/)检查文件的语法完整性(注:虽然该网站会将//注释视为错误,但在Minecraft中实际允许使用注释)
|
||||
|
||||
### 3.1.2 - 文件夹误命名
|
||||
|
||||
请确认行为包中的实体文件夹命名为"entities"(资源包对应的是"entity",这个不一致设定确实容易引起困惑)
|
||||
|
||||
## 步骤3.2.0 - 资源包.entity文件问题
|
||||
|
||||
_能在创造模式物品栏中看到生成蛋,但显示为黑色且实体名异常(如"item.spawn_egg.entity.wiki:your_mob.name"),且无法正常生成实体_
|
||||
|
||||
此现象说明行为文件已生效,但资源包未能正确关联对应.entity文件。常见原因包括:
|
||||
|
||||
- .entity文件语法错误
|
||||
- 实体identifier不匹配
|
||||
- 资源引用路径错误
|
||||
- 资源包文件夹应命名为"entity",行为包文件夹应命名为"entities"
|
||||
|
||||
### 步骤3.2.1 - 语法错误
|
||||
|
||||
再次推荐使用[JSON验证工具](https://jsonlint.com/)进行深度校验(注意注释标识的兼容性问题)
|
||||
|
||||
### 步骤3.2.2 - 标识符不匹配
|
||||
|
||||
需确保资源包.entity文件与行为包的identifier字段完全一致,包括命名空间(冒号前的部分,例如`minecraft:bat`中的`minecraft`)。特别注意:
|
||||
|
||||
- 除了冒号外不要使用特殊字符
|
||||
- 命名空间和ID避免以数字或大写字母开头(虽然现行版本允许,但历史版本曾存在兼容性问题)
|
||||
- 非官方实体切勿使用`minecraft`作为命名空间
|
||||
|
||||
### 步骤3.2.3 - 无效资源引用
|
||||
|
||||
检查.entity文件中各项资源引用路径是否正确指向有效文件
|
||||
|
||||
## 步骤3.3.0 - 资源包资源排查(进行中)
|
||||
|
||||
_生成蛋显示正常颜色但在生成/召唤时实体不可见或仅显示阴影_
|
||||
|
||||
这说明基本功能文件已正常加载,但存在次级资源配置问题。根据现象选择排查方向:
|
||||
|
||||
- 完全隐形无阴影 → 资源引用错误:<BButton link="#_3-3-1-invisible-no-shadow" color=blue >前往</BButton>
|
||||
- 隐形但显示阴影 → 几何体问题:<BButton link="#_3-3-2-invisible-shadow-exists" color=blue >前往</BButton>
|
||||
- 可见但贴图异常 → 材质问题:<BButton link="#_3-3-3-visible-weird-texture" color=blue >前往</BButton>
|
||||
- 可见但渲染异常 → 材质类型错误:<BButton link="#_3-3-4-visible-weird-visibility-stuff" color=blue >前往</BButton>
|
||||
|
||||
### 3.3.1 - 完全隐形无阴影
|
||||
|
||||
确认实体未设置立即消失逻辑(如instant_despawn),优先检查实体基础配置。
|
||||
|
||||
### 3.3.2 - 隐形但显示阴影
|
||||
|
||||
此类问题通常涉及模型或材质配置,排查重点:
|
||||
|
||||
1. 几何体文件:检查命名正确性、文件完整性和几何偏移量设置
|
||||
2. 材质匹配:例如透明材质与普通材质的兼容性
|
||||
3. 渲染控制器:验证控制器逻辑与参数设置
|
||||
|
||||
### 3.3.3 - 可见但贴图异常
|
||||
|
||||
(内容开发中)
|
||||
|
||||
### 3.3.4 - 可见但渲染异常
|
||||
(内容开发中)
|
||||
165
docs/wiki/3-实体/2-巧思案例/boat-entities.md
Normal file
165
docs/wiki/3-实体/2-巧思案例/boat-entities.md
Normal file
@@ -0,0 +1,165 @@
|
||||
---
|
||||
title: Creating Boats
|
||||
category: Tutorials
|
||||
tags:
|
||||
- recipe
|
||||
- intermediate
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
- MedicalJewel105
|
||||
- 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.
|
||||
:::
|
||||
|
||||
## 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.
|
||||
|
||||
## 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.
|
||||
|
||||
## 1st method: minecraft:behavior.rise_to_liquid_level
|
||||
|
||||
<CodeHeader>BP/entities/bar</CodeHeader>
|
||||
|
||||
```json
|
||||
{
|
||||
"minecraft:entity": {
|
||||
"format_version": "1.14.0",
|
||||
"description": {
|
||||
"identifier": "foo:bar",
|
||||
"is_summonable": true,
|
||||
"is_spawnable": true,
|
||||
"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
|
||||
},
|
||||
"minecraft:rideable": {
|
||||
"seat_count": 1,
|
||||
"family_types": ["player"],
|
||||
"interact_text": "action.interact.enter_boat",
|
||||
"seats": {
|
||||
"position": [0, 0, 0]
|
||||
}
|
||||
},
|
||||
//Add this component if you want your boat to be controlled with 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)
|
||||
"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,
|
||||
"height": 1
|
||||
},
|
||||
"minecraft:physics": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 2nd method: minecraft:buoyant
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
{
|
||||
"minecraft:entity": {
|
||||
"format_version": "1.14.0",
|
||||
"description": {
|
||||
"identifier": "foo:bar",
|
||||
"is_summonable": true,
|
||||
"is_spawnable": true,
|
||||
"is_experimental": false
|
||||
},
|
||||
"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
|
||||
"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.
|
||||
"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
|
||||
},
|
||||
"minecraft:rideable": {
|
||||
"seat_count": 1,
|
||||
"family_types": ["player"],
|
||||
"interact_text": "action.interact.enter_boat",
|
||||
"seats": {
|
||||
"position": [0, 0, 0]
|
||||
}
|
||||
},
|
||||
//Add this component if you want your boat to be controlled with 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)
|
||||
"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,
|
||||
"height": 1
|
||||
},
|
||||
"minecraft:physics": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 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.
|
||||
221
docs/wiki/3-实体/2-巧思案例/detecting-other-entities.md
Normal file
221
docs/wiki/3-实体/2-巧思案例/detecting-other-entities.md
Normal file
@@ -0,0 +1,221 @@
|
||||
---
|
||||
title: Detecting Other Entities
|
||||
category: Tutorials
|
||||
tags:
|
||||
- intermediate
|
||||
mentions:
|
||||
- ANightDazingZoroark
|
||||
- SmokeyStack
|
||||
- MedicalJewel105
|
||||
- SirLich
|
||||
- Luthorius
|
||||
- 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.
|
||||
|
||||
## 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:
|
||||
|
||||
<CodeHeader>BP/entities/my_entity.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"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
|
||||
"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
|
||||
}
|
||||
```
|
||||
|
||||
## `/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.
|
||||
|
||||
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
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
"animations": {
|
||||
"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"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Molang, BP Animations & Animation Controllers
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
{
|
||||
"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.
|
||||
|
||||
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
|
||||
{
|
||||
"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
|
||||
{
|
||||
"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
|
||||
"animations": {
|
||||
"manage_find_player": "controller.animation.pig_find_player",
|
||||
"find_player": "animation.pig.find_player"
|
||||
},
|
||||
"scripts": {
|
||||
"animate": [
|
||||
"manage_find_player"
|
||||
]
|
||||
}
|
||||
```
|
||||
184
docs/wiki/3-实体/2-巧思案例/disabling-team-damage.md
Normal file
184
docs/wiki/3-实体/2-巧思案例/disabling-team-damage.md
Normal file
@@ -0,0 +1,184 @@
|
||||
---
|
||||
title: Disabling Team-damage
|
||||
category: Tutorials
|
||||
tags:
|
||||
- intermediate
|
||||
mentions:
|
||||
- SirLich
|
||||
- solvedDev
|
||||
- Joelant05
|
||||
- MedicalJewel105
|
||||
- Luthorius
|
||||
- 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>
|
||||
|
||||
```json
|
||||
"minecraft:damage_sensor":{
|
||||
"triggers":[
|
||||
{ //if you already have a damage sensor, simply copy this object into the "triggers" array
|
||||
"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?
|
||||
]
|
||||
},
|
||||
{
|
||||
"all_of":[
|
||||
{ "test":"has_tag", "value":"team2" }, //repeats for every team
|
||||
{ "test":"has_tag", "subject":"other", "value":"team2" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"all_of":[
|
||||
{ "test":"has_tag", "value":"team3" },
|
||||
{ "test":"has_tag", "subject":"other", "value":"team3" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"all_of":[
|
||||
{ "test":"has_tag", "value":"team4" },
|
||||
{ "test":"has_tag", "subject":"other", "value":"team4" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"all_of":[
|
||||
{ "test":"has_tag", "value":"team5" },
|
||||
{ "test":"has_tag", "subject":"other", "value":"team5" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"deals_damage":false //if any of these filters evaluate to true in the current attack interaction, the target will not be hurt.
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Projectiles
|
||||
|
||||
Due to the primitive filters used by projectile entities, you have to use a completely different method to achieve this.
|
||||
|
||||
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.
|
||||
0.0,
|
||||
0.1
|
||||
],
|
||||
"looping": true,
|
||||
"time_down_event": {
|
||||
"event": "wiki:projectile_team",
|
||||
"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 . . .
|
||||
"filters": {
|
||||
"test": "has_tag",
|
||||
"value": "damage"
|
||||
},
|
||||
"cause": "projectile",
|
||||
"damage_per_tick": 4
|
||||
}
|
||||
]
|
||||
},
|
||||
"minecraft:damage_sensor": { //. . . which in turn, will trigger an event
|
||||
"triggers": { //to remove this tag, so the damage only
|
||||
"cause": "projectile", //happens once.
|
||||
"deals_damage": true,
|
||||
"on_damage": {
|
||||
"filters": {
|
||||
"test": "has_tag",
|
||||
"value": "damage"
|
||||
},
|
||||
"event": "wiki:stop_damage"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//"events"
|
||||
"wiki:projectile_team": { //The function here will apply tags depending on
|
||||
"run_command": { //which team tags the player has.
|
||||
"command": [
|
||||
"function wiki-apply_team"
|
||||
]
|
||||
}
|
||||
},
|
||||
"wiki:stop_damage": { //The event that simply removes the damage tag.
|
||||
"run_command": {
|
||||
"command": [
|
||||
"tag @s remove damage"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader>BP/functions/wiki-apply_team.mcfunction</CodeHeader>
|
||||
|
||||
```
|
||||
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 . . .
|
||||
"definition_event": {
|
||||
"affect_projectile": true,
|
||||
"event_trigger": {
|
||||
"event": "wiki:hit",
|
||||
"target": "self"
|
||||
}
|
||||
},
|
||||
"remove_on_hit": {}
|
||||
}
|
||||
|
||||
//"events"
|
||||
"wiki:hit": { //. . . which executes a function, applying
|
||||
"run_command": { //the damage tag to any players of a different team!
|
||||
"command": [
|
||||
"function wiki-apply_damage"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader>BP/functions/wiki-apply_damage.mcfunction</CodeHeader>
|
||||
|
||||
```
|
||||
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.
|
||||
|
||||
146
docs/wiki/3-实体/2-巧思案例/dummy-entities.md
Normal file
146
docs/wiki/3-实体/2-巧思案例/dummy-entities.md
Normal file
@@ -0,0 +1,146 @@
|
||||
---
|
||||
title: Dummy Entities
|
||||
category: Tutorials
|
||||
tags:
|
||||
- beginner
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
- MedicalJewel105
|
||||
- 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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
{
|
||||
"format_version": "1.16.0",
|
||||
"minecraft:entity": {
|
||||
"description": {
|
||||
"identifier": "wiki:dummy",
|
||||
"is_summonable": true,
|
||||
"is_spawnable": false,
|
||||
"is_experimental": false
|
||||
},
|
||||
"components": {
|
||||
"minecraft:breathable": { //Optional, allows the entity to breath underwater
|
||||
"breathes_water": true
|
||||
},
|
||||
"minecraft:physics": {
|
||||
"has_gravity": false, //Optional, allows the entity to not be affected by gravity or water
|
||||
"has_collision": false
|
||||
},
|
||||
"minecraft:custom_hit_test": {
|
||||
"hitboxes": [
|
||||
{
|
||||
"pivot": [0, 100, 0],
|
||||
"width": 0,
|
||||
"height": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"minecraft:damage_sensor": {
|
||||
"triggers": {
|
||||
"deals_damage": false
|
||||
}
|
||||
},
|
||||
"minecraft:pushable": {
|
||||
"is_pushable": false,
|
||||
"is_pushable_by_piston": false
|
||||
},
|
||||
"minecraft:collision_box": {
|
||||
"width": 0.0001,
|
||||
"height": 0.0001
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### Resource Entity
|
||||
|
||||
<CodeHeader>RP/entity/dummy.json</CodeHeader>
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"minecraft:client_entity": {
|
||||
"description": {
|
||||
"identifier": "wiki:dummy",
|
||||
"materials": {
|
||||
"default": "entity_alphatest"
|
||||
},
|
||||
"geometry": {
|
||||
"default": "geometry.dummy"
|
||||
},
|
||||
"render_controllers": ["controller.render.dummy"],
|
||||
"textures": {
|
||||
"default": "textures/entity/dummy"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Geometry
|
||||
|
||||
<CodeHeader>RP/models/entity/dummy.json</CodeHeader>
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": "1.12.0",
|
||||
"minecraft:geometry": [
|
||||
{
|
||||
"description": {
|
||||
"identifier": "geometry.dummy",
|
||||
"texture_width": 16,
|
||||
"texture_height": 16
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Render Controller (Optional)
|
||||
|
||||
<CodeHeader>RP/render_controllers/dummy.json</CodeHeader>
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"render_controllers": {
|
||||
"controller.render.dummy": {
|
||||
"geometry": "Geometry.default",
|
||||
"textures": ["Texture.default"],
|
||||
"materials": [
|
||||
{
|
||||
"*": "Material.default"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Texture (Optional)
|
||||
|
||||
You can either leave the texture location blank, or open the model in blockbench and create a blank texture.
|
||||
570
docs/wiki/3-实体/2-巧思案例/entity-attack.md
Normal file
570
docs/wiki/3-实体/2-巧思案例/entity-attack.md
Normal file
@@ -0,0 +1,570 @@
|
||||
---
|
||||
title: Entity Attacks
|
||||
category: Tutorials
|
||||
mentions:
|
||||
- Luthorius
|
||||
- TheDoctor15
|
||||
- SirLich
|
||||
- MedicalJewel105
|
||||
- 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
|
||||
|
||||
## 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.
|
||||
|
||||
:::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:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"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
|
||||
"entity_types": [
|
||||
{
|
||||
"filters": { //Entities to attack
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
},
|
||||
"max_dist": 48.0
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
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 |
|
||||
|
||||
But there is also one more - `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
|
||||
"minecraft:lookat": {
|
||||
"search_radius": 64.0,
|
||||
"set_target": true, //Becomes a valid target if true
|
||||
"look_cooldown": 5.0,
|
||||
"filters": {
|
||||
"all_of": [
|
||||
{
|
||||
"subject": "other",
|
||||
"test": "is_family",
|
||||
"value": "player"
|
||||
},
|
||||
{
|
||||
"test": "has_equipment",
|
||||
"domain": "head",
|
||||
"subject": "other",
|
||||
"operator": "not",
|
||||
"value": "carved_pumpkin" //All players not with carved_pumpkin equipped on head
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 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>
|
||||
|
||||
```json
|
||||
"entity_types":[
|
||||
{
|
||||
"filters":{
|
||||
"any_of":[
|
||||
{
|
||||
"test":"is_family",
|
||||
"subject":"other",
|
||||
"operator":"==",
|
||||
"value":"snow_golem"
|
||||
},
|
||||
{
|
||||
"test":"is_family",
|
||||
"subject":"other",
|
||||
"operator":"==",
|
||||
"value":"iron_golem"
|
||||
}
|
||||
//anything that is equal to either" snow_golem" or "iron_golem"
|
||||
]
|
||||
},
|
||||
"max_dist":24
|
||||
},
|
||||
{
|
||||
"filters":{
|
||||
"all_of":[
|
||||
{
|
||||
"test":"is_family",
|
||||
"subject":"other",
|
||||
"operator":"==",
|
||||
"value":"player"
|
||||
},
|
||||
{
|
||||
"test":"has_equipment",
|
||||
"subject":"other",
|
||||
"domain":"head",
|
||||
"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 |
|
||||
|
||||
### Melee
|
||||
|
||||
Melee attacks are the most common type of attack, they cause knockback, and have a 100% success rate at accuracy.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"wiki:melee_attack": {
|
||||
"minecraft:attack": {
|
||||
"damage": 3,
|
||||
"effect_name": "slowness",
|
||||
"effect_duration": 20
|
||||
},
|
||||
"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
|
||||
"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": [ 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.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"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
|
||||
},
|
||||
"minecraft:shooter": {
|
||||
"def": "wiki:projectile"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
List of vanilla projectiles:
|
||||
|
||||
| Vanilla Projectiles |
|
||||
| -------------------------------- |
|
||||
| minecraft:arrow |
|
||||
| minecraft:dragon_fireball |
|
||||
| minecraft:egg |
|
||||
| minecraft:ender_pearl |
|
||||
| minecraft:fireball |
|
||||
| minecraft:fishing_hook |
|
||||
| minecraft:lingering_potion |
|
||||
| minecraft:llama_spit |
|
||||
| minecraft:skulker_bullet |
|
||||
| minecraft:small_fireball |
|
||||
| minecraft:snowball |
|
||||
| minecraft:splash_potion |
|
||||
| minecraft:thrown_trident |
|
||||
| minecraft:wither_skull |
|
||||
| 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
|
||||
"minecraft:behavior.charge_held_item": {
|
||||
"priority": 2,
|
||||
"items": [
|
||||
"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.
|
||||
|
||||
### 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
|
||||
"minecraft:area_attack" : {
|
||||
"damage_range": 1, //distance in blocks
|
||||
"damage_per_tick": 2,
|
||||
"cause": "contact",
|
||||
"entity_filter": {
|
||||
"any_of": [
|
||||
{
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
},
|
||||
{
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "monster"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[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`.
|
||||
|
||||
### Knockback Roar
|
||||
|
||||
Many similarities between this and `minecraft:area_attack`, this component though having much more flexibility.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"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":{
|
||||
"test":"is_family",
|
||||
"subject":"other",
|
||||
"operator":"==",
|
||||
"value":"player"
|
||||
},
|
||||
"damage_filters":{
|
||||
"test":"is_family",
|
||||
"subject":"other",
|
||||
"operator":"==",
|
||||
"value":"player"
|
||||
},
|
||||
"on_roar_end":{
|
||||
"event":"wiki:other_event"
|
||||
},
|
||||
"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
|
||||
"easy_attack": {
|
||||
"minecraft:attack": {
|
||||
"damage": 2
|
||||
}
|
||||
},
|
||||
"normal_attack": {
|
||||
"minecraft:attack": {
|
||||
"damage": 2,
|
||||
"effect_name": "poison",
|
||||
"effect_duration": 10
|
||||
}
|
||||
},
|
||||
"hard_attack": {
|
||||
"minecraft:attack": {
|
||||
"damage": 2,
|
||||
"effect_name": "poison",
|
||||
"effect_duration": 18
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
#### Attacks
|
||||
|
||||
Component groups are required to define the different modes of attack, such as:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"wiki:ranged_components": {
|
||||
"minecraft:shooter": {
|
||||
"def": "wiki:projectile"
|
||||
},
|
||||
"minecraft:behavior.ranged_attack": {
|
||||
"priority": 3,
|
||||
"ranged_fov": 90.0,
|
||||
"attack_interval_min": 1.0,
|
||||
"attack_interval_max": 3.0,
|
||||
"attack_radius": 15.0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"wiki:melee_components": {
|
||||
"minecraft:attack": {
|
||||
"damage": 6
|
||||
},
|
||||
"minecraft:behavior.melee_attack": {
|
||||
"priority": 3
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
"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
|
||||
"event": "wiki:melee_swap",
|
||||
"target": "self"
|
||||
},
|
||||
"on_outside_range": { //When target is beyond 5 blocks range, trigger "wiki:ranged_swap" event
|
||||
"event": "wiki:ranged_swap",
|
||||
"target": "self"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- For sensing certain features of the environment of which the mob is exposed to
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"wiki:switcher_environment": {
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": [
|
||||
{
|
||||
"filters": { //When underwater, trigger "wiki:melee_swap" event
|
||||
"test": "is_underwater",
|
||||
"subject": "self",
|
||||
"operator": "==",
|
||||
"value": true
|
||||
},
|
||||
"event": "wiki:melee_swap"
|
||||
},
|
||||
{
|
||||
"filters": { //When not underwater, trigger "wiki:ranged_swap" event
|
||||
"test": "is_underwater",
|
||||
"subject": "self",
|
||||
"operator": "==",
|
||||
"value": false
|
||||
},
|
||||
"event": "wiki:ranged_swap"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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).
|
||||
|
||||
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).
|
||||
76
docs/wiki/3-实体/2-巧思案例/entity-holds-item.md
Normal file
76
docs/wiki/3-实体/2-巧思案例/entity-holds-item.md
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
title: Entity Holds Item
|
||||
category: Tutorials
|
||||
tags:
|
||||
- intermediate
|
||||
mentions:
|
||||
- pieterdefour
|
||||
- SirLich
|
||||
- solvedDev
|
||||
- stirante
|
||||
- Joelant05
|
||||
- destruc7ion
|
||||
- Dreamedc2015
|
||||
- sermah
|
||||
- 7dev7urandom
|
||||
---
|
||||
|
||||
::: tip
|
||||
This tutorial assumes you have a basic understanding of entities, loot tables, and 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.
|
||||
|
||||
## 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.
|
||||
|
||||

|
||||
|
||||
## 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.
|
||||
|
||||
In our example it will look like this:
|
||||
|
||||
<CodeHeader>BP/entity/mandolorian.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"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>
|
||||
|
||||
```json
|
||||
{
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "item",
|
||||
"name": "dd:hammer",
|
||||
"weight": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
If everything went well, you'd have something looking like this:
|
||||
|
||||

|
||||
202
docs/wiki/3-实体/2-巧思案例/entity-movement.md
Normal file
202
docs/wiki/3-实体/2-巧思案例/entity-movement.md
Normal file
@@ -0,0 +1,202 @@
|
||||
---
|
||||
title: Entity Movement
|
||||
category: Tutorials
|
||||
mentions:
|
||||
- SirLich
|
||||
- sermah
|
||||
- MedicalJewel105
|
||||
- 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:
|
||||
|
||||
- [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)
|
||||
|
||||
:::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.
|
||||
:::
|
||||
|
||||
## 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. |
|
||||
|
||||
You should always include `minecraft:movement`. Add the other two as needed.
|
||||
|
||||
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.
|
||||
|
||||
## 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.
|
||||
|
||||
| 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.
|
||||
|
||||
| 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. |
|
||||
|
||||
## 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. |
|
||||
|
||||
There are also components like `minecraft:preferred_path`, which will modify navigation based on block-based path-cost.
|
||||
|
||||
## AI Goals
|
||||
|
||||
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 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).
|
||||
|
||||
### 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.
|
||||
|
||||
#### 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.
|
||||
|
||||
Don't forget to add some basic movement and navigation components so your entity is able to move.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:behavior.nearest_attackable_target": {
|
||||
"priority": 0,
|
||||
"reselect_targets": true,
|
||||
"target_search_height": 1000,
|
||||
"within_radius": 1000,
|
||||
"must_see": false,
|
||||
"entity_types": [
|
||||
{
|
||||
"filters": [
|
||||
{
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "waypoint_1"
|
||||
}
|
||||
],
|
||||
"max_dist": 1000
|
||||
}
|
||||
]
|
||||
},
|
||||
"minecraft:attack": {
|
||||
"damage": 0
|
||||
},
|
||||
"minecraft:behavior.melee_attack": {
|
||||
"priority": 0,
|
||||
"require_complete_path": true,
|
||||
"track_target": true
|
||||
},
|
||||
"minecraft:follow_range": {
|
||||
"value": 1000,
|
||||
"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
|
||||
"minecraft:target_nearby_sensor": {
|
||||
"inside_range": 2.0,
|
||||
"outside_range": 4.0,
|
||||
"must_see": true,
|
||||
"on_inside_range": {
|
||||
"event": "reached_waypoint"
|
||||
},
|
||||
"on_outside_range": {
|
||||
"event": "not_reached_waypoint"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 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.
|
||||
:::
|
||||
359
docs/wiki/3-实体/2-巧思案例/flying-entities.md
Normal file
359
docs/wiki/3-实体/2-巧思案例/flying-entities.md
Normal file
@@ -0,0 +1,359 @@
|
||||
---
|
||||
title: Flying Entities
|
||||
category: Tutorials
|
||||
tags:
|
||||
- recipe
|
||||
- intermediate
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
- Dreamedc2015
|
||||
- MedicalJewel105
|
||||
- aexer0e
|
||||
- imsolucid
|
||||
- nebulacrab
|
||||
- Luthorius
|
||||
- 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
|
||||
|
||||
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": {
|
||||
"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
|
||||
"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).)
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"controller.animation.dragon.flying":{
|
||||
"states":{
|
||||
"default":{
|
||||
"transitions":[
|
||||
{
|
||||
"jumping":"!q.is_on_ground"
|
||||
}
|
||||
]
|
||||
},
|
||||
"jumping":{
|
||||
"transitions":[
|
||||
{
|
||||
"default":"q.is_on_ground"
|
||||
}
|
||||
],
|
||||
"on_entry":[
|
||||
"/effect @s slow_falling 20000 0 true",
|
||||
"/effect @s speed 20000 10 true"
|
||||
],
|
||||
"on_exit":[
|
||||
"/effect @s clear"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
We'll also need to hook it up to our entity as so:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"description":{
|
||||
"identifier":"wiki:dragon",
|
||||
"is_spawnable":true,
|
||||
"is_summonable":true,
|
||||
"is_experimental":false,
|
||||
"scripts":{
|
||||
"animate":[
|
||||
"flying"
|
||||
]
|
||||
},
|
||||
"animations":{
|
||||
"flying":"controller.animation.dragon.flying"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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>
|
||||
|
||||
```
|
||||
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
|
||||
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.**
|
||||
|
||||
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
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
"controller.animation.base": {
|
||||
"initial_state": "default",
|
||||
"states": {
|
||||
"default": {
|
||||
"transitions": [
|
||||
{
|
||||
"base": "(1.0)"
|
||||
}
|
||||
],
|
||||
"on_entry": [
|
||||
"/function dragon_control"
|
||||
]
|
||||
},
|
||||
"base": {
|
||||
"transitions": [
|
||||
{
|
||||
"default": "(1.0)"
|
||||
}
|
||||
],
|
||||
"on_entry": [
|
||||
"/function dragon_control"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
"controller.animation.dragon.flying":{
|
||||
"states":{
|
||||
"default":{
|
||||
"transitions":[
|
||||
{
|
||||
"jumping_1":"!q.is_on_ground"
|
||||
}
|
||||
]
|
||||
},
|
||||
"jumping_1":{
|
||||
"transitions":[
|
||||
{
|
||||
"transition_to_default":"q.is_on_ground"
|
||||
},
|
||||
{
|
||||
"jumping_2":"true"
|
||||
}
|
||||
],
|
||||
"on_entry":[
|
||||
"/effect @s speed 15 10 true"
|
||||
]
|
||||
},
|
||||
"jumping_2":{
|
||||
"transitions":[
|
||||
{
|
||||
"transition_to_default":"q.is_on_ground"
|
||||
},
|
||||
{
|
||||
"jumping_1":"true"
|
||||
}
|
||||
],
|
||||
"on_entry":[
|
||||
"/effect @s speed 15 10 true"
|
||||
]
|
||||
},
|
||||
"transition_to_default":{
|
||||
"transitions":[
|
||||
{
|
||||
"transition_to_default":"true"
|
||||
}
|
||||
],
|
||||
"on_entry":[
|
||||
"/effect @s clear"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
_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
|
||||
"controller.animation.dragon.test_rider":{
|
||||
"states":{
|
||||
"default":{
|
||||
"transitions":[
|
||||
{
|
||||
"has_rider":"q.has_rider"
|
||||
}
|
||||
]
|
||||
},
|
||||
"has_rider":{
|
||||
"transitions":[
|
||||
{
|
||||
"default":"!q.has_rider"
|
||||
}
|
||||
],
|
||||
"on_entry":[
|
||||
"/tag @s add has_rider"
|
||||
],
|
||||
"on_exit":[
|
||||
"/tag @s remove has_rider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```
|
||||
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
|
||||
execute @a[rxm=-5,rx=20] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 1 true
|
||||
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
|
||||
"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
|
||||
"controller.animation.fly_dragon":{
|
||||
"initial_state":"falling",
|
||||
"states":{
|
||||
"falling":{
|
||||
"on_entry":[
|
||||
"/effect @e[type=wiki:dragon,r=1,c=1] levitation 0"
|
||||
],
|
||||
"transitions":[
|
||||
{
|
||||
"rising":"q.is_jumping"
|
||||
}
|
||||
]
|
||||
},
|
||||
"rising":{
|
||||
"on_entry":[
|
||||
"/effect @e[type=wiki:dragon,r=1,c=1] levitation 100000 6 true"
|
||||
],
|
||||
"transitions":[
|
||||
{
|
||||
"falling":"!q.is_jumping"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"description":{
|
||||
"identifier":"minecraft:player",
|
||||
"is_spawnable":false,
|
||||
"is_summonable":false,
|
||||
"animations":{
|
||||
"fly_dragon":"controller.animation.fly_dragon"
|
||||
},
|
||||
"scripts":{
|
||||
"animate":[
|
||||
{
|
||||
"fly_dragon":"q.is_riding"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
"controller.animation.reset_levitation":{
|
||||
"initial_state":"no_rider",
|
||||
"states":{
|
||||
"no_rider":{
|
||||
"transitions":[
|
||||
{
|
||||
"has_rider":"q.has_rider"
|
||||
}
|
||||
]
|
||||
},
|
||||
"has_rider":{
|
||||
"on_exit":[
|
||||
"/effect @s levitation 0"
|
||||
],
|
||||
"transitions":[
|
||||
{
|
||||
"no_rider":"!q.has_rider"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
78
docs/wiki/3-实体/2-巧思案例/introduction-to-aec.md
Normal file
78
docs/wiki/3-实体/2-巧思案例/introduction-to-aec.md
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: Introduction to AOE Clouds
|
||||
category: Tutorials
|
||||
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.
|
||||
|
||||
## Overview
|
||||
|
||||
Area-of-effect clouds have several special features we can take advantage of:
|
||||
|
||||
- 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.
|
||||
|
||||
[Projectiles Documentation](/documentation/projectiles#spawn-aoe-cloud)
|
||||
|
||||
## Method 2: NBT Editing
|
||||
|
||||
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.
|
||||
|
||||
### NBT Editors
|
||||
|
||||
One of the following NBT editors are recommended:
|
||||
|
||||
- [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)
|
||||
|
||||
### Structure file
|
||||
|
||||
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.
|
||||
|
||||
<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)
|
||||
|
||||
### NBT Format
|
||||
|
||||
| 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. |
|
||||
|
||||
Below are the parameters for the `mobEffects` tag.
|
||||
|
||||
| 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. |
|
||||
67
docs/wiki/3-实体/2-巧思案例/invulnerable-entities.md
Normal file
67
docs/wiki/3-实体/2-巧思案例/invulnerable-entities.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
title: Invulnerable Entities
|
||||
category: Tutorials
|
||||
tags:
|
||||
- beginner
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
- solvedDev
|
||||
- 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.
|
||||
|
||||
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
|
||||
|
||||
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:damage_sensor": {
|
||||
"triggers": {
|
||||
"cause": "all",
|
||||
"deals_damage": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Disable Damage from Player
|
||||
|
||||
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:damage_sensor": {
|
||||
"triggers": {
|
||||
"on_damage": {
|
||||
"filters": {
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
}
|
||||
},
|
||||
"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.
|
||||
|
||||
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`.
|
||||
|
||||
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:health": {
|
||||
"value": 1,
|
||||
"max": 1,
|
||||
"min": 1
|
||||
}
|
||||
```
|
||||
|
||||
Note that setting it to 0 breaks some death and spawn animations/effects.
|
||||
44
docs/wiki/3-实体/2-巧思案例/look-at-entity.md
Normal file
44
docs/wiki/3-实体/2-巧思案例/look-at-entity.md
Normal file
@@ -0,0 +1,44 @@
|
||||
---
|
||||
title: Look at Entity
|
||||
category: Tutorials
|
||||
tags:
|
||||
- intermediate
|
||||
mentions:
|
||||
- shanewolf38
|
||||
- MedicalJewel105
|
||||
- TheItsNameless
|
||||
- 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
|
||||
|
||||
<CodeHeader>RP/entity/mob.entity.json</CodeHeader>
|
||||
|
||||
```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.
|
||||
:::
|
||||
|
||||
<CodeHeader>RP/entity/mob.entity.json</CodeHeader>
|
||||
|
||||
```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
|
||||
|
||||
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.
|
||||
|
||||
## 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.
|
||||
396
docs/wiki/3-实体/2-巧思案例/sleeping-entities.md
Normal file
396
docs/wiki/3-实体/2-巧思案例/sleeping-entities.md
Normal file
@@ -0,0 +1,396 @@
|
||||
---
|
||||
title: Sleeping Entities
|
||||
category: Tutorials
|
||||
tags:
|
||||
- intermediate
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
- SirLich
|
||||
---
|
||||
|
||||
This tutorial will explain how to make entity sleep.
|
||||
|
||||
## Sleeping in beds
|
||||
|
||||
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
|
||||
"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
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": [
|
||||
{
|
||||
"filters": {
|
||||
"test": "is_daytime",
|
||||
"value": false
|
||||
},
|
||||
"event": "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
|
||||
|
||||
Now you need some component groups for your entity with some components.
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#component_groups</CodeHeader>
|
||||
|
||||
```json
|
||||
"sleeping": {
|
||||
"minecraft:behavior.sleep": {
|
||||
"priority": 0,
|
||||
"goal_radius": 1.5,
|
||||
"speed_multiplier": 1.25,
|
||||
"sleep_collider_height": 0.3,
|
||||
"sleep_collider_width": 1,
|
||||
"sleep_y_offset": 0.6,
|
||||
"timeout_cooldown": 10
|
||||
},
|
||||
"minecraft:damage_sensor": {
|
||||
"triggers": {
|
||||
"on_damage": {
|
||||
"event": "wake_up"
|
||||
}
|
||||
}
|
||||
},
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": [
|
||||
{
|
||||
"filters": {
|
||||
"test": "is_daytime",
|
||||
"value": true
|
||||
},
|
||||
"event": "wake_up"
|
||||
}
|
||||
]
|
||||
},
|
||||
"minecraft:interact": {
|
||||
"interactions": [
|
||||
{
|
||||
"on_interact": {
|
||||
"filters": {
|
||||
"all_of": [
|
||||
{
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"value": "player"
|
||||
}
|
||||
]
|
||||
},
|
||||
"event": "woken_up"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `minecraft:behavior.sleep`
|
||||
|
||||
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:environment_sensor`
|
||||
|
||||
Runs `wake_up` event when it is day time.
|
||||
|
||||
- `minecraft:interact`
|
||||
|
||||
This makes player to be able wake up entity without hurting it.
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#component_groups</CodeHeader>
|
||||
|
||||
```json
|
||||
"sleep_timer": {
|
||||
"minecraft:timer": {
|
||||
"time": 15,
|
||||
"time_down_event": {
|
||||
"event": "sleep_again"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
"sleep": {
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"sleeping"
|
||||
]
|
||||
}
|
||||
},
|
||||
"wake_up": {
|
||||
"remove": {
|
||||
"component_groups": [
|
||||
"sleeping"
|
||||
]
|
||||
}
|
||||
},
|
||||
"woken_up": {
|
||||
"remove": {
|
||||
"component_groups": [
|
||||
"sleeping"
|
||||
]
|
||||
},
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"sleep_timer"
|
||||
]
|
||||
}
|
||||
},
|
||||
"sleep_again": {
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"sleeping"
|
||||
]
|
||||
},
|
||||
"remove": {
|
||||
"component_groups": [
|
||||
"sleep_timer"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 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
|
||||
{
|
||||
"format_version": "1.8.0",
|
||||
"animations": {
|
||||
"animation.sleeping_entity.sleep": {
|
||||
"loop": "hold_on_last_frame",
|
||||
"animation_length": 0.5,
|
||||
"bones": {
|
||||
"body": {
|
||||
"rotation": {
|
||||
"0.0": [0, 0, 0],
|
||||
"0.5": [-90, 0, 0]
|
||||
},
|
||||
"position": [0, 2, -15]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Animation Controller
|
||||
|
||||
Again just copy/paste it if you need.
|
||||
|
||||
<CodeHeader>RP/animations_controllers/ac.sleeping_entity.sleep.json</CodeHeader>
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
"controller.animation.sleeping_entity.sleep": {
|
||||
"initial_state": "default",
|
||||
"states": {
|
||||
"default": {
|
||||
"transitions": [
|
||||
{
|
||||
"sleep": "q.is_sleeping"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sleep": {
|
||||
"animations": ["sleeping"],
|
||||
"transitions": [
|
||||
{
|
||||
"default": "!q.is_sleeping"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Note that you will need to define animation in client entity like this:
|
||||
|
||||
`"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.
|
||||
|
||||
### 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
|
||||
"minecraft:behavior.nap": {
|
||||
"priority": 8,
|
||||
"cooldown_min": 2.0,
|
||||
"cooldown_max": 7.0,
|
||||
"mob_detect_dist": 12.0,
|
||||
"mob_detect_height": 6.0,
|
||||
"can_nap_filters": {
|
||||
"all_of": [
|
||||
{
|
||||
"test": "in_water",
|
||||
"subject": "self",
|
||||
"operator": "==",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"test": "on_ground",
|
||||
"subject": "self",
|
||||
"operator": "==",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"test": "is_underground",
|
||||
"subject": "self",
|
||||
"operator": "==",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"test": "weather_at_position",
|
||||
"subject": "self",
|
||||
"operator": "!=",
|
||||
"value": "thunderstorm"
|
||||
}
|
||||
]
|
||||
},
|
||||
"wake_mob_exceptions": {
|
||||
"any_of": [
|
||||
{
|
||||
"test": "trusts",
|
||||
"subject": "other",
|
||||
"operator": "==",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"test": "is_family",
|
||||
"subject": "other",
|
||||
"operator": "==",
|
||||
"value": "sleeping_entity"
|
||||
},
|
||||
{
|
||||
"test": "is_sneaking",
|
||||
"subject": "other",
|
||||
"operator": "==",
|
||||
"value": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If you want to also use the trusting mechanic, add:
|
||||
|
||||
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
|
||||
|
||||
```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
|
||||
{
|
||||
"format_version": "1.10.0",
|
||||
"animation_controllers": {
|
||||
"controller.animation.sleeping_entity.sleep": {
|
||||
"initial_state": "default",
|
||||
"states": {
|
||||
"default": {
|
||||
"transitions": [
|
||||
{
|
||||
"sleep": "q.is_sleeping"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sleep": {
|
||||
"animations": ["sleeping"],
|
||||
"transitions": [
|
||||
{
|
||||
"default": "!q.is_sleeping"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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).
|
||||
90
docs/wiki/3-实体/2-巧思案例/solid-entities.md
Normal file
90
docs/wiki/3-实体/2-巧思案例/solid-entities.md
Normal file
@@ -0,0 +1,90 @@
|
||||
---
|
||||
title: Solid Entities
|
||||
category: Tutorials
|
||||
tags:
|
||||
- recipe
|
||||
- intermediate
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
- Chikorita-Lover
|
||||
- Luthorius
|
||||
- MedicalJewel105
|
||||
- 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.
|
||||
|
||||
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>
|
||||
|
||||
```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
|
||||
{
|
||||
"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.
|
||||
|
||||
## 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": {}`
|
||||
|
||||
You will also need to add `minecraft:push_through` and set its `value` parameter to 1.
|
||||
|
||||
`"minecraft:push_through": 1`
|
||||
|
||||
(they should both go in `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.
|
||||
|
||||
`/fill ~ ~ ~ ~ ~1 ~ barrier 0 replace air`
|
||||
Places barriers in a 1x1x2 area.
|
||||
|
||||
`/fill ~1 ~1 ~1 ~-1 ~-1 ~-1 air 0 replace barrier`
|
||||
Removes barriers within a 3x3x3 area.
|
||||
|
||||
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.
|
||||
320
docs/wiki/3-实体/2-巧思案例/timers.md
Normal file
320
docs/wiki/3-实体/2-巧思案例/timers.md
Normal file
@@ -0,0 +1,320 @@
|
||||
---
|
||||
title: Entity Timers
|
||||
category: Tutorials
|
||||
tags:
|
||||
- intermediate
|
||||
mentions:
|
||||
- SirLich
|
||||
- Joelant05
|
||||
- MedicalJewel105
|
||||
- aexer0e
|
||||
- Justash01
|
||||
- TheItsNameless
|
||||
- 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
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
In the vanilla Behavior Pack, this component is used in all kinds of circumstances. For example:
|
||||
|
||||
- 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
|
||||
|
||||
A simple example which triggers an event after 5.6 seconds:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:timer": {
|
||||
"time": 5.6,
|
||||
"time_down_event": {
|
||||
"event": "wiki:my_event"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
A more complex example which triggers an event after a randomized amount of delay using weighted values:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:timer": {
|
||||
"looping": false, //true will fires event after every execution, false will fire event only once.
|
||||
"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
|
||||
}
|
||||
],
|
||||
"time_down_event": {
|
||||
"event": "wiki:event",
|
||||
"target": "self"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"wiki:do_event": {
|
||||
"randomize": [
|
||||
{
|
||||
"weight": 1,
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"wiki:my_event"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"weight": 5,
|
||||
"add": {
|
||||
"component_groups": [
|
||||
"wiki:my_more_frequent_event"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"weight": 50 //Fires nothing
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
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):
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:environment_sensor": {
|
||||
"triggers": [
|
||||
{
|
||||
"filters": {
|
||||
"test": "hourly_clock_time",
|
||||
"operator": "=",
|
||||
"value": 800
|
||||
},
|
||||
"event": "wiki:my_daily_event"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
Here is an example which fires an event after four seconds:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:is_baby": {},
|
||||
"minecraft:ageable": {
|
||||
"duration": 4,
|
||||
"grow_up": {
|
||||
"event": "wiki:my_other_event",
|
||||
"target": "self"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 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".
|
||||
|
||||
Non-exhaustive list of promising examples:
|
||||
|
||||
- `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).
|
||||
|
||||
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
|
||||
{
|
||||
"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"
|
||||
},
|
||||
"animation_length": 3.1
|
||||
},
|
||||
"animation.command.example_timeline_2": {
|
||||
"timeline": {
|
||||
"100": "/say this will trigger after 100 seconds",
|
||||
"0.0": [
|
||||
"/say you can trigger multiple events at once",
|
||||
"/say by using timelines."
|
||||
],
|
||||
"55.55": "/say this will trigger after 55.55 seconds."
|
||||
},
|
||||
"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.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"controller.animation.shanewolf.random_interval": {
|
||||
"initial_state": "inactive",
|
||||
"states": {
|
||||
"inactive": {
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"on_exit": [
|
||||
"@s wiki:stop_random_interval",
|
||||
"/say random interval finished"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```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.
|
||||
|
||||
**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
|
||||
|
||||
### 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.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"controller.animation.shanewolf.random_choices": {
|
||||
"initial_state": "inactive",
|
||||
"states": {
|
||||
"inactive": {
|
||||
"transitions": [
|
||||
{
|
||||
"active": "q.is_powered"
|
||||
}
|
||||
]
|
||||
},
|
||||
"active": {
|
||||
"on_entry": [
|
||||
"v.random_choices = math.random(0, 100);",
|
||||
"/say random interval started"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
],
|
||||
"on_exit": [
|
||||
"@s wiki:stop_random_choices",
|
||||
"/say random choices finished"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```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)!
|
||||
357
docs/wiki/3-实体/2-巧思案例/village-mechanic.md
Normal file
357
docs/wiki/3-实体/2-巧思案例/village-mechanic.md
Normal file
@@ -0,0 +1,357 @@
|
||||
---
|
||||
title: Village Mechanic
|
||||
category: Tutorials
|
||||
mentions:
|
||||
- AeroForta
|
||||
- MedicalJewel105
|
||||
- stirante
|
||||
- SmokeyStack
|
||||
- SirLich
|
||||
- Ciosciaa
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
This article is for anyone who wants to try imitate the village mechanic for their entities
|
||||
|
||||
## Navigation Behavior
|
||||
|
||||
First let's start with some basic navigation behavior.
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:preferred_path":{
|
||||
"max_fall_blocks":1,
|
||||
"jump_cost":5,
|
||||
"default_block_cost":1.5,
|
||||
"preferred_path_blocks":[
|
||||
{
|
||||
"cost":0,
|
||||
"blocks":[
|
||||
"grass_path"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cost":1,
|
||||
"blocks":[
|
||||
"cobblestone",
|
||||
"stone"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cost":50,
|
||||
"blocks":[
|
||||
"bed",
|
||||
"lectern"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Allows entity to do random walk.
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:behavior.random_stroll":{
|
||||
"priority":9,
|
||||
"speed_multiplier":0.55,
|
||||
"xz_dist":10,
|
||||
"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.
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"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
|
||||
"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
|
||||
"minecraft:behavior.move_indoors":{
|
||||
"priority":5
|
||||
}
|
||||
```
|
||||
|
||||
Makes entity stay indoors while sun is down.
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:behavior.restrict_open_door":{
|
||||
"priority": 5
|
||||
}
|
||||
```
|
||||
|
||||
Use in pair with:
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:annotation.open_door":{
|
||||
"priority": 5
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:navigation.walk":{
|
||||
"can_pass_doors":true,
|
||||
"can_open_doors":true
|
||||
}
|
||||
```
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:behavior.open_door":{
|
||||
"priority":6,
|
||||
"close_door_after":true
|
||||
}
|
||||
```
|
||||
|
||||
## Main Behavior
|
||||
|
||||
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:dweller": {
|
||||
"dwelling_type": "village",
|
||||
"dweller_role": "inhabitant",
|
||||
"preferred_profession": "farmer",
|
||||
"update_interval_base": 60,
|
||||
"update_interval_variant": 40,
|
||||
"can_find_poi": true,
|
||||
"can_migrate": true,
|
||||
"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:
|
||||
|
||||
```
|
||||
bed
|
||||
jobsite
|
||||
meeting_area
|
||||
```
|
||||
|
||||
- `can_migrate`
|
||||
Defines if entity can migrate from one village to another or not.
|
||||
|
||||
### Sleep
|
||||
|
||||
You can find out how to make your entity sleep [here](/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.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:behavior.work": {
|
||||
"priority": 4,
|
||||
"active_time": 250,
|
||||
"speed_multiplier": 0.5,
|
||||
"goal_cooldown": 200,
|
||||
"sound_delay_min": 100,
|
||||
"sound_delay_max": 200,
|
||||
"can_work_in_rain": false,
|
||||
"work_in_rain_tolerance": 1000,
|
||||
"on_arrival": {
|
||||
"event": "minecraft:resupply_trades",
|
||||
"target": "self"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Gathering
|
||||
|
||||
Allows the entity to gather.
|
||||
Requires "dweller_role" set to be "inhabitant".
|
||||
|
||||
```json
|
||||
"minecraft:behavior.mingle": {
|
||||
"priority": 4,
|
||||
"speed_multiplier": 0.5,
|
||||
"duration": 30,
|
||||
"cooldown_time": 10,
|
||||
"mingle_partner_type": "my:custom_entity",
|
||||
"mingle_distance": 2.0
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### 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
|
||||
"component_groups":{
|
||||
"work_schedule":{
|
||||
"minecraft:behavior.work":{
|
||||
"priority":4,
|
||||
"active_time":250,
|
||||
"speed_multiplier":0.5,
|
||||
"goal_cooldown":200,
|
||||
"sound_delay_min":100,
|
||||
"sound_delay_max":200,
|
||||
"can_work_in_rain":true,
|
||||
"work_in_rain_tolerance":1000,
|
||||
"on_arrival":{
|
||||
"event":"minecraft:resupply_trades",
|
||||
"target":"self"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gather_schedule":{
|
||||
"minecraft:behavior.mingle":{
|
||||
"priority": 5,
|
||||
"speed_multiplier": 0.8,
|
||||
"cooldown_time":10.0,
|
||||
"duration": 30.0,
|
||||
"mingle_dist": 1.5,
|
||||
"mingle_partner_type": "my:custom_entity"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Next, make your entity work.
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"minecraft:scheduler":{
|
||||
"min_delay_secs":0,
|
||||
"max_delay_secs":10,
|
||||
"scheduled_events":[
|
||||
{
|
||||
"filters":{
|
||||
"all_of":[
|
||||
{
|
||||
"test":"hourly_clock_time",
|
||||
"operator":">=",
|
||||
"value":0 //Morning
|
||||
},
|
||||
{
|
||||
"test":"hourly_clock_time",
|
||||
"operator":"<",
|
||||
"value":12000 //Evening
|
||||
}
|
||||
]
|
||||
},
|
||||
"event":"work"
|
||||
},
|
||||
{
|
||||
"filters":{
|
||||
"all_of":[
|
||||
{
|
||||
"test":"hourly_clock_time",
|
||||
"operator":">=",
|
||||
"value":21000
|
||||
},
|
||||
{
|
||||
"test":"hourly_clock_time",
|
||||
"operator":"<",
|
||||
"value":24000
|
||||
}
|
||||
]
|
||||
},
|
||||
"event":"gather"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
The events section looks something like this:
|
||||
|
||||
<CodeHeader></CodeHeader>
|
||||
|
||||
```json
|
||||
"events":{
|
||||
"work":{
|
||||
"remove":{
|
||||
"component_groups":[
|
||||
"gather_schedule"
|
||||
]
|
||||
},
|
||||
"add":{
|
||||
"component_groups":[
|
||||
"work_schedule"
|
||||
]
|
||||
}
|
||||
},
|
||||
"gather":{
|
||||
"remove":{
|
||||
"component_groups":[
|
||||
"work_schedule"
|
||||
]
|
||||
},
|
||||
"add":{
|
||||
"component_groups":[
|
||||
"gather_schedule"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
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. |
|
||||
80
docs/wiki/3-实体/3-文档/dummy-components.md
Normal file
80
docs/wiki/3-实体/3-文档/dummy-components.md
Normal file
@@ -0,0 +1,80 @@
|
||||
---
|
||||
title: 虚拟组件
|
||||
category: 文档
|
||||
mentions:
|
||||
- SirLich
|
||||
- jigarbov
|
||||
- MedicalJewel105
|
||||
- StealthyExpertX
|
||||
- TheItsNameless
|
||||
---
|
||||
|
||||
# 虚拟组件
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
:::warning 弃用警告
|
||||
|
||||
'虚拟组件'是一个旧版概念,现已被[实体属性](https://learn.microsoft.com/en-us/minecraft/creator/documents/introductiontoentityproperties)取代。建议尽可能使用实体属性代替。
|
||||
:::
|
||||
|
||||
虚拟组件是仅用于数据存储的"无功能"组件。它们本身**不会**产生任何实际效果,需要配合其他机制才能发挥作用。这类组件的主要价值在于可将数据存储在实体上,并通过Molang查询来驱动图形/游戏机制。
|
||||
|
||||
典型案例包括 `variant`(变种)和 `mark_variant`(标记变种)。这些组件接受整数值设置,在原版资源包中用于定义猫和马匹的贴图选择。另一个典型案例是 `is_tamed`(驯服状态),用于控制马匹能否被骑乘。
|
||||
|
||||
虚拟组件的优势在于能够将数据与实体绑定,并通过Molang查询调用这些信息。
|
||||
|
||||
## 整型虚拟组件
|
||||
|
||||
整型组件存储整数值(例如1、10、1423),可使用Molang查询进行读取,是最常用的虚拟组件类型。
|
||||
|
||||
## 布尔型虚拟组件
|
||||
|
||||
布尔型组件存储单一状态信息,包括 `True`(真)和 `False`(假)。以 `is_tamed` 为例,组件存在表示为 `True`(已驯服),不存在则为 `False`(未驯服)。
|
||||
|
||||
## 组件列表
|
||||
|
||||
| 类型 | 查询语句 | 组件名称 | 备注 |
|
||||
| --------- | ------------------------------------------------------------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| **整型** | q.variant | minecraft:variant | |
|
||||
| **整型** | q.mark_variant | minecraft:mark_variant | |
|
||||
| **整型** | q.skin_id | minecraft:skin_id | |
|
||||
| **整型\*** | 使用类似 `"test": "is_color"` 的过滤器,下方提供颜色列表 | minecraft:color | 同时在材质系统中设置颜色 |
|
||||
| **整型\*** | 无对应过滤器语法,可使用 `"has_component"` | minecraft:color2 | 同时在材质系统中设置颜色 |
|
||||
| 布尔型 | q.is_illager_captain | minecraft:is_illager_captain | |
|
||||
| 布尔型 | q.is_baby | minecraft:is_baby | 禁用`minecraft:breedable`组件功能 |
|
||||
| 布尔型 | q.is_sheared | minecraft:is_sheared | |
|
||||
| 布尔型 | q.is_saddled | minecraft:is_saddled | |
|
||||
| 布尔型 | q.is_tamed | minecraft:is_tamed | |
|
||||
| 布尔型 | q.is_chested | minecraft:is_chested | 死亡时会掉落储存箱 |
|
||||
| 布尔型 | q.is_powered | minecraft:is_charged | |
|
||||
| 布尔型 | q.is_stunned | minecraft:is_stunned | |
|
||||
| 布尔型 | q.can_climb | minecraft:can_climb | 允许实体攀爬梯子 |
|
||||
| 布尔型 | q.can_fly | minecraft:can_fly | 标记实体具有飞行能力,路径查找器将不限于下方有固体方块的位置 |
|
||||
| 布尔型 | q.can_power_jump | minecraft:can_power_jump | 允许实体执行强力跳跃(如原版马匹动作) |
|
||||
| 布尔型 | q.is_ignited | minecraft:is_ignited | |
|
||||
| 布尔型 | q.out_of_control | minecraft:out_of_control | 新版功能,用于处理船体硬编码运动/粒子效果,Molang q查询可安全 |
|
||||
| 布尔型 | q.has_any_family('monster') | minecraft:type_family | 可检测指定Family类型(如'monster')返回布尔值
|
||||
|
||||
### color与color2组件颜色对照表
|
||||
|
||||
::: code-group
|
||||
```json [颜色代码]
|
||||
- black
|
||||
- blue
|
||||
- brown
|
||||
- cyan
|
||||
- gray
|
||||
- green
|
||||
- light_blue
|
||||
- light_green
|
||||
- magenta
|
||||
- orange
|
||||
- pink
|
||||
- purple
|
||||
- red
|
||||
- silver
|
||||
- white
|
||||
- yellow
|
||||
```
|
||||
:::
|
||||
140
docs/wiki/3-实体/3-文档/non-mob-runtime-identifiers.md
Normal file
140
docs/wiki/3-实体/3-文档/non-mob-runtime-identifiers.md
Normal file
@@ -0,0 +1,140 @@
|
||||
---
|
||||
title: 非生物运行时标识符
|
||||
category: 文档
|
||||
mentions:
|
||||
- Ciosciaa
|
||||
- SmokeyStack
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
# 非生物运行时标识符
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
_最后更新于1.19.10 版本_
|
||||
|
||||
非生物实体是用于游戏机制或实用功能的不常规实体。典型示例包括抛射物、运输类实体以及模拟方块的实体。这些运行时标识符的属性与普通生物实体有根本性不同,其特殊属性在某些场景下可能具有实用价值。
|
||||
|
||||
## 总览
|
||||
### 服务端属性
|
||||
| 属性 | 已注册 | 可配置行为 | 可配置碰撞箱 | 可配置方块碰撞 | 可配置重力 | 可配置实体推动性 | 可配置活塞推动性 | 支持传送门 | 生命值类型 | 可受伤害 | 可燃性 | 可击退 | 受效果影响 | 可选择 | 可挂钩 | 可锁定 | 可作为抛射体 | 可沿轨道移动 | 自动骑乘 | 可配置战利品 | 生成行为 |
|
||||
|------------------------------------------------------------|--------|------------|--------------|----------------|------------|------------------|------------------|------------|-------------------|----------|--------|--------|------------|--------|--------|--------|--------------|--------------|----------|--------------|----------------|
|
||||
| `minecraft:arrow` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:thrown_trident` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:snowball` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 抛射物 |
|
||||
| `minecraft:egg` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 抛射物 |
|
||||
| `minecraft:splash_potion` & `minecraft:lingering_potion` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 抛射物 |
|
||||
| `minecraft:ice_bomb` | ⚠️ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 抛射物 |
|
||||
| `minecraft:llama_spit` | ✅ | ❌ | ⚠️ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ⚠️ | ⚠️ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:fireball` | ✅ | ❌ | ⚠️ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ⚠️ | ⚠️ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:small_fireball` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:shulker_bullet` | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ❌ | ❌ | ❌ | ⚠️ | ⚠️ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:dragon_fireball` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:wither_skull` & `minecraft:wither_skull_dangerous` | ✅ | ❌ | ⚠️ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ❌ | ❌ | ❌ | ⚠️ | ⚠️ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:ender_pearl` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 抛射物 |
|
||||
| `minecraft:fishing_hook` | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | 🐛 | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:xp_bottle` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 抛射物 |
|
||||
| `minecraft:boat` & `minecraft:chest_boat` | ✅ | ❌ | ✅ | ✅ | ⚠️ | ✅ | ❌ | ✅ | 结构完整性 | ✅ | ✅ | ❌ | ❌ | ✅ | ⚠️ | ❌ | ✅ | ⚠️ | ❌ | ⚠️ | 目标表面 |
|
||||
| `minecraft:minecart` & 变种 | ✅ | ❌ | ✅ | ❌ | ⚠️ | ❌ | ✅ | ✅ | 结构完整性 | ✅ | ✅ | ❌ | ❌ | ✅ | ⚠️ | ❌ | ⚠️ | ✅ | ❌ | ⚠️ | 轨道 |
|
||||
| `minecraft:balloon` | ⚠️ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:tnt` | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ⚠️ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:armor_stand` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 结构完整性 | ⚠️ | ✅ | ❌ | ✅ | ✅ | ✅ | ⚠️ | ✅ | ⚠️ | ✅ | ⚠️ | 目标表面 |
|
||||
| `minecraft:painting` | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ⚠️ | 无 | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | 目标表面 |
|
||||
| `minecraft:falling_block` | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | 无 | ⚠️ | ✅ | ❌ | ❌ | ⚠️ | ⚠️ | ❌ | 🐛 | ❌ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:ender_crystal` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ⚠️ | ⚠️ | ❌ | ⚠️ | ❌ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:leash_knot` | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ⚠️ | 无 | ✅ | ❌ | ❌ | ❌ | ⚠️ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | 轨道 |
|
||||
| `minecraft:chalkboard` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 生命值 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | ✅ | ✅ | 目标表面 |
|
||||
| `minecraft:tripod_camera` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 生命值 | ❌ | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ⚠️ | ✅ | ✅ | 目标表面 |
|
||||
| `minecraft:area_effect_cloud` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❓ | ❌ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:lightning_bolt` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ❌ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:evocation_fang` | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ❌ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:item` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | 物品 | ❌ | ⚠️ | ❌ | ❌ | ❌ | ❌ | ❌ | ❓ | ⚠️ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:xp_orb` | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ❌ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:fireworks_rocket` | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ⚠️ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:eye_of_ender_signal` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | 无 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ⚠️ | ✅ | ❌ | ✅ | 目标表面 |
|
||||
| `minecraft:elder_guardian_ghost` | ✅ | ⚠️ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 生命值 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 目标表面 |
|
||||
| `minecraft:npc` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 生命值 | ❌ | ✅ | ⚠️ | ❌ | ✅ | ❌ | ✅ | ✅ | ⚠️ | ❌ | ❌ | 目标表面 |
|
||||
| `minecraft:agent` | ❌ | ❌ | ⚠️ | ❌ | ❌ | ❌ | ✅ | ✅ | 生命值 | ✅ | ✅ | ❌ | ❌ | ⚠️ | ⚠️ | ✅ | ❌ | ✅ | ❌ | ⚠️ | 目标表面 |
|
||||
| `minecraft:shield` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 生命值 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚠️ | ✅ | ✅ | 目标表面 |
|
||||
|
||||
### 客户端属性
|
||||
| 属性 | 客户端实体 | 位置更新 | 插值移动 | 面向方向 | 阴影 | 死亡效果 | 踏步音效 |
|
||||
|------------------------------------------------------------|------------|----------|----------|----------|------|----------|----------|
|
||||
| `minecraft:arrow` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:thrown_trident` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
||||
| `minecraft:snowball` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:egg` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:splash_potion` & `minecraft:lingering_potion` | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:ice_bomb` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:llama_spit` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
||||
| `minecraft:fireball` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:small_fireball` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:shulker_bullet` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
||||
| `minecraft:dragon_fireball` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:wither_skull` & `minecraft:wither_skull_dangerous` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:ender_pearl` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:fishing_hook` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
||||
| `minecraft:xp_bottle` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:boat` & `minecraft:chest_boat` | ✅ | ✅ | ❌ | ❌ | ⚠️ | ❌ | ❌ |
|
||||
| `minecraft:minecart` & 变种 | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:balloon` | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ |
|
||||
| `minecraft:tnt` | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:armor_stand` | ✅ | ✅ | ✅ | ✅ | ❌ | ⚠️ | ✅ |
|
||||
| `minecraft:painting` | ❌ | ✅ | ❓ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:falling_block` | ⚠️ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:ender_crystal` | ✅ | ❌ | ❌ | ❌ | ⚠️ | ❌ | ❌ |
|
||||
| `minecraft:leash_knot` | ✅ | ✅ | ❓ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:chalkboard` | ✅ | ✅ | ✅ | ⚠️ | ✅ | ✅ | ✅ |
|
||||
| `minecraft:tripod_camera` | ✅ | ✅ | ✅ | ✅ | ⚠️ | ✅ | ✅ |
|
||||
| `minecraft:area_effect_cloud` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:lightning_bolt` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:evocation_fang` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:item` | ❌ | ✅ | ✅ | ❌ | ⚠️ | ❌ | ❌ |
|
||||
| `minecraft:xp_orb` | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:fireworks_rocket` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
||||
| `minecraft:eye_of_ender_signal` | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
|
||||
| `minecraft:elder_guardian_ghost` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
|
||||
| `minecraft:npc` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| `minecraft:agent` | ⚠️ | ✅ | ❓ | ⚠️ | ⚠️ | ✅ | ✅ |
|
||||
| `minecraft:shield` | ✅ | ✅ | ✅ | ⚠️ | ✅ | ✅ | ✅ |
|
||||
|
||||
## 属性定义与章节说明
|
||||
本文档中使用的属性定义用于描述特定运行时标识符实体的行为特征。每个属性配有一个值及可能的附加说明,用以强调关联定义的异常情况。
|
||||
|
||||
大多数属性使用表情符号简短表达:
|
||||
| 值 | 说明 |
|
||||
|:---:|-------------------------------------------------------------------------|
|
||||
| ✅ | **激活/可用**<br>该属性在当前运行时标识符实体上通常处于活跃或可用状态。附加说明为特殊情况提供说明。 |
|
||||
| ⚠️ | **需警告**<br>该属性在特定条件下可用。标有此符号的属性可能需要特别处理。附加说明会细化具体例外情况。 |
|
||||
| ❌ | **未激活/不可用**<br>该属性在当前运行时标识符实体上不可用。附加说明会阐述实体如何处理该属性。 |
|
||||
| ❓ | **未知**<br>该属性的具体行为在当前上下文中尚未明确。 |
|
||||
| 🐛 | **存在漏洞**<br>该属性激活时会导致崩溃或其他错误。附加说明会具体描述漏洞触发条件。 |
|
||||
|
||||
### NBT扩展字段
|
||||
此部分列出该运行时标识符实体专用的NBT字段(其他实体不使用),字段用途通常在本体注释中说明。
|
||||
|
||||
### 特殊查询
|
||||
若Molang查询在当前运行时标识符上有特殊行为,则会在此说明。所有查询在服务端和客户端均可使用。
|
||||
|
||||
### 硬编码变量
|
||||
本节列出该运行时标识符绑定的硬编码Molang变量(若无声明则为未定义)。所有这些变量服务端和客户端均可使用。
|
||||
|
||||
### 特效
|
||||
本节描述与实体绑定的硬编码粒子或音效。除`minecraft:fireworks_rocket`外,其他效果可通过修改粒子/音效定义进行配置。
|
||||
|
||||
### 服务端属性
|
||||
服务端属性描述实体核心行为机制,包含位置、状态和交互等正规信息。
|
||||
|
||||
**已注册**
|
||||
当实体可通过`/summon`生成且`type`选择器能选中时视为已注册。只要`is_spawnable`为`true`,生成蛋始终可用。
|
||||
|
||||
**可配置行为**
|
||||
若为是,则该实体可使用通用行为组件(如`minecraft:behavior.panic`)。
|
||||
|
||||
**可配置碰撞箱**
|
||||
此属性激活时,`minecraft:collision_box`生效。某些运行时标识符会强制应用固定碰撞箱或修改碰撞箱计算方式。
|
||||
|
||||
**可配置方块碰撞**
|
||||
当激活时,`minecraft:physics`的`has_collision`生效。若实体声明了`minecraft:projectile`组件,此属性仍标记为活跃。
|
||||
|
||||
(由于长度限制,完整翻译内容超过单次响应限制,将分次响应。)
|
||||
422
docs/wiki/3-实体/3-文档/runtime-identifier.md
Normal file
422
docs/wiki/3-实体/3-文档/runtime-identifier.md
Normal file
@@ -0,0 +1,422 @@
|
||||
---
|
||||
title: 运行时标识符
|
||||
category: 文档
|
||||
mentions:
|
||||
- MedicalJewel105
|
||||
- aexer0e
|
||||
- Luthorius
|
||||
- SirLich
|
||||
- TheDoctor15
|
||||
- ChibiMango
|
||||
- stirante
|
||||
- epxzzy
|
||||
- IlkinQafarov
|
||||
- TheItsNameless
|
||||
- SmokeyStack
|
||||
- ThomasOrs
|
||||
- Goatfu
|
||||
---
|
||||
|
||||
# 运行时标识符
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
`runtime_identifier` 是位于实体行为文件描述部分的可选参数,用于模拟原版实体的硬编码特性。
|
||||
它接受原版 Minecraft 标识符,例如 `minecraft:shulker`。
|
||||
|
||||
::: code-group
|
||||
```json [行为实体描述]
|
||||
"description": {
|
||||
"identifier": "wiki:my_box",
|
||||
"runtime_identifier": "minecraft:shulker", // 此运行时标识符会将潜影贝的硬编码行为附加到当前实体
|
||||
"is_spawnable": true,
|
||||
"is_summonable": true,
|
||||
"is_experimental": false
|
||||
}
|
||||
```
|
||||
|
||||
:::tip 注意
|
||||
需要注意 `runtime_identifier` **仅解析实体的硬编码特性**。这意味着使用100%数据驱动的生物作为运行时标识符不会给实体添加新特性。此外,某些实体运行时可能会覆盖组件部分定义的属性,例如潜影贝实体的碰撞箱尺寸。
|
||||
:::
|
||||
|
||||
:::warning 警告
|
||||
此处未列出所有运行时标识符效果。建议通过实验自行探索新效果,也欢迎在此补充发现。
|
||||
:::
|
||||
|
||||
## 已知的运行时标识符效果:
|
||||
|
||||
- 所有运行时ID都会将实体名称更改为对应原版实体的名称
|
||||
|
||||
### minecraft:area_effect_cloud
|
||||
|
||||
- 导致实体崩溃
|
||||
|
||||
---
|
||||
|
||||
### minecraft:armor_stand
|
||||
|
||||
- 禁用实体阴影
|
||||
- 击打时立即消失
|
||||
- 允许装备穿戴/卸除
|
||||
- 死亡时掉落盔甲架物品
|
||||
|
||||
---
|
||||
|
||||
### minecraft:arrow
|
||||
|
||||
- 为抛射物添加朝向玩家的动画
|
||||
- 禁用死亡动画/声音/粒子
|
||||
- 缩小实体阴影(但不会消失)
|
||||
- 不可交互
|
||||
- 通过生成蛋或/summon生成时,玩家接触后获得箭矢同时实体消失
|
||||
- 飞行物理特性和击退效果与箭矢一致
|
||||
|
||||
---
|
||||
|
||||
### minecraft:axolotl
|
||||
- 不影响游泳/移动/重力行为
|
||||
- 类似热带鱼,不同变种值影响水桶名称(如"亮蓝色美西螈桶"或"幼年黄色美西螈桶")
|
||||
年龄变种: 成年/幼年
|
||||
颜色变种: 亮色/野生/黄色/青色/蓝色
|
||||
|
||||
---
|
||||
|
||||
### minecraft:bee
|
||||
|
||||
- 添加蜜蜂音效
|
||||
|
||||
---
|
||||
|
||||
### minecraft:blaze
|
||||
|
||||
- 添加烈焰人燃烧音效和粒子
|
||||
- 实体将具有烈焰人飞行特性(即使未添加飞行行为)
|
||||
|
||||
---
|
||||
|
||||
### minecraft:boat
|
||||
|
||||
- 骑乘时显示船型UI界面
|
||||
- 禁止实体旋转
|
||||
- 具有船形固体碰撞箱
|
||||
|
||||
---
|
||||
|
||||
### minecraft:chest_minecart
|
||||
|
||||
- 导致实体崩溃
|
||||
- 击打后立即消失
|
||||
- 生成状态异常
|
||||
- 掉落箱子和矿车
|
||||
|
||||
---
|
||||
|
||||
### minecraft:chicken
|
||||
|
||||
- 部分动画失效
|
||||
- 更新移动速度
|
||||
- 实体下落减缓但仍受掉落伤害
|
||||
- 生成时不携带装备(若原有)
|
||||
|
||||
---
|
||||
|
||||
### minecraft:cod
|
||||
|
||||
- 脱离水体时扑腾
|
||||
- 使用水桶交互获得鳕鱼桶(放置时生成当前实体而非鳕鱼)
|
||||
- 赋予特殊游泳和重力特性
|
||||
|
||||
---
|
||||
|
||||
### minecraft:command_block_minecart
|
||||
|
||||
- 导致实体崩溃
|
||||
- 击打后立即消失
|
||||
- 生成状态异常
|
||||
- 掉落矿车
|
||||
|
||||
---
|
||||
|
||||
### minecraft:cow
|
||||
|
||||
- 部分动画失效
|
||||
- 更新移动速度
|
||||
- 生成时不携带装备(若原有)
|
||||
|
||||
---
|
||||
|
||||
### minecraft:dolphin
|
||||
|
||||
- 添加 `minecraft:movement.dolphin` 组件
|
||||
|
||||
---
|
||||
|
||||
### minecraft:donkey
|
||||
|
||||
- 将纹理/模型/动画更换为驴子
|
||||
|
||||
---
|
||||
|
||||
### minecraft:dragon_fireball
|
||||
|
||||
- 完全破坏实体
|
||||
- 生成龙息火球尾迹粒子
|
||||
|
||||
---
|
||||
|
||||
### minecraft:egg
|
||||
|
||||
- 为抛射物添加朝向玩家的动画
|
||||
- 导致实体崩溃
|
||||
- 使用生成蛋生成时会出现在玩家位置而非指定位置,且面朝天空
|
||||
|
||||
---
|
||||
|
||||
### minecraft:elder_guardian
|
||||
|
||||
- 将纹理/模型/动画更换为远古守卫者
|
||||
- 改变部分行为特性
|
||||
|
||||
---
|
||||
|
||||
### minecraft:ender_crystal
|
||||
|
||||
- 实体将固定在生成方块的中央
|
||||
- 除传送外始终保持位置不变
|
||||
- 可放置于任何表面
|
||||
- 其他实体可穿透
|
||||
- 无法配置承受伤害
|
||||
- 无法改变朝向
|
||||
- 可复活末影龙
|
||||
- 生成时带火焰效果
|
||||
|
||||
---
|
||||
|
||||
### minecraft:ender_dragon
|
||||
|
||||
- 添加末影龙死亡特效
|
||||
- 继承末影龙碰撞箱
|
||||
- 破坏碰撞箱内所有方块(包括底部方块),建议在下方放置不可破坏方块/移除重力/禁用`mobGriefing`规则
|
||||
- 对碰撞箱2格范围内的玩家造成伤害
|
||||
- 增加渲染距离
|
||||
- 只能通过/kill指令消除
|
||||
|
||||
---
|
||||
|
||||
### minecraft:ender_pearl
|
||||
|
||||
- 破坏实体行为
|
||||
- 受伤时生成粒子
|
||||
|
||||
---
|
||||
|
||||
### minecraft:endermite
|
||||
|
||||
- 受伤时生成粒子
|
||||
- 导致旋转异常
|
||||
- 部分动画失效
|
||||
|
||||
---
|
||||
|
||||
### minecraft:evocation_fang
|
||||
|
||||
- 对接触实体造成伤害
|
||||
- 完全禁用碰撞
|
||||
|
||||
---
|
||||
|
||||
### minecraft:falling_block
|
||||
|
||||
- 导致实体崩溃并下落
|
||||
- 接触地面后无动画消失,掉落金合欢按钮
|
||||
- 移除效果附着能力
|
||||
|
||||
### minecraft:horse
|
||||
|
||||
- 将纹理/模型/动画更换为马匹
|
||||
|
||||
---
|
||||
|
||||
### minecraft:iron_golem
|
||||
|
||||
- 允许发动攻击(击退效果垂直增强)
|
||||
- 加速四肢动画(可手动修复为约1/4速度)
|
||||
- 可能与村庄/村民逻辑冲突
|
||||
|
||||
---
|
||||
|
||||
### minecraft:llama_spit
|
||||
|
||||
- 添加羊驼唾沫粒子
|
||||
|
||||
---
|
||||
|
||||
### minecraft:minecart
|
||||
|
||||
- 禁用实体阴影
|
||||
- 死亡时掉落矿车
|
||||
- 禁止实体旋转
|
||||
|
||||
---
|
||||
|
||||
### minecraft:panda
|
||||
|
||||
- 使`q.is_grazing`和`q.sit_mount`能与`minecraft:behavior.random_sitting`组件协同工作
|
||||
|
||||
---
|
||||
|
||||
### minecraft:parrot
|
||||
|
||||
- 启用翅膀扇动动画
|
||||
- 缓慢降落
|
||||
- 跟随音乐唱片跳舞
|
||||
|
||||
---
|
||||
|
||||
### minecraft:piglin
|
||||
|
||||
- 启用`minecraft:celebrate_hunt`功能(激活 q.is_celebrating)
|
||||
|
||||
---
|
||||
|
||||
### minecraft:player
|
||||
|
||||
- 激活`q.movement_direction`
|
||||
|
||||
---
|
||||
|
||||
### minecraft:pufferfish
|
||||
|
||||
- 脱离水体时扑腾
|
||||
- 使用水桶交互获得河豚桶(放置时生成当前实体而非河豚)
|
||||
- 赋予特殊游泳和重力特性
|
||||
|
||||
---
|
||||
|
||||
### minecraft:salmon
|
||||
|
||||
- 脱离水体时扑腾
|
||||
- 使用水桶交互获得鲑鱼桶(放置时生成当前实体而非鲑鱼)
|
||||
- 赋予特殊游泳和重力特性
|
||||
|
||||
---
|
||||
|
||||
### minecraft:sheep
|
||||
|
||||
- 使`q.is_grazing`能与`behavior.eat_block`组件协同工作
|
||||
|
||||
---
|
||||
|
||||
### minecraft:shulker
|
||||
|
||||
冒险模式玩家的方块拟态神器
|
||||
|
||||
- 1x1x1固体碰撞箱
|
||||
- 固定于生成方块的中央
|
||||
- 附着方块被破坏后传送至附近可用位置
|
||||
- 在非完整方块(床/台阶等)上生成时自动传送
|
||||
- 无法修改碰撞箱尺寸
|
||||
|
||||
---
|
||||
|
||||
### minecraft:shulker_bullet
|
||||
|
||||
- 生成潜影贝导弹尾迹粒子
|
||||
|
||||
---
|
||||
|
||||
### minecraft:slime
|
||||
|
||||
- 下落时生成黏液粒子
|
||||
- 根据变体值分裂(1-5为史莱姆常规尺寸,5以上视为中型)
|
||||
- 允许攻击同时保持史莱姆跳跃机制(无此标识符时攻击状态无法转向)
|
||||
|
||||
---
|
||||
|
||||
### minecraft:snowball
|
||||
|
||||
- 移除碰撞箱
|
||||
- 不可交互
|
||||
- 生成于玩家头部位置
|
||||
- 无视重力
|
||||
- 移除实体阴影
|
||||
- 恒定面朝南方
|
||||
- 无法发出踏步音效
|
||||
|
||||
---
|
||||
|
||||
### minecraft:spider
|
||||
|
||||
- 蛛网减速失效
|
||||
|
||||
---
|
||||
|
||||
### minecraft:skeleton
|
||||
|
||||
- 治疗效果造成伤害/瞬间伤害效果恢复生命
|
||||
- 亡灵杀手附魔增伤
|
||||
- 变体≥1时近战与远程攻击附加凋零效果
|
||||
|
||||
---
|
||||
|
||||
### minecraft:stray
|
||||
|
||||
- 治疗效果造成伤害/瞬间伤害效果恢复生命
|
||||
- 亡灵杀手附魔增伤
|
||||
- 免疫冰冻伤害
|
||||
|
||||
---
|
||||
|
||||
### minecraft:squid
|
||||
|
||||
- 支持特殊行为组件(参考squid.json)
|
||||
- 受伤时生成墨汁粒子
|
||||
|
||||
---
|
||||
|
||||
### minecraft:thrown_trident
|
||||
|
||||
- 为抛射物添加朝向玩家的动画
|
||||
- 禁用死亡动画/声音/粒子
|
||||
- 缩小实体阴影(但不会消失)
|
||||
- 不可交互
|
||||
- 飞行物理特性和击退效果与三叉戟一致
|
||||
|
||||
---
|
||||
|
||||
### minecraft:tropicalfish
|
||||
|
||||
- 脱离水体时扑腾
|
||||
- 赋予特殊游泳和重力特性
|
||||
- 使用水桶获得热带鱼桶(若无variant/mark_variant/color定义则为白色考伯鱼规格,含相关组件时桶名与实体规格对应)
|
||||
|
||||
---
|
||||
|
||||
### minecraft:wither_skull_dangerous
|
||||
|
||||
- 死亡时掉落凋零玫瑰
|
||||
- 被击杀实体会在原地生成凋零玫瑰(僵尸类异常掉落)
|
||||
- 持续生成基础烟雾粒子
|
||||
- 无视重力(使projectile组件实体直线运动)
|
||||
- 免疫所有伤害
|
||||
- 仅对无AI目标的实体生效(适用于假人实体和弹射物)
|
||||
|
||||
---
|
||||
|
||||
### minecraft:xp_orb
|
||||
|
||||
- 完全禁用碰撞
|
||||
- 接触玩家增加经验值
|
||||
|
||||
### minecraft:zombie
|
||||
|
||||
- 治疗效果造成伤害/瞬间伤害效果恢复生命
|
||||
- 亡灵杀手附魔增伤
|
||||
|
||||
---
|
||||
|
||||
### minecraft:wither
|
||||
|
||||
- 死亡时爆炸
|
||||
|
||||
---
|
||||
194
docs/wiki/3-实体/3-文档/spawning-tamed-entities.md
Normal file
194
docs/wiki/3-实体/3-文档/spawning-tamed-entities.md
Normal file
@@ -0,0 +1,194 @@
|
||||
---
|
||||
title: 生成已驯服的实体
|
||||
category: 教程
|
||||
tags:
|
||||
- 中级
|
||||
mentions:
|
||||
- Axelpvz2030
|
||||
- aexer0e
|
||||
- SirLich
|
||||
- MedicalJewel105
|
||||
- SmokeyStack
|
||||
- ThomasOrs
|
||||
---
|
||||
|
||||
# 生成已驯服的实体
|
||||
|
||||
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
|
||||
|
||||
在本教程中,您将学习如何通过向特定玩家触发事件来生成预驯服的实体,以及如何投掷在撞击时变形为已驯服实体的物品。
|
||||
|
||||
## 概述
|
||||
|
||||
传统方式中,若要让玩家驯服实体,必须通过 `minecraft:tameable` 强制玩家与实体互动。但我们也可以利用原版弹射物会记录生成者*\*的特性来实现预驯服实体的生成。
|
||||
|
||||
具体实现步骤:
|
||||
1. 通过 `minecraft:spawn_entity` 生成一个中间态弹射物实体
|
||||
2. 该实体将立即转换为预驯服的目标实体(本教程以原版狼为例)
|
||||
3. 在 `minecraft:transformation` 组件中将 `keep_owner` 设置为 `true`
|
||||
|
||||
\*: 需要区分 _Spawn(生成)_ 和 _Summon(召唤)_ 的区别。只有通过生成蛋或 `minecraft:spawn_entity` 组件生成的弹射物才会记录玩家信息,使用 `/summon` 命令生成的则不会。
|
||||
|
||||
## player.json
|
||||
|
||||
我们需要对玩家行为文件进行微调,添加一个事件来激活组件组用于生成中间态实体。
|
||||
|
||||
您可以在 Mojang 提供的[原版行为包模板](https://aka.ms/behaviorpacktemplate)中找到玩家实体的行为文件。
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/player.json]
|
||||
{
|
||||
"format_version":"1.16.0",
|
||||
"minecraft:entity":{
|
||||
"description":{
|
||||
"identifier":"minecraft:player",
|
||||
"is_spawnable":false,
|
||||
"is_summonable":false,
|
||||
"is_experimental":false
|
||||
},
|
||||
"component_groups":{ // 组件组定义
|
||||
"wiki:spawn_tamed_wolf":{
|
||||
"minecraft:spawn_entity":{
|
||||
"entities":{
|
||||
"min_wait_time":0,
|
||||
"max_wait_time":0,
|
||||
"spawn_entity":"wiki:pretamed_wolf",
|
||||
"single_use":true,
|
||||
"num_to_spawn":1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
...
|
||||
"events":{ // 事件定义
|
||||
"wiki:spawn_tamed_wolf":{
|
||||
"add":{
|
||||
"component_groups":[
|
||||
"wiki:spawn_tamed_wolf"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## pretamed_wolf.json
|
||||
|
||||
创建一个使用 `minecraft:arrow` 作为运行时标识符(也可选用其他弹射物标识符)的自定义实体,包含空白弹射物组件和用于转换为驯服狼的变形组件。
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/pretamed_wolf.json]
|
||||
{
|
||||
"format_version": "1.16.0",
|
||||
"minecraft:entity": {
|
||||
"description": {
|
||||
"identifier": "wiki:pretamed_wolf",
|
||||
"runtime_identifier": "minecraft:arrow",
|
||||
"is_spawnable": false,
|
||||
"is_summonable": true,
|
||||
"is_experimental": false
|
||||
},
|
||||
"components": { // 组件配置
|
||||
"minecraft:projectile": {}, // 弹射物组件
|
||||
"minecraft:transformation": { // 变形组件
|
||||
"into": "minecraft:wolf<minecraft:on_tame>",
|
||||
"keep_owner": true // 保持归属关系
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
现在即可通过命令 `/event entity @p wiki:spawn_tamed_wolf` 在玩家身边生成驯服的狼。若将 `is_spawnable` 设为 `true` 还可通过生成蛋调用!
|
||||
|
||||
:::warning 重要提示
|
||||
如需生成自定义实体而非原版狼:
|
||||
1. 必须为实体添加 `minecraft:is_tamed` 组件
|
||||
2. 未被驯服的实体可能出现预期外的行为
|
||||
:::
|
||||
|
||||
## 集成物品抛射物(替代方法)
|
||||
|
||||
利用 [1.16 实验性物品特性](/items/item-components) 中的 `shoot` 事件属性,可制作碰撞时转换为已驯服实体的弹射物。
|
||||
|
||||
::: code-group
|
||||
```json [BP/items/throwable_pretamed_wolf.json]
|
||||
{
|
||||
"format_version":"1.16.100",
|
||||
"minecraft:item":{
|
||||
"description":{
|
||||
"identifier":"wiki:throwable_pretamed_wolf"
|
||||
},
|
||||
"components":{ // 物品组件
|
||||
"minecraft:on_use":{
|
||||
"on_use":{
|
||||
"event":"wiki:on_use" // 使用事件触发
|
||||
}
|
||||
}
|
||||
},
|
||||
"events":{ // 事件配置
|
||||
"wiki:on_use":{
|
||||
"shoot":{
|
||||
"projectile":"wiki:pretamed_wolf" // 发射自定义弹射物
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
同时需修改弹射物实体的转化逻辑以避免即时变形:
|
||||
|
||||
::: code-group
|
||||
```json [BP/entities/pretamed_wolf.json]
|
||||
{
|
||||
"minecraft:entity":{
|
||||
"description":{
|
||||
"identifier":"wiki:pretamed_wolf",
|
||||
"runtime_identifier":"minecraft:arrow",
|
||||
"is_spawnable":false,
|
||||
"is_summonable":true,
|
||||
"is_experimental":false
|
||||
},
|
||||
"component_groups":{ // 组件组定义
|
||||
"wiki:transform_to_entity":{
|
||||
"minecraft:transformation":{
|
||||
"into":"minecraft:wolf<minecraft:on_tame>",
|
||||
"keep_owner":true
|
||||
}
|
||||
}
|
||||
},
|
||||
"components":{ // 组件配置
|
||||
"minecraft:projectile":{
|
||||
"on_hit":{ // 碰撞触发配置
|
||||
"impact_damage":{
|
||||
"damage":0 // 禁用伤害
|
||||
},
|
||||
"stick_in_ground":{}, // 插入地面
|
||||
"definition_event":{
|
||||
"event_trigger":{
|
||||
"event":"wiki:on_hit" // 碰撞事件触发
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"events":{ // 事件响应
|
||||
"wiki:on_hit":{
|
||||
"add":{
|
||||
"component_groups":[
|
||||
"wiki:transform_to_entity" // 添加变形组件组
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
特别感谢 [Zarkmend ZAN](https://twitter.com/Zarkmend_ZAN) 发现这一方法 :)
|
||||
20969
docs/wiki/3-实体/3-文档/vanilla-usage-components.md
Normal file
20969
docs/wiki/3-实体/3-文档/vanilla-usage-components.md
Normal file
File diff suppressed because it is too large
Load Diff
1383
docs/wiki/3-实体/3-文档/vanilla-usage-spawn-rules.md
Normal file
1383
docs/wiki/3-实体/3-文档/vanilla-usage-spawn-rules.md
Normal file
File diff suppressed because it is too large
Load Diff
47771
docs/wiki/3-实体/3-文档/vuc-full.md
Normal file
47771
docs/wiki/3-实体/3-文档/vuc-full.md
Normal file
File diff suppressed because it is too large
Load Diff
4500
docs/wiki/3-实体/3-文档/vusr-full.md
Normal file
4500
docs/wiki/3-实体/3-文档/vusr-full.md
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user