Creep4Play

ComputerCraft Mining Turtle - Stripmining

Jun 2nd, 2013
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.43 KB | None | 0 0
  1. print("STRIPMINE STARTEN")
  2. print("PN Creep4Play fuer mehr Info.")
  3. os.sleep(4)
  4. term.clear()
  5. term.setCursorPos(1,1)
  6.  
  7. function digU()
  8.   while turtle.detectUp() do  
  9.     turtle.digUp()
  10.   end
  11. end
  12.  
  13. function digF()
  14.   while turtle.detect() do
  15.     turtle.dig()
  16.   end
  17. end
  18.  
  19. function digD()
  20.   while turtle.detectDown() do
  21.     turtle.digDown()
  22.   end
  23. end
  24.  
  25. function goU(proof)
  26.   repeat
  27.     digU()
  28.     if proof then
  29.       if not proofFuel(false) then
  30.         return false
  31.       end
  32.     end
  33.   until turtle.up()
  34.   return true
  35. end
  36.  
  37. function goF(proof)
  38.   repeat
  39.     digF()
  40.     if proof then
  41.       if not proofFuel(false) then
  42.         return false
  43.       end
  44.     end
  45.   until turtle.forward()
  46.   return true
  47. end
  48.  
  49. function goD(proof)
  50.   repeat
  51.     digD()
  52.     if proof then
  53.       if not proofFuel(false) then
  54.         return false
  55.       end
  56.     end
  57.   until turtle.down()
  58.   return true
  59. end
  60.  
  61. function proofFuel(wait)
  62.   while turtle.getFuelLevel()<(mainGone+subGone+2) do
  63.     local broken=false
  64.     for i=16,1,-1 do
  65.       if turtle.getItemCount(i)>0 then
  66.         turtle.select(i)
  67.         if turtle.refuel(1) then
  68.           broken=true
  69.           break
  70.         end
  71.       end
  72.     end
  73.     if not broken then
  74.       if wait then
  75.         os.sleep(1)
  76.       else
  77.         return false      
  78.       end
  79.     end
  80.     turtle.select(1)
  81.   end
  82.   return true
  83. end
  84.  
  85. function goBack()
  86.   turtle.turnRight()
  87.   turtle.turnRight()
  88.   if inSub then
  89.     for i=1,subGone do
  90.       goF(false)
  91.     end
  92.     if (thisSub%2)==0 then
  93.       turtle.turnLeft()
  94.     else
  95.       turtle.turnRight()
  96.     end
  97.   end
  98.   for i=1,mainGone do
  99.     goF(false)
  100.   end
  101.   local fuel=false
  102.   for i=3,16 do
  103.     if turtle.getItemCount(i)>0 then
  104.       turtle.select(i)
  105.       if not turtle.refuel(0) then
  106.         turtle.drop()
  107.       elseif fuel then
  108.         turtle.drop()
  109.       else
  110.         fuel=true
  111.       end
  112.     end
  113.   end
  114.   turtle.select(1)
  115.   turtle.turnRight()
  116.   turtle.turnRight()
  117. end
  118.  
  119. function invFull()
  120.   for i=1,16 do
  121.     if turtle.getItemCount(i)==0 then
  122.       return false
  123.     end
  124.   end
  125.   return true
  126. end
  127.  
  128. function awaitFuel()
  129.   term.clear()
  130.   term.setCursorPos(1,1)
  131.   print("Stripmining:")
  132.   print("")
  133.   print("Add more fuel to continue.")
  134.   goBack()
  135.   proofFuel(true)
  136.   term.clear()
  137.   term.setCursorPos(1,1)
  138.   print("Stripmining:")
  139.   print("")
  140.   print("Put some cobblestones on slot 1.")
  141.   print("Put torches on slot 2.")
  142.   print("Put fuel on any slot.")
  143.   print("Number of strips: "..subNumber)
  144.   print("Length of strips: "..subLength)
  145. end
  146.  
  147. function place()
  148.   if not turtle.detectDown() then  
  149.     if turtle.getItemCount(1)>1 then
  150.       turtle.placeDown()
  151.       return
  152.     end
  153.     for i=3,16 do
  154.       if turtle.compareTo(i) then
  155.         turtle.select(i)
  156.         turtle.placeDown()
  157.         turtle.select(1)
  158.         break
  159.       end
  160.     end
  161.   end
  162. end
  163.  
  164. term.clear()
  165. term.setCursorPos(1,1)
  166. print("Stripmining:")
  167. print("")
  168. print("Put some cobblestones on slot 1.")
  169. print("Put torches on slot 2.")
  170. print("Put fuel on any slot.")
  171. print("Number of strips:")
  172. repeat
  173.   term.setCursorPos(19,6)
  174.   print("          ")
  175.   term.setCursorPos(19,6)
  176.   subNumber=tonumber(read())
  177. until subNumber>0
  178. term.setCursorPos(1,7)
  179. print("Length of strips:")
  180. repeat
  181.   term.setCursorPos(19,7)
  182.   print("          ")
  183.   term.setCursorPos(19,7)
  184.   subLength=tonumber(read())
  185. until subLength>0
  186. thisSub=0
  187. for i1=1,subNumber do
  188.   local broken=false
  189.   thisSub=thisSub+1
  190.   inSub=false
  191.   subGone=0
  192.   repeat
  193.     broken=false
  194.     mainGone=0
  195.     for i2=1,(thisSub+(thisSub%2))*2 do
  196.       if not goF(true) then
  197.         awaitFuel()
  198.         broken=true
  199.         break
  200.       end
  201.       mainGone=mainGone+1
  202.       place()
  203.       if (thisSub%2)==1 then
  204.         if i2>(thisSub-1)*2 then
  205.           digU()
  206.         end
  207.       else
  208.         if i2==(thisSub-1)*2 then
  209.           turtle.select(2)
  210.           turtle.placeUp()
  211.           turtle.select(1)
  212.         end
  213.       end
  214.     end
  215.   until not broken
  216.   if (thisSub%2)==0 then
  217.     turtle.turnRight()
  218.   else
  219.     turtle.turnLeft()
  220.   end
  221.   inSub=true
  222.   for iS=1,subLength do
  223.     if not goF(true) then
  224.       awaitFuel()
  225.       broken=true
  226.       break
  227.     end
  228.     subGone=subGone+1
  229.     place()
  230.     digU()
  231.     if invFull() then
  232.       break  
  233.     end
  234.   end
  235.   if not broken then
  236.     goBack()
  237.   end
  238. end
  239. term.clear()
  240. term.setCursorPos(1,1)
  241. print("STRIPMINE FERTIG")
  242. print("PN Creep4Play fuer mehr Info.")
Advertisement
Add Comment
Please, Sign In to add comment