Advertisement
Slayster

Tekkit Leaf Placer Turtle

Jun 18th, 2013
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.76 KB | None | 0 0
  1. -- ======================================
  2. -- Moon Leaf Placer Turtle
  3. -- brendan@slayweb.com 2013-06-03
  4. -- ======================================
  5.  
  6. -- ======================
  7. -- Variables
  8. -- ======================
  9.  
  10. local programrunning = true
  11. local walllength = 18
  12.  
  13. -- ======================
  14. -- Functions
  15. -- ======================
  16.  
  17. function refuel()
  18.    -- refuel turtle from one of the bottom four slots
  19.    if turtle.getItemCount(16)==64 then
  20.       turtle.select(16)
  21.       turtle.refuel(64)
  22.    else
  23.        if turtle.getItemCount(15)==64 then
  24.           turtle.select(15)
  25.           turtle.refuel(64)
  26.        else
  27.            if turtle.getItemCount(14)==64 then
  28.               turtle.select(14)
  29.               turtle.refuel(64)
  30.            else
  31.                if turtle.getItemCount(13)==64 then
  32.                   turtle.select(13)
  33.                   turtle.refuel(64)
  34.                else
  35.                   programrunning = false
  36.                   print("Error: Ran out of fuel")
  37.                end
  38.            end
  39.        end
  40.    end
  41. end
  42.  
  43. function check_fuel()
  44.    if turtle.getFuelLevel()<1 then
  45.       refuel()
  46.    end
  47. end
  48.  
  49. function place_leaf()
  50.    if turtle.getItemCount(1)>0 then
  51.       turtle.select(1)
  52.       turtle.place()
  53.    else
  54.        if turtle.getItemCount(2)>0 then
  55.           turtle.select(2)
  56.           turtle.place()
  57.        else
  58.            if turtle.getItemCount(3)>0 then
  59.               turtle.select(3)
  60.               turtle.place()
  61.            else
  62.                if turtle.getItemCount(4)>0 then
  63.                   turtle.select(4)
  64.                   turtle.place()
  65.                else
  66.                   programrunning = false
  67.                   print("Error: Ran out of leaves")
  68.                end
  69.            end
  70.        end
  71.    end
  72. end
  73.  
  74. function need_fuel()
  75.    if turtle.getItemCount(13)==0 then
  76.       turtle.select(13)
  77.       turtle.suck()
  78.    end  
  79.    if turtle.getItemCount(14)==0 then
  80.       turtle.select(14)
  81.       turtle.suck()
  82.    end  
  83.    if turtle.getItemCount(15)==0 then
  84.       turtle.select(15)
  85.       turtle.suck()
  86.    end  
  87.    if turtle.getItemCount(16)==0 then
  88.       turtle.select(16)
  89.       turtle.suck()
  90.    end  
  91. end
  92.  
  93. function need_leaves()
  94.    if turtle.getItemCount(1)==0 then
  95.       turtle.select(1)
  96.       turtle.suck()
  97.    end  
  98.    if turtle.getItemCount(2)==0 then
  99.       turtle.select(2)
  100.       turtle.suck()
  101.    end  
  102.    if turtle.getItemCount(3)==0 then
  103.       turtle.select(3)
  104.       turtle.suck()
  105.    end  
  106.    if turtle.getItemCount(4)==0 then
  107.       turtle.select(4)
  108.       turtle.suck()
  109.    end  
  110. end
  111.  
  112. -- ======================
  113. -- Main Program
  114. -- ======================
  115.  
  116. while programrunning==true do
  117.  
  118.    -- start in front of fuel box
  119.  
  120.    -- do we need to pick up more fuel?
  121.    need_fuel()
  122.    -- do we need to refuel?
  123.    check_fuel()
  124.  
  125.    -- move to leaf box
  126.    turtle.turnLeft()
  127.    turtle.forward()
  128.    turtle.turnRight()
  129.  
  130.    -- do we need to restock on leaves?
  131.    need_leaves()
  132.    
  133.    -- about face
  134.    turtle.turnLeft()
  135.    turtle.turnLeft()
  136.  
  137.    -- move to top
  138.    turtle.up()
  139.    check_fuel()
  140.    turtle.up()
  141.    check_fuel()
  142.    turtle.up()
  143.    check_fuel()
  144.    
  145.    -- check row 1 of leaves
  146.     for n = 1,walllength,1 do
  147.         check_fuel()
  148.         if turtle.detect()==false then
  149.             -- move forward
  150.             turtle.forward()
  151.             check_fuel()
  152.             -- place leaf if not there
  153.             if turtle.detect()==false then
  154.                place_leaf()
  155.             end
  156.             -- move back
  157.             turtle.back()
  158.             check_fuel()
  159.             -- place leaf
  160.             place_leaf()
  161.         end
  162.         turtle.turnLeft()
  163.         turtle.forward()
  164.         check_fuel()
  165.         turtle.turnRight()
  166.     end
  167.  
  168.     -- down for next row
  169.     turtle.down()
  170.     check_fuel()
  171.  
  172.     -- check row 2 of leaves
  173.     for n = 1,walllength,1 do
  174.         check_fuel()
  175.         if turtle.detect()==false then
  176.             -- move forward
  177.             turtle.forward()
  178.             check_fuel()
  179.             -- place leaf if not there
  180.             if turtle.detect()==false then
  181.                place_leaf()
  182.             end
  183.             -- move back
  184.             turtle.back()
  185.             check_fuel()
  186.             -- place leaf
  187.             place_leaf()
  188.         end
  189.         turtle.turnRight()
  190.         turtle.forward()
  191.         check_fuel()
  192.         turtle.turnLeft()
  193.     end
  194.  
  195.     -- down for next row
  196.     turtle.down()
  197.     check_fuel()
  198.  
  199.     -- check row 3 of leaves
  200.     for n = 1,walllength,1 do
  201.         check_fuel()
  202.         if turtle.detect()==false then
  203.             -- move forward
  204.             turtle.forward()
  205.             check_fuel()
  206.             -- place leaf if not there
  207.             if turtle.detect()==false then
  208.                place_leaf()
  209.             end
  210.             -- move back
  211.             turtle.back()
  212.             check_fuel()
  213.             -- place leaf
  214.             place_leaf()
  215.         end
  216.         turtle.turnLeft()
  217.         turtle.forward()
  218.         check_fuel()
  219.         turtle.turnRight()
  220.     end
  221.  
  222.     -- down for next row
  223.     turtle.down()
  224.     check_fuel()
  225.  
  226.     -- check row 4 of leaves
  227.     for n = 1,walllength,1 do
  228.         check_fuel()
  229.         if turtle.detect()==false then
  230.             -- move forward
  231.             turtle.forward()
  232.             check_fuel()
  233.             -- place leaf if not there
  234.             if turtle.detect()==false then
  235.                place_leaf()
  236.             end
  237.             -- move back
  238.             turtle.back()
  239.             check_fuel()
  240.             -- place leaf
  241.             place_leaf()
  242.         end
  243.         turtle.turnRight()
  244.         turtle.forward()
  245.         check_fuel()
  246.         turtle.turnLeft()
  247.     end
  248.  
  249.     -- back to start
  250.     turtle.turnLeft()
  251.     turtle.forward()
  252.     turtle.turnLeft()
  253.  
  254.  
  255. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement