微缩方块

来自Minecraft基岩版开发Wiki

"微缩方块",网易自定的一种新概念方块,在生存模式下使用木镐及以上采掘工具可以破坏并掉落其物品形式,它可以将游戏内自定义区域的方块压缩成若干个小方块进行显示,但这并不意味着类似将原方块缩小显示,方块为载体,显示时为一种纯色(相当于自定义了方块模型),目前仅开放预压缩方块。

网易示例,纯色方块,并非搭建的方块材质
网易示例,纯色方块,并非搭建的方块材质
  1. 预微缩方块,通过使用 modsdk 接口生成对应的微缩方块信息并由开发者保存为微缩方块文件,然后将该文件放入到 mod 中,重进游戏后,微缩方块便类似于游戏的原生方块,可以在物品列表里找到并使用

开发者可以通过Api CreateMicroBlockResStr 来对一个区域进行保存,返回的结果为字符串,开发者需要手动保存

CreateMicroBlockResStr(self, identifier, frompos, topos, colorMap=None, isMerge=False, icon="")
CreateMicroBlockResStr method in mod.server.component.blockCompServer.BlockCompServer 服务端
参数名 参数类型 说明
identifier str 微缩方块的唯一标识,由于会自动添加 micro_block:,所以这里只用填入 x 即可
start tuple(int,int,int) 微缩的起始坐标(游戏坐标)
end tuple(int,int,int) 微缩的结束坐标(游戏坐标)
colorMap dict 用于指定某类型方块的微缩后的方块颜色,例如 colorMap={"minecraft:grass": [12, 12, 12, 255]},会将所有草方块的颜色改变(RGB和RGBA)
isMerge bool 用于标识是否合并同类型方块
icon str 用于指定微缩方块的 icon。注意 icon 并不能直接使用图标所在的相对路径,而是需要先将图标添加到 terrain_texture.json 中,然后引用图标的注册名称
返回值
数据类型 说明
str 生成的微缩方块的资源字符串,书写于资源包根目录/models/netease_micro_block/xx.json里
  • 使用 frompos 和 topos 选中的区域,仅仅会生成其中的方块数据(包括自定义方块),对于生物等实体数据并不会包含其中。当选中的区域没有被加载时,不会产生数据,当选中的区域包含已加载区域和未加载区域时,仅仅只会产生已加载区域的数据。

拆开微缩方块数据驱动文件(来源于开发者文档)

{
"netease:micro_block": {
       "data": {
           "11": [[], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "10": [[], [], [0, 0, 0, 1], [], [], [], [], [], [], [], [0, 0, 0, 1]],
           "13": [[], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "12": [[], [], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "14": [[], [], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 2]],
           "1": [[], [], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1]],
           "3": [[], [], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "2": [[], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "5": [[], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [], [], [], [], [], [0, 0, 0, 1]],
           "4": [[], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "7": [[], [], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "6": [[], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1]],
           "9": [[], [], [0, 0, 0, 1], [0, 0, 0, 1], [], [], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1]],
           "8": [[], [], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [], [], [], [0, 0, 0, 1], [0, 0, 0, 1]]
       },
       "description": {
           "identifier": "micro_block:number_9_2",
           "blocks": [{//包含的方块信息
                   "aux": 0,
                   "name": "minecraft:grass",
                   "color": [254, 46, 45]
               }, {
                   "aux": 1,
                   "name": "minecraft:grass",
                   "color": [254, 46, 45]
               }
           ],
           "icon": "",
           "size": [11, 15, 6]
       }
   },
   "format_version": "1.13.0"
}


示例:

如图可见,这是我搭建的一个豪华小屋

我的豪华小屋

通过Api

comp = serverApi.GetEngineCompFactory().CreateBlock(self.GetLevelId())
result = comp.CreateMicroBlockResStr("x", (576, 96, -3), (573, 100, 0), colorMap={'minecraft:planks': [218, 165, 32, 255], 'minecraft:log': [0, 0, 0, 255], 'minecraft:glass_pane': [255, 140, 0, 255], 'minecraft:wooden_door': [255, 0, 0, 255]}, isMerge=True, icon="diamond")
print result

打印出了一段JSON文本,格式化了一下

{
    "netease:micro_block":{
        "data":{
            "0":[
                [
                    1,
                    2,
                    2
                ],
                [
                    3,
                    0,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ],
                [
                    4,
                    4,
                    4
                ]
            ],
            "1":[
                [
                    5,
                    2,
                    2
                ]
            ],
            "2":[
                [
                    6,
                    7,
                    8
                ]
            ],
            "3":[
                [
                    6,
                    2,
                    2
                ]
            ]
        },
        "description":{
            "identifier":"micro_block:x",
            "blocks":[
                {
                    "color":[
                        218,
                        165,
                        32,
                        255
                    ],
                    "aux":0,
                    "name":"minecraft:planks"
                },
                {
                    "color":[
                        218,
                        165,
                        32,
                        255
                    ],
                    "aux":1,
                    "name":"minecraft:planks"
                },
                {
                    "aux":0,
                    "name":"minecraft:grass"
                },
                {
                    "aux":3,
                    "name":"minecraft:grass"
                },
                {
                    "color":[
                        0,
                        0,
                        0,
                        255
                    ],
                    "aux":0,
                    "name":"minecraft:log"
                },
                {
                    "color":[
                        0,
                        0,
                        0,
                        255
                    ],
                    "aux":5,
                    "name":"minecraft:log"
                },
                {
                    "color":[
                        255,
                        140,
                        0,
                        255
                    ],
                    "aux":0,
                    "name":"minecraft:glass_pane"
                },
                {
                    "color":[
                        255,
                        140,
                        0,
                        255
                    ],
                    "aux":7,
                    "name":"minecraft:glass_pane"
                }
            ],
            "icon":"diamond",
            "size":[
                3,
                4,
                3
            ]
        }
    },
    "format_version":"1.13.0"
}

此段JSON代码写入资源包根目录/models/netease_micro_block/xx.json里

行为包根目录/netease_blocks/xx.json新编写一个自定义方块

两个文件中identifier需保持一致重新进入游戏

然后这么个东西出来了