Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- local posX = 0
- local posZ = 0
- local posY = 0
- local replant = false
- local replant_delay = 60
- local maxloops = 1
- if #args < 1 then
- print("Usage: programname <diam. (1|2)> [loop count] [delay (s)]")
- return false
- end
- local diam = tonumber( args[1] )
- if #args >= 2 then
- maxloops = tonumber( args[2] )
- replant = true
- end
- if #args >= 3 then
- replant_delay = tonumber( args[3] )
- end
- if maxloops > 1 then
- if turtle.getItemCount(15) == 0 or turtle.getItemCount(16) == 0 then
- print("Error: need saplings and bonemeal in slots 15 (s) and 16 (bm)")
- return false
- end
- end
- function digOneStripUp()
- turtle.digUp()
- if turtle.up() == false then
- print("Error: Could not move up")
- return false
- end
- posY = posY + 1
- if diam > 1 then
- turtle.dig()
- end
- return true
- end
- function digOneStripDown()
- turtle.digDown()
- if turtle.down() == false then
- print("Error: Could not move down")
- return false
- end
- posY = posY - 1
- if diam > 1 then
- turtle.dig()
- end
- return true
- end
- function dumpInventory()
- if turtle.detect() then
- -- Now we should be where we started
- for i=1,14 do
- local items = 0
- items = turtle.getItemCount(i)
- turtle.select(i)
- res = turtle.drop()
- -- Chest is full
- if res == false and items > 0 then
- return false
- end
- end
- end
- return true
- end
- function feller()
- turtle.select(1)
- if turtle.detect() == false then
- print("Error: No block in front!")
- return
- end
- -- Dig the first block ...
- if turtle.dig() == false then
- print("Error: Could not dig the first block!")
- return
- end
- -- ... and move to position "inside" the tree area
- if turtle.forward() == true then
- posX = posX + 1
- else
- print("Error: Could not move to position!")
- return
- end
- if diam == 2 then
- turtle.dig()
- end
- -- Dig the first colum (1 or 2 blocks wide)
- while turtle.detectUp() == true do
- if digOneStripUp() == false then
- print("Error while digging and moving up")
- return false
- end
- end
- -- If we are digging a 2x2 tree, move the the other column:
- if diam == 2 then
- turtle.turnRight()
- turtle.dig() -- Dig just to be sure there are no leaves blocking our way
- turtle.forward()
- posZ = posZ + 1
- turtle.turnLeft()
- turtle.dig()
- -- Dig down until we are at the same level that we started
- while posY > 0 do
- if digOneStripDown() == false then
- print("Error while digging and moving down")
- return false
- end
- end
- -- Move back to the same position that we started in
- -- First, move in the "Z"-direction
- turtle.turnLeft()
- while posZ > 0 do
- turtle.forward()
- posZ = posZ - 1
- end
- turtle.turnLeft()
- elseif diam == 1 then
- while posY > 0 do
- if turtle.down() == false then
- print("Error while moving down")
- return false
- end
- posY = posY - 1
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- -- Move back in the "X"-direction
- if turtle.forward() == false then
- print("Error while trying to move to the starting spot")
- return false
- end
- posX = posX - 1
- dumpInventory()
- -- And finally, reorient
- turtle.turnRight()
- turtle.turnRight()
- suckSaplings()
- end
- function doReplant()
- if diam == 1 then
- turtle.select(15)
- turtle.place()
- turtle.select(16)
- turtle.place()
- elseif diam == 2 then
- turtle.select(15)
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- turtle.back()
- turtle.place()
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- turtle.back()
- turtle.place()
- turtle.select(16)
- turtle.place()
- end
- end
- function suckSaplings()
- local down = false
- turtle.select(15)
- turtle.suckDown()
- -- If there is no block below, go down and suck the saplings
- -- that the water currents have brought us.
- if turtle.detectDown() == false then
- down = true
- turtle.down()
- end
- turtle.turnRight()
- turtle.suck()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.suck()
- if down == true then
- turtle.turnLeft()
- turtle.suck()
- turtle.turnRight()
- turtle.up()
- end
- turtle.turnRight()
- end
- for i = 1,maxloops do
- feller()
- if replant == true then
- os.sleep(replant_delay)
- suckSaplings()
- turtle.turnRight()
- turtle.turnRight()
- dumpInventory()
- turtle.turnRight()
- turtle.turnRight()
- if i < maxloops then
- doReplant()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement