CaptainSpaceCat

Turtle Adventurer V2

Jun 23rd, 2021 (edited)
737
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Turtle Adventurer V2
  2. -- By CaptainSpaceCat
  3. -- This program will send a turtle off into the wilderness to travel in a straight line as far as possible
  4. -- You must equip the turtle with 3 chunk loaders so that it can load the chunk it's in and the next one
  5. -- You should also give it an rftools Matter Receiver so that you can teleport to it once it gets thousands of blocks away!
  6. -- NOTE: you MUST start the turtle ONE BLOCK AWAY from the edge of a chunk, facing INTO the chunk
  7. -- otherwise the chunk loaders won't work properly
  8.  
  9. -- CHANGES
  10. -- Turtle will now log all landmasses it travels over
  11. -- it does this by keeping track of its coordinates and logging chunks where it has to break terrain at least once
  12. -- you should place it one block above sea level for this to work as well as possible
  13. -- you MUST enter its initial coordinates and rotation accurately for this to be useful
  14.  
  15. shell.run("delete travel_log")
  16.  
  17. local anchorSlot = 1
  18. local receiverSlot = 2
  19. local tArgs = {...}
  20. local terrainFlag = false
  21.  
  22. local coords = {}
  23. local chunks = turtle.getFuelLevel() / 48
  24. local function getCoords()
  25.     print("Turtle's X coordinate: ")
  26.     coords.x = tonumber(read())
  27.     print("Turtle's Y coordinate: ")
  28.     coords.y = tonumber(read())
  29.     print("Turtle's Z coordinate: ")
  30.     coords.z = tonumber(read())
  31.     print("Turtle's direction: ")
  32.     print("1 - north")
  33.     print("2 - east")
  34.     print("3 - west")
  35.     print("4 - south")
  36.     coords.f = tonumber(read())
  37.     print("Desired number of chunks to travel:")
  38.     print("(Leave empty to go as far as fuel allows)")
  39.     local c = tonumber(read())
  40.     if not c == nil then
  41.         chunks = c
  42.     end
  43. end
  44.  
  45. local function log(message)
  46.     handle = fs.open("travel_log", "a")
  47.     handle.writeLine(message)
  48.     handle.close()
  49. end
  50.  
  51. local dirTab = {
  52.     {0, -1}, --north
  53.     {1, 0}, --south
  54.     {0, 1}, --east
  55.     {-1, 0} --west
  56. }
  57.  
  58. local function forward(num)
  59.     num = num or 1
  60.     for i = 1, num do
  61.         if turtle.detect() then
  62.             turtle.dig()
  63.             terrianFlag = true
  64.         end
  65.         turtle.forward()
  66.         coords.x = coords.x + dirTab[coords.f][1]
  67.         coords.z = coords.z + dirTab[coords.f][2]
  68.     end
  69. end
  70.  
  71. local function up(num)
  72.     num = num or 1
  73.     for i = 1, num do
  74.         if turtle.detectUp() then
  75.             turtle.digUp()
  76.         end
  77.         turtle.up()
  78.         coords.y = coords.y + 1
  79.     end
  80. end
  81.  
  82. local function down(num)
  83.     num = num or 1
  84.     for i = 1, num do
  85.         if turtle.detectDown() then
  86.             turtle.digDown()
  87.         end
  88.         turtle.down()
  89.         coords.y = coords.y - 1
  90.     end
  91. end
  92.  
  93. local function left(num)
  94.     num = num or 1
  95.     for i = 1, num do
  96.         turtle.turnLeft()
  97.         coords.f = ((coords.f + 2) % 4) + 1
  98.     end
  99. end
  100.  
  101. local function right(num)
  102.     num = num or 1
  103.     for i = 1, num do
  104.         turtle.turnRight()
  105.         coords.f = (coords.f % 4) + 1
  106.     end
  107. end
  108.  
  109. local function placeAnchor()
  110.     turtle.dig()
  111.     turtle.select(anchorSlot)
  112.     turtle.place()
  113. end
  114.  
  115. local function placeAnchorUp()
  116.     turtle.digUp()
  117.     turtle.select(anchorSlot)
  118.     turtle.placeUp()
  119. end
  120.  
  121. local function pickupAnchor()
  122.     turtle.select(anchorSlot)
  123.     turtle.dig()
  124. end
  125.  
  126. local function loop(chunks)
  127.     for i = 1, chunks do
  128.         terrainFlag = false
  129.         forward(14)
  130.         placeAnchor()
  131.         placeAnchorUp()
  132.         left(2)
  133.         forward(14)
  134.         pickupAnchor()
  135.         left(2)
  136.         forward(14)
  137.         right()
  138.         forward()
  139.         left()
  140.         forward()
  141.         up()
  142.         left()
  143.         forward()
  144.         left()
  145.         pickupAnchor()
  146.         left(2)
  147.         forward()
  148.         down()
  149.         if terrainFlag then
  150.             log(tostring(coords.x) .. "|" .. tostring(coords.z))
  151.         end
  152.     end
  153. end
  154.  
  155. local function placeReceiver()
  156.     turtle.select(receiverSlot)
  157.     turtle.dig()
  158.     turtle.place()
  159. end
  160.  
  161. getCoords()
  162. print("Adventuring approximately " .. tostring(chunks) .. " chunks!")
  163. loop(chunks)
  164. placeReceiver()
RAW Paste Data