Advertisement
gridcaster

pathTest.lua

Jun 18th, 2021 (edited)
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. local keepRunning=true
  2. local borderBlock="minecraft:glass"
  3.  
  4. local turnedRightLast=false
  5. local shouldGoDown=false
  6.  
  7.  
  8. local x=0
  9. local y=0
  10. local z=0
  11.  
  12. local function goForward() write("F") return turtle.forward() end
  13. local function turnRight() write("R") turtle.turnRight() end
  14. local function turnLeft() write("L") turtle.turnLeft() end
  15. local function detectBorder() local success, data = turtle.inspect() if success then if data.name == borderBlock then return true else return false end end end
  16. local function detectBorderUp() local success, data = turtle.inspectUp() if success then if data.name == borderBlock then shouldGoDown=true end end end
  17. local function detectDown() local success, data = turtle.inspectDown() if success then return data.name end end
  18. local function suckAll () turtle.suck() turtle.suckDown() turtle.suckUp() end
  19. local function goUp() write("U")  y=y+1 return turtle.up() end
  20. local function goDown() write("D") y=y-1 return  turtle.down() end
  21. local function upOrDown ()
  22.     if detectBorderUp() then
  23.          
  24.     end
  25. end
  26. local function turnAround () turnRight() turnRight() end
  27.  
  28. local function detectCorner()
  29.     -- Look forward
  30.     local borderForward = detectBorder()
  31.     -- Look left
  32.     turnLeft()
  33.     local borderLeft = detectBorder()
  34.     -- turn Right and look
  35.     turnRight()
  36.     local borderRight = detectBorder()
  37.     -- turn back left (so we are looking forward)
  38.     turnLeft()
  39.     if (borderForward and borderLeft) or (borderForward and borderRight) then
  40.         if shouldGoDown then
  41.             goDown()
  42.         else
  43.             goUp()
  44.         end
  45.         turnAround()
  46.     end
  47. end
  48.  
  49.  
  50.  
  51. while keepRunning do
  52.     while not turtle.detect() do
  53.         -- White we didn't detect anything
  54.         goForward()    
  55.     end
  56.     detectCorner()
  57.  
  58. end    
  59.  
  60.  
  61.  
  62. -- -- go forward to border
  63.     -- -- at border turn right
  64.     -- -- try to go forward.  If not forward, and not at top, go up
  65.  
  66.  
  67.  
  68.  
  69.     -- if not goForward() then
  70.     --     if detectBorder() then
  71.     --         write("B")
  72.     --         if not turnedRightLast then
  73.     --             write("rt")
  74.     --             if not uTurnRight() then
  75.     --                 if not detectedTop then
  76.     --                     if not goUp() then
  77.     --                         if detectBorderUp() then
  78.     --                             detectedTop=true
  79.     --                             goDown()
  80.     --                         end
  81.     --                     else
  82.     --                         uTurnRight()
  83.     --                         uTurnRight()
  84.     --                     end
  85.     --                 uTurnLeft()
  86.     --                 else
  87.     --                     goDown()
  88.                    
  89.     --                 end
  90.     --             end
  91.     --         turnedRightLast=true
  92.     --      else
  93.     --             write("lt")
  94.     --             if not uTurnLeft() then
  95.     --                 goUp()
  96.     --                 uTurnRight()
  97.     --             end
  98.     --             turnedRightLast=false
  99.     --      end
  100.     --     else
  101.     --         turtle.dig()
  102.     --         suckAll()
  103.     --     end
  104.     -- end
  105.  
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement