Advertisement
M0n5t3r

Tree3

Jun 28th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. local tArgs = { ... }
  2. local togo = tonumber(tArgs[1])
  3. togo = togo or 1
  4. local sapling = 0
  5. term.clear()
  6. term.setCursorPos(1,1)
  7.  
  8. -- print stuff... nothing to be honest...
  9.  
  10. print(" *******************************")
  11. print(" *    Treefarm By BlackApple   *")
  12. print(" *******************************")
  13. print(" * How to start??              *")
  14. print(" * Put Coal in the right chest *")
  15. print(" * Put sapplings in the left   *")
  16. print(" *                             *")
  17. print(" *  Press [ENTER] when ready   *")
  18. print(" *******************************")
  19. read(input)
  20.  
  21. -- Fuel CHEST startup
  22.  
  23. if turtle.getItemCount(16) < 10 then
  24. turtle.select(16)
  25.     turtle.turnRight()
  26.     turtle.drop()
  27.     turtle.suck()
  28.     turtle.drop(54)
  29.     turtle.turnLeft()
  30. end
  31. sappling = 0
  32. if turtle.getItemCount(15) < 32 then
  33. turtle.select(15)
  34.     turtle.turnLeft()
  35.     turtle.drop()
  36.     turtle.suck()
  37.     turtle.turnRight()
  38. end
  39.  
  40. -- Functions
  41.  
  42. local function tfuel(amount)
  43.  if turtle.getFuelLevel() < 16 then
  44.   turtle.select(1)
  45.   turtle.refuel(amount)
  46.  end
  47. end
  48.  
  49. local function tforward(steps) -- turtle takes x steps forward
  50.   if steps==nil or steps==0 then steps=1 end
  51.   tfuel(1)
  52.   for i=1,steps do
  53.     while not turtle.forward() do
  54.       turtle.dig()
  55.           turtle.attack()
  56.     end
  57.   end
  58. end
  59.  
  60. local function turnaround()
  61.   turtle.turnRight()
  62.   turtle.turnRight()
  63. end
  64.  
  65. local function discard() -- drop off extra stuff into water
  66.   if turtle.getItemCount(3)<1 then
  67.     return
  68.   end
  69.   while not turtle.down() do
  70.     turtle.digDown()
  71.   end
  72.   for i = 1,13 do
  73.     if turtle.getItemCount(i)>0 then
  74.           turtle.select(i)
  75.           turtle.dropDown()
  76.     end
  77.   end
  78.   while not turtle.up() do
  79.     turtle.digUp()
  80.   end
  81.   turtle.select(16)  
  82. end
  83.  
  84. local function climb()
  85.   if turtle.detect() then
  86.     turtle.dig()
  87.     tforward()
  88.     local cnt=0
  89.     repeat
  90.       cnt = cnt + 1
  91.           turtle.dig()
  92.           sleep(0.5)
  93.           turtle.digUp()
  94.           tfuel(1)
  95.           turtle.up()
  96.     until not turtle.detect()
  97.     turtle.turnRight()
  98.     tforward()
  99.     turtle.turnLeft()
  100.     for i = 1,cnt do
  101.       turtle.digDown()
  102.           sleep(0.5)
  103.           tfuel(1)
  104.           turtle.down()
  105.           turtle.dig()
  106.     end
  107.     turtle.digDown()
  108.     turtle.select(15)
  109.     turtle.placeDown()
  110.     tforward()
  111.     turtle.digDown()
  112.     turtle.select(15)
  113.     turtle.placeDown()
  114.     turtle.turnLeft()
  115.     tforward()
  116.     turtle.digDown()
  117.     turtle.select(15)
  118.     turtle.placeDown()
  119.     turtle.turnLeft()
  120.     tforward()
  121.     turtle.digDown()
  122.     turtle.select(15)
  123.     turtle.placeDown()
  124.     turnaround()
  125.     tforward(2)
  126.   else
  127.     tforward(3)
  128.   end
  129.   discard()
  130. end
  131.  
  132. -- Main Loop
  133. tforward(2)  -- move into first position
  134. for r = 1,4 do
  135.   for i = 1,4 do
  136.     climb() -- climb and cut tree
  137.     if i<4 then
  138.       tforward(2)
  139.     end
  140.   end
  141.   if r<4 then
  142.     if r%2>0 then
  143.       turtle.turnRight()
  144.     else
  145.       turtle.turnLeft()
  146.     end
  147.     tforward(4+2*(r%2))
  148.     if r%2>0 then
  149.       turtle.turnRight()
  150.     else
  151.       turtle.turnLeft()
  152.     end
  153.   end
  154. end
  155. turtle.turnRight()
  156. tforward(16)  -- move back to base
  157. turtle.turnLeft()
  158. tforward(2)
  159. turnaround()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement