local robot = require("robot") local component = require("component") local term = require("term") if not component.isAvailable("inventory_controller") then print("КРИТИЧНА ПОМИЛКА: Немає модуля Inventory Controller для зняття Ваджри!") os.exit() end local inv = component.inventory_controller -- === НАЛАШТУВАННЯ === local CHARGE_TIME = 30 -- Час зарядки Ваджри (сек) local SWINGS_BEFORE_CHARGE = 1000 -- Зарядка раз на 1000 блоків local PAUSE_BEFORE_CHARGE = 5 -- Пауза перед зняттям Ваджри -- ==================== local total_mined = 0 local current_swings = 0 local current_ore_slot = 8 -- Трекер поточного слота з рудою -- Функція малювання полоски прогресу local function getProgressBar(current, max, width) local filled = math.floor((current / max) * width + 0.5) if filled > width then filled = width end if filled < 0 then filled = 0 end local bar = "[" for i = 1, width do if i <= filled then bar = bar .. "#" else bar = bar .. "-" end end bar = bar .. "]" return bar end local function updateHUD(status) term.setCursor(1, 1) term.clearLine() print("======================================") term.clearLine() print(" АВТОНОМНИЙ ЗАВОД РУДИ ") term.clearLine() print("======================================") term.clearLine() print("Статус: " .. status) term.clearLine() print("Зарядка: " .. getProgressBar(current_swings, SWINGS_BEFORE_CHARGE, 20) .. " " .. current_swings .. "/" .. SWINGS_BEFORE_CHARGE) term.clearLine() print("Всього викопано: " .. total_mined .. " блоків") term.clearLine() print("======================================") end -- Очищення 16-го слота викликається ТІЛЬКИ перед зарядкою local function clearSlot16() if robot.count(16) > 0 then robot.select(16) for i = 1, 7 do robot.transferTo(i) if robot.count(16) == 0 then break end end end end -- Вивантаження луту (слоти 1-7) у скриню ЛІВОРУЧ local function dumpItems() updateHUD("Скидаю лут ліворуч...") robot.turnLeft() for i = 1, 7 do if robot.count(i) > 0 then robot.select(i) robot.drop() end end robot.turnRight() end -- Забір блоків руди (слоти 8-15) зі скрині ПРАВОРУЧ local function restockOres() updateHUD("Беру руду праворуч...") robot.turnRight() for i = 8, 15 do robot.select(i) robot.suck() end robot.turnLeft() end -- Процедура зарядки Ваджри через блок ЗНИЗУ local function chargeTool() updateHUD("Підготовка до зарядки...") os.sleep(PAUSE_BEFORE_CHARGE) -- 1. Скидаємо лут ліворуч, щоб звільнити місце dumpItems() -- 2. Тільки зараз чистимо 16-й слот (якщо туди щось залетіло) clearSlot16() if robot.count(16) > 0 then updateHUD("ПОМИЛКА: 16-й слот не очистився!") os.sleep(3) return end -- 3. Знімаємо Ваджру в 16-й слот updateHUD("Знімаю Ваджру...") robot.select(16) inv.equip() os.sleep(0.5) -- 4. Кладемо Ваджру ЗНИЗУ if robot.count(16) > 0 then updateHUD("Кладу Ваджру в блок ЗНИЗУ...") local ok = robot.dropDown() if not ok or robot.count(16) > 0 then updateHUD("ПОМИЛКА: Блок знизу не прийняв Ваджру!") inv.equip() os.sleep(3) return end else updateHUD("ПОМИЛКА: Ваджра не знялася!") os.sleep(3) return end -- 5. Очікуємо 30 секунд for i = CHARGE_TIME, 1, -1 do updateHUD("Зарядка знизу (" .. i .. " сек)...") os.sleep(1) end -- 6. Забираємо Ваджру ЗНИЗУ updateHUD("Забираю Ваджру...") robot.select(16) local gotOk = robot.suckDown() if gotOk and robot.count(16) > 0 then inv.equip() updateHUD("Зарядка успішна!") os.sleep(1) else updateHUD("КРИТИЧНА ПОМИЛКА: Не зміг забрати Ваджру!") os.exit() end end term.clear() updateHUD("Ініціалізація...") -- === ГОЛОВНИЙ ЦИКЛ === while true do -- 1. Швидкий вибір слота з рудою без циклів if robot.count(current_ore_slot) == 0 then current_ore_slot = current_ore_slot + 1 if current_ore_slot > 15 then restockOres() current_ore_slot = 8 end end -- 2. Ставимо блок руди robot.select(current_ore_slot) robot.place() -- 3. Копаємо блок robot.select(1) local hit = robot.swing() if hit then current_swings = current_swings + 1 total_mined = total_mined + 1 end -- Оновлюємо екран тільки раз на 20 блоків для швидкості if current_swings % 20 == 0 then updateHUD("Копаю...") end -- 4. Перевірка заповненості лутом (слот 7) if robot.count(7) > 0 then dumpItems() end -- 5. Перевірка лічильника для зарядки (раз на 1000 блоків) if current_swings >= SWINGS_BEFORE_CHARGE then chargeTool() current_swings = 0 updateHUD("Копаю...") end os.sleep(0.05) end