Advertisement
Guest User

Mining-turtle (Stripmining) V.1.7 Final (XenoEdit3)

a guest
Aug 1st, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     --This code is developed by me (onix331) and modified by Xenomurks and is availiable under the GNU General Public License (Version 3)
  2.     --See http://opensource.org/licenses/GPL-3.0
  3.     --Have fun
  4.      
  5.     shaftcount = 0--Used later in the program, usually not necessary do modify it
  6.     space = 15--Defines the space of the turtle
  7.     ver = 1.7--For updates
  8.     chest = 0--If the turtle has stopped at a chest
  9.     stop = 0--If the turtle has stopped at a chest
  10.     torch = n
  11.    
  12.      
  13.     function returnmining()--Beta-feature
  14.         stop = 1
  15.         chest = 0
  16.         if direction=="r" then
  17.             turnaround()
  18.             for i = 1, shaftcount do
  19.                 turtle.forward()
  20.                 turtle.forward()
  21.                 turtle.forward()
  22.             end
  23.             turtle.turnRight()
  24.             for i = 1, count do
  25.                 move()
  26.                 turnaround()
  27.                 move()
  28.                 move()
  29.                 turnaround()
  30.                 move()
  31.                 nextshaft()
  32.                 shaftcount = shaftcount + 1
  33.                 count = count - 1
  34.                 checkspace()               
  35.             end
  36.         end
  37.     end
  38.    
  39.    
  40.    
  41.     function checkl() --To check if length is valid (>0, not a String), also transforms the string into a number
  42.         length = tonumber(length)
  43.         if length==nil then
  44.             print ("Invalid number!")
  45.             length = read()
  46.             checkl()
  47.         elseif length <= 0 then
  48.             print ("Invalid number!")
  49.             length = read()
  50.             checkl()
  51.         end
  52.     end
  53.      
  54.     function checka()--To check if count is valid (>0, not a String), also transforms the string into a number
  55.         count = tonumber(count)
  56.         if count==nil then
  57.             print ("Invalid number!")
  58.             count = read()
  59.             checka()
  60.         elseif count <= 0 then
  61.             print ("Invalid number!")
  62.             count = read()
  63.             checka()
  64.         end
  65.     end
  66.      
  67.     function checkr()--To check if direction is valid ((r) or (l))
  68.         if direction=="r" then
  69.             print ("")
  70.         elseif direction=="l" then
  71.             print ("")
  72.         else
  73.             print ("Invalid input!")
  74.             direction = io.read()
  75.             checkr()
  76.         end
  77.     end
  78.      
  79.     function checkref()--To check if refuel is valid ((r) or (l))
  80.         if refuel=="y" then
  81.             print ("")
  82.         elseif refuel=="n" then
  83.             print ("")
  84.         else
  85.             print ("Invalid number!")
  86.             refuel = io.read()
  87.             checkref()
  88.         end
  89.     end
  90.    
  91.     function checktor()--To check if torch is valid ((y) or (n))
  92.         if torch=="y" then
  93.             print ("")
  94.         elseif torch=="n" then
  95.             print ("")
  96.         else
  97.             print ("Invalid number!")
  98.             torch = io.read()
  99.             checktor()
  100.         end
  101.     end
  102.      
  103.     function move()--Basic movement funktion
  104.         local debug = 8--Used to avoid gavel, sand, etc.
  105.         for i = 1, length do
  106.         if turtle.detect() then
  107.             for i = 1, debug do
  108.                 turtle.dig()
  109.             end
  110.             turtle.forward()
  111.         else
  112.             turtle.forward()
  113.         end
  114.         if turtle.detectUp() then
  115.             for i = 1, debug do
  116.                 turtle.digUp()
  117.             end
  118.         end
  119.         end
  120.     end
  121.      
  122.     function turnaround()--Turns the turtle at 90 degrees
  123.         turtle.turnRight()
  124.         turtle.turnRight()
  125.     end
  126.      
  127.     function torching()
  128.         if torch=="y" then
  129.             turtle.turnRight()
  130.             turtle.select(16)
  131.             turtle.placeUp()
  132.             turtle.turnLeft()  
  133.         end
  134.     end
  135.      
  136.      
  137.     function nextshaft()--Next shaft (right)
  138.         turtle.turnLeft()
  139.         turtle.dig()
  140.         turtle.digUp()
  141.         turtle.forward()
  142.         turtle.dig()
  143.         turtle.digUp()
  144.         torching()
  145.         turtle.forward()
  146.         turtle.dig()
  147.         turtle.digUp()
  148.         turtle.forward()
  149.         turtle.digUp()
  150.         turtle.turnRight()
  151.     end
  152.          
  153.     function returnpoint()--Return to initial point
  154.             shaftcount = shaftcount + 1
  155.             turtle.turnRight()
  156.             if shaftcount>=2 then
  157.                 turtle.forward()
  158.             end
  159.             turtle.forward()
  160.             for i = 1, shaftcount do
  161.                 turtle.forward()
  162.                 turtle.forward()
  163.             end
  164.             if stop==1 then
  165.                 turtle.forward()
  166.             end
  167.             turtle.forward()
  168.             for i = 1, space do
  169.                 turtle.select(i)
  170.                 turtle.drop()
  171.             end
  172.             turtle.select(1)
  173.        
  174.         turnaround()
  175.         if chest==1 then
  176.             returnmining()
  177.         end
  178.     end
  179.    
  180.      
  181.     function checkspace()--Check for space and if necessary, return to initial point to the chest
  182.         local spaceleft = 0
  183.         for i = 1, space do
  184.             if turtle.getItemSpace(i) > 10 then
  185.                 spaceleft = spaceleft + 1
  186.             end
  187.         end
  188.         if spaceleft < 5 then
  189.             chest = 1
  190.             count = count - 1
  191.             returnpoint()
  192.         end
  193.     end
  194.      
  195.     shell.run ("clear")
  196.     print ("Strip-mining-program by onix331")
  197.     print ("Version ", ver)
  198.      
  199.     --Start user input
  200.     print ("Length of the single shaft(s):")
  201.     length = read()
  202.     checkl()
  203.      
  204.     print ("Count of the shafts:")
  205.     count = read()
  206.     checka()
  207.      
  208.    
  209.     print ("Want to put some Torches on the Wall?")
  210.     print ("Now? (Yes (y), No (n):")
  211.     torch = read()
  212.     checktor()
  213.     if torch=="y" then
  214.         print ("Please Put some in Slot 16")
  215.         print ("When done, press ENTER")
  216.         local sEvent, param = os.pullEvent("key")
  217.         if sEvent == "key" then
  218.            
  219.         end
  220.     end
  221.     direction = r
  222.    
  223.     --Refueling, a little bit complicated
  224.     print ("Dont forget to refuel!")
  225.     print ("Now? (Yes (y), No (n):")
  226.     refuel = read()
  227.     checkref()
  228.     if refuel=="y" then
  229.         print ("Please insert fuel anywhere")
  230.         print ("When done, press ENTER")
  231.         while true do
  232.                 local sEvent, param = os.pullEvent("key")
  233.                 if sEvent == "key" then
  234.                         if param == 28 then
  235.                     for i = 1, space do
  236.                         for i = 1, 64 do
  237.                             shell.run("refuel", rafzahl)
  238.                         end
  239.                         turtle.select(i)
  240.                     end
  241.                     turtle.select(1)
  242.                     break
  243.                 end
  244.             end
  245.         end
  246.     end
  247.      
  248.     --Print user inputs
  249.     shell.run ("clear")
  250.     print ("Input of Length:")
  251.     print (length)
  252.     print ("Input of count")
  253.     print (count)
  254.     os.sleep(2)
  255.     print ("3")
  256.     os.sleep(1)
  257.     print ("2")
  258.     os.sleep(1)
  259.     print ("1")
  260.     os.sleep(1)
  261.     print("Start!")
  262.      
  263.     --Main Program
  264.      
  265.     turtle.turnRight()
  266.     for i = 1, count do
  267.         move()
  268.         turnaround()
  269.         move()
  270.         move()
  271.         turnaround()
  272.         move()
  273.         nextshaft()
  274.         shaftcount = shaftcount + 1
  275.         count = count - 1
  276.         checkspace()
  277.     end
  278.     returnpoint()
  279.     print ("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement