Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #深夜のComputerCrafting60分一本勝負
- -- お題: 「turtle.inspect()」または「turtle.getItemDetail()」を使ったプログラム
- -- 2015/01/31 23:15スタート by kssr3951
- -- 残業20分&リタイヤ
- -- ----------------------------------------
- -- utility
- -- ----------------------------------------
- local DEBUG_FILE_NAME = "scaanner_data.txt"
- local function fileReadAll(filePath)
- local hFile = fs.open(filePath, "r")
- local txt = hFile.readAll()
- hFile.close()
- return txt
- end
- local function debug(txt)
- local hFile
- if fs.exists("debug.txt") then
- hFile = fs.open("debug.txt", "a");
- else
- hFile = fs.open("debug.txt", "w");
- end
- hFile.writeLine(txt);
- hFile.close();
- end
- local function splitLine(data)
- local lines = { }
- local pos = 1
- local tmp
- while true do
- local p1, p2 = string.find(data, "\n", pos, true)
- if nil == p1 then
- tmp = string.sub(data, pos)
- tmp = string.gsub(tmp, "\n", "")
- table.insert(lines, tmp)
- break
- else
- tmp = string.sub(data, pos, p1)
- tmp = string.gsub(tmp, "\n", "")
- table.insert(lines, tmp)
- pos = math.min(p1 + 1)
- end
- end
- return lines
- end
- -- ----------------------------------------
- -- main
- -- ----------------------------------------
- print("3d print")
- --local args = { ... }
- local dataFilePath
- --if 1 == #args then
- -- dataFilePath = tonumber(args[1])
- --end
- dataFilePath = DEBUG_FILE_NAME
- local right, forward, height
- local lines = splitLine(fileReadAll(dataFilePath))
- local dataList = { }
- local pair = { }
- for i, v in ipairs(lines) do
- print(i)
- print(v)
- if i == 1 then
- right = tonumber(v)
- elseif i == 2 then
- forward = tonumber(v)
- elseif i == 3 then
- height = tonumber(v)
- elseif i % 2 == 0 then
- pair.blockName = v
- else
- pair.meta = v
- table.insert(dataList, 1, pair)
- pair = { }
- end
- end
- print(string.format("right = %d, forward = %d, height = %d",
- tostring(right), tostring(forward), tostring(height)))
- for i, v in ipairs(dataList) do
- debug(v.blockName)
- debug("-----")
- debug(v.meta)
- debug("===============")
- end
- turtle.forward()
- turtle.turnRight()
- for i = 1, right do
- turtle.forward()
- end
- turtle.turnLeft()
- for j = 1, forward do
- turtle.forward()
- end
- for h = 1, height do
- for i = 1, right do
- for j = 1, forward do
- --[[
- --
- if fs.exists(DEBUG_FILE_NAME) then
- print(DEBUG_FILE_NAME .. " exists. continue? (y / n)")
- local ch = read()
- if "y" ~= ch then
- print("3d scan canceled.")
- end
- fs.delete(DEBUG_FILE_NAME)
- end
- for i = 1, height do
- turtle.up()
- end
- turtle.forward()
- --
- debug(right)
- debug(forward)
- debug(height)
- --
- for h = 1, height do
- for i = 1, right do
- for j = 1, forward do
- local rslt, scan = turtle.inspectDown()
- if rslt then
- debug(scan.name)
- debug(scan.metadata)
- else
- debug("-")
- debug("-")
- end
- turtle.digDown()
- turtle.forward()
- end
- for j = 1, forward do
- turtle.back()
- end
- if i < right then
- turtle.turnRight()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- turtle.turnLeft()
- for i = 1, right - 1 do
- turtle.forward()
- end
- turtle.turnRight()
- turtle.down()
- end
- print("3d scan completed.")
- --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement