Advertisement
Guest User

startup

a guest
Oct 24th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.53 KB | None | 0 0
  1. if posx == nil then posx = 1 end
  2. if posy == nil then posy = 0 end
  3.  
  4.  
  5. if fieldx == nil then fieldx = 9 end
  6. if fieldy == nil then fieldy = 9 end
  7.  
  8. if wait == nil then wait = 420 end
  9. if waitafter == nil then waitafter = true end
  10.  
  11. function refuel()
  12.   if turtle.getFuelLevel() < 150 then
  13.     turtle.select(15)
  14.     turtle.refuel()
  15.     turtle.select(1)
  16.   end
  17. end
  18.    
  19.  
  20. function coord()
  21. print("Position: "..posx.." / "..posy)
  22. end
  23.  
  24. function iposx()
  25. posx = posx + 1
  26. end
  27.  
  28. function iposy()
  29. posy = posy + 1
  30. end
  31.  
  32. function dposx()
  33. posx = posx - 1
  34. end
  35.  
  36. function dposy()
  37. posy = posy - 1
  38. end
  39.  
  40. function mine()
  41.     print("doing stuff here")
  42.     turtle.select(1)
  43.     turtle.placeDown()
  44.     turtle.digDown()
  45.    
  46.     for i=5,8 do
  47.       turtle.select(i)
  48.       turtle.placeDown()
  49.     end
  50.     turtle.select(1)
  51. end
  52.  
  53. function move(dx, dy)
  54. --coord()
  55.   if dy >= posy then
  56.     moveDirY(posy, dy)
  57.     moveDirX(posx, dx)
  58.   else
  59.     moveDirX(posx, dx)
  60.     moveDirY(posy, dy)
  61.   end
  62.   coord()
  63. end
  64.  
  65. function moveDirX(ax, dx)
  66.     if ax==dx then return end
  67.     if ax == 0 then step(dx, 0) else
  68.         delta = dx - ax
  69.         step(delta, 0)
  70.     end
  71. end
  72.  
  73. function moveDirY(ay, dy)
  74.     if not (ay==dy) then
  75.     if ay == 0 then step(dy, 1) else
  76.         delta = dy - ay
  77.         step(delta, 1)
  78.     end
  79.     else
  80.     --print("Fuck!")
  81.     end
  82. end
  83.  
  84. function betrag(zahl1)
  85.     if zahl1 < 0 then return zahl1 * -1
  86.     else return zahl1
  87.     end
  88. end
  89.  
  90. function step(count, axis)
  91.     if axis == 0 then
  92.         if count < 0 then
  93.             moveLeft(betrag(count))
  94.             return true
  95.         else
  96.             moveRight(betrag(count))
  97.             return true
  98.         end
  99.     else
  100.         if count > 0 then
  101.             moveForward(betrag(count))
  102.             return true
  103.         else
  104.             moveBack(betrag(count))
  105.             return true
  106.         end
  107.     end
  108.    
  109. end
  110.  
  111. function moveRight(ci)
  112.     turtle.turnRight(1)
  113.         for i=1, ci do
  114.             print("Moving right. New: "..(posx+1).." / "..posy)
  115.             if not turtle.detect() then
  116.                 turtle.forward()
  117.                 iposx()
  118.             else print("I crashed right!")
  119.             end
  120.         end
  121.     turtle.turnLeft(1)
  122. end
  123.  
  124. function moveLeft(ci)
  125.     turtle.turnLeft(1)
  126.         for i=1, ci do
  127.             print("Moving left. New: "..(posx-1).." / "..posy)
  128.             if not turtle.detect() then
  129.                 turtle.forward()
  130.                 dposx()
  131.             else print("I crashed left!")
  132.             end
  133.         end
  134.     turtle.turnRight(1)
  135. end
  136.  
  137. function moveForward(ci)
  138.     for i=1, ci do
  139.         print("Moving forward. New: "..posx.." / "..(posy+1))
  140.         if not turtle.detect() then
  141.             turtle.forward()
  142.             iposy()
  143.         else print("I crashed forward!")
  144.         end
  145.     end
  146. end
  147.  
  148. function moveBack(ci)
  149.     turn180()
  150.     for i=1, ci do
  151.         print("Moving back. New: "..posx.." / "..(posy-1))
  152.         if not turtle.detect() then
  153.             turtle.forward()
  154.             dposy()
  155.         else print("I crashed backward!")
  156.         end
  157.     end
  158.     turn180()
  159. end
  160.  
  161. function turn180()
  162. turtle.turnRight()
  163. turtle.turnRight()
  164. end
  165.  
  166.  
  167. if waitafter then sleep(wait) end
  168. --move(5,5)
  169. --move(1,1)
  170. --move(1,2)
  171. --move(2,2)
  172.  
  173. while turtle.getItemCount(15) >= 1 do
  174.   for i=1, 9 do
  175.     for j=1, 9 do
  176.       if not ((i==4) and (j==5)) then
  177.         move(i,j)
  178.         mine()
  179.       else
  180.         move(i,j)
  181.       end
  182.     end
  183.     refuel()
  184.   end
  185.   move(1,1)
  186.  
  187. end
  188.  
  189.  
  190.  
  191. if waitafter then sleep(wait) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement