Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Если бур надо заряжать, в первый слот кладем
- --энергохранилище во второй ключ, ставим
- --на игнор 2 слота и подключаем апгрейд
- --контроллера инвентаря
- ------------Настройки---------------
- incont=false;--заряжать кирку?
- slots=32;--количество слотов у робота?
- propusk=1;--игнорировать первые N слотов
- slotstocheck=2;--выгрузка если заполнены последние N слотов
- cobblestone=1
- ------------Переменные---------------
- local computer = require('computer')
- local component = require("component")
- if require("component").isAvailable("generator") then
- generator=require("component").generator
- end
- if require("component").isAvailable("inventory_controller") then
- incontrol=require("component").inventory_controller
- end
- if require("component").isAvailable("chunkloader") then
- component.chunkloader.setActive(true)
- loader=require("component").chunkloader
- end
- robot=require("robot")
- withg=(generator~=nil)
- propusk=propusk+1;
- coords={x=0,y=0,z=0,side=1}
- extcoords={x=0,y=0,z=0,side=1}
- sx={0,1,0,-1}
- sy={1,0,-1,0}
- -------------Функции-----------------
- function go() while not robot.forward() do robot.swing()end coords.x=coords.x + sx[coords.side];coords.y = coords.y + sy[coords.side] end
- function godown() while not robot.down() do robot.swingDown()end coords.z = coords.z - 1 end
- function goup() while not robot.up() do robot.swingUp()end coords.z = coords.z + 1 end
- function check() return robot.count(slots-(slotstocheck-1)) > 0 end
- function energy() return computer.energy()<((computer.maxEnergy()*10)/100) end
- function energy2() return computer.energy()<((computer.maxEnergy()*70)/100) end
- function turnLeft() robot.turnLeft(); coords.side = (coords.side + 3)%4;if coords.side == 0 then coords.side =4 end; end
- function turnRight() robot.turnRight(); coords.side = (coords.side + 1)%4; if coords.side == 0 then coords.side =4 end; end
- function tosurf()
- extcoords.x=coords.x
- extcoords.y=coords.y
- extcoords.z=coords.z
- extcoords.side=coords.side
- while coords.z ~= 0 do goup() end
- while coords.side ~= 3 do turnRight() end
- while coords.y ~= 0 do go() end
- turnRight();
- while coords.x ~= 0 do go() end
- turnLeft();
- end
- function back()
- while coords.z ~= extcoords.z do godown() end
- while coords.side~= 1 do turnRight() end
- while coords.y ~= extcoords.y do go() end
- turnRight();
- while coords.x ~= extcoords.x do go() end
- while coords.side ~= extcoords.side do turnRight() end
- end
- function clearinv()
- alreadyhave=false
- for invcounter=propusk,slots do
- robot.select(invcounter)
- if withg then
- suc,error=generator.insert()
- if (error=="selected slot does not contain fuel" or alreadyhave) then
- robot.drop()
- else
- alreadyhave=true
- end
- else
- robot.drop()
- end
- end
- robot.select(1)
- end
- function cobbleDel()
- if incontrol.getStackInInternalSlot(cobblestone).name=='minecraft:cobblestone' or 'Mars Cobblestone' then
- if robot.count(cobblestone)>1 then
- robot.select(cobblestone)
- if robot.count()==1 then
- robot.select(1)
- else
- robot.dropDown(robot.count()-1)
- robot.select(1)
- end
- end
- end
- end
- function charg()
- print("Уровень энергии." ,computer.energy())
- if (energy2()) then
- refuel()
- end
- if (computer.energy())<((computer.maxEnergy()*30)/100) then
- print("меньше 30 %")
- while energy() do
- for i=1, 10 do
- os.sleep(20)
- print("Ожидаю ",(10*i)..'%')
- end
- end
- end
- end
- function refuel() -- Заправка генератора
- for invfuel=1,slots do
- robot.select(invfuel)
- generator.insert(33)
- if generator.count() >= 32 then
- print("заправка зевершена")
- print("топлива в генераторе = "..generator.count())
- do break end
- end
- end
- end
- function prevent()
- print (("полный? -"),(check()),("энергия -"),(energy())) --,("кирка -"),(robot.durability()>0.01))
- if ((check()) or (energy())) then
- tosurf()
- clearinv()
- charg()
- back()
- end
- end
- function digrow(n)
- prevent()
- robot.swingUp()
- robot.swingDown()
- for k=1,n do
- go()
- robot.swingUp()
- robot.swingDown()
- cobbleDel()
- prevent()
- end
- end
- function digdim(x,y)
- godown()
- godown()
- for n=1,y do
- if tl then turnLeft() else turnRight() end
- digrow(ex)
- if tl then turnRight() else turnLeft() end
- tl = not tl
- if n==y then print("ok") else go() end
- end
- turnRight();
- turnRight();
- tl= not tl
- end
- ------------Глав прог-----------------
- x,y,z=...
- tl=false
- x=x+0
- y=y+0
- z=z+0
- ex=x-1
- fullz=(z-z%3)/3
- print("Fullz = " .. fullz)
- refuel()
- do
- if incont==true then
- if (incontrol~=nil)==false then
- print("!!!ОШИБКА!!!")
- print("Вы забыли установить контроллер инвентаря, зарядка невозможна без него")
- print("Продолжить работать без него?(1-продолжить, 0-выйти)")
- a=io.read(1)
- if a=='1' then
- print('Продолжаем работать, зарядка отключена')
- incont=false;
- else
- print('Инициализация выхода...')
- os.sleep(3)
- computer.shutdown()
- end
- else
- print('Контроллер инвентаря подключен, бур будет заряжаться, не забудьте положить энергохранилище и ключ')
- end
- else
- print('Зарядка рабочего инструмента отключена')
- end
- end
- print('Запуск генератора... ',generator~=nil)
- print('Запуск чанклодера... ',loader~=nil)
- print('Объем рабочей зоны - ',x*y*z,' м^3, будет добыто ~',math.ceil((x*y*z)/64))
- print('Проверка завершена, запуск...')
- for i=1,fullz do
- digdim(x,y)
- godown()
- end
- if fullz*3==z then
- elseif fullz*3+1==z then
- goup();
- goup();
- digdim(tl,x,y)
- else
- goup();
- digdim(tl,x,y)
- end
- tosurf()
- clearinv()
- computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement