Advertisement
Guest User

Pathmaker.lua

a guest
Sep 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local startPoint = vector.new(gps.locate()
  2. local lastPoint = vector.new(gps.locate())
  3. local stop = false
  4. local light = true
  5.  
  6. function refuel()
  7.   if(turtle.getFuelLevel() < 100) then
  8.     turtle.select(2)
  9.     turtle.refuel(5)
  10.   end
  11. end
  12.  
  13. function torch()
  14.   turtle.select(1)
  15.   if(turtle.getItemCount() == 1)
  16.     stop = true
  17.   end
  18.   turtle.placeUp()
  19.   light = false
  20. end
  21.  
  22. function clear()
  23.   local i = 3
  24.   while i < 17 do
  25.     turtle.select(i)
  26.     turtle.drop()
  27.     i = i + 1
  28.   end
  29. end
  30.  
  31. function arm()
  32.   for i=1,4 do
  33.     turtle.dig()
  34.     turtle.forward()
  35.   end
  36.   turtle.dig()
  37. end
  38.  
  39. function armExit()
  40.   for i=1,4 do
  41.     turtle.forward()
  42.   end
  43. end
  44.  
  45. function way()
  46.   local i = 0
  47.   if(not(startPoint.x==lastPoint.x)) then
  48.     local length = startPoint.x - lastpoint.x
  49.     if(length<0) then
  50.       length = -1*length
  51.     end
  52.     i = length
  53.   elseif(not(startPoint.z==lastPoint.z)) then
  54.     local length = startPoint.z - lastPoint.z
  55.     if(length<0) then
  56.       length = -1*length
  57.     end
  58.     i = length
  59.   end
  60.   return i
  61. end
  62.  
  63. function move(length)
  64.   for i=1,length do
  65.     turtle.forward()
  66.   end
  67. end
  68.  
  69. do
  70.   coroutine.create(refuel())
  71.   while not stop do
  72.     for i=1,3 do
  73.     for i=1,4 do
  74.       turtle.dig()
  75.       turtle.forward()
  76.       turtle.digUp()
  77.       if(light and i==2) then
  78.         torch()
  79.       elseif(i==2)
  80.         light = true
  81.       end
  82.     end
  83.     turtle.turnLeft()
  84.     turtle.up()
  85.     arm()
  86.     turtle.turnRight()
  87.     turtle.turnRight()
  88.     armExit()
  89.     arm()
  90.     turtle.turnRight()
  91.     turtle.turnRight()
  92.     armExit()
  93.     turtle.turnRight()
  94.     turtle.down()
  95.     lastPoint = vector.new(gps.locate())
  96.     end
  97.     turtle.turnRight()
  98.     turtle.turnRight()
  99.     move(way())
  100.     clear()
  101.     turtle.turnRight()
  102.     turtle.turnRight()
  103.     move(way())
  104.   end  
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement