Advertisement
massacring

StripMine

Jul 19th, 2024 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. local TurtleLib = require('MassaTurtleLib')
  2. local MiningLib = require('MassaMiningTurtleLib')
  3.  
  4. local tags = {}
  5. local ids = {}
  6. local inclusive = true
  7.  
  8. local function tutorial()
  9.     print("How to use the StripMine script.")
  10.     print("")
  11.     print("[] means required.")
  12.     print("<> means optional.")
  13.     print("")
  14.     print("StripMine [depth: number] [distance: number] <direction: left or right> <inclusive: bool> <id: text> <tag: #text>")
  15.     print("")
  16.     print("Example command:")
  17.     print("'StripMine 10 3 left #forge:ores'")
  18.     print("This will dig a 2x1 hole forwards for 10 blocks, then go to the left by 3 and dig back, mining all ores along the way.")
  19. end
  20.  
  21. local function tunnel(depth)
  22.     for _ = 1, depth, 1 do
  23.         local has_block = turtle.detect()
  24.         if has_block then
  25.             MiningLib.digAndMoveForward()
  26.             MiningLib.veinMine(inclusive, ids, tags)
  27.         else turtle.forward() end
  28.  
  29.         local has_blockUp = turtle.detectUp()
  30.         if has_blockUp then
  31.             MiningLib.digAndMoveUp()
  32.             MiningLib.veinMine(inclusive, ids, tags)
  33.             turtle.down()
  34.         end
  35.  
  36.         if not turtle.detectDown() then
  37.             for i = 1, 16, 1 do
  38.                 local item = turtle.getItemDetail(i)
  39.                 if not item then goto continue end
  40.        
  41.                 if item.name == "minecraft:cobblestone" or item.name == "minecraft:cobbled_deepslate" then
  42.                     turtle.select(i)
  43.                     turtle.placeDown()
  44.                     break
  45.                 end
  46.        
  47.                 ::continue::
  48.             end
  49.         end
  50.     end
  51. end
  52.  
  53. local function turn(direction)
  54.     if (direction == "right") then turtle.turnRight()
  55.     else turtle.turnLeft() end
  56. end
  57.  
  58. local function strip(direction, depth, distance)
  59.     tunnel(depth)
  60.  
  61.     turn(direction)
  62.  
  63.     tunnel(distance)
  64.  
  65.     turn(direction)
  66.  
  67.     tunnel(depth)
  68.  
  69.     turn(direction)
  70.  
  71.     tunnel(distance)
  72. end
  73.  
  74. local function init()
  75.     if arg[1] == "help" then return true end
  76.     local depth = tonumber(arg[1]) or error("Requires number argument", 0)
  77.     local distance = tonumber(arg[2]) or error("Requires number argument", 0)
  78.     local direction
  79.     local hasInclusive = true
  80.     if (not arg[3]) or (arg[3] ~= "right" and arg[3] ~= "left" and arg[3] ~= "r" and arg[3] ~= "l") then direction = nil
  81.     else direction = arg[3] end
  82.  
  83.     if (arg[3] and string.lower(arg[3])) == "false" then
  84.         inclusive = false
  85.     elseif (arg[4] and string.lower(arg[4])) == "false" then
  86.         inclusive = false
  87.     elseif (arg[3] and string.lower(arg[3])) ~= "true" and (arg[4] and string.lower(arg[4])) ~= "true" then hasInclusive = false
  88.     end
  89.     for i,argument in ipairs(arg) do
  90.         if i <= 2 then goto continue end
  91.         if (direction or hasInclusive) and i <= 3 then goto continue end
  92.         if (direction and hasInclusive) and i <= 4 then goto continue end
  93.  
  94.         if string.sub(argument, 1, 1) == "#" then
  95.             table.insert(tags, argument:sub(2))
  96.         else
  97.             table.insert(ids, argument)
  98.         end
  99.  
  100.         ::continue::
  101.     end
  102.  
  103.     local fuel = turtle.getFuelLevel()
  104.     local requiredFuel = (depth + distance) * 2 * 3
  105.     if fuel < requiredFuel then
  106.         error(string.format("[%d/%d] - Turtle requires %d more fuel.", fuel, requiredFuel, (requiredFuel-fuel)), 0)
  107.     end
  108.  
  109.     strip(direction, depth, distance)
  110. end
  111.  
  112. local guide = init()
  113. if guide then tutorial() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement