Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- facing = 1 --facing:richtung von ursprung ausgehend NOSW 1234 aktuallisiert beim bewegen/drehen N/S ist xachse
- cords = vector.new(0,0,0)
- farmlenght = 5 --farmlenght:amount of trees
- farmwidth = 8
- treedist = 2
- modus = null
- status = "notfull" -- stati: notfull,full,nosaplings
- function loadcords()
- local file = fs.open("cords.dat","r")
- facing = tonumber(file.readLine())
- cords.x = tonumber(file.readLine())
- cords.y = tonumber(file.readLine())
- cords.z = tonumber(file.readLine())
- file.close()
- end
- function updatecords()
- local file = fs.open("cords.dat","w")
- file.writeLine(facing)
- file.writeLine(cords.x)
- file.writeLine(cords.y)
- file.writeLine(cords.z)
- file.close()
- loadcords()
- end
- function loadsettings()
- local file = fs.open ("chopper.cfg", "r")
- file.readLine(farmlenght)
- file.readLine(farmwidht)
- file.readLine(treedist)
- file.readLine(modus)
- file.close()
- end
- function savesattings()
- local file = fs.open ("chopper.cfg", "w")
- file.writeLine (farmlenght)
- file.writeLine (farmwidht)
- file.writeLine (treedist)
- file.writeLine (modus)
- file.close()
- loadsettings()
- end
- function breakcheck()
- if turtle.getItemCount(9) == 0 then
- print("turtle was broken! reset to startpoint!")
- cords.x,cords.y,cords.z = 0,0,0
- facing = 1
- updatecords()
- else loadcords() loadsettings()
- end
- end
- function move(amount, direction) -- direction: 1, 2 or empty 1=left,2=right,3=up,4=down empty = forward
- selectlogslot()
- if direction == null then
- direction = 0
- elseif direction == 1 then
- turtle.turnLeft()
- facing = (facing+2)%4 + 1
- elseif direction == 2 then
- turtle.turnRight()
- facing = (facing)%4 + 1
- end
- updatecords()
- if amount == null then amount = 1 end
- if amount ~= 0 then
- if direction < 3 then
- for i=1,amount do
- if turtle.detect() then turtle.dig() end
- while not turtle.forward() do sleep(0.1) end
- if facing == 1 then cords.x = cords.x + 1
- elseif facing == 2 then cords.y = cords.y + 1
- elseif facing == 3 then cords.x = cords.x - 1
- elseif facing == 4 then cords.y = cords.y - 1
- end
- updatecords()
- end
- elseif direction == 3 then
- for i=1,amount do
- if turtle.detectUp() then turtle.digUp() end
- while not turtle.up() do sleep(0.1) end
- cords.z = cords.z + 1
- updatecords()
- end
- elseif direction == 4 then
- for i=1,amount do
- if turtle.detectDown() then turtle.digDown() end
- while not turtle.down() do sleep(0.1) end
- cords.z = cords.z - 1
- updatecords()
- end
- end
- end
- end
- function selectlogslot()
- for i=9,16 do
- if turtle.getItemCount(i) < 64 then
- turtle.select(i)
- status = "notfull"
- return
- end
- end
- status = "full"
- end
- function selectsaplingslot()
- for i=5,8 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- status = "notfull"
- return
- end
- end
- status = "nosaplings"
- end
- function cut()
- selectlogslot()
- if turtle.compare() then
- if status == "notfull" then move() end
- selectlogslot()
- if status == "notfull" then turtle.digDown()
- selectsaplingslot() if status ~= "nosaplings" then turtle.placeDown() end end
- selectlogslot()
- while turtle.compareUp() do if status == "notfull" then move(1,3) selectlogslot() end end
- temp = cords.z
- for a=1, temp do move(1,4) end
- selectlogslot()
- else
- move()
- selectsaplingslot()
- if not turtle.compareDown() then
- if turtle.detectDown() then
- selectlogslot() turtle.digDown() selectsaplingslot() turtle.placeDown()
- else selectsaplingslot() turtle.placeDown()
- end
- selectlogslot()
- end
- end
- end
- function empty()
- if cords.x+cords.y+cords.z+facing == 1 then
- move(0,2)
- for i=9,16 do
- if turtle.getItemCount(i) > 0 then
- selectsaplingslot()
- if turtle.compareTo(i) then
- turtle.select(i)
- turtle.transferTo(8)
- turtle.transferTo(7)
- turtle.transferTo(6)
- end
- turtle.select(i)
- if i == 9 then turtle.drop(turtle.getItemCount(i)-1)
- else turtle.drop() end
- end
- end
- selectlogslot()
- move(0,1)
- end
- end
- function refill()
- --sort dirt
- if cords.x+cords.y+cords.z+facing == 1 then
- move(0,1)
- dirt,saplings = 0,0
- for i=2,4 do
- turtle.select(i)
- turtle.transferTo(1)
- end
- for i=3,4 do
- turtle.select(i)
- turtle.transferTo(2)
- end
- turtle.select(4)
- turtle.transferTo(3)
- --sort saplings
- for i=6,8 do
- turtle.select(i)
- turtle.transferTo(5)
- end
- for i=7,8 do
- turtle.select(i)
- turtle.transferTo(6)
- end
- turtle.select(8)
- turtle.transferTo(7)
- for i=5,8 do
- if turtle.getItemCount(i) < 64 then turtle.select(i) turtle.suck() end
- end
- nottoomuch = true
- for i=10,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- nottoomuch = nottoomuch and turtle.drop()
- end
- end
- if not nottoomuch then
- move(0,2) move(0,2)
- for i=10,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- while not turtle.drop() do sleep(0.3) end
- end
- end
- move(0,1)
- else
- move(0,2)
- end
- end
- end
- function gohome()
- if cords.z ~= 0 then
- selectlogslot()
- while turtle.compareUp() do if status == "notfull" then move(1,3) selectlogslot() end end
- temp = cords.z
- for a=1, temp do move(1,4) end
- selectlogslot()
- end
- if cords.z == 0 then
- if facing == 1 then
- move(1,2) move(0,2)
- elseif facing == 2 then
- move() move(0,2)
- elseif facing == 3 then
- move(1,2) move(0,1)
- elseif facing == 4 then
- move()
- while facing ~= 3 do move(0,1) end
- end
- end
- while cords.x > 1 do move() end
- move(0,2)
- while cords.y > 0 do move() end
- move(1,1) move(0,1) move(0,1)
- end
- function work()
- -- initial row
- move(1)
- cut()
- while cords.x < ((farmlenght-1)*treedist + farmlenght) do
- move(treedist)
- cut()
- end
- -- all other rows
- while cords.y < ((farmwidth-1)*treedist + farmwidth)-1 do
- if facing == 1 then
- move(0,2) move(treedist) cut() move(0,2)
- while cords.x > 3 do
- move(treedist)
- cut()
- end
- else
- move(0,1) move(treedist) cut() move(0,1)
- while cords.x < ((farmlenght-1)*treedist + farmlenght) do
- move(treedist)
- cut()
- end
- end
- end
- end
- function startup()
- breakcheck()
- if cords.z ~= 0 then
- print("finishing tree")
- selectsaplingslot()
- if turtle.compareDown() then
- selectlogslot()
- while turtle.compareUp() do
- move(1,3)
- end
- temp = cords.z
- for a=1, temp do move(1,4) end
- end
- end
- if cords.x ~= 0 or cords.y ~= 0 then print("returning home coz restart") gohome() end
- main()
- end
- function everythingokcheck()
- while turtle.getItemCount(5) < (farmlenght * farmwidth) do
- turtle.select(5)
- sleep(0.1)
- term.clear()
- term.setCursorPos(1,1)
- a = (farmlenght * farmwidth) - turtle.getItemCount(5)
- print("put at least ".. tostring(a) .. " saplings in slot 5")
- end
- while turtle.getItemCount(9) < 1 do
- turtle.select(9)
- sleep(0.1)
- term.clear()
- term.setCursorPos(1,1)
- print("at least 1 log in slot 9")
- end
- term.clear()
- print("going to work :-)")
- end
- function main()
- while true do
- empty()
- refill()
- everythingokcheck()
- work()
- gohome()
- sleep(300)
- end
- end
- startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement