Guest User

chopper

a guest
Jun 30th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.91 KB | None | 0 0
  1. local function checkFuel()
  2.   if turtle.getFuelLevel() < 1 then
  3.     turtle.select(1)
  4.     turtle.refuel(1)
  5.   end
  6. end
  7. --
  8. local function Saplings()
  9.   print "Make sure Saplings are in Slot 16"
  10.   sleep(1)
  11.   Saplings = tonumber(turtle.getItemCount(16))
  12.   if Saplings > 3 then
  13.     print "Something is in Slot 16.\nLet's hope that are saplings ;)"
  14.   else
  15.     print "Need at least 4 saplings in Slot 16"
  16.       while Saplings < 4 do
  17.         Saplings = tonumber(turtle.getItemCount(16))
  18.         sleep(0)
  19.       end
  20.   end
  21. end
  22. --
  23. local function Ask()
  24.   term.clear()
  25.   term.setCursorPos(1,1)
  26.   sleep(1)
  27.   print "Enable Bonemeal? [y/n]"
  28.   bm = read()
  29. end
  30. --
  31. local function CheckInput()
  32.   if bm == "y" or bm == "yes" or bm == "n" or bm == "no" then
  33.     print("Input '" .. bm .. "'accepted")
  34.   else
  35.     error("Invalid Input! Ending program...",0)
  36.   end
  37. end
  38. --
  39. local function ConvertInput()
  40.   if bm == "y" or bm == "yes" then
  41.     bm = true
  42.     toDrop = 14
  43.   elseif bm == "n" or bm == "no" then
  44.     bm = false
  45.     toDrop = 15
  46.   end
  47. bm1 = tostring(bm)
  48. print("bm = " .. bm1)
  49. print("Drop =" .. toDrop)
  50. end
  51. --
  52. local function Start()
  53.   turtle.dig()
  54.   checkFuel()
  55.   turtle.forward()
  56. end
  57. --
  58. local function FellUp()
  59. up = 0
  60.   while turtle.detectUp() do
  61.     turtle.digUp()
  62.     turtle.dig()
  63.     checkFuel()
  64.     turtle.up()
  65.     up = up + 1
  66.   end
  67. end
  68. --
  69. local function Move()
  70.   turtle.dig()
  71.   checkFuel()
  72.   turtle.turnRight()
  73.   turtle.dig()
  74.   turtle.forward()
  75.   turtle.turnLeft()
  76. end
  77. --
  78. local function FellDown()
  79.   while up > 0 do
  80.     turtle.dig()
  81.     turtle.digDown()
  82.     checkFuel()
  83.     turtle.down()
  84.     up = up - 1
  85.   end
  86. end
  87. --
  88. local function Plant() --That's a mess. Sorry :)
  89.   turtle.dig()
  90.   checkFuel()
  91.   turtle.up()
  92.   turtle.select(16)
  93.   turtle.placeDown()
  94.   checkFuel()
  95.   turtle.forward()
  96.   turtle.select(16)
  97.   turtle.placeDown()
  98.   turtle.turnLeft()
  99.   checkFuel()
  100.   turtle.forward()
  101.   turtle.select(16)
  102.   turtle.placeDown()
  103.   turtle.turnLeft()
  104.   checkFuel()
  105.   turtle.forward()
  106.   turtle.select(16)
  107.   turtle.placeDown()
  108.   checkFuel()
  109.   turtle.forward()
  110.   checkFuel()
  111.   turtle.turnRight()
  112.   turtle.down()
  113.   turtle.turnRight()
  114. end
  115. --
  116. local function GetDrop()
  117. print(toDrop)
  118.   if not toDrop == 14 and not toDrop == 15 then
  119.     DropInvalid = 1
  120.     while DropInvalid == 1 do
  121.     print "Something went wrong. Unable to drop."
  122.     print "Drop everything? [y/n]"
  123.     DropAll = read()
  124.       if DropAll == y or DropAll == yes then
  125.         for i = 1,16 do
  126.           turtle.select(i)
  127.           turtle.drop()
  128.         end
  129.         DropInvalid = 0
  130.       elseif DropAll == n or DropAll == no then
  131.         print "Returning to start.\nPlease empty the inventory."
  132.         turtle.turnRight()
  133.         DropInvaild = 0
  134.       else
  135.         print "Invalid Input! Reloading"
  136.         term.clear()
  137.         term.setCursorPos(1,1)
  138.         sleep(1)
  139.         DropInvalid = 1 --Still 1
  140.       end
  141.     end
  142.   end
  143. end
  144. --
  145. local function Drop()
  146.   for i = 2,toDrop do
  147.     turtle.select(i)
  148.     turtle.dropDown()
  149.   end
  150. end
  151. --
  152. local function MovetoChest()
  153.   move = 10
  154.   checkFuel()
  155.   while move > 0 do
  156.     checkFuel()
  157.     turtle.forward()
  158.     move = move - 1
  159.   end
  160. end
  161. --
  162. local function CheckRes()
  163.   if bm == true then
  164.   bmCount = turtle.getItemCount(15)
  165.   end
  166.   SaplingCount = turtle.getItemCount(16)
  167.   print(bmCount)
  168.   print(SaplingCount)
  169. end
  170. --
  171. local function Decide()
  172.   if bmCount < 2 and bm == true then  
  173.     NeedBonemeal = 1
  174.   else
  175.     NeedBonemeal = 0
  176.   end
  177.   if SaplingCount < 4 then
  178.     NeedSaplings = 1
  179.   else
  180.     NeedSaplings = 0
  181.   end
  182. end
  183. --Begin
  184. Saplings()
  185. Ask()
  186. CheckInput()
  187. ConvertInput()
  188. Start()
  189. FellUp()
  190. Move()
  191. FellDown()
  192. Plant()
  193. print(Drop)
  194. GetDrop()
  195. Drop()
  196. CheckRes()
  197. Decide()
  198.   if Needbm == 1 or NeedSaplings == 1 then
  199.     MovetoChest()
  200.     GetRes = 1
  201.   else
  202.     turtle.turnRight()
  203.     GetRes = 0
  204.   end
  205. print(Needbm)
  206. print(NeedSaplings)
  207. print(GetRes)
Advertisement
Add Comment
Please, Sign In to add comment