Razara

digger

Jan 16th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs == 0 then
  4.     print("What do you want me to do?")
  5.     print(" dig numberOfBlocks")
  6.     print(" move left")
  7.     print(" move right")
  8.    
  9. -- relocation code
  10. elseif tArgs[1] == "move" and #tArgs>=2 then
  11.     if tArgs[2] == "right"  or tArgs[2]=="left" then
  12.         turtle.back()
  13.         if tArgs[2]=="right" then
  14.             turtle.turnRight()
  15.         else
  16.             turtle.turnLeft()
  17.         end
  18.        
  19.         for i=1,3 do turtle.forward() end
  20.        
  21.         if tArgs[2]=="right" then
  22.             turtle.turnLeft()
  23.         else
  24.             turtle.turnRight()
  25.         end
  26.        
  27.         for i = 1,2 do
  28.             turtle.dig()
  29.             turtle.forward()
  30.             turtle.digUp()
  31.             turtle.digDown()
  32.         end
  33.         turtle.back()
  34.         turtle.select(1)
  35.         turtle.placeUp()
  36.     end
  37. -- Digging code
  38. elseif tArgs[1] == "dig" then
  39.     local range = 1
  40.     if #tArgs > 1 then
  41.         range = tonumber(tArgs[2])
  42.     end
  43.    
  44.     -- Check number of torches before digging
  45.     if turtle.getItemCount(1) < range/6 then
  46.         print("I will just light up the tunnel with my personality...")
  47.     else
  48.         local x = 0
  49.         local xmax = 0
  50.  
  51.         while xmax < range-1 and range <= turtle.getFuelLevel()/2 do
  52.            
  53.                 -- empty inventory
  54.                 print("Pooping...")
  55.                 for i = 2, 16 do
  56.                     turtle.select(i)
  57.                     turtle.dropDown()
  58.                 end --end inventory drop
  59.                 turtle.select(1)
  60.                
  61.                 print("Hi Ho, Hi Ho, it's off to work we go *whistles*")
  62.                 -- move forward until wall is hit
  63.                 while turtle.forward() do
  64.                     x = x + 1
  65.                 end -- end while forward
  66.                
  67.                 -- start digging
  68.                 while turtle.getItemCount(15) == 0 and x <= range do
  69.                     local count = 0 -- counts how many blocks are broken. if above 20, assume water and move on
  70.                    
  71.                     while turtle.dig() and count < 20 do
  72.                         sleep(0.5)
  73.                         count = count + 1
  74.                     end
  75.                     turtle.forward()
  76.                     x = x + 1
  77.                     turtle.digDown()
  78.                    
  79.                     count = 0
  80.                     while turtle.digUp() and count < 20 do
  81.                         sleep(0.5)
  82.                         count = count + 1
  83.                     end
  84.                    
  85.                     --place some torches
  86.                     if x%6 == 0 then
  87.                         turtle.select(1)
  88.                         turtle.placeDown()
  89.                     end
  90.                 end -- end while digging
  91.                    
  92.                 -- go back to start
  93.                 xmax = x
  94.                 while x > 0 do
  95.                     if turtle.back() then
  96.                         x = x -1
  97.                     end
  98.                 end
  99.                
  100.             print("I got all the way to "..xmax)
  101.            
  102.         end -- end while range check
  103.     end
  104.    
  105.     if range > turtle.getFuelLevel()/2 then
  106.         print("But I'm le tired")
  107.     else
  108.         print("I fought the blocks, and I won")
  109.     end
  110. else
  111.     print("You want me to do WHAT???")
  112. end
Advertisement
Add Comment
Please, Sign In to add comment