Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ opencomputers Ферма дерева by serafim pastebin.com/XWmaX9A9
- Использать с модом который разрушает дерево убрав нижний блок !
- Например: treecapitator или Большой топор из tinkers construct
- Используя Большой топор с улучшением на жарку(лавовый кристалл),
- получим ферму древестного угля.
- требования:
- корпус 3-го уровня из за притягивающего луча,
- инвентарь, контроллер инвентаря
- испозование:
- Поставить сундук справа от робота, положить саженцы с 1 по 4 слот
- в инвентарь робота, дать роботу топор
- пример запуска: treefarm 5 5 60
- или по умолчанию: treefarm
- ]]--
- local a = {...}
- local grid_x = tonumber(a[1]) or 5 -- Размер сетки по X
- local grid_y = tonumber(a[2]) or 5 -- Размер сетки по Y
- local delay = tonumber(a[3]) or 60 -- Ожидание в секундах
- local upstate,final,start,empty = false,false,true,true
- local computer = require("computer")
- local term = require('term')
- local com = require("component")
- if not com.isAvailable("robot") then
- print("Только роботы могут использовать эту программу")
- computer.beep(1000,2)
- os.exit()
- end
- local r = require("robot")
- local invsize = r.inventorySize()
- if not com.isAvailable("inventory_controller") then
- print("Для работы нужен контроллер инвентаря")
- computer.beep(1000,2)
- os.exit()
- end
- local ic = com.inventory_controller
- if not com.isAvailable("tractor_beam") then
- print("Для работы нужен притягивающий луч")
- computer.beep(1000,2)
- os.exit()
- end
- local tb = com.tractor_beam
- if require("component").isAvailable("generator") then
- gen = require("component").generator
- print("Доступен генератор")
- geninst = true
- end
- if grid_x < 1 then
- print("Размер сетки по оси X не может быть меньше 1")
- computer.beep(1000,2)
- os.exit()
- end
- if grid_y < 1 then
- print("Размер сетки по оси Y не может быть меньше 1")
- computer.beep(1000,2)
- os.exit()
- end
- if delay < 1 then
- print("Задержка не может быть меньше 1")
- computer.beep(1000,2)
- os.exit()
- end
- print(" ")
- print("Размер поля:")
- print("Х = "..grid_x)
- print("Y = "..grid_y)
- print("Ожидание между сбором:")
- print(delay.." секунд")
- local function forward()
- while r.detect() do
- r.swing()
- end
- if not r.forward() then
- forward()
- end
- end
- local function up()
- while r.detectUp() do
- r.swingUp()
- end
- if not r.up() then
- up()
- end
- end
- local function down()
- while r.detectDown() do
- r.swingDown()
- end
- if not r.down() then
- down()
- end
- end
- local function slotsapling(slot)
- if r.count(slot) > 0 then
- if ic.getStackInInternalSlot(slot).name == "minecraft:sapling" then
- return true
- end
- end
- return false
- end
- local function checkforsapling()
- local detect, reason = r.detectDown()
- if not detect and reason == "air" then
- for i = 1, 4 do
- if slotsapling(i) then
- r.select(i)
- ic.equip()
- r.useDown()
- ic.equip()
- empty = true
- break
- end
- if i == 4 and not slotsapling(4) then
- if empty then
- r.setLightColor(0xFF0000)
- term.clear()
- print("Саженцев в слотах 1 - 4 не найдено !")
- empty = false
- end
- computer.beep(1000,10)
- os.sleep(10)
- while tb.suck() do end
- for i = 5, invsize do
- if slotsapling(i) then
- r.select(i)
- r.transferTo(1)
- end
- end
- checkforsapling()
- r.setLightColor(0xFFFFFF)
- term.clear()
- print("Работаю ...")
- end
- end
- elseif detect and reason == "solid" then
- r.swingDown()
- checkforsapling()
- end
- while tb.suck() do end
- end
- local function checkforlog()
- local detect, reason = r.detect()
- if detect and reason == "solid" then --дерево
- if upstate then
- down()
- upstate = false
- end
- r.swing()
- os.sleep(1)
- while tb.suck() do end
- elseif detect and reason == "passable" then --саженец
- up()
- upstate = true
- end
- for i = 1, 2 do
- forward()
- end
- end
- local function unload()
- for i = 1, invsize do
- if slotsapling(i) then
- r.select(i)
- for j = 1, 4 do
- r.transferTo(j)
- end
- else
- if r.count(i) > 0 then
- r.select(i)
- if not r.drop() then
- r.setLightColor(0xFF0000)
- print("В сундуке нет места :(")
- computer.beep(1000,10)
- r.turnLeft()
- os.exit()
- end
- end
- end
- end
- for i = 5, invsize do
- if r.count(i) > 0 then
- r.select(i)
- r.drop()
- end
- end
- r.select(1)
- end
- local function checkfuel()
- if geninst and computer.energy()/computer.maxEnergy() < 0.23 then
- local gencount = gen.count()
- for i = 2, invsize do
- if r.count(i) > 0 and not slotsapling(i) then
- r.select(i)
- gen.insert(32)
- end
- end
- if gen.count() > gencount then
- print("Аварийная заправка зевершена")
- print("Топлива в генераторе = "..gen.count())
- os.sleep(2)
- end
- end
- end
- local function checkenergy()
- local battery = computer.energy()/computer.maxEnergy()
- if battery < 0.25 then
- print("Уровень заряда робота меньше 25%")
- computer.beep(1000,10)
- print("Тест зарядки ...")
- os.sleep(5)
- if battery < computer.energy()/computer.maxEnergy() then
- print("Заряжаюсь до 30% ...")
- local tru = 0
- while computer.energy()/computer.maxEnergy() < 0.3 do
- os.sleep(30)
- tru = tru + 1
- if tru == 6 then
- print("Зарядка слишком долгая !")
- break
- end
- if geninst and gen.count() == 0 then
- print("Закончилось топливо !")
- break
- end
- end
- else
- print("Робот не заряжается !")
- end
- end
- end
- local function axe()
- if r.durability() == nil or r.durability() < 0.03 then
- if empty then
- r.setLightColor(0xFF0000)
- term.clear()
- print("Нет топора, или он сломан !")
- empty = false
- end
- computer.beep(1000,10)
- os.sleep(20)
- axe()
- term.clear()
- empty = true
- end
- end
- local function move_y()
- if start then
- forward()
- start = false
- end
- for i = 1, grid_y do
- checkforlog()
- end
- r.turnAround()
- if not upstate then
- up()
- upstate = true
- end
- for i = 1, grid_y do
- forward()
- checkforsapling()
- forward()
- end
- down()
- upstate = false
- if grid_x == 1 then
- forward()
- r.turnAround()
- else
- if not final then
- r.turnLeft()
- for i = 1, 2 do
- forward()
- end
- r.turnLeft()
- end
- end
- end
- local function move_x()
- local lol3 = grid_x - 1
- for i = 1,lol3 do
- if i == lol3 then
- final = true
- end
- move_y()
- end
- r.turnRight()
- local lol2 = grid_x * 2 - 2
- for i = 1, lol2 do
- forward()
- end
- r.turnLeft()
- forward()
- r.turnLeft()
- checkfuel()
- unload()
- r.turnLeft()
- end
- local function wait()
- term.clear()
- for i = delay, 1, -10 do
- if i == delay then
- term.write("До следующего сбора")
- term.setCursor(1,2)
- term.write("осталось "..delay.." секунд")
- end
- os.sleep(10)
- term.clearLine()
- term.write("осталось "..(i-10).." секунд")
- end
- term.clear()
- end
- while true do
- axe()
- checkenergy()
- r.select(1)
- r.setLightColor(0xFFFFFF)
- print("Работаю ...")
- move_y()
- move_x()
- wait()
- start = true
- final = false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement