Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Var
- local robot = require("robot")
- local inv = require("component").inventory_controller
- local comp = require("computer")
- local s = require("sides")
- local tr = require("component").tractor_beam
- Xn = 0
- Yn = 0
- Zn = 0
- nSide = 0
- Xc,Xt,Yc,Yt,Zc,Zt = 0,0,0,0,0,0
- --Function
- function Left()
- robot.turnLeft()
- nSide = nSide+1
- end
- function Right()
- robot.turnRight()
- nSide = nSide-1
- end
- function Around()
- robot.turnAround()
- nSide = nSide-2
- end
- function forward()
- local n = 0
- while true do
- if robot.forward() then
- while tr.suck() do end
- nSide = nSide%4
- if nSide == 0 then Xt = Xt+1
- elseif nSide == 1 then Zt = Zt+1
- elseif nSide == 2 then Xt = Xt-1
- elseif nSide == 3 then Zt = Zt-1
- end
- return true
- else
- robot.swing()
- n = n+1
- end
- if n == 20 then print("no run forward, program stop!") os.exit() end
- end
- end
- function up()
- local n = 0
- while true do
- if robot.up() then Yt = Yt+1 return true else
- robot.swingUp()
- n = n+1
- end
- if n == 20 then print("no run up, program stop!") os.exit() end
- end
- end
- function down()
- local n = 0
- while true do
- if robot.down() then Yt = Yt-1 return true else
- robot.swingDown()
- n = n+1
- end
- if n == 20 then print("no run down, program stop!") os.exit() end
- end
- end
- function sapling()
- robot.select(2)
- up()
- forward()
- robot.placeDown()
- forward()
- robot.placeDown()
- Left()
- forward()
- robot.placeDown()
- Left()
- forward()
- robot.placeDown()
- forward()
- Left()
- forward()
- Left()
- down()
- end
- function wood()
- local n=0
- robot.swing()
- forward()
- while true do
- if robot.detectUp() then
- n=n+1
- robot.swing()
- robot.swingUp()
- up()
- else break end
- end
- robot.swing()
- Left()
- robot.swing()
- forward()
- Right()
- for i=1,n do
- robot.swing()
- robot.swingDown()
- down()
- end
- robot.swing()
- Right()
- forward()
- Right()
- forward()
- Around()
- end
- function new_tools()
- if robot.durability() == nil then return false end
- if robot.durability()<150 then
- robot.select(1)
- inv.equip()
- if robot.durability()<150 then
- return false
- else
- return true
- end
- else
- return true
- end
- end
- function detect_wood()
- if robot.detect() then
- up()
- if robot.detect() then
- down()
- return "wood"
- else
- down()
- return "sapling"
- end
- else
- return "clear"
- end
- end
- function run_a()
- Left()
- for i=1,10 do
- forward()
- end
- Right()
- end
- function run_b()
- Right()
- forward()
- Right()
- for i=1,10 do
- forward()
- end
- Right()
- forward()
- Right()
- end
- function run_c()
- Right()
- for i=1,10 do
- forward()
- end
- Left()
- end
- function run_d()
- Left()
- forward()
- forward()
- Right()
- for i=1,10 do
- forward()
- end
- Right()
- forward()
- forward()
- Left()
- end
- function bksp(area)
- if area == "chest" then
- Left()
- forward()
- forward()
- Right()
- Xc=Xt Yc=Yt Zc=Zt
- while Zn~=Zt do
- forward()
- end
- Right()
- while Xn~=Xt do
- forward()
- end
- elseif area == "wood" then
- Around()
- while Xc~=Xt do
- forward()
- end
- Left()
- while Zc~=Zt do
- forward()
- end
- Left()
- forward()
- forward()
- Left()
- end
- end
- function chest(tools)
- for i=3,16 do
- robot.select(i)
- if (robot.count(i) ~= 0) and (not robot.drop(64)) then Around() print("chest full, stop!") os.exit() end
- end
- Right()
- robot.select(2)
- for i=1,5 do
- if robot.count(2) ~= 64 then robot.suck(robot.space(2)) else break end
- end
- Left()
- if not count_sapl() then return "sapling" end
- if not tools then
- robot.select(1)
- robot.drop()
- inv.equip()
- robot.drop()
- if not robot.suckDown(1) then return "tools" end
- inv.equip()
- if not robot.suckDown(1) then return "tools" end
- end
- return true
- end
- function count_sapl()
- if robot.count(2) < 5 then return false else return true end
- end
- function full()
- if robot.count(13) == 0 then return true else return false end
- end
- function energy()
- if comp.energy() < 1800 then os.sleep(180) end
- end
- -- MultiFunction
- function woodAll()
- while true do
- if count_sapl() and full() and new_tools() then
- detect = detect_wood()
- if detect == "clear" then sapling() break
- elseif detect == "wood" then wood() sapling() break
- elseif detect == "sapling" then break end
- else
- bksp("chest")
- _exit = chest(new_tools())
- if "tools" == _exit then Around() print("not tools, stop!") os.exit()
- elseif "sapling" ==_exit then Around() print("not sapling, stop!") os.exit()
- end
- bksp("wood")
- end
- end
- end
- --Programs:
- Right()
- while true do
- for i=1,3 do
- energy()
- woodAll()
- if i == 2 then os.sleep(10) else os.sleep(0) end
- energy()
- run_a()
- end
- energy()
- woodAll()
- os.sleep(0)
- energy()
- run_b()
- for i=1,3 do
- energy()
- woodAll()
- os.sleep(0)
- energy()
- run_c()
- end
- energy()
- woodAll()
- os.sleep(0)
- energy()
- run_d()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement