Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ opencomputers лазерный карьер by serafim
- pastebin.com/WGYGG261 update 09.06.2019
- робот в качестве инструмента использует лазер из мода Industrial Craft
- из плюсов большая скорость работы, низкий расход энергии,
- за один подход проходит 30 слоёв породы.
- из минусов лазер плохо работает в жидкостях(вода,лава), в итоге
- робот может пропускать столбы пород, или застрять под лавой.
- требования:
- корпус третьего уровня, притягивающий луч, инвентарь(можно три),
- контроллер инвентаря, генератор, улучшение парение,
- чанк лоадер если нужно.
- пример сборки:
- https://i.imgur.com/JAm0IS0.png
- номера слотов:
- 1: лазер из мода Industrial Craft
- 2: уголь
- 3: булыжник
- использование:
- на старте, сзади робота поставить сундук.
- положить в инвентарь роботу:
- запасной заряженный лазер, уголь, булыжник.
- дать роботу ЛАЗЕР В РЕЖИМЕ ДАЛЬНЕГО ДЕЙСТВИЯ !
- пример запуска: (по умолчанию один чанк)
- quarry 16 16 30 или quarry
- получить названия мусорных блоков pastebin.com/q4g9JDeW
- --]]
- local a = {...}
- local x = tonumber(a[1]) or 16 --ширина
- local y = tonumber(a[2]) or 16 --длина
- local z = tonumber(a[3]) or 30 --глубина одного слоя
- local unloaded,countsort,PosZ,fuelinv,fuelchest,ridht,stepdown = 0,0,0,true,true,true,false
- local xPos,depth,zPos,xDir,zDir = 0,0,0,0,1
- local lazer,coal,cobble = 1,2,3
- --список мусорных блоков
- local scrap = {
- "minecraft:cobblestone",
- "minecraft:dirt",
- "minecraft:gravel",
- "minecraft:flint",
- "minecraft:sand",
- "minecraft:sandstone",
- "chisel:andesite",
- "chisel:diorite",
- "chisel:granite",
- "chisel:limestone",
- "minecraft:wheat_seeds",
- }
- local computer = require("computer")
- local com = require("component")
- if not com.isAvailable("robot") then
- print("только роботы могут использовать эту программу")
- os.exit()
- end
- local r = require("robot")
- local invsize = r.inventorySize()
- 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
- if not com.isAvailable("tractor_beam") then
- print("для работы нужен притягивающий луч")
- os.exit()
- end
- local tb = com.tractor_beam
- if com.isAvailable("chunkloader") then
- cloader = com.chunkloader
- cloader.setActive(true)
- print("чанк лоадер активен")
- end
- --поиск предмета в инвентаре робота
- local function slotitem(slot, name)
- local item = i_c.getStackInInternalSlot(slot)
- if item and item.name == name then
- return true
- else
- for i = 1, invsize do
- local item = i_c.getStackInInternalSlot(i)
- if item and item.name == name then
- r.select(i)
- r.transferTo(slot)
- return true
- end
- end
- print(name.."\n".."в инвентаре не найден :(")
- return false
- end
- end
- --ставим под робота булыжник
- local function placecobble()
- if not r.detectDown() then
- if r.count(cobble) > 16 then
- r.select(cobble)
- r.placeDown()
- else
- slotitem(cobble, "minecraft:cobblestone")
- r.select(cobble)
- r.placeDown()
- end
- end
- end
- --сортируем лут
- local function sortlut(droplut)
- print("сортирую лут...")
- --складываем лут в сундук
- local unload = function()
- local inv = i_c.getInventorySize(3)
- if inv then
- for i = 4,invsize do
- if r.count(i) > 0 then
- r.select(i)
- unloaded = unloaded + r.count(i)
- if not r.drop() then
- returnHome("в сундуке нет места :(" , false)
- end
- end
- end
- else
- returnHome("нет сундука :(" , false)
- end
- print("всего добыто руды: "..unloaded)
- fuelchest = true
- r.select(cobble)
- end
- --выкидываем мусор
- local isscrap = function()
- r.useDown()
- for i = 4, invsize do
- local slot = i_c.getStackInInternalSlot(i)
- if slot ~= nil then
- for k, name in pairs(scrap) do
- if slot.name == name then
- r.select(i)
- r.dropDown()
- end
- end
- end
- end
- r.select(cobble)
- end
- --компонуем лут
- local compact = function()
- for i = 3, invsize do
- if r.count(i) == 0 then
- for j = invsize, 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
- r.select(cobble)
- end
- --возврат к сундуку и обратно
- local gotochest = function()
- xP,yP,zP,xD,zD = xPos,depth,zPos,xDir,zDir
- print("возвращаюсь к сундуку сложить лут")
- goTo( 0,0,0,0,-1 )
- isscrap()
- unload()
- countsort = 0
- goTo( xP,yP,zP,xD,zD )
- end
- --проверить есть ли запас угля
- if r.count(coal) < 32 then
- slotitem(coal, "minecraft:coal")
- end
- --проверить достигнут ли низ
- if stepdown then
- gotochest()
- return
- else
- countsort = countsort + 1
- if countsort == 1 then
- PosZ = zPos
- elseif countsort == 2 and zPos == PosZ then
- local countcobbl = 0
- for i = 4, invsize do
- local item = i_c.getStackInInternalSlot(i)
- if item and item.name == "minecraft:cobblestone" then
- countcobbl = countcobbl + item.size
- end
- if countcobbl >= 128 then
- isscrap()
- print("ожидаю очистку мира от мусора...")
- os.sleep(360)
- if tb.suck() then
- print("6 минут мало, ожидаю еще 6 минут")
- os.sleep(360)
- end
- if tb.suck() then
- returnHome("устал ждать :(" , true)
- end
- print("низ достигнут !")
- stepdown = true
- countsort = 0
- return
- end
- end
- countsort = 0
- else
- countsort = 0
- end
- end
- --сортировка
- isscrap()
- if droplut then
- unload()
- return
- end
- compact()
- if r.count(invsize - 4) > 0 then
- gotochest()
- end
- end
- --стоим и заряжаемся, если генератор не справляется
- local function checkenergy()
- if computer.energy() < 5000 then
- if gen.count() >= 10 then
- print("мало энергии, заряжаюсь до 5000")
- while true do
- os.sleep(30)
- if computer.energy() >= 5000 then
- print("зарядился :)")
- break
- end
- if gen.count() == 0 then
- returnHome("закончилось топливо :(" , true)
- end
- end
- else
- returnHome("закончилось топливо :(" , true)
- end
- end
- end
- --возвращаемся к сундуку за углем
- local function fuelinchest()
- if fuelchest then
- xP,yP,zP,xD,zD = xPos,depth,zPos,xDir,zDir
- print("возвращаюсь к сундуку за углем")
- goTo( 0,0,0,0,-1 )
- local inv = i_c.getInventorySize(3)
- if inv then
- for slot = 1, inv do
- local item = i_c.getStackInSlot(3, slot)
- if item and item.name == "minecraft:coal" then
- r.select(coal)
- if r.count(coal) > 0 then
- r.dropDown()
- end
- i_c.suckFromSlot(3, slot)
- gen.insert()
- r.select(cobble)
- print("заправился, топлива в генераторе = "..gen.count())
- if r.count(4) > 0 then
- sortlut(true)
- end
- goTo( xP,yP,zP,xD,zD )
- return true
- end
- end
- fuelchest = false
- print("нет топлива в сундуке :(")
- goTo( xP,yP,zP,xD,zD )
- else
- returnHome("нет сундука !" , false)
- end
- end
- end
- --дозаправка углём из инвентаря
- local function checkfuel()
- if fuelinv and gen.count() <= 10 then
- local gencount = gen.count()
- for i = 1,invsize do
- local item = i_c.getStackInInternalSlot(i)
- if item and item.name == "minecraft:coal" then
- r.select(i)
- r.transferTo(coal)
- end
- end
- r.select(coal)
- gen.insert()
- if gen.count() > gencount then
- print("заправился, топлива в генераторе = "..gen.count())
- else
- print("нет топлива в инвентаре робота !!!")
- fuelinv = false
- fuelinchest()
- end
- r.select(cobble)
- end
- end
- --ищем лазер в сундуке
- local function findlazerinchest()
- xP,yP,zP,xD,zD = xPos,depth,zPos,xDir,zDir
- print("возвращаюсь к сундуку за лазером")
- goTo( 0,0,0,0,-1 )
- local inv = i_c.getInventorySize(3)
- if inv then
- for slot = 1, inv do
- local item = i_c.getStackInSlot(3, slot)
- if item and item.name == "IC2:itemToolMiningLaser" then
- print("лазер в слоте: "..slot.." заряд: "..item.charge)
- if item.charge > 10000 then
- r.select(lazer)
- r.drop()
- i_c.suckFromSlot(3, slot)
- i_c.equip()
- r.drop()
- r.select(cobble)
- print("взял лазер из сундука :)")
- if r.count(4) > 0 then
- sortlut(true)
- end
- goTo( xP,yP,zP,xD,zD )
- return true
- end
- end
- end
- returnHome("нет заряженного лазера в сундуке :(" , false)
- else
- returnHome("нет сундука !" , false)
- end
- end
- --ищем лазер в инвентаре
- local function lazerequip()
- if r.durability() == nil then
- if slotitem(lazer, "IC2:itemToolMiningLaser") then
- r.select(lazer)
- i_c.equip()
- r.select(cobble)
- print("взял запасной лазер :)")
- else
- returnHome("положите в инвентарь лазер !!!" , true)
- end
- elseif r.durability() < 0.02 then
- if slotitem(lazer, "IC2:itemToolMiningLaser") then
- local device = i_c.getStackInInternalSlot(lazer)
- if device.charge > 10000 then
- r.select(lazer)
- i_c.equip()
- r.select(cobble)
- else
- findlazerinchest()
- end
- else
- findlazerinchest()
- end
- end
- end
- --идём по Х в 0 координат
- local function x_forward()
- for xx = 1,x-1 do
- while true do
- if r.forward() then
- xPos = xPos - 1
- break
- else
- r.use()
- end
- end
- end
- end
- --идём вперед
- local function go_forward()
- local tru = 0
- while true do
- if r.forward() then
- xPos = xPos + xDir
- zPos = zPos + zDir
- break
- else
- r.use()
- tru = tru + 1
- if tru == 3 then
- lazerequip()
- end
- if tru >= 10 then
- tru = 0
- returnHome("непреодолимое препятствие :(" , true)
- end
- end
- end
- end
- --спускаемся отлавливая бедрок
- local function go_down()
- for zz = 1,z do
- local tru = 0
- while true do
- if r.down() then
- depth = depth + 1
- break
- else
- r.useDown()
- tru = tru + 1
- if tru >= 5 then
- stepdown = true
- print("низ достигнут !")
- lazerequip()
- r.useUp()
- for i = 1,2 do
- if r.up() then
- depth = depth - 1
- end
- end
- xP,yP,zP,xD,zD = xPos,depth,zPos,xDir,zDir
- while true do
- r.use()
- if not r.detect() then
- return
- else
- if r.up() then
- depth = depth - 1
- end
- tru = tru + 1
- if tru >= 10 then
- tru = 0
- returnHome("непреодолимое препятствие :(" , false)
- goTo( xP,yP,zP,xD,zD )
- return
- end
- end
- end
- end
- end
- end
- end
- end
- --поворот в лево
- local function turnLeft()
- r.turnLeft()
- xDir, zDir = -zDir, xDir
- end
- --поворот в право
- local function turnRight()
- r.turnRight()
- xDir, zDir = zDir, -xDir
- end
- --навигация к сундуку
- function goTo( xP, yP, zP, xD, zD )
- while depth > yP do
- if r.up() then
- depth = depth - 1
- else
- r.useUp()
- r.swingUp()
- end
- end
- if xPos > xP then
- while xDir ~= -1 do
- turnLeft()
- end
- while xPos > xP do
- if r.forward() then
- xPos = xPos - 1
- else
- r.use()
- r.swing()
- end
- end
- elseif xPos < xP then
- while xDir ~= 1 do
- turnLeft()
- end
- while xPos < xP do
- if r.forward() then
- xPos = xPos + 1
- else
- r.use()
- r.swing()
- end
- end
- end
- if zPos > zP then
- while zDir ~= -1 do
- turnLeft()
- end
- while zPos > zP do
- if r.forward() then
- zPos = zPos - 1
- else
- r.use()
- r.swing()
- end
- end
- elseif zPos < zP then
- while zDir ~= 1 do
- turnLeft()
- end
- while zPos < zP do
- if r.forward() then
- zPos = zPos + 1
- else
- r.use()
- r.swing()
- end
- end
- end
- while depth < yP do
- if r.down() then
- depth = depth + 1
- else
- r.useDown()
- r.swingDown()
- end
- end
- while zDir ~= zD or xDir ~= xD do
- turnLeft()
- end
- end
- --возврат к старту
- function returnHome(message, savepoint)
- if savepoint then
- xP,yP,zP,xD,zD = xPos,depth,zPos,xDir,zDir
- end
- goTo( 0,0,0,0,-1 )
- sortlut(true)
- goTo( 0,0,0,0,1 )
- print("\n".."!!! стоп !!!".."\n"..message.."\n")
- r.setLightColor(0xFF0000)
- computer.beep(2000, 3)
- io.write("продолжить копать ? (y/n) >")
- oq = io.read()
- if oq == "y" or oq == "Y" then
- r.setLightColor(0xFFFFFF)
- print("продолжаю копать...")
- goTo( xP,yP,zP,xD,zD )
- else
- print("программа завершена")
- os.exit()
- end
- end
- --копаем
- local function start()
- r.setLightColor(0xFFFFFF)
- print("размер карьера: X "..x.." Y "..y.." Z "..z)
- while true do
- lazerequip()
- checkfuel()
- checkenergy()
- print("опускаюсь на "..z.." блоков...")
- r.select(cobble)
- go_down()
- print("копаю...")
- for xx = 1,x do
- for yy = 1,y-1 do
- go_forward()
- placecobble()
- r.useUp()
- lazerequip()
- checkfuel()
- checkenergy()
- while tb.suck() do
- if r.count(invsize) > 0 then
- sortlut()
- placecobble()
- end
- end
- end
- if xx ~= x then
- if ridht then
- turnRight()
- go_forward()
- turnRight()
- ridht = false
- else
- turnLeft()
- go_forward()
- turnLeft()
- ridht = true
- end
- placecobble()
- r.useUp()
- fuelinv = true
- end
- end
- if ridht then
- turnLeft()
- x_forward()
- turnLeft()
- ridht = false
- else
- turnRight()
- x_forward()
- turnRight()
- ridht = true
- end
- if stepdown then
- goTo( 0,0,0,0,-1 )
- sortlut(true)
- r.turnAround()
- print("\n".."завершил копать :)")
- r.setLightColor(0xFF0000)
- computer.beep(2000, 3)
- os.exit()
- end
- end
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement