CaptainSpaceCat

Turtle Adventurer

Jun 23rd, 2021 (edited)
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. -- Turtle Adventurer
  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.  
  10. local anchorSlot = 1
  11. local receiverSlot = 2
  12. local tArgs = {...}
  13.  
  14. local function forward(num)
  15.     num = num or 1
  16.     for i = 1, num do
  17.         if turtle.detect() then
  18.             turtle.dig()
  19.         end
  20.         turtle.forward()
  21.     end
  22. end
  23.  
  24. local function up(num)
  25.     num = num or 1
  26.     for i = 1, num do
  27.         if turtle.detectUp() then
  28.             turtle.digUp()
  29.         end
  30.         turtle.up()
  31.     end
  32. end
  33.  
  34. local function down(num)
  35.     num = num or 1
  36.     for i = 1, num do
  37.         if turtle.detectDown() then
  38.             turtle.digDown()
  39.         end
  40.         turtle.down()
  41.     end
  42. end
  43.  
  44. local function left(num)
  45.     num = num or 1
  46.     for i = 1, num do
  47.         turtle.turnLeft()
  48.     end
  49. end
  50.  
  51. local function right(num)
  52.     num = num or 1
  53.     for i = 1, num do
  54.         turtle.turnRight()
  55.     end
  56. end
  57.  
  58. local function placeAnchor()
  59.     turtle.dig()
  60.     turtle.select(anchorSlot)
  61.     turtle.place()
  62. end
  63.  
  64. local function placeAnchorUp()
  65.     turtle.digUp()
  66.     turtle.select(anchorSlot)
  67.     turtle.placeUp()
  68. end
  69.  
  70. local function pickupAnchor()
  71.     turtle.select(anchorSlot)
  72.     turtle.dig()
  73. end
  74.  
  75. local function loop(chunks)
  76.     for i = 1, chunks do
  77.         forward(14)
  78.         placeAnchor()
  79.         placeAnchorUp()
  80.         left(2)
  81.         forward(14)
  82.         pickupAnchor()
  83.         left(2)
  84.         forward(14)
  85.         right()
  86.         forward()
  87.         left()
  88.         forward()
  89.         up()
  90.         left()
  91.         forward()
  92.         left()
  93.         pickupAnchor()
  94.         left(2)
  95.         forward()
  96.         down()
  97.     end
  98. end
  99.  
  100. local function placeReceiver()
  101.     turtle.select(receiverSlot)
  102.     turtle.dig()
  103.     turtle.place()
  104. end
  105.  
  106. local chunks = turtle.getFuelLevel() / 47
  107. print("Adventuring approximately " .. tostring(tArgs[1] or chunks) .. " chunks!")
  108. loop(tArgs[1] or chunks)
  109. placeReceiver()
Add Comment
Please, Sign In to add comment