微縮方塊

出自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需保持一致重新進入遊戲

然後這麼個東西出來了