Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tree Farm by Andronio
- local tArgs = {...} -- Данные, вводимые в самом начале
- local r = require("robot") -- Робот
- local cmp = require("component") -- Компонент
- local computer = require("computer") -- Компьютер
- local term = require('term')
- local gz = cmp.geolyzer -- Геолизёр
- local tb = cmp.tractor_beam -- Тянущий луч
- local ic = cmp.inventory_controller -- Контроллер Инвентаря
- local event = require('event')
- local delay = 0 -- В секундах
- local grid_x = 0 -- Размер сетки по X
- local grid_y = 0 -- Размер сетки по Y
- local layers = 0 -- Количесто слоев
- local layer_h = 0 -- Высота слоя
- local remainlayers = layers -- Осталось слоев. Для мультислойной фермы
- local iscoalfarm = false -- Является ли ферма угольной
- local upstate = 0
- term.clear()
- if tArgs[1] == 'help' then
- io.write('Запуск:\nwoodman start X Y delay layers layer_h IsCoalFarm\n')
- io.write('Задержка в секундах. Если слой один -\nвысоту не указывать!')
- io.write('\nIsCoalFarm - является ли ферма угольной\nTrue - если да, False - если нет\n')
- io.write('Например:\nwoodman start 10 8 1200 1 0 true\n')
- io.write('\nВ разработке:')
- io.write('\nСохранение в файл:\nwoodman save X Y delay layers layer_h IsCoalFarm\n')
- io.write('Если вы сохранили в файл, то можно запустить так:\nwoodman start saved')
- io.write('Чтобы посмотреть оставшееся время, зажмите C и D\n Чтобы остановить программу, зажмите S и P')
- os.exit()
- elseif tArgs[1] == 'start' then
- if #tArgs > 5 then
- grid_x = tonumber(tArgs[2])
- grid_y = tonumber(tArgs[3])
- delay = tonumber(tArgs[4])
- layers = tonumber(tArgs[5])
- if layers > 1 then
- layer_h = tonumber(tArgs[6])
- if tArgs[7] == 'true' then
- iscoalfarm = true
- elseif tArgs[7] == 'false' then
- iscoalfarm = false
- else
- print('Неверный 6-й аргумент!')
- os.exit()
- end
- elseif layers == 1 then
- if tArgs[6] == 'true' then
- iscoalfarm = true
- elseif tArgs[6] == 'false' then
- iscoalfarm = false
- else
- print('Неверный 5-й аргумент!')
- os.exit()
- end
- end
- elseif tArgs[2] == 'saved' then
- -- Когда-то и здесь появится код... А пока что:
- os.exit()
- elseif #tArgs == 1 then
- print('Загляните в woodman help для помощи!')
- os.exit()
- elseif #tArgs < 6 then
- print('Недостаточно аргументов!')
- os.exit()
- end
- elseif tArgs[1] == 'save' then
- -- Когда-то и здесь появится код...
- elseif #tArgs == 0 then
- print('Загляните в woodman help для помощи!')
- os.exit()
- else
- print('Невозможно распознать команду! Воспользуйтесь одной из этих: help, start, save(в разработке). Также загляните в woodman help для помощи!')
- os.exit()
- end
- function report(msg)
- print(msg)
- if cmp.isAvailable('tunnel') then
- cmp.tunnel.send(msg)
- end
- end
- function forward()
- while r.detect() do
- r.swing()
- end
- if not r.forward() then
- forward()
- end
- end
- function up()
- while r.detectUp() do
- r.swingUp()
- end
- if not r.up() then
- up()
- end
- end
- function down()
- while r.detectDown() do
- r.swingDown()
- end
- if not r.down() then
- down()
- end
- end
- function checkforlog()
- local item_id = gz.analyze(3).name
- if item_id == 'minecraft:log' then
- if upstate == 1 then
- down()
- upstate = 0
- end
- r.swing()
- if iscoalfarm == true then
- for i=1,40 do
- tb.suck()
- end
- else
- for i=1,16 do
- tb.suck()
- end
- end
- for i=1,2 do
- forward()
- end
- elseif item_id == 'minecraft:sapling' then
- up()
- upstate = 1
- for i=1,2 do
- forward()
- end
- else
- for i=1,2 do
- forward()
- end
- end
- end
- if grid_x < 1 then
- print('Размер сетки по оси X не может быть меньше 1!')
- computer.beep(1000,2.5)
- os.exit()
- end
- if grid_y < 1 then
- print('Размер сетки по оси Y не может быть меньше 1!')
- computer.beep(1000,2.5)
- os.exit()
- end
- if delay < 1 then
- print('Задержка не может быть меньше 1!')
- computer.beep(1000,2.5)
- os.exit()
- end
- if layers < 1 then
- print('Количество слоев не может быть меньше 1!')
- computer.beep(1000,2.5)
- os.exit()
- end
- if layers > 1 then
- if layer_h < 7 then
- print('Высота одного слоя не может быть меньше 7!')
- computer.beep(1000,2.5)
- os.exit()
- end
- end
- r.select(1)
- function checkforsapling()
- local hassapl = false
- local item = gz.analyze(0).name
- if item == 'minecraft:air' then
- for i=1,4 do
- if ic.getStackInInternalSlot(i) then
- if ic.getStackInInternalSlot(i).name == 'minecraft:sapling' then
- r.select(i)
- hassapl = true
- break
- end
- end
- end
- if not hassapl then
- report('Саженцев не найдено, либо они закончились!')
- hassapl = false
- computer.beep(1000,10)
- while not hassapl do
- os.sleep(15)
- for i=1,4 do
- if ic.getStackInInternalSlot(i) then
- if ic.getStackInInternalSlot(i).name == 'minecraft:sapling' then
- r.select(i)
- hassapl = true
- report('Саженцы обнаружены! Продолжаю работу!')
- break
- end
- end
- end
- computer.beep(1000,1)
- end
- end
- ic.equip()
- r.useDown()
- ic.equip()
- end
- for i=1,2 do
- tb.suck()
- end
- end
- function move_y()
- for i=1,grid_y do
- checkforlog()
- end
- r.turnAround()
- if upstate == 0 then
- up()
- upstate = 1
- end
- for i=1,grid_y do
- forward()
- checkforsapling()
- forward()
- end
- down()
- upstate = 0
- if grid_x == 1 then
- forward()
- r.turnAround()
- else
- r.turnLeft()
- for i=1,2 do
- forward()
- end
- r.turnLeft()
- end
- end
- function move_x()
- if grid_x > 1 then
- local lol3 = grid_x - 1
- for i=1,lol3 do
- move_y()
- end
- r.turnLeft()
- local lol2 = grid_x*2
- for i=1,lol2 do
- forward()
- end
- if layers == 1 then
- r.turnLeft()
- forward()
- r.turnAround()
- else
- r.turnRight()
- end
- end
- end
- local is = r.inventorySize()
- function unload()
- r.turnRight()
- local s1,s2,s3,s4=0,0,0,0
- for i=1,4 do
- if ic.getStackInInternalSlot(i) then
- if i == 1 then
- s1 = ic.getStackInInternalSlot(1).size
- elseif i == 2 then
- s2 = ic.getStackInInternalSlot(2).size
- elseif i == 3 then
- s3 = ic.getStackInInternalSlot(3).size
- elseif i == 4 then
- s4 = ic.getStackInInternalSlot(4).size
- end
- end
- end
- if s1 > 24 then
- r.select(1)
- r.drop(s1 - 24)
- end
- if s2 > 24 then
- r.select(2)
- r.drop(s2 - 24)
- end
- if s3 > 24 then
- r.select(3)
- r.drop(s3 - 24)
- end
- if s4 > 24 then
- r.select(4)
- r.drop(s4 - 24)
- end
- for i=5,is do
- r.select(i)
- r.drop()
- end
- r.turnLeft()
- r.select(1)
- end
- function onelayer()
- move_y()
- move_x()
- end
- function morethanone()
- onelayer()
- remainlayers = layers - 1
- for i=remainlayers,1,-1 do
- for i=1,layer_h do
- up()
- end
- onelayer()
- end
- local godown = (layers - 1) * layer_h
- for i=1,godown do
- down()
- end
- r.turnAround()
- forward()
- r.turnAround()
- end
- while true do
- local hsbs = false
- local pseo = 0
- for p=1,4 do
- if ic.getStackInInternalSlot(p) then
- if ic.getStackInInternalSlot(p).name == 'minecraft:sapling' then
- hsbs = true
- break
- end
- end
- end
- while not hsbs do
- if pseo == 0 and hsbs == false then
- report('Саженцов не найдено! Положите саженцы в первые 4 слота!')
- pseo = 1
- end
- for p=1,4 do
- if ic.getStackInInternalSlot(p) then
- if ic.getStackInInternalSlot(p).name == 'minecraft:sapling' then
- hsbs = true
- pseo = 0
- break
- end
- end
- end
- os.sleep(14)
- computer.beep(1000,1)
- end
- local ica = 0
- local nc = 0
- local icgn = 0
- while computer.energy()/computer.maxEnergy() < 0.25 do
- if gz.analyze(0).name == 'OpenComputers:charger' or gz.analyze(1).name == 'OpenComputers:charger' or gz.analyze(2).name == 'OpenComputers:charger' or gz.analyze(5).name == 'OpenComputers:charger' then
- if ica == 0 then
- report('Уровень зарядки робота меньше 25%. Зарядка...')
- icgn = 1
- ica = 1
- end
- else
- if nc == 0 then
- report('Подключите зарядник!!!')
- nc = 1
- end
- os.sleep(10)
- end
- end
- while icgn == 1 do
- while computer.energy()/computer.maxEnergy() < 0.5 do
- os.sleep(30)
- end
- icgn = 0
- report('Робот достиг 50% заряда! Продолжаю работу...')
- end
- forward()
- if layers == 1 then
- onelayer()
- else
- morethanone()
- end
- unload()
- os.sleep(delay)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement