Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Var
- Xn = 0
- Yn = 0
- Zn = 0
- nSide = 0
- Xc,Xt,Yc,Yt,Zc,Zt = 0,0,0,0,0,0
- --Function
- function Left()
- turtle.turnLeft()
- nSide = nSide+1
- end
- function Right()
- turtle.turnRight()
- nSide = nSide-1
- end
- function Around()
- turtle.turnRight()
- turtle.turnRight()
- nSide = nSide-2
- end
- function forward()
- local n = 0
- while true do
- if turtle.forward() then
- 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
- if turtle.detect() then turtle.dig() else turtle.attack() end
- 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 turtle.up() then Yt = Yt+1 return true else
- if turtle.detectUp() then turtle.digUp() else turtle.attackUp() end
- 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 turtle.down() then Yt = Yt-1 return true else
- if turtle.detectDown() then turtle.digDown() else turtle.attackDown() end
- n = n+1
- end
- if n == 20 then print("no run down, program stop!") os.exit() end
- end
- end
- function sapling()
- turtle.select(2)
- up()
- forward()
- turtle.placeDown()
- forward()
- turtle.placeDown()
- Left()
- forward()
- turtle.placeDown()
- Left()
- forward()
- turtle.placeDown()
- forward()
- Left()
- forward()
- Left()
- down()
- end
- function wood()
- local n=0
- turtle.dig()
- forward()
- while true do
- if turtle.detectUp() then
- n=n+1
- turtle.dig()
- turtle.digUp()
- up()
- else break end
- end
- turtle.dig()
- Left()
- turtle.dig()
- forward()
- Right()
- for i=1,n do
- turtle.dig()
- turtle.digDown()
- down()
- end
- turtle.dig()
- Right()
- forward()
- Right()
- forward()
- Around()
- end
- function detect_wood()
- if turtle.detect() then
- up()
- if turtle.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()
- for i=3,16 do
- turtle.select(i)
- if (turtle.getItemCount(i) ~= 0) and (not turtle.drop(64)) then Around() print("chest full, stop!") os.exit() end
- end
- Right()
- turtle.select(2)
- for i=1,5 do
- if turtle.getItemCount(2) ~= 64 then turtle.suck(turtle.getItemSpace(2)) else break end
- end
- Left()
- if not count_sapl() then return "sapling" end
- return true
- end
- function count_sapl()
- if turtle.getItemCount(2) < 5 then return false else return true end
- end
- function full()
- if turtle.getItemCount(13) == 0 then return true else return false end
- end
- function energy()
- sleep(0)
- end
- -- MultiFunction
- function woodAll()
- while true do
- if count_sapl() and full() 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()
- if "sapling" ==_exit then Around() print("not sapling, stop!") os.exit()
- end
- bksp("wood")
- end
- end
- end
- --Programs:
- Right()
- while true do
- for i=1,4 do
- woodAll()
- run_a()
- end
- woodAll()
- run_b()
- for i=1,4 do
- woodAll()
- run_c()
- end
- woodAll()
- run_d()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement