Advertisement
Kagee

resin

May 6th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. args = {...}
  2.  
  3. -- Rubber collecting program for the Treetap Turtle
  4. -- Made by hildenae
  5. -- Example: (x:rubbertree, T:turtle, C:chest, #:space)
  6. --
  7. -- x#x#x#x
  8. -- #######
  9. -- x#x#x#x
  10. -- #######
  11. -- x#x#x#x
  12. -- T
  13. -- C
  14. --
  15. -- Command: resin 4 3
  16. -- Example loop: http://pastebin.com/dz0rDp7p
  17. -- Place Rubber Wood (ID 627 on FTB MindCrack) in
  18. -- top-left inventory slot (slot 1)
  19. -- Expects rubbertrees to be from 1 to 8 blocks of wood
  20.  
  21. if #args < 2 then
  22.         error("Arguments: <width of field> <depth of field>")
  23. end
  24.  
  25. width_of_field=tonumber(args[1])
  26. depth_of_field=tonumber(args[2])
  27.  
  28. rubberwood=1
  29.  
  30. function harvest_side(height, up, first)
  31.     if up then
  32.         move=turtle.up
  33.         direction="up"
  34.     else
  35.         move=turtle.down
  36.         direction="down"
  37.     end
  38.     d = 0
  39.     for i=1,height do
  40.         d = d +1
  41.         turtle.dig()
  42.         if i < height then
  43.             --print("Moving " .. direction)
  44.             move()
  45.         end
  46.         turtle.select(rubberwood)
  47.         if not turtle.compare() then
  48.             turtle.down()
  49.             return i
  50.         end
  51.        
  52.     end
  53.     --print("Tried to harvest #" .. d .. " blocks")
  54.     return height
  55. end
  56.  
  57. function move_cc_around_tree(last)
  58.     turtle.turnRight()
  59.     turtle.forward()
  60.     turtle.turnLeft()
  61.     turtle.forward()
  62.     if last == nil or last == false then
  63.         turtle.turnLeft()
  64.     end
  65. end
  66.  
  67. function move_tree_right()
  68.     --print("Moving right to next tree")
  69.     turtle.forward()
  70.     turtle.forward()
  71.     turtle.turnLeft()
  72. end
  73.  
  74. function move_row_forward()
  75.     --print("Moving forward to next row")
  76.     turtle.turnRight()
  77.     turtle.forward()
  78.     turtle.turnLeft()
  79.     turtle.forward()
  80.     turtle.forward()
  81.     turtle.turnLeft()
  82.     turtle.forward()
  83.     turtle.turnRight()
  84. end
  85.  
  86. function harvest_tree()
  87.     --print("Harvesting tree")
  88.     up=true
  89.     he=harvest_side(8,up) -- side 1
  90.     move_cc_around_tree(false)
  91.     he=harvest_side(he,not up)   -- side 2
  92.     move_cc_around_tree(false)
  93.     he=harvest_side(he, up)   -- side 3
  94.     move_cc_around_tree(false)
  95.     he=harvest_side(he, not up)   -- side 4
  96.     move_cc_around_tree(true) -- back where we started
  97. end
  98.  
  99. function harvest_row()
  100.     --print("Harvesting row")
  101.     for i=1,width_of_field do
  102.         harvest_tree()
  103.         if i < width_of_field then
  104.             move_tree_right()
  105.         end
  106.     end
  107.     --print("Moving to start of row")
  108.     turtle.turnRight()
  109.     turtle.turnRight()
  110.     for i=1,((width_of_field-1)*2) do
  111.         turtle.forward()
  112.     end
  113.     turtle.turnRight()
  114.     --print("Harvested row")
  115. end
  116.  
  117. function harvest()
  118.     for i=1,depth_of_field do
  119.         harvest_row()
  120.         if i < depth_of_field then
  121.             move_row_forward()
  122.         end
  123.     end
  124. end
  125.  
  126. function go_to_start()
  127.     turtle.turnRight()
  128.     turtle.forward()
  129.     turtle.turnRight()
  130.     for i=1,((depth_of_field-1)*2) do
  131.         turtle.forward()
  132.     end
  133.     turtle.turnRight()
  134.     turtle.forward()
  135.     turtle.turnRight()
  136. end
  137.  
  138. function drop_loot()
  139.     turtle.turnRight()
  140.     turtle.turnRight()
  141.     for i=2,16 do
  142.         turtle.select(i)
  143.         turtle.drop()
  144.     end
  145.     turtle.turnRight()
  146.     turtle.turnRight()
  147. end
  148.  
  149. harvest()
  150. go_to_start()
  151. drop_loot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement