TheSommer

Plane (Not Yet Tested)

Oct 2nd, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. local resourceSlot = 2
  2.  
  3. function refuel()
  4.     if(turtle.getFuelLevel() == 0) then
  5.         turtle.select(1)
  6.         turtle.refuel(1)
  7.         turtle.select(resourceSlot)
  8.     end
  9. end
  10.  
  11. function forward()
  12.     refuel()
  13.     turtle.forward()
  14. end
  15.  
  16. function readyResource()
  17.     if(turtle.getItemCount(resourceSlot) == 0) then
  18.         count = 1
  19.         for i = 2, 16, 1 do
  20.             if(turtle.getItemCount(i) ~= 0) then
  21.                 resourceSlot = i
  22.                 turtle.select(resourceSlot)
  23.                 return true
  24.             else
  25.                 count = count + 1
  26.             end
  27.             if(count == 15) then
  28.                 term.write("Waiting for new Resources!")
  29.                 return false
  30.             end
  31.         end
  32.     end
  33.     return true
  34. end
  35.  
  36. local a,b = term.getCursorPos()
  37. term.write("How long do you want the plane?")
  38. b = b + 1
  39. term.setCursorPos(a, b)
  40. term.write("(Where the length is straight forward from the turtle)")
  41. b = b + 1
  42. term.setCursorPos(a, b)
  43. local x = io.read()
  44.  
  45. term.write("How wide do you want the plane?\n")
  46. b = b + 1
  47. term.setCursorPos(a, b)
  48. term.write("(Where the length is extending to the left of the turtle)")
  49. b = b + 1
  50. term.setCursorPos(a, b)
  51. local y = io.read()
  52.  
  53. if(x % 1 ~= 0 or y % 1 ~= 0) then
  54.     term.write("Invalid arguments, please only use numbers.")
  55.     return
  56. end
  57.  
  58. term.clear()
  59.  
  60. for i = 1, y, 1 do
  61.     for j = 1, x, 1 do
  62.         forward()
  63.         if(readyResource()) then
  64.         else
  65.             while(readyResource ~= true) do
  66.                 sleep(5)
  67.             end
  68.         end
  69.         turtle.placeDown() 
  70.     end
  71.     if(y % 2 == 0) then
  72.         turtle.turnRight()
  73.         forward()
  74.         turtle.turnRight()
  75.     else
  76.         turtle.turnLeft()
  77.         forward()
  78.         turtle.turnLeft()  
  79.     end
  80. end
Advertisement
Add Comment
Please, Sign In to add comment