Files
netease-bedrock-wiki/mcguide/20-玩法开发/15-自定义游戏内容/2-自定义方块/2-功能.md
2025-08-25 18:36:29 +08:00

277 lines
14 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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

---
front:
hard: 入门
time: 分钟
---
# 功能
## 获取及设置某个位置的方块
获取见服务端blockInfo组件的GetBlockNew接口
设置见服务端blockInfo组件的SetBlockNew接口
## 物品形式的生成及获取
支持“MOD SDK文档”中所有与物品相关的接口及事件其中的物品identifier对应方块identifier。
## 方块及物品事件
支持“MOD API”中所有与方块相关的事件其中添加了“fullName”字段返回对应的方块identifier
支持"MOD API"中所有与物品相关的事件其中添加了“itemName”字段返回对应的方块identifier。
## 自定义配方
见[自定义配方文档](../5-自定义配方.md)材料及结果都支持填写方块identifier。可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)行为包的netease_recipes
## 方块组合
见"MOD API"的服务端block组件defines项支持填写自定义方块的identifier。可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)脚本的CustomBlocksServer.RegisterBlockPattern
## 村民交易
可将行为包的交易配置中的item修改为自定义方块的identifier。可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)行为包的`trading\economy_trades\armorer_trades.json`里面将新手级盔甲商的其中一个交易项替换为绿宝石兑换customblocks:customblocks_test0方块
## 构成自定义群系
阅读这条前请先阅读[群系地貌文档](../4-自定义维度/2-群系地貌.md)。
可通过修改minecraft:overworld_surface字段来使用自定义方块生成区块。可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)行为包的`netease_biomes\dm5`里面在自定义群系demo[CustomBiomesMod](../../13-模组SDK编程/60-Demo示例.md#CustomBiomesMod)中dm5维度的基础上进行修改将该维度的dm5_cold_beach、dm5_frozen_ocean、dm5_frozen_river、dm5_ice_plains、dm5_river几个群系的地表方块进行了替换。
<span id="shengyin"></span>
## 声音
resource包中`blocks.json`配置方块的sound。
可以使用原版`sounds.json`中block_sounds里的类型。不支持添加自定义block_sounds类型
<span id="liangdu"></span>
## 亮度
行为包中使用[minecraft:block_light_emission](./1-JSON组件.md#minecraft_block_light_emission)可将方块设置为光源。
可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)的customblocks:customblocks_model_flower方块。
[minecraft:block_light_absorption](./1-JSON组件.md#minecraft_block_light_absorption)可设置方块透光率值的范围为0-15
<span id="wajue"></span>
## 挖掘
挖掘的详细介绍可参考[官方wiki](https://zh.minecraft.wiki/w/挖掘)
挖掘时间可使用[minecraft:destroy_time](./1-JSON组件.md#minecraft_destroy_time)配置
挖掘工具可使用[netease:tier](./1-JSON组件.md#netease_tier)配置
可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)的customblocks:customblocks_test_ore方块
<span id="duomianxiang"></span>
## 多面向
行为包中使用[netease:face_directional](./1-JSON组件.md#netease_face_directional)配置。
四面向可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)的customblocks:customblocks_test_face4方块
六面向可参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)的customblocks:customblocks_test_face6方块
对于两种面向当玩家进行放置时都是north的贴图面向玩家。
方块的面向等于north贴图面向的方向即玩家放置时准心的反方向
当设置为四面向时方块面向与附加值auxvalue的关系为
| 方块面向 | auxvalue |
| -------- | -------- |
| south | 0 |
| west | 1 |
| north | 2 |
| east | 3 |
当设置为六面向时方块面向与附加值auxvalue的关系为
| 方块面向 | auxvalue |
| -------- | -------- |
| down | 0 |
| up | 1 |
| north | 2 |
| south | 3 |
| west | 4 |
| east | 5 |
<span id="zidingyiqunxiyanse"></span>
## 自定义方块及自定义方块模型的群系颜色
关于生物群系颜色的描述可看[生物群系 - Minecraft Wiki最详细的我的世界百科 ](https://zh.minecraft.wiki/w/%E7%94%9F%E7%89%A9%E7%BE%A4%E7%B3%BB)
原版方块在不同生物群系中会有稍稍不同的颜色变化,例如草、树叶等方块,它们会随着它们所在的群系的温度以及降雨量而产生颜色变化,在温度高的环境中会偏绿,在降雨量低的环境中会变黄。
[自定义方块](./0-自定义方块概述.md)及[自定义方块模型](./5-自定义方块模型.md)也支持该特性。开发者们也可以参考[CustomBlocksMod](../../13-模组SDK编程/60-Demo示例.md#CustomBlocksMod)中的**customblocks:customblocks_leaves_tinted**方块、**customblocks:customblocks_leaves_tinted_by_dimension**方块、**customblocks:customblocks_test_face4_tinted**方块、**customblocks:customblocks_test_face4_tinted_by_dimension**方块以及**customblocks:customblocks_model_flower_tinted**方块并参考这五个方块所使用的的颜色渐变图CustomBlocksMod\CustomBlocksMod_resource\textures\colormap\my_grass.png和CustomBlocksMod\CustomBlocksMod_resource\textures\colormap\my_color2.png
以下将会说明如何为自定义方块添加自定义群系颜色和在不同的维度中指定使用不同的颜色渐变图。
#### **1. 颜色渐变图的准备**
首先我们需要为方块准备两张颜色渐变图color map,该图示例如下:
<img src="./picture/customblock/custom_foliage-0-1.png" style="zoom: 67%;" />
该图分辨率固定为256x256目前暂不支持其他分辨率并且仅图像中的左下三角形部分会被使用右上三角形部分不会被使用因此可以置为空白。
方块在被添加群系颜色时,会按照该群系的降雨量及温度来决定我们所取的群系颜色是这张颜色渐变图上的哪一个颜色点。其规则如下:
- 温度从低往高时会按照红色箭头方向从颜色渐变图的右边到左边决定颜色点的x坐标值
- 降雨量从低往高时会按照蓝色箭头方向从颜色渐变图的下方到上方决定颜色点的y坐标值。
举个例子,在降雨量低而且温度高的群系,所取的颜色为这张颜色渐变图的最左下角部分,即颜色会偏黄色。
**根据以上规则,开发者可以自己来定义自己的颜色渐变图来为自定义方块添加特殊的群系颜色。制作时也可以根据原版的颜色渐变图来修改。需要注意的是,分 辨率固定为256x256。**
制作好的渐变图可以放在resource_pack/textures/colormap/这个路径下。
#### **2. 为自定义方块设置这张渐变图**
渐变图的使用方式有两种,一种是为方块整体使用渐变图,一种是为方块中指定的贴图使用渐变图。
两种使用方式中,渐变图的设定方式也有两种,一种是为所有维度设定使用一张渐变图,一种是为不同维度设定使用不同渐变图。
##### 1为方块整体使用这张渐变图
在准备好颜色渐变图后我们需要在resource_pack/blocks.json中添加渐变图的配置
1对所有维度使用同一张渐变图
```json
"customblocks:customblocks_leaves_tinted": {
"sound": "grass",
"textures": "customblocks:customblocks_leaves_tinted",
// 使用"use_colormap"字段指定使用的colormap贴图路径
// 使用colormap后, 该方块的颜色将会随群系的变化而变化
"use_colormap":"textures/colormap/my_grass"
}
```
2对不同维度指定使用不同渐变图
```json
"customblocks:customblocks_leaves_tinted_by_dimension": {
"sound": "grass",
"textures": "customblocks:customblocks_leaves_tinted",
// 使用"use_colormap"字段指定使用的colormap贴图路径, 分辨率固定为256x256, 暂不支持其他分辨率
// 使用colormap后, 该方块的颜色将会随群系的变化而变化
// colormap支持字符串和dict格式配置成字符串格式表示所有维度使用同一张colormap贴图
// 配置成dict格式可以对指定维度使用指定colormap贴图其中default所指定为默认贴图
"use_colormap":{
"default":"textures/colormap/my_grass", // 默认的colormap贴图所在维度没有配置对应贴图时使用默认贴图
"overworld":"textures/colormap/my_grass", // 主世界的colormap贴图
"nether":"textures/colormap/my_color2", // 下界的colormap贴图
"the end":"textures/colormap/my_color2", // 末地的colormap贴图
// 自定义维度colormap贴图
"dm3":"textures/colormap/my_color2",
"dm5":"textures/colormap/my_color2",
"dm22":"textures/colormap/my_color2"
}
}
```
我们使用"use_colormap"字段来指定这个方块使用自定义群系颜色,
其中customblocks:customblocks_leaves_tinted方块对所有维度使用同一张渐变图use_colormap这个字段的值则是这张颜色渐变图的相对路径。
而customblocks:customblocks_leaves_tinted_by_dimension方块对不同维度使用不同渐变图use_colormap的格式为字典字典的key为维度名字主世界、下界、末地分别对应overworld、nether、the end自定义维度以“dm_”拼接维度id为名value为对应渐变图的相对路径。default为默认配置所在维度没有指定对应渐变图时使用该渐变图
这样我们的自定义方块就能在不同群系中表现出不同的颜色差异了。
<img src="./picture/customblock/custom_foliage-0-3.png" style="zoom: 67%;" />
其中customblocks:customblocks_leaves_tinted_by_dimension则可以在不同的维度中展现出不同的颜色渐变图的效果。
<img src="./picture/customblock/custom_foliage-0-4.png" style="zoom: 67%;" />
##### 2为方块指定的贴图使用这张渐变图
为方块指定的贴图使用这张渐变图时我们需要在resource_pack/textures/terrain_texture.json中为某张贴图进行指定
1对所有维度使用同一张渐变图
```json
"customblocks:customblocks_test_face4_top_tinted":{
"textures": "textures/blocks/glazed_terracotta_white",
// 使用"use_colormap"字段指定使用的colormap贴图路径, 分辨率固定为256x256, 暂不支持其他分辨率
"use_colormap":"textures/colormap/my_grass"
},
```
2对不同维度指定使用不同渐变图
```json
"customblocks:customblocks_test_face4_top_tinted_by_dimension":{
"textures": "textures/blocks/glazed_terracotta_white",
// 使用"use_colormap"字段指定使用的colormap贴图路径, 分辨率固定为256x256, 暂不支持其他分辨率
// colormap支持字符串和dict格式配置成字符串格式表示所有维度使用同一张colormap贴图
// 配置成dict格式可以对指定维度使用指定colormap贴图其中default所指定为默认贴图。
"use_colormap":{
"default":"textures/colormap/my_grass", // 默认的colormap贴图所在维度没有配置对应贴图时使用默认贴图
"overworld":"textures/colormap/my_grass", // 主世界的colormap贴图
"nether":"textures/colormap/my_color2", // 下界的colormap贴图
"the end":"textures/colormap/my_color2", // 末地的colormap贴图
// 自定义维度colormap贴图
"dm3":"textures/colormap/my_color2",
"dm5":"textures/colormap/my_color2",
"dm22":"textures/colormap/my_color2"
},
}
```
我们在上面的代码示例中为"customblocks:customblocks_test_face4_top_tinted"这张贴图在所有维度中指定了同一张渐变图,为"customblocks:customblocks_test_face4_top_tinted_by_dimension"这张贴图在不同维度中指定了不同的渐变图。这样一来我们可以在resource_pack/blocks.json为这个方块的某个面指定使用这两张贴图了
```json
"customblocks:customblocks_test_face4_tinted": {
"textures": {
// 这个贴图使用了带colormap的贴图(colormap在textures/terrain_texture.json中指定), 该面的颜色将会随群系的变化而变化
"down": "customblocks:customblocks_test_face4_front_tinted",
"up": "customblocks:customblocks_test_face4_front_not_tinted",
// 这个贴图使用了带colormap的贴图(colormap在textures/terrain_texture.json中指定), 该面的颜色将会随群系的变化而变化
"north": "customblocks:customblocks_test_face4_top_tinted",
"south": "customblocks:customblocks_test_face4_top_sides_not_tinted",
"west": "customblocks:customblocks_test_face4_top_sides_not_tinted",
// 这个贴图使用了带colormap的贴图(colormap在textures/terrain_texture.json中指定)
// 该面的颜色将会随群系的变化而变化且在不同的维度中会使用不同的colormap的贴图
"east": "customblocks:customblocks_test_face4_top_tinted_by_dimension"
},
"sound": "stone"
}
```
我们为这个方块的下表面,东表面以及北表面使用了这些带有渐变图的贴图,如此,方块就表现为某些面能在群系中产生不同颜色的变化,而某些面则不会产生颜色变化。
<img src="./picture/customblock/custom_foliage-0-2.png" style="zoom: 67%;" />
其中东表面的贴图对不同维度指定使用不同的渐变图,能在不同的维度中展现出使用不同渐变图的颜色变化效果。
<img src="./picture/customblock/custom_foliage-0-5.png" style="zoom: 67%;" />
#### **3.不适用的方块及情况**
注意,以下自定义方块或情形将不适用自定义群系颜色:
1重力方块在下落时由于会转换为方块实体因此方块颜色将变为原来的颜色。
2使用了textures/flipbook_textures.json中定义的动态贴图的自定义方块自定义群系颜色也不会生效。
3自定义方块实体外观不适用自定义群系颜色。
4自定义流体不适用自定义群系颜色。
5自定义刷怪箱、自定义传送门不适用自定义群系颜色。
6自定义方块模型无法支持为这个模型中指定的贴图使用自定义群系颜色只能整体使用自定义群系颜色。