Zekrommaster110

[LUA CC1.7] Mining v3.3.2

Jun 27th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.45 KB | None | 0 0
  1. -- Usage:   type in the console of any labeled mining turtle (w/o the ""):
  2. --          "pastebin get mfNUumgr mining" (you can also replace "mining" with another programname you want)
  3. --          "mining <number of mining floors> <type of delivery>" (or instead of "mining" your chosen programname)
  4. -- EXAMPLE: "mining 20 1"
  5. -- OR:      "mining" only to show the help
  6.  
  7. -- (C) Copyright 2016 zekro
  8.  
  9. local arg1, arg2 = ...
  10. local vers = "MINING v3.3.2 | (c) 2016 zekro"
  11.  
  12. function cls()
  13.     shell.run("clear")
  14. end
  15.  
  16. function dff(times)
  17.     for i = 1, tonumber(times), 1 do
  18.         while turtle.detect(forward) do
  19.             turtle.dig()
  20.             sleep(0.3)
  21.         end
  22.         turtle.forward()
  23.         turtle.digUp()
  24.     end
  25. end
  26.  
  27. -- start script
  28. function start()
  29.    
  30.     cls()
  31.     -- tests for the right start arguments
  32.     if (arg1 == nil) or (arg2 == nil) or (tonumber(arg2) > 2) then
  33.         print("Please name the length of the mine you want to have in the first Argument and the type of delivery in the second Argument!")
  34.         print("\nFor arg 2: 0 - without chests, 1 - double chest places nexto turtle, 2 - enderchest delivery")
  35.         print("\nExample: '<programname> 5 0'")
  36.         print("\nATTENTION: 1 unit means 3 Blocks!")
  37.         error()
  38.     end
  39.    
  40.     -- tests for a required empty inventory
  41.     while (turtle.getItemCount(1)>0) or (turtle.getItemCount(2)>0) or (turtle.getItemCount(4)>0) or (turtle.getItemCount(5)>0)  or (turtle.getItemCount(6)>0) or (turtle.getItemCount(7)>0) or (turtle.getItemCount(8)>0) or (turtle.getItemCount(9)>0) or (turtle.getItemCount(10)>0) or (turtle.getItemCount(11)>0) or (turtle.getItemCount(12)>0) or (turtle.getItemCount(13)>0) or (turtle.getItemCount(14)>0) or (turtle.getItemCount(15)>0) or (turtle.getItemCount(16)>0) do
  42.         cls()
  43.         print(vers, "\n")
  44.         print("Please empty the inventory of the turtle to continue!")
  45.         sleep(0,5)
  46.     end
  47.    
  48.     cls()
  49.     print(vers, "\n")
  50.     testForFuel()
  51.     print("Please put ", arg1, " torches in the first slot.")
  52.     repeat
  53.         sleep(0.5)
  54.     until turtle.getItemCount(1)==tonumber(arg1)
  55.    
  56.     -- if MODE 1 was chosen
  57.     if arg2 == "1" then
  58.         cls()
  59.         print(vers, "\n")
  60.         print("Please put in the second slot two normal chests.")
  61.         turtle.select(2)
  62.         repeat
  63.             sleep(0.5)
  64.         until turtle.getItemCount(2)==2
  65.     end
  66.    
  67.     -- if MODE 2 was chosen
  68.     if arg2 == "2" then
  69.         cls()
  70.         print(vers, "\n")
  71.         print("Please put in the second slot an enderchest.")
  72.         turtle.select(2)
  73.         repeat
  74.             sleep(0.5)
  75.         until turtle.getItemCount(2)==1
  76.     end
  77. end
  78.  
  79. -- tests for the fuel level of turtle & refilling
  80. function testForFuel()
  81.     fuel_need = arg1*30
  82.     if turtle.getFuelLevel() < fuel_need then
  83.         print("The fuel level don't suffice for the process.\nPlease put the following ammount of fuel in any slot:")
  84.         fuel_delta = fuel_need-turtle.getFuelLevel()
  85.         print("\n- ", fuel_delta/80, " coal\n- ", fuel_delta/15, " wooden plancks")
  86.         while (turtle.getItemCount(1)==0) and (turtle.getItemCount(2)==0) and (turtle.getItemCount(4)==0) and (turtle.getItemCount(5)==0)   and (turtle.getItemCount(6)==0) and (turtle.getItemCount(7)==0) and (turtle.getItemCount(8)==0) and (turtle.getItemCount(9)==0) and (turtle.getItemCount(10)==0) and (turtle.getItemCount(11)==0) and (turtle.getItemCount(12)==0) and (turtle.getItemCount(13)==0) and (turtle.getItemCount(14)==0) and (turtle.getItemCount(15)==0) and (turtle.getItemCount(16)==0) do
  87.             sleep(0.5)
  88.         end
  89.         shell.run("refuel all")
  90.         turtle.select(1)
  91.         cls()
  92.     end
  93. end
  94.  
  95. -- dig base with 2 standart chests (MODE 0)
  96. function base_1()
  97.     cls()
  98.     print(vers, "\n")
  99.     print("Digging base with two chests in progress...")
  100.    
  101.     dff(1)
  102.     turtle.turnRight()
  103.     dff(1)
  104.     turtle.back()
  105.     turtle.place()
  106.     turtle.turnLeft()
  107.     dff(1)
  108.     turtle.turnRight()
  109.     dff(1)
  110.     turtle.back()
  111.     turtle.place()
  112.     turtle.turnLeft()
  113. end
  114.  
  115. function base_2()
  116.     cls()
  117.     print(vers, "\n")
  118.     print("Digging base with enderchest in progress...")
  119.    
  120.     dff(1)
  121.     turtle.turnRight()
  122.     dff(1)
  123.     turtle.back()
  124.     turtle.place()
  125.     turtle.turnLeft()
  126. end
  127.  
  128. function strip()
  129.     for sf = 1, tonumber(arg1), 1 do
  130.         dff(2)
  131.         turtle.select(1)
  132.         dff(1)
  133.         turtle.back()
  134.         turtle.placeUp()
  135.         turtle.forward()
  136.         turtle.turnRight()
  137.         dff(4)
  138.         turtle.turnLeft()
  139.         turtle.turnLeft()
  140.         dff(8)
  141.         turtle.turnLeft()
  142.         turtle.turnLeft()
  143.         dff(4)
  144.         turtle.turnLeft()
  145.         if tonumber(arg2)>0 and (turtle.getItemCount(1)>0) and (turtle.getItemCount(2)>0) and (turtle.getItemCount(4)>0) and (turtle.getItemCount(5)>0) and (turtle.getItemCount(6)>0) and (turtle.getItemCount(7)>0) and (turtle.getItemCount(8)>0) and (turtle.getItemCount(9)>0) and (turtle.getItemCount(10)>0) and (turtle.getItemCount(11)>0) and (turtle.getItemCount(12)>0) and (turtle.getItemCount(13)>0) and (turtle.getItemCount(14)>0) and (turtle.getItemCount(15)>0) and (turtle.getItemCount(16)>0) then
  146.             turtle.turnLeft()
  147.             turtle.turnLeft()
  148.             for goback = 1, sf*3, 1 do
  149.                 turtle.forward()
  150.             end
  151.             turtle.turnLeft()
  152.             for ind = 2, 16, 1 do
  153.             turtle.select(ind)
  154.                 while turtle.getItemCount(ind)>0 do
  155.                     turtle.drop()
  156.                 end
  157.             end
  158.             turtle.turnLeft()
  159.             for goback = 1, sf*3, 1 do
  160.                 turtle.forward()
  161.             end
  162.         end
  163.     end
  164.     turtle.turnLeft()
  165.     turtle.turnLeft()
  166.     for goback = 1, tonumber(arg1)*3, 1 do
  167.         turtle.forward()
  168.     end
  169.     turtle.turnLeft()
  170.     for ind = 2, 16, 1 do
  171.         turtle.select(ind)
  172.         while turtle.getItemCount(ind)>0 do
  173.             turtle.drop()
  174.         end
  175.     end
  176.     turtle.turnRight()
  177.     turtle.forward()
  178.     turtle.forward()
  179. end
  180.  
  181. -- MAIN PROGRAM
  182. start()
  183. if arg2 == "1" then
  184.     base_1()
  185. end
  186. if arg2 == "2" then
  187.     base_2()
  188. end
  189. strip()
  190. cls()
  191. print(vers, "\n")
  192. print("FINISHED.")
Add Comment
Please, Sign In to add comment