Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Log V2
- local Sapling = 1
- local Tree = 2
- local Wall = 3
- local Home = 4
- local Height = 1
- local RandMove = 4
- function checkSpace()
- -- let's check if there's space for more wood
- local space = 0
- for i=5,16 do
- turtle.select(i)
- if turtle.compareTo(Tree) then
- if turtle.getItemSpace(i) >= 1 then
- space = space + turtle.getItemSpace(i)
- end
- elseif turtle.getItemSpace(i) == 64 then
- space = space + 64
- end
- end
- if space >= 15 then
- rednet.send(Console,"Space:"..space.." Felling now!")
- return true
- else
- rednet.send(Console,"Not enough space - not felling!")
- return false
- end
- end
- function plantTree()
- turtle.select(Sapling)
- if turtle.getItemCount(Sapling) >= 2 then
- turtle.place(1)
- rednet.send(Console, "Sapling placed, "..turtle.getItemCount(Sapling).." Saplings left")
- return true
- else
- if saplingRefill() and turtle.getItemCount(Sapling) >= 2 then
- turtle.place(1)
- rednet.send(Console, "Sapling placed, "..turtle.getItemCount(Sapling).." Saplings left")
- return true
- else
- return false
- end
- end
- if checkSpace() == false then
- goHome()
- end
- end
- function saplingRefill()
- for i = 5,16 do
- turtle.select(i)
- if turtle.compareTo(Sapling) then
- rednet.send(Console,"Found Saplings - refilling...")
- if turtle.transferTo(Sapling) then
- rednet.send(Console,"Refilled Saplings!")
- return true
- else
- rednet.send(Console,"Sapling Refill failed!")
- return false
- end
- end
- end
- end
- function farming()
- -- do whatever we need to plant or harvest a tree
- if turtle.detect() then
- turtle.select(Sapling)
- if turtle.compare() then
- return true;
- else
- logTree()
- end
- else
- freeSpaceAround = true;
- if turtle.forward() then
- turtle.suck()
- if turtle.detect() then
- freeSpaceAround = false
- else
- turtle.back()
- for i=1,4 do
- turtle.turnRight()
- turtle.suck()
- if turtle.detect() == true then
- logTree()
- freeSpaceAround = false
- end
- end
- end
- else
- freeSpaceAround = false
- end
- if freeSpaceAround == true then
- if not plantTree() then
- rednet.send(Console,"Planting failed!")
- end
- end
- end
- end
- function logTree()
- turtle.select(Tree)
- if turtle.compare() then
- if checkSpace() then
- turtle.dig()
- turtle.forward()
- while turtle.detectUp() do
- turtle.digUp()
- turtle.up()
- Height = Height + 1
- --print("Height: "..Height)
- end
- while Height > 1 do
- turtle.digDown()
- turtle.down()
- Height = Height - 1
- end
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- turtle.suck()
- turtle.back()
- turtle.suck()
- turtle.select(Sapling)
- plantTree()
- else
- goHome()
- end
- end
- end
- function move()
- turn = math.random(2)
- if turn == 1 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- turtle.suck()
- rand = math.random(RandMove)
- for i=1,rand do
- turtle.forward()
- turtle.suck()
- end
- end
- function goHome()
- rednet.send(Console,"Going home...")
- -- find the next wall
- failcount = 0
- while not turtle.compare() do
- turtle.select(Wall)
- turtle.turnLeft()
- while not turtle.detect() do
- turtle.forward()
- end
- failcount = failcount + 1
- rednet.send(Console,"Failcount "..failcount)
- if failcount >= 5 then
- turtle.select(Sapling)
- if turtle.compare() then
- turtle.dig()
- failcount = 0
- turtle.forward()
- end
- end
- end
- rednet.send(Console,"Found wall - driving home along now...")
- -- move along the wall to go home
- restart = false
- while not restart do
- while not turtle.detect() do
- turtle.forward()
- end
- turtle.select(Home)
- if turtle.compare() then
- -- we're at home - do some home stuff
- saplingRefill()
- turtle.select(Tree)
- TreeNum = turtle.getItemCount(Tree)
- turtle.dropDown(TreeNum-1)
- for i=5,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.turnRight()
- turtle.turnRight()
- restart = true
- shell.run("reboot")
- else
- turtle.turnLeft()
- end
- end
- return true
- end
- -- The program starts here!
- term.clear()
- print("Logger V2 - by Helmi74")
- print("----------------------")
- rednet.open("right")
- rednet.send(Console,"starting to work now...")
- ready = true
- for i=1,4 do
- turtle.select(i)
- if turtle.getItemCount(i) == 0 then
- print("not ready - please fill slots 1 to 4")
- print("--- --- --- --- ---")
- print("Put a stack of saplings in slot "..Sapling)
- print("Put one tree log of the same sort in slot "..Tree)
- print("Put one wall block in slot "..Wall)
- print("Put one home block in slot "..Home)
- rednet.send(Conosole,"Not ready -instructions printed to local console")
- ready = false
- break
- end
- end
- if ready == true then
- while true do
- move()
- farming()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement