Creep4Play

ComputerCraft Mining Turtle - Stripmining mit Erzabbau

May 28th, 2013
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.20 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 doubleTest()
  86.   turtle.turnLeft()
  87.   for i=minTest,maxTest do
  88.     turtle.select(i)
  89.     testD()
  90.     testF()
  91.   end    
  92.   if not goU(true) then
  93.     turtle.turnRight()
  94.     turtle.turnRight()
  95.     return
  96.   end
  97.   subGone=subGone+1
  98.   for i=minTest,maxTest do
  99.     turtle.select(i)
  100.     testF()
  101.     testU()
  102.   end
  103.   turtle.turnRight()
  104.   for i=minTest,maxTest do
  105.     turtle.select(i)
  106.     testF()
  107.   end
  108.   turtle.turnRight()
  109.   for i=minTest,maxTest do
  110.     turtle.select(i)
  111.     testF()
  112.   end
  113.   goD(false)
  114.   subGone=subGone-1
  115.   for i=minTest,maxTest do
  116.     turtle.select(i)
  117.     testF()
  118.   end
  119.   turtle.select(1)
  120. end
  121.  
  122. function test()
  123.   for i=minTest,maxTest do
  124.     turtle.select(i)
  125.     testU()
  126.     testF()
  127.   end
  128.   for i1=1,2 do
  129.     turtle.turnLeft()
  130.     for i=minTest,maxTest do
  131.       turtle.select(i)
  132.       testF()
  133.     end
  134.   end
  135.   turtle.turnLeft()
  136.   for i=minTest,maxTest do
  137.     turtle.select(i)
  138.     testF()
  139.     testD()
  140.   end
  141.   turtle.select(1)
  142. end
  143.  
  144. function testU()
  145.   if turtle.compareUp() then
  146.     if not goU(true) then
  147.       return
  148.     end
  149.     subGone=subGone+1
  150.     test()
  151.     turtle.turnLeft()
  152.     goD(false)
  153.     subGone=subGone-1
  154.   end
  155. end
  156.  
  157. function testF()
  158.   if turtle.compare() then
  159.     if not goF(true) then
  160.       return
  161.     end
  162.     subGone=subGone+1
  163.     test()
  164.     turtle.turnRight()
  165.     goF(false)
  166.     subGone=subGone-1
  167.     turtle.turnRight()
  168.     turtle.turnRight()
  169.   end
  170. end
  171.  
  172. function testD()
  173.   if turtle.compareDown() then
  174.     if not goD(true) then
  175.       return
  176.     end
  177.     subGone=subGone+1
  178.     test()
  179.     turtle.turnLeft()
  180.     goU(false)
  181.     subGone=subGone-1
  182.   end
  183. end
  184.  
  185. function goBack()
  186.   turtle.turnRight()
  187.   turtle.turnRight()
  188.   if inSub then
  189.     for i=1,subGone do
  190.       goF(false)
  191.     end
  192.     if (thisSub%2)==0 then
  193.       turtle.turnLeft()
  194.     else
  195.       turtle.turnRight()
  196.     end
  197.   end
  198.   for i=1,mainGone do
  199.     goF(false)
  200.   end
  201.   local fuel=false
  202.   for i=3,16 do
  203.     if turtle.getItemCount(i)>0 then
  204.       turtle.select(i)
  205.       if not turtle.refuel(0) then
  206.         if i<minTest then
  207.           turtle.drop()
  208.         elseif i>maxTest then
  209.           turtle.drop()
  210.         end
  211.       elseif fuel then
  212.         if i<minTest then
  213.           turtle.drop()
  214.         elseif i>maxTest then
  215.           turtle.drop()
  216.         end
  217.       else
  218.         fuel=true
  219.       end
  220.     end
  221.   end
  222.   turtle.select(1)
  223.   turtle.turnRight()
  224.   turtle.turnRight()
  225. end
  226.  
  227. function invFull()
  228.   for i=1,16 do
  229.     if turtle.getItemCount(i)==0 then
  230.       return false
  231.     end
  232.   end
  233.   return true
  234. end
  235.  
  236. function awaitFuel()
  237.   term.clear()
  238.   term.setCursorPos(1,1)
  239.   print("Stripmining:")
  240.   print("")
  241.   print("Add more fuel to continue.")
  242.   goBack()
  243.   proofFuel(true)
  244.   term.clear()
  245.   term.setCursorPos(1,1)
  246.   print("Stripmining:")
  247.   print("")
  248.   print("Put some cobblestones on slot 1.")
  249.   print("Put torches on slot 2.")
  250.   print("Put fuel on any slot.")
  251.   print("Number of strips: "..subNumber)
  252.   print("Length of strips: "..subLength)
  253.   print("Materials to dig on slot "..minTest.." to "..maxTest)
  254. end
  255.  
  256. function place()
  257.   if not turtle.detectDown() then  
  258.     if turtle.getItemCount(1)>1 then
  259.       turtle.placeDown()
  260.       return
  261.     end
  262.     for i=3,16 do
  263.       if i<minTest then
  264.         if turtle.compareTo(i) then
  265.           turtle.select(i)
  266.           turtle.placeDown()
  267.           turtle.select(1)
  268.           return
  269.         end  
  270.       elseif i>maxTest then
  271.         if turtle.compareTo(i) then
  272.           turtle.select(i)
  273.           turtle.placeDown()
  274.           turtle.select(1)
  275.           return
  276.         end
  277.       end
  278.     end
  279.   end
  280. end
  281.  
  282. term.clear()
  283. term.setCursorPos(1,1)
  284. print("Stripmining:")
  285. print("")
  286. print("Put some cobblestones on slot 1.")
  287. print("Put torches on slot 2.")
  288. print("Put fuel on any slot.")
  289. print("Number of strips:")
  290. repeat
  291.   term.setCursorPos(19,6)
  292.   print("          ")
  293.   term.setCursorPos(19,6)
  294.   subNumber=tonumber(read())
  295. until subNumber>0
  296. term.setCursorPos(1,7)
  297. print("Length of strips:")
  298. repeat
  299.   term.setCursorPos(19,7)
  300.   print("          ")
  301.   term.setCursorPos(19,7)
  302.   subLength=tonumber(read())
  303. until subLength>0
  304. term.setCursorPos(1,8)
  305. print("Materials to dig on slot:")
  306. repeat
  307.   term.setCursorPos(27,8)
  308.   print("          ")
  309.   term.setCursorPos(27,8)
  310.   minTest=tonumber(read())
  311.   local isok=false
  312.   if minTest>2 then
  313.     if minTest<17 then
  314.       isok=true
  315.     end
  316.   end
  317. until isok
  318. term.setCursorPos(25,8)
  319. print(" "..minTest.." to:")
  320. repeat
  321.   term.setCursorPos(33,8)
  322.   print("          ")
  323.   term.setCursorPos(33,8)
  324.   maxTest=tonumber(read())
  325.   local isok=false
  326.   if maxTest>=minTest then
  327.     if maxTest<17 then
  328.       isok=true
  329.     end
  330.   end
  331. until isok
  332. term.setCursorPos(26,8)
  333. print(minTest.." to "..maxTest.."  ")
  334. thisSub=0
  335. for i1=1,subNumber do
  336.   local broken=false
  337.   thisSub=thisSub+1
  338.   inSub=false
  339.   subGone=0
  340.   repeat
  341.     broken=false
  342.     mainGone=0
  343.     for i2=1,(thisSub+(thisSub%2))*2 do
  344.       if not goF(true) then
  345.         awaitFuel()
  346.         broken=true
  347.         break
  348.       end
  349.       mainGone=mainGone+1
  350.       place()
  351.       if i2>(thisSub-(thisSub%2))*2 then
  352.         doubleTest()
  353.         turtle.turnLeft()
  354.       elseif (thisSub%2)==0 then
  355.     if i2==(thisSub-1)*2 then
  356.           turtle.select(2)
  357.           turtle.placeUp()
  358.           turtle.select(1)
  359.         end
  360.       end
  361.     end
  362.   until not broken
  363.   if (thisSub%2)==0 then
  364.     turtle.turnRight()
  365.   else
  366.     turtle.turnLeft()
  367.   end
  368.   inSub=true
  369.   for iS=1,subLength do
  370.     if not goF(true) then
  371.       awaitFuel()
  372.       broken=true
  373.       break
  374.     end
  375.     subGone=subGone+1
  376.     place()
  377.     doubleTest()
  378.     turtle.turnLeft()
  379.     if invFull() then
  380.       break  
  381.     end
  382.   end
  383.   if not broken then
  384.     goBack()
  385.   end
  386. end
  387. term.clear()
  388. term.setCursorPos(1,1)
  389. print("STRIPMINE FERTIG")
  390. print("PN Creep4Play fuer mehr Info.")
Advertisement
Add Comment
Please, Sign In to add comment