Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ##################################
- -- yuka (build frame and floor)
- -- API install and load API
- local api_name = "h2turtle"
- if fs.exists(api_name) then
- print("Found API: "..api_name)
- else
- print("Download API: "..api_name)
- assert(shell.run("pastebin","get","NCKmS1qx",api_name), "Failed!: download API")
- end
- os.loadAPI(api_name)
- -- ##################################
- -- 使い方(奥行き3、幅4の床を作る)
- -- > yuka 3 4
- -- 枠として使うブロック名を聞いてくるので入力
- -- 枠の中として使うブロック名を聞いてくるので入力
- -- 必要なアイテム数を渡すと、プログラム開始
- -- 枠作成→中を埋めるという順番で床を作成する
- -- FFFF
- -- FBBF
- -- FFFF
- -- T
- -- F:枠として使うブロック、B:枠の中のブロック、T:タートル
- -- ##################################
- -- Config
- -- 床の奥行き、幅。デフォルト値
- local depth = 4
- local width = 4
- -- 床作成に使うブロック名
- -- {アイテム名, ダメージ値}
- -- アイテム名は部分一致、ダメージ値は省略可能
- local frame_name = {"stonebrick", 0}
- local floor_name = {"cobblestone", 0}
- -- ##################################
- -- functions
- function buildFrameOneLine(length)
- for i=1,length do
- if h2turtle.isDownBlock(frame_name) then
- -- do nothing
- else
- turtle.digDown()
- h2turtle.placeDownItem(unpack(frame_name))
- end
- if i ~= length then turtle.forward() end
- end
- end
- function buildFrame()
- turtle.forward()
- for i=1,2 do
- buildFrameOneLine(depth)
- turtle.turnRight()
- buildFrameOneLine(width)
- turtle.turnRight()
- end
- end
- function buildFloor()
- while true do
- while not turtle.detectDown() do
- turtle.digDown()
- h2turtle.placeDownItem(unpack(floor_name))
- turtle.forward()
- end
- turtle.back()
- turtle.turnRight()
- turtle.forward()
- if turtle.detectDown() then break end
- end
- end
- -- ##################################
- -- main
- -- 床のサイズを確認
- local args = {...}
- depth = args[1] and tonumber(args[1]) or depth
- width = args[2] and tonumber(args[2]) or width
- print()
- local depth = tonumber(h2turtle.promptValue("depth?", depth))
- local width = tonumber(h2turtle.promptValue("width?", width))
- print()
- print(string.format("depth: %d, width: %d", depth, width))
- print()
- -- 床の材料を確認
- local _frame_n = h2turtle.promptValue("frame block name?", frame_name[1])
- local _frame_d = h2turtle.promptValue("frame block damage?", frame_name[2])
- frame_name = {_frame_n, tonumber(_frame_d)}
- local _floor_n = h2turtle.promptValue("floor block name?", floor_name[1])
- local _floor_d = h2turtle.promptValue("floor block damage?", floor_name[2])
- floor_name = {_floor_n, tonumber(_floor_d)}
- -- ここまでに入力された値を確認表示
- print()
- print("Build frame and floor:")
- print(string.format(" depth: %d, width: %d", depth, width))
- print(string.format(" frame block: %s (%d)", frame_name[1], frame_name[2]))
- print(string.format(" floor block: %s (%d)", floor_name[1], floor_name[2]))
- print()
- -- 必要アイテム数を確保
- print("Please give me items.")
- local required_frame_qty = (depth+width)*2
- h2turtle.waitForEnoughItems(required_frame_qty, unpack(frame_name))
- local required_floor_qty = (depth-2)*(width-2)
- h2turtle.waitForEnoughItems(required_floor_qty, unpack(floor_name))
- -- スタートしてよいか最終確認
- print()
- assert(h2turtle.promptYN(),"terminated!")
- -- build frame
- print()
- print("Build frame and floor: frame..")
- buildFrame()
- -- 中心の床部分を埋めるために、最初の位置に移動
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- -- build floor
- print()
- print("Build frame and floor: floor..")
- buildFloor()
- print("Build frame and floor: finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement