Advertisement
gravitowl

AutoMiner

Dec 20th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. local tabula = require("/lib/tabula");
  2. local ecdysis = require("/lib/ecdysis");
  3.  
  4. local ORES = {
  5.     "minecraft:coal_ore",
  6.     "minecraft:deepslate_coal_ore",
  7.     "minecraft:iron_ore",
  8.     "minecraft:deepslate_iron_ore",
  9.     "minecraft:copper_ore",
  10.     "minecraft:deepslate_copper_ore",
  11.     "minecraft:gold_ore",
  12.     "minecraft:deepslate_gold_ore",
  13.     "minecraft:redstone_ore",
  14.     "minecraft:deepslate_redstone_ore",
  15.     "minecraft:emerald_ore",
  16.     "minecraft:deepslate_emerald_ore",
  17.     "minecraft:lapis_ore",
  18.     "minecraft:deepslate_lapis_ore",
  19.     "minecraft:diamond_ore",
  20.     "minecraft:deepslate_diamond_ore",
  21.     "create:zinc_ore",
  22.     "create:deepslate_zinc_ore",
  23. };
  24.  
  25. local function isOre(block)
  26.     if not block or not block.name then
  27.         return false;
  28.     end
  29.  
  30.     local blockName = block.name;
  31.  
  32.     return table.contains(ORES, blockName);
  33. end
  34.  
  35. local function getOreNeighbours()
  36.     local neighbours = ecdysis.inspectSurroundings();
  37.     local neighbourPositions = {}
  38.  
  39.     for direction, neighbour in pairs(neighbours) do
  40.         if isOre(neighbour.data) then
  41.             local delta = ecdysis.applyDirectionDelta(ecdysis.relativeDeltas[direction]);
  42.             local orePosition = ecdysis.applyPositionDelta(delta);
  43.  
  44.             table.insert(neighbourPositions, orePosition);
  45.         end
  46.     end
  47.  
  48.     return neighbourPositions;
  49. end
  50.  
  51. local function mineOreVein(firstOrePosition, endPosition)
  52.     local stack = {firstOrePosition};
  53.     local visited = {};
  54.     visited[ecdysis.getPositionKey(endPosition)] = true;
  55.  
  56.     while #stack > 0 do
  57.         local currentPosition = table.remove(stack, #stack);
  58.         local key = ecdysis.getPositionKey(currentPosition);
  59.  
  60.         if visited[key] then
  61.             goto continue
  62.         end
  63.  
  64.         visited[key] = true;
  65.  
  66.         local couldTravel = ecdysis.pathfindToPosition(ecdysis.getPosition(), currentPosition, visited);
  67.  
  68.         if not couldTravel then
  69.             return false, "Could not travel to required position.";
  70.         end
  71.        
  72.         for _, position in pairs(getOreNeighbours()) do
  73.             table.insert(stack, position);
  74.         end
  75.  
  76.         ::continue::
  77.     end
  78.  
  79.     ecdysis.pathfindToPosition(ecdysis.getPosition(), endPosition, visited);
  80. end
  81.  
  82. local function digForward()
  83.     ecdysis.forceForward();
  84.  
  85.     local direction = ecdysis.getDirection();
  86.     for _, position in pairs(getOreNeighbours()) do
  87.         mineOreVein(position, ecdysis.getPosition());
  88.     end
  89.     ecdysis.turnTo(direction);
  90. end
  91.  
  92. local function main()
  93.     while true do
  94.         digForward();        
  95.     end
  96. end
  97.  
  98. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement