S3mpx

test

Nov 6th, 2023 (edited)
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.39 KB | None | 0 0
  1. -- pastebin get LbxkYAYh tree.lua
  2.  
  3. -- [SETTINGS]
  4. -- tree farm perimeter
  5. pointA = { -- CURRENTLY STORED: SMP with da Boys
  6.     ['x'] = -1002,
  7.     ['z'] = 702,
  8.     ['y'] = 91
  9. }
  10. pointB = {
  11.     ['x'] = -1002,
  12.     ['z'] = 706,
  13.     ['y'] = 91
  14. }
  15. -- specifics
  16. treeRows = 1
  17. -- turtle
  18. location = {
  19.     ['x'] = -998,
  20.     ['z'] = 704,
  21.     ['y'] = 91
  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. -- locate long side
  197.  
  198. -- NORTH OR SOUTH
  199. if(pointA["z"] > pointB["z"])
  200. then
  201.     lenZ = pointA["z"] - pointB["z"]
  202.     tarDir["z"] = -1
  203. else
  204.     lenZ = pointB["z"] - pointA["z"]
  205.     tarDir["z"] = 1
  206. end
  207.    
  208. -- WEST OR EAST
  209. if(pointA["x"] > pointB["x"])
  210. then
  211.     lenX = pointA["x"] - pointB["x"]
  212.     tarDir["x"] = -1
  213. else
  214.     lenX = pointB["x"] - pointA["x"]
  215.     tarDir["X"] = 1
  216. end
  217.    
  218. if(LenZ > lenX)
  219. then
  220.     -- change dir
  221. else
  222.     -- change dir
  223. end
  224. -- look at direction of point B
  225. -- move 2 forward
  226. -- turn left
  227. -- move 1 forward
  228.  
  229. -- LOOP !!
  230. -- [chop tree]
  231.     -- dig
  232.     -- forward
  233.     -- digUp & Up till no obstacle (count for every time went up)
  234.     -- go COUNT down
  235.     -- go 1 backwards
  236.     -- replant
  237.     -- turn right
  238.     -- move 3 forward
  239.     -- turn left
  240.     -- check if obstacle ? continue loop : position next row and do again
  241.  
  242. -- [Clear inventory]
  243. -- get to drop off station
  244. for i = 1, 16 do
  245.     turtle.select(i)
  246.     turtle.drop()
  247. end
  248.  
  249. -- [Refueling]
  250. -- * get to refuel station
  251. if turtle.getFuelLevel() < 5000 then
  252.    
  253. end
  254.  
  255. -- wait (for fuel efficiency, so the turtle doesn't waste fuel walking around ungrown trees
  256.  
  257. -- VERSIONING AND OPTIMISATIONS TO CODE
Advertisement
Add Comment
Please, Sign In to add comment