Advertisement
Guest User

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

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