player.onChat("maze2", function (n) {
// 尺寸調整
if (n < 9) n = 9
if (n % 2 == 0) n += 1
const WALL = STONE
const PATH = AIR
let base = positions.add(player.position(), positions.create(0, -1, 5))
// 全牆
for (let x = 0; x < n; x++) {
for (let z = 0; z < n; z++) {
blocks.place(WALL, positions.add(base, positions.create(x, 0, z)))
}
}
// 節點(奇數格)挖空
for (let x = 1; x < n; x += 2) {
for (let z = 1; z < n; z += 2) {
blocks.place(PATH, positions.add(base, positions.create(x, 0, z)))
}
}
// Sidewinder:從南到北(z=3 開始),逐列處理
for (let z = 1; z < n; z += 2) {
let run: number[] = []
for (let x = 1; x < n; x += 2) {
run.push(x)
let atEastEdge = (x + 2 >= n)
let atNorthEdge = (z - 2 < 0)
// 是否結束這一段 run
let shouldCloseOut = atEastEdge || (!atNorthEdge && Math.randomRange(0, 2) == 0)
if (shouldCloseOut) {
// 從 run 中隨機挑一個格子,往北開通
if (!atNorthEdge) {
let carveX = run[Math.randomRange(0, run.length - 1)]
blocks.place(PATH, positions.add(base, positions.create(carveX, 0, z - 1)))
}
run = [] // 清空 run
} else {
// 向東開通
blocks.place(PATH, positions.add(base, positions.create(x + 1, 0, z)))
}
}
}
// 入口與出口
blocks.place(PATH, positions.add(base, positions.create(1, 0, 0))) // 入口
blocks.place(PATH, positions.add(base, positions.create(n - 2, 0, n - 1))) // 出口
})
#變身成其他實體
/give @s command_block
/execute as @p at @s run tp @e[name=mob] ^^^-0.1 facing @p (放重複指令方塊)
/effect @p invisibility 1 1 true (放連鎖指令方塊)
/gamerule commandblockoutput false
/summon warden ~ ~ ~ a mob
/kill @[name=mob]
#跟著地上的箭頭走
/give @s command_block
#箭頭朝東邊(重複指令方塊)
/execute as @e at @s if block ~ ~-1 ~ magenta_glazed_terracotta 4 run tp @s ~1 ~ ~
#箭頭朝西邊(重複指令方塊)
/execute as @e at @s if block ~ ~-1 ~ magenta_glazed_terracotta 5 run tp @s ~-1 ~ ~
#箭頭朝南邊(重複指令方塊)
/execute as @e at @s if block ~ ~-1 ~ magenta_glazed_terracotta 2 run tp @s ~ ~ ~1
#箭頭朝北邊(重複指令方塊)
/execute as @e at @s if block ~ ~-1 ~ magenta_glazed_terracotta 3 run tp @s ~ ~ ~-1
#關閉傳送後通知
/gamerule sendcommandfeedback false
#關閉指令方塊運行通知
/gamerule commandblockoutput false
學習資源(請注意軟體版本)
模組的家