Creep4Play

ComputerCraft Mining Turtle - Wall/Bottom

May 27th, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | None | 0 0
  1. function digU()
  2.   while turtle.detectUp() do
  3.     turtle.digUp()
  4.   end
  5. end
  6.  
  7. function digF()
  8.   while turtle.detect() do
  9.     turtle.dig()
  10.   end
  11. end
  12.  
  13. function digD()
  14.   while turtle.detectDown() do
  15.     turtle.digDown()
  16.   end
  17. end
  18.  
  19. function goU()
  20.   repeat
  21.     digU()
  22.     proofFuel()
  23.   until turtle.up()
  24. end
  25.  
  26. function goF()
  27.   repeat
  28.     digF()
  29.     proofFuel()
  30.   until turtle.forward()
  31. end
  32.  
  33. function goD()
  34.   repeat
  35.     digD()
  36.     proofFuel()
  37.   until turtle.down()
  38. end
  39.  
  40. function status()
  41.   term.clear()
  42.   term.setCursorPos(1,1)
  43.   print("Build wall:")
  44.   print("")
  45.   if wall then
  46.     print("H:"..other.." L:"..length)
  47.   else
  48.     print("W:"..other.." L:"..length)
  49.   end
  50.   print("")
  51.   print(set.."/"..blocks.." set, "..(blocks-set).." left.")
  52. end
  53.  
  54. function proofFuel()
  55.   if turtle.getFuelLevel()==0 then
  56.     turtle.select(16)
  57.     while turtle.refuel(1)==false do
  58.       term.clear()
  59.       term.setCursorPos(1,1)
  60.       print("Build wall:")
  61.       print("")
  62.       print("Put coal on slot 16.")
  63.       os.sleep(4)
  64.       turtle.select(16)
  65.     end
  66.     turtle.select(1)
  67.   end
  68. end
  69.  
  70. function place()
  71.   local showFillMsg=true
  72.   while true do
  73.     digF()
  74.     if turtle.getItemCount(1)>1 then
  75.       if turtle.place() then
  76.         return
  77.       end
  78.     else
  79.       for i=2,15 do
  80.         if turtle.compareTo(i) then
  81.           turtle.select(i)
  82.           if turtle.place() then
  83.             turtle.select(1)
  84.             return
  85.           end
  86.           break
  87.         end
  88.       end
  89.     end
  90.     if showFillMsg then
  91.       term.clear()
  92.       term.setCursorPos(1,1)
  93.       print("Build wall:")
  94.       print("")
  95.       print("Put building blocks on slot 1.")
  96.       print("Fill turtle with more of them.")
  97.       showFillMsg=false
  98.     end
  99.     os.sleep(4)
  100.   end
  101. end
  102.  
  103. turtle.select(1)
  104. term.clear()
  105. term.setCursorPos(1,1)
  106. print("Build wall:")
  107. print("")
  108. print("Put building blocks on slot 1")
  109. print("Fill turtle with more of them.")
  110. print("Put coal on slot 16.")
  111. print("Wall/Bottom (w/b):")
  112. term.setCursorPos(20,6)
  113. if read()=="w" then
  114.   term.setCursorPos(20,6)
  115.   print("Wall")
  116.   wall=true
  117. else
  118.   term.setCursorPos(20,6)
  119.   print("Bottom")
  120.   wall=false
  121. end
  122. term.setCursorPos(1,7)
  123. if wall then
  124.   print("Height:")
  125.   repeat
  126.     term.setCursorPos(9,7)
  127.     print("          ")
  128.     term.setCursorPos(9,7)
  129.     other=tonumber(read())
  130.   until other>0
  131. else
  132.   print("Width:")
  133.   repeat
  134.     term.setCursorPos(8,7)
  135.     print("          ")
  136.     term.setCursorPos(8,7)
  137.     other=tonumber(read())
  138.   until other>0
  139. end
  140. term.setCursorPos(1,8)
  141. print("Length:")
  142. repeat
  143.   term.setCursorPos(9,8)
  144.   print("          ")
  145.   term.setCursorPos(9,8)
  146.   length=tonumber(read())
  147. until length>0
  148. blocks=length*other
  149. set=0
  150. pos=0
  151. for i=2,length do
  152.   goF()
  153. end
  154. for iL=1,length do
  155.   place()
  156.   set=set+1
  157.   status()
  158.   for iO=2,other do
  159.     if wall then
  160.       if pos==0 then
  161.         goU()
  162.       else
  163.         goD()
  164.       end
  165.     else
  166.       if pos==0 then
  167.         turtle.turnRight()
  168.         goF()
  169.         turtle.turnLeft()
  170.       else
  171.         turtle.turnLeft()
  172.         goF()
  173.         turtle.turnRight()
  174.       end
  175.     end
  176.     place()
  177.     set=set+1
  178.     status()
  179.   end
  180.   if iL~=length then
  181.     turtle.turnLeft()
  182.     turtle.turnLeft()
  183.     goF()
  184.     turtle.turnLeft()
  185.     turtle.turnLeft()
  186.   end
  187.   pos=(pos*-1)+1
  188. end
  189. if other>1 then
  190.   if pos==1 then
  191.     if wall then
  192.       for i=2,other do
  193.         goD()
  194.       end
  195.     else
  196.       turtle.turnLeft()
  197.       for i=2,other  do
  198.         goF()
  199.       end
  200.       turtle.turnRight()
  201.     end
  202.   end
  203. end
Advertisement
Add Comment
Please, Sign In to add comment