Guest User

Choppin

a guest
Aug 25th, 2019
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. --Declaring Variables
  3. local isWood
  4. local Length
  5. local pastSelect
  6. local Block
  7. local Coal
  8. local Sap
  9. local Amount
  10. local Wait
  11. local Trees = 0
  12.  
  13. --Start
  14. function start()
  15.     term.setTextColor( colors.green )
  16.     print("Welcome to the wood chopping program.")
  17.     term.setTextColor( colors.red )
  18.     print("How long do you want it to be?")
  19.     Length = tonumber( io.read() )
  20.     term.setTextColor( colors.green )
  21.     print("The length is", Length)
  22.     term.setTextColor( colors.red )
  23.     print("How long do you want it to wait before checking for trees(in seconds)?")
  24.     Wait = tonumber( io.read() )
  25.     term.setTextColor( colors.green )
  26.     print("The turtle will wait", Wait, "seconds")
  27.     term.setTextColor( colors.blue )
  28.     print("To Do: \n  1:Place 2 chests on on top of the\n    other infront of the turtle so its\n    facing it")
  29.     term.setTextColor( colors.green )
  30.     print("Press any key to continue")
  31.     os.pullEvent("key")
  32.     term.setTextColor( colors.blue )
  33.     print("  2:Place 10 charcoal in the bottom\n    chest and", (Length * 2), "saplings in the top\n    chest")
  34.     term.setTextColor( colors.green )
  35.     print("Press any key to continue")
  36.     os.pullEvent("key")
  37.     term.setTextColor( colors.blue )
  38.     print("  3:Place", (Length * 2), "of any block if you dont\n    want any large trees to grow")
  39.     term.setTextColor( colors.green)
  40.     print("Press any key to continue")
  41.     os.pullEvent("key")
  42.     term.setTextColor( colors.blue )
  43.     print("  4:Route all saplings to the top chest\n    and part of the charcoal to the\n    bottom chest")
  44.     term.setTextColor( colors.green )
  45.     print("Press any key to continue")
  46.     os.pullEvent("key")
  47.     term.setTextColor( colors.blue )
  48.     print("  5:Make sure there is some method to\n    suck up the dropped items")
  49.     term.setTextColor( colors.green )
  50.     print("Press any key to continue")
  51.     os.pullEvent("key")
  52.     term.setTextColor( colors.blue )
  53.     print("  6:Make sure the space is clear for\n    the turtle")
  54.     term.setTextColor( colors.orange )
  55.     print("Press any key to start turtle.")
  56.     os.pullEvent("key")
  57.     getCoal()
  58.     fuel()
  59.     getSap()
  60.     turtle.turnRight()
  61.     --Places sapplings
  62.     turtle.select(2)
  63.     for i = 1, Length do
  64.         turtle.dig()
  65.         turtle.place()
  66.         turtle.turnRight()
  67.         turtle.turnRight()
  68.         turtle.dig()
  69.         turtle.place()
  70.         turtle.turnLeft()
  71.         turtle.forward()
  72.         turtle.turnLeft()
  73.     end
  74.     turtle.turnRight()
  75.     turtle.back()
  76.     turtle.turnLeft()
  77.     for i = 1, 10 do
  78.         turtle.up()
  79.     end
  80.     turtle.select(3)
  81.     --Makes the top line to stop big trees
  82.     for i = 1, Length do
  83.         turtle.place()
  84.         turtle.turnLeft()
  85.         turtle.turnLeft()
  86.         turtle.place()
  87.         turtle.turnRight()
  88.         turtle.forward()
  89.         turtle.turnRight()
  90.     end
  91.     turtle.turnRight()
  92.     turtle.forward()
  93.     for i = 1, 10 do
  94.         turtle.down()
  95.     end
  96.     turtle.select(2)
  97. end
  98.  
  99. --Main part that loops
  100. function main()
  101.     for i = 1, Length do
  102.         fuel()
  103.         turtle.turnLeft()
  104.         check()
  105.         turtle.turnRight()
  106.         turtle.turnRight()
  107.         check()
  108.         turtle.turnLeft()
  109.         turtle.forward()
  110.     end
  111.     turtle.turnLeft()
  112.     turtle.turnLeft()
  113.     for i = 1, Length do
  114.         turtle.forward()
  115.     end
  116.     getCoal()
  117.     getSap()
  118.     turtle.turnLeft()
  119.     turtle.turnLeft()
  120.     sleep()
  121. end
  122.  
  123. function fuel()
  124.     if (turtle.getFuelLevel() < 100) then
  125.         repeat
  126.             pastSelect = turtle.getSelectedSlot()
  127.             turtle.select(1)
  128.             turtle.refuel(1)
  129.             turtle.select(pastSelect)
  130.         until turtle.getFuelLevel() >= 100
  131.     end
  132. end
  133.  
  134. function check()
  135.     turtle.place()
  136.     local Um, Block = turtle.inspect()
  137.     if (Block.name == "minecraft:log") then
  138.         Trees = Trees+1
  139.         print("Total trees:", Trees)
  140.         chopNplant()
  141.     end
  142. end
  143.  
  144. function getCoal()
  145.     if (turtle.getItemCount(1) < 10) then
  146.         pastSelect = turtle.getSelectedSlot()
  147.         Amount = 64 - turtle.getItemCount(1)
  148.         turtle.select(1)
  149.         turtle.suck(Amount)
  150.         turtle.select(pastSelect)
  151.     end
  152. end
  153.  
  154. function getSap()
  155.     if (turtle.getItemCount(2) < Length) then
  156.         turtle.up()
  157.         pastSelect = turtle.getSelectedSlot()
  158.         Amount = 64 - turtle.getItemCount(2)
  159.         turtle.select(2)
  160.         turtle.suck(Amount)
  161.         turtle.select(pastSelect)
  162.         turtle.down()
  163.     end
  164. end
  165.  
  166. function sleep()
  167.     os.sleep(Wait)
  168.     main()
  169. end
  170.  
  171. function chopNplant()
  172.     turtle.dig()
  173.     turtle.place()
  174.     pastSelect = turtle.getSelectedSlot()
  175.     turtle.select(3)
  176.     turtle.drop()
  177.     turtle.select(pastSelect)
  178. end
  179.  
  180. start()
  181. main()
RAW Paste Data