Advertisement
zaboodable

Turtle Remove 2.0

Mar 2nd, 2013
1,514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. --Input
  2.   print("This program will remove all blocks in an area defined by the following parameters.")
  3.   print("")
  4.   print("------------------------------------------------------------------------------")
  5.   print("")
  6.  
  7.   print("Enter area length.")
  8.   local length = tonumber(io.read())
  9.   length = length or 5
  10.   print("Area length set to: " .. length .. " blocks.")
  11.   print("")
  12.  
  13.   print("Enter area width.")
  14.   local width = tonumber(io.read())
  15.   width = width or length
  16.   print("Area width set to: " .. width .. " blocks.")
  17.   print("")
  18.  
  19.   print("Should the turtle move left or right?")
  20.   print("Type 0 or leave blank for Right.")
  21.   print("Type 1 for Left.")
  22.   local hdir = tonumber(io.read())
  23.   hdir = hdir or 0
  24.   if (hdir ~= 1) then
  25.     hdir = 0
  26.     hdirst = "Right"
  27.    else
  28.     hdir = 1
  29.     hdirst = "Left"
  30.   end
  31.   hhdir = hdir
  32.   print("Turtle will move " .. hdirst)
  33.   print("")
  34.  
  35.   print("Should the turtle move up or down?")
  36.   print("Type 0 or leave blank for down.")
  37.   print("Type 1 for up.")
  38.   local vdir = tonumber(io.read())
  39.   vdir = vdir or 0
  40.   if (vdir ~= 1) then
  41.     vdir = 0
  42.     vdirst = "Down"
  43.    else
  44.     vdir = 1
  45.     vdirst = "Up"
  46.   end
  47.   print("Turtle will move " .. vdirst)
  48.   print("")
  49.  
  50.   print("How far vertically should the turtle travel?")
  51.   print("Leave blank for 1")
  52.   local height = tonumber(io.read())
  53.   height = height or 1
  54.   if (height < 2) then
  55.     height = 1
  56.   end
  57.   print("Area height set to: " .. height .. " blocks.")
  58.   print("")
  59.   print("---------------------------------------")
  60.   print("")
  61.   print("Removing a " .. length .. "x" .. width .. "x" .. height .. " area to the " .. hdirst .. " of the turtle, digging " .. vdirst .. ".")
  62.  
  63.  
  64. --Functions
  65.  
  66.   function checkfuel()
  67.     if turtle.getFuelLevel() < 10 then
  68.       for i = 1, 16 do
  69.         turtle.select(i)
  70.         turtle.refuel(1)
  71.       end
  72.       turtle.select(1)
  73.     end
  74.   end
  75.  
  76.   function turnaround()
  77.     turtle.turnRight()
  78.     sleep(0.1)
  79.     turtle.turnRight()
  80.     sleep(0.1)
  81.   end
  82.    
  83.   function dig()
  84.     while turtle.detect() do
  85.       turtle.dig()
  86.       sleep(0.5)
  87.     end
  88.   end
  89.  
  90.   function digUp()
  91.     while turtle.detectUp() do
  92.       turtle.digUp()
  93.       sleep(0.5)
  94.     end
  95.   end
  96.  
  97.   function digDown()
  98.     while turtle.detectDown() do
  99.       turtle.digDown()
  100.       sleep(0.5)
  101.     end
  102.   end
  103.  
  104.   function nextcolumn()
  105.     for i = (vdir + 1), height do
  106.       checkfuel()
  107.       if vdir == 1 then
  108.         turtle.down()
  109.        else
  110.         turtle.up()
  111.       end
  112.     end
  113.   end
  114.  
  115.   function backlength()
  116.     turnaround()
  117.     for i = 1, length do
  118.       dig()
  119.       checkfuel()
  120.       turtle.forward()
  121.     end
  122.     turnaround()
  123.   end
  124.  
  125.   function dircheck()
  126.     if hdir == 0 then
  127.       turtle.turnRight()
  128.       dig()
  129.       checkfuel()
  130.       turtle.forward()
  131.       turtle.turnLeft()
  132.      else
  133.       turtle.turnLeft()
  134.       dig()
  135.       checkfuel()
  136.       turtle.forward()
  137.       turtle.turnRight()
  138.     end
  139.   end
  140.  
  141.  
  142. --Main
  143.  
  144.   for w = 1, width do
  145.     dig()
  146.     checkfuel()
  147.     turtle.forward()
  148.    
  149.     for l = 1, length do
  150.      
  151.       for h = (vdir + 1), height do
  152.         if vdir == 1 then
  153.             digUp()
  154.             checkfuel()
  155.             turtle.up()
  156.          else
  157.           digDown()
  158.           checkfuel()
  159.           turtle.down()
  160.         end
  161.       end
  162.       nextcolumn()
  163.       if l < length then
  164.         dig()
  165.         checkfuel()
  166.         turtle.forward()
  167.       end
  168.     end
  169.     backlength()
  170.     if w < width then
  171.       dircheck()
  172.     end
  173.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement