Advertisement
R167

Turtle Program: Ender Quarry

Nov 23rd, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. args = { ... }
  2.  
  3. function usage()
  4.   usages = {
  5.     "fence",
  6.     "destroy",
  7.     "compute",
  8.     "mark"
  9.   }
  10.   for i = 1, #usages do
  11.     print("Usage: " .. shell.getRunningProgram() .. " " .. usages[i] .. " <length> <width>")
  12.   end
  13. end
  14.  
  15. function distance(dist, exec)
  16.   for i = 1, dist do
  17.     while not turtle.forward() do turtle.dig() turtle.attack() end
  18.     exec(i == dist)
  19.   end
  20. end
  21.  
  22. function goSize(length, width, exec)
  23.   distance(length, exec)
  24.   turtle.turnLeft()
  25.   distance(width, exec)
  26.   turtle.turnLeft()
  27.   distance(length, exec)
  28.   turtle.turnLeft()
  29.   distance(width, exec)
  30.   turtle.turnLeft()
  31. end
  32.  
  33. if #args < 3 then
  34.   usage()
  35.   return
  36. end
  37.  
  38. local execute = function() end
  39. local length = args[2] - 1
  40. local width = args[3] - 1
  41.  
  42. if args[1] == "fence" then
  43.   execute = function()
  44.     turtle.digDown()
  45.     slot = 2
  46.     while turtle.getItemCount(1) <= 1 do
  47.       if slot > 16 then error("Could not find more fences!") os.exit(1) end
  48.       turtle.select(slot)
  49.       if turtle.compareTo(1) then
  50.         turtle.transferTo(1)
  51.       end
  52.       slot = slot + 1
  53.     end
  54.     turtle.select(1)
  55.     turtle.placeDown()
  56.   end
  57. elseif args[1] == "destroy" then
  58.   execute = function()
  59.     turtle.digDown()
  60.   end
  61. elseif args[1] == "mark" then
  62.   execute = function(atEnd)
  63.     if atEnd then
  64.       while not turtle.down() do turtle.digDown() turtle.attackDown() end
  65.       turtle.select(2)
  66.       turtle.placeDown()
  67.       while not turtle.up() do turtle.digUp() turtle.attackUp() end
  68.       turtle.select(1)
  69.       turtle.placeDown()
  70.     end
  71.   end
  72. elseif args[1] == "compute" then
  73.   print("Fence needed: " .. tostring(2 * length + 2 * width))
  74.   return
  75. else
  76.   return
  77. end
  78.  
  79. goSize(length, width, execute)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement