Advertisement
Andersfc

Tree-Farm

Dec 11th, 2012
1,630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.70 KB | None | 0 0
  1. --Pastebin code: UBF9dPVh
  2. --Wood-Log of the same type as the sapling, goes to slot #16
  3. --Saplings go to slot #15
  4. --Put a chest to the left of the turtle, to have the turtle drop his wood-logs
  5. --Put a chest on top of the turtle, to have it collect fuel (charcoal is gd, since its a tree-farm)
  6. --Put a chest behind it, to have it collect saplings+drop the saplings
  7. --If the turtle has more than 64 saplings, it will drop the saplings into the chest!
  8.  
  9. local tArgs = {...}
  10. local AmountCheck = 0
  11. local LogCount = 0
  12. local LogCount2 = 0
  13. local RefuelAmount = 0
  14.  
  15. shell.run("clear")
  16.  
  17. if tArgs[1] == "info" then
  18.    print("the same wood-log as the tree-farm's sapling")
  19.    print("goes into slot #16, saplings #15")
  20.    print("Press ENTER to continue reading the info!")
  21.    check = read()
  22.    shell.run("clear")
  23.    print("put a chest, behind the turtle, and it will draw saplings from the chest")
  24.    print("It will also deposit saplings, but it will try to keep 1 stack on itself")
  25.    print("put a chest to the left of the turtle, and it will drop logs into the chest")
  26.    print("remember to put the turtle at 2 blocks height!")
  27.    print("Press ENTER to continue reading the info!")
  28.    check = read()
  29.    shell.run("clear")
  30.    print("and a water-flow to collect extra saplings is useful")
  31.    print("the turtle can almost keep its saplings at a stable level")
  32.    print("the turtle will try to keep 1 stack of wood-logs on itself, at all times for fuel")
  33.    print("put a chest above the turtle to resupply it with fuel")
  34.    print("the turtle will try to keep atleast 10000 fuel units, per cycle!")
  35.    print("to allow big tree-farms")
  36.    return
  37. end
  38.  
  39. if #tArgs > 5 or #tArgs < 5 then
  40.    shell.run("clear")
  41.    print("Arguments are:")
  42.    print("1. <amount of space between saplings>")
  43.    print("1. You can also write <info> as the 1. argument!")
  44.    print("2. <amount of times to go forward and place saplings>")
  45.    print("3. <amount of times to make rows to the side>")
  46.    print("4. <amount of cycles> you can write a number, or <forever>")
  47.    print("5. <amount of things to refuel, per cycle from the top chest>")
  48.    return
  49. end
  50.  
  51. if tArgs[4] == "forever" then
  52.    AmountCheck = 1
  53. end
  54.  
  55. tArgs[1] = tArgs[1] + 1
  56.  
  57. function TopChestRefuel()
  58.  
  59.    if turtle.getFuelLevel() < 10000 then
  60.       turtle.select(14)
  61.       turtle.suckUp()
  62.       while turtle.getItemCount(14) < 1 do
  63.          shell.run("clear")
  64.          print("Master, the chest above my head has no fuel in it!")
  65.          turtle.suckUp()
  66.       end
  67.       for i = 1, tArgs[5] do
  68.          turtle.refuel(1)
  69.          RefuelAmount = RefuelAmount+1
  70.          if RefuelAmount == 64 then
  71.             RefuelAmount = 0
  72.             turtle.select(14)
  73.             turtle.suckUp()
  74.             while turtle.getItemCount(14) < 1 do
  75.                shell.run("clear")
  76.                print("Master, the chest above my head has no fuel in it!")
  77.                turtle.suckUp()
  78.             end
  79.          end        
  80.       end
  81.    end  
  82.    turtle.select(14)
  83.    turtle.dropUp()
  84.    turtle.select(1)
  85. end
  86.  
  87. function LogChestDeposit()
  88.  
  89.    ItemSlot = 0
  90.    turtle.turnLeft()
  91.    if turtle.getItemCount(16) > 1 then
  92.       LogCount = turtle.getItemCount(16)
  93.       LogCount2 = LogCount-1
  94.       turtle.select(16)
  95.       turtle.drop(LogCount)
  96.    end
  97.    for i = 1, 14 do
  98.       ItemSlot = ItemSlot+1
  99.       if turtle.getItemCount(ItemSlot) > 0 then
  100.          turtle.select(16)
  101.          if turtle.compareTo(ItemSlot) == true then
  102.             turtle.select(ItemSlot)
  103.             turtle.transferTo(1)
  104.          end
  105.       end
  106.    end
  107.    ItemSlot = 1
  108.    for i = 1, 13 do
  109.       ItemSlot = ItemSlot+1
  110.       if turtle.getItemCount(ItemSlot) > 0 then
  111.          turtle.select(16)
  112.          if turtle.compareTo(ItemSlot) == true then
  113.             turtle.select(ItemSlot)
  114.             if turtle.detect() == true then
  115.                turtle.drop()
  116.             end
  117.          end
  118.       end
  119.    end
  120.    turtle.turnRight()
  121. end
  122.        
  123. function SaplingChestDraw()
  124.    
  125.    if turtle.getItemCount(15) > 0 then
  126.       turtle.turnRight()
  127.       turtle.turnRight()
  128.       if turtle.detect() == true then
  129.          turtle.suck()
  130.          ItemSlot = 0
  131.          for i = 1, 14 do
  132.             ItemSlot = ItemSlot + 1
  133.             if turtle.getItemCount(ItemSlot) > 0 then
  134.                turtle.select(ItemSlot)
  135.                if turtle.compareTo(15) == true then
  136.                   turtle.transferTo(15)
  137.                end
  138.             end
  139.          end
  140.          ItemSlot = 0
  141.          for i = 1, 14 do
  142.             ItemSlot = ItemSlot + 1
  143.             if turtle.getItemCount(ItemSlot) > 0 then
  144.                turtle.select(ItemSlot)
  145.                if turtle.compareTo(15) == true then
  146.                   turtle.drop()
  147.                end
  148.             end
  149.          end
  150.       end
  151.       turtle.turnRight()
  152.       turtle.turnRight()
  153.    end
  154. end      
  155.  
  156. function CheckRefuel()
  157.    
  158.    while turtle.getFuelLevel() == 0 do
  159.       ItemSlot = 0
  160.       FuelCheck = 0
  161.       shell.run("clear")
  162.       print("I am out of fuel, my Master!")  
  163.       while FuelCheck == 0 do
  164.          ItemSlot = ItemSlot+1
  165.             sleep(0.4)
  166.             if turtle.getItemCount(ItemSlot) > 0 then
  167.                turtle.select(ItemSlot)
  168.                if turtle.refuel(1) == true then
  169.                   FuelCheck = 1
  170.                   shell.run("clear")
  171.                end
  172.             end
  173.             if ItemSlot == 14 then
  174.             ItemSlot = 0
  175.          end
  176.       end
  177.    end
  178. end
  179.  
  180. function MoveBack()
  181.    
  182.    CheckRefuel()
  183.    turtle.suckDown()
  184.    if turtle.back() == false then
  185.       turtle.turnRight()
  186.       turtle.turnRight()
  187.        while turtle.forward() == false do
  188.           turtle.select(16)
  189.           if turtle.compare() == true then
  190.             OakTreeCut()
  191.          else
  192.             turtle.dig()
  193.             CheckRefuel()
  194.             turtle.attack()
  195.          end
  196.       end
  197.       turtle.turnRight()
  198.       turtle.turnRight()
  199.       CheckRefuel()
  200.    end
  201. end
  202.  
  203. function OakSaplingPlace()
  204.  
  205.    for i = 1, tArgs[1] do
  206.          CheckRefuel()
  207.          turtle.suckDown()
  208.          while turtle.forward() == false do
  209.             turtle.select(16)
  210.             if turtle.compare() == true then
  211.                OakTreeCut()
  212.          else
  213.             turtle.dig()
  214.             CheckRefuel()
  215.             turtle.attack()
  216.          end
  217.       end
  218.    end
  219.    if turtle.detectDown() == false then
  220.       turtle.select(15)
  221.       while turtle.placeDown() == false do
  222.          if turtle.getItemCount(15) == 0 then
  223.             shell.run("clear")
  224.             print("I am out of saplings Master!")
  225.             sleep(5)
  226.          end
  227.       end
  228.    end  
  229. end
  230.  
  231. function OakTreeCut()
  232.    
  233.    turtle.select(1)
  234.    heightCheck = 0
  235.    turtle.dig()
  236.    CheckRefuel()
  237.    turtle.suckDown()
  238.    while turtle.forward() == false do
  239.       CheckRefuel()
  240.       turtle.attack()
  241.    end
  242.    while turtle.detectUp() do
  243.       heightCheck = heightCheck+1
  244.       turtle.select(1)
  245.       turtle.digUp()
  246.       CheckRefuel()
  247.       while turtle.up() == false do
  248.          CheckRefuel()
  249.          turtle.attackUp()
  250.       end
  251.       turtle.select(15)
  252.       for i = 1, 4 do
  253.          turtle.turnRight()
  254.          turtle.dig()
  255.       end
  256.    end
  257.    for i = 1, heightCheck do
  258.       CheckRefuel()
  259.       while turtle.down() == false do
  260.          CheckRefuel()
  261.          turtle.attackDown()
  262.       end
  263.    end
  264.    turtle.suckDown()
  265.    turtle.select(1)
  266.    turtle.digDown()
  267.    turtle.select(15)
  268.    if turtle.detectDown() == false then
  269.       turtle.select(15)
  270.        while turtle.placeDown() == false do
  271.           if turtle.getItemCount(15) < 0 then
  272.             print("I am out of saplings Master!")
  273.             sleep(5)
  274.          end
  275.       end
  276.    end
  277.    MoveBack()
  278. end
  279.  
  280. function OakFarm()
  281.    
  282.    for i = 1, tArgs[2] do
  283.       OakSaplingPlace()
  284.    end
  285.    for i = 1, tArgs[1] do
  286.       for i = 1, tArgs[2] do
  287.          MoveBack()
  288.       end
  289.    end
  290.    turtle.turnRight()
  291.    for i = 1, tArgs[3] do
  292.       OakSaplingPlace()
  293.       turtle.turnLeft()
  294.       for i = 1, tArgs[2] do
  295.          OakSaplingPlace()
  296.       end
  297.       for i = 1, tArgs[1] do  
  298.          for i = 1, tArgs[2] do
  299.             MoveBack()
  300.          end
  301.       end
  302.       turtle.turnRight()
  303.    end
  304.    for i = 1, tArgs[1] do
  305.       for i = 1, tArgs[3] do
  306.          MoveBack()
  307.       end
  308.    end
  309.    turtle.turnLeft()
  310.    SaplingChestDraw()
  311.    LogChestDeposit()
  312.    TopChestRefuel()
  313.    shell.run("clear")
  314.    print("Resting for 150 seconds!")
  315.    sleep(150)
  316. end
  317.  
  318. SaplingChestDraw()
  319. LogChestDeposit()
  320. TopChestRefuel()
  321. if AmountCheck == 1 then
  322.    while true do
  323.       OakFarm()
  324.    end
  325. else
  326.    AmountCheck = tArgs[4]
  327.    for i = 1, AmountCheck do
  328.       OakFarm()
  329.    end
  330.    shell.run("clear")
  331.    print("I am done my Master!")
  332. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement