BeastmodeJD

turtleMiner_XxX

Sep 13th, 2021 (edited)
1,584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.20 KB | None | 0 0
  1. local shouldFuel = false
  2. local receivePort = 62101
  3. local sendPort = 62100
  4. local modem = peripheral.wrap("left")
  5. local forbidItems = {
  6.     "lavastone",
  7.     "cobblestone",
  8.     "diorite",
  9.     "dirt",
  10.     "gravel",
  11.     "granite",
  12.     "andesite",
  13.     "scoria",
  14.     "marble"
  15. }
  16. function termReset()
  17.     term.clear()
  18.     term.setCursorPos(1,1)
  19. end
  20.  
  21. function refu()
  22.     if not shouldFuel then
  23.         return
  24.     end
  25.     turtle.select(1)
  26.     if (turtle.getItemCount() < 1) then
  27.         term.clear()
  28.         print("No fuel!")
  29.         return
  30.     end
  31.     if not (turtle.refuel()) then
  32.         term.clear()
  33.         print("Refuel Error!")
  34.         return
  35.     end
  36. end
  37.  
  38. function digRound(right)
  39.     while (turtle.detect()) do
  40.         turtle.dig()
  41.     end
  42.     if (right) then
  43.         turtle.turnRight()
  44.         turtle.forward()
  45.         turtle.turnLeft()
  46.     else
  47.         turtle.turnLeft()
  48.         turtle.forward()
  49.         turtle.turnRight()
  50.     end
  51. end
  52.  
  53. function digRoundSolo()
  54.     while (turtle.detect()) do
  55.         turtle.dig()
  56.     end
  57. end
  58.  
  59. function report(done)
  60.     local x, y, z = gps.locate()
  61.     if not x then
  62.         print("Can't GPS")
  63.         return
  64.     end
  65.     local transmitData = {}
  66.     transmitData["x"] = x
  67.     transmitData["y"] = y
  68.     transmitData["z"] = z
  69.     transmitData["label"] = os.getComputerLabel()
  70.     transmitData["id"] = os.getComputerID()
  71.     transmitData["done"] = done
  72.     modem.transmit(sendPort, receivePort, transmitData)
  73. end
  74.  
  75. local limitForward
  76. while not (tonumber(limitForward)) do
  77.     termReset()
  78.     print("How far would you like the turtle to dig in forward blocks? Must be number.");
  79.     limitForward = read()
  80. end
  81. limitForward = math.floor(tonumber(limitForward))
  82. local limitUp
  83. while not (tonumber(limitUp)) do
  84.     termReset()
  85.     print("How far would you like the turtle to dig in vertical blocks? Must be number.");
  86.     limitUp = read()
  87. end
  88. limitUp = math.floor(tonumber(limitUp))
  89. local limtSide
  90. while not (tonumber(limtSide)) do
  91.     termReset()
  92.     print("How far would you like the turtle to dig in horizontal blocks? Must be number.");
  93.     limtSide = read()
  94. end
  95. limtSide = math.floor(tonumber(limtSide))
  96. local temp = 5
  97. termReset()
  98. print("Make sure turtle is in the bottom left of grid")
  99. while (temp > 0) do
  100.     sleep(1)
  101.     temp = temp - 1
  102. end
  103. termReset()
  104. print("running " .. limtSide .."x".. limitUp .." mine for " .. limitForward .. " blocks")
  105. local path = 0
  106. refu()
  107. while (path < limitForward) do
  108.     if (turtle.getFuelLevel() < 1) then
  109.         refu()
  110.     end
  111.     local doneUp = 1
  112.     while (doneUp < limitUp) do
  113.         turtle.up()
  114.         doneUp = doneUp + 1
  115.     end
  116.     local doneSide = 0
  117.     doneUp = 1
  118.     while (doneUp <= limitUp) do
  119.         doneSide = 0
  120.         while (doneSide < limtSide) do
  121.             if (doneUp % 2 ~= 0) then
  122.                 if (doneSide >= limtSide - 1) then
  123.                     digRoundSolo()
  124.                 else
  125.                     digRound(true)
  126.                 end
  127.                 doneSide = doneSide + 1
  128.             else
  129.                 if (doneSide >= limtSide - 1) then
  130.                     digRoundSolo()
  131.                 else
  132.                     digRound(false)
  133.                 end
  134.                 doneSide = doneSide + 1
  135.             end
  136.         end
  137.         turtle.down()
  138.         doneUp = doneUp + 1
  139.     end
  140.     turtle.forward()
  141.     if (limitUp % 2 ~= 0) then
  142.         doneSide = 0
  143.         turtle.turnLeft()
  144.         while (doneSide < limtSide) do
  145.             turtle.forward()
  146.              doneSide = doneSide + 1
  147.         end
  148.         turtle.turnRight()
  149.     end
  150.     local slot = 1
  151.     while (slot <= 16) do
  152.         turtle.select(slot)
  153.         local data = turtle.getItemDetail()
  154.         for i, v in pairs(forbidItems) do
  155.             if (data) then
  156.                 if string.find(data.name, v) then
  157.                     turtle.dropDown(turtle.getItemCount())
  158.                 end
  159.             end
  160.         end
  161.         slot = slot + 1
  162.     end
  163.     path = path + 1
  164.     report(false)
  165. end
  166. termReset()
  167. print("Done! Returning Home")
  168. turtle.turnRight()
  169. turtle.turnRight()
  170. while (path > 0) do
  171.     turtle.forward()
  172.     path = path - 1
  173. end
  174. termReset()
  175. print("Done!")
  176. report(true)
Advertisement
Add Comment
Please, Sign In to add comment