Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print("Startentfernung benoetigt.")
- return
- end
- local nz = -tonumber(tArgs[1])
- local left = 1
- local x, y, z = 0, 0, 0
- local xd, zd = 0, -1
- local nx = 0
- local err = false
- function mineat()
- goto(nx, 0, nz, 0, -1)
- while true do
- if not trydown() then
- home()
- break
- end
- end
- end
- function collect()
- for n = 1, 16 do
- local cnt = turtle.getItemCount(n)
- if cnt == 0 then
- return true
- end
- end
- return false
- end
- function trydown()
- while not turtle.down() do
- if turtle.detectDown() then
- if turtle.digDown() then
- if not collect() then
- return false
- end
- else
- err = true
- return false
- end
- end
- end
- y = y - 1
- return true
- end
- function unload()
- for n = 1, 16 do
- local cnt = turtle.getItemCount(n)
- if cnt > 0 then
- turtle.select(n)
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- function home()
- goto(0, 0, 0, 0, 1)
- unload()
- turn(0, -1)
- if err then
- err = false
- nz = nz - 1
- print("Now at "..(-nz).." distance...")
- else
- mineat()
- end
- end
- function turn(txd, tzd)
- while xd ~= txd or zd ~= tzd do
- turtle.turnRight()
- local tmp = xd
- xd = -zd
- zd = tmp
- end
- end
- function goto(tx, ty, tz, txd, tzd)
- while ty > y do
- turtle.up()
- y = y + 1
- end
- while ty < y do
- turtle.down()
- y = y - 1
- end
- while tz < z do
- turn(0, -1)
- turtle.forward()
- z = z - 1
- end
- while tz > z do
- turn(0, 1)
- turtle.forward()
- z = z + 1
- end
- while tx < x do
- turn(-1, 0)
- turtle.forward()
- x = x - 1
- end
- while tx > x do
- turn(1, 0)
- turtle.forward()
- x = x + 1
- end
- turn(txd, tzd)
- end
- mineat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement