Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.12 KB | None | 0 0
  1. donedistance = 0
  2. leftdistance = 0
  3. totaldistance = 0
  4. doneblocks = 0
  5. leftblocks = 0
  6. totalblocks = 0
  7. torchblocks = 0
  8. status = false
  9. height = 0
  10. width = 0
  11.  
  12. function input()
  13.     term.clear()
  14.     term.setTextColor(colors.blue)
  15.     term.setCursorPos(1, 1)
  16.     term.write("Input tunnel width: ")
  17.     temp = read()
  18.     if tonumber(temp) == nil then
  19.         input()
  20.     else
  21.         width = tonumber(temp)
  22.         term.clear()
  23.         term.setTextColor(colors.blue)
  24.         term.setCursorPos(1, 1)
  25.         term.write("Input tunnel height: ")
  26.         temp = read()
  27.         if tonumber(temp) == nil then
  28.             input()
  29.         else
  30.             height = tonumber(temp)
  31.             term.clear()
  32.             term.setTextColor(colors.blue)
  33.             term.setCursorPos(1, 1)
  34.             term.write("Input tunnel distance: ")
  35.             temp = read()
  36.             if tonumber(temp) == nil then
  37.                 input()
  38.             else
  39.                 totaldistance = tonumber(temp)
  40.                 totalblocks = height * width * totaldistance
  41.                 tunnel()
  42.             end
  43.         end
  44.     end
  45. end
  46.  
  47. function update()
  48.     term.clear()
  49.     term.setTextColor(colors.red)
  50.     term.setCursorPos(1, 1)
  51.     term.write("Total distance      : " .. totaldistance)
  52.     term.setCursorPos(1, 2)
  53.     term.write("Distance done       : " .. donedistance)
  54.     term.setCursorPos(1, 3)
  55.     term.write("Distance left       : " .. leftdistance)
  56.     term.setCursorPos(1, 4)
  57.     term.write("Total blocks        : " .. totalblocks)
  58.     term.setCursorPos(1, 5)
  59.     term.write("Blocks done         : " .. doneblocks)
  60.     term.setCursorPos(1, 6)
  61.     term.write("Blocks left         : " .. leftblocks)
  62.     term.setCursorPos(1, 7)
  63.     term.write("Next torch          : " .. (12 - torchblocks))
  64.     term.setCursorPos(1, 8)
  65.     if status == true then
  66.         term.setTextColor(colours.green)
  67.         term.write("Status              : Finished")
  68.     else
  69.         term.setTextColor(colours.red)
  70.         term.write("Status              : Unfinished")
  71.     end
  72. end
  73.  
  74. function drop()
  75.     right(2)
  76.     for i = 1, donedistance do
  77.         turtle.forward()
  78.     end
  79.     for i = 2, 15 do
  80.         turtle.select(i)
  81.         turtle.drop()
  82.     end
  83.     if status == false then
  84.         right(2)
  85.         for i = 1, donedistance do
  86.             turtle.forward()
  87.         end
  88.     end
  89. end
  90.  
  91. function move(direction)
  92.     if direction == "for" then
  93.         repeat
  94.             turtle.dig()
  95.             sleep(0.2)
  96.         until turtle.forward() == true
  97.         doneblocks = doneblocks + 1
  98.         leftblocks = totalblocks - doneblocks
  99.         update()
  100.     elseif direction == "up" then
  101.         repeat
  102.             turtle.digUp()
  103.             sleep(0.2)
  104.         until turtle.up() == true
  105.         doneblocks = doneblocks + 1
  106.         leftblocks = totalblocks - doneblocks
  107.         update()
  108.     elseif direction == "dow" then
  109.         repeat
  110.             turtle.digDown()
  111.             sleep(0.2)
  112.         until turtle.down() == true
  113.         doneblocks = doneblocks + 1
  114.         leftblocks = totalblocks - doneblocks
  115.         update()
  116.     end
  117. end
  118.  
  119. function left(amount)
  120.     for i = 1, amount do
  121.         turtle.turnLeft()
  122.     end
  123. end
  124.  
  125. function right(amount)
  126.     for i = 1, amount do
  127.         turtle.turnRight()
  128.     end
  129. end
  130.  
  131. function strip(width, height)
  132.     halfwidth = math.floor(width / 2)
  133.     move("for")
  134.     for i = 1, height do
  135.         left(1)
  136.         for ii = 1, halfwidth do
  137.             move("for")
  138.             if i == 1 then
  139.                 turtle.select(1)
  140.                 turtle.placeDown()
  141.             elseif i == height then
  142.                 turtle.select(1)
  143.                 turtle.placeUp()
  144.             end
  145.         end
  146.         turtle.select(1)
  147.         turtle.place()
  148.         turtle.back()
  149.         if i == 1 then
  150.             if torchblocks == 12 then
  151.                 turtle.select(16)
  152.                 turtle.place()
  153.                 turtle.select(1)
  154.                 torchblocks = 0
  155.             end
  156.         end
  157.         right(2)
  158.         for ii = 1, (halfwidth - 1) do
  159.             turtle.forward()
  160.         end
  161.         for ii = 1, halfwidth do
  162.             move("for")
  163.             if i == 1 then
  164.                 turtle.select(1)
  165.                 turtle.placeDown()
  166.             elseif i == height then
  167.                 turtle.select(1)
  168.                 turtle.placeUp()
  169.             end
  170.         end
  171.         turtle.select(1)
  172.         turtle.place()
  173.         turtle.back()
  174.         if i == 1 then
  175.             if torchblocks == 12 then
  176.                 turtle.select(16)
  177.                 turtle.place()
  178.                 turtle.select(1)
  179.                 torchblocks = 0
  180.             end
  181.         end
  182.         left(2)
  183.         for ii = 1, (halfwidth - 1) do
  184.             turtle.forward()
  185.         end
  186.         right(1)
  187.         move("up")
  188.     end
  189.     for i = 1, (height - 1) do
  190.         turtle.down()
  191.     end
  192.     if turtle.getItemCount(15) > 0 then
  193.         drop()
  194.     end
  195. end
  196.  
  197. function tunnel()
  198.     for i = 1, totaldistance do
  199.         strip(width, height)
  200.         donedistance = donedistance + 1
  201.         leftdistance = totaldistance + donedistance
  202.         torchblocks = torchblocks + 1
  203.         update()
  204.     end
  205.     status = true
  206.     update()
  207. end
  208.  
  209. input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement