bigougit

redwoodFarm

Mar 20th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.20 KB | None | 0 0
  1. --[[
  2. redwoodFarm v0.1 by bigougit
  3. youtube.com/user/bigougit
  4. http://twitter.com/bigougit
  5.  
  6. This program is for mining
  7. or felling turtles only.
  8.  
  9. To install in-game, make sure
  10. that http = true in your
  11. computercraft config.
  12.  
  13. To install, open your turtle
  14. and type:
  15. pastebin get AfDQfiwf redwoodFarm
  16.  
  17. The turtle needs 5 sapplings
  18. and 1 log to start. This
  19. program only handles 2x2
  20. trees like redwoods .
  21.  
  22. Place sapplings in slot 1
  23. and logs in slot 2. The
  24. turtle will use logs for
  25. fuel as needed.
  26.  
  27. --]]
  28.  
  29. local continue = true
  30. local treeCount = 0
  31. local moved = 0
  32. local fakeTrees = 0
  33.  
  34. turtle.select(1)
  35. term.clear()
  36. term.setCursorPos(1,1)
  37.  
  38. --return how many items in [slot]
  39. local function sCount(slot)
  40.   return turtle.getItemCount(slot)
  41. end
  42.  
  43. function stack(slot)
  44.  
  45.   local room = turtle.getItemSpace(slot)
  46.   local s = 0
  47.   while room > 0 do
  48.     s = s + 1
  49.     if s >= 16 then
  50.       room = 0
  51.     end
  52.     if s ~= slot then      
  53.       turtle.select(s)
  54.       if turtle.compareTo(slot) then
  55.         if sCount(s) >= room then        
  56.           turtle.transferTo(slot, room)
  57.           room = 0
  58.         else
  59.           local temp = sCount(s)
  60.           turtle.transferTo(slot,temp)
  61.           room = room - temp
  62.         end
  63.       end
  64.     end
  65.   end
  66.   turtle.select(slot)
  67. end
  68.  
  69. local function dispStats(message)
  70.   term.clear()
  71.   term.setCursorPos(1,1)
  72.   print("Bigougit's tree farming program.")
  73.   print("Trees farmed:    "..treeCount)
  74.   print("Fakes trees:     "..fakeTrees)
  75.   if message ~= nil then
  76.     print(message)
  77.   end
  78. end
  79.  
  80. function fuel(slot, need)
  81.   local iCount = sCount(slot)
  82.   --stack(slot)
  83.   local cont = true
  84.   while cont do
  85.     if turtle.getFuelLevel() < need then
  86.       if iCount > 1 then
  87.         turtle.select(slot)
  88.         turtle.refuel(1)
  89.         if iCount == sCount(slot) then
  90.           cont = false
  91.         else
  92.           iCount = sCount(slot)
  93.         end
  94.       else
  95.         cont = false
  96.       end
  97.     else
  98.       return true
  99.     end
  100.   end
  101.   if turtle.getFuelLevel() < need then
  102.     return false
  103.   else
  104.     return true
  105.   end
  106. end
  107.  
  108. function chop()
  109.   if turtle.getFuelLevel() < 100 then
  110.     print("need more fuel")
  111.     return false
  112.   end
  113.  
  114.   turtle.dig()
  115.   turtle.forward()
  116.  
  117.   count = 0
  118.  
  119.   while turtle.detectUp() do
  120.     turtle.dig()
  121.     turtle.digUp()
  122.     turtle.up()
  123.     count = count + 1
  124.     moved = moved + 1  
  125.    --print(count)
  126.   end
  127.  
  128.   turtle.turnRight()
  129.   turtle.dig()
  130.   turtle.forward()
  131.   turtle.turnLeft()
  132.   turtle.dig()
  133.  
  134.  
  135.   while count > 0 do
  136.     turtle.dig()
  137.     turtle.digDown()
  138.     turtle.down()
  139.     count = count - 1
  140.     --print(count)
  141.   end
  142.   turtle.dig()
  143. end
  144.  
  145. function plant()
  146.   turtle.select(1)
  147.   while sCount(1) <= 4 do
  148.     dispStats("Need more sapplings.")
  149.   end
  150.   turtle.place()
  151.   turtle.turnLeft()
  152.   turtle.forward()
  153.   turtle.turnRight()
  154.   turtle.place()
  155.   turtle.turnRight()
  156.   turtle.place()
  157.   turtle.turnLeft()
  158.   turtle.back()
  159.   turtle.place()
  160. end
  161.  
  162. -- start of main program
  163.  
  164. dispStats(nil)
  165. stack(1)
  166. while ( sCount(1) <= 1 ) do
  167.   dispStats("Need at least 2 sapplings in first slot to start.")
  168.   sleep(2)
  169.   term.clear()
  170.   term.setCursorPos(1,1)
  171. end
  172.  
  173. dispStats(nil)
  174.  
  175. if not turtle.detect() then
  176.   turtle.place()
  177. end
  178.  
  179. while continue do
  180.   turtle.select(2)
  181.   if turtle.compare() then
  182.     if fuel(2, 18) then
  183.       dispStats("Chopping Tree...")
  184.       turtle.select(2)
  185.       chop()
  186.       plant()
  187.     end
  188.    -- stack(1)
  189.    -- stack(2)
  190.     turtle.select(1)
  191.     if sCount(1) > 1 then
  192.       turtle.place()
  193.     end
  194.     if moved > 0 then
  195.       treeCount = treeCount + 1
  196.       stack(1)
  197.       stack(2)
  198.       turtle.select(2)
  199.     else
  200.       --turtle.dig()
  201.       fakeTrees = fakeTrees + 1
  202.     end
  203.     moved = 0
  204.   end
  205.   while not turtle.compare() do
  206.     dispStats("Waiting for tree to grow.")
  207.     redstone.setOutput("bottom",true)
  208.     sleep(0.5)
  209.     redstone.setOutput("bottom",false)
  210.     sleep(5)
  211.   end
  212.   while sCount(1) <= 1 do
  213.     dispStats("Need at least 2 sapplings in first slot to start.")
  214.     sleep(2)
  215.     term.clear()
  216.     term.setCursorPos(1,1)
  217.   end
  218.   dispStats(nil)
  219.   turtle.select(1)
  220.   if not turtle.detect() then
  221.     turtle.place()
  222.   end
  223.   turtle.select(2)
  224.   sleep(.5)
  225. end
Advertisement
Add Comment
Please, Sign In to add comment