Advertisement
Wyvern67

Mining (left turtle)

Jul 5th, 2015
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.04 KB | None | 0 0
  1. -- Fais une mine optimisée à partir d'un tunnel principal. La turtle creuse x blocs en face d'elle avant de revenir sur ses pas et de faire pareil 3 blocs plus loin dans le tunnel
  2. local function printUsage()
  3.     print( "Usage:" )
  4.     print( "mining <distance per shafts>" )
  5.     print( "Inventory:" )
  6.     print( "It is not mandatory, but fuel goes into the slot 1 and torches to the slot 2 if you care to supply some for me.")
  7. end
  8.  
  9. local function placeTorch(justChecking)
  10.     if type(turtle.getItemDetail(2)) == "table" then
  11.         if turtle.getItemDetail(2).name == "minecraft:torch" then
  12.             if not justChecking then               
  13.                 turtle.select(2)
  14.                 turtle.placeUp()
  15.                 turtle.select(blockSlot)
  16.             end
  17.             blockSlot = 3
  18.             torches = true
  19.         else
  20.             torches = false
  21.             blockSlot = 2
  22.         end
  23.     else
  24.         torches = false
  25.         blockSlot = 2
  26.     end
  27. end
  28.  
  29. local function refuel()
  30.     shell.run("refuel", "all")
  31.     if turtle.getFuelLevel() == 0 then
  32.         return false
  33.     end
  34.     turtle.select(blockSlot)
  35.     return true
  36. end
  37.  
  38. local function blockLiquids()
  39.     while turtle.up() == false do end
  40.    
  41.     _, block = turtle.inspectUp()
  42.     detect = turtle.detectUp()
  43.     if type(block) == "table" and detect == false then -- it has most likely detected a liquid
  44.         turtle.placeUp()
  45.     end
  46.    
  47.     turtle.turnLeft()
  48.     _, block = turtle.inspect()
  49.     detect = turtle.detect()
  50.     if type(block) == "table" and detect == false then
  51.         turtle.place()
  52.     end
  53.    
  54.     turtle.turnLeft()
  55.     turtle.turnLeft()
  56.     _, block = turtle.inspect()
  57.     detect = turtle.detect()
  58.     if type(block) == "table" and detect == false then
  59.         turtle.place()
  60.     end
  61.    
  62.     turtle.down()
  63.    
  64.     _, block = turtle.inspect()
  65.     detect = turtle.detect()
  66.     if type(block) == "table" and detect == false then
  67.         turtle.place()
  68.     end
  69.    
  70.     turtle.turnLeft()
  71.     turtle.turnLeft()  
  72.     _, block = turtle.inspect()
  73.     detect = turtle.detect()
  74.     if type(block) == "table" and detect == false then
  75.         turtle.place()
  76.     end
  77.     turtle.turnRight()
  78. end
  79.  
  80. function digforward()
  81.     if turtle.getFuelLevel() > 0 then
  82.         if turtle.detectDown() == false then turtle.placeDown() end
  83.    
  84.         _, block = turtle.inspectUp()
  85.         detect = turtle.detectUp()
  86.         if type(block) == "table" then
  87.             if block.name == "minecraft:gravel" or block.name == "minecraft:sand" then
  88.                 while turtle.detectUp() do turtle.digUp() sleep(0.5) end
  89.             elseif type(block) == "table" and detect == false then
  90.                 blockLiquids()
  91.             else
  92.                 while turtle.detectUp() do turtle.digUp() end
  93.             end
  94.         end
  95.        
  96.         _, block = turtle.inspect()
  97.         if type(block) == "table" then
  98.             if block.name == "minecraft:gravel" or block.name == "minecraft:sand" then
  99.                 while turtle.detect() do turtle.dig() sleep(0.5) end
  100.             else
  101.                 while turtle.detect() do turtle.dig() end
  102.             end
  103.         end
  104.        
  105.         local walked = turtle.forward()
  106.         if not walked then
  107.             print("ERROR : Unable to move forward")
  108.             if turtle.detect() then
  109.                 print("Il y a un bloc")
  110.                 while not digforward() do
  111.                     sleep(0.5)
  112.                 end
  113.             else
  114.                 print("ERROR : There must be a mob.")
  115.                 while true do
  116.                     turtle.attack()
  117.                     walked = turtle.forward()
  118.                     if walked == true then break end
  119.                 end
  120.                 print("SUCCESS : Mob gone")
  121.             end
  122.         end
  123.     else
  124.         print("Lacking energy. Attempting to refuel.")
  125.         if refuel() == false then
  126.             print("ERROR : No more fuel.")
  127.             shell.exit()
  128.         end
  129.         return false
  130.     end
  131.     return true
  132. end
  133.  
  134. local tArgs = { ... }
  135. if #tArgs == 0 then
  136.     printUsage()
  137.     return false
  138. end
  139.  
  140. local goal = tonumber(tArgs[1])-1
  141. placeTorch(true) --if arg==true then it doesnt place a torch it just does some checking
  142.  
  143. while true do
  144.     chemin = 0
  145.     while chemin <= goal do
  146.         if digforward() then
  147.             chemin = chemin+1
  148.         end
  149.     end
  150.     turtle.turnRight()
  151.     turtle.turnRight()
  152.     chemin = 0
  153.     while chemin <= goal do
  154.         while turtle.forward() == false do
  155.             --
  156.         end
  157.         chemin = chemin+1
  158.         if torches == true then
  159.             if (chemin%5) == 0 then --every 5 blocks
  160.                 placeTorch()
  161.             end
  162.         end
  163.     end
  164.  
  165.     turtle.turnLeft()
  166.     for i=0,3 do
  167.         local walked = turtle.forward()
  168.         if not walked then print("ERROR : End of tunnel") return end
  169.     end
  170.     turtle.turnLeft()
  171. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement