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')
- x1=10
- y1=13
- --================СПИСОК БЛОКОВ ДЛЯ ЗАПОЛНЕНИЯ================--
- 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 find()
- for i = 12,16 do
- r.select(i)
- if r.compareTo(16) == true then
- r.select(slot)
- end
- end
- end
- --================ПОИСК БЛОКОВ ДЛЯ РАВНЕНИЯ===================--
- 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
- --========================НАВИГАЦИЯ============================--
- 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 dom()
- 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
- for i=13,16 do
- r.select(i)
- if not r.compareTo(16) then
- if r.count(i)>0 then
- turnRight()
- r.drop()
- turnLeft()
- end
- end
- if r.count(i)<64 then
- while not r.suck(64-r.count(i)) do
- os.sleep(0.2)
- end
- end
- end
- turnRight()
- for i=1,12 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 rovnenie()
- 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()
- find()
- placeDown()
- end
- end
- function inventar()
- if not poisk(12) then
- dom()
- end
- end
- --======================УСЛОВИЯ ДЛЯ ВОЗВРАТА ДОМОЙ======================--
- function usl()
- if r.count(12) > 0 then
- dom()
- elseif r.count(1) < 32 then
- dom()
- elseif r.count(15) < 32 then
- dom()
- elseif comp.energy() < comp.maxEnergy()*0.8 then
- dom()
- end
- end
- --============================ГЛАВНЫЙ ЦИКЛ==============================--
- usl()
- rovnenie()
- for o=1,x1 do
- for i=1,y1 do
- forward()
- usl()
- rovnenie()
- end
- if o < x1 then
- while loc.b<1 do
- turnRight()
- end
- while loc.b>1 do
- turnLeft()
- end
- forward()
- usl()
- rovnenie()
- if (o)%2==0 then
- turnLeft()
- else
- turnRight()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement