Advertisement
Guest User

miner

a guest
Feb 9th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. local tArgs = { ... }
  2. if #tArgs ~= 1 then
  3.   print("Startentfernung benoetigt.")
  4.   return
  5. end
  6.  
  7. local nz = -tonumber(tArgs[1])
  8.  
  9. local left = 1
  10. local x, y, z = 0, 0, 0
  11. local xd, zd = 0, -1
  12. local nx = 0
  13. local err = false
  14.  
  15. function mineat()
  16.   goto(nx, 0, nz, 0, -1)
  17.   while true do
  18.     if not trydown() then
  19.       home()
  20.       break
  21.     end
  22.   end
  23. end
  24.  
  25. function collect()
  26.   for n = 1, 16 do
  27.     local cnt = turtle.getItemCount(n)
  28.     if cnt == 0 then
  29.       return true
  30.     end
  31.   end
  32.   return false
  33. end
  34.  
  35. function trydown()
  36.   while not turtle.down() do
  37.     if turtle.detectDown() then
  38.       if turtle.digDown() then
  39.         if not collect() then
  40.           return false
  41.         end
  42.       else
  43.         err = true
  44.         return false
  45.       end
  46.     end
  47.   end
  48.   y = y - 1
  49.   return true
  50. end
  51.  
  52. function unload()
  53.   for n = 1, 16 do
  54.     local cnt = turtle.getItemCount(n)
  55.     if cnt > 0 then
  56.       turtle.select(n)
  57.       turtle.drop()
  58.     end
  59.   end
  60.   turtle.select(1)
  61. end
  62.  
  63. function home()
  64.   goto(0, 0, 0, 0, 1)
  65.   unload()
  66.   turn(0, -1)
  67.   if err then
  68.     err = false
  69.     nz = nz - 1
  70.     print("Now at "..(-nz).." distance...")
  71.   else
  72.     mineat()
  73.   end
  74. end
  75.  
  76. function turn(txd, tzd)
  77.   while xd ~= txd or zd ~= tzd do
  78.     turtle.turnRight()
  79.     local tmp = xd
  80.     xd = -zd
  81.     zd = tmp
  82.   end
  83. end
  84.  
  85. function goto(tx, ty, tz, txd, tzd)
  86.   while ty > y do
  87.     turtle.up()
  88.     y = y + 1
  89.   end
  90.   while ty < y do
  91.     turtle.down()
  92.     y = y - 1
  93.   end
  94.   while tz < z do
  95.     turn(0, -1)
  96.     turtle.forward()
  97.     z = z - 1
  98.   end
  99.   while tz > z do
  100.     turn(0, 1)
  101.     turtle.forward()
  102.     z = z + 1
  103.   end
  104.   while tx < x do
  105.     turn(-1, 0)
  106.     turtle.forward()
  107.     x = x - 1
  108.   end
  109.   while tx > x do
  110.     turn(1, 0)
  111.     turtle.forward()
  112.     x = x + 1
  113.   end
  114.   turn(txd, tzd)
  115. end
  116.  
  117. mineat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement