Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get -f 0CpP3Jzy mine.lua
- local robot=require("robot")
- local component=require("component")
- local computer=require("computer")
- local ic = component.inventory_controller
- local a = {...}
- local xLength=tonumber(a[1]) or 48
- local yLength=tonumber(a[2]) or 48
- local zDepth=tonumber(a[3]) or 7
- local dLayer=tonumber(a[4]) or 3
- local nStart=5
- local tDumpster ={
- "minecraft:cobblestone",
- "minecraft:dirt",
- "minecraft:gravel",
- "chisel:granite",
- "chisel:limestone",
- "chisel:andesite",
- "chisel:diorite"
- }
- if component.isAvailable("chunkloader")
- then
- component.chunkloader.setActive(true)
- end
- -- Добыча 1 столба
- local function prey()
- while not robot.forward() do robot.swing() os.sleep(0,5) end
- while robot.swingUp() do os.sleep(0,5) end
- robot.swingDown()
- end
- -- Спуск на заданную глубину
- local function preyDown(dLL)
- for dLLL=1,dLL do
- while not robot.down() do robot.swingDown() end
- end
- end
- -- Добыча 1 траншеи
- local function trench(ll)
- for lll=1,ll do
- prey()
- -- while robot.durability()*1000000<100 do os.sleep(180) end
- end
- end
- -- Перемещение на заданное расстояние
- local function moveLine(ll)
- while ll>1 do while not robot.forward() do robot.swing() os.sleep(0,5) end ll=ll-1 end
- end
- -- 1 слот - кирка
- local nKir=1
- -- 2 слот - рычаг
- local nRyc=2
- -- 3 слот - зарядник
- local nZar=3
- -- 4 слот - трансивер
- local nTra=4
- local function goForward()
- while not robot.forward() do robot.swing() os.sleep(0,5) end
- robot.suck()
- return true
- end
- local function goUp()
- while not robot.up() do robot.swingUp() end
- end
- local function goDown()
- while not robot.down() do robot.swingDown() end
- end
- local function goBack()
- if not robot.back() then robot.turnAround() goForward() robot.turnAround() end
- end
- local function doPlace(nSlot)
- robot.select(nSlot)
- while not robot.place() do robot.select(nStart) goForward() goBack() robot.select(nSlot) end
- robot.select(nStart)
- end
- local function suckDrill()
- ll=false
- for jj=9,16 do if ic.getStackInSlot(3,jj) ~= nil then if ic.getStackInSlot(3,jj).label=="bamik_drill" then ic.suckFromSlot(3,jj) ll=true end end end
- return ll
- end
- -- Проверка на мусор
- local function dumpster(sNN)
- local log=false
- local i,j=1,#tDumpster
- repeat
- if sNN==tDumpster[i] then log=true end
- i=i+1
- until log or i>j
- return log
- end
- -- Выгрузка инвентаря в указанную сторону. Если нет сундука, то выброс мусора и уплотнение.
- -- Слоты до указанного не трогаются.
- local function drop()
- if ic.getInventorySize(3) ~= nil then
- for i = robot.inventorySize(), nStart, -1 do
- robot.select(i)
- while robot.count()>0 do robot.drop() end
- end
- else
- local i,j=nStart, robot.inventorySize()
- while i ~= j do
- robot.select(j)
- local t = ic.getStackInInternalSlot(j)
- if t ~= nil then
- local sN = t.name
- if dumpster(sN) then robot.drop() j=j-1
- else robot.transferTo(i) i=i+1
- end
- else
- j=j-1
- end
- end
- end
- end
- local function zaryad()
- goForward()
- -- Устанавливаем трансивер
- doPlace(nTra)
- -- Заряжаем лазер или бур
- robot.select(nKir) ic.equip() robot.drop() drop() robot.select(nKir) os.sleep(120) ic.equip() robot.select(nStart)
- -- Устанавливаем зарядник
- goUp() doPlace(nZar)
- -- Устанавливаем рычаг и включаем его
- goUp() robot.select(nRyc) robot.placeDown(3) ic.equip() robot.useDown(3) ic.equip() robot.select(nStart)
- -- Встаем на зарядку
- goForward() while computer.energy()<0.99* computer.maxEnergy() do os.sleep(15) end
- -- Снимаем
- robot.select(nKir)
- goBack() goDown() goForward()
- goBack() goDown() goForward()
- goBack() goBack() robot.select(nStart)
- end
- local function servicing()
- -- Если инвентарь заполнился, то выброс мусора.
- -- Свободного места до переполнения, должно хватить от проверки до проверки. Оставляем 5 слотов.
- -- Для добычи в ваниле, можно оставить 2.
- robot.select(1) ic.equip()
- local tL=ic.getStackInInternalSlot(1)
- ic.equip()
- local robEn=computer.energy()/computer.maxEnergy()
- local lasDm=tL.damage/tL.maxDamage
- -- Если разрядился робот, бур или заполнился инвентарь, то проводим обслуживание.
- if (robot.count(robot.inventorySize()-5)>0) or (robEn<0.1) or (lasDm>0.9) then zaryad() end
- end
- -- Тело программы
- -- Текущая глубина копания
- local zD=zDepth
- -- Текущая толщина слоя копания
- local dL=dLayer
- repeat
- print(zD,dL)
- xL=xLength
- yL=yLength-1
- repeat
- trench(xL)
- xL=xL-1
- servicing()
- robot.turnRight()
- trench(yL)
- yL=yL-1
- servicing()
- robot.turnRight()
- until xL<1 or yL<0
- -- Очищаемся от мусора перед возвратом в исходную позицию.
- -- drop()
- -- Вычисление длины "обратного" хода
- local xyBack=math.ceil((math.min(xLength, yLength)-1)/2)+1
- if math.min(xLength, yLength)%2 == 0 then
- yBack=xyBack
- xBack=yBack
- else
- robot.turnAround()
- if xLength-yLength<=0 then
- yBack=yLength-xyBack+1
- xBack=xyBack+1
- else
- xBack=xLength-xyBack+2
- yBack=xyBack
- end
- end
- robot.turnLeft()
- moveLine(yBack)
- robot.turnLeft()
- moveLine(xBack)
- robot.turnAround()
- zD=zD-dL
- dL=math.min(zD,dL)
- preyDown(dL)
- until dL<1
- for k=1,zDepth do goUp() end
- zaryad()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement