Advertisement
massacring

VerticalMining

Feb 4th, 2024 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | None | 0 0
  1. local MassaLib = require('MassaMainLib')
  2. local MiningLib = require('MassaMiningTurtleLib')
  3.  
  4. local tags = {}
  5. local ids = {}
  6. local inclusive
  7.  
  8. local function stripMine(direction, limit)
  9.     limit = limit or 0
  10.     local count = 0
  11.     repeat
  12.         MiningLib.veinMine(inclusive, ids, tags)
  13.         local success = direction()
  14.         if success then count = count + 1 end
  15.     until not success or count == limit
  16.     if count == 0 then return end
  17.     MiningLib.broadcast("Finished a strip.")
  18.     return count
  19. end
  20.  
  21. local function spiralSequence(rotations)
  22.     rotations = (rotations * 2) - 1
  23.     MiningLib.broadcast("Commencing vertical strip mining...")
  24.     sleep(0.2)
  25.     MiningLib.broadcast("Rotations: " .. tostring(rotations))
  26.     MiningLib.broadcast("Whitelist: " .. tostring(inclusive))
  27.     MiningLib.broadcast("Tags: " .. MassaLib.tprint(tags))
  28.     MiningLib.broadcast("IDs: " .. MassaLib.tprint(ids))
  29.     local count = 1
  30.     for i = 1, rotations, 1 do
  31.         local depth
  32.         local jMax = math.floor((i+1) / 2)
  33.         for j = 1, jMax, 1 do
  34.             if (i == rotations) and (j == jMax) then goto continue end
  35.  
  36.             if count % 2 == 1 then
  37.                 depth = stripMine(MiningLib.digAndMoveDown)
  38.                 if type(depth) ~= "number" then return end
  39.                 for k = 1, 3, 1 do
  40.                     turtle.up()
  41.                 end
  42.                 depth = depth - 3
  43.             end
  44.             MiningLib.digAndMoveForward()
  45.             MiningLib.digAndMoveForward()
  46.             if count % 2 == 1 then
  47.                 local depth2 = stripMine(MiningLib.digAndMoveDown)
  48.                 if type(depth2) ~= "number" then return end
  49.                 depth = depth + depth2
  50.                 local depth3 = stripMine(MiningLib.digAndMoveUp, depth)
  51.                 if type(depth3) ~= "number" then return end
  52.             end
  53.             count = count + 1
  54.  
  55.             ::continue::
  56.         end
  57.         if not (i == rotations) then turtle.turnLeft() end
  58.     end
  59. end
  60.  
  61. local function tutorial()
  62.     print("How to use the VerticalMining script.")
  63.     print("")
  64.     print("[] means required.")
  65.     print("<> means optional.")
  66.     print("bool means either true or false.")
  67.     print("")
  68.     print("VerticalMining [gridSize: number] [inclusive: bool] <id: text> <tag: text>")
  69.     print("")
  70.     print("You can enter as many tags and ids as you wish, so long as they are entered after the rotations.")
  71.     print("Tags must always be affixed with '#'.")
  72.     print("The minimum rotations is 2, for a 2x2 grid.")
  73.     print("'inclusive' is whether the ids and tags should be a whitelist (true) or blacklist (false).")
  74.     print("")
  75.     print("Example command:")
  76.     print("'VerticalMining 3 true #forge:ores minecraft:clay'")
  77.     print("This will mine a 3x3 grid and gather any ores and clay it can find.")
  78. end
  79.  
  80. local function init()
  81.     if arg[1] == "help" then return true end
  82.     local rotations = tonumber(arg[1]) or error("Requires a number argument.", 0)
  83.     if (arg[2] and string.lower(arg[2])) == "true" and true or false then
  84.         inclusive = true
  85.     elseif (arg[2] and string.lower(arg[2])) ~= "false" then error("Requires a boolean argument.", 0)
  86.     else inclusive = false end
  87.     for i,argument in ipairs(arg) do
  88.         if i <= 2 then goto continue end
  89.  
  90.         if string.sub(argument, 1, 1) == "#" then
  91.             tags[i-2] = argument:sub(2)
  92.         else
  93.             ids[i-2] = argument
  94.         end
  95.  
  96.         ::continue::
  97.     end
  98.     spiralSequence(rotations)
  99. end
  100.  
  101. local guide = init()
  102. if guide then tutorial() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement