添加了部分来自于BedrockWiki的文章!

This commit is contained in:
boybook
2025-03-19 22:17:04 +08:00
parent 41635cf9bb
commit c25ebf2767
558 changed files with 96136 additions and 24 deletions

View File

@@ -0,0 +1,540 @@
---
title: 方块组件
description: 方块组件用于改变方块在世界中的外观和功能。
category: 常规
nav_order: 2
mentions:
- SirLich
- solvedDev
- yanasakana
- SmokeyStack
- MedicalJewel105
- aexer0e
- Chikorita-Lover
- Luthorius
- TheDoctor15
- XxPoggyisLitxX
- TheItsNameless
- ThomasOrs
- Kaioga5
- QuazChick
---
# 方块组件 Components
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip 格式版本 & 最低引擎版本 `1.20.30`
在创建自定义方块时使用最新格式版本可获取最新功能和改进。本wiki旨在提供关于自定义方块的最新信息当前目标格式版本为`1.20.30`
:::
:::danger <nbsp/>
每个组件在同一时间只能有一个实例生效。重复的组件将被最新的[permutation条件置换](/blocks/block-permutations)覆盖。
:::
需要事件触发组件?[点击此处查看!](/blocks/block-events#event-triggers)
## 应用组件
方块组件用于改变方块在世界中的外观和功能。它们被应用在`minecraft:block`或其[permutation条件置换](/blocks/block-permutations)的`components`子项中。
::: code-group
```json [BP/blocks/lamp.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:lamp",
"menu_category": {
"category": "items"
}
},
"components": {
"minecraft:light_dampening": 0,
"minecraft:light_emission": 15,
"minecraft:map_color": [210, 200, 190],
"minecraft:geometry": "geometry.lamp",
"minecraft:material_instances": {
"*": {
"texture": "lamp"
},
"shade": {
"texture": "lamp_shade"
}
}
}
}
}
```
:::
## 碰撞箱
设置方块实体/粒子的碰撞箱,单位为<abbr title="1/16方块单位">像素</abbr> - 必须包含在基础方块单位内16×16×16
- 原点从方块的水平中点和垂直底部开始计算,向东北方向延伸。
- 尺寸从原点开始计算,向东北方向延伸。
**也可定义为布尔值:**
- `false`时实体可穿过方块
- `true`时设置单位大小的立方体作为碰撞箱
**默认值:** `true`
_自实验性玩法`Holiday Creator Features`中发布适用于格式版本1.19.50及以上。_
::: code-group
```json [minecraft:block > components]
"minecraft:collision_box": {
"origin": [-8, 0, -8],
"size": [16, 16, 16]
}
```
:::
::: code-group
```json [minecraft:block > components]
"minecraft:collision_box": false
```
:::
## 工作台
将方块变为工作台,交互时打开合成界面。
_自实验性玩法`Holiday Creator Features`中发布适用于格式版本1.19.50及以上。_
::: code-group
```json [minecraft:block > components]
"minecraft:crafting_table": {
"table_name": "Wiki工作台", // 在合成菜单中显示的名称,可本地化
"crafting_tags": ["crafting_table", "wiki_workbench"] // 用于配方文件的标签
}
```
:::
## 可被爆炸破坏
设置方块对爆炸破坏的抗性。
**也可定义为布尔值:**
- `false`时不可被爆炸破坏
- `true`时爆炸抗性为`0`
**默认值:** `true`
::: code-group
```json [minecraft:block > components]
"minecraft:destructible_by_explosion": {
"explosion_resistance": 20
}
```
:::
::: code-group
```json [minecraft:block > components]
"minecraft:destructible_by_explosion": false // 不可被爆炸破坏
```
:::
## 可被挖掘破坏
设置挖掘破坏所需时间。
**也可定义为布尔值:**
- `false`时不可被挖掘破坏
- `true`时可被瞬间破坏
**默认值:** `true`
::: code-group
```json [minecraft:block > components]
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 0.5
}
```
:::
::: code-group
```json [minecraft:block > components]
"minecraft:destructible_by_mining": false // 不可被挖掘破坏
```
:::
## 显示名称
设置当鼠标悬停在物品栏和快捷栏中的方块时显示的文本对应的语言文件键名。
如果给定的字符串没有对应的翻译,将直接显示原始字符串。
**注意**在某些情况下Minecraft可能会回退使用`tile.<标识符>.name`。
_自实验性玩法`Holiday Creator Features`中发布适用于格式版本1.19.60及以上。_
::: code-group
```json [minecraft:block > components]
"minecraft:display_name": "tile.example_block.red.name"
```
:::
::: code-group
```c [RP/texts/zh_CN.lang]
tile.example_block.red.name=红色示例方块
```
:::
## 可燃性
设置方块的可燃性参数。
**也可定义为布尔值:**
- `false`时方块不会着火或被火焰破坏
- `true`时将使用下方示例值
**默认值:** `false`
::: code-group
```json [minecraft:block > components]
"minecraft:flammable": {
"catch_chance_modifier": 5, // 影响方块在火源旁被点燃的几率
"destroy_chance_modifier": 20 // 影响方块在燃烧时被火焰破坏的几率
}
```
:::
::: code-group
```json [minecraft:block > components]
"minecraft:flammable": false // 默认值 - 方块不会自然引燃,但可被直接点燃
```
:::
## 摩擦力
设置方块表面摩擦力0.0至0.9的小数)。数值越小表面越滑。
**原版示例值:**
- 泥土:`0.4`
- 冰:`0.02`
**默认值:** `0.4`
::: code-group
```json [minecraft:block > components]
"minecraft:friction": 0.4
```
:::
## 几何模型
设置方块使用的模型。当与其他方块相交时,模型不会应用面剔除。
**自定义方块模型限制:**
- 模型尺寸限制为30×30×30<abbr title="1/16方块单位">像素</abbr>
- 每个轴上至少要有1像素位于基础16×16×16方块内
- 模型的位置绝对边界为原点各方向30像素。只要遵守第二条规则模型可放置在这些边界内的任意位置
**启用时:**
- 方块变为可呼吸
- 方块不再传导红石信号
_自实验性玩法`Holiday Creator Features`中发布适用于格式版本1.19.40及以上。_
::: code-group
```json [minecraft:block > components]
"minecraft:geometry": "geometry.example_block" // 来自'RP/models/entity'或'RP/models/blocks'文件夹的几何模型标识符
```
:::
---
### 骨骼可见性
隐藏模型中骨骼的直接子立方体。
**Molang表达式需遵守[条件置换限制](/blocks/block-permutations#permutation-conditions)。**
_自格式版本1.20.10起支持`bone_visibility`中的Molang表达式。_
::: code-group
```json [minecraft:block > components]
"minecraft:geometry": {
"identifier": "geometry.example_block", // 来自'RP/models/entity'或'RP/models/blocks'文件夹的几何模型标识符
"bone_visibility": {
"wiki_bone": false, // 隐藏该骨骼中的立方体
"conditional_bone": "q.block_state('wiki:example_state') == 3", // 使用Molang表达式条件设置可见性
"another_bone": true // true为默认值无实际效果
}
}
```
:::
## 光照衰减
设置光线穿过方块时的衰减程度0-15整数 - 数值越大透光越少。
**原版示例值:**
- 泥土和染色玻璃:`15`
- 铁栏杆和玻璃板:`0`
**默认值:** `15`
::: code-group
```json [minecraft:block > components]
"minecraft:light_dampening": 7
```
:::
## 光照发射
设置方块发出的光照强度0-15整数
**原版示例值:**
- 蛙明灯:`15`
- 红石火把(点亮):`7`
**默认值:** `0`
::: code-group
```json [minecraft:block > components]
"minecraft:light_emission": 10
```
:::
## 战利品表
设置方块被破坏时掉落的战利品(无视`精准采集`附魔)。
**若省略则掉落方块本身。**
::: code-group
```json [minecraft:block > components]
"minecraft:loot": "loot_tables/blocks/custom_block.json"
```
:::
## 地图颜色
设置方块在地图上的显示颜色(十六进制字符串或[R, G, B]数组0-255
**若省略则地图不显示该方块。**
::: code-group
```json [minecraft:block > components]
"minecraft:map_color": "#ffffff"
```
:::
::: code-group
```json [minecraft:block > components]
"minecraft:map_color": [255, 255, 255]
```
:::
## 材质实例
配置方块的渲染参数,包括纹理和光照处理。
- 所有实例必须使用相同的渲染方法
- 与其他方块相交时,方块面会无条件变暗
材质实例可与`RP/blocks.json`条目结合使用,创建具有类不透明属性的方块。这主要用于在[自定义玻璃方块](/blocks/custom-glass-blocks)上启用面剔除。
_自实验性玩法`Holiday Creator Features`中发布适用于格式版本1.19.40及以上。_
### 渲染方法
渲染方法本质上控制方块在世界中的显示方式,类似于实体的材质。以下是各类型的关键属性:
| 渲染方法 | _透明度_ | _半透明性_ | _背面剔除_ | 原版示例 |
| ---------------- | :------: | :--------: | :--------: | ------------------------ |
| opaque默认 | ❌ | ❌ | ✔️ | 泥土、石头、混凝土 |
| double_sided | ❌ | ❌ | ❌ | 无 - 用于不透明2D平面 |
| alpha_test | ✔️ | ❌ | ❌ | 藤蔓、铁轨、树苗 |
| blend | ✔️ | ✔️ | ✔️ | 玻璃、信标、蜂蜜块 |
- **_透明度_** - 完全透明区域
- **_半透明性_** - 半透明区域
- 半透明像素在UI渲染中显示为不透明
- **_背面剔除_** - 从背面观察时面不可见
- 没有背面剔除的渲染方法在远处会消失(基于迷雾/渲染距离)
- 在UI渲染中始终启用背面剔除
::: code-group
```json [minecraft:block > components]
"minecraft:material_instances": {
// '*' 为必需实例 - 方块的默认实例(也用于破坏粒子)
// 通配符遵循渲染控制器语法
// 内置实例名包括'up', 'down', 'north', 'east', 'south'和'west'
"*": {
"texture": "texture_name", // 在`RP/textures/terrain_textures.json`中定义的短名称
"render_method": "blend", // 上表中的渲染方法之一
"face_dimming": true, // 默认true是否根据方向调暗该材质的表面
"ambient_occlusion": true // 默认true是否根据周围方块生成阴影
}
}
```
:::
### 自定义实例名称
:::tip
可在Blockbench中通过右键立方体并打开`材质实例`来定义自定义材质实例名称。
:::
可在材质实例中定义自定义实例名称,可被内置实例名称引用,或在方块模型中引用。
::: code-group
```json [minecraft:block > components]
"minecraft:material_instances": {
"*": {
"texture": "texture_name",
"render_method": "blend" // 必须与其他实例匹配
},
// 自定义实例名称
"end": {
"texture": "texture_name_end",
"render_method": "blend" // 必须与其他实例匹配
},
"up": "end",
"down": "end",
// 模型中定义的实例名称:
"flower": {
"texture": "texture_name_flower",
"render_method": "blend" // 必须与其他实例匹配
}
}
```
:::
## 放置过滤器
配置方块可存在的条件。当条件不满足时,方块将无法放置;若已放置则会弹出。
**`block_filter`最多可包含64个条目。**
**若省略,方块可被放置并存在于任何表面。**
_自实验性玩法`Holiday Creator Features`中发布适用于格式版本1.19.60及以上。_
::: code-group
```json [minecraft:block > components]
"minecraft:placement_filter": {
"conditions": [
{
"allowed_faces": ["up"], // 可包含'up', 'down', 'north', 'east', 'south', 'west'和'side'
"block_filter": [
// 测试标识符
"minecraft:dirt",
// 测试标签
{ "tags": "!q.any_tag('stone', 'wiki_tag')" }
]
}
]
}
```
:::
查看[此页面](/blocks/block-tags)获取原版标签及相关方块列表。
## 选择箱
设置方块的可选区域(点击框),单位为<abbr title="1/16方块单位">像素</abbr> - 必须包含在基础方块单位内16×16×16
- 原点从方块的水平中点和垂直底部开始计算,向东北方向延伸。
- 尺寸从原点开始计算,向东北方向延伸。
**也可定义为布尔值:**
- `false`时实体可穿过方块
- `true`时设置单位大小的立方体作为碰撞箱
**默认值:** `true`
_自实验性玩法`Holiday Creator Features`中发布适用于格式版本1.19.60及以上。_
::: code-group
```json [minecraft:block > components]
"minecraft:selection_box": {
"origin": [-8, 0, -8],
"size": [16, 16, 16]
}
```
:::
或:
::: code-group
```json [minecraft:block > components]
"minecraft:selection_box": false
```
:::
## 变换
允许对方块进行平移、缩放和旋转(包含视觉和功能变化)。
**变换后的模型不得超过[几何模型限制](#geometry)。**
:::tip
学习如何应用[可旋转方块](/blocks/rotatable-blocks),就像熔炉和生物头颅一样根据放置方向旋转!
:::
::: code-group
```json [minecraft:block > components]
"minecraft:transformation": {
"translation": [-5, 8, 0],
"rotation": [90, 180, 0],
"scale": [0.5, 1, 0.5],
}
```
:::
## 单位立方体(实验性功能) {#unit-cube}
:::warning 实验性功能
此组件需要启用`Holiday Creator Features`实验性玩法,未来可能会被移除/修改。
:::
将方块变为16×16×16立方体覆盖`minecraft:geometry`设置。
**启用时:**
- 方块变为不可呼吸
- 方块可传导红石信号
**如果方块的纹理/模型不需要根据条件置换改变,请在`RP/blocks.json`中定义纹理以避免使用此实验性组件。**
::: code-group
```json [minecraft:block > components]
"minecraft:unit_cube": {}
```
:::

View File

@@ -0,0 +1,623 @@
---
title: 方块事件与触发器
description: 方块事件允许你在满足特定条件时操控游戏世界。
category: 常规
nav_order: 8
tags:
- 实验性功能
mentions:
- SirLich
- solvedDev
- yanasakana
- MedicalJewel105
- aexer0e
- SmokeyStack
- TheDoctor15
- XxPoggyisLitxX
- TheItsNameless
- ThomasOrs
- QuazChick
- VactricaKing
- BlazeDrake
---
# 方块事件与触发器
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip 格式与最低引擎版本 `1.20.30`
创建自定义方块时使用最新格式版本可获得新功能和改进。本wiki旨在分享关于自定义方块的最新信息当前目标格式版本为`1.20.30`
:::
:::warning 实验性功能
方块事件需要启用`假日创作者功能`实验性玩法。
:::
:::danger 警告
方块事件已被弃用,将在未来更新中移除。除非必要,否则不建议使用,因为在移除后你需要将所有功能迁移至脚本系统。
:::
## 定义事件
方块事件允许你在满足特定条件时操控游戏世界,事件定义在`minecraft:block``events`子项中。在事件内部,你可以通过配置[事件响应](#事件响应)来设定触发事件时执行的操作。
[事件触发器](#事件触发器)会在适当条件下运行事件,执行所有关联的事件响应。
::: code-group
```json [BP/blocks/loot_dropper.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:loot_dropper"
},
"components": {
"minecraft:on_step_on": {
"event": "wiki:drop_loot"
}
},
"events": {
"wiki:drop_loot": {
"spawn_loot": {
"table": "loot_tables/blocks/my_loot_table.json"
}
}
}
}
}
```
:::
_此示例在实体踏上方块时生成战利品_
## 序列响应
序列允许你多次运行相同响应,或在满足条件时触发特定操作。
所有事件响应都应包含在序列中。
::: code-group
```json [minecraft:block > events]
"wiki:my_sequence": {
"sequence": [
{
"set_block_state": {
"wiki:my_state": true
}
},
{
"condition": "q.block_state('wiki:my_state')", // 可选
"trigger": {
"event": "wiki:my_entity_event",
"target": "other"
}
}
]
}
```
:::
## 随机响应
随机执行事件响应。
::: code-group
```json [minecraft:block > events]
"wiki:random_action": {
"randomize": [
{
"weight": 1, // 1/4概率
"set_block_state": {
"wiki:my_state": true
}
},
{
"weight": 3, // 3/4概率
"trigger": {
"event": "wiki:my_entity_event",
"target": "other"
}
}
]
}
```
:::
## 事件响应
- [`add_mob_effect`](#添加生物效果)
- [`damage`](#造成伤害)
- [`decrement_stack`](#减少堆叠)
- [`die`](#摧毁)
- [`play_effect`](#播放特效)
- [`play_sound`](#播放音效)
- [`remove_mob_effect`](#移除生物效果)
- [`run_command`](#执行命令)
- [`set_block`](#设置方块)
- [`set_block_at_pos`](#在指定位置设置方块)
- [`set_block_state`](#设置方块状态)
- [`spawn_loot`](#生成战利品)
- [`swing`](#挥动)
- [`teleport`](#传送)
- [`transform_item`](#转换物品)
- [`trigger`](#触发事件)
### 添加生物效果
为指定目标添加生物效果。
::: code-group
```json [minecraft:block > events]
"wiki:effect_event": {
"add_mob_effect": {
"effect": "poison",
"target": "other",
"duration": 8,
"amplifier": 3
}
}
```
:::
### 造成伤害
对目标造成指定类型和数值的伤害。
::: code-group
```json [minecraft:block > events]
"wiki:damage_event": {
"damage": {
"type": "magic",
"target": "other",
"amount": 4
}
}
```
:::
### 减少堆叠
移除玩家当前手持物品堆叠中的一个物品。
::: code-group
```json [minecraft:block > events]
"wiki:remove_one": {
"decrement_stack": {
"ignore_game_mode": true // 可选 - 是否影响创造模式玩家默认为false
}
}
```
:::
### 摧毁
摧毁指定目标,若目标为`self`则方块直接消失且不生成战利品或效果。
::: code-group
```json [minecraft:block > events]
"wiki:destroy": {
"die": {
"target": "self"
}
}
```
:::
### 播放特效
在目标位置播放粒子特效。
支持的`effect`值未知。可通过[`run_command`](#执行命令)配合`playsound`命令实现类似效果。
::: code-group
```json [minecraft:block > events]
"wiki:particle_effect": {
"play_effect": {
"effect": "???",
"target": "self"
}
}
```
:::
### 播放音效
在目标位置播放音效。
支持`RP/sounds.json`中大多数原版独立音效事件ID但自定义音效条目不可用。
::: code-group
```json [minecraft:block > events]
"wiki:play_sound": {
"play_sound": {
"sound": "beacon.power",
"target": "self"
}
}
```
:::
### 移除生物效果
移除目标的指定生物效果。
::: code-group
```json [minecraft:block > events]
"wiki:remove_effect_event": {
"remove_mob_effect": {
"effect": "poison",
"target": "other"
}
}
```
:::
### 执行命令
对目标执行命令。
使用数组可执行多个命令。
::: code-group
```json [minecraft:block > events]
"wiki:execute_event": {
"run_command": {
"target": "self", // 可选 - 默认为'self'(目标为方块)
"command": "summon pig"
}
}
```
:::
或...
::: code-group
```json [minecraft:block > events]
"wiki:execute_event": {
"run_command": {
"target": "self", // 可选 - 默认为'self'(目标为方块)
"command": [
"summon pig",
"say 大家欢迎小猪!"
]
}
}
```
:::
### 设置方块
用指定方块替换当前方块。
::: code-group
```json [minecraft:block > events]
"wiki:place_block": {
"set_block": {
"block_type": "minecraft:grass"
}
}
```
:::
或...
::: code-group
```json [minecraft:block > events]
"wiki:place_block": {
"set_block": {
"block_type": {
"name": "minecraft:trapdoor",
"states": {
"direction": 2,
"open_bit": true
}
}
}
}
```
:::
### 在指定位置设置方块
在方块相对位置生成指定方块。
::: code-group
```json [minecraft:block > events]
"wiki:generate_stone_above": {
"set_block_at_pos": {
"block_type": "minecraft:stone",
"block_offset": [0, 1, 0]
}
}
```
:::
或...
::: code-group
```json [minecraft:block > events]
"wiki:generate_upper_door_above": {
"set_block_at_pos": {
"block_type": {
"name": "minecraft:wooden_door",
"states": {
"upper_block_bit": true
}
},
"block_offset": [0, 1, 0]
}
}
```
:::
### 设置方块状态
设置方块状态值可设置为Molang表达式字符串的返回值
:::warning
字符串值会被解析为Molang表达式。因此要设置字符串状态时必须用`'`包裹值(见示例)。
:::
::: code-group
```json [minecraft:block > events]
"wiki:change_state": {
"set_block_state": {
"wiki:boolean_state_example": false,
"wiki:integer_state_example": "q.block_state('wiki:integer_state_example') + 1",
"wiki:string_state_example": "'red'"
}
}
```
:::
### 生成战利品
生成战利品表内容。
::: code-group
```json [minecraft:block > events]
"wiki:drop_loot": {
"spawn_loot": {
"table": "loot_tables/blocks/my_loot_table.json"
}
}
```
:::
### 挥动
使关联实体执行挥动动作。
::: code-group
```json [minecraft:block > events]
"wiki:swing_arm": {
"swing": {}
}
```
:::
### 传送
将目标随机传送至目标点周围。
::: code-group
```json [minecraft:block > events]
"wiki:go_away": {
"teleport": {
"target": "other", // 被传送实体
"avoid_water": true, // 避免传入水中
"land_on_block": true, // 将目标放置在方块上
"destination": [0, 0, 0], // 目标原点
"max_range": [5, 6, 7] // 相对原点的最大偏移范围
}
}
```
:::
### 转换物品
替换目标的当前手持物品。
::: code-group
```json [minecraft:block > events]
"wiki:replace": {
"transform_item": {
"transform": "iron_sword"
}
}
```
:::
### 触发事件
触发指定目标的事件。
::: code-group
```json [minecraft:block > events]
"wiki:trigger_crack": {
"trigger": {
"event": "wiki:crack",
"target": "self"
}
}
```
:::
## 事件触发器
事件触发器通过[组件](/blocks/block-components)定义,可通过[permutations](/blocks/block-permutations)动态添加、修改或移除。
- [`minecraft:on_fall_on`](#跌落触发)
- [`minecraft:on_interact`](#交互触发)
- [`minecraft:on_placed`](#放置触发)
- [`minecraft:on_player_destroyed`](#玩家破坏触发)
- [`minecraft:on_player_placing`](#玩家放置时触发)
- [`minecraft:on_step_off`](#离开触发)
- [`minecraft:on_step_on`](#踏入触发)
- [`minecraft:queued_ticking`](#队列计时)
- [`minecraft:random_ticking`](#随机计时)
### 跌落触发
当实体跌落在方块上时触发事件。
**注意**:需要`minecraft:collision_box`组件的Y轴高度≥4。
::: code-group
```json [minecraft:block > components]
"minecraft:on_fall_on": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')", // 可选
"min_fall_distance": 5
}
```
:::
### 交互触发
当玩家与方块交互时触发事件。
::: code-group
```json [minecraft:block > components]
"minecraft:on_interact": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
```
:::
### 放置触发
当方块被放置时触发事件。
::: code-group
```json [minecraft:block > components]
"minecraft:on_placed": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
```
:::
### 玩家破坏触发
当玩家通过挖掘破坏方块时触发事件(创造模式不触发)。
::: code-group
```json [minecraft:block > components]
"minecraft:on_player_destroyed": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
```
:::
### 玩家放置时触发
当玩家放置方块时触发事件。
::: code-group
```json [minecraft:block > components]
"minecraft:on_player_placing": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
```
:::
### 离开触发
当实体离开方块时触发事件。
**注意**:需要`minecraft:collision_box`组件的Y轴高度≥4。
::: code-group
```json [minecraft:block > components]
"minecraft:on_step_off": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
```
:::
### 踏入触发
当实体踏上方块时触发事件。
**注意**:需要`minecraft:collision_box`组件的Y轴高度≥4。
::: code-group
```json [minecraft:block > components]
"minecraft:on_step_on": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
```
:::
### 队列计时
在`interval_range`范围内随机间隔触发事件。
::: code-group
```json [minecraft:block > components]
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [20, 20], // 两个游戏刻数值,随机决定延迟时间
"on_tick": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
}
```
:::
### 随机Tick
在每次随机刻触发事件(如作物随机生长机制)。
::: code-group
```json [minecraft:block > components]
"minecraft:random_ticking": {
"on_tick": {
"event": "wiki:example_event",
"target": "self", // 可选 - 默认为'self'(目标为方块)
"condition": "q.block_state('wiki:boolean_state_example')" // 可选
}
}
```
:::

View File

@@ -0,0 +1,83 @@
---
title: 方块变换(转体)
description: 方块变换数组提供了一种基于当前置换条件性应用组件的方法。
category: 常规
nav_order: 7
mentions:
- QuazChick
---
# 方块变换(转体)
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip 格式要求 & 最低引擎版本 `1.20.30`
在学习方块变换前,您应当已熟练掌握[方块状态](/blocks/block-states)知识。
使用方块状态时,请确保资源包清单中的`min_engine_version``1.20.20`或更高版本。
:::
方块`permutations`数组提供了一种基于当前置换(状态值集合)条件性应用组件(包括事件触发器和标签)的方式。
`permutations`数组中的组件可以覆盖方块的基类组件以及其他组件列表中的组件。置换数组中最后出现的条目具有最高优先级。
## 定义置换
`permutations`数组是`minecraft:block`的直接子项由包含组件的对象组成。当条件判断为真值非false或0相关组件将被应用。
**置换条件必须遵守其[Molang限制条件](#置换条件限制)。**
_自实验性玩法`Holiday Creator Features`发布支持格式版本1.19.70及更高。_
::: code-group
```json [BP/blocks/custom_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_block",
"states": {
"wiki:integer_state_example": [2, 4, 6, 8],
"wiki:boolean_state_example": [false, true],
"wiki:string_state_example": ["red", "green", "blue"]
}
},
"components": {},
"permutations": [
{
"condition": "q.block_state('wiki:integer_state_example') == 2",
"components": {
"minecraft:friction": 0.1
}
},
{
"condition": "q.block_state('wiki:boolean_state_example')",
"components": {
"minecraft:friction": 0.8 // 覆盖之前的置换
}
},
{
"condition": "q.block_state('wiki:string_state_example') == 'red' && !q.block_state('wiki:boolean_state_example')",
"components": {
"minecraft:geometry": "geometry.pig"
}
}
]
}
}
```
:::
## 置换条件限制
当条件评估为真值非false或0关联的组件列表将被应用。
置换条件需以Molang表达式字符串形式编写并具有严格限制
- 条件判断完全基于方块的置换状态,因此只能使用`q.block_state`查询函数
- 这意味着条件判断不会产生副作用
- 禁止使用以下数学函数:`math.die_roll`、`math.die_roll_integer`、`math.random`、`math.random_integer`
- 不可进行变量赋值操作
保留英文术语如Component、Entity、Block等根据中文技术文档惯例处理专有名词

View File

@@ -0,0 +1,128 @@
---
title: 方块状态
description: 方块状态允许你的方块拥有多种变体,每种变体通过使用置换具备独特的功能和外观。
category: 常规
nav_order: 4
mentions:
- QuazChick
---
# 方块状态
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip 格式要求 & 最低引擎版本 `1.20.30`
使用方块状态时,请确保资源包清单中的 `min_engine_version` 设置为 `1.20.20` 或更高。
:::
方块状态允许你的方块拥有多种变体,每种变体通过使用[置换](/blocks/block-permutations)具备独特的功能和外观。
## 定义状态
有效状态值可以定义为布尔值、整数或字符串数组,也可以通过对象定义为整数范围。`values` 数组中的第一个元素将作为默认值使用。
### 置换数量限制
**每个状态最多可定义 16 个有效值。所有可能的状态值组合([置换](/blocks/block-permutations))总数不应超过 65,536。**
计算方块置换总数时,需将所有状态的有效值数量相乘。例如下方示例的计算公式为 3 × 2 × 3 × 6说明该方块具有 108 种可能的置换组合。
_该功能需启用 `Holiday Creator Features` 实验性玩法(格式版本 1.19.70 及以上)。_
::: code-group
```json [BP/blocks/custom_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_block",
"states": {
"wiki:string_state_example": ["red", "green", "blue"],
"wiki:boolean_state_example": [false, true],
"wiki:integer_state_example": [1, 2, 3],
"wiki:integer_range_state_example": {
"values": { "min": 0, "max": 5 } // 等同于 [0, 1, 2, 3, 4, 5]
}
}
},
"components": { ... },
"permutations": [ ... ]
}
}
```
:::
## 获取状态值
以下列出在不同上下文中获取方块状态当前值的方法。
### Molang 查询函数
可通过 `block_state` 查询函数获取状态值。
```c
q.block_state('wiki:string_state_example') == 'blue'
```
### 命令参数
在 `execute` 和 `testforblock` 等命令中使用[方块状态参数](/commands/block-states)来检查状态值。
```c
execute if block ~~~ wiki:custom_block["wiki:string_state_example"="blue", "wiki:integer_state_example"=4] run kill
```
### 脚本API
:::warning 实验性功能
使用 [`BlockPermutation.getState()`](https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blockpermutation#getstate) 方法需启用 `Beta APIs` 实验性玩法。
:::
通过 [`BlockPermutation.getState()`](https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blockpermutation#getstate) 方法可获取不同状态的当前值。
```js
customBlock.permutation.getState("wiki:integer_state_example") === 3
```
## 设置状态值
### 命令参数
在 `setblock` 和 `fill` 等命令中使用[方块状态参数](/commands/block-states)来修改默认状态值。
```c
setblock ~~~ wiki:custom_block["wiki:string_state_example"="blue", "wiki:integer_state_example"=4]
```
### 脚本API
:::warning 实验性功能
使用 [`BlockPermutation.withState()`](https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blockpermutation#withstate) 方法需启用 `Beta APIs` 实验性玩法。
:::
[`BlockPermutation.withState()`](https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blockpermutation#withstate) 方法会返回修改了指定状态值的新置换对象。可通过 [`Block.setPermutation()`](https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/block#setpermutation) 方法应用此置换,如下所示:
```js
customBlock.setPermutation(
customBlock.permutation.withState("wiki:boolean_state_example", false)
);
```
### 事件响应
:::warning 实验性功能
方块事件需启用 `Holiday Creator Features` 实验性玩法。
:::
使用 [`set_block_state`](/blocks/block-events#set-block-state) 事件响应可以修改自定义方块状态的值。
::: code-group
```json [minecraft:block > events]
"wiki:change_state": {
"set_block_state": {
"wiki:boolean_state_example": false,
"wiki:string_state_example": "'red'"
}
}
```
:::

View File

@@ -0,0 +1,145 @@
---
title: 方块标签
category: 常规
nav_order: 3
mentions:
- SirLich
- yanasakana
- aexer0e
- SmokeyStack
- MedicalJewel105
- Luthorius
- Chikorita-Lover
- victorsigma
- TheItsNameless
- QuazChick
- Kaioga5
---
# 方块标签
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
方块标签可用于确保某个方块符合特定条件。
## 应用标签
方块标签的应用方式与物品标签相同 - 在方块的`components`组件中添加 - 如下所示:
::: code-group
```json [BP/blocks/tree_stump.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:tree_stump",
"menu_category": {
"category": "nature"
}
},
"components": {
"tag:wood": {},
"tag:my_lovely_tag": {},
"tag:wiki:very_useless": {}
}
}
}
```
:::
## 测试标签
可通过以下Molang查询函数检测标签
- `q.all_tags`
- `q.any_tag`
:::warning 实验性功能
以下查询函数需要启用实验性Molang功能。
:::
- `q.block_has_all_tags`
- `q.block_has_any_tag`
- `q.block_neighbor_has_all_tags`
- `q.block_neighbor_has_any_tag`
- `q.relative_block_has_all_tags`
- `q.relative_block_has_any_tag`
物品检测方块标签的示例:
::: code-group
```json [BP/items/custom_pickaxe.json]
{
"format_version": "1.20.30",
"minecraft:item": {
"description": {
"identifier": "wiki:custom_pickaxe",
"menu_category": {
"category": "equipment",
"group": "itemGroup.name.pickaxe"
}
},
"components": {
"minecraft:digger": {
"use_efficiency": true,
"destroy_speeds": [
{
"speed": 5,
"block": {
"tags": "q.any_tag('custom_ore', 'stone', 'metal')"
}
}
]
}
}
}
}
```
:::
## 方块标签列表
### 原版标签
原版标签可应用于自定义方块,部分原版方块内部已标记。此类标签不会赋予方块原版特性,仅用于通过标签查询时与原版方块保持相同检测结果。
| 标签 | 原版用途 |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| wood | 金合欢木门、金合欢木栅栏、金合欢木栅栏门、金合欢木板、金合欢木压力板、金合欢木告示牌、木桶、蜂巢、蜂箱、白桦木门、白桦木栅栏、白桦木栅栏门、白桦原木、白桦木板、白桦木压力板、白桦木告示牌、白桦木台阶、白桦木楼梯、深色橡木门、深色橡木栅栏、深色橡木栅栏门、深色橡木原木、深色橡木板、深色橡木压力板、深色橡木告示牌、深色橡木台阶、深色橡木楼梯、制箭台、丛林木门、丛林木栅栏、丛林木栅栏门、丛林原木、丛林木板、丛林压力板、丛林告示牌、丛林木台阶、丛林木楼梯、梯子、橡木门、橡木栅栏、橡木栅栏门、橡木原木、橡木板、橡木压力板、橡木告示牌、橡木台阶、橡木楼梯、橡木活板门、锻造台、云杉木门、云杉木栅栏、云杉木栅栏门、云杉原木、云杉木板、云杉木压力板、云杉木告示牌、云杉木台阶、云杉木楼梯、云杉木活板门 |
| pumpkin | 雕刻过的南瓜、南瓜灯、南瓜 |
| plant | 金合欢树苗、白桦树苗、深色橡树苗、丛林树苗、大型蕨、丁香、橡树苗、牡丹、玫瑰丛、云杉树苗、向日葵、高草丛 |
| stone | 安山岩、安山岩墙、砖台阶、砖墙、砖块、圆石、圆石台阶、圆石楼梯、圆石墙、闪长岩、闪长岩墙、滴水石块、末地石砖墙、花岗岩、花岗岩墙、苔石、苔石墙、下界砖墙、磨制安山岩、磨制闪长岩、磨制花岗岩、海晶石墙、石英台阶、红色下界砖墙、红砂岩墙、砂岩台阶、砂岩墙、平滑石台阶、石头、石砖墙、石砖台阶 |
| metal | 金块、铁块、炼药锅、铁栏杆 |
| diamond_pick_diggable | 粗金块、粗铁块、煤矿石、深层煤矿石、深层绿宝石矿石、深层金矿石、深层铁矿石、深层红石矿石、钻石矿石、绿宝石矿石、金矿石、铁矿石、青金石矿石、黑曜石、红石矿石 |
| gold_pick_diggable | (无内容) |
| iron_pick_diggable | 粗金块、粗铁块、煤矿石、深层煤矿石、深层绿宝石矿石、深层金矿石、深层铁矿石、深层红石矿石、钻石矿石、绿宝石矿石、金矿石、铁矿石、青金石矿石、红石矿石 |
| stone_pick_diggable | (无内容) |
| wood_pick_diggable | (无内容) |
| dirt | 耕地 |
| sand | 红沙、沙子 |
| gravel | 沙砾 |
| grass | 砂土、泥土、草径、草方块 |
| snow | 雪 |
| rail | 激活铁轨、探测铁轨、动力铁轨、铁轨 |
| water | 水 |
| mob_spawner | 刷怪笼 |
| lush_plants_replaceable | (无内容) |
| azalea_log_replaceable | (无内容) |
| not_feature_replaceable | 基岩、箱子、末地传送门框架、刷怪笼 |
| text_sign | 所有种类的告示牌 |
| minecraft:crop | 甜菜根、胡萝卜、马铃薯、小麦 |
| fertilize_area | 所有花卉(除高茎花卉和凋灵玫瑰外);绯红菌岩、诡异菌岩、草、苔藓块 |
### 原版方块标签
原版方块标签是专门为方块设计的标签,可以为标记的方块赋予某些原版特性。
| 标签 | 原版应用 | 描述 |
| -------- | ---------------- | ------------ |
| acacia | 金合欢原木 | |
| birch | 白桦原木 | |
| dark_oak | 深色橡木原木 | |
| jungle | 丛林原木 | |
| log | 所有原木类型 | 原木方块 |
| oak | 橡木原木 | |
| spruce | 云杉原木 | |

View File

@@ -0,0 +1,110 @@
---
title: 方块特性
description: 方块特性可轻松为自定义方块应用原版方块状态(如朝向),无需借助事件和触发器。
category: 常规
nav_order: 5
mentions:
- QuazChick
---
# 方块特性
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip 格式要求 & 最低引擎版本 `1.20.30`
在学习方块特性前,您应当已熟练掌握[方块状态](/blocks/block-states)知识。
使用方块状态时,请确保资源包清单中的`min_engine_version``1.20.20`或更高版本。
:::
## 应用特性
方块特性可轻松为自定义方块应用原版方块状态(如朝向),无需借助复杂的事件和触发器系统。
::: code-group
```json [BP/blocks/custom_slab.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_slab",
"menu_category": {
"category": "construction",
"group": "itemGroup.name.slab"
},
"traits": {
"minecraft:placement_position": {
"enabled_states": ["minecraft:vertical_half"]
}
}
},
"components": { ... },
"permutations": [ ... ]
}
}
```
:::
_此示例将在放置时设置`minecraft:vertical_half`方块状态为`'top'`或`'bottom'`——具体取决于玩家视角位置。_
**仍需通过置换系统配合条件查询来实现功能差异:**
```c
q.block_state('minecraft:vertical_half') // 查询垂直半区状态
```
## 放置朝向
记录玩家放置方块时的旋转方向信息。
_自实验性玩法`Upcoming Creator Features`发布支持格式版本1.20.30及更高。_
**可启用以下状态:**
| 状态名称 | 可选值 | 描述 |
| ------------------------------ | -------------------------------------------------------------------------------- | ---------------------------------- |
| `minecraft:cardinal_direction` | `"south"`(默认)<br>`"north"`<br>`"west"`<br>`"east"` | 放置时玩家的主要朝向(东南西北) |
| `minecraft:facing_direction` | `"down"`(默认)<br>`"up"`<br>`"south"`<br>`"north"`<br>`"west"`<br>`"east"` | 放置时玩家的完整朝向(含上下方向) |
<br>
**额外参数:**
- `y_rotation_offset` - 此旋转偏移仅适用于水平方向状态值(北/南/西/东必须指定轴对齐角度如90、180、-90
::: code-group
```json [minecraft:block > description > traits]
"minecraft:placement_direction": {
"enabled_states": ["minecraft:cardinal_direction"],
"y_rotation_offset": 180 // Y轴旋转偏移量
}
```
:::
## 放置位置
记录玩家放置方块时的具体位置信息。
_自实验性玩法`Upcoming Creator Features`发布支持格式版本1.20.30及更高。_
**可启用以下状态:**
| 状态名称 | 可选值 | 描述 |
| ------------------------- | -------------------------------------------------------------------------------- | ----------------------------- |
| `minecraft:block_face` | `"down"`(默认)<br>`"up"`<br>`"south"`<br>`"north"`<br>`"west"`<br>`"east"` | 方块被放置时所处的表面方位 |
| `minecraft:vertical_half` | `"top"`<br>`"bottom"`(默认) | 方块被放置时所处的垂直半区位置 |
<br>
**_此特性无额外参数_**
::: code-group
```json [minecraft:block > description > traits]
"minecraft:placement_position": {
"enabled_states": [
"minecraft:block_face", // 方块表面方位
"minecraft:vertical_half" // 垂直半区位置
]
}
```
:::

View File

@@ -0,0 +1,62 @@
---
title: 实验性方块
category: 通用
tags:
- 信息
- 实验性
mentions:
- SmokeyStack
- MedicalJewel105
- QuazChick
---
# 实验性方块
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip 格式版本 `1.20.30`
在创建自定义方块时使用最新格式版本,可获取最新功能和改进。本维基旨在分享自定义方块的最新信息,当前目标格式版本为 `1.20.30`
:::
本文作为索引文档,概述自定义方块功能的实验性要求。
## 方块组件
| 组件 | 所需实验性功能 |
| ------------------------------------------------------------------------------------------- | --------------------------------- |
| [`minecraft:collision_box`](/blocks/block-components#collision-box) | 无格式版本1.19.50及以上) |
| [`minecraft:crafting_table`](/blocks/block-components#crafting-table) | 无格式版本1.19.50及以上) |
| [`minecraft:destructible_by_explosion`](/blocks/block-components#destructible-by-explosion) | 无 |
| [`minecraft:destructible_by_mining`](/blocks/block-components#destructible-by-mining) | 无 |
| [`minecraft:display_name`](/blocks/block-components#display-name) | 无格式版本1.19.60及以上) |
| [`minecraft:flammable`](/blocks/block-components#flammable) | 无 |
| [`minecraft:friction`](/blocks/block-components#friction) | 无 |
| [`minecraft:geometry`](/blocks/block-components#geometry) | 无格式版本1.19.40及以上) |
| [`minecraft:light_dampening`](/blocks/block-components#light-dampening) | 无 |
| [`minecraft:light_emission`](/blocks/block-components#light-emission) | 无 |
| [`minecraft:loot`](/blocks/block-components#loot) | 无 |
| [`minecraft:map_color`](/blocks/block-components#map-color) | 无 |
| [`minecraft:material_instances`](/blocks/block-components#material-instances) | 无格式版本1.19.40及以上) |
| [`minecraft:placement_filter`](/blocks/block-components#placement-filter) | 无格式版本1.19.60及以上) |
| [`minecraft:selection_box`](/blocks/block-components#selection-box) | 无格式版本1.19.60及以上) |
| [`minecraft:transformation`](/blocks/block-components#transformation) | 无 |
| [`minecraft:unit_cube`](/blocks/block-components#unit-cube) | **`假日创作者功能Holiday Creator Features`** |
## 方块状态
_从实验性功能 **`假日创作者功能`** 中释放适用于格式版本1.19.70及以上。_
## 方块特性
| 特性 | 所需实验性功能 |
| ------------------------------------------------------------------------------- | --------------------------------- |
| [`minecraft:placement_direction`](/blocks/block-components#placement-direction) | 无格式版本1.20.20及以上) |
| [`minecraft:placement_position`](/blocks/block-components#placement-position) | 无格式版本1.20.20及以上) |
## 方块置换
_从实验性功能 **`假日创作者功能`** 中释放适用于格式版本1.19.70及以上。_
## 方块事件与触发器
**完整功能仍处于实验性阶段,需启用 `假日创作者功能`。**

View File

@@ -0,0 +1,322 @@
---
title: 方块入门
description: A "Hello world" guide in making blocks. Learn the block format and how to create basic custom blocks.
category: General
nav_order: 1
---
# 方块入门
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip 格式版本 & 最低引擎版本 `1.20.30`
本页介绍基础方块特性。更多方块组件内容请访问[此处](/blocks/block-components)。
:::
:::danger <nbsp/>
原版方块的逻辑是硬编码实现的,无法被修改或访问。
:::
Minecraft 基岩版允许我们添加具有多种类原版特性的自定义方块。自定义方块可以拥有多阶段生长(如植物)、方向朝向等实用功能。
本教程将指导如何在稳定版 Minecraft 中创建基础方块。
## 注册方块
方块定义的结构与实体类似:包含行为描述和定义方块特性的组件列表。
与实体不同,方块除`RP/blocks.json`外没有其他资源定义。
以下是将自定义方块加入创造模式物品栏所需的**最低限度**行为包代码:
::: code-group
```json [BP/blocks/custom_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_block",
"menu_category": {
"category": "construction", // 方块所在的创造模式物品栏或配方书标签
"group": "itemGroup.name.concrete", // 方块所属的可展开分组(可选)
"is_hidden_in_commands": false // 是否在命令中隐藏该方块(可选)
}
},
"components": {} // 必须保留,即使为空!
}
}
```
:::
### 方块描述
- 定义方块的`identifier` - 采用`命名空间:标识符`格式的唯一ID
- 配置方块的`menu_category`归属
- 可选参数`group`和`is_hidden_in_commands`
_方块描述还包含[状态](/blocks/block-states)和[特性](/blocks/block-traits)相关内容请参见对应页面。_
## 添加组件
目前我们的自定义方块使用的是默认组件值(可参考[此处](/blocks/block-components))。
现在开始自定义功能配置!
::: code-group
```json [BP/blocks/custom_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_block",
"menu_category": {
"category": "construction"
}
},
"components": {
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 3
},
"minecraft:destructible_by_explosion": {
"explosion_resistance": 3
},
"minecraft:friction": 0.4,
"minecraft:map_color": "#ffffff",
"minecraft:light_dampening": 0,
"minecraft:light_emission": 4,
"minecraft:loot": "loot_tables/blocks/custom_block.json"
}
}
}
```
:::
- [`minecraft:destructible_by_mining`](/blocks/block-components#destructible-by-mining) 定义玩家破坏方块所需时间(目前无法为不同工具设置不同破坏时间)
- [`minecraft:destructible_by_explosion`](/blocks/block-components#destructible-by-explosion) 定义抗爆性。值越高,被炸毁概率越低
- [`minecraft:friction`](/blocks/block-components#friction) 定义方块摩擦系数。例如灵魂沙具有高摩擦值会减缓玩家,冰的低摩擦值则产生滑溜效果。经典方块(如木头/石头)的摩擦系数为`0.4`
- [`minecraft:map_color`](/blocks/block-components#map-color) 是地图上显示的代表色(十六进制)。`#ffffff`代表白色,可通过[在线取色器](https://www.google.com/search?q=hex+color+picker)获取其他颜色代码
- [`minecraft:light_dampening`](/blocks/block-components#light-dampening) 定义光线阻挡程度
- [`minecraft:light_emission`](/blocks/block-components#light-emission) 定义方块发光等级
- [`minecraft:loot`](/blocks/block-components#loot) 定义战利品表路径。若移除,方块将默认掉落自身。更多战利品表信息请访问[此处](/loot/loot-tables)
_更多组件配置请访问[方块组件手册](/blocks/block-components)!_
## 应用纹理
:::warning
`RP/blocks.json`会忽略命名空间。即使不写命名空间或随意填写也不会产生影响。若自定义方块与原版方块同名(仅命名空间不同)可能导致问题
:::
:::tip <nbsp/>
[方块音效](/blocks/block-sounds)也可在`RP/blocks.json`中定义
:::
对于基础的16×16×16像素方块纹理应在`RP/blocks.json`中定义。
如需使用自定义模型,应使用[geometry几何组件](/blocks/block-components#geometry)和[material_instances材质实例](/blocks/block-components#material-instances)。
::: code-group
```json [RP/blocks.json]
{
"format_version": [1, 1, 0],
"wiki:custom_block": {
"textures": "custom_block", // 此纹理简称需在下方terrain_texture.json中定义
"sound": "grass"
}
}
```
:::
现在需要在`RP/textures/terrain_texture.json`中关联纹理简称与图片路径:
::: code-group
```json [RP/textures/terrain_texture.json]
{
"texture_name": "atlas.terrain",
"resource_pack_name": "wiki", // 资源包ID
"padding": 8, // 防止纹理视觉溢出
"num_mip_levels": 4, // 远距离/倾斜视角下的纹理质量
"texture_data": {
// 我们的纹理简称:
"custom_block": {
"textures": "textures/blocks/custom_block" // 指向图片文件名
}
}
}
```
:::
### 分面纹理
纹理可按面分别设置。例如一个自定义"指南针方块"可使用以下✨惊艳✨纹理:
`textures/blocks/compass_block_down.png`
<WikiImage src="/assets/images/blocks/blocks-intro/compass_block_down.png" pixelated="true" width="64"/>
`textures/blocks/compass_block_up.png`
<WikiImage src="/assets/images/blocks/blocks-intro/compass_block_up.png" pixelated="true" width="64"/>
`textures/blocks/compass_block_north.png`
<WikiImage src="/assets/images/blocks/blocks-intro/compass_block_north.png" pixelated="true" width="64"/>
`textures/blocks/compass_block_east.png`
<WikiImage src="/assets/images/blocks/blocks-intro/compass_block_east.png" pixelated="true" width="64"/>
`textures/blocks/compass_block_south.png`
<WikiImage src="/assets/images/blocks/blocks-intro/compass_block_south.png" pixelated="true" width="64"/>
`textures/blocks/compass_block_west.png`
<WikiImage src="/assets/images/blocks/blocks-intro/compass_block_west.png" pixelated="true" width="64"/>
<br>
<br>
对应的`blocks.json`配置如下:
::: code-group
```json [RP/blocks.json]
{
"format_version": [1, 1, 0],
"wiki:compass_block": {
"textures": {
"down": "compass_block_down",
"up": "compass_block_up",
"north": "compass_block_north",
"east": "compass_block_east",
"south": "compass_block_south",
"west": "compass_block_west"
}
}
}
```
:::
<br>
若使用[材质实例](/blocks/block-components#material-instances),配置示例如下:
::: code-group
```json [minecraft:block > components]
"minecraft:material_instances": {
"*": {
"texture": "compass_block_down" // 此纹理用于破坏粒子效果
},
"up": {
"texture": "compass_block_up"
},
"north": {
"texture": "compass_block_north"
},
"east": {
"texture": "compass_block_east"
},
"south": {
"texture": "compass_block_south"
},
"west": {
"texture": "compass_block_west"
}
}
```
:::
对应的`terrain_texture.json`数据:
::: code-group
```json [RP/textures/terrain_texture.json]
{
"texture_name": "atlas.terrain",
"resource_pack_name": "wiki",
"padding": 8,
"num_mip_levels": 4,
"texture_data": {
"compass_block_down": {
"textures": "textures/blocks/compass_block_down"
},
"compass_block_up": {
"textures": "textures/blocks/compass_block_up"
},
"compass_block_north": {
"textures": "textures/blocks/compass_block_north"
},
"compass_block_east": {
"textures": "textures/blocks/compass_block_east"
},
"compass_block_west": {
"textures": "textures/blocks/compass_block_west"
},
"compass_block_south": {
"textures": "textures/blocks/compass_block_south"
}
}
}
```
:::
## 定义名称
最后定义方块的显示名称:
::: code-group
```c [RP/texts/en_US.lang]
tile.wiki:custom_block.name=自定义方块
tile.wiki:compass_block.name=指南针方块
```
:::
更多本地化内容请访问[文本与翻译指南](/concepts/text-and-translations)。
## 成果总结
通过本教程,您已掌握:
<Checklist>
- [x] 方块基础特性
- [x] 如何应用统一纹理
- [x] 如何设置分面纹理
</Checklist>
...但这只是开始,更多精彩内容等待探索!
## 下一步学习
<div class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-5 m-0 p-0">
<Card
title="扩展功能"
imgsrc-light="assets/images/homepage/crafting_table_0.png"
link="/blocks/block-components">
学习各类可用[方块组件](/blocks/block-components)打造独特玩法。
<br><br>
使用[geometry几何组件](/blocks/block-components#geometry)为方块添加自定义模型!还可以通过[collision_box碰撞箱](/blocks/block-components#collision-box)和[selection_box选择框](/blocks/block-components#selection-box)配置物理交互区域。
</Card>
<Card
title="创建变体"
imgsrc-light="assets/images/homepage/scripting.png">
利用[方块状态](/blocks/block-states)和[permutations状态切换](/blocks/block-permutations)实现条件触发的组件功能。
<br><br>
例如为储液罐方块添加多级液面高度功能,并支持多种液体类型。
</Card>
<Card
title="复刻原版"
imgsrc-light="assets/images/homepage/diamond_ore_0.png"
link="/blocks/block-components">
在<b class="orange px-1 rounded-md">原版复刻</b>分类中查看多个完整实现案例。
<br><br>
从简单的[自定义玻璃方块](/blocks/custom-glass-blocks)开始,体验[material_instances材质实例](/blocks/block-components#material-instances)的应用!
</Card>
</div>

View File

@@ -0,0 +1,271 @@
---
title: 方块故障排除
category: 常规
tags:
- help
mentions:
- SmokeyStack
- SirLich
- aexer0e
- MedicalJewel105
- Sprunkles137
- QuazChick
---
# 方块故障排除
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::tip
本页包含关于_方块_的故障排除信息。在继续阅读前建议先查阅我们的[全局故障排除指南](/guide/troubleshooting)。
:::
## 0.0 - 常见问题
> "我按照教程制作方块时遇到了问题!"
无需惊慌!本页将帮助您排查常见问题。
## 1.0 - 纹理问题排查
修复与方块纹理相关的常见问题。
## 1.1 - 纹理显示为黑紫相间
我们将分析三种不同布局的方块类型:
- 类似泥土的方块 ![](/assets/images/blocks/block_tr/tr_dirt.png)
- 类似原木的方块 ![](/assets/images/blocks/block_tr/tr_log.png)
- 类似草块的方块 ![](/assets/images/blocks/block_tr/tr_grass.png)
请定位至 `RP/textures/terrain_texture.json` 文件,确保文件名正确。
::: code-group
```json [RP/textures/terrain_texture.json]
{
"texture_name": "atlas.terrain",
"resource_pack_name": "wiki",
"padding": 8,
"num_mip_levels": 4,
"texture_data": {
"dirt_like": {
"textures": "textures/blocks/dirt_like" // 此处可替换为任意内容,但需记住此名称
},
"log_like_top": {
"textures": "textures/blocks/log_like_top" // 此处可替换为任意内容,但需记住此名称
},
"log_like_side": {
"textures": "textures/blocks/log_like_side" // 此处可替换为任意内容,但需记住此名称
},
"custom_grass_top": {
"textures": "textures/blocks/custom_grass_top" // 此处可替换为任意内容,但需记住此名称
},
"custom_grass_bottom": {
"textures": "textures/blocks/custom_grass_bottom" // 此处可替换为任意内容,但需记住此名称
},
"custom_grass_side": {
"textures": "textures/blocks/custom_grass_side" // 此处可替换为任意内容,但需记住此名称
}
}
}
```
:::
接下来检查方块配置文件,确保包含 `material_instances` 组件。
类似泥土的方块配置示例:
::: code-group
```json [BP/blocks/dirt_like.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:dirt_like"
},
"components": {
"minecraft:material_instances": {
"*": {
"texture": "dirt_like"
}
}
}
}
}
```
:::
类似原木的方块配置示例:
::: code-group
```json [BP/blocks/log_like.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:log_like"
},
"components": {
"minecraft:material_instances": {
"*": {
"texture": "log_like_side"
},
"end": {
"texture": "log_like_top"
},
"up": "end",
"down": "end"
}
}
}
}
```
:::
类似草块的配置示例:
::: code-group
```json [BP/blocks/custom_grass.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_grass"
},
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_grass_side"
},
"up": {
"texture": "custom_grass_top"
},
"down": {
"texture": "custom_grass_bottom"
}
}
}
}
}
```
:::
正确配置后,方块的纹理应正常显示。
## 1.2 - 纹理显示为带"Update"字样的泥土块
问题现象:自定义方块变成带有绿色文字的泥土方块。
![](/assets/images/blocks/block_tr/tr_update.png)
这是_未知方块_的标识通常由以下原因引起
- 方块标识符被修改
- 方块JSON文件格式错误
解决方案:
1. 使用JSON校验工具检查文件格式
2. 确认方块标识符未更改
3. 确保方块配置包含以下任意组件:
- `minecraft:unit_cube`
- `minecraft:geometry`
- `minecraft:material_instances`
- 或正确配置了 `RP/blocks.json` 中的纹理条目
## 2.0 - 渲染问题排查
本节将描述常见的方块渲染问题及解决方案。
## 2.1 - 透明效果失效
问题现象:纹理中的透明像素在游戏中显示为不透明。
解决方案:在方块的 `material_instances` 组件中添加渲染方法:
::: code-group
```json [BP/blocks/your_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
...
"components": {
"minecraft:material_instances": {
"*": {
"render_method": "alpha_test"
}
}
}
}
}
```
:::
## 2.2 - 方块产生阴影
问题现象:自定义几何体方块产生阴影。
解决方案:在方块组件中添加光照衰减配置:
::: code-group
```json [minecraft:block > components]
"minecraft:light_dampening": 0
```
:::
## 2.3 - 模型立方体在物品栏中重叠
问题现象:自定义几何体方块在物品栏中呈现异常堆叠:
![](/assets/images/blocks/block_tr/inventory_render_cubes.png)
解决方案在Blockbench中调整立方体绘制顺序从下到上
```
cube_middle cube_bottom
cube_top -> cube_middle
cube_bottom cube_top
```
## 2.4 - 方块在物品栏中显示过小
问题现象16³标准尺寸方块在物品栏中比原版方块小。
解决方案分析:
- 使用 `RP/blocks.json` 配置纹理可使方块正常显示,但无法使用自定义模型
- 使用 `material_instances` 组件时需配合以下配置:
- 添加旋转组件需同时配置材质实例
- 使用单位立方体或自定义几何体
- 确保基础状态使用 `blocks.json` 配置
---
## 3.0 - 常见日志错误
本节将解析常见的日志报错信息。
## 3.1 - 碰撞/选择框错误
典型错误提示:
> `[Blocks][error]-minecraft:collision_box: min 值不能低于 (-8, 0, -8)max 值不能超过 (8, 16, 8)`
排查步骤:
- 检查 X/Z 轴数值是否在 -8 至 8 范围内
- 检查 Y 轴数值是否在 0 至 16 范围内
- 确保碰撞框不超过 16×16×16 单位区域
## 3.2 - 模型尺寸错误
典型错误提示:
> `geometry.your_block 包含 X 个超出范围的立方体...`
解决方案:
- 缩小几何体尺寸
- 将大型模型拆分为多个方块
---
## 后续步骤
若问题仍未解决欢迎加入Discord社区交流。如发现文档内容有误请通过GitHub提交修正建议

View File

@@ -0,0 +1,190 @@
---
title: 创建方块模型
category: 教程
tags:
- 新手
- 简单
mentions:
- QuazChick
---
# 创建方块模型
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
尽管自定义方块无法使用原版的[方块形状](/blocks/block-shapes),但我们可以创建遵循类似实体模型格式的自定义模型。本教程将引导您使用[Blockbench](https://blockbench.net)为"纸袋"创建自定义方块模型。通过学习本教程您将掌握专为自定义方块设计的Minecraft几何体核心功能。
**注意:** 自定义方块模型必须符合[模型尺寸限制](/blocks/block-components.html#geometry)。
## 模型设置
打开Blockbench并新建一个`Bedrock Block`项目。
![新建项目面板中选择Bedrock Block](/assets/images/blocks/block-models/new_project.png)
现在可以为模型设置标识符!您可以在此处决定文件名,或稍后修改。
UV模式和纹理尺寸应保持不变。
:::danger 命名空间
模型标识符**不使用命名空间且不能包含冒号**。冒号曾用于模型继承,在现代几何格式中已失效。
:::
![](/assets/images/blocks/block-models/project_settings.png)
## 添加立方体
虽然不一定是完美立方体,但模型中的元素都称为**立方体**。所有立方体必须包含在作为分组的**骨骼**中。
首先通过大纲视图点击`Add Group`创建根骨骼。按`F2`可重命名骨骼。
![](/assets/images/blocks/block-models/root_bone.png)
"纸袋"模型需要两个立方体:一个作为提手,一个作为主体。选择根骨骼后点击`Add Cube`添加。
<WikiImage
src="/assets/images/blocks/block-models/new_cube.png"
alt
width="600"
class="my-4"
/>
通过顶部工具栏可移动、缩放和旋转立方体。以下是"paper_bag"模型使用的两个立方体:
<WikiImage
src="/assets/images/blocks/block-models/paper_bag_cubes.png"
alt
width="300"
class="my-4"
/>
## 移除面
某些面可能无需可见。在示例中,移除纸袋顶部面以实现透视效果。
点击预览中的面在UV面板删除其UV映射即可移除。
<WikiImage
src="/assets/images/blocks/block-models/paper_bag_top_removed.png"
alt
width="600"
class="my-4"
/>
提手仅需保留南北面。在UV面板按住Ctrl可多选面名称进行操作。
<WikiImage
src="/assets/images/blocks/block-models/paper_bag_handle_faces_removed.png"
alt
width="600"
class="my-4"
/>
## 预览纹理
:::tip
点击`Create Texture`选择`Blank`即可在Blockbench中创建纹理。
:::
"纸袋"模型包含以下预制纹理:
- `textures/blocks/paper_bag.png`
<WikiImage src="/assets/images/blocks/block-models/paper_bag.png" style="background-color: rgb(0,0,0,0.15);" pixelated="true" width="128"/>
<br>
<br>
- `textures/blocks/paper_bag_bottom_fold.png`
<WikiImage src="/assets/images/blocks/block-models/paper_bag_bottom_fold.png" style="background-color: rgb(0,0,0,0.15);" pixelated="true" width="128"/>
<br>
<br>
- `textures/blocks/paper_bag_side_gusset.png`
<WikiImage src="/assets/images/blocks/block-models/paper_bag_side_gusset.png" style="background-color: rgb(0,0,0,0.15);" pixelated="true" width="128"/>
将纹理导入Blockbench后拖拽至对应面初始效果可能不够理想...
<WikiImage
src="/assets/images/blocks/block-models/preview_textures_applied.png"
alt
width="300"
class="my-4"
/>
## 调整UV布局
通过UV面板重新定位/缩放面的UV映射来修正纹理位置。选择目标面后操作UV面板即可。
<WikiImage
src="/assets/images/blocks/block-models/paper_bag_handle_uv.png"
alt
width="300"
class="my-4"
/>
<br>
<WikiImage
src="/assets/images/blocks/block-models/paper_bag_final.png"
alt
width="300"
class="my-4"
/>
## 修改材质实例
自定义材质实例名称可便捷定义面渲染方式。
右键立方体选择`Edit Material Instances`进行编辑。
![](/assets/images/blocks/block-models/select_edit_material_instances.png)
在示例中,东西面需要独立纹理。通过分配材质实例实现。
![](/assets/images/blocks/block-models/edit_material_instances.png)
## 应用几何体与纹理
通过`File > Export > Export Bedrock Geometry`导出至`RP/models/blocks`文件夹后即可在方块JSON中引用模型。
通过`RP/textures/terrian_texture.json`短名称应用纹理。本例中纸袋不遮挡光线故设置光照衰减为0。
::: code-group
```json [BP/blocks/paper_bag.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:paper_bag",
"menu_category": {
"category": "items"
}
},
"components": {
// 通过引用模型标识符应用模型
"minecraft:geometry": "geometry.paper_bag",
// 应用纹理及其他渲染配置
"minecraft:material_instances": {
"*": {
"texture": "paper_bag",
"render_method": "alpha_test" // 禁用背面剔除并启用透明
},
"down": {
"texture": "paper_bag_bottom_fold",
"render_method": "alpha_test" // 所有实例必须保持一致
},
// 模型中使用的自定义实例名称
"side_gusset": {
"texture": "paper_bag_side_gusset",
"render_method": "alpha_test" // 所有实例必须保持一致
}
},
// 防止产生阴影
"minecraft:light_dampening": 0
}
}
}
```
:::

View File

@@ -0,0 +1,183 @@
---
title: 持续效果应用指南
category: 教程
tags:
- 实验性内容
- 初级难度
mentions:
- MysticChair
- SirLich
- MedicalJewel105
- QuazChick
---
# 持续效果应用指南
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
::: tip 格式要求 & 最低引擎版本 `1.20.30`
本教程假设您已掌握[方块状态](/blocks/block-states)的基本概念。建议在开始前先阅读[方块基础指南](/blocks/blocks-intro)。
:::
::: warning 实验性功能
需要启用 `假日创作者功能` 来触发事件。
:::
本教程将展示如何在实体持续站立于方块时为其附加状态效果。
## 设置步骤
我们需要在代码中添加以下组件,首先创建一个用于记录站立状态的布尔值:
::: code-group
```json [minecraft:block > description]
"states": {
"wiki:stood_on": [false, true]
}
```
:::
接下来添加 `minecraft:queued_ticking` 组件,当检测到站立状态为 `true` 时触发效果事件:
::: code-group
```json [minecraft:block > components]
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [1, 1],
"on_tick": {
"event": "wiki:add_effect",
"target": "self",
"condition": "q.block_state('wiki:stood_on')"
}
}
```
:::
使用 `minecraft:on_step_on` 事件组件在实体踏上方块时更新状态:
::: code-group
```json [minecraft:block > components]
"minecraft:on_step_on": {
"event": "wiki:step_on"
}
```
:::
通过 `minecraft:on_step_off` 事件组件在实体离开时重置状态:
::: code-group
```json [minecraft:block > description]
"minecraft:on_step_off": {
"event": "wiki:step_off"
}
```
:::
配置事件处理逻辑。首先定义状态更新事件:
::: code-group
```json [minecraft:block > components]
"events": {
"wiki:step_on": {
"set_block_state": {
"wiki:stood_on": true
}
},
"wiki:step_off": {
"set_block_state": {
"wiki:stood_on": false
}
}
}
```
:::
最后添加效果触发事件:
::: code-group
```json [minecraft:block > components]
"wiki:add_effect": {
"run_command": {
"command": "effect @e[r=1] wither 2 2"
}
}
```
:::
完成!上述代码将在实体持续站立时施加凋零效果。
## 示例JSON
<Spoiler title="凋零方块实现案例">
::: code-group
```json [BP/blocks/wither_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:wither_block",
"menu_category": {
"category": "nature"
},
"states": {
"wiki:stood_on": [false, true]
}
},
"components": {
"minecraft:geometry": "geometry.wither_block",
"minecraft:material_instances": {
"*": {
"texture": "wither_block"
}
},
"minecraft:loot": "loot_tables/empty.json",
"minecraft:on_step_on": {
"event": "wiki:step_on"
},
"minecraft:on_step_off": {
"event": "wiki:step_off"
},
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [1, 1],
"on_tick": {
"event": "wiki:add_effect",
"condition": "q.block_state('wiki:stood_on')"
}
},
"minecraft:map_color": "#181818"
},
"events": {
"wiki:step_on": {
"set_block_state": {
"wiki:stood_on": true
}
},
"wiki:step_off": {
"set_block_state": {
"wiki:stood_on": false
}
},
"wiki:add_effect": {
"run_command": {
"command": "effect @e[r=1] wither 2 2"
}
}
}
}
}
```
:::
</Spoiler>
## 技术说明
关于代码实现的几点说明:
- **问**:为何使用 `run_command` 事件响应来触发效果,而不是专用的 `add_mob_effect` 响应?
- **答**:当通过 `minecraft:queued_ticking` 触发时,`add_mob_effect` 无法获取有效目标,因此必须改用 `/effect` 命令的目标选择器。
注意当效果时长设置小于2秒时可能出现异常。如果效果会造成持续伤害如中毒伤害会在效果施加时立即生效。这将导致实体受到的伤害频率高于原版机制当实体快速移动时。可通过将命令中的效果时长设为1秒进行对比测试。保持2秒时长可确保伤害间隔符合原版节奏。

View File

@@ -0,0 +1,74 @@
---
title: 规避状态值上限
category: 教程
tags:
- 专家
mentions:
- Kaioga5
- QuazChick
---
# 规避状态值上限
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
## 前言
方块每个状态最多只能拥有16个有效状态值。本指南将解释如何避免触及这个上限。
:::tip
本教程不会直接展示如何突破16个状态值的限制但通过以下方法可以模拟实现类似效果
:::
## 实现原理
该方法通过组合两个或多个状态值进行复用并在排列组合或条件判断中读取这些组合值。例如一个需要表示26个英文字母的方块可以通过数值组合的方式减少状态值数量。
## 逻辑推演
以下示例代码演示了如何通过组合实现字母映射:
```
1 & 1 = A 1 & 5 = E 1 & 9 = I 1 & 13 = M
1 & 2 = B 1 & 6 = F 1 & 10 = J
1 & 3 = C 1 & 7 = G 1 & 11 = K
1 & 4 = D 1 & 8 = H 1 & 12 = L
```
继续扩展:
```
2 & 1 = N 2 & 5 = R 2 & 9 = V 2 & 13 = Z
2 & 2 = O 2 & 6 = S 2 & 10 = W
2 & 3 = P 2 & 7 = T 2 & 11 = X
2 & 4 = Q 2 & 8 = U 2 & 12 = Y
```
通过这种组合方式仅需15个状态值即可实现26个字母的映射。可用组合值越多状态上限的扩展空间就越大。
## 实际应用
参照上述示例,您的状态定义应如下所示:
::: code-group
```json [minecraft:block > description]
"states": {
"wiki:value": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
"wiki:division": [1, 2]
}
```
:::
对应的条件判断语句应如下编写:
```json
"condition": "q.block_state('wiki:division') == 1 && q.block_state('wiki:value') == 1"
```
```json
"condition": "q.block_state('wiki:division') == 1 && q.block_state('wiki:value') == 2"
```
## 知识总结
您已掌握如何通过状态值组合突破64个状态值的限制使用更少的资源实现更复杂的逻辑。
:::tip
通过增加组合维度使用2个以上的状态值您可以获得更多可能的组合结果。
:::

View File

@@ -0,0 +1,84 @@
---
title: 纹理变体
category: 教程
tags:
- 中级
mentions:
- SirLich
- solvedDev
- Hatchibombotar
- SmokeyStack
- MedicalJewel105
- QuazChick
---
# 纹理变体
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
方块纹理变体是指单个方块可以拥有多个纹理。这在需要表现细微差异的方块(如带有小石块的泥土或不同生长阶段的草方块)时非常实用。
要启用纹理变体功能,需在资源包的`textures`文件夹中创建`terrain_texture.json`文件。在方块定义中,纹理应设置为包含`variations`键的字典,该键对应一个由字典组成的数组。每个字典必须包含指向纹理文件的`path`键,并可添加`weight`参数控制纹理出现的概率。
## 应用纹理变体
以下是为泥土方块创建三种纹理变体的示例:
- 在资源包中创建`textures/terrain_texture.json`文件
- 在JSON文件中定义需要添加变体的方块示例如下
::: code-group
```json [RP/textures/terrain_texture.json]
{
"texture_name": "atlas.terrain",
"resource_pack_name": "wiki", // 资源包ID
"padding": 8, // 防止纹理视觉溢出
"num_mip_levels": 4, // 远距离/倾斜视角下的纹理质量
"texture_data": {
"dirt": {
"textures": {
"variations": [
{ "path": "textures/blocks/dirt0" },
{ "path": "textures/blocks/dirt1" },
{ "path": "textures/blocks/dirt2" }
]
}
}
}
}
```
:::
- 创建或修改三个泥土纹理文件,分别命名为`dirt0.png`、`dirt1.png`和`dirt2.png`
- 将纹理文件放置于`path`参数指定的路径下(可添加子文件夹保持整洁)
## 权重控制变体分布
完成基础配置后,可通过添加权重值调整纹理出现概率:
::: code-group
```json [RP/textures/terrain_texture.json]
{
"texture_name": "atlas.terrain",
"resource_pack_name": "wiki", // 资源包ID
"padding": 8, // 防止纹理视觉溢出
"num_mip_levels": 4, // 远距离/倾斜视角下的纹理质量
"texture_data": {
"dirt": {
"textures": {
"variations": [
{ "path": "textures/blocks/dirt0", "weight": 70 }, // 70%出现概率
{ "path": "textures/blocks/dirt1", "weight": 20 }, // 20%出现概率
{ "path": "textures/blocks/dirt2", "weight": 10 } // 10%出现概率
]
}
}
}
}
```
:::
注意事项:
- 当前版本存在纹理集文件引用问题可能导致无法正确识别MER文件或常规纹理文件
-- [官方漏洞报告](https://bugs.mojang.com/browse/MCPE-126617)

View File

@@ -0,0 +1,279 @@
---
title: 伪方块
category: 教程
tags:
- 中级
mentions:
- SirLich
- solvedDev
- Joelant05
- MedicalJewel105
- aexer0e
- ThijsHankelMC
- QuazChick
---
# 伪方块
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
::: warning 实验性功能
需要启用 `Holiday Creator Features` 来触发方块事件。
:::
当你的方块需要实现Minecraft原生不支持的功能时可以通过创建具有方块特征的实体来模拟实现。
## 创建碰撞箱
[固体实体教程](/entities/solid-entities)中介绍了四种创建碰撞箱的方式,涉及 `runtime_identifiers`、方块和组件组合方案。
## 基础组件
以下组件是让实体模拟方块行为的关键配置。注意不要添加 `"minecraft:physics": {}` 组件,否则实体会受重力影响坠落或与水/岩浆等方块发生异常碰撞。
::: code-group
```json [BP/entities/your_entity.json#minecraft:entity/components]
{
// 需要击退抗性来防止实体被击退
"minecraft:knockback_resistance": {
"value": 1
},
// 控制实体是否可被推动
"minecraft:pushable": {
"is_pushable": false,
"is_pushable_by_piston": true
},
// 设置实体可被推动的穿透距离
"minecraft:push_through": {
"value": 1
},
// 使实体无敌
"minecraft:damage_sensor": {
"triggers": [
{
"deals_damage": false,
"cause": "all"
}
]
}
}
```
:::
## 实体旋转对齐
通过数学计算实现实体旋转对齐:
::: code-group
```json [动画控制器]
"rotation": [ 0, "-q.body_y_rotation + (Math.round(q.body_y_rotation / 90) * 90)", 0 ]
```
:::
将此代码应用在模型动画的核心分组包含其他所有分组的父级确保X轴和Z轴旋转中心点为0以避免视觉错位。同时避免添加以下组件
- `"minecraft:behavior.look_at_entity": {}`
- `"minecraft:behavior.look_at_player": {}`
- `"minecraft:behavior.look_at_target": {}`
这些组件会改变目标Y轴旋转角度导致模型异常位移。同时也不要添加行走类组件。
## 实体位置对齐
位置对齐的实现较为复杂,需分步操作:
1. 在 `minecraft:entity_spawned` 事件中生成临时方块
2. 通过指令生成虚拟实体
3. 将虚拟实体转换为目标实体
::: code-group
```json [BP/entities/your_entity.json#minecraft:entity/events]
// 原实体中的事件
"minecraft:entity_spawned": {
"add": {
"components_groups": [
"despawn" // 需要移除初始实体
]
},
"run_command": {
"command": [
"setblock ~~~ wiki:align"
]
}
}
```
:::
::: code-group
```json [BP/entities/your_entity.json#minecraft:entity/component_groups]
// 原实体中的组件组
"component_groups": {
"despawn": {
"minecraft:despawn": {}
}
}
```
:::
用于生成虚拟实体的对齐方块配置:
::: code-group
```json [BP/blocks/your_dummy_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:align"
},
"components": {
"minecraft:light_dampening": 0,
"minecraft:collision_box": false,
"minecraft:selection_box": false,
"minecraft:loot": "loot_tables/empty.json",
"minecraft:geometry": "geometry.empty",
"minecraft:material_instances": {
"*": {
"texture": "empty"
}
},
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 2
},
"minecraft:on_placed": {
"event": "wiki:event"
}
},
"events": {
"wiki:event": {
"run_command": {
"command": [
"setblock ~~~ air", // 移除临时方块
"summon wiki:dummy_align" // 生成虚拟实体
]
}
}
}
}
}
```
:::
虚拟实体的转换配置:
::: code-group
```json [BP/entities/your_dummy_entity.json]
{
"format_version": "1.13.0",
"minecraft:entity": {
"description": {
"identifier": "wiki:dummy_align", // 虚拟实体用于避免触发原实体的生成事件
"is_spawnable": false,
"is_summonable": true,
"is_experimental": false
},
"component_groups": {
"transform": {
"minecraft:transformation": {
"into": "wiki:your_entity",
"delay": 0
}
}
},
"components": {
"minecraft:physics": {
"has_gravity": false
},
"minecraft:collision_box": {
"width": 0.1,
"height": 0.1
},
"minecraft:damage_sensor": {
"triggers": {
"cause": "all",
"deals_damage": false
}
}
},
"events": {
"minecraft:entity_spawned": {
"add": {
"component_groups": ["transform"]
}
}
}
}
}
```
:::
## 裂纹纹理效果
为实体添加原生方块的破坏裂纹效果:
1. 添加原版裂纹纹理(兼容材质包)
2. 创建专用几何体
3. 配置渲染控制器
::: code-group
```json [RP/entity/your_entity.json#description]
"textures": {
"default": "textures/entity/your_texture",
"destroy_stage_0": "textures/environment/destroy_stage_0",
"destroy_stage_1": "textures/environment/destroy_stage_1",
"destroy_stage_2": "textures/environment/destroy_stage_2",
"destroy_stage_3": "textures/environment/destroy_stage_3",
"destroy_stage_4": "textures/environment/destroy_stage_4",
"destroy_stage_5": "textures/environment/destroy_stage_5",
"destroy_stage_6": "textures/environment/destroy_stage_6",
"destroy_stage_7": "textures/environment/destroy_stage_7",
"destroy_stage_8": "textures/environment/destroy_stage_8",
"destroy_stage_9": "textures/environment/destroy_stage_9"
}
```
:::
创建防Z轴冲突的几何体
::: code-group
```json [RP/entity/your_entity.json#description]
"geometry": {
"default": "geometry.your_geometry",
"broken": "geometry.broken"
}
```
:::
配置动态纹理渲染控制器:
::: code-group
```json [RP/render_controllers/my_entity.json]
"controller.render.broken": {
"arrays": {
"textures": {
"array.broken": [
"texture.destroy_stage_9",
"texture.destroy_stage_8",
"texture.destroy_stage_7",
"texture.destroy_stage_6",
"texture.destroy_stage_5",
"texture.destroy_stage_4",
"texture.destroy_stage_3",
"texture.destroy_stage_2",
"texture.destroy_stage_1",
"texture.destroy_stage_0",
"texture.normal"
]
}
},
"geometry": "Geometry.broken",
"materials": [
{
"*": "Material.default"
}
],
"textures": [
"array.broken[q.health * 1]" // 根据实体生命值调整参数10生命值保持1倍20生命值改为0.540生命值改为0.25...
]
}
```
:::

View File

@@ -0,0 +1,172 @@
---
title: 纹理动画
category:
- 教程
tags:
- 中级
mentions:
- MedicalJewel105
- SquisSloim
- SmokeyStack
- QuazChick
---
# 纹理动画
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
通过本文你将了解:
- 如何为方块应用翻页书贴图
- `RP/textures/flipbook_textures.json` 中可用的参数及其作用
## 应用翻页书贴图
翻页书贴图即动态纹理。火焰、水、岩浆和岩浆块等方块都使用此类贴图。你也可以为自己创建的方块添加动态纹理!
首先以原版岩浆的动效贴图为例。只需在材质实例组件中将 `texture` 值设为 `Vanilla RP/textures/terrain_texture.json` 中定义的纹理名称即可:
```json
"magma": {
"textures": "textures/blocks/magma"
}
```
::: code-group
```json [BP/blocks/flipbook_block.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:flipbook_block",
"menu_category": {
"category": "construction"
}
},
"components": {
"minecraft:unit_cube": {},
"minecraft:material_instances": {
"*": {
"texture": "magma" // 将纹理名称填在此处
}
}
}
}
}
```
:::
![](/assets/images/blocks/flipbook-textures/animated_texture_1.gif)
现在你的方块已经拥有动态纹理了!
## 定义翻页书贴图
在为方块添加动态纹理后,我们需要了解其工作原理。
1. 游戏会根据 `terrain_texture.json` 中定义的纹理名称(如 magma读取对应贴图路径
::: code-group
```json [RP/textures/terrain_texture.json]
{
"texture_name": "atlas.terrain",
"resource_pack_name": "wiki", // 资源包ID
"padding": 8, // 防止贴图边缘像素溢出
"num_mip_levels": 4, // 控制远视角和倾斜视角下的材质质量
"texture_data": {
"magma": {
"textures": "textures/blocks/magma"
}
}
}
```
:::
2. 游戏会根据上述名称magma在 `flipbook_textures.json` 中查找对应的动画参数
::: code-group
```json [RP/textures/flipbook_textures.json]
[
{
"atlas_tile": "magma",
"flipbook_texture": "textures/blocks/magma",
"ticks_per_frame": 10
}
]
```
:::
`"atlas_tile"` 表示将动画参数绑定到 `terrain_texture.json` 中定义的 magma 纹理名称。
3. 所有使用 `magma` 作为纹理的方块都将应用此动态纹理
## 翻页书贴图参数配置
在查阅官方示例时,你可能会发现一些额外的配置参数:
| 参数名 | 类型 | 描述 |
|--------------------|------------------|-------------------------------------------------------------------------------------------------|
| flipbook_texture | string | 纹理文件路径 |
| atlas_tile | string | 在terrain_textures.json中定义的短名称 |
| atlas_index | integer | 短名称对应的纹理数组中目标纹理的索引 |
| atlas_tile_variant | integer | 短名称对应的方块变体数组中纹理的变化索引 |
| ticks_per_frame | integer | 帧切换速度单位ticks20 ticks = 1秒 |
| frames | array 或 integer | 帧索引数组;或表示总帧数的整数值 |
| replicate | integer | 像素倍数仅允许2的幂次值默认1 |
| blend_frames | boolean | 是否启用帧过渡平滑效果默认true |
### `atlas_index`
用于指定需要添加动画效果的纹理在数组中的索引位置
::: code-group
```json [RP/textures/terrain_texture.json#texture_data]
"dirt": {
"textures": [
"textures/blocks/dirt",
"textures/blocks/coarse_dirt" // 假设此纹理需要添加动效
]
}
```
:::
由于要设置第二个纹理索引为1的动效需要在对应配置中设置 `"atlas_index": 1`
### `atlas_tile_variant`
用于指定需要添加动画效果的方块变体(需在 `variations` 数组中定义)索引
::: code-group
```json [RP/textures/terrain_texture.json#texture_data]
"dirt": {
"textures": [
{
"variations": [
{ "path": "textures/blocks/dirt_va" }, // 假设此变体需要添加动效
{ "path": "textures/blocks/dirt0" },
{ "path": "textures/blocks/dirt1" }
]
}
]
}
```
:::
若需要设置索引1的变体动画需在参数中添加 `"atlas_tile_variant": 1`
### `replicate`
控制贴图像素显示倍数。仅允许使用2的幂次数值当原帧分辨率较小时可实现像素扩展效果
| 参数值 | 效果说明 |
|--------------------|----------------------------|
| < 0 | 动画失效 |
| 0 | 动画失效且贴图不显示 |
| 2 | 每像素扩展为4格尺寸缩小1/2 |
| x | 每像素扩展为x²格尺寸缩小1/x |
## 效果展示
![](/assets/images/blocks/flipbook-textures/animated_texture_2.gif)
现在你可以开始修改原版动效贴图或创作属于你的动态纹理了!

View File

@@ -0,0 +1,215 @@
---
title: 矿石战利品表
category: 教程
tags:
- 简单
mentions:
- SykoUSS
- ExDrill
- MedicalJewel105
- SmokeyStack
- Chikorita-Lover
- SirLich
- TheItsNameless
- QuazChick
- Keyyard
---
# 矿石战利品表
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
::: tip 格式版本 `1.20.30`
本教程假设您已具备方块基础知识。
开始前请先查阅[方块指南](/blocks/blocks-intro)。
:::
::: warning 实验性功能
需要启用`假日创造者特性`来触发事件。
:::
本教程旨在展示一种通过战利品表创建自定义矿石方块的全新方法。使用`minecraft:loot`组件时将始终调用指定战利品表,而通过在战利品表中添加`match_tool`条件,可以逐池限定挖掘工具要求。
- 特性:
- 可使用指定工具挖掘(本教程以铁镐为例)
- 可指定工具附魔等级
- 经验值掉落支持
- 限制:
- 所有工具需逐个单独指定
- 非玩家破坏方式(爆炸/指令等)不会触发掉落
## 方块JSON
以下方块行为文件可作为模板使用。记得通过`terrain_texture.json`设置方块纹理。
::: code-group
```json [BP/blocks/silver_ore.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:silver_ore",
"menu_category": {
"category": "nature",
"group": "itemGroup.name.ore"
}
},
"components": {
...
// 触发加载带有经验奖励结构的事件
"minecraft:on_player_destroyed": {
"event": "wiki:xp_reward"
},
"minecraft:loot": "loot_tables/blocks/silver_ore.json" // 使用精准采集时不会掉落
},
"events": {
"wiki:xp_reward": {
"run_command": {
"command": [
"structure load ore_xp_reward ~~~" // 需下载下方预存经验球的结构文件
]
}
}
}
}
}
```
## 战利品表
以下示例展示了必需组件
::: code-group
```json [BP/loot_tables/blocks/silver_ore.json]
{
"pools": [
{
"rolls": 1,
"conditions": [
{
"condition": "match_tool",
"item": "minecraft:iron_pickaxe",
"count": 1
}
],
"entries": [
{
"type": "item",
"name": "wiki:raw_silver"
}
]
}
]
}
```
## 附魔等级限定
可通过添加`enchantments`区间限定附魔等级。注意每组工具及其等级需独立成池。
目前兼容检测1级和2级附魔。
::: code-group
```json [BP/loot_tables/blocks/silver_ore.json#pools]
"conditions": [
{
"condition": "match_tool",
"item": "minecraft:iron_pickaxe",
"count": 1,
"enchantments": [
{
"fortune": {
"level": 1
}
}
]
}
]
```
## 非实验性方案
若不想通过方块事件触发经验奖励,可选用以下替代方案。
请从[此处](#下载结构文件)下载内含经验球的`ore_xp_reward`结构文件。
### 方案一:虚拟物品与循环函数
**步骤1**:为需要掉落经验的方块创建战利品表。以"minecraft:redstone"为例:
```json
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:redstone"
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:barrier" // 虚拟物品
}
]
}
]
}
```
此处添加已有物品"minecraft:barrier"作为触发经验掉落的虚拟物品,也可创建专用虚拟物品。
**步骤2**:创建循环函数处理掉落物品。需在`BP/functions/tick.json`中定义:
```c
execute as @e[type=item, name="Barrier"] at @s run structure load ore_xp_reward ~~~
execute as @e[type=item, name="Barrier"] run kill
```
该函数会捕捉名为"Barrier"的掉落物,加载经验奖励结构后销毁虚拟物品。
### 方案二:纯函数循环
**步骤1**:创建基础战利品表。以"wiki:raw_silver"为例:
```json
{
"pools": [
{
"entries": [
{
"type": "item",
"name": "wiki:raw_silver"
}
]
}
]
}
```
**步骤2**:创建标记处理函数。需在`BP/functions/tick.json`中定义:
```c
execute as @e[type=item, name="Raw Silver", tag=!xp] at @s run structure load ore_xp_reward ~~~
execute as @e[type=item, name="Raw Silver", tag=!xp] run tag @s add xp
```
该函数为所有未标记"xp"的银矿掉落物加载经验结构,并通过标签防止重复触发。
请根据实际情况调整物品ID、标签等参数。
## 下载结构文件
<BButton link="/assets/packs/tutorials/blocks/ore-loot-tables/ore_xp_reward.mcstructure" download color=blue> 下载MCSTRUCTURE</BButton>
## 实际效果
![](/assets/images/blocks/ore-loot/result.gif)

View File

@@ -0,0 +1,352 @@
---
title: 精确旋转
category: 教程
tags:
- experimental
- expert
mentions:
- QuazChick
---
# 精确旋转
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
::: tip 格式与最低引擎版本 `1.20.30`
本教程假定您已具备方块的进阶知识与Molang基础。
开始前建议先阅读[方块指南](/blocks/blocks-intro)。
:::
::: warning 实验性功能
需要启用 `Holiday Creator Features` 来触发事件。
:::
本教程将引导您实现可支持次级方位旋转的方块(如爬行者头颅与告示牌),通过一个包含此类旋转类型的"贝壳"方块作为实例进行讲解。
*查看常规旋转方式?请前往[此页面](/blocks/rotatable-blocks)*
![随机朝向的自定义贝壳方块](/assets/images/blocks/precise-rotation/showcase.png)
特性概览:
- 可附着于方块顶部具备16种旋转角度
- 可附着于方块的侧表面(北、东、南、西)
- 旋转行为与原版生物头颅一致,且无需依赖方块实体性能消耗!
## 方块模型
要实现更精确的旋转机制,您的方块模型需额外添加若干骨骼节点。
实现地面精确旋转需要4个基础骨骼节点每个对应不同的Y轴旋转角度:
- `up_0` (Y旋转角度 = 0)
- `up_22_5` (Y旋转角度 = 22.5)
- `up_45` (Y旋转角度 = 45)
- `up_67_5` (Y旋转角度 = 67.5)
**上述角度值采用顺时针方向递增**
这些骨骼除旋转参数外,在结构上通常是互为复制的。
:::tip
建议将所有骨骼的枢轴点设置于 `[0, 0, 0]` ,以确保其围绕方块中心旋转。
:::
此外,还需一个 `side` 骨骼用于侧表面附着时的定位调整。
下方展示的"贝壳"模型结构可供参考:
![](/assets/images/blocks/precise-rotation/model_bones.png)
<Spoiler title="贝壳模型实例">
::: code-group
```json [RP/models/blocks/shell.geo.json]
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.shell",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 3,
"visible_bounds_height": 2.5,
"visible_bounds_offset": [0, 0.75, 0]
},
"bones": [
{
"name": "shell",
"pivot": [0, 0, 0]
},
{
"name": "up_0",
"parent": "shell",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-3, 0, -3],
"size": [6, 3, 6],
"uv": {
"north": { "uv": [0, 6], "uv_size": [6, 3] },
"east": { "uv": [0, 6], "uv_size": [6, 3] },
"south": { "uv": [0, 6], "uv_size": [6, 3] },
"west": { "uv": [0, 6], "uv_size": [6, 3] },
"up": { "uv": [6, 6], "uv_size": [-6, -6] },
"down": { "uv": [6, 6], "uv_size": [-6, -6] }
}
}
]
},
{
"name": "up_22_5",
"parent": "shell",
"pivot": [0, 0, 0],
"rotation": [0, 22.5, 0],
"cubes": [
{
"origin": [-3, 0, -3],
"size": [6, 3, 6],
"uv": {
"north": { "uv": [0, 6], "uv_size": [6, 3] },
"east": { "uv": [0, 6], "uv_size": [6, 3] },
"south": { "uv": [0, 6], "uv_size": [6, 3] },
"west": { "uv": [0, 6], "uv_size": [6, 3] },
"up": { "uv": [6, 6], "uv_size": [-6, -6] },
"down": { "uv": [6, 6], "uv_size": [-6, -6] }
}
}
]
},
{
"name": "up_45",
"parent": "shell",
"pivot": [0, 0, 0],
"rotation": [0, 45, 0],
"cubes": [
{
"origin": [-3, 0, -3],
"size": [6, 3, 6],
"uv": {
"north": { "uv": [0, 6], "uv_size": [6, 3] },
"east": { "uv": [0, 6], "uv_size": [6, 3] },
"south": { "uv": [0, 6], "uv_size": [6, 3] },
"west": { "uv": [0, 6], "uv_size": [6, 3] },
"up": { "uv": [6, 6], "uv_size": [-6, -6] },
"down": { "uv": [6, 6], "uv_size": [-6, -6] }
}
}
]
},
{
"name": "up_67_5",
"parent": "shell",
"pivot": [0, 0, 0],
"rotation": [0, 67.5, 0],
"cubes": [
{
"origin": [-3, 0, -3],
"size": [6, 3, 6],
"uv": {
"north": { "uv": [0, 6], "uv_size": [6, 3] },
"east": { "uv": [0, 6], "uv_size": [6, 3] },
"south": { "uv": [0, 6], "uv_size": [6, 3] },
"west": { "uv": [0, 6], "uv_size": [6, 3] },
"up": { "uv": [6, 6], "uv_size": [-6, -6] },
"down": { "uv": [6, 6], "uv_size": [-6, -6] }
}
}
]
},
{
"name": "side",
"parent": "shell",
"pivot": [0, 5, 8],
"rotation": [90, 0, 0],
"cubes": [
{
"origin": [-3, 5, 8],
"size": [6, 3, 6],
"uv": {
"north": { "uv": [0, 6], "uv_size": [6, 3] },
"east": { "uv": [0, 6], "uv_size": [6, 3] },
"south": { "uv": [0, 6], "uv_size": [6, 3] },
"west": { "uv": [0, 6], "uv_size": [6, 3] },
"up": { "uv": [6, 6], "uv_size": [-6, -6] },
"down": { "uv": [6, 6], "uv_size": [-6, -6] }
}
}
]
}
]
}
]
}
```
:::
</Spoiler>
## 基础方块JSON
下方是待添加高级旋转功能的"贝壳"方块基础定义。
::: code-group
```json [BP/blocks/shell.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:shell",
"menu_category": {
"category": "nature"
}
},
"components": {
// `up` 表面的碰撞/选择框
"minecraft:collision_box": {
"origin": [-3, 0, -3],
"size": [6, 3, 6]
},
"minecraft:selection_box": {
"origin": [-3, 0, -3],
"size": [6, 3, 6]
},
"minecraft:material_instances": {
"*": {
"texture": "shell" // 在 `RP/textures/terrain_texture.json` 中定义的短名称
}
},
// 阻止方块附着于 `down` 表面
"minecraft:placement_filter": {
"conditions": [
{
"allowed_faces": ["up", "side"]
}
]
}
}
}
}
```
:::
## 方块状态
为实现头颅式旋转机制需为方块添加2种状态参数
::: code-group
```json [minecraft:block]
"description": {
...
"traits": {
// 方块附着面 - 默认为 `north`
"minecraft:placement_position": {
"enabled_states": ["minecraft:block_face"]
}
},
"states": {
// 当附着于 `up` 表面时的精确旋转参数
"wiki:rotation": {
"values": { "min": 0, "max": 15 } // 使用更方便的定义整数范围的语法
}
}
}
```
:::
## 旋转Molang表达式
相较于逐个定义每个 `wiki:rotation` 值的范围,运用[复合Molang表达式](https://learn.microsoft.com/en-us/minecraft/creator/reference/content/molangreference/examples/molangconcepts/molangintroduction#simple-vs-complex-expressions)配合除法运算可高效实现需求!
```c
// 转换玩家头部Y旋转角度至正值
t.positive_head_rot = q.head_y_rotation(0) + 360 * (q.head_y_rotation(0) != math.abs(q.head_y_rotation(0)));
// 计算头部旋转对应的十六分之一圆角(取整)
t.rotation = math.round(t.positive_head_rot / 22.5);
// 0与16代表重复旋转0度与360度故当值为16时返回0
return t.rotation != 16 ? t.rotation;
```
合并为单行表达式以便嵌入JSON
::: code-group
```json [minecraft:block > components > minecraft:on_player_placing > condition]
"condition": "t.positive_head_rot = q.head_y_rotation(0) + 360 * (q.head_y_rotation(0) != math.abs(q.head_y_rotation(0))); t.rotation = math.round(t.positive_head_rot / 22.5); return t.rotation != 16 ? t.rotation;"
```
:::
## 应用旋转
现在通过Molang表达式动态设定方块属性!
通过事件在玩家放置方块时更新方块属性。此事件上下文可访问 `q.block_face` 与 `q.head_y_rotation`。
在方块JSON中添加以下组件与事件
::: code-group
```json [minecraft:block]
"components": {
...
"minecraft:on_player_placing": {
"condition": "q.block_face == 1", // 精确旋转仅作用于 `up` 表面
"event": "wiki:set_rotation"
}
},
"events": {
"wiki:set_rotation": {
"set_block_property": {
// 应用之前的Molang表达式设置rotation属性
"wiki:rotation": "q.block_face == 1 ? { t.positive_head_rot = q.head_y_rotation(0) + 360 * (q.head_y_rotation(0) != math.abs(q.head_y_rotation(0))); t.block_rotation = math.round(t.positive_head_rot / 22.5); return t.block_rotation != 16 ? t.block_rotation; };"
}
}
}
```
:::
<br>
接着,使用[置换](/blocks/block-permutations)定义基础朝向旋转,由模型中的精细骨骼进一步细化。
按顺序在方块JSON中添加以下置换条件
::: code-group
```json [minecraft:block]
"permutations": [
{
"condition": "q.block_property('wiki:rotation') >= 4 || q.block_property('minecraft:block_face') == 'east'",
"components": {
"minecraft:transformation": { "rotation": [0, -90, 0] }
}
},
{
"condition": "q.block_property('wiki:rotation') >= 8 || q.block_property('minecraft:block_face') == 'south'",
"components": {
"minecraft:transformation": { "rotation": [0, 180, 0] }
}
},
{
"condition": "q.block_property('wiki:rotation') >= 12 || q.block_property('minecraft:block_face') == 'west'",
"components": {
"minecraft:transformation": { "rotation": [0, 90, 0] }
}
}
]
```
:::
## 骨骼可见性
并非所有骨骼节点始终可见,因此需利用 `minecraft:geometry` 的骨骼可见性属性精确控制渲染。多个骨骼存在的目的是因为 `minecraft:transformation` 仅支持90度的整数倍旋转而精确旋转需要22.5度的增量。
在方块组件中加入以下内容:
::: code-group
```json [minecraft:block > components]
"minecraft:geometry": {
"identifier": "geometry.shell", // 第一步创建的模型
"bone_visibility": {
"up_0": "q.block_property('minecraft:block_face') == 'up' && !math

View File

@@ -0,0 +1,403 @@
---
title: 可旋转方块
category: 教程
mentions:
- Ultr4Anubis
- SmokeyStack
- ihategravel2
- MedicalJewel105
- MajestikButter
- QuazChick
---
# 可旋转方块
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
::: tip 格式与最低引擎版本 `1.20.30`
本教程假设您已掌握方块基础知识,包括[方块状态](/blocks/block-states)与[方块特性](/blocks/block-traits)。
开始前请先阅读[方块指南](/blocks/blocks-intro)。
:::
## 旋转类型
- ### [基本方向旋转](#cardinal-direction-rotation)
- 适用于雕刻南瓜和熔炉
- 4个方向 - 'north'(北)、'south'(南)、'east'(东)、'west'(西)
- ### [面向方向旋转](#facing-direction-rotation)
- 适用于发射器和观测器
- 6个方向 - 'down'(下)、'up'(上)、'north'(北)、'south'(南)、'east'(东)、'west'(西)
- ### [方块面附着旋转](#block-face-rotation)
- 适用于梯子和物品展示框
- 6个附着方向 - 'down'(下)、'up'(上)、'north'(北)、'south'(南)、'east'(东)、'west'(西)
- ### [原木/柱体旋转](#log-rotation)
- 适用于原木和玄武岩
- 3个轴对齐方向
- ### [精确旋转](/blocks/precise-rotation)
- 适用于头颅、告示牌和旗帜
- 16个方向以22.5度递增)
- 4个侧面附着方向
## 基本方向旋转
### 特性
使用`minecraft:placement_direction`方块特性并启用`minecraft:cardinal_direction`状态来设置方块方向。
::: code-group
```json [minecraft:block]
"description": {
"identifier": "wiki:cardinal_direction_example",
// 在此处定义方块特性
"traits": {
"minecraft:placement_direction": {
"enabled_states": ["minecraft:cardinal_direction"], // 可在查询中使用,例如`q.block_state('minecraft:cardinal_direction') == 'north'`
"y_rotation_offset": 180 // 朝向玩家
}
}
}
```
:::
### 置换
通过方块置换实现旋转。每个置换包含`minecraft:transformation`组件,检查`minecraft:cardinal_direction`状态并应用相应旋转。
**下方旋转值假设模型正面朝北**
::: code-group
```json [minecraft:block]
"permutations": [
// 面向北
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'north'",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
// 面向西
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'west'",
"components": {
"minecraft:transformation": { "rotation": [0, 90, 0] }
}
},
// 面向南
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'south'",
"components": {
"minecraft:transformation": { "rotation": [0, 180, 0] }
}
},
// 面向东
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'east'",
"components": {
"minecraft:transformation": { "rotation": [0, -90, 0] }
}
}
]
```
:::
## 面向方向旋转
### 特性
使用`minecraft:placement_direction`方块特性并启用`minecraft:facing_direction`状态来设置方块方向。
::: code-group
```json [minecraft:block]
"description": {
"identifier": "wiki:facing_direction_example",
// 在此处定义方块特性
"traits": {
"minecraft:placement_direction": {
"enabled_states": ["minecraft:facing_direction"], // 可在查询中使用,例如`q.block_state('minecraft:facing_direction') == 'north'`
}
}
}
```
:::
### 置换
通过方块置换实现旋转。每个置换包含`minecraft:transformation`组件,检查`minecraft:facing_direction`状态并应用相应旋转。
**下方旋转值假设模型正面朝北**
::: code-group
```json [minecraft:block]
"permutations": [
// 朝下
{
"condition": "q.block_state('minecraft:facing_direction') == 'down'",
"components": {
"minecraft:transformation": { "rotation": [-90, 0, 0] }
}
},
// 朝上
{
"condition": "q.block_state('minecraft:facing_direction') == 'up'",
"components": {
"minecraft:transformation": { "rotation": [90, 0, 0] }
}
},
// 朝北
{
"condition": "q.block_state('minecraft:facing_direction') == 'north'",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
// 朝西
{
"condition": "q.block_state('minecraft:facing_direction') == 'west'",
"components": {
"minecraft:transformation": { "rotation": [0, 90, 0] }
}
},
// 朝南
{
"condition": "q.block_state('minecraft:facing_direction') == 'south'",
"components": {
"minecraft:transformation": { "rotation": [0, 180, 0] }
}
},
// 朝东
{
"condition": "q.block_state('minecraft:facing_direction') == 'east'",
"components": {
"minecraft:transformation": { "rotation": [0, -90, 0] }
}
}
]
```
:::
## 方块面附着旋转
### 特性
使用`minecraft:placement_position`方块特性并启用`minecraft:block_face`状态来设置方块附着面。
::: code-group
```json [minecraft:block]
"description": {
"identifier": "wiki:facing_direction_example",
// 在此处定义方块特性
"traits": {
"minecraft:placement_position": {
"enabled_states": ["minecraft:block_face"], // 可在查询中使用,例如`q.block_state('minecraft:block_face') == 'north'`
}
}
}
```
:::
### 置换
通过方块置换实现旋转。每个置换包含`minecraft:transformation`组件,检查`minecraft:block_face`状态并应用相应旋转。
**下方旋转值假设模型正面朝北**
::: code-group
```json [minecraft:block]
"permutations": [
// 朝下
{
"condition": "q.block_state('minecraft:block_face') == 'down'",
"components": {
"minecraft:transformation": { "rotation": [-90, 0, 0] }
}
},
// 朝上
{
"condition": "q.block_state('minecraft:block_face') == 'up'",
"components": {
"minecraft:transformation": { "rotation": [90, 0, 0] }
}
},
// 朝北
{
"condition": "q.block_state('minecraft:block_face') == 'north'",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
// 朝西
{
"condition": "q.block_state('minecraft:block_face') == 'west'",
"components": {
"minecraft:transformation": { "rotation": [0, 90, 0] }
}
},
// 朝南
{
"condition": "q.block_state('minecraft:block_face') == 'south'",
"components": {
"minecraft:transformation": { "rotation": [0, 180, 0] }
}
},
// 朝东
{
"condition": "q.block_state('minecraft:block_face') == 'east'",
"components": {
"minecraft:transformation": { "rotation": [0, -90, 0] }
}
}
]
```
:::
## 原木旋转
实现与原版原木相同的旋转方式
::: warning 实验性功能
需要启用`假日创作者功能`来触发事件
:::
### 方块状态
::: code-group
```json [minecraft:block > description]
"states": {
"wiki:axis": [0, 1, 2]
}
```
:::
### 方块事件与触发
使用Molang表达式通过查询方块附着面来确定坐标轴方向转换为0、1或2
::: code-group
```json [minecraft:block > events]
"wiki:set_axis": {
"set_block_state": {
"wiki:axis": "数学运算.floor(q.block_face / 2)"
}
}
```
:::
使用`minecraft:on_player_placing`触发器组件调用事件
::: code-group
```json [minecraft:block > components]
"minecraft:on_player_placing": {
"event": "wiki:set_axis"
}
```
:::
### 置换
::: code-group
```json [minecraft:block]
"permutations": [
{
"condition": "q.block_state('wiki:axis') == 0",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 1",
"components": {
"minecraft:transformation": { "rotation": [90, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 2",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 90] }
}
}
]
```
:::
### 原木旋转示例
::: warning 实验性功能
本示例需要启用`假日创作者功能`以使用`minecraft:unit_cube`
:::
<Spoiler title="基础自定义原木JSON">
::: code-group
```json [BP/blocks/custom_log.json]
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_log",
"states": {
"wiki:axis": [0, 1, 2]
}
},
"components": {
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 1.5
},
"minecraft:destructible_by_explosion": {
"explosion_resistance": 15
},
"minecraft:material_instances": {
"*": {
"texture": "log_side"
},
"end": {
"texture": "log_top"
},
"up": "end",
"down": "end"
},
"minecraft:unit_cube": {},
"minecraft:on_player_placing": {
"event": "wiki:set_axis"
}
},
"events": {
"wiki:set_axis": {
"set_block_state": {
"wiki:axis": "Math.floor(q.block_face / 2)"
}
}
},
"permutations": [
{
"condition": "q.block_state('wiki:axis') == 0",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 1",
"components": {
"minecraft:transformation": { "rotation": [90, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 2",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 90] }
}
}
]
}
}
```
:::
</Spoiler>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,364 @@
---
title: Custom Fluids
category: Vanilla Re-Creations
tags:
- experimental
- intermediate
- scripting
mentions:
- Provedule
- JaylyDev
- QuazChick
---
::: tip FORMAT & MIN ENGINE VERSION `1.20.30`
This tutorial assumes an advanced understanding of blocks and the execute command.
Check out the [blocks guide](/blocks/blocks-intro) before starting.
:::
::: warning EXPERIMENTAL
Requires `Holiday Creator Features` for use of block tag Molang queries and to trigger block events.
Requires `Beta APIs` to use [@minecraft/server](https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/minecraft-server) module version `1.6.0-beta`.
:::
Creating fluids that are identical to vanilla fluids is not currently possible, but you can make something similar! This template/tutorial is designed to assist you in creating a custom "semi-fluid".
## Flow Logic
- The fluid block has states defining whether it is a source and its depth.
- If there is air beneath fluid blocks, it will be converted into falling fluid.
- Fluids with a depth above `1` will spread horizontally with decreasing depths.
- This will not occur if there is falling fluid below.
- Flowing fluid block must have another fluid block adjacent to survive.
- Source blocks do not need to have other fluid blocks surrounding themselves.
**This implementation does not include face culling due to its current complexity.**
<WikiImage
src="/assets/images/blocks/custom-fluids/fluid_display.png"
alt=""
pixelated="true"
width=608
/>
## Source Fluid Block
Below is the code for a custom fluid. Copy and quick replace `custom_fluid` with your fluid's name. When the source block detects air in its surroundings, it replaces it with the outer fluid blocks. If the source block detects air beneath it, it will also place a falling fluid block underneath.
<BButton
link="https://github.com/Bedrock-OSS/wiki-addon/blob/main/ma-custom_fluids/rp/models/blocks/fluid.geo.json"
color=blue
>Download Custom Fluid Geometry</BButton>
<Spoiler title="Custom Fluid Block JSON">
<CodeHeader>BP/blocks/custom_fluid.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_fluid",
"menu_category": {
"category": "none"
},
"states": {
"wiki:source": [true, false],
// Depth of fluid - default to 4
"wiki:depth": [4, 5, 3, 2, 1]
}
},
"components": {
"minecraft:light_dampening": 0,
"minecraft:collision_box": false,
"minecraft:selection_box": false,
"minecraft:destructible_by_explosion": false,
// Trigger fluid spread
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [20, 20], // Fluid speed in ticks
"on_tick": {
"event": "wiki:flow"
}
},
"minecraft:material_instances": {
"*": {
"texture": "custom_fluid", // Shortname defined in `RP/textures/terrain_texture.json`
"render_method": "blend",
"ambient_occlusion": false,
"face_dimming": false
}
},
"minecraft:loot": "loot_tables/empty.json",
"tag:custom_fluid": {}
},
"events": {
"wiki:flow": {
"sequence": [
// Dry out
{
"condition": "!q.block_state('wiki:source') && ((q.block_state('wiki:depth') == 5 && !q.block_neighbor_has_any_tag(0, 1, 0, 'custom_fluid')) || (q.block_state('wiki:depth') == 1 && !(q.block_neighbor_has_any_tag(1, 0, 0, 'custom_fluid_2') || q.block_neighbor_has_any_tag(-1, 0, 0, 'custom_fluid_2') || q.block_neighbor_has_any_tag(0, 0, 1, 'custom_fluid_2') || q.block_neighbor_has_any_tag(0, 0, -1, 'custom_fluid_2')) || q.block_state('wiki:depth') == 2 && !(q.block_neighbor_has_any_tag(1, 0, 0, 'custom_fluid_3') || q.block_neighbor_has_any_tag(-1, 0, 0, 'custom_fluid_3') || q.block_neighbor_has_any_tag(0, 0, 1, 'custom_fluid_3') || q.block_neighbor_has_any_tag(0, 0, -1, 'custom_fluid_3'))) || (q.block_state('wiki:depth') == 3 && !(q.block_neighbor_has_any_tag(1, 0, 0, 'custom_fluid_4', 'custom_fluid_5') || q.block_neighbor_has_any_tag(-1, 0, 0, 'custom_fluid_4', 'custom_fluid_5') || q.block_neighbor_has_any_tag(0, 0, 1, 'custom_fluid_4', 'custom_fluid_5') || q.block_neighbor_has_any_tag(0, 0, -1, 'custom_fluid_4', 'custom_fluid_5'))))",
"die": {}
},
// Spread
{
"condition": "q.block_state('wiki:depth') == 4",
"run_command": {
"command": [
"execute if block ~~~1 air run setblock ~~~1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]",
"execute if block ~~~-1 air run setblock ~~~-1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]",
"execute if block ~1~~ air run setblock ~1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]",
"execute if block ~-1~~ air run setblock ~-1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]"
]
}
},
{
"condition": "q.block_state('wiki:source') && q.block_neighbor_has_any_tag(0, 1, 0, 'custom_fluid')",
"set_block_state": {
"wiki:depth": 5
}
},
{
"condition": "q.block_state('wiki:source') && !q.block_neighbor_has_any_tag(0, 1, 0, 'custom_fluid')",
"set_block_state": {
"wiki:depth": 4
}
},
{
"condition": "q.block_state('wiki:depth') == 3",
"run_command": {
"command": [
"execute if block ~~~1 air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~~~1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=2]",
"execute if block ~~~-1 air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~~~-1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=2]",
"execute if block ~1~~ air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=2]",
"execute if block ~-1~~ air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~-1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=2]"
]
}
},
{
"condition": "q.block_state('wiki:depth') == 2",
"run_command": {
"command": [
"execute if block ~~~1 air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~~~1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=1]",
"execute if block ~~~-1 air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~~~-1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=1]",
"execute if block ~1~~ air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=1]",
"execute if block ~-1~~ air unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid run setblock ~-1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=1]"
]
}
},
{
"condition": "q.block_state('wiki:depth') == 5 && q.block_neighbor_has_any_tag(0, 1, 0, 'custom_fluid')",
"run_command": {
"command": [
"execute if block ~~-1~ wiki:custom_fluid [\"wiki:depth\"=3] run setblock ~~-1~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=5]",
"execute if block ~~-1~ wiki:custom_fluid [\"wiki:depth\"=2] run setblock ~~-1~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=5]",
"execute if block ~~-1~ wiki:custom_fluid [\"wiki:depth\"=1] run setblock ~~-1~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=5]",
"execute unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid if block ~1~~ air run setblock ~1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]",
"execute unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid if block ~~~1 air run setblock ~~~1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]",
"execute unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid if block ~-1~~ air run setblock ~-1~~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]",
"execute unless block ~~-1~ air unless block ~~-1~ wiki:custom_fluid if block ~~~-1 air run setblock ~~~-1 wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=3]"
]
}
},
// Fall
{
"run_command": {
"command": "execute if block ~~-1~ air run setblock ~~-1~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=5]"
}
},
{
"condition": "q.block_neighbor_has_any_tag(0, -1, 0, 'flowing_custom_fluid')",
"run_command": {
"command": "setblock ~~-1~ wiki:custom_fluid [\"wiki:source\"=false,\"wiki:depth\"=5]"
}
}
]
},
"wiki:pick_up": {
"die": {},
"decrement_stack": {},
"run_command": {
"command": "give @s lava_bucket",
"target": "other"
}
}
},
"permutations": [
{
"condition": "q.block_state('wiki:source')",
"components": {
// Enables the block to be picked up by an item of choice
"minecraft:selection_box": {
"origin": [-7.5, 0.5, -7.5],
"size": [15, 13, 15]
},
"tag:custom_fluid_source": {}
}
},
{
"condition": "!q.block_state('wiki:source')",
"components": {
"tag:flowing_custom_fluid": {}
}
},
{
"condition": "q.block_state('wiki:depth') == 5",
"components": {
"minecraft:geometry": "geometry.fluid.5",
"tag:custom_fluid_5": {}
}
},
{
"condition": "q.block_state('wiki:depth') == 4",
"components": {
"minecraft:geometry": "geometry.fluid.4",
"tag:custom_fluid_4": {}
}
},
{
"condition": "q.block_state('wiki:depth') == 3",
"components": {
"minecraft:geometry": "geometry.fluid.3",
"tag:custom_fluid_3": {}
}
},
{
"condition": "q.block_state('wiki:depth') == 2",
"components": {
"minecraft:geometry": "geometry.fluid.2",
"tag:custom_fluid_2": {}
}
},
{
"condition": "q.block_state('wiki:depth') == 1",
"components": {
"minecraft:geometry": "geometry.fluid.1",
"tag:custom_fluid_1": {}
}
}
]
}
}
```
</Spoiler>
## Fluid Bucket
To place your custom fluid you need a custom bucket item. Below is the JSON for the custom bucket. Replace any instance of `custom_fluid` with your fluid's name.
<Spoiler title="Custom Bucket Item JSON">
<CodeHeader>BP/items/custom_fluid_bucket.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:item": {
"description": {
"identifier": "wiki:custom_fluid_bucket",
"menu_category": {
"category": "items"
}
},
"components": {
"minecraft:max_stack_size": 1,
"minecraft:icon": {
"texture": "custom_fluid_bucket" // Shortname defined in `RP/textures/item_texture.json`
},
"minecraft:block_placer": {
"block": "wiki:custom_fluid"
}
}
}
}
```
</Spoiler>
## Scripts
The fluids use a script to add the ability for the player to float/sink in the fluid. The script also adds fog. To add your fluid to the script, put the ID of your new fluids in the `fluids` string array.
<CodeHeader>BP/manifest.json</CodeHeader>
```json
{
"modules": [
...
{
"type": "script",
"language": "javascript",
"entry": "fluids.js",
"uuid": ...,
"version": [1, 0, 0]
}
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.6.0-beta"
}
]
}
```
<Spoiler title="Fluid Movement & Fog Script">
<CodeHeader>BP/scripts/fluids.js</CodeHeader>
```javascript
import { system, world } from "@minecraft/server";
const fluids = ["wiki:custom_fluid"];
system.runInterval(() => {
const players = world.getPlayers();
for (const player of players) {
// Fluid effects
if (
fluids.includes(world.getDimension(player.dimension.id).getBlock({ ...player.location, y: player.location.y + 1 }).typeId) ||
fluids.includes(world.getDimension(player.dimension.id).getBlock(player.location).typeId)
) {
player.addEffect("slowness", 3, { amplifier: 2, showParticles: false });
player.addEffect("slow_falling", 4, { showParticles: false });
if (player.isJumping) {
player.addEffect("levitation", 3, { amplifier: 2, showParticles: false });
}
}
// Fluid fog
if (fluids.includes(world.getDimension(player.dimension.id).getBlock({ ...player.location, y: player.location.y + 1.63 }).typeId)) {
player.runCommand("fog @s push wiki:custom_fluid_fog fluid_fog");
} else {
player.runCommand("fog @s remove fluid_fog");
}
}
});
```
</Spoiler>
## Result
By the end your BP folder should look like this:
<FolderView
:paths="[
'BP/blocks/custom_fluid.json',
'BP/items/custom_fluid_bucket.json',
'BP/scripts/fluids.js',
'RP/fogs/custom_fluid.json'
]"
></FolderView>
## Download Example Pack
If anything goes wrong, or if you require all of the template files, they are available for download here. The pack includes everything necessary for a functional fluid.
<BButton
link="https://github.com/Bedrock-OSS/wiki-addon/releases/download/download/custom_fluids.mcaddon"
color=blue
>Download MCADDON</BButton>

View File

@@ -0,0 +1,661 @@
---
title: Custom Glass
category: Vanilla Re-Creations
tags:
- experimental
- expert
mentions:
- Eko-byte
- QuazChick
---
Making glass blocks may seem like a simple task, however it comes with many drawbacks as you will find, this tutorial aims to help you achieve a vanilla like glass block.
By the end you should be able to create something like this!
![Glass Results](/assets/images/blocks/glass-block/glass_showcase.png)
## Basic Glass
::: tip FORMAT VERSION `1.20.30`
This example requires basic knowledge of blocks to understand.
Check out the [blocks guide](/blocks/blocks-intro) before starting.
:::
This will create a custom glass block which appears the same as vanilla glass blocks!
<CodeHeader>BP/blocks/custom_glass.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_glass",
"menu_category": {
"category": "construction",
"group": "itemGroup.name.glass"
}
},
"components": {
"minecraft:light_dampening": 0,
"minecraft:material_instances": {
"*": {
"render_method": "blend" // Allows translucency
}
}
}
}
}
```
<CodeHeader>RP/blocks.json</CodeHeader>
```json
{
"wiki:custom_glass": {
"textures": "custom_glass", // Shortname defined in `RP/textures/terrain_texture.json`
"sound": "glass"
}
}
```
## Vertically-Connecting Glass
::: tip FORMAT & MIN ENGINE VERSION `1.20.30`
This example requires advanced knowledge of blocks and Molang to understand.
Check out the [blocks guide](/blocks/blocks-intro), [block states](/blocks/block-states) and [Molang](/concepts/molang) before starting.
:::
::: warning EXPERIMENTAL
Requires `Holiday Creator Features` for use of `minecraft:unit_cube` and to trigger events.
:::
<Spoiler title="Vertically-Connecting Glass JSON">
<CodeHeader>BP/blocks/custom_vertical_connecting_glass.json</CodeHeader>
```json
// Add a "nothing" texture in terrain_texture, and make it have a transparent file
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_vertical_connecting_glass",
"menu_category": {
"category": "construction",
"group": "itemGroup.name.glass"
},
"states": {
// States needed for connected textures, also controls up and down culling
"wiki:connection": [0, 1, 2, 3],
// States to cull faces depending on surrounding blocks
"wiki:cull_north": [false, true],
"wiki:cull_south": [false, true],
"wiki:cull_east": [false, true],
"wiki:cull_west": [false, true]
}
},
"components": {
// Basic glass components
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 1
},
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [0, 0],
"on_tick": {
"event": "wiki:update"
}
},
"minecraft:unit_cube": {},
"minecraft:light_dampening": 0,
// Tags used to give connected textures, and remove culling
"tag:custom_vertical_connecting_glass": {},
"tag:glass": {}
},
"permutations": [
// These permutations control what textures are displayed at different situations
// They also use tags to determine what state they are in, (top texture then top tag)
{
"condition": "q.block_state('wiki:connection') == 0 && !q.block_state('wiki:cull_north') && !q.block_state('wiki:cull_south') && !q.block_state('wiki:cull_east') && !q.block_state('wiki:cull_west')",
"components": {
"tag:default": {},
"minecraft:material_instances": {
"*": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
}
}
}
},
{
"condition": "q.block_state('wiki:connection') == 1 && !q.block_state('wiki:cull_north') && !q.block_state('wiki:cull_south') && !q.block_state('wiki:cull_east') && !q.block_state('wiki:cull_west')",
"components": {
"tag:top": {},
"minecraft:material_instances": {
"*": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_top"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:connection') == 2 && !q.block_state('wiki:cull_north') && !q.block_state('wiki:cull_south') && !q.block_state('wiki:cull_east') && !q.block_state('wiki:cull_west')",
"components": {
"tag:bottom": {},
"minecraft:material_instances": {
"*": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_bottom"
},
"up": {
"render_method": "blend",
"texture": "nothing"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
}
}
}
},
{
"condition": "q.block_state('wiki:connection') == 3 && !q.block_state('wiki:cull_north') && !q.block_state('wiki:cull_south') && !q.block_state('wiki:cull_east') && !q.block_state('wiki:cull_west')",
"components": {
"tag:middle": {},
"minecraft:material_instances": {
"*": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_middle"
},
"up": {
"render_method": "blend",
"texture": "nothing"
},
"down": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_north') && q.block_state('wiki:connection') == 0",
"components": {
"tag:default": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass",
"render_method": "blend"
},
"north": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_south') && q.block_state('wiki:connection') == 0",
"components": {
"tag:default": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass",
"render_method": "blend"
},
"south": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_east') && q.block_state('wiki:connection') == 0",
"components": {
"tag:default": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass",
"render_method": "blend"
},
"east": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_west') && q.block_state('wiki:connection') == 0",
"components": {
"tag:default": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass",
"render_method": "blend"
},
"west": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_north') && q.block_state('wiki:connection') == 1",
"components": {
"tag:top": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_top",
"render_method": "blend"
},
"north": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_south') && q.block_state('wiki:connection') == 1",
"components": {
"tag:top": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_top",
"render_method": "blend"
},
"south": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_east') && q.block_state('wiki:connection') == 1",
"components": {
"tag:top": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_top",
"render_method": "blend"
},
"east": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
//in this situation if there is a block to the west and it is the upper connected texture then it shall have the west side invisible and the sides be the upper connected part
{
"condition": "q.block_state('wiki:cull_west') && q.block_state('wiki:connection') == 1",
"components": {
"tag:top": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_top",
"render_method": "blend"
},
"west": {
"texture": "nothing",
"render_method": "blend"
},
"up": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"down": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_north') && q.block_state('wiki:connection') == 2",
"components": {
"tag:bottom": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_bottom",
"render_method": "blend"
},
"north": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_south') && q.block_state('wiki:connection') == 2",
"components": {
"tag:bottom": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_bottom",
"render_method": "blend"
},
"south": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_east') && q.block_state('wiki:connection') == 2",
"components": {
"tag:bottom": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_bottom",
"render_method": "blend"
},
"east": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_west') && q.block_state('wiki:connection') == 2",
"components": {
"tag:bottom": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_bottom",
"render_method": "blend"
},
"west": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "custom_vertical_connecting_glass_up"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_north') && q.block_state('wiki:connection') == 3",
"components": {
"tag:middle": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_middle",
"render_method": "blend"
},
"north": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "nothing"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_south') && q.block_state('wiki:connection') == 3",
"components": {
"tag:middle": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_middle",
"render_method": "blend"
},
"south": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "nothing"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_east') && q.block_state('wiki:connection') == 3",
"components": {
"tag:middle": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_middle",
"render_method": "blend"
},
"east": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "nothing"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
},
{
"condition": "q.block_state('wiki:cull_west') && q.block_state('wiki:connection') == 3",
"components": {
"tag:middle": {},
"minecraft:material_instances": {
"*": {
"texture": "custom_vertical_connecting_glass_middle",
"render_method": "blend"
},
"west": {
"texture": "nothing",
"render_method": "blend"
},
"down": {
"render_method": "blend",
"texture": "nothing"
},
"up": {
"render_method": "blend",
"texture": "nothing"
}
}
}
}
],
"events": {
"wiki:update": {
"sequence": [
// Set the block to have no culling
{
"condition": "q.block_neighbor_has_any_tag(0,0,-1,'custom_vertical_connecting_glass')",
"set_block_state": {
"wiki:cull_north": "q.block_neighbor_has_any_tag(0,0,-1,'custom_vertical_connecting_glass')",
"wiki:cull_south": "q.block_neighbor_has_any_tag(0,0,1,'custom_vertical_connecting_glass')",
"wiki:cull_west": "q.block_neighbor_has_any_tag(-1,0,0,'custom_vertical_connecting_glass')",
"wiki:cull_east": "q.block_neighbor_has_any_tag(1,0,0,'custom_vertical_connecting_glass')"
}
},
// Control the custom texture state
{
"condition": "q.block_neighbor_has_any_tag(0,-1,0,'default')",
"set_block_state": {
"wiki:connection": 1
}
},
{
"condition": "q.block_neighbor_has_any_tag(0,1,0,'top') && !q.block_neighbor_has_any_tag(0,-1,0,'middle')",
"set_block_state": {
"wiki:connection": 2
}
},
{
"condition": "q.block_neighbor_has_any_tag(0,1,0,'top') && q.block_neighbor_has_any_tag(0,-1,0,'middle')",
"set_block_state": {
"wiki:connection": 3
}
},
{
"condition": "q.block_neighbor_has_any_tag(0,-1,0,'top')",
"set_block_state": {
"wiki:connection": 1
}
},
{
"condition": "q.block_neighbor_has_any_tag(0,-1,0,'bottom') && (q.block_neighbor_has_any_tag(0,1,0,'top') || q.block_neighbor_has_any_tag(0,1,0,'middle'))",
"set_block_state": {
"wiki:connection": 3
}
},
{
"condition": "!q.block_neighbor_has_any_tag(0,1,0,'top', 'default', 'middle', 'bottom') && q.block_neighbor_has_any_tag(0,-1,0,'middle', 'bottom')",
"set_block_state": {
"wiki:connection": 1
}
},
{
"condition": "!q.block_neighbor_has_any_tag(0,1,0,'top', 'default', 'middle', 'bottom') && !q.block_neighbor_has_any_tag(0,-1,0,'middle', 'bottom', 'top', 'default')",
"set_block_state": {
"wiki:connection": 0
}
},
{
"condition": "q.block_neighbor_has_any_tag(0,1,0,'top', 'middle', 'bottom') && !q.block_neighbor_has_any_tag(0,-1,0,'middle', 'bottom', 'top', 'default')",
"set_block_state": {
"wiki:connection": 2
}
},
{
"condition": "q.block_neighbor_has_any_tag(0,1,0,'default') && q.block_neighbor_has_any_tag(0,-1,0,'default')",
"set_block_state": {
"wiki:connection": 3
}
}
]
}
}
}
}
```
</Spoiler>

View File

@@ -0,0 +1,289 @@
---
title: Custom Glazed Terracotta
category: Vanilla Re-Creations
tags:
- easy
mentions:
- Kaioga5
---
::: tip FORMAT & MIN ENGINE VERSION `1.20.40`
This tutorial assumes a basic understanding of blocks.
Check out the [blocks guide](/blocks/blocks-intro) before starting.
:::
## Introduction
Glazed Terracotta has its own rotation mechanism, enabling players to craft aesthetically pleasing patterns for walls, floors, and ceilings. This guide will instruct you on creating your own blocks resembling glazed terracotta.
## Custom Glazed Terracotta
This will create a vanilla-like custom glazed terracotta.
<CodeHeader>BP/blocks/custom_glazed_terracotta.json</CodeHeader>
```json
{
"format_version": "1.20.40",
"minecraft:block": {
"description": {
"identifier": "wiki:glazed_terracotta_template",
"menu_category": {
"category": "construction",
"group": "itemGroup.name.glazedTerracotta"
},
"traits": {
"minecraft:placement_direction": {
"enabled_states": [
"minecraft:cardinal_direction"
]
}
}
},
"permutations": [
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'north'",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] },
"minecraft:geometry": {
"identifier": "geometry.glazed_terracotta",
"bone_visibility": {
"bottom_1": false,
"bottom_2": false,
"bottom_3": false,
"bottom_4": true
}
}
}
},
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'west'",
"components": {
"minecraft:transformation": { "rotation": [0, 90, 0] },
"minecraft:geometry": {
"identifier": "geometry.glazed_terracotta",
"bone_visibility": {
"bottom_1": false,
"bottom_2": false,
"bottom_3": true,
"bottom_4": false
}
}
}
},
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'south'",
"components": {
"minecraft:transformation": { "rotation": [0, 180, 0] },
"minecraft:geometry": {
"identifier": "geometry.glazed_terracotta",
"bone_visibility": {
"bottom_1": false,
"bottom_2": true,
"bottom_3": false,
"bottom_4": false
}
}
}
},
{
"condition": "q.block_state('minecraft:cardinal_direction') == 'east'",
"components": {
"minecraft:transformation": { "rotation": [0, -90, 0] },
"minecraft:geometry": {
"identifier": "geometry.glazed_terracotta",
"bone_visibility": {
"bottom_1": true,
"bottom_2": false,
"bottom_3": false,
"bottom_4": false
}
}
}
}
],
"components": {
"minecraft:geometry": {
"identifier": "geometry.glazed_terracotta"
},
"minecraft:material_instances": {
"*": {
"texture": "purple_glazed_terracotta",
"render_method": "opaque"
}
}
}
}
}
```
## Geometry
Vanilla glazed terracotta rotates certain faces of the block with some specific values, which is what gives the block it's magic. Use the following geometry to replicate that behavior.
<Spoiler title="Geometry JSON">
<CodeHeader>RP/models/blocks/glazed_terracotta.geo.json</CodeHeader>
```json
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.glazed_terracotta",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 4,
"visible_bounds_height": 3.5,
"visible_bounds_offset": [0, 1.25, 0]
},
"bones": [
{
"name": "glazed_terracotta",
"pivot": [0, 0, 0]
},
{
"name": "top",
"parent": "glazed_terracotta",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 16, 16],
"uv": {
"up": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
},
{
"name": "north",
"parent": "glazed_terracotta",
"pivot": [0, 8, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 16, 0],
"pivot": [0, 8, 0],
"rotation": [180, 0, 90],
"uv": {
"north": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
},
{
"name": "south",
"parent": "glazed_terracotta",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [0, -8, 8],
"size": [16, 16, 0],
"pivot": [0, 0, 0],
"rotation": [180, 0, 270],
"uv": {
"south": {"uv": [0, 0], "uv_size": [16, 16]}
}
}
]
},
{
"name": "east",
"parent": "glazed_terracotta",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, -16, -8],
"size": [0, 16, 16],
"pivot": [0, 0, 0],
"rotation": [0, 0, -180],
"uv": {
"east": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
},
{
"name": "west",
"parent": "glazed_terracotta",
"pivot": [-16, 0, 0],
"cubes": [
{
"origin": [-24, 0, -8],
"size": [0, 16, 16],
"pivot": [-16, 0, 0],
"rotation": [0, 180, 0],
"uv": {
"west": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
},
{
"name": "bottom",
"parent": "glazed_terracotta",
"pivot": [0, 0, 0]
},
{
"name": "bottom_1",
"parent": "bottom",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 0, 16],
"uv": {
"down": {"uv": [0, 0], "uv_size": [16, 16]}
}
}
]
},
{
"name": "bottom_2",
"parent": "bottom",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 0, 16],
"uv": {
"down": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
},
{
"name": "bottom_3",
"parent": "bottom",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 0, 16],
"uv": {
"down": {"uv": [0, 0], "uv_size": [16, 16]}
}
}
]
},
{
"name": "bottom_4",
"parent": "bottom",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 0, 16],
"uv": {
"down": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
}
]
}
]
}
```
</Spoiler>

View File

@@ -0,0 +1,201 @@
---
title: Custom Slabs
category: Vanilla Re-Creations
tags:
- experimental
- easy
mentions:
- Kaioga5
- QuazChick
---
::: tip FORMAT & MIN ENGINE VERSION `1.20.30`
This tutorial assumes a basic understanding of blocks.
Check out the [blocks guide](/blocks/blocks-intro) before starting.
:::
::: warning EXPERIMENTAL
Requires `Holiday Creator Features` to trigger block events and for use of the `minecraft:unit_cube` component.
:::
## Introduction
Making custom slabs is a simple task, but if you find any drawbacks during recreating slabs, this tutorial will help you with it, and you'll be provided with a template for you to use.
Issues:
- Your custom slab will appear vertically centred when carried.
- Your custom slab may appear full-sized in item form (on the ground, in item frames, in hand)
## Custom Slab
This will create a vanilla-like custom slab.
<CodeHeader>BP/blocks/custom_slab.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_slab",
"menu_category": {
"category": "construction",
"group": "itemGroup.name.slab"
},
"traits": {
"minecraft:placement_position": {
"enabled_states": ["minecraft:vertical_half"]
}
},
"states": {
"wiki:double": [false, true]
}
},
"permutations": [
// Bottom Slab
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && !q.block_state('wiki:double')",
"components": {
"minecraft:collision_box": {
"origin": [-8, 0, -8],
"size": [16, 8, 16]
},
"minecraft:selection_box": {
"origin": [-8, 0, -8],
"size": [16, 8, 16]
},
"minecraft:on_interact": {
"event": "wiki:form_double",
"condition": "q.block_face == 1.0 && q.is_item_name_any('slot.weapon.mainhand', 'wiki:custom_slab')"
}
}
},
// Top Slab
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && !q.block_state('wiki:double')",
"components": {
"minecraft:collision_box": {
"origin": [-8, 8, -8],
"size": [16, 8, 16]
},
"minecraft:selection_box": {
"origin": [-8, 8, -8],
"size": [16, 8, 16]
},
"minecraft:on_interact": {
"event": "wiki:form_double",
"condition": "q.block_face == 0.0 && q.is_item_name_any('slot.weapon.mainhand', 'wiki:custom_slab')"
}
}
},
// Double Slab
{
"condition": "q.block_state('wiki:double')",
"components": {
"minecraft:unit_cube": {},
"minecraft:on_player_destroyed": {
"event": "wiki:destroy_double"
}
}
}
],
"components": {
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 7
},
"minecraft:destructible_by_explosion": {
"explosion_resistance": 6
},
"minecraft:geometry": {
"identifier": "geometry.slab",
"bone_visibility": {
"bottom_slab": "q.block_state('minecraft:vertical_half') == 'bottom'",
"top_slab": "q.block_state('minecraft:vertical_half') == 'top'"
}
},
"minecraft:material_instances": {
"*": {
"texture": "stone"
}
}
},
"events": {
"wiki:form_double": {
"set_block_state": {
"wiki:double": true
},
"run_command": {
"command": "playsound use.stone @a ~~~ 1 0.8"
},
"decrement_stack": {}
},
"wiki:destroy_double": {
"spawn_loot": {} // Spawns the block's default loot
}
}
}
}
```
## Geometry
This will be the geometry used for your custom slabs.
<Spoiler title="Geometry JSON">
<CodeHeader>RP/models/blocks/slab.geo.json</CodeHeader>
```json
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.slab",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 2,
"visible_bounds_height": 2.5,
"visible_bounds_offset": [0, 0.75, 0]
},
"bones": [
{
"name": "top_slab",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 8, -8],
"size": [16, 8, 16],
"uv": {
"north": {"uv": [0, 0], "uv_size": [16, 8]},
"east": {"uv": [0, 0], "uv_size": [16, 8]},
"south": {"uv": [0, 0], "uv_size": [16, 8]},
"west": {"uv": [0, 0], "uv_size": [16, 8]},
"up": {"uv": [16, 16], "uv_size": [-16, -16]},
"down": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
},
{
"name": "bottom_slab",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 8, 16],
"uv": {
"north": {"uv": [0, 8], "uv_size": [16, 8]},
"east": {"uv": [0, 8], "uv_size": [16, 8]},
"south": {"uv": [0, 8], "uv_size": [16, 8]},
"west": {"uv": [0, 8], "uv_size": [16, 8]},
"up": {"uv": [16, 16], "uv_size": [-16, -16]},
"down": {"uv": [16, 16], "uv_size": [-16, -16]}
}
}
]
}
]
}
]
}
```
</Spoiler>

View File

@@ -0,0 +1,254 @@
---
title: Custom Trapdoors
category: Vanilla Re-Creations
tags:
- experimental
- intermediate
mentions:
- Kaioga5
- QuazChick
---
::: tip FORMAT & MIN ENGINE VERSION `1.20.30`
This tutorial assumes a good understanding of blocks.
Check out the [blocks guide](/blocks/blocks-intro) before starting.
:::
::: warning EXPERIMENTAL
Requires `Holiday Creator Features` to trigger block events.
:::
## Introduction
Making custom trapdoors is an often difficult task to do, but after reading this tutorial you'll understand how they work in case you find any drawbacks during recreating them, and you'll be provided with a template for you to use.
## Custom Trapdoor
This will create a vanilla-like custom trapdoor.
<CodeHeader>BP/blocks/custom_trapdoor.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_trapdoor",
"menu_category": {
"category": "construction",
"group": "itemGroup.name.trapdoor"
},
"traits": {
"minecraft:placement_position": {
"enabled_states": ["minecraft:vertical_half"]
},
"minecraft:placement_direction": {
"enabled_states": ["minecraft:cardinal_direction"]
}
},
"states": {
"wiki:open": [false, true]
}
},
"permutations": [
// Top Closed
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'north' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 180] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'south' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [180, 0, 0] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'east' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [180, -270, 0] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'west' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [180, 270, 0] }
}
},
// Top Open
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'north' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [-270, 0, 0] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'south' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [270, 0, -180] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'east' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [0, 270, 90] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'top' && q.block_state('minecraft:cardinal_direction') == 'west' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": {
"rotation": [180, -270, -270]
}
}
},
// Bottom Closed
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'north' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'south' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [0, 180, 0] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'east' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [0, 270, 0] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'west' && !q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [0, -270, 0] }
}
},
// Bottom Open
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'north' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [90, 0, 180] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'south' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [270, 0, 0] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'east' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [0, -270, 90] }
}
},
{
"condition": "q.block_state('minecraft:vertical_half') == 'bottom' && q.block_state('minecraft:cardinal_direction') == 'west' && q.block_state('wiki:open')",
"components": {
"minecraft:transformation": { "rotation": [180, 270, -270] }
}
}
],
"components": {
"minecraft:collision_box": {
"origin": [-8, 0, -8],
"size": [16, 3, 16]
},
"minecraft:selection_box": {
"origin": [-8, 0, -8],
"size": [16, 3, 16]
},
"minecraft:geometry": "geometry.trapdoor",
"minecraft:material_instances": {
"*": {
"texture": "spruce_trapdoor",
"render_method": "alpha_test"
}
},
"minecraft:on_interact": {
"event": "wiki:toggle"
}
},
"events": {
"wiki:toggle": {
"sequence": [
{
"set_block_state": {
"wiki:open": "!q.block_state('wiki:open')"
}
},
{
"condition": "q.block_state('wiki:open')",
"run_command": {
"command": "playsound close.wooden_trapdoor @a ~~~ 0.9 0.9"
}
},
{
"condition": "!q.block_state('wiki:open')",
"run_command": {
"command": "playsound open.wooden_trapdoor @a ~~~ 0.9 0.9"
}
}
]
}
}
}
}
```
## Geometry
This will be the geometry used for your custom trapdoors.
<Spoiler title="Geometry JSON">
<CodeHeader>RP/models/blocks/trapdoor.geo.json</CodeHeader>
```json
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.trapdoor",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 2,
"visible_bounds_height": 1.5,
"visible_bounds_offset": [0, 0.25, 0]
},
"bones": [
{
"name": "trapdoor",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, -8],
"size": [16, 3, 16],
"uv": {
"north": {"uv": [16, 3], "uv_size": [-16, -3]},
"east": {"uv": [16, 3], "uv_size": [-16, -3]},
"south": {"uv": [16, 3], "uv_size": [-16, -3]},
"west": {"uv": [16, 3], "uv_size": [-16, -3]},
"up": {"uv": [16, 16], "uv_size": [-16, -16]},
"down": {"uv": [0, 0], "uv_size": [16, 16]}
}
}
]
}
]
}
]
}
```
</Spoiler>
:::tip
Vanilla trapdoors have a few issues in the direction of the texture in certain faces and having a height of 2.95 when it should be 3. This block template and geometry fixes both of those issues.
:::

View File

@@ -0,0 +1,994 @@
---
title: Custom Trees
category: Vanilla Re-Creations
tags:
- experimental
mentions:
- MedicalJewel105
- TheItsNameless
- QuazChick
---
::: tip FORMAT & MIN ENGINE VERSION `1.20.30`
This tutorial assumes an advanced understanding of blocks.
Check out the [blocks guide](/blocks/blocks-intro) before starting.
:::
::: warning EXPERIMENTAL
Requires `Holiday Creator Features` for use of block tag Molang queries and to trigger block events.
:::
Creating your own tree with decaying leaves is complex, but possible! Follow this tutorial and you'll have your own in no time.
- Features:
- Decaying leaves
- Tree Feature compatable
- If leaves were broken using shears, they will drop the block
- Leaves don't decay if placed by player
- Logs are strippable and rotatable
- Stripping logs is compatible with tools from other add-ons (if they have the `minecraft:is_axe` tag)
- Saplings can be bonemealed and grow the tree (with structures)
- Issues:
- If you make a structure with these blocks, it will crash the game when generated using features.
## Decaying Leaves
You will notice straight away that our custom leaves have a long list to search for a vanilla log/custom log by its block tag, although the code example uses the custom logs for this tutorial. The value is 4 and this method is used to search for the nearest log in a circular radius.
<WikiImage
src="/assets/images/blocks/custom-trees/decaying_leaves_showcase_example.png"
alt="Decaying Leaves Showcase"
pixelated="false"
width=420
/>
Our custom leaves disables ticking when placed by the player which doesn't make the leaves decay and this removes the requirements for another duplicate leave block.
<Spoiler title="Code">
<CodeHeader>BP/blocks/custom_leaves.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_leaves",
"states": {
"wiki:decay_tier": [4, 3, 2, 1, 0], // Distance in blocks to find the log
"wiki:should_decay": [true, false], // Used when placed by the player or with features
"wiki:opaque": [false, true] // Optional; makes the leaves opaque when surrounded
}
},
"components": {
"tag:custom_leaves": {},
"minecraft:loot": "loot_tables/empty.json",
"minecraft:unit_cube": {},
"minecraft:on_player_placing": {
"event": "wiki:stop_decay"
},
// Triggers event that spawns different loot
"minecraft:on_player_destroyed": {
"event": "wiki:on_destroyed"
},
// We need both of these to work with world generation
"minecraft:queued_ticking": {
"looping": true,
"interval_range": [0, 0],
"on_tick": {
"event": "wiki:check"
}
},
"minecraft:random_ticking": {
"on_tick": {
"event": "wiki:check"
}
},
"minecraft:destructible_by_explosion": {
"explosion_resistance": 1
},
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 0.3
},
"minecraft:map_color": "#DDDDDD",
"minecraft:light_dampening": 0,
"minecraft:material_instances": {
"*": {
"texture": "custom_leaves",
"render_method": "blend"
}
}
},
"events": {
// Defines the loot for the tool
"wiki:on_destroyed": {
"sequence": [
{
"condition": "q.is_item_name_any('slot.weapon.mainhand','minecraft:shears')",
"spawn_loot": {
"table": "loot_tables/blocks/custom_leaves_shears.json"
}
},
{
"condition": "!q.is_item_name_any('slot.weapon.mainhand','minecraft:shears')",
"spawn_loot": {
"table": "loot_tables/blocks/custom_leaves.json"
}
}
]
},
// Checks for the log
"wiki:check": {
"sequence": [
{
"condition": "q.block_state('wiki:should_decay')",
"set_block_state": {
"wiki:decay_tier": "(q.block_neighbor_has_any_tag(0,0,-1,'log') || q.block_neighbor_has_any_tag(0,0,1,'log') || q.block_neighbor_has_any_tag(-1,0,0,'log') || q.block_neighbor_has_any_tag(1,0,0,'log') || q.block_neighbor_has_any_tag(0,-1,0,'log') || q.block_neighbor_has_any_tag(0,1,0,'log')) ? 4 : ((q.block_neighbor_has_any_tag(0,0,-1,'decay_tier_4') || q.block_neighbor_has_any_tag(0,0,1,'decay_tier_4') || q.block_neighbor_has_any_tag(-1,0,0,'decay_tier_4') || q.block_neighbor_has_any_tag(1,0,0,'decay_tier_4') || q.block_neighbor_has_any_tag(0,-1,0,'decay_tier_4') || q.block_neighbor_has_any_tag(0,1,0,'decay_tier_4')) ? 3 : ( (q.block_neighbor_has_any_tag(0,0,-1,'decay_tier_3') || q.block_neighbor_has_any_tag(0,0,1,'decay_tier_3 ') || q.block_neighbor_has_any_tag(-1,0,0,'decay_tier_3') || q.block_neighbor_has_any_tag(1,0,0,'decay_tier_3') || q.block_neighbor_has_any_tag(0,-1,0,'decay_tier_3') || q.block_neighbor_has_any_tag(0,1,0,'decay_tier_3')) ? 2 : ( (q.block_neighbor_has_any_tag(0,0,-1,'decay_tier_2') || q.block_neighbor_has_any_tag(0,0,1,'decay_tier_2') || q.block_neighbor_has_any_tag(-1,0,0,'decay_tier_2') || q.block_neighbor_has_any_tag(1,0,0,'decay_tier_2') || q.block_neighbor_has_any_tag(0,-1,0,'decay_tier_2') || q.block_neighbor_has_any_tag(0,1,0,'decay_tier_2')) ? 1 : 0 ) ) )"
}
},
{
"set_block_state": {
"wiki:opaque": "q.block_neighbor_has_any_tag(0,0,-1,'log','stone','custom_leaves') && q.block_neighbor_has_any_tag(0,0,1,'log','stone','custom_leaves') && q.block_neighbor_has_any_tag(0,1,0,'log','stone','custom_leaves') && q.block_neighbor_has_any_tag(0,-1,0,'log','stone','custom_leaves') && q.block_neighbor_has_any_tag(-1,0,0,'log','stone','custom_leaves') && q.block_neighbor_has_any_tag(1,0,0,'log','stone','custom_leaves')"
}
}
]
},
// When placed
"wiki:stop_decay": {
"set_block_state": {
"wiki:should_decay": false
}
},
// When decayed
"wiki:decay": {
"die": {},
"spawn_loot": {
"table": "loot_tables/blocks/custom_leaves.json"
}
}
},
"permutations": [
{
"condition": "q.block_state('wiki:decay_tier') == 0",
"components": {
"minecraft:random_ticking": {
"on_tick": {
"event": "wiki:decay"
}
},
"tag:decay_tier_0": {}
}
},
{
"condition": "q.block_state('wiki:decay_tier') == 1",
"components": {
"tag:decay_tier_1": {}
}
},
{
"condition": "q.block_state('wiki:decay_tier') == 2",
"components": {
"tag:decay_tier_2": {}
}
},
{
"condition": "q.block_state('wiki:decay_tier') == 3",
"components": {
"tag:decay_tier_3": {}
}
},
{
"condition": "q.block_state('wiki:decay_tier') == 4",
"components": {
"tag:decay_tier_4": {}
}
},
{
"condition": "q.block_state('wiki:opaque')",
"components": {
"minecraft:material_instances": {
"*": {
"texture": "custom_leaves",
"render_method": "opaque"
}
}
}
}
]
}
}
```
</Spoiler>
## Custom Log
<Spoiler title="Code">
<CodeHeader>BP/blocks/custom_log.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_log",
"menu_category": {
"category": "nature",
"group": "itemGroup.name.log"
},
"states": {
// Log direction state
"wiki:axis": [0, 1, 2]
}
},
"components": {
"tag:log": {},
"minecraft:unit_cube": {},
// Sets different textures for sides and top/bottom of log
"minecraft:material_instances": {
"*": {
"texture": "custom_log"
},
"ends": {
"texture": "custom_log_top"
},
"up": "ends",
"down": "ends"
},
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 1
},
// Sets log rotation on player placing
"minecraft:on_player_placing": {
"event": "wiki:set_axis"
},
// Make log strippable
"minecraft:on_interact": {
"condition": "q.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_axe')",
"event": "wiki:strip"
}
},
"events": {
"wiki:set_axis": {
"set_block_state": {
"wiki:axis": "Math.floor(q.block_face / 2)"
}
},
"wiki:strip": {
"sequence": [
{
"run_command": {
"command": "playsound hit.wood @a ~~~"
},
// Damages axe of player who stripped the log
"damage": {
"type": "durability",
"amount": 1,
"target": "item"
}
},
{
"condition": "q.block_state('wiki:axis') == 0",
"run_command": {
"command": "setblock ~~~ wiki:custom_stripped_log [\"wiki:axis\"=0]"
}
},
{
"condition": "q.block_state('wiki:axis') == 1",
"run_command": {
"command": "setblock ~~~ wiki:custom_stripped_log [\"wiki:axis\"=1]"
}
},
{
"condition": "q.block_state('wiki:axis') == 2",
"run_command": {
"command": "setblock ~~~ wiki:custom_stripped_log [\"wiki:axis\"=2]"
}
}
]
}
},
"permutations": [
{
"condition": "q.block_state('wiki:axis') == 0",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 1",
"components": {
"minecraft:transformation": { "rotation": [90, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 2",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 90] }
}
}
]
}
}
```
</Spoiler>
## Stripped Log
Here all components are the same
<Spoiler title="Code">
<CodeHeader>BP/blocks/custom_stripped_log.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_stripped_log",
"menu_category": {
"category": "nature",
"group": "itemGroup.name.log"
},
"states": {
// Log direction state
"wiki:axis": [0, 1, 2]
}
},
"components": {
"tag:log": {},
"minecraft:unit_cube": {},
// Sets different textures for sides and top/bottom of log
"minecraft:material_instances": {
"*": {
"texture": "custom_stripped_log"
},
"ends": {
"texture": "custom_stripped_log_top"
},
"up": "ends",
"down": "ends"
},
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 1
},
// Sets log rotation on player placing
"minecraft:on_player_placing": {
"event": "wiki:set_axis"
}
},
"events": {
"wiki:set_axis": {
"set_block_state": {
"wiki:axis": "Math.floor(q.block_face / 2)"
}
}
},
"permutations": [
{
"condition": "q.block_state('wiki:axis') == 0",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 1",
"components": {
"minecraft:transformation": { "rotation": [90, 0, 0] }
}
},
{
"condition": "q.block_state('wiki:axis') == 2",
"components": {
"minecraft:transformation": { "rotation": [0, 0, 90] }
}
}
]
}
}
```
</Spoiler>
## Custom Sapling
For the sapling we will need structures of our tree to make the sapling semi-realistic as features cannot currently be placed with commands on Minecraft Bedrock.
<Spoiler title="Code">
<CodeHeader>BP/blocks/custom_sapling.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:block": {
"description": {
"identifier": "wiki:custom_sapling",
"states": {
// Sapling's growth stage
"wiki:growth_stage": [0, 1, 2]
}
},
"components": {
"minecraft:collision_box": false,
"minecraft:selection_box": {
"origin": [-6, 0, -6],
"size": [12, 13, 12]
},
"minecraft:light_dampening": 0,
"minecraft:geometry": "geometry.custom_sapling",
"minecraft:material_instances": {
"*": {
"texture": "custom_sapling",
"render_method": "alpha_test",
"face_dimming": false,
"ambient_occlusion": false
}
},
// Add loot component so it will drop sapling placer item
"minecraft:loot": "loot_tables/blocks/custom_sapling.json",
// Allows to place block only on these blocks
"minecraft:placement_filter": {
"conditions": [
{
"allowed_faces": ["up"],
"block_filter": ["minecraft:dirt", "minecraft:grass", "minecraft:podzol"]
}
]
},
// Trigger growth on each random tick
"minecraft:random_ticking": {
"on_tick": {
"event": "wiki:grow"
}
},
// Trigger growth when bone meal is used
"minecraft:on_interact": {
"condition": "q.is_item_name_any('slot.weapon.mainhand', 'minecraft:bone_meal')",
"event": "wiki:fertilize"
}
},
"events": {
"wiki:grow": {
"sequence": [
{
"condition": "q.block_state('wiki:growth_stage') < 2",
"set_block_state": {
"wiki:growth_stage": "q.block_state('wiki:growth_stage') + 1"
}
},
{
"condition": "q.block_state('wiki:growth_stage') == 2",
"run_command": {
"command": "structure load custom_tree ~-2~~-2"
}
}
]
},
"wiki:fertilize": {
// Removes item that was used to interact
"decrement_stack": {},
// Trigger growth
"trigger": {
"event": "wiki:grow"
},
// Trigger effects
"run_command": {
"command": ["particle minecraft:crop_growth_emitter ~~~", "playsound item.bone_meal.use @a ~~~"]
}
}
}
}
}
```
</Spoiler>
## Sapling Placer
<Spoiler title="Code">
<CodeHeader>BP/items/custom_sapling_placer.json</CodeHeader>
```json
{
"format_version": "1.20.30",
"minecraft:item": {
"description": {
"identifier": "wiki:custom_sapling_placer",
"menu_category": {
"category": "nature",
"group": "itemGroup.name.sapling"
}
},
"components": {
"minecraft:max_stack_size": 64,
"minecraft:block_placer": {
"block": "wiki:custom_sapling"
},
"minecraft:icon": {
"texture": "custom_sapling_placer"
}
}
}
}
```
</Spoiler>
## Loot Tables
<Spoiler title="Code">
This loot will spawn leaves block (when you break it using shears)
<CodeHeader>BP/loot_tables/blocks/custom_leaves_shears.json</CodeHeader>
```json
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "wiki:custom_leaves"
}
]
}
]
}
```
Leaves default loot
<CodeHeader>BP/loot_tables/blocks/custom_leaves.json</CodeHeader>
```json
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:apple",
"weight": 1
},
{
"type": "item",
"name": "wiki:custom_sapling_placer",
"weight": 5
},
{
// Nothing will drop
"type": "empty",
"weight": 10
}
]
}
]
}
```
This will spawn `wiki:custom_sapling`
<CodeHeader>BP/loot_tables/blocks/custom_sapling.json</CodeHeader>
```json
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "wiki:custom_sapling_placer"
}
]
}
]
}
```
</Spoiler>
## Exporting Structures
Build a tree for your sapling to grow into!
![](/assets/images/blocks/custom-trees/export_tree.png)
## Tree Features
:::tip
Tree Features are a really great way to get actual custom trees. You need some understanding on how they work but for this tutorial you can uses these templates.
:::
<Spoiler title="Feature">
<CodeHeader>BP/feature/custom_tree_feature.json</CodeHeader>
```json
{
"format_version": "1.13.0",
"minecraft:tree_feature": {
"description": {
"identifier": "wiki:custom_tree_feature"
},
"trunk": {
"trunk_block": "wiki:custom_log",
"trunk_height": {
"range_min": 4,
"range_max": 7
}
},
"canopy": {
"leaf_block": "wiki:custom_leaves",
"canopy_offset": {
"min": -3,
"max": 0
},
"variation_chance": [
{
"numerator": 1,
"denominator": 2
},
{
"numerator": 1,
"denominator": 2
},
{
"numerator": 1,
"denominator": 2
},
{
"numerator": 1,
"denominator": 1
}
]
},
"base_block": [
"minecraft:dirt",
{
"name": "minecraft:dirt",
"states": {
"dirt_type": "coarse"
}
}
],
"may_grow_on": [
"minecraft:dirt",
"minecraft:grass",
"minecraft:podzol",
{
"name": "minecraft:dirt",
"states": {
"dirt_type": "coarse"
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 0
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 1
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 2
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 3
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 4
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 5
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 6
}
},
{
"name": "minecraft:farmland",
"states": {
"moisturized_amount": 7
}
}
],
"may_replace": [
"minecraft:air",
{
"name": "minecraft:leaves",
"states": {
"old_leaf_type": "oak"
}
},
{
"name": "minecraft:leaves",
"states": {
"old_leaf_type": "spruce"
}
},
{
"name": "minecraft:leaves",
"states": {
"old_leaf_type": "birch"
}
},
{
"name": "minecraft:leaves",
"states": {
"old_leaf_type": "jungle"
}
},
{
"name": "minecraft:leaves2",
"states": {
"new_leaf_type": "acacia"
}
},
{
"name": "minecraft:leaves2",
"states": {
"new_leaf_type": "dark_oak"
}
}
],
"may_grow_through": [
"minecraft:dirt",
"minecraft:grass",
{
"name": "minecraft:dirt",
"states": {
"dirt_type": "coarse"
}
}
]
}
}
```
</Spoiler>
<Spoiler title="Feature Rule">
<CodeHeader>BP/feature_rules/custom_tree_feature_rule.json</CodeHeader>
```json
{
"format_version": "1.13.0",
"minecraft:feature_rules": {
"description": {
"identifier": "wiki:custom_tree_feature_rule",
"places_feature": "wiki:custom_tree_feature"
},
"conditions": {
"placement_pass": "surface_pass",
"minecraft:biome_filter": [
{
"test": "has_biome_tag",
"operator": "==",
"value": "plains"
}
]
},
"distribution": {
"iterations": 1,
"x": {
"distribution": "uniform",
"extent": [0, 16]
},
"y": "q.heightmap(v.worldx, v.worldz)",
"z": {
"distribution": "uniform",
"extent": [0, 16]
}
}
}
}
```
</Spoiler>
## Resource Pack (optional guide)
Now it is time to make a resource pack!
Make translations for blocks:
<CodeHeader>RP/texts/en_US.lang</CodeHeader>
```
tile.wiki:custom_log.name=Custom Log
tile.wiki:custom_leaves.name=Custom Leaves
tile.wiki:custom_stripped_log.name=Custom Stripped Log
tile.wiki:custom_sapling.name=Custom Sapling
item.wiki:custom_sapling_placer=Custom Sapling
```
Make terrain_texture.json and textures.
<CodeHeader>RP/textures/terrain_texture.json</CodeHeader>
```json
{
"resource_pack_name": "custom-trees",
"texture_name": "atlas.terrain",
"num_mip_levels": 4,
"padding": 8,
"texture_data": {
"custom_leaves": {
"textures": "textures/blocks/leaves_oak"
},
"custom_log": {
"textures": "textures/blocks/log_oak"
},
"custom_log_top": {
"textures": "textures/blocks/log_oak_top"
},
"custom_stripped_log": {
"textures": "textures/blocks/stripped_oak_log"
},
"custom_stripped_log_top": {
"textures": "textures/blocks/stripped_oak_log_top"
},
"custom_sapling": {
"textures": "textures/blocks/sapling_oak"
}
}
}
```
Make geometry for sapling:
<CodeHeader>RP/models/blocks/custom_sapling.geo.json</CodeHeader>
```json
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.custom_sapling",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 2,
"visible_bounds_height": 2.5,
"visible_bounds_offset": [0, 0.75, 0]
},
"bones": [
{
"name": "sapling",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-8, 0, 0],
"size": [16, 16, 0],
"pivot": [0, 0, 0],
"rotation": [0, 45, 0],
"uv": {
"north": {"uv": [0, 0], "uv_size": [16, 16]}
}
},
{
"origin": [-8, 0, 0],
"size": [16, 16, 0],
"pivot": [0, 0, 0],
"rotation": [0, -45, 0],
"uv": {
"north": {"uv": [0, 0], "uv_size": [16, 16]}
}
}
]
}
]
}
]
}
```
Make item_texture file
<CodeHeader>RP/textures/item_texture.json</CodeHeader>
```json
{
"resource_pack_name": "custom-trees",
"texture_name": "atlas.items",
"texture_data": {
"custom_sapling_placer": {
"textures": "textures/blocks/sapling_oak"
}
}
}
```
Add sounds to blocks
<CodeHeader>RP/blocks.json</CodeHeader>
```json
{
"format_version": [1, 1, 0],
"wiki:custom_leaves": {
"sound": "grass"
},
"wiki:custom_log": {
"sound": "wood"
},
"wiki:custom_stripped_log": {
"sound": "wood"
},
"wiki:custom_sapling": {
"sound": "grass"
}
}
```
## Result
What you have created:
<Checklist>
- [x] Custom Trees with Decaying Leaves
- [x] Working Sapling
- [x] Rotatable and Stripable Logs
</Checklist>
<FolderView :paths="[
'BP/blocks/custom_leaves.json',
'BP/blocks/custom_log.json',
'BP/blocks/custom_stripped_log.json',
'BP/blocks/custom_sapling.json',
'BP/features/custom_tree_feature.json',
'BP/feature_rules/custom_tree_feature_rule.json',
'BP/items/custom_sapling_placer.json',
'BP/loot_tables/blocks/custom_leaves.json',
'BP/loot_tables/blocks/custom_leaves_shears.json',
'BP/loot_tables/blocks/custom_sapling.json',
'BP/structures/custom_tree.mcstructure',
'RP/blocks.json',
'RP/texts/en_US.lang',
'RP/textures/terrain_texture.json',
'RP/models/blocks/custom_sapling.geo.json',
'RP/textures/item_texture.json'
]"></FolderView>
![](/assets/images/blocks/custom-trees/result.png)
## Download Example Pack
Template Pack to use in-game to get the idea.
<BButton
link="https://github.com/Bedrock-OSS/wiki-addon/releases/download/download/custom_trees.mcaddon"
color=blue
>Download MCADDON</BButton>

View File

@@ -0,0 +1,131 @@
---
title: 方块形状
category: 文档
mentions:
- SirLich
- yanasakana
- MedicalJewel105
- aexer0e
- Luthorius
- Fabrimat
- TheItsNameless
- QuazChick
---
# 方块形状
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
:::warning 已弃用
方块形状功能已不再受官方支持,且无法应用于自定义方块,但仍可作用于原版方块。
:::
方块形状本质上是硬编码于原版游戏中的几何模型,这意味着它们的存在不依赖于可见建模文件。
## 应用方式
在资源包的`blocks.json`文件中,通过方块对象的`"blockshape"`子项进行定义。具体示例如下:
::: code-group
```json [RP/blocks.json]
"wiki:invisible_aluminium_ore": {
"blockshape": "invisible",
"sound": "stone",
"textures": "invisible_aluminium_ore"
}
```
:::
## 已知方块形状列表
| 标识符 | 方块形状名称 |
| --- | ------------------------- |
| -1 | invisible不可见 |
| 0 | block普通方块 |
| 1 | cross_texture交叉纹理 |
| 2 | torch火把 |
| 3 | fire火焰 |
| 4 | water水体 |
| 5 | red_dust红石粉 |
| 6 | rows行排列 |
| 7 | door |
| 8 | ladder梯子 |
| 9 | rail轨道 |
| 10 | stairs阶梯 |
| 11 | fence栅栏 |
| 12 | lever拉杆 |
| 13 | cactus仙人掌 |
| 14 | bed |
| 15 | diode二极管 |
| 18 | iron_fence铁栏杆 |
| 19 | stem茎干 |
| 20 | vine藤蔓 |
| 21 | fence_gate栅栏门 |
| 22 | chest箱子 |
| 23 | lilypad睡莲 |
| 25 | brewing_stand炼药台 |
| 26 | portal_frame传送门框架 |
| 28 | cocoa可可豆 |
| 31 | tree树木 |
| 32 | cobblestone_wall圆石墙 |
| 40 | double_plant双层植物 |
| 42 | flower_pot花盆 |
| 43 | anvil铁砧 |
| 44 | dragon_egg龙蛋 |
| 48 | structure_void结构空位 |
| 67 | block_half半砖 |
| 68 | top_snow顶层雪 |
| 69 | tripwire绊线 |
| 70 | tripwire_hook绊线钩 |
| 71 | cauldron炼药锅 |
| 72 | repeater中继器 |
| 73 | comparator比较器 |
| 74 | hopper漏斗 |
| 75 | slime_block粘液块 |
| 76 | piston活塞 |
| 77 | beacon信标 |
| 78 | chorus_plant紫颂植物 |
| 79 | chorus_flower紫颂花 |
| 80 | end_portal末地传送门 |
| 81 | end_rod末地烛 |
| 83 | skull头颅 |
| 84 | facing_block朝向方块 |
| 85 | command_block命令方块 |
| 86 | terracotta陶瓦 |
| 87 | double_side_fence双面栅栏 |
| 88 | frame物品展示框 |
| 89 | shulker_box潜影盒 |
| 90 | doublesided_cross_texture双面交叉纹理 |
| 91 | doublesided_double_plant双面双层植物 |
| 92 | doublesided_rows双面行排列 |
| 93 | element_block元素方块 |
| 94 | chemistry_table化学工作台|
| 96 | coral_fan珊瑚扇 |
| 97 | seagrass海草 |
| 98 | kelp海带 |
| 99 | trapdoor活板门 |
| 100 | sea_pickle海泡菜 |
| 101 | conduit潮涌核心 |
| 102 | turtle_egg海龟蛋 |
| 105 | bubble_column气泡柱 |
| 106 | barrier屏障 |
| 107 | sign告示牌 |
| 108 | bamboo竹子 |
| 109 | bamboo_sapling竹笋 |
| 110 | scaffolding脚手架 |
| 111 | grindstone砂轮 |
| 112 | bell |
| 113 | lantern灯笼 |
| 114 | campfire营火 |
| 115 | lectern讲台 |
| 116 | sweet_berry_bush甜浆果丛|
| 117 | cartography_table制图台 |
| 119 | stonecutter_block切石机 |
| 123 | chain锁链 |
| 126 | sculk_sensor侦测器 |
| 133 | azalea杜鹃花丛 |
| 133 | flowering_azalea盛开的杜鹃花丛 |
| 134 | glow_frame荧光物品展示框|
| 135 | glow_lichen发光地衣 |
[原作者致谢](https://gist.github.com/toka7290/3bef704d2f57c775bb9ac84443a6df1c)

View File

@@ -0,0 +1,122 @@
---
title: 方块声音
category: 文档
mentions:
- MedicalJewel105
- TheItsNameless
- QuazChick
---
# 方块声音
<!--@include: @/wiki/bedrock-wiki-mirror.md-->
方块声音指的是`blocks.json`中方块条目内的音效属性。
该属性用于设置方块的基本音效,包含挖掘音效、踩踏音效、破坏音效和放置音效等。您可以通过以下方式为方块添加音效:
::: code-group
```json [RP/blocks.json]
{
"format_version": [1, 1, 0],
"wiki:custom_log": {
"sound": "wood" // 在此定义音效
}
}
```
:::
以下为`sound`属性的有效值:
<!-- page_dumper_start -->
| *最后更新于1.20.10版本* |
| -------------------------- |
| amethyst_block |
| amethyst_cluster |
| ancient_debris |
| anvil |
| azalea |
| azalea_leaves |
| bamboo |
| bamboo_sapling |
| bamboo_wood |
| bamboo_wood_hanging_sign |
| basalt |
| big_dripleaf |
| bone_block |
| calcite |
| candle |
| cave_vines |
| chain |
| cherry_leaves |
| cherry_wood |
| cherry_wood_hanging_sign |
| chiseled_bookshelf |
| cloth |
| comparator |
| copper |
| coral |
| decorated_pot |
| deepslate |
| deepslate_bricks |
| dirt_with_roots |
| dripstone_block |
| frog_spawn |
| froglight |
| fungus |
| glass |
| grass |
| gravel |
| hanging_roots |
| hanging_sign |
| honey_block |
| itemframe |
| ladder |
| lantern |
| large_amethyst_bud |
| lever |
| lodestone |
| mangrove_roots |
| medium_amethyst_bud |
| metal |
| moss_block |
| moss_carpet |
| mud |
| mud_bricks |
| muddy_mangrove_roots |
| nether_brick |
| nether_gold_ore |
| nether_sprouts |
| nether_wart |
| nether_wood |
| nether_wood_hanging_sign |
| netherite |
| netherrack |
| nylium |
| packed_mud |
| pink_petals |
| pointed_dripstone |
| powder_snow |
| roots |
| sand |
| scaffolding |
| sculk |
| sculk_catalyst |
| sculk_sensor |
| sculk_shrieker |
| sculk_vein |
| shroomlight |
| slime |
| small_amethyst_bud |
| snow |
| soul_sand |
| soul_soil |
| spore_blossom |
| stem |
| stone |
| suspicious_gravel |
| suspicious_sand |
| sweet_berry_bush |
| tuff |
| vines |
| wood |
<!-- page_dumper_end -->