Files
netease-bedrock-wiki/mcguide/20-玩法开发/15-自定义游戏内容/4-自定义维度/3-生物生成.md
2025-08-25 18:36:29 +08:00

149 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
front:
hard: 入门
time: 分钟
---
# 生物生成
## 概述
开发者可以使用原版addon的`spawn_rules`功能控制自定义维度中的生物生成。
## spawn_rules使用方法
1.在addon的bevavior目录下新增spawn_rules文件夹
2.创建一个json文件并命名如example.json例子
```python
{
"format_version": "1.8.0",
"minecraft:spawn_rules": {
"description": {
"identifier": "minecraft:netease_example",
"population_control": "ambient"
},
"conditions": [
{
"minecraft:spawns_underground": {},
"minecraft:brightness_filter": {
"min": 0,
"max": 4,
"adjust_for_weather": true
},
"minecraft:height_filter": {
"min": 0,
"max": 63
},
"minecraft:weight": {
"default": 10
},
"minecraft:herd": {
"min_size": 2,
"max_size": 2
},
"minecraft:density_limit": {
"surface": 5
},
"minecraft:biome_filter": {
"test": "has_biome_tag", "operator":"==", "value": "animal"
}
}
]
}
}
```
description参数解释
| 参数 | 类型 | 解释 |
| --- | --- | --- |
| identifier | str | 该spawn rule的identifier格式为namespace:name |
| population_control | str | 生成生物的种类,每一种类都有生成个数的限制,可选的值为:<br>animal<br>monster<br>water_animal<br>villager<br>ambient<br>cat<br>pillager |
conditions参数解释
| Name | Description |
| :-------------------------: | :--------------------: |
| minecraft:spawns_on_surface | 允许mob在地上生成 |
| minecraft:spawns_underwater | 允许mob在水里生成 |
| minecraft:brightness_filter | 允许mob生成的光照条件 |
| minecraft:weight | mob生成的权重默认为0 |
| minecraft:difficulty_filter | mob生成的困难模式 |
| minecraft:herd | herd的大小 |
| minecraft:biome_filter | 允许mob生成的biome |
## 自定义群系的spawn_rules
利用condition中的minecraft:biome_filter过滤自定义群系的tag例如群系开发模板自带的dm3等tag或者其他自定义tag。
## demo解释
示例[CustomBiomesMod](../../13-模组SDK编程/60-Demo示例.md#CustomBiomesMod)中对dm4于dm5两个自定义维度的生物生成做了一些调整。
- dm4
使北极熊仅在该维度中生成,不会在其他维度的冰原群系生成。
1. 在polar_bear的spawn_rules中设置为仅在含dm4标签的群系生成
见customBiomesBehaviorPack/spawn_rules/polar_bear.json
```json
"minecraft:biome_filter": [
...,
{"test": "has_biome_tag", "operator":"==", "value": "dm4"}
]
```
- dm5
在冰原上不会生成兔子会生成3倍大小的北极熊。
1. 重写rabbit的spawn_rules使其不在带dm5标签的群系生成
见customBiomesBehaviorPack/spawn_rules/rabbit.json
```json
"minecraft:biome_filter": {
"any_of": [
{
"all_of": [
{ "test": "has_biome_tag", "operator":"==", "value": "taiga"},
{ "test": "has_biome_tag", "operator":"!=", "value": "mega"}
]
},
{
"all_of": [
{"test": "is_snow_covered", "operator":"==", "value": true},
{"test": "has_biome_tag", "operator":"!=", "value": "dm5"} //添加这一句
]
},
{"test": "has_biome_tag", "operator":"==", "value":"desert"}
]
}
```
2. 新建一个名为neteasebiomes:dm5_polar_bear的自定义生物除了设置为3倍大小外与原版北极熊一致
见customBiomesBehaviorPack/entities/polar_bear.json及customBiomesResourcePack/entity/dm5_polar_bear.entity.json
```json
"minecraft:scale": {
"value": 3.0
},
```
然后为其配置spawn_rules使其仅在dm5中生成
见customBiomesBehaviorPack/spawn_rules/dm5_polar_bear.json
```python
"minecraft:biome_filter": [
... ,
{"test": "has_biome_tag", "operator":"==", "value": "dm5"}
]
```