Advertisement
Guest User

t

a guest
Oct 25th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. local tArgs ={...}
  2. local torchLoc = 1
  3. local torchDist = 6
  4.  
  5. function findTorchLoc()
  6.   torchLoc = 0
  7.   for i = 1,16 do
  8.     local data = turtle.getItemDetail(i)  
  9. --    print("i",i)
  10.     if turtle.getItemCount(i) > 0 then
  11.       if data.name == "minecraft:torch" then
  12.         torchLoc = i                  
  13.         print("torchLoc: ", torchLoc)
  14.       end
  15.     end
  16.   end    
  17. end
  18.  
  19. function placeTorch()
  20.   findTorchLoc()
  21.   if torchLoc > 0 then
  22.     turtle.turnLeft()
  23.     turtle.turnLeft()
  24.     turtle.select(torchLoc)
  25.     turtle.place()
  26.     turtle.turnLeft()
  27.     turtle.turnLeft()
  28.   end
  29. end
  30.  
  31. function checkFuel()
  32.   local slot = 1
  33.   while turtle.getFuelLevel() < 80 do    
  34.     print("Fuel Level:", turtle.getFuelLevel())
  35.     for i=1,16 do      
  36.       turtle.select(i)
  37.       turtle.refuel(20)        
  38.     end
  39.     print("Fuel Level:", turtle.getFuelLevel())
  40.   end
  41. end
  42.  
  43. function findSlot(ItemName)
  44.     for i =1,16 do      
  45.       if turtle.getItemCount(i) > 0 then  
  46.         -- print(turtle.getItemCount(i))
  47.         local data2 = turtle.getItemDetail(i)
  48. --        print(data2.name)
  49. --        print(ItemName)
  50.         if ItemName == data2.name then
  51.           return
  52.         end
  53.       end
  54.     end
  55. end
  56.  
  57. function dig(direction)
  58.   if direction == "up" then
  59.     local success, data = turtle.inspectUp()
  60.     turtle.digUp()      
  61.   elseif direction == "down" then
  62.     local success, data = turtle.inspectDonw()
  63.     while data.name ~= "minecraft:gravel" do  
  64.       turtle.digDown()
  65.     end  
  66.     findSlot(data.name)
  67.     turtle.digDown()
  68.   else        
  69.     local succ, data = turtle.inspect()
  70.     while data.name == "minecraft:gravel" do
  71.       turtle.dig()
  72.       succ, data = turtle.inspect()
  73.       print(data.name)
  74.     end      
  75.     findSlot(data.name)
  76.     turtle.dig()
  77.   end  
  78. end
  79.  
  80. function digForward()
  81.   dig()
  82.   turtle.forward()
  83.   dig("up")
  84.   turtle.turnLeft()
  85.   dig()
  86.   turtle.up()
  87.   dig()
  88.   turtle.turnLeft()
  89.   turtle.turnLeft()
  90.   dig()
  91.   turtle.down()
  92.   dig()
  93.   turtle.turnLeft()
  94. end
  95.  
  96.  
  97.  
  98. distance = 1
  99.  
  100.  
  101.  
  102. local startFace = 0
  103. distance = tArgs[1]
  104. if tArgs[2] == "right" then
  105.   print ("Digging forward and to the right")
  106.   startFace = 2  
  107. elseif tArgs[2] == 'left' then
  108.   print ("Digging forward and to the left")
  109.   startFace = 1
  110. end
  111.  
  112. findTorchLoc()
  113. local continue = true
  114.  
  115. while continue do
  116.   local currentDist = 1
  117.   for i = 1, distance do
  118.     checkFuel()
  119.     digForward()
  120.     currentDist = currentDist + 1
  121.     if math.fmod(currentDist, torchDist) == 0 then
  122.       placeTorch()
  123.     end
  124.   end
  125.  
  126.   if startFace == 1 then
  127.     turtle.turnLeft()
  128.     turtle.forward()
  129.     turtle.dig()
  130.     turtle.forward()
  131.     turtle.dig()
  132.     turtle.forward()
  133.     turtle.turnLeft()    
  134.     startFace = 2
  135.   elseif startFace == 2 then
  136.     turtle.turnRight()
  137.     turtle.forward()
  138.     turtle.dig()
  139.     turtle.forward()
  140.     turtle.dig()
  141.     turtle.forward()
  142.     turtle.turnRight()
  143.     startFace = 1
  144.   elseif startFace == 0 then
  145.     continue = false
  146.   end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement