TheSommer

Mineshaft

Jan 26th, 2013
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. --[[
  2.     Author
  3.         Rasmus Sommer aka. TheSommer
  4.         youtube.com/thesommersmc
  5.         twitch.tv/thesommer
  6.    
  7.     How to use:
  8.         Slot 1 - Fuel
  9.         Slot 2 - (OPTIONAL) Torches
  10.    
  11.         mineshaft <param: right | left>
  12.     OPTIONAL parameters: right OR left
  13.        
  14.     This program uses optional parameters.
  15.     You don't HAVE to write something after the program name,
  16.     but if you write "right" or "left" the turtle will place torches to the specified side.
  17. --]]
  18.  
  19. local tArgs = { ... }
  20. local side = "NA"
  21. if #tArgs == 0 then
  22. elseif #tArgs == 1 then
  23.     if tArgs[1] == "right" then
  24.         side = "right"
  25.     elseif tArgs[1] == "left" then
  26.         side = "left"
  27.     else
  28.         print ("Usage: mineshaft <param>")
  29.         print ("OPTIONAL parameters: right OR left")
  30.         print ("--- Using parameters will make the turtle place torches! ---")
  31.     end
  32. else
  33.     print ("Usage: mineshaft <param>")
  34.     print ("OPTIONAL parameters: right OR left")
  35.     print ("--- Using parameters will make the turtle place torches! ---")
  36. end
  37.  
  38. local function tryRefuel()
  39.     if turtle.getFuelLevel() == 0 then
  40.         turtle.select(1)
  41.         turtle.refuel(1)
  42.     end
  43. end
  44.  
  45. local function tryDig()
  46.     while turtle.detect() == true do
  47.         if turtle.dig() == false then
  48.             return false
  49.         end
  50.         sleep(0.5)
  51.     end
  52. end
  53.  
  54. local function tryDigUp()
  55.     while turtle.detectUp() == true do
  56.         if turtle.digUp() == false then
  57.             return false
  58.         end
  59.         sleep(0.5)
  60.     end
  61. end
  62.  
  63. local function tryDigDown()
  64.     while turtle.detectDown() == true do
  65.         if turtle.digDown() == false then
  66.             return false
  67.         end
  68.         sleep(0.5)
  69.     end
  70. end
  71.  
  72. local function tryForward()
  73.     if tryDig() == false then
  74.         return false
  75.     end
  76.     tryRefuel()
  77.     turtle.forward()
  78. end
  79.  
  80. local function tryDown()
  81.     if tryDigDown() == false then
  82.         return false
  83.     end
  84.     tryRefuel()
  85.     turtle.down()
  86. end
  87.  
  88. local count = 0
  89. local torchSpacing = 3
  90.  
  91. while true do
  92.     count = count + 1
  93.     if tryForward() == false then
  94.         print("Can't dig that, aborting.")
  95.         return
  96.     end
  97.     if tryDigUp() == false then
  98.         print("Can't dig that, aborting.")
  99.         return
  100.     end
  101.    
  102.     if count % torchSpacing == 0 then
  103.         if side == "right" then
  104.             turtle.turnRight()
  105.             tryDig()
  106.             turtle.select(2)
  107.             turtle.place()
  108.             turtle.turnLeft()
  109.         elseif side == "left" then
  110.             turtle.turnLeft()
  111.             tryDig()
  112.             turtle.select(2)
  113.             turtle.place()
  114.             turtle.turnRight()
  115.         end
  116.     end
  117.    
  118.     if tryDown() == false then
  119.         print("Can't dig that, aborting.")
  120.         return
  121.     end
  122.     if tryDigDown() == false then
  123.         print("Can't dig that, aborting.")
  124.         return
  125.     end
  126. end
Advertisement
Add Comment
Please, Sign In to add comment