S3mpx

Tree Farm Programm

Nov 3rd, 2023 (edited)
1,048
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.92 KB | Gaming | 0 0
  1. -- pastebin get UtfrZCiN tree.lua
  2.  
  3. -- [SETTINGS]
  4. -- tree farm perimeter
  5. pointA = { -- CURRENTLY STORED: SMP with da Boys
  6.     ['x'] = -42,
  7.     ['z'] = 51,
  8.     ['y'] = 72
  9. }
  10. pointB = {
  11.     ['x'] = -35,
  12.     ['z'] = 88,
  13.     ['y'] = 72
  14. }
  15. -- specifics
  16. treeRows = 2
  17. -- turtle
  18. location = {
  19.     ['x'] = -52,
  20.     ['z'] = 128,
  21.     ['y'] = 69
  22. }
  23. direction = {
  24.     ['x'] = 0,
  25.     ['z'] = -1;
  26. }
  27. -- NORTH -z, SOUTH z
  28. -- WEST -x, EAST x
  29.  
  30. -- check fuel
  31. fuelLevel = turtle.getFuelLevel()
  32. if(fuelLevel < 5000)
  33. then
  34.     write("fuel level too low \n")
  35.     write("by " .. (5000-fuelLevel) .. " fuel \n")
  36. else
  37.     write("sufficient fuel \n")
  38. end
  39.  
  40. -- implement break when fuel too low
  41.  
  42. -- [ LOCATE COORDINATES ]
  43. --> Y-Axis
  44. write("checking Y-Axis ... \n")
  45. if(location['y'] ~= pointA['y'])
  46. then
  47.     while(location['y'] ~= pointA['y'])
  48.     do
  49.         if(location['y'] > pointA['y'])
  50.         then -- go down
  51.             if(turtle.down() == false) then
  52.                 write("removing obstacle... \n")
  53.                 turtle.digDown()
  54.                 turtle.down()
  55.             end
  56.         write("moved down... \n")
  57.         location['y'] = location['y'] - 1
  58.         else -- go up
  59.             if(turtle.up() == false) then
  60.                 write("removing obstacle... \n")
  61.                 turtle.digUp()
  62.                 turtle.up()
  63.             end
  64.         write("moved up... \n")
  65.         location['y'] = location['y'] + 1
  66.         end
  67.     end
  68.     write("reached target Y-Axis ! \n")
  69. else
  70.     write("already on target Y-Axis \n")
  71. end
  72.  
  73. --> Z-Axis
  74. if(direction["z"] == 0) then -- TURN TO NORTH
  75.     if(direction["x"] == 1)
  76.     then -- turn south
  77.         turtle.turnLeft()
  78.     else -- turn north? XD
  79.         turtle.turnRight()
  80.     end
  81.     direction["z"] = -1
  82.     direction["x"] = 0
  83.     write("turned to Z-Axis \n")
  84. end
  85.  
  86. write("checking Z-Axis ... \n")
  87. if(location['z'] ~= pointA['z']) -- is on target?
  88. then
  89.     while(location['z'] ~= pointA['z']) -- while isn't on target
  90.     do
  91.         if(location['z'] > pointA['z']) -- if target is north
  92.         then -- go forward
  93.             if(direction['z'] == -1) -- make sure to face north
  94.             then
  95.                 if(turtle.forward() == false) then
  96.                     write("removing obstacle... \n")
  97.                     turtle.dig()
  98.                     turtle.forward()
  99.                 end
  100.                 write("moved forward... \n")
  101.                 location['z'] = location['z'] - 1
  102.             else -- turn 18
  103.                 turtle.turnRight()
  104.                 turtle.turnRight()
  105.                 direction["z"] = -1
  106.                 write("adjusted direction... \n")
  107.             end
  108.         else -- go back
  109.             if(direction['z'] == 1) -- make sure to face south
  110.             then
  111.                 if(turtle.forward() == false) then
  112.                     write("removing obstacle... \n")
  113.                     turtle.dig()
  114.                     turtle.forward()
  115.                 end
  116.                 write("moved forward... \n")
  117.                 location['z'] = location['z'] + 1
  118.             else
  119.                 -- turn 180
  120.                 turtle.turnRight()
  121.                 turtle.turnRight()
  122.                 direction["z"] = 1
  123.                 write("adjusted direction... \n")
  124.             end
  125.         end
  126.     end
  127.     write("reached target Z-Axis ! \n")
  128. else
  129.     write("already on target Z-Axis \n")
  130. end
  131.  
  132. --> X-Axis
  133. if(direction["x"] == 0) --
  134. then
  135.     if(direction["z"] == 1)
  136.     then -- turn
  137.         turtle.turnRight()
  138.     else -- turn  XD
  139.         turtle.turnLeft()
  140.     end
  141.     direction["x"] = -1
  142.     direction["z"] = 0
  143.     write("turned to X-Axis \n")
  144. end
  145.  
  146. write("checking X-Axis ... \n")
  147. if(location['x'] ~= pointA['x']) -- is on target?
  148. then
  149.     while(location['x'] ~= pointA['x']) -- while isn't on target
  150.     do
  151.         if(location['x'] > pointA['x']) -- if target is north
  152.         then -- go forward
  153.             if(direction['x'] == -1) -- make sure to face north
  154.             then
  155.                 if(turtle.forward() == false) then
  156.                     write("removing obstacle... \n")
  157.                     turtle.dig()
  158.                     turtle.forward()
  159.                 end
  160.                 write("moved forward... \n")
  161.                 location['x'] = location['x'] - 1
  162.             else -- turn 18
  163.                 turtle.turnRight()
  164.                 turtle.turnRight()
  165.                 direction["x"] = -1
  166.                 write("adjusted direction... \n")
  167.             end
  168.         else -- go back
  169.             if(direction['x'] == 1) -- make sure to face south
  170.             then
  171.                 if(turtle.forward() == false) then
  172.                     write("removing obstacle... \n")
  173.                     turtle.dig()
  174.                     turtle.forward()
  175.                 end
  176.                 write("moved forward... \n")
  177.                 location['x'] = location['x'] + 1
  178.             else
  179.                 -- turn 180
  180.                 turtle.turnRight()
  181.                 turtle.turnRight()
  182.                 direction["x"] = 1
  183.                 write("adjusted direction... \n")
  184.             end
  185.         end
  186.     end
  187.     write("reached target X-Axis ! \n")
  188. else
  189.     write("already on target X-Axis \n")
  190. end
  191.  
  192. write("ALLAHU AKBAR ! \n")
  193. -- WIP
  194.  
  195. -- [locate tree row]
  196. -- look at direction of point B
  197. -- move 2 forward
  198. -- turn left
  199. -- move 1 forward
  200.  
  201. -- LOOP !!
  202. -- [chop tree]
  203.     -- dig
  204.     -- forward
  205.     -- digUp & Up till no obstacle (count for every time went up)
  206.     -- go COUNT down
  207.     -- go 1 backwards
  208.     -- replant
  209.     -- turn right
  210.     -- move 3 forward
  211.     -- turn left
  212.     -- check if obstacle ? continue loop : position next row and do again
  213.  
  214. -- [Clear inventory]
  215. -- get to drop off station
  216. for i = 1, 16 do
  217.     turtle.select(i)
  218.     turtle.drop()
  219. end
  220.  
  221. -- [Refueling]
  222. -- * get to refuel station
  223. if turtle.getFuelLevel() < 5000 then
  224.    
  225. end
  226.  
  227. -- wait (for fuel efficiency, so the turtle doesn't waste fuel walking around ungrown trees
  228.  
  229. -- VERSIONING AND OPTIMISATIONS TO CODE
Advertisement
Comments
  • S3mpx
    1 year (edited)
    # text 0.16 KB | 0 0
    1. You shouldn't install this on your turtle as it's custom made for my tree farms, instead look through the commented code and see if you can change it to your liking :3c
Add Comment
Please, Sign In to add comment