Advertisement
Sedrowow

FancyQuarry

May 1st, 2025 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.32 KB | None | 0 0
  1. local log_file = "log.txt"
  2. local options_file = "flex_options.cfg"
  3. os.loadAPI("flex.lua")
  4. os.loadAPI("dig.lua")
  5. local modem_channel = 6464
  6. -- local received_command = nil -- Remove if not needed for status only
  7.  
  8. dig.doBlacklist() -- Avoid Protected Blocks
  9. dig.doAttack() -- Attack entities that block the way
  10. dig.setFuelSlot(1)
  11. dig.setBlockSlot(2)
  12. local world_height = 384
  13.  
  14. if fs.exists(options_file) then
  15.  local file = fs.open("flex_options.cfg", "r")
  16.  local line = file.readLine()
  17.  while line ~= nil do
  18.   if string.find(line, "modem_channel=") == 1 then
  19.    modem_channel = tonumber( string.sub(
  20.          line, 15, string.len(line) ) )
  21.    break
  22.   end --if
  23.   line = file.readLine()
  24.  end --while
  25.  file.close()
  26. end --if
  27. -- Add debug prints around modem initialization
  28. print("DEBUG: Attempting to initialize modem.")
  29. local modem -- Make sure modem is declared here, outside of any function
  30. local hasModem = false
  31. local p = flex.getPeripheral("modem")
  32. if #p > 0 then
  33.     print("DEBUG: Modem peripheral found: " .. tostring(p[1]))
  34.     hasModem = true
  35.     modem = peripheral.wrap(p[1])
  36.     -- No need to open modem if only using modem.transmit for broadcast on a specific channel
  37.     print("DEBUG: Modem peripheral wrapped. Will attempt to transmit status on channel 6465.")
  38. else
  39.     print("DEBUG: No modem peripheral found during initialization. Status updates disabled.")
  40.     -- The script can still run without a modem, but status updates won't work.
  41. end
  42.  
  43. -- ... (modemListener coroutine and related removed if only status is needed) ...
  44.  
  45.  
  46. local args = {...}
  47. if #args == 0 then
  48.  flex.printColors(
  49.    "quarry <length> [width] [depth]\n"..
  50.    "[skip <layers>] [dump] [nolava] [nether]",
  51.    colors.lightBlue)
  52.  return
  53. end --if
  54.  
  55.  
  56. local reloaded = false
  57. if dig.saveExists() then
  58.  reloaded = true
  59.  dig.loadCoords()
  60. end --if
  61. dig.makeStartup("quarry",args)
  62.  
  63.  
  64. local zmax = tonumber(args[1])
  65. local xmax = tonumber(args[2]) or zmax
  66. local depth = world_height-1
  67. if tonumber(args[2]) ~= nil then
  68.  depth = tonumber(args[3]) or depth
  69. end --if
  70. local ymin = -depth --(1-depth)
  71.  
  72. if xmax == nil or zmax == nil then
  73.  flex.send("Invalid dimensions,",colors.red)
  74.  shell.run("rm startup.lua")
  75.  return
  76. end --if
  77.  
  78.  
  79. local x
  80. local skip = 0 -- Initialized to 0
  81. local lava = true
  82. local dodumps = false
  83.  
  84. for x=1,#args do
  85.  if args[x] == "dump" then
  86.   dodumps = true
  87.  elseif args[x] == "nolava" then
  88.   lava = false
  89.  elseif args[x] == "nether" then
  90.   dig.setBlockStacks(4)
  91.  end --if
  92.  
  93.  if args[x] == "skip" then
  94.   local skip_value = tonumber(args[x+1]) -- Use a temporary variable
  95.   if skip_value == nil then
  96.    flex.printColors("Please specify skip depth",
  97.      colors.red)
  98.    dig.saveClear()
  99.    return -- Script exits
  100.   end --if
  101.   skip = skip_value -- Assign only if it's a number
  102.   if dig.getymin() > -skip then
  103.    dig.setymin(-skip)
  104.   end --if
  105.  end --if
  106. end --for
  107. -- After this loop, if "skip" arg was used with a number, `skip` is that number.
  108. -- If "skip" arg was NOT used, `skip` remains 0.
  109. -- If "skip" arg was used without a number, the script should have returned.
  110.  
  111.  
  112. if not lava then -- Block lava around edges of quarry
  113.  dig.setBlockSlot(0)
  114.  -- Always keep a stack of blocks
  115. end --if
  116.  
  117.  
  118.  
  119.  
  120. ----------------------------------------------
  121. -- |¯¯]|| |||\ || /¯][¯¯][¯¯] /¯\ |\ ||/¯¯\ --
  122. -- | ] ||_||| \ || [  ||  ][ | O || \ |\_¯\ --
  123. -- ||   \__||| \| \_] || [__] \_/ || \|\__/ --
  124. ----------------------------------------------
  125.  
  126. local location
  127. local function gotoBase()
  128.  local x = dig.getxlast()
  129.  location = dig.location()
  130.  -- skip is used here
  131.  if dig.gety() < -skip then dig.up() end
  132.  dig.gotox(0)
  133.  dig.gotoz(0)
  134.  dig.gotor(180)
  135.  dig.gotoy(0)
  136.  dig.gotox(0)
  137.  dig.setxlast(x)
  138.  dig.gotoz(0)
  139.  dig.gotor(180)
  140.  return location
  141. end --function
  142.  
  143. local function returnFromBase(loc)
  144.  local loc = loc or location
  145.  local x = dig.getxlast()
  146.  dig.gotor(0)
  147.  checkFuel()
  148.  -- skip is used here
  149.  dig.gotoy(math.min(loc[2]+1,-skip))
  150.  checkFuel()
  151.  dig.gotoz(loc[3])
  152.  checkFuel()
  153.  dig.gotox(loc[1])
  154.  dig.setxlast(x) -- Important for restoring
  155.  checkFuel()
  156.  dig.gotor(loc[4])
  157.  checkFuel()
  158.  dig.gotoy(loc[2])
  159. end --function
  160.  
  161.  
  162. local function checkHalt()
  163.  -- Remote control halt via modem is removed (assuming for status only)
  164.  -- Check for redstone signal from above
  165.  if not rs.getInput("top") then
  166.   return
  167.  end --if
  168.  -- skip is used here
  169.  if dig.gety() == -skip then -- Check against skip depth
  170.   return
  171.  end --if
  172.  if dig.gety() == 0 then -- Check against surface
  173.   return
  174.  end --if
  175.  
  176.  
  177.  local loc,x
  178.  -- Manual halt; redstone signal from above
  179.  flex.send("Manual halt initiated (Redstone)", colors.orange)
  180.  flex.printColors("Press ENTER to resume mining\n"
  181.    .."or SPACE to return to base",
  182.    colors.pink)
  183.  
  184.  while true do
  185.   x = flex.getKey()
  186.   if x == keys.enter then return end
  187.   if x == keys.space then break end
  188.  end --while
  189.  
  190.  flex.send("Returning to base", colors.yellow)
  191.  loc = gotoBase()
  192.  print(" ")
  193.  flex.printColors("Press ENTER to resume mining",
  194.    colors.pink)
  195.  while flex.getKey() ~= keys.enter do
  196.   sleep(1)
  197.  end --while
  198.  
  199.  if dodumps then dig.doDumpDown() end
  200.  dig.dropNotFuel()
  201.  flex.send("Resuming quarry",colors.yellow)
  202.  returnFromBase(loc)
  203.  
  204. end --function
  205.  
  206.  
  207. local function checkInv()
  208.  if turtle.getItemCount(16) > 0 then
  209.  
  210.   if dodumps then
  211.    dig.right(2)
  212.    dig.doDump()
  213.    dig.left(2)
  214.   end --if
  215.  
  216.   if turtle.getItemCount(14) > 0 then
  217.    local loc = gotoBase()
  218.    dig.dropNotFuel()
  219.    returnFromBase(loc)
  220.   end --if
  221.  
  222.  end --if
  223. end --function
  224.  
  225.  
  226. function checkFuel()
  227.  local a = turtle.getFuelLevel()
  228.  -- This fuel estimate is very basic, you might need to adjust it
  229.  -- local b = ( zmax + xmax + math.abs(dig.gety() - ymin) ) * 2 -- Original basic fuel estimate
  230.  local c = true
  231.  
  232.  -- More detailed fuel estimate based on remaining blocks
  233.  local total_quarry_blocks = xmax * zmax * (dig.getymax() - dig.getymin() + 1) -- Assuming ymax is start y
  234.  local current_dug_blocks = dig.getdug()
  235.  local estimated_remaining_blocks = total_quarry_blocks - current_dug_blocks
  236.  -- Rough estimate of fuel needed per block (adjust based on your setup)
  237.  local fuel_per_block = 0.05 -- Example: needs calibration
  238.  local estimated_fuel_needed = estimated_remaining_blocks * fuel_per_block
  239.  
  240.  -- Use a more robust fuel check based on estimated needs
  241.  -- Only check if estimated_fuel_needed is a valid number (it should be if math is correct)
  242.  if type(estimated_fuel_needed) == 'number' and a < estimated_fuel_needed * 1.2 then -- Check if current fuel is less than 120% of estimated needed
  243.      flex.send("Fuel low (Estimated needed: "..tostring(math.ceil(estimated_fuel_needed)).."), returning to surface", colors.yellow)
  244.      local loc = gotoBase()
  245.      turtle.select(1)
  246.      if dodumps then dig.doDumpDown() end
  247.      while turtle.suckUp() do sleep(0) end
  248.      dig.dropNotFuel()
  249.      -- Ensure refuel amount is not nil or non-positive
  250.      local refuel_amount = estimated_fuel_needed * 1.5
  251.      if type(refuel_amount) == 'number' and refuel_amount > 0 then
  252.         dig.refuel(refuel_amount) -- Refuel to 150% of estimated needed
  253.      else
  254.         dig.refuel(1000) -- Fallback refuel amount
  255.      end
  256.      flex.send("Fuel acquired! ("..tostring(turtle.getFuelLevel()).." fuel)", colors.lightBlue)
  257.      returnFromBase(loc)
  258.  end
  259.  -- ADDED MISSING `end` FOR checkFuel
  260. end --function checkFuel()
  261.  
  262.  
  263. -- Add this function to gather and send status (DEFINED OUTSIDE any function)
  264. local function sendStatus()
  265.     -- Gather status data
  266.     local total_quarry_blocks = xmax * zmax * (dig.getymax() - dig.getymin() + 1) -- Assuming ymax is start y
  267.     local current_dug_blocks = dig.getdug()
  268.     local estimated_remaining_blocks = total_quarry_blocks - current_dug_blocks
  269.     local estimated_time_display = "Calculating..."
  270.     -- Only calculate estimated time if remaining blocks is a valid number > 0
  271.     if type(estimated_remaining_blocks) == 'number' and estimated_remaining_blocks > 0 then
  272.         local avg_blocks_per_second = 0.8 -- Calibrate this value
  273.         local estimated_time_seconds = estimated_remaining_blocks / avg_blocks_per_second
  274.         local hours = math.floor(estimated_time_seconds / 3600)
  275.         local minutes = math.floor((estimated_time_seconds % 3600) / 60)
  276.         local seconds = math.floor(estimated_time_seconds % 60)
  277.         estimated_time_display = string.format("%02d:%02d:%02d", hours, minutes, seconds)
  278.     end
  279.  
  280.     -- Get inventory summary (basic example)
  281.     local inventory_summary = {}
  282.     for slot = 1, 16 do
  283.         local item = turtle.getItemDetail(slot)
  284.         if item then
  285.             table.insert(inventory_summary, { name = item.name, count = item.count })
  286.         end
  287.     end
  288.     -- Ensure 'done' is accessible or determine mining state differently if 'done' is local to main loop
  289.     local is_mining_status = false
  290.     -- Assuming 'done' is a boolean defined in the main loop's scope
  291.     if type(done) == "boolean" then
  292.        is_mining_status = not done and not dig.isStuck()
  293.     else
  294.        -- If 'done' is not globally available, assume mining is true unless stuck
  295.        is_mining_status = not dig.isStuck()
  296.     end
  297.  
  298.     local status_message = {
  299.         type = "status_update", -- Indicate this is a status update
  300.         id = os.getComputerID(), -- Include turtle ID
  301.         label = os.getComputerLabel(), -- Include turtle label
  302.         fuel = turtle.getFuelLevel(),
  303.         position = { x = dig.getx(), y = dig.gety(), z = dig.getz(), r = dig.getr() },
  304.         is_mining = is_mining_status, -- Reflect actual mining state
  305.         estimated_time = estimated_time_display,
  306.         dug_blocks = dig.getdug(),
  307.         inventory_summary = inventory_summary -- Include basic inventory summary
  308.     }
  309.  
  310.     -- Send the status message on a specific channel (e.g., 6465)
  311.     local status_channel = modem_channel -- Channel for status updates
  312.     if modem then -- Check if modem peripheral is available
  313.         print("DEBUG: Attempting to transmit status on channel " .. status_channel) -- NEW DEBUG PRINT before transmit
  314.         -- Transmit from status_channel to status_channel for a broadcast on 6465
  315.         modem.transmit(status_channel, status_channel, status_message)
  316.         print("DEBUG: Status update sent on channel " .. status_channel) -- Optional debug
  317.     else
  318.         print("DEBUG: sendStatus called but modem is nil. Cannot transmit.") -- NEW DEBUG PRINT if modem is nil
  319.     end
  320. end
  321.  
  322. -- Variables for status sending interval (DEFINED OUTSIDE any function)
  323. local last_status_sent_time = os.epoch("utc") or 0 -- Initialize defensively
  324. local status_send_interval = 10 * 1000 -- Send status every 10 seconds (in milliseconds)
  325.  
  326.  
  327.  
  328. local dug = dig.getdug()
  329. local ydeep = dig.getymin()
  330.  
  331. local function checkProgress()
  332.     -- print("DEBUG: checkProgress called.")
  333.  
  334.     -- Print detailed progress information (keep this for console)
  335.     term.setCursorPos(1,1)
  336.     term.clearLine()
  337.     flex.printColors("Pos: X="..tostring(dig.getx())..
  338.                        ", Y="..tostring(dig.gety())..
  339.                        ", Z="..tostring(dig.getz())..
  340.                        ", Rot="..tostring(dig.getr()%360), colors.white)
  341.  
  342.     term.setCursorPos(1,2)
  343.     term.clearLine()
  344.     flex.printColors("Fuel: "..tostring(turtle.getFuelLevel()), colors.orange)
  345.  
  346.     term.setCursorPos(1,3)
  347.     term.clearLine()
  348.     flex.printColors("Dug: "..tostring(dig.getdug()).." blocks", colors.lightBlue)
  349.  
  350.     term.setCursorPos(1,4)
  351.     term.clearLine()
  352.     flex.printColors("Depth: "..tostring(-dig.gety()).."m / "..tostring(-ymin).."m", colors.green)
  353.  
  354.     -- Use os.epoch("utc") for timing comparison in milliseconds
  355.     local current_epoch_time_ms = os.epoch("utc") or 0 -- Get current epoch time in milliseconds
  356.     local time_difference_ms = current_epoch_time_ms - (last_status_sent_time or 0) -- Calculate difference in milliseconds
  357.  
  358.     -- print("DEBUG: Status check timing (Epoch UTC) - os.epoch(): "..tostring(current_epoch_time_ms)..", last_status_sent_time: "..tostring(last_status_sent_time)..", difference: "..tostring(time_difference_ms)..", interval (ms): "..tostring(status_send_interval))
  359.  
  360.     -- Send status update periodically using os.epoch() for the check
  361.     if type(current_epoch_time_ms) == 'number' and time_difference_ms >= status_send_interval then
  362.         -- print("DEBUG: Status send interval met (Epoch UTC). Calling sendStatus.")
  363.         sendStatus()
  364.         last_status_sent_time = current_epoch_time_ms -- Update last sent time using epoch time in milliseconds
  365.     -- else
  366.         -- print("DEBUG: Status send interval not met (Epoch UTC).")
  367.     end
  368.  
  369.     -- Removed original progress prints
  370.     local a = 1000 --report every <a> blocks dug
  371.     local b = 5 --report every <b> meters descended
  372.     if math.floor(dug/a) < math.floor(dig.getdug()/a) then
  373.      flex.send("Dug "..tostring(dig.getdug())..
  374.        " blocks",colors.lightBlue)
  375.     end --if
  376.     if math.floor(-ydeep/b) < math.floor(-dig.gety()/b) then
  377.      flex.send("Descended "..tostring(-dig.gety())..
  378.        "m",colors.green)
  379.     end --if
  380.     dug = dig.getdug()
  381.     ydeep = dig.gety()
  382.     -- checkReceivedCommand() -- Remove if not doing remote control
  383. end --function checkProgress()
  384.  
  385. -- ... (processCommand and checkReceivedCommand removed if not doing remote control) ...
  386.  
  387.  
  388. local newlayer = false
  389. function checkNewLayer()
  390.  if newlayer then
  391.   -- This encodes whether or not the turtle has
  392.   --  started a new layer if at the edge
  393.   dig.setr(dig.getr() % 360 + 360)
  394.  else
  395.   dig.setr(dig.getr() % 360)
  396.  end --if
  397. end --function
  398.  
  399.  
  400.  
  401. function lavax()
  402.   if dig.getx() == 0 then
  403.    dig.gotor(270)
  404.    checkNewLayer()
  405.    dig.blockLava()
  406.   elseif dig.getx() == xmax-1 then
  407.    dig.gotor(90)
  408.    checkNewLayer()
  409.    dig.blockLava()
  410.   end --if/else
  411. end --function
  412.  
  413. function lavaz()
  414.   if dig.getz() == 0 then
  415.    dig.gotor(180)
  416.    checkNewLayer()
  417.    dig.blockLava()
  418.   elseif dig.getz() == zmax-1 then
  419.    dig.gotor(0)
  420.    checkNewLayer()
  421.    dig.blockLava()
  422.   end --if/else
  423. end --function
  424.  
  425. function checkLava(n)
  426.  if lava then
  427.   local x
  428.   local r = dig.getr() % 360
  429.  
  430.   if r == 0 or r == 180 then
  431.    lavaz()
  432.    lavax()
  433.   else
  434.    lavax()
  435.    lavaz()
  436.   end --if/else
  437.  
  438.   -- skip is used here
  439.   if dig.gety() == -skip then
  440.    dig.blockLavaUp()
  441.   end --if
  442.  
  443.   -- skip is used here
  444.   if dig.getx() == 0 and dig.getz() == 0
  445.      and dig.gety() > -skip then
  446.    for x=1,4 do
  447.     dig.blockLava()
  448.     dig.left()
  449.     checkNewLayer()
  450.    end --for
  451.   end --if
  452.  
  453.   if n ~= 0 then
  454.    dig.gotor(r)
  455.    checkNewLayer()
  456.   end --if
  457.  
  458.  end --if
  459. end --function
  460.  
  461.  
  462. local function checkAll(n)
  463.  checkNewLayer()
  464.  checkProgress() -- checkProgress calls status send logic
  465.  checkFuel()
  466.  checkInv()
  467.  checkHalt() -- checkHalt also uses skip
  468.  checkLava(n)
  469.  dig.checkBlocks()
  470.  checkNewLayer()
  471. end --function
  472.  
  473.  
  474.  
  475. ---------------------------------------
  476. --      |\/|  /\  [¯¯] |\ ||         --
  477. --      |  | |  |  ][  | \ |         --
  478. --      |||| |||| [__] || \|         --
  479. ---------------------------------------
  480. -- |¯\ |¯\  /¯\   /¯¯] |¯\  /\  |\/| --
  481. -- | / | / | O | | [¯| | / |  | |  | --
  482. -- ||  | \  \_/   \__| | \ |||| |||| --
  483. ---------------------------------------
  484.  
  485. local a,b,c,x,y,z,r,loc
  486. local xdir, zdir = 1, 1
  487.  
  488. turtle.select(1)
  489. if reloaded then
  490.  
  491.  flex.send("Resuming "..tostring(zmax).."x"
  492.    ..tostring(xmax).." quarry",colors.yellow)
  493.  
  494.  if dig.gety()==dig.getymin() and dig.gety()~=0 then
  495.   zdir = dig.getzlast()
  496.   if zdir == 0 then zdir = 1 end
  497.   xdir = dig.getxlast()
  498.   if xdir == 0 then xdir = 1 end
  499.  
  500.   if dig.getr() >= 360 then
  501.    -- This encodes whether or not the turtle has
  502.    --  started a new layer if at the edge
  503.    xdir = -xdir
  504.    newlayer = true
  505.   end --if
  506.  
  507.  else
  508.   gotoBase()
  509.   if dodumps then dig.doDumpDown() end
  510.   dig.dropNotFuel()
  511.   dig.gotor(0)
  512.   checkFuel()
  513.   -- skip is used here
  514.   dig.gotoy(math.min(dig.getymin(),-skip)) -- Corrected: go to min y or skip depth
  515.  end --if
  516.  
  517. else
  518.  
  519.  flex.send("Starting "..tostring(zmax).."x"
  520.    ..tostring(xmax).." quarry",colors.yellow)
  521.  
  522.  -- skip is used here
  523.  if skip > 0 then
  524.   flex.send("Skipping "..tostring(skip)
  525.     .."m", colors.lightGray)
  526.  end --if
  527.  
  528.  if depth < world_height-1 then
  529.   flex.send("Going "..tostring(-ymin)
  530.     .."m deep", colors.lightGray)
  531.  else
  532.   flex.send("To bedrock!",colors.lightGray)
  533.  end --if/else
  534.  
  535. end --if/else
  536.  
  537.  
  538. -- Immediately before the descent loop
  539. print("DEBUG: Before descent loop. dig.gety(): " .. tostring(dig.gety()) .. ", -skip: " .. tostring(-skip)) -- Debug print kept
  540. -- ERROR IS HERE: while dig.gety() > -skip do
  541. while dig.gety() > -skip do
  542.  checkFuel()
  543.  dig.down()
  544.  
  545.  if dig.isStuck() then
  546.   flex.send("Co-ordinates lost! Shutting down",
  547.     colors.red)
  548.   --rs.delete("startup.lua")
  549.   return
  550.  end --if
  551.  -- checkReceivedCommand() -- Remove if not doing remote control
  552. end --while
  553. print("DEBUG: After descent loop.") -- Debug print kept
  554.  
  555.  
  556. --------------------------
  557. -- |\/|  /\  [¯¯] |\ || --
  558. -- |  | |  |  ][  | \ | --
  559. -- |||| |||| [__] || \| --
  560. --------------------------
  561. -- ||    /¯\   /¯\  |¯\ --
  562. -- ||_  | O | | O | | / --
  563. -- |__]  \_/   \_/  ||  --
  564. --------------------------
  565.  
  566. local done = false -- 'done' is local to this main loop
  567. while not done and not dig.isStuck() do
  568.  -- checkReceivedCommand() -- Remove if not doing remote control
  569.  turtle.select(1)
  570.  
  571.  while not done do
  572.   -- checkReceivedCommand() -- Remove if not doing remote control
  573.  
  574.   checkAll(0) -- checkAll calls checkProgress, which calls status send
  575.  
  576.   if dig.getz()<=0 and zdir==-1 then break end
  577.   if dig.getz()>=zmax-1 and zdir==1 then break end
  578.  
  579.   if zdir == 1 then dig.gotor(0)
  580.   elseif zdir == -1 then dig.gotor(180)
  581.   end --if/else
  582.   checkNewLayer()
  583.  
  584.   dig.fwd()
  585.  
  586.   if dig.isStuck() then
  587.    done = true
  588.   end --if
  589.  
  590.  end --while (z loop)
  591.  
  592.  if done then break end
  593.  
  594.  zdir = -zdir
  595.  newlayer = false
  596.  
  597.  -- Add print at the start of a new row
  598.  flex.printColors("Starting new row at X="..tostring(dig.getx()).." Z="..tostring(dig.getz()).." Layer="..tostring(-dig.gety()), colors.gray)
  599.  
  600.  if dig.getx()<=0 and xdir==-1 then
  601.   newlayer = true
  602.  elseif dig.getx()>=xmax-1 and xdir==1 then
  603.   newlayer = true
  604.  else
  605.   checkAll(0) -- checkAll calls checkProgress, which calls status send
  606.   dig.gotox(dig.getx()+xdir)
  607.  end --if/else
  608.  
  609.  if newlayer and not dig.isStuck() then
  610.   xdir = -xdir
  611.   if dig.getymin() <= ymin then break end
  612.   checkAll(0) -- checkAll calls checkProgress, which calls status send
  613.   dig.down()
  614.   -- Add print at the start of a new layer
  615.   flex.printColors("Starting new layer at Y="..tostring(dig.gety()), colors.purple)
  616.  end --if
  617.  
  618. end --while (cuboid dig loop)
  619.  
  620.  
  621. flex.send("Digging completed, returning to surface",
  622.   colors.yellow)
  623. gotoBase()
  624.  
  625. flex.send("Descended "..tostring(-dig.getymin())..
  626.     "m total",colors.green)
  627. flex.send("Dug "..tostring(dig.getdug())..
  628.     " blocks total",colors.lightBlue)
  629.  
  630. for x=1,16 do
  631.  if dig.isBuildingBlock(x) then
  632.   turtle.select(x)
  633.   dig.placeDown()
  634.   break
  635.  end --if
  636. end --for
  637. turtle.select(1)
  638.  
  639. if dodumps then
  640.  dig.gotor(0)
  641.  dig.doDump()
  642.  dig.gotor(180)
  643. end
  644. dig.dropNotFuel()
  645. dig.gotor(0)
  646.  
  647. dig.clearSave()
  648. flex.modemOff() -- Keep this to close the modem even if not used for remote control
  649. os.unloadAPI("dig.lua")
  650. os.unloadAPI("flex.lua")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement