Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local r = require('robot')
- local comp = require('computer')
- local term = require('term')
- local sides = require('sides')
- local inv = require('component').inventory_controller
- local fs = require('filesystem')
- --================СПИСОК БЛОКОВ ДЛЯ ЗАПОЛНЕНИЯ================--
- musor={}
- musor['minecraft:stone'] = true
- musor['minecraft:cobblestone'] = true
- musor['minecraft:dirt'] = true
- musor['minecraft:gravel'] = true
- musor['minecraft:sandstone'] = true
- musor['minecraft:stonebrick'] = true
- --================ПОИСК БЛОКОВ ДЛЯ РАВНЕНИЯ===================--
- function poisk(slots)
- for slot = 1, slots do
- if r.count(slot) > 0 then
- if musor[inv.getStackInInternalSlot(slot).name] ~= nil then
- r.select(slot)
- return true
- end
- end
- end
- return false
- end
- --=======ЗАПОЛНЕНИЕ ИНВЕНТАРЯ БЛОКАМИ ДЛЯ СТРОИТЕЛЬСТВА========--
- function zapoln(slot1)
- for a=1,inv.getInventorySize(3) do
- if inv.getStackInSlot(3,a) ~= nil then
- if musor[inv.getStackInSlot(3,a).name] then
- r.select(slot1)
- inv.suckFromSlot(3,a)
- return true
- end
- end
- end
- return false
- end
- function placeDown()
- while not r.placeDown() do
- r.swingDown()
- end
- end
- function place(a)
- while not r.place(a) do
- r.swing()
- end
- end
- loc = {x=0, y=0, z=0, b=0}
- function forward()
- while not r.forward() do
- r.swing()
- end
- if loc.b == 0 then loc.y = loc.y+1
- elseif loc.b == 1 then loc.x = loc.x+1
- elseif loc.b == 2 then loc.y = loc.y-1
- else loc.x = loc.x-1 end
- return true
- end
- function back()
- if not r.back() then
- r.turnAround()
- while not r.forward() do
- r.swing()
- end
- r.turnAround()
- end
- if loc.b == 0 then loc.y = loc.y-1
- elseif loc.b == 1 then loc.x = loc.x-1
- elseif loc.b == 2 then loc.y = loc.y+1
- else loc.x = loc.x+1 end
- return true
- end
- function up()
- while not r.up() do
- r.swingUp()
- end
- loc.z = loc.z+1
- return true
- end
- function down()
- while not r.down() do
- r.swingDown()
- end
- loc.z = loc.z-1
- return true
- end
- function turnRight()
- loc.b = (loc.b+1)%4
- r.turnRight()
- end
- function turnAround()
- loc.b = (loc.b+2)%4
- r.turnAround()
- end
- function turnLeft()
- loc.b = (loc.b+3)%4
- r.turnLeft()
- end
- function d1()
- local d = loc.b
- local p = loc.x
- local t = loc.y
- local g = loc.z
- if loc.b ~= 2 then
- while loc.b ~= 2 do
- turnRight()
- end
- end
- if loc.z>0 then
- while loc.z > 0 do
- down()
- end
- end
- if loc.z < 0 then
- while loc.z < 0 do
- up()
- end
- end
- if loc.x > 0 then
- turnRight()
- while loc.x > 0 do
- forward()
- end
- turnLeft()
- end
- while loc.y > 0 do
- forward()
- end
- while comp.energy() < comp.maxEnergy() * 0.8 do
- os.sleep(8)
- end
- turnRight()
- for i=1,11 do
- r.select(i)
- r.drop()
- end
- for i=1,8 do
- while not zapoln(i) do
- os.sleep(0.2)
- end
- end
- turnRight()
- while loc.y ~= t do
- forward()
- end
- if loc.x ~= p then
- turnRight()
- while loc.x ~=p do
- forward()
- end
- end
- if loc.b ~= d then
- while loc.b ~= d do
- turnLeft()
- end
- end
- if g<0 then
- while loc.z>g do
- down()
- end
- end
- if g>0 then
- while loc.z<g do
- up()
- end
- end
- end
- function t()
- local bl,en=r.detectUp()
- if en == 'solid' then
- while (en=='solid') and (loc.z<10) do
- up()
- r.swingUp()
- bl,en=r.detectUp()
- end
- while loc.z>0 do
- down()
- end
- end
- local bl,en = r.detectDown()
- if en ~= 'solid' then
- while en ~= 'solid' do
- down()
- bl,en = r.detectDown()
- end
- while loc.z<-1 do
- up()
- inventar()
- placeDown()
- end
- up()
- end
- r.select(16)
- if (r.compareDown()==false) or (r.detectDown()==false) then
- r.swingDown()
- inv1()
- end
- end
- function inv1()
- r.select(12)
- if r.count()==0 then
- local b = 12
- while (r.count() == 0) and (b <=16) do
- r.select(b)
- b=b+1
- end
- end
- placeDown()
- r.select(a)
- end
- function rastasovka()
- t1={}
- t1['minecraft:hopper']={slot=1,kol=17}
- t1['minecraft:dirt']={slot=2,kol=16}
- t1['minecraft:torch']={slot=3,kol=12}
- t1['minecraft:chest']={slot=4,kol=4}
- t1['minecraft:water_bucket']={slot=5,kol=1}
- t1['minecraft:sapling']={slot=16,kol=64}
- b4 = 'minecraft:water_bucket'
- for i1=1,9 do
- r.select(t1[inv.getStackInSlot(3, i1).name].slot)
- inv.suckFromSlot(3,i1,t1[inv.getStackInSlot(3, i1).name].kol)
- if inv.getStackInSlot(3, i1+1) ~= nil then
- if inv.getStackInSlot(3,i1+1).name=='minecraft:water_bucket' and inv.getStackInInternalSlot(t1['minecraft:water_bucket'].slot) ~=nil then
- t1['minecraft:water_bucket'].slot = t1['minecraft:water_bucket'].slot+1
- end
- end
- end
- t1 = nil
- i1 = nil
- end
- function inventar()
- if not poisk(11) then
- d1()
- end
- end
- function usl1()
- if comp.energy() < comp.maxEnergy()*0.5 then
- d1()
- elseif r.count(9) > 0 then
- d1()
- end
- end
- function file()
- if fs.exists('Progr') == true then
- file = io.open("Progr","r")
- Prog = file:read()+0
- file:close()
- end
- end
- Progr = 0
- file()
- if Prog ~=1 then
- t()
- for o=1,13 do
- for i=1,16 do
- forward()
- usl1()
- t()
- end
- if o < 13 then
- while loc.b<1 do
- turnRight()
- end
- while loc.b>1 do
- turnLeft()
- end
- forward()
- usl1()
- t()
- if (o)%2==0 then
- turnLeft()
- else
- turnRight()
- end
- end
- end
- up()
- for i=1,4 do
- turnLeft()
- for i=1,12 do
- forward()
- inv1()
- end
- end
- if loc.b ~= 2 then
- while loc.b ~= 2 do
- turnRight()
- end
- end
- if loc.x > 0 then
- turnRight()
- while loc.x > 0 do
- forward()
- end
- turnLeft()
- end
- while loc.y > 0 do
- forward()
- end
- down()
- turnRight()
- for i=1,16 do
- r.select(i)
- os.sleep(0.2)
- r.drop()
- end
- turnLeft()
- rastasovka()
- r.select(4)
- turnAround()
- up()
- for i=1,10 do
- forward()
- end
- turnRight()
- for i=1,6 do
- forward()
- end
- down()
- r.select(9)
- r.swingDown()
- down()
- for i=1,3 do
- for i=1,3 do
- r.swing()
- forward()
- end
- for i=1,3 do
- back()
- end
- turnLeft()
- end
- for i=1,5 do
- r.swing()
- forward()
- end
- turnRight()
- for i=1,3 do
- r.swing()
- forward()
- end
- turnLeft()
- for i=1,3 do
- r.swing()
- forward()
- end
- turnLeft()
- r.swing()
- forward()
- up()
- r.select(4)
- forward()
- place()
- back()
- place()
- down()
- back()
- place()
- turnRight()
- back()
- place()
- r.select(1)
- for i=1,2 do
- back()
- place(3)
- end
- turnRight()
- back()
- place(5)
- for i=1,2 do
- back()
- place(3)
- end
- turnLeft()
- back()
- place(4)
- for i=1,7 do
- back()
- place(3)
- end
- up()
- r.select(9)
- placeDown()
- r.select(1)
- turnLeft()
- for i=1,3 do
- forward()
- end
- turnRight()
- for i=1,3 do
- forward()
- end
- turnRight()
- down()
- forward()
- place(3)
- back()
- place(3)
- up()
- r.select(9)
- placeDown()
- r.select(1)
- up()
- for i=1,6 do
- forward()
- end
- turnAround()
- for i=1,2 do
- down()
- end
- forward()
- place(3)
- back()
- place(3)
- up()
- r.select(9)
- r.placeDown()
- r.select(2)
- turnLeft()
- for i=1,2 do
- forward()
- end
- turnRight()
- up()
- for i=1,2 do
- for o=1,4 do
- down()
- r.select(2)
- turnLeft()
- place()
- turnAround()
- place()
- turnLeft()
- up()
- r.select(16)
- turnLeft()
- place()
- turnAround()
- place()
- turnLeft()
- if o<4 then
- forward()
- end
- forward()
- end
- if i<2 then
- turnRight()
- for i=1,4 do
- forward()
- end
- turnRight()
- forward()
- end
- end
- forward()
- turnLeft()
- for i=1,3 do
- forward()
- end
- turnAround()
- for i=1,4 do
- for o=1,11 do
- if (o==1) or (o==6) or (o==11) then
- r.select(3)
- turnLeft()
- place()
- turnRight()
- end
- if o<11 then
- forward()
- end
- end
- r.select(i+4)
- turnRight()
- inv.equip()
- r.useDown()
- end
- r.select(15)
- inv.equip()
- for i=1,2 do
- turnRight()
- forward()
- if i==2 then
- forward()
- end
- end
- turnRight()
- while loc.x>0 do
- forward()
- end
- turnLeft()
- while loc.y>0 do
- forward()
- end
- down()
- for i=1,15 do
- r.select(i)
- r.drop()
- end
- turnAround()
- while loc.y<2 do
- forward()
- end
- turnRight()
- while loc.x<4 do
- forward()
- end
- turnLeft()
- r.select(1)
- Progr=1
- file = io.open("Progr","w")
- file:write(Progr)
- file:close()
- end
- loc = {x=0, y=0, z=0, b=0}
- function dom(noreturn)
- -- двигаемся домой
- local d = loc.b
- local p = loc.x
- local t = loc.y
- if loc.b ~= 2 then
- while loc.b ~= 2 do
- turnRight()
- end
- end
- if loc.x > 0 then
- turnRight()
- while loc.x > 0 do
- forward()
- end
- turnLeft()
- end
- while loc.y > 0 do
- forward()
- end
- while loc.z>0 do
- down()
- end
- turnLeft()
- -- выгрузка дерева
- for i=1,15 do
- r.select(i)
- if r.compareTo(16)==true then
- r.dropDown()
- else
- r.drop()
- end
- end
- -- забираем саженцы
- r.select(16)
- r.suckDown(64-r.count(16))
- -- зарядка
- while comp.energy() < 25000 do
- os.sleep(8)
- end
- turnLeft()
- -- возвращаемся если нет флага "в один конец"
- if not noreturn then
- while loc.z<2 do
- up()
- end
- while loc.y ~= t do
- forward()
- end
- if loc.x ~= p then
- turnRight()
- while loc.x ~=p do
- forward()
- end
- end
- if loc.b ~= d then
- while loc.b ~= d do
- turnLeft()
- end
- end
- end
- end
- -- Проверка условий, на возврат домой
- function usl()
- if r.count(15) > 32 then
- dom()
- end
- if r.count(16) < 8 then
- dom()
- end
- if comp.energy() < 11000 then
- dom()
- end
- end
- -- Робот определяет выросло ли дерево и рубит его
- function axe()
- if r.detect() == true then
- r.select(1)
- r.swing()
- forward()
- r.swingDown()
- -- робот рубит дерево
- while r.compareUp() == true do
- r.swingUp()
- up()
- end
- -- возвращается
- while loc.z ~= 2 do
- down()
- r.swingDown()
- end
- r.select(16)
- placeDown()
- r.select(1)
- back()
- end
- end
- -- ======================== Г Л А В Н Ы Й Ц И К Л ======================== --
- -- робот движется по полю по кругу,
- -- и рубит выросшие деревья
- while true do
- -- робот едет на стартовую позицию
- -- (левый передний угол поля)
- for i=1,2 do
- up()
- end
- for i=1,4 do
- forward()
- end
- -- проход по ферме
- for i=1, 8 do
- -- проверка дерева слева и справа
- usl()
- forward()
- turnLeft()
- axe()
- turnAround()
- axe()
- turnLeft()
- forward()
- -- если робот прошел первые 4 пары деревьев,
- -- движемся ко второму ряду
- if i == 4 then
- turnRight()
- for c=1, 4 do forward() end
- turnRight()
- end
- end
- -- робот возвращается домой
- -- (флаг true означает - в один конец)
- dom(true)
- -- робот спит и видит сны =)
- print('Progress of sleeping')
- for i=1,10 do
- os.sleep(72)
- print(i*10,' %')
- end
- term.clear()
- print('moving')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement