svennp

miner

Oct 15th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. args = {...}
  2.  
  3. torchdistance = 5
  4. torchcounter = 0
  5. torchslot = 16
  6.  
  7. if args[1] == nil then
  8.     write "how long do you want the tunnell:"
  9.     long = tonumber(read())
  10. else
  11.     long = tonumber(args[1])
  12. end
  13.  
  14.  
  15.  
  16. --FUNCTIONS--
  17.  
  18. function mine(poo)
  19.   dig()
  20.   goforward()
  21.   digUp()
  22.   turtle.digDown()
  23.   turtle.turnLeft()
  24.   dig()
  25.   goforward()
  26.   digUp()
  27.   turtle.digDown()
  28.   goback()
  29.   turtle.turnRight()
  30.   turtle.turnRight()
  31.   dig()
  32.   goforward()
  33.   digUp()
  34.   turtle.digDown()
  35.   goback()
  36.   if torchcounter == torchdistance then
  37.     turtle.select(16)
  38.     turtle.place()
  39.     turtle.select(1)
  40.     torchcounter = 0
  41.   else
  42.     torchcounter = torchcounter + 1
  43.   end
  44.   turtle.turnLeft()
  45.  
  46.   if turtle.getItemCount(15) > 0 then
  47.     for o = poo,0,-1 do
  48.       goback()
  49.     end
  50.     return true
  51.   else return false
  52.   end
  53. end
  54.  
  55. function refuel(min)
  56.   if turtle.getFuelLevel() < min then
  57.     for l=1,16 do
  58.       if turtle.getItemCount(l) > 0 then
  59.         turtle.select(l)
  60.         if turtle.refuel(1) then
  61.           while turtle.getFuelLevel() < min and turtle.getItemCount(l) > 0 do
  62.             turtle.refuel(1)
  63.           end
  64.         end
  65.       end
  66.       if turtle.getFuelLevel() > min then
  67.         break
  68.       end
  69.     end
  70.     if turtle.getFuelLevel() < min then
  71.       print "insert fuel and press any key"
  72.       ev,pa = os.pullEvent("key")
  73.       refuel(min)
  74.      end
  75.   end
  76.   min = nil
  77.   turtle.select(1)
  78. end
  79.  
  80. function digUp()
  81.   repeat
  82.     turtle.digUp()
  83.     sleep(0.5)
  84.   until not turtle.detectUp()
  85. end
  86.  
  87. function dig()
  88.   repeat
  89.     turtle.dig()
  90.     sleep(0.5)
  91.   until not turtle.detect()
  92. end
  93.  
  94. function goback()
  95.   while not turtle.back() do end
  96. end
  97.  
  98. function goforward()
  99.   while not turtle.forward() do
  100.     turtle.attack()
  101.   end
  102. end
  103.  
  104. function gotostart()
  105.   refuel(long)
  106.   for i = 0, long do
  107.     goback()
  108.   end
  109. end
  110.  
  111. function info(counter)
  112.   term.clear()
  113.   term.setCursorPos(1,1)
  114.   print("fuel: "..turtle.getFuelLevel())
  115.   print("blocks to go: "..long - counter)
  116.   print("blocks until torch placement: "..torchdistance - torchcounter)
  117.   if turtle.getItemCount(16) < 1 then
  118.     print("")
  119.     print("place torches in slot 16!")
  120.   end
  121. end
  122.  
  123. -- MAIN --
  124.  
  125. for i = 0, long do
  126.   refuel(10)
  127.   info(i)
  128.   if mine(i) == true then
  129.     term.clear()
  130.     term.setCursorPos(1,1)
  131.     return print("INV FULL!   program terminated")
  132.   end
  133.   info(i)
  134. end
  135.  
  136. gotostart()
  137. term.clear()
  138. term.setCursorPos(1,1)
  139. print("DONE")
Advertisement
Add Comment
Please, Sign In to add comment