Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x=0
- y=0
- z=0 --[this is called globally because it's used and shared in all subs; it is used to return the turtle to ground level after completing its task.]--
- function forward()
- local count = 0
- repeat
- turtle.select(1)
- if turtle.compare() then
- turtle.dig()
- else
- if turtle.detect() then
- while turtle.detectUp() do
- turtle.back()
- end
- turtle.up()
- z = z + 1
- end
- end
- until turtle.forward()
- for count=0,3 do
- turtle.select(1)
- if turtle.compare() then
- turtle.dig()
- end
- turtle.turnLeft()
- end
- --[The turtle will check if the block in front of it is the target blocktype and mine it if it is. If it is a nontarget block, the turtle will reverse until it is able to climb a level]--
- end
- function up()
- turtle.select(1)
- local alt=0
- local count=0
- repeat
- if turtle.detectUp() then
- turtle.digUp()
- turtle.up()
- else
- turtle.up()
- alt=alt+1
- z=z+1
- end
- --[If the turtle has free air above it, it will ascend. It will increment 'alt' only when it ascends in free air. If it does not have free air, it will break the block above it (no matter the block) and move up. This behaviour is to help it escape caves, if required.]--
- for count=0,3 do
- turtle.select(1)
- if turtle.compare() then
- alt=0
- turtle.dig()
- end
- turtle.turnLeft()
- end --[the turtle will check each facing for target blocks. If it finds one, it will mine it and set 'alt' to zero.]--
- if alt==2 then
- turtle.down()
- turtle.down()
- z=z-2
- end
- until alt==2 --[if the turtle has gone up through free air 3 blocks and found no minable blocks or is sitting under a non-target block, it will end the sub.]--
- end
- function down()
- local cave = 0
- local count = 0
- repeat
- if turtle.detectDown() then
- turtle.select(1)
- if turtle.compareDown() then
- turtle.digDown()
- end
- else
- turtle.down()
- if turtle.compareDown() then
- turtle.digDown()
- end
- z = z - 1
- cave = cave + 1
- if cave == 3 then
- for count=0,4 do
- turtle.up()
- z=z+1
- end
- break --[If turtle thinks it's in a cave, it'll go back to the last known surface and quit the sub, returning to the For loop at forward()]--
- end
- end
- for count = 0,3 do
- turtle.select(1)
- if turtle.compare() then
- turtle.dig()
- cave = 0
- end
- turtle.turnLeft()
- end
- --[If the turtle finds target blocks on any of its 4 facings, it will mine them and reset the 'cave' counter to zero. Suspect it will check twice for every downward movement.]--
- until turtle.detectDown() --[Ends the sub (if it hasn't been ended by being in a cave) when the turtle is sitting on a block.]--
- end
- print "Width (chunk is 16)"
- x = tonumber(read())
- print "Depth (chunk is 16)"
- y = tonumber(read())
- print "And we're off. If your code doesn't work as intended, I'll be mining the clouds."
- os.pullEvent("key")
- leftright = "left" --[global because it's used in the harness.]--
- x=x/2
- y=y/2
- --[since the turtle moves forward twice for each iteration of the loop]--
- for count = 1,x do
- for notcount = 1, y do
- down()
- forward()
- up()
- forward()
- end
- if leftright=="right" then
- turtle.turnRight()
- forward()
- forward()
- forward()
- turtle.turnRight()
- leftright="left"
- else
- turtle.turnLeft()
- forward()
- forward()
- forward()
- turtle.turnLeft()
- leftright="right"
- end
- end --[Will run the turtle down until it hits a non-target block or a cave, advance it one block, run it up until alt=3 or non target block, forward and repeat. 'If' statement should make the turtle alternate left-right turns at end of y-rows.]--
- repeat
- if z>0 then
- turtle.down()
- else
- turtle.up()
- end
- until z == 0
Add Comment
Please, Sign In to add comment