Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local robot = require("robot")
- local comp = require("computer")
- local magnet
- local red
- function main()
- if battest() > 30 then io.write("Battery check = ",battest(),"%\n")
- else
- io.write("Low battery level") return
- end
- --Настройка
- io.write("Введеите к-во деревьев: ")
- count = io.read()
- io.write("Проверьте к-во саженцев в слоте\n\tНужно: ",count,", в слоте: ", robot.count())
- io.read()
- io.write("Введеите задержку между проверками (в секундах):\n")
- wait = toInteger(io.read())
- io.write("Режим работы: \n\t1.Ванильный\n(дерево рубиться целиком блок за блоком)\n\t2.Модифицированый\n(дерево рубиться полностью при срубании\nпервого блока, должен быть установлен мод)\n")
- mode = io.read()
- range = 6 --растояние между саженцами (в блоках)
- trees = 0
- --
- io.write("Приступаю...\n")
- for j = 1,count do
- for i = 1,range do
- robot.forward()
- end
- robot.turnLeft()
- if not robot.detect() then robot.place() end
- robot.turnRight()
- end
- robot.turnAround()
- while true do
- for i = 1,count*range do
- robot.forward()
- end
- robot.turnAround()
- if status() ~= nil then
- while status() ~= nil do
- os.sleep(3)
- end
- io.write("tool equipped")
- else os.sleep(wait)
- end
- for j = 1,count do
- for i = 1,range do
- robot.forward()
- end
- tmp = check(trees,mode)
- if tmp ~= trees and tmp ~= nil then
- io.write("Срублено деревьев: ", tmp,"\n")
- trees = tmp
- end
- end
- robot.turnAround()
- end
- end
- function toInteger(anystring)
- number = 0
- for i = 0,anystring do
- number = i
- end
- return number
- end
- function battest()
- return math.ceil(comp.energy()*100/comp.maxEnergy())
- end
- function status()
- inf,err = robot.durability()
- if battest() < 30 then
- red.setOutput(5,15)
- io.write("Зарядка...")
- while battest()~=100 do os.sleep(1) end
- red.setOutput(5,0)
- io.write("Зарядка завершена\n")
- end
- if robot.count(2) == 64 then unload() end
- if inf == nil then print(err) return err
- else if inf == 0 then return "low durability" end end
- return nil
- end
- function check(count,mode)
- inf,err = robot.durability()
- if inf == nil then print(err) return nil
- else if inf == 0 then return nil end end
- robot.turnLeft()
- robot.up()
- if robot.detect() then
- robot.down()
- robot.swing()
- robot.forward()
- if mode == "2" then harvest()
- else chopUp() end
- robot.turnAround()
- robot.forward()
- robot.turnAround()
- robot.place()
- robot.turnRight()
- count = count+1
- else
- robot.down()
- robot.turnRight()
- end
- if mode == "1" then harvest() end
- return count
- end
- function harvest()
- while magnet.suck() do
- end
- end
- function chopUp()
- countblock = 0
- while robot.detectUp() do
- robot.swingUp()
- robot.up()
- countblock = countblock + 1
- end
- for i = 1,countblock do
- robot.down()
- end
- end
- function unload()
- robot.turnAround()
- for c = 2,16 do
- robot.select(c)
- if robot.count() > 0 then
- robot.drop()
- end
- end
- robot.select(1)
- robot.turnAround()
- end
- if component.isAvailable("tractor_beam") and component.isAvailable("redstone") then
- red = component.redstone
- magnet = component.tractor_beam
- main()
- else io.write("Не хватает компонентов: \n")
- if not component.isAvailable("tractor_beam") then io.write("\tПритягивающий луч\n") end
- if not component.isAvailable("redstone") then io.write("\tПлата на красном камне\n") end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement