Advertisement
Ignius12

TreeChopper

Aug 4th, 2022 (edited)
1,091
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. host = 3
  2. status = "Inactive"
  3. pos = vector.new(gps.locate())
  4.  
  5. function chopTree()
  6. local modem = peripheral.find("modem")
  7. rednet.open("left")
  8.  
  9.  
  10. status = "Chopping"
  11. while turtle.detect() do
  12.     turtle.dig()
  13.     turtle.digUp()
  14.     turtle.up()
  15.     pos = vector.new(gps.locate())
  16. end
  17. status = "Returning"
  18. while not turtle.detect() and not turtle.detectDown() do
  19.     turtle.down()
  20.     pos = vector.new(gps.locate())
  21. end
  22.     turtle.select(1)
  23.     turtle.place()
  24.     turtle.select(2)
  25. status = "Idle"
  26. end
  27.  
  28. function farmTree()
  29.    while true do
  30.         turtle.select(2)
  31.         if(turtle.compare()) then
  32.                 chopTree()
  33.                 turtle.turnLeft()
  34.                 turtle.turnLeft()
  35.                 for i=3, 16 do
  36.                     turtle.select(i)
  37.                     if(turtle.compareTo(1)) then
  38.                         print("same!")
  39.                         turtle.transferTo(1)
  40.                     else
  41.                         turtle.drop()
  42.                     end
  43.                 end
  44.                 turtle.select(1)
  45.                 turtle.suckDown()
  46.                 turtle.turnLeft()
  47.                 turtle.turnLeft()
  48.         end
  49.         if(turtle.getFuelLevel() < 20) then
  50.             status = "Waiting for Fuel"
  51.             for i=3, 16 do
  52.                 turtle.select(i)
  53.                 turtle.refuel()
  54.             end
  55.             turtle.select(1)
  56.        end
  57.    end
  58. end
  59. function rangeCheck()
  60.     while true do
  61.         if rednet.receive("failsafe") == null then
  62.             os.shutdown()
  63.         end
  64.         sleep(1)
  65.     end
  66. end
  67. function transmit()
  68.     while(true) do
  69.     local sender, message, protocol = rednet.receive("ping")
  70.         if(message ~= nil and message == "send") then
  71.             rednet.send(host, os.getComputerLabel() .. " " .. turtle.getFuelLevel() .. " " .. pos.x .. " " .. pos.y .." " .. pos.z .. " " .. status, "miners")
  72.             sleep(0.5)
  73.         end
  74.     end
  75. end
  76. parallel.waitForAny(farmTree, rangeCheck, transmit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement