Advertisement
ThatsHawkward

mine.lua

Feb 19th, 2025
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. local tArgs = { ... }
  2. local side = 40;
  3. if #tArgs >= 1 then
  4.     side = tonumber(tArgs[1])
  5. end
  6.  
  7. local api = require("api")
  8. local ENDERCHEST_SLOT = 1
  9.  
  10. -- Blacklist
  11. local blackIds = { "forbidden_arcanus:stella_arcanum" }
  12. local function blacklist(data)
  13.     for _, value in ipairs(blackIds) do
  14.         if value == data.name then
  15.             return true
  16.         end
  17.     end
  18.     return false
  19. end
  20.  
  21. print("Mining a square of side " .. side)
  22.  
  23. local function safeDig(i)
  24.     local exists, blacklisted = api.checkBlacklist(blacklist, i)
  25.     if blacklisted then return false end
  26.     if not exists then return true end
  27.     if not api.dig(i) then
  28.         api.attack(i)
  29.     end
  30.     return true
  31. end
  32.  
  33. local function freeupSpace()
  34.     local dir = api.DOWN
  35.     local exists = true
  36.     while true do
  37.         local blacklisted
  38.         exists, blacklisted = api.checkBlacklist(blacklist, dir)
  39.         if not exists or not blacklisted then
  40.             break
  41.         end
  42.  
  43.         if dir == api.DOWN then
  44.             dir = api.FRONT
  45.         elseif dir == api.FRONT then
  46.             dir = api.UP
  47.         elseif dir == api.UP then
  48.             api.turn(api.RIGHT)
  49.             dir = api.DOWN
  50.         end
  51.     end
  52.  
  53.     if exists then
  54.         api.dig(dir)
  55.     end
  56.     api.place(dir, ENDERCHEST_SLOT)
  57.     api.dropAll(dir)
  58.     api.select(ENDERCHEST_SLOT)
  59.     api.dig(dir)
  60. end
  61.  
  62. local function ensureSpace()
  63.     if api.freeSlots() == 0 then
  64.         freeupSpace()
  65.     end
  66. end
  67.  
  68. local function mine()
  69.     local blocksToUp = -1
  70.     local downBy = 0
  71.     local times = 2 * side - 1;
  72.  
  73.     for n=1,times do
  74.         print("Segment " .. n)
  75.         local blocks = side - math.floor(n / 2)
  76.         for b=1,blocks do
  77.             print("Block " .. b)
  78.             ensureSpace()
  79.             safeDig(api.UP)
  80.             safeDig(api.DOWN)
  81.             while not api.move(api.FRONT) do
  82.                 if not safeDig(api.FRONT) then
  83.                     safeDig(api.DOWN)
  84.                     if api.move(api.DOWN) then
  85.                         downBy = downBy + 1
  86.                         blocksToUp = 1
  87.                     end
  88.                 end
  89.             end
  90.             while blocksToUp <= 0 and downBy > 0 do
  91.                 if not safeDig(api.UP) then
  92.                     break
  93.                 end
  94.                 if api.move(api.UP) then
  95.                     downBy = downBy - 1
  96.                 end
  97.             end
  98.             if blocksToUp > 0 then
  99.                 blocksToUp = blocksToUp - 1
  100.             end
  101.         end
  102.         api.turn(api.RIGHT)
  103.     end
  104.  
  105.     freeupSpace()
  106. end
  107.  
  108. mine()
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement