Community程式設計與開發github.com

Minecraft 圖片建造器

分析上傳的 Minecraft 建築圖片或截圖,逆向工程出其確切尺寸、方塊調色板、屋頂輪廓、立面深度以及隱藏的後方/內部佈局,並立即輸出一個可下載的獨立無依賴 Node.js (.mjs) 生成器檔案,無需提問。

Minecraft 圖片建造器 是什麼?

Minecraft 圖片建造器是一款專業技能,專為從單張圖片或截圖中逆向工程 Minecraft 結構而設計。它能自動分析視覺細節,生成詳細的元件清單、座標錨點表,並建立一個可直接下載的獨立 ESM 檔案(.mjs),該檔案使用僅依賴 node:fs 和 node:zlib 的標準 Node.js 函式庫,產生適用於 Minecraft 26.3 (DataVersion 5023) 的壓縮 .nbt 結構檔案。此技能支援所有 Minecraft 結構類型,包括房屋、雕像、家具和紀念碑,並能處理多面板技術參考圖紙,從所有面板合成資訊以重建完整的 3D 模型。工作流程分為四個連續階段:深度視覺分解與元件清單、區塊註冊表驗證、座標錨點表與五階段建構規則,以及最終的獨立 .mjs 檔案輸出。此技能專為直接執行而設計,不會向使用者提出任何腦力激盪問題,非常適合需要快速、精準重建的場景。它相容於 Claude Code、Cursor 和 Codex 等平台。

相容平台✓Claude Code~Codex CLI~Cursor
Part ofMobile
npx skills add https://github.com/marvaproject/minecraft-structure-builder/tree/HEAD/minecraft-builder-img

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Minecraft 圖片建造器 是做什麼的?

將任何上傳的 Minecraft 結構圖片或截圖逆向工程,精確生成元件清單、座標錨點表,以及一個可下載的獨立、零依賴 ESM(.mjs)檔案(使用檔案生成工具,而非在聊天中傾印原始程式碼區塊),該檔案會匯出一個適用於 Minecraft 26.3(DataVersion: 5023)的 gzip 壓縮 vanilla .nbt 檔案,立即在單一次傳遞中完成,無需腦力激盪問題。

使用時機

  • 使用者提供了 Minecraft 建築(房屋、小屋、塔樓、橋樑、水井、雕像、家具、寺廟或綜合體)的圖片、截圖或渲染圖,並要求重現、複製、逆向工程或將其生成為 .nbt 或 Node.js 程式碼。
  • 使用者希望獲得直接的視覺分解 + 結構化的方塊/元件列表 + 立即的 .mjs 檔案輸出,無需來回確認。

不適用範圍

  • 從頭開始的純文字構想(未提供圖片)- 將其轉交給 minecraft-builder 進行從無到有的腦力激盪與建築設計。
  • 紅石電路、自訂地形/地形改造、儲物箱 NBT 內容或實體擺設 - 清楚說明限制,並改為重建靜態方塊外殼。

資料夾結構

minecraft-image-builder/
├── SKILL.md
└── registry_26_3.json

工作流程(直接執行 - 無腦力激盪)

當提供圖片時,不要提出釐清或腦力激盪問題。在單一回應中依序執行所有四個階段:

階段 1:深度視覺分解與元件清單

