G2A Many GEOs
SHARE
TWEET

3d printer (unfinished)

kssr3951 Jan 31st, 2015 194 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- #深夜のComputerCrafting60分一本勝負
  2. -- お題: 「turtle.inspect()」または「turtle.getItemDetail()」を使ったプログラム
  3. -- 2015/01/31 23:15スタート by kssr3951
  4. -- 残業20分&リタイヤ
  5. -- ----------------------------------------
  6. -- utility
  7. -- ----------------------------------------
  8. local DEBUG_FILE_NAME = "scaanner_data.txt"
  9. local function fileReadAll(filePath)
  10.   local hFile = fs.open(filePath, "r")
  11.   local txt = hFile.readAll()
  12.   hFile.close()
  13.   return txt
  14. end
  15. local function debug(txt)
  16.   local hFile
  17.   if fs.exists("debug.txt") then
  18.     hFile = fs.open("debug.txt", "a");
  19.   else
  20.     hFile = fs.open("debug.txt", "w");
  21.   end
  22.   hFile.writeLine(txt);
  23.   hFile.close();
  24. end
  25. local function splitLine(data)
  26.   local lines = { }
  27.   local pos = 1
  28.   local tmp
  29.   while true do
  30.     local p1, p2 = string.find(data, "\n", pos, true)
  31.     if nil == p1 then
  32.       tmp = string.sub(data, pos)
  33.       tmp = string.gsub(tmp, "\n", "")
  34.       table.insert(lines, tmp)
  35.       break
  36.     else
  37.       tmp = string.sub(data, pos, p1)
  38.       tmp = string.gsub(tmp, "\n", "")
  39.       table.insert(lines, tmp)
  40.       pos = math.min(p1 + 1)
  41.     end
  42.   end
  43.   return lines
  44. end
  45. -- ----------------------------------------
  46. -- main
  47. -- ----------------------------------------
  48. print("3d print")
  49. --local args = { ... }
  50. local dataFilePath
  51. --if 1 == #args then
  52. --  dataFilePath = tonumber(args[1])
  53. --end
  54. dataFilePath = DEBUG_FILE_NAME
  55.  
  56. local right, forward, height
  57.  
  58. local lines = splitLine(fileReadAll(dataFilePath))
  59. local dataList = { }
  60. local pair = { }
  61. for i, v in ipairs(lines) do
  62.   print(i)
  63.   print(v)
  64.   if i == 1 then
  65.     right = tonumber(v)
  66.   elseif i == 2 then
  67.     forward = tonumber(v)
  68.   elseif i == 3 then
  69.     height = tonumber(v)
  70.   elseif i % 2 == 0 then
  71.     pair.blockName = v
  72.   else
  73.     pair.meta = v
  74.     table.insert(dataList, 1, pair)
  75.     pair = { }
  76.   end
  77. end
  78. print(string.format("right = %d, forward = %d, height = %d",
  79.   tostring(right), tostring(forward), tostring(height)))
  80.  
  81. for i, v in ipairs(dataList) do
  82.   debug(v.blockName)
  83.   debug("-----")
  84.   debug(v.meta)
  85.   debug("===============")
  86. end
  87.  
  88. turtle.forward()
  89. turtle.turnRight()
  90. for i = 1, right do
  91.   turtle.forward()
  92. end
  93. turtle.turnLeft()
  94. for j = 1, forward do
  95.   turtle.forward()
  96. end
  97. for h = 1, height do
  98.   for i = 1, right do
  99.     for j = 1, forward do
  100.  
  101. --[[
  102.  
  103. --
  104. if fs.exists(DEBUG_FILE_NAME) then
  105.   print(DEBUG_FILE_NAME .. " exists. continue? (y / n)")
  106.   local ch = read()
  107.   if "y" ~= ch then
  108.     print("3d scan canceled.")
  109.   end
  110.   fs.delete(DEBUG_FILE_NAME)
  111. end
  112.  
  113. for i = 1, height do
  114.   turtle.up()
  115. end
  116. turtle.forward()
  117. --
  118. debug(right)
  119. debug(forward)
  120. debug(height)
  121. --
  122. for h = 1, height do
  123.   for i = 1, right do
  124.     for j = 1, forward do
  125.       local rslt, scan = turtle.inspectDown()
  126.       if rslt then
  127.         debug(scan.name)
  128.         debug(scan.metadata)
  129.       else
  130.         debug("-")
  131.         debug("-")
  132.       end
  133.       turtle.digDown()
  134.       turtle.forward()
  135.     end
  136.     for j = 1, forward do
  137.       turtle.back()
  138.     end
  139.     if i < right then
  140.       turtle.turnRight()
  141.       turtle.forward()
  142.       turtle.turnLeft()
  143.     end
  144.   end
  145.   turtle.turnLeft()
  146.   for i = 1, right - 1 do
  147.     turtle.forward()
  148.   end
  149.   turtle.turnRight()
  150.   turtle.down()
  151. end
  152. print("3d scan completed.")
  153. --]]
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top