Advertisement
QQII

Pumpkin Farmer V0.1

Apr 2nd, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --Pumpkin Farmer V0.1 by QQII
  2. --Declerations
  3. local length = 0
  4. local width = -1
  5.  
  6. --Functions
  7. local function refuel()
  8.     while turtle.getFuelLevel() <= 0 do
  9.         shell.run("refuel", "all")
  10.         if turtle.getFuelLevel() <= 0 then
  11.             print("ERROR: out of fuel")
  12.             read()
  13.         end
  14.     end
  15. end
  16.  
  17. local function forward()                --Moves forward
  18.     refuel()
  19.     while not turtle.forward() do
  20.         while not turtle.dig() do
  21.             turtle.attack()
  22.         end
  23.     end
  24. end
  25.  
  26. local function digDown()                --Digs down
  27.     if turtle.detectDown() then
  28.         while not turtle.digDown() do
  29.             turtle.attackDown()
  30.         end
  31.     end
  32. end
  33.  
  34. local function line(l)                  --Harvests a line of l
  35.     for i = 1, l do
  36.         forward()
  37.         digDown()
  38.     end
  39.     forward()
  40. end
  41.  
  42. local function clearSlot(slotNumber)            --Attemps to clear the slot slotNumber
  43.     if turtle.getItemCount(slotNumber) ~= 0 then
  44.         turtle.select(slotNumber)
  45.         if not turtle.drop() then
  46.             print("ERROR: failure to clear slot number " .. slotNumber)
  47.         end
  48.     end
  49. end
  50.  
  51. local function clearSlots()             --Places all the items into the chest infront of the turtle
  52.     for i = 1,16 do
  53.         if turtle.getItemCount(i) ~= 0 then
  54.             clearSlot(i)
  55.         end
  56.     end
  57. end
  58.  
  59. --User Inputs
  60. print("The turtle will harvest a a pumpkin or melon farm")
  61. if length < 1 then
  62.     io.write("Length: ")
  63.         while length <= 0 do
  64.             length = tonumber(read())
  65.         end
  66. end
  67. if width < 0 then
  68.     io.write("Width: ")
  69.         while width <= 0 do
  70.             width = tonumber(read())
  71.         end
  72. end
  73.  
  74. --Main Script
  75. refuel()
  76. while true do
  77.     clearSlots()
  78.     os.sleep(length * 30)
  79.     for i = 1, 2 do
  80.         turtle.turnRight()
  81.         line(width)
  82.         turtle.turnRight()
  83.         line(length)
  84.     end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement