Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ opencomputers копатель алмазов by serafim
- pastebin.com/qAeXekby update 13.06.21
- Копает бесконечный туннель 1х3 змейкой ряд за рядом,
- предназначен для добычи алмазов по горизонту,
- оптимальная высота = 12 (так как на 11 лава)
- требования:
- инвентарь, контроллер инвентаря,
- генератор, желателен чанк лоадер.
- пример сборки:
- https://i.imgur.com/fR7F4fA.png
- использование:
- положить в инвентарь робота инструмент (кирка, бур и т.д.),
- эндер-сундук (можно обычные сундуки, 64 шт. например),
- уголь больше 20 штук.
- пример запуска:
- tunnel 30 1 или tunnel
- ]]--
- local a = {...}
- local width = tonumber(a[1]) or 30 --ширина туннеля
- local stepline = tonumber(a[2]) or 1 --отступ между рядами
- --список мусора
- local scrap = {
- "cobblestone", --булыжник
- "stone", --камень
- "dirt", --земля
- "gravel", --гравий
- "flint", --кремень
- "sand", --песок
- "sandstone" --песчаник
- }
- --список инструмента
- local toollist = {
- "ickaxe",
- "rill",
- "pick",
- "vajra"
- }
- local com = require('component')
- local computer = require("computer")
- local event = require("event")
- local timestart = computer.uptime()
- local fuelinv,refuel,chestcoal = true,true,true
- local unloaded,durability,placeside = 0,0,false
- local toolstrength = 0.07
- if not com.isAvailable("robot") then
- print("только роботы могут использовать эту программу")
- os.exit()
- end
- local r = require("robot")
- local invsize = r.inventorySize()
- local tools = invsize
- local coal = invsize-1
- local chest = invsize-2
- if not com.isAvailable("inventory_controller") then
- print("нет контроллера инвентаря")
- os.exit()
- end
- local i_c = com.inventory_controller
- if not com.isAvailable("generator") then
- print("нет генератора")
- os.exit()
- end
- local gen = com.generator
- --статус
- local function status(msg)
- print("[ "..os.date("%H:%M:%S",computer.uptime()-timestart).." ] "..msg)
- end
- --чанк лоадер
- local function chunkload(state)
- if com.isAvailable("chunkloader") then
- if state then
- com.chunkloader.setActive(true)
- print("чанк лоадер активен")
- else
- com.chunkloader.setActive(false)
- print("чанк лоадер деактивирован".."\n")
- end
- end
- end
- --стоп
- local function stop(msg,reason)
- print("всего выгрузил руды: "..unloaded.."\n")
- if reason then
- print("причина остановки: "..reason)
- end
- status("!!! стоп !!!".."\n"..msg.."\n")
- chunkload(false)
- print("продолжить копать ? [Y/n]")
- while true do
- r.setLightColor(0xFFFFFF)
- computer.beep(1000, 1)
- r.setLightColor(0xFF0000)
- local e = ({event.pull(10,"key_down")})[4]
- if e == 49 then
- computer.beep(500, 0.1)
- print("программа завершена")
- os.exit()
- elseif e == 21 or e == 28 then
- computer.beep(500, 0.1)
- r.setLightColor(0xFFFFFF)
- print("продолжаю копать...")
- chunkload(true)
- break
- end
- end
- end
- --поиск предмета в инвентаре робота
- local function slotitem(slot, list)
- local item = i_c.getStackInInternalSlot(slot)
- if item then
- for j, name in pairs(list) do
- if string.find(item.name,name) then
- if item.charge == nil or item.charge/item.maxCharge > toolstrength then
- return true
- end
- end
- end
- end
- for i = 1,invsize do
- if r.count(i) > 0 then
- for j, name in pairs(list) do
- local item = i_c.getStackInInternalSlot(i)
- if item and string.find(item.name,name) then
- if item.charge == nil or item.charge/item.maxCharge > toolstrength then
- r.select(i)
- r.transferTo(slot)
- return true
- end
- end
- end
- end
- end
- return false
- end
- --ставим и забираем сундук по трём сторонам
- local function placechest(place)
- if place then
- local tryplase = function()
- for i, side in ipairs({0,1,3}) do
- r.select(1)
- com.robot.swing(side)
- r.select(chest)
- local ok = com.robot.place(side)
- if ok then
- placeside = side
- return true
- end
- end
- return false
- end
- while not tryplase() do
- if not slotitem(chest,{"hest","ender"}) then
- stop("сундук в инвентаре не найден")
- else
- stop("не могу поставить сундук")
- end
- end
- else
- while r.durability() == nil do
- if slotitem(tools,toollist) then
- r.select(tools)
- i_c.equip()
- break
- else
- stop("нет инструмента")
- end
- end
- local detect = function()
- return com.robot.detect(placeside)
- end
- r.select(chest)
- while detect() do
- com.robot.swing(placeside)
- end
- end
- end
- --ожидаем пока в сундуке появится место
- local function waitdrop()
- local drop = function()
- com.robot.drop(placeside)
- if r.count() == 0 then
- return true
- end
- return false
- end
- if not drop() then
- status("в сундуке нет места")
- while not drop() do
- r.setLightColor(0xFFFFFF)
- computer.beep(1000, 1)
- r.setLightColor(0xFF0000)
- os.sleep(5)
- end
- r.setLightColor(0xFFFFFF)
- end
- end
- --проверяем электроинструмент
- local function electric()
- local item = i_c.getStackInInternalSlot(tools)
- if item and item.charge ~= nil then
- return true
- end
- return false
- end
- --берем запасной инструмент
- local function tool()
- local checktool = r.durability()
- if checktool == nil or checktool <= toolstrength then
- if slotitem(tools,toollist) then
- r.select(tools)
- i_c.equip()
- status("взял инструмент в инвентаре робота")
- if not electric() then
- r.drop()
- end
- durability = 0
- elseif slotitem(chest,{"ender"}) then
- local findtool = function()
- local inv = i_c.getInventorySize(placeside)
- if inv then
- for slot = 1,inv do
- for j, name in pairs(toollist) do
- local item = i_c.getStackInSlot(placeside,slot)
- if item and string.find(item.name,name) then
- if item.charge == nil or item.charge/item.maxCharge > toolstrength then
- i_c.suckFromSlot(placeside,slot)
- i_c.equip()
- status("взял запасной инструмент из сундука")
- durability = 0
- return true
- end
- end
- end
- end
- return false
- else
- stop("нет эндер-сундука")
- end
- end
- status("ищу инструмент в эндер-сундуке")
- placechest(true)
- r.select(tools)
- i_c.equip()
- if electric() then
- waitdrop()
- status("положил разряженный инструмент")
- else
- r.drop()
- end
- if not findtool() then
- status("в сундуке нет инструмента")
- while not findtool() do
- r.setLightColor(0xFFFFFF)
- computer.beep(1000, 1)
- r.setLightColor(0xFF0000)
- os.sleep(5)
- end
- r.setLightColor(0xFFFFFF)
- end
- placechest()
- else
- stop("в инвентаре робота нет инструмента")
- end
- r.select(1)
- elseif r.detect() then
- local d1 = string.format("%.3f",r.durability())
- for i, side in ipairs({1,3,0}) do
- com.robot.swing(side)
- local d2 = string.format("%.3f",r.durability())
- if d2 < d1 then
- durability = math.floor(d2/(d1-d2))
- break
- end
- end
- end
- end
- --сортируем лут
- local function sortlut()
- status("сортирую лут...")
- r.swingDown()
- for i = 1,invsize do
- if r.count(i) > 0 then
- local item = i_c.getStackInInternalSlot(i)
- if string.find(item.name,"coal") then
- r.select(i)
- r.transferTo(coal)
- else
- for n = 1,#scrap do
- if scrap[n] == item.name:gsub('%g+:','') then
- r.select(i)
- r.dropDown()
- break
- end
- end
- end
- end
- end
- for i = 1,invsize-3 do
- if r.count(i) == 0 then
- for j = invsize-3,1,-1 do
- if r.count(j) > 0 then
- if j < i then
- break
- end
- r.select(j)
- r.transferTo(i)
- break
- end
- end
- end
- end
- if r.count(invsize-6) > 0 then
- local unload = function()
- local inv = i_c.getInventorySize(placeside)
- local dropcount = 0
- if inv then
- for i = 1,invsize-3 do
- if r.count(i) > 0 then
- r.select(i)
- unloaded = unloaded + r.count(i)
- dropcount = dropcount + 1
- if dropcount < inv then
- waitdrop()
- else
- break
- end
- end
- end
- chestcoal = true
- else
- stop("нет сундука")
- return
- end
- status("всего добыто: "..unloaded)
- end
- slotitem(coal,{"coal"})
- if slotitem(chest,{"ender"}) then
- placechest(true)
- unload()
- placechest()
- elseif slotitem(chest,{"hest"}) then
- placechest(true)
- unload()
- else
- stop("инвентарь заполнен")
- end
- end
- r.select(1)
- end
- --дозоправка углём
- local function checkfuel()
- local energy = computer.energy()
- if energy <= 6000 then
- refuel = true
- chestcoal = true
- end
- if gen.count() <= 10 and refuel then
- for i = 1,invsize do
- local item = i_c.getStackInInternalSlot(i)
- if item and string.find(item.name,"coal") then
- r.select(i)
- r.transferTo(coal)
- end
- end
- r.select(coal)
- if gen.insert() then
- fuelinv = true
- status("заправился, угля в генераторе = "..gen.count())
- elseif fuelinv then
- fuelinv = false
- refuel = false
- status("нет угля в инвентаре робота !!!")
- elseif chestcoal and slotitem(chest,{"ender"}) then
- status("ищу уголь в эндер-сундуке")
- placechest(true)
- local inv = i_c.getInventorySize(placeside)
- if inv then
- for slot = 1,inv do
- local item = i_c.getStackInSlot(placeside,slot)
- if item and string.find(item.name,"coal") then
- r.select(coal)
- i_c.suckFromSlot(placeside,slot,32)
- status("взял уголь из сундука")
- if gen.insert() then
- status("заправился, угля в генераторе = "..gen.count())
- end
- break
- end
- if slot == inv then
- chestcoal = false
- status("нет угля в сундуке")
- end
- end
- end
- placechest()
- end
- r.select(1)
- end
- if energy <= 5000 then
- if gen.count() >= 10 then
- status("мало энергии, заряжаюсь до 10 000")
- while true do
- os.sleep(10)
- if computer.energy() >= 10000 then
- status("зарядился :)")
- break
- end
- if gen.count() == 0 then
- stop("закончился уголь")
- end
- end
- else
- stop("закончился уголь")
- end
- end
- end
- --движение в сторону side
- local function robotMove(side)
- while true do
- local ok,reason = com.robot.move(side)
- if ok then
- return true
- elseif reason and reason == "already moving" then
- os.sleep(0.1)
- else
- return false,reason
- end
- end
- end
- --копаем и движемся вперед
- local function digForward(step)
- for i = 1,step do
- if durability <= 3 then
- tool()
- end
- r.swingUp()
- r.swing()
- r.swingDown()
- durability = durability - 3
- if r.count(invsize-3) > 0 then
- sortlut()
- end
- local tru,reason = 0
- while true do
- if r.detect() then
- _,reason = r.swing()
- durability = durability - 1
- else
- ok,reason = robotMove(3)
- if ok then
- break
- end
- end
- tru = tru + 1
- if tru == 3 then
- tool()
- elseif tru >= 20 then
- tru = 0
- stop("непреодолимое препятствие",reason)
- end
- end
- end
- end
- --копаем
- os.execute("cls")
- print("копатель алмазов by serafim")
- if width > 100 or width < 10 then
- print("\n".." ширина тунеля")
- print("должна быть от 10 до 100".."\n")
- os.exit()
- end
- print("угля в генераторе = "..gen.count())
- print("энергии = "..math.floor(100*computer.energy()/computer.maxEnergy()).." %")
- print("подготовка...")
- for slot = 1,invsize do
- if r.count(slot) == 0 then
- r.select(slot)
- i_c.equip()
- break
- end
- if slot == invsize then
- print("в инвентаре робота нет пустых слотов")
- os.exit()
- end
- end
- if slotitem(tools,toollist) then
- r.select(tools)
- i_c.equip()
- slotitem(tools,toollist)
- else
- print("в инвентаре робота нет инструмента")
- os.exit()
- end
- slotitem(chest,{"hest","ender"})
- slotitem(coal, {"coal"})
- print("ширина тунеля = "..width)
- r.setLightColor(0xFFFFFF)
- r.select(1)
- chunkload(true)
- while true do
- checkfuel()
- digForward(width-1)
- r.turnRight()
- digForward(stepline)
- r.turnRight()
- checkfuel()
- digForward(width-1)
- r.turnLeft()
- digForward(stepline)
- r.turnLeft()
- end
Add Comment
Please, Sign In to add comment