從下到上、從前到後仔細檢查圖片,然後輸出簡潔、結構化的藍圖與元件清單:

  1. 多面板技術圖紙與軸對齊(如適用):
    • 當上傳的圖片是多面板技術參考圖紙(例如 01. 前右 3/4 視角、02. 後左 3/4 視角、03. 內部/結構細節視角)時,將所有面板綜合在一起,而不是將它們視為獨立的建築。
    • 將 X、Y 和 Z 方向嚴格鎖定在面板 01 的 3D XYZ 軸輔助線(紅色 X、綠色 Y 向上、藍色 Z)以及任何 "FRONT" 地板標籤。如果面板 02 中的輔助線箭頭與面板 01 的相機旋轉衝突,則忽略面板 02 中翻轉或重複的輔助線箭頭。
    • 交叉比對面板 01 和面板 02,在不猜測的情況下提取所有 4 個外部立面,並優先使用面板 03 的剖面圖佈局來確定內部房間隔間、樓梯和家具擺放。
    • 忽略面板 03 中偶然出現的重複道具(例如一個額外的燈籠或告示牌),這些道具在面板 01 和面板 02 中均未出現。
  2. 整體尺寸與比例(網格三角測量):
    • 透過沿寬度 (X)、高度 (Y) 和深度 (Z) 計算可見方塊,估算確切的邊界框 SIZE = [W, H, L],保持與截圖相符的非 1:1:1 比例。
    • 如果牆壁或表面在 AI 生成的參考圖像中顯得平滑/非體素,則根據 1x1 地板網格線、角落框架柱、窗格和屋頂階梯進行三角測量確切方塊數量,而不是從平滑的牆壁高度猜測。
    • 定義高程基準層級:Y_base、Y_floor1、Y_floor2(如果多層)、Y_roof_start 和 Y_roof_peak。
  3. 材質調色板分解(對應 registry_26_3.json):
    • 地基/底座: 例如 cobblestone、stone_bricks、tuff_bricks、deepslate_bricks。
    • 框架柱與橫樑: 例如 oak_log、spruce_log、stripped_dark_oak_log 帶有 axis 屬性。
    • 主要與次要牆壁: 例如 oak_planks、white_concrete、calcite、mud_bricks。
    • 屋頂與飾邊: 例如 spruce_stairs、brick_stairs、deepslate_tile_stairs、半磚和懸挑飾邊。
    • 開口、照明與外部細節: 窗戶 (glass_pane)、百葉窗 (*_trapdoor)、門 (*_door)、柵欄/牆、燈籠、煙囪、葉子/藤蔓以及在鏡頭中可見的裝飾性道具。
  4. 背面與內部重建計畫(被遮擋側):
    • 對於在所有面板中仍隱藏的任何面或內部角落,推斷出對稱或功能連貫的佈局(與窗戶節奏和屋頂坡度匹配),並遵循模擬市民導航標準(床/工作站/展示品、每 4x4 區域照明、以及可通行的 1x2 路徑)乾淨地佈置內部,無需詢問使用者。

階段 2:方塊註冊表驗證(registry_26_3.json)

  • 根據技能目錄中的 registry_26_3.json(Minecraft 26.3 / DataVersion: 5023)驗證每個選擇的方塊 ID(minecraft:<name>)和狀態屬性。
  • 絕不發明方塊 ID 或列舉值。如果截圖中出現模組化、平滑或非體素的道具(例如平滑灰泥牆、空調機、展示冰箱、文字告示牌),將其轉換為 registry_26_3.json 中最接近的有效 vanilla 26.3 方塊組合,並在元件清單中註明映射關係。

階段 3:座標錨點表與 5 遍建構規則

在撰寫程式碼之前,將元件清單映射為精確的座標錨點表(X, Y, Z):

  1. 外殼與框架柱: 角柱 (X, Z) 座標與外部牆面平面。
  2. 內部地板範圍(X_min..X_max,Z_min..Z_max): 確保所有內部家具嚴格保持在 X_wall_west + 1 .. X_wall_east - 1 和 Z_wall_north + 1 .. Z_wall_south - 1 範圍內,以便第 5 遍永遠不會覆寫牆壁。
  3. 門、窗與陽台: 精確的 (X, Y, Z) + facing,在門/閘門前後保持 1-2 個可通行的地板瓷磚暢通,並確保任何圍欄陽台在其外部欄杆內有 >= 1 個可通行的地板行(深度 >= 2)。
  4. 樓梯與閣樓屋脊對齊:
    • 使用明確的 shape: 'straight' 鎖定可通行的樓梯階梯和樓梯椅,以便 autoConnectStairs() 僅塑造屋頂階梯。
    • 任何延伸至傾斜屋頂上層/閣樓的樓梯必須終止於高中心屋脊 (Y_roof_peak) 下方,以便 carveStairHeadroom(x, y, z, 3) 永遠不會穿透外部屋頂斜面。
    • 對於轉彎樓梯,使用與第一段樓梯頂部階梯 (Y_turn) 齊平的平坦 1x1(L 型轉彎)或 1x2(U 型轉彎)完整方塊平台,在平坦平台上方保持 2 個方塊的空氣,並從 Y_turn + 1 開始第二段樓梯。
    • 僅在上升階梯正上方且 step.y + 3 >= Y_upper 處移除上層地板磚,並用 *_fence 安全欄杆封閉開放的樓梯井邊緣。
  5. 離散網格鄰接與煙囪蓋:
    • 牆壁安裝物品(wall_torch、*_wall_sign、ladder、trapdoor 百葉窗、vine)佔據相鄰的空氣方塊(X_wall +/- 1 或 Z_wall +/- 1),永遠不會覆寫牆壁方塊。
    • 對於延伸至屋頂上方的外部煙囪,檢查頂部 campfire 周圍所有 4 個水平鄰近方塊,並在每個與 air 相鄰的側面放置打開的 *_trapdoor(open: 'true',half: 'top')。

階段 4:立即輸出獨立 .mjs 檔案與執行說明

生成並匯出完整的、自包含的 ESM 檔案(<build-name>.mjs)作為可下載的 .mjs 檔案(如果可用,使用 file_gen 工具——除非檔案生成不可用,否則不要將完整的 .mjs 原始碼作為原始 Markdown 程式碼區塊傾印在聊天回應中),僅使用 node:fs 和 node:zlib,並按照 5 遍建構分層順序進行:

  • 第 1 遍: 地基、樁柱和地板。
  • 第 2 遍: 框架柱、外牆、窗戶、陽台和門(placeDoor)。
  • 第 3 遍: 屋頂(帶 1 方塊懸挑)和外部煙囪(帶 4 面蓋)。
  • 第 4 遍: 樓梯(shape: 'straight')、精確的樓梯井地板鏤空、安全欄杆和 carveStairHeadroom()。
  • 第 5 遍: 內部家具(在房間範圍內)、placeBed()、牆壁附件、照明,接著是 autoConnectStairs()、autoPairDoubleDoors()、connectDoubleChests()、connectWalls() 以及 connectFencesAndPanes()。

不要包含執行時 throw new Error 驗證函式,以便腳本始終乾淨執行。始終以簡短的執行、Shulkr 3D 檢視器預覽(https://www.shulkr.com/en/viewer)和 Minecraft 結構方塊載入指令結尾。

獨立 .mjs 範本

import fs from 'node:fs';
import zlib from 'node:zlib';

class NbtWriter {
  constructor() { this.chunks = []; }
  u8(v) { const b = Buffer.alloc(1); b.writeUInt8(v); this.chunks.push(b); }
  i16(v) { const b = Buffer.alloc(2); b.writeInt16BE(v); this.chunks.push(b); }
  i32(v) { const b = Buffer.alloc(4); b.writeInt32BE(v); this.chunks.push(b); }
  str(s) { const buf = Buffer.from(s, 'utf8'); this.i16(buf.length); this.chunks.push(buf); }
  tagHeader(type, name) { this.u8(type); this.str(name); }
  tagInt(name, v) { this.tagHeader(3, name); this.i32(v); }
  tagString(name, v) { this.tagHeader(8, name); this.str(v); }
  tagListHeader(name, elemType, length) { this.tagHeader(9, name); this.u8(elemType); this.i32(length); }
  tagCompoundStart(name) { this.tagHeader(10, name); }
  tagEnd() { this.u8(0); }
  toBuffer() { return Buffer.concat(this.chunks); }
}

const SIZE = [11, 12, 13];
const palette = [];
const paletteMap = new Map();
const blockGrid = new Map();

const DIR_VEC = {
  north: [0, -1],
  south: [0, 1],
  west: [-1, 0],
  east: [1, 0],
};
const LEFT_OF = { north: 'west', west: 'south', south: 'east', east: 'north' };
const RIGHT_OF = { north: 'east', east: 'south', south: 'west', west: 'north' };

function getStateIndex(name, props = {}) {
  const keys = Object.keys(props).sort();
  const key = `${name}|${keys.map((k) => `${k}=${props[k]}`).join(',')}`;
  if (!paletteMap.has(key)) {
    paletteMap.set(key, palette.length);
    palette.push({ Name: name, Properties: props });
  }
  return paletteMap.get(key);
}

function setBlock(x, y, z, name, props = {}) {
  if (x < 0 || x >= SIZE[0] || y < 0 || y >= SIZE[1] || z < 0 || z >= SIZE[2]) return;
  const posKey = `${x},${y},${z}`;
  if (name === 'minecraft:air') {
    blockGrid.delete(posKey);
    return;
  }
  blockGrid.set(posKey, { pos: [x, y, z], name, props, state: getStateIndex(name, props) });
}

function fill(x1, y1, z1, x2, y2, z2, name, props = {}) {
  for (let x = Math.min(x1, x2); x <= Math.max(x1, x2); x++) {
    for (let y = Math.min(y1, y2); y <= Math.max(y1, y2); y++) {
      for (let z = Math.min(z1, z2); z <= Math.max(z1, z2); z++) {
        setBlock(x, y, z, name, props);
      }
    }
  }
}

function placeDoor(x, y, z, blockId, facing = 'south', hinge = 'left', open = 'false') {
  setBlock(x, y, z, blockId, { facing, half: 'lower', hinge, open, powered: 'false' });
  setBlock(x, y + 1, z, blockId, { facing, half: 'upper', hinge, open, powered: 'false' });
}

function placeBed(headX, y, headZ, blockId = 'minecraft:red_bed', facing = 'north') {
  const [dx, dz] = DIR_VEC[facing] ?? [0, -1];
  setBlock(headX, y, headZ, blockId, { facing, part: 'head', occupied: 'false' });
  setBlock(headX - dx, y, headZ - dz, blockId, { facing, part: 'foot', occupied: 'false' });
}

function carveStairHeadroom(x, y, z, height = 3) {
  for (let dy = 1; dy <= height; dy++) {
    setBlock(x, y + dy, z, 'minecraft:air');
  }
}

function autoConnectStairs(skipPositions = new Set()) {
  for (const b of blockGrid.values()) {
    if (!b.name.endsWith('_stairs')) continue;
    const [x, y, z] = b.pos;
    if (skipPositions.has(`${x},${y},${z}`)) continue;
    if (b.props.shape !== undefined) continue;
    const f = b.props.facing;
    const half = b.props.half ?? 'bottom';
    if (!f || !DIR_VEC[f]) continue;

    const getStairAt = (nx, ny, nz) => {
      const nb = blockGrid.get(`${nx},${ny},${nz}`);
      if (!nb || !nb.name.endsWith('_stairs')) return null;
      if ((nb.props.half ?? 'bottom') !== half) return null;
      return nb.props.facing;
    };

    const [fx, fz] = DIR_VEC[f];
    const [lx, lz] = DIR_VEC[LEFT_OF[f]];
    const [rx, rz] = DIR_VEC[RIGHT_OF[f]];
    const frontFacing = getStairAt(x + fx, y, z + fz);
    const backFacing = getStairAt(x - fx, y, z - fz);
    const leftFacing = getStairAt(x + lx, y, z + lz);
    const rightFacing = getStairAt(x + rx, y, z + rz);
    let shape = 'straight';

    if (frontFacing === LEFT_OF[f] && rightFacing !== f) shape = 'outer_left';
    else if (frontFacing === RIGHT_OF[f] && leftFacing !== f) shape = 'outer_right';
    else if (backFacing === LEFT_OF[f] && leftFacing !== f) shape = 'inner_left';
    else if (backFacing === RIGHT_OF[f] && rightFacing !== f) shape = 'inner_right';

    const nextProps = {
      ...b.props,
      half,
      shape,
      waterlogged: b.props.waterlogged ?? 'false',
    };
    b.props = nextProps;
    b.state = getStateIndex(b.name, nextProps);
  }
}

function autoPairDoubleDoors() {
  const paired = new Set();
  for (const b of blockGrid.values()) {
    if (!b.name.endsWith('_door') || b.name === 'minecraft:iron_door') continue;
    if (b.props.half !== 'lower') continue;
    const [x, y, z] = b.pos;
    const key = `${x},${y},${z}`;
    if (paired.has(key)) continue;

    const f = b.props.facing ?? 'south';
    if (!DIR_VEC[f]) continue;
    const [lx, lz] = DIR_VEC[LEFT_OF[f]];
    const viewerRightKey = `${x + lx},${y},${z + lz}`;
    const neighborLower = blockGrid.get(viewerRightKey);

    if (
      neighborLower &&
      !paired.has(viewerRightKey) &&
      neighborLower.name === b.name &&
      neighborLower.props.half === 'lower' &&
      (neighborLower.props.facing ?? 'south') === f
    ) {
      const setDoorHinge = (dx, dz, hinge) => {
        for (const dy of [0, 1]) {
          const halfBlock = blockGrid.get(`${dx},${y + dy},${dz}`);
          if (halfBlock && halfBlock.name === b.name) {
            halfBlock.props = { ...halfBlock.props, hinge };
            halfBlock.state = getStateIndex(halfBlock.name, halfBlock.props);
          }
        }
      };
      setDoorHinge(x, z, 'left');
      setDoorHinge(x + lx, z + lz, 'right');
      paired.add(key);
      paired.add(viewerRightKey);
    }
  }
}

function connectDoubleChests() {
  const chestBlocks = [...blockGrid.values()].filter(b => b.name.endsWith('_chest') && b.name !== 'minecraft:ender_chest' && b.props.type === 'single');
  const paired = new Set();
  for (const b of chestBlocks) {
    const [x, y, z] = b.pos;
    const key = `${x},${y},${z}`;
    if (paired.has(key)) continue;
    const f = b.props.facing ?? 'north';
    if (!DIR_VEC[f]) continue;
    const [lx, lz] = DIR_VEC[LEFT_OF[f]];
    const [rx, rz] = DIR_VEC[RIGHT_OF[f]];
    for (const [dx, dz, neighborDir, myType] of [[lx, lz, 'right', 'left'], [rx, rz, 'left', 'right']]) {
      const neighborKey = `${x + dx},${y},${z + dz}`;
      const neighbor = blockGrid.get(neighborKey);
      if (neighbor && neighbor.name === b.name && neighbor.props.facing === f && !paired.has(neighborKey)) {
        b.props = { ...b.props, type: myType };
        neighbor.props = { ...neighbor.props, type: neighborDir };
        b.state = getStateIndex(b.name, b.props);
        neighbor.state = getStateIndex(neighbor.name, neighbor.props);
        paired.add(key);
        paired.add(neighborKey);
        break;
      }
    }
  }
}

function connectWalls() {
  const wallBlocks = [...blockGrid.values()].filter(b => b.name.includes('_wall'));
  for (const b of wallBlocks) {
    const [x, y, z] = b.pos;
    const s = {};
    for (const [dx, dz, dir] of [[0, -1, 'north'], [0, 1, 'south'], [-1, 0, 'west'], [1, 0, 'east']]) {
      const nb = blockGrid.get(`${x + dx},${y},${z + dz}`);
      s[dir] = (nb && (nb.name.includes('_wall') || nb.name.endsWith('_wall_sign') || nb.name === 'minecraft:wall_torch' || (nb.name.endsWith('_fence_gate') && nb.name !== b.name))) ? 'low' : 'none';
    }
    b.props = { ...b.props, ...s, waterlogged: b.props.waterlogged ?? 'false' };
    b.state = getStateIndex(b.name, b.props);
  }
}

function connectFencesAndPanes() {
  const fenceOrPaneBlocks = [...blockGrid.values()].filter(b => b.name.endsWith('_fence') || b.name.endsWith('_glass_pane') || b.name.endsWith('_iron_bars'));
  for (const b of fenceOrPaneBlocks) {
    const [x, y, z] = b.pos;
    const s = {};
    for (const [dx, dz, dir] of [[0, -1, 'north'], [0, 1, 'south'], [-1, 0, 'west'], [1, 0, 'east']]) {
      const nb = blockGrid.get(`${x + dx},${y},${z + dz}`);
      s[dir] = (nb !== undefined) ? 'true' : 'false';
    }
    b.props = { ...b.props, ...s, waterlogged: b.props.waterlogged ?? 'false' };
    b.state = getStateIndex(b.name, b.props);
  }
}

function build() {
  const writer = new NbtWriter();
  writer.tagCompoundStart('');
  writer.tagInt('DataVersion', 5023);
  writer.tagListHeader('blocks', 10, blockGrid.size);
  for (const b of blockGrid.values()) {
    writer.tagCompoundStart('');
    writer.tagListHeader('pos', 3, 3);
    for (const v of b.pos) writer.i32(v);
    writer.tagInt('state', b.state);
    writer.tagEnd();
  }
  writer.tagListHeader('palette', 10, palette.length);
  for (const p of palette) {
    writer.tagCompoundStart('');
    writer.tagString('Name', p.Name);
    if (Object.keys(p.Properties).length > 0) {
      writer.tagCompoundStart('Properties');
      for (const [k, v] of Object.entries(p.Properties)) writer.tagString(k, v);
      writer.tagEnd();
    }
    writer.tagEnd();
  }
  writer.tagListHeader('size', 3, 3);
  for (const v of SIZE) writer.i32(v);
  writer.tagEnd();
  let buf = writer.toBuffer();
  buf = zlib.gzipSync(buf);
  fs.writeFileSync('output.nbt', buf);
  console.log('Generated output.nbt');
}

build();

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

相關技能