Advertisement
yokmama

Awesome Branch Miner!

Jun 10th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. print("branch no kazu ha?")
  2. local tunnelNumber = read() -- ブランチの数を入力
  3. print("Branch no nagasa ha?( kojinteki niha nagakute mo 10 guraikana")
  4. local tunnelLength = read()
  5. print("kyori ha? 3 gurai ga best")
  6. local tunnelWall = read()
  7. print("Slot2 ni Toatch wo oite kudasai. jyunbi gadekitara enter site kudasai")
  8. read()
  9. local mainDistance = 0
  10. local sideDistance = 0
  11. local mainLength = tunnelNumber*(tunnelWall+1)
  12. local totalTravel = (4*tunnelLength)*(tunnelNumber+2)+(mainLength*2)
  13. print("Hituyou na nenryou : "..totalTravel)
  14. sleep(2)
  15.  
  16.     function sideWork(dist) -- 横のトンネルを作る, トンネルの距離を引数にする
  17.         for i=1,dist do
  18.             while turtle.detect() do
  19.                 turtle.dig()
  20.             end
  21.             turtle.forward()
  22.             sideDistance = sideDistance +1
  23.             turtle.digDown()
  24.             turtle.digUp()
  25.         end
  26.     end
  27.    
  28.     function mainWork(dist) -- メインのトンネルを作る, トンネルの長さを引数にする
  29.         for i=1,dist do
  30.             while turtle.detect() do
  31.                 turtle.dig()
  32.             end
  33.             turtle.forward()
  34.             mainDistance = mainDistance + 1
  35.             turtle.digDown()
  36.             turtle.digUp()
  37.         end
  38.     end
  39.  
  40.     function travel(dist) -- turtle.forward で掘る必要がないところをスキップ、または強制停止か、敵にぶつかったりとか.
  41.         for i=1, dist do
  42.             repeat
  43.             until turtle.forward() == true
  44.         end
  45.     end
  46.    
  47.     function spin() -- なぜなら、これ以上無理だから
  48.         turtle.turnRight()
  49.         turtle.turnRight()
  50.     end
  51.    
  52.     function noFuel() -- 全体の燃料を計算し必要とする燃料の数を返却
  53.         if turtle.getFuelLevel() < totalTravel then
  54.             return true
  55.         end
  56.     end
  57.    
  58.     function placeTorch() -- Slot2にトーチを設定
  59.         turtle.select(2)
  60.         turtle.placeUp()
  61.         turtle.select(1)
  62.     end
  63.    
  64.     function checkInventory() -- インベントリを確認
  65.         if turtle.getItemCount(15) > 0 then
  66.             return true
  67.         end
  68.     end
  69.    
  70.     function goHome() -- メイントンネルからスタートの位置へ戻る
  71.         spin()
  72.         travel(mainDistance)
  73.     end
  74.    
  75.     function goToMain() -- メインのトンネルへ戻る
  76.         spin()
  77.         travel(sideDistance)
  78.     end
  79.    
  80.     function main(number,length,wall) -- さぁ、掘りまくろう
  81.        
  82.         if noFuel() == true then
  83.         print("motto nenryo kudasai "..totalTravel - turtle.getFuelLevel().." ga hituyou desu.")
  84.         end
  85.        
  86.         while noFuel() do -- もしん燃料がないなら, スロット1に燃料があるかたしかめ、あるなら補給
  87.             turtle.select(1)
  88.             turtle.refuel()
  89.             sleep(0.5)
  90.         end
  91.        
  92.        
  93.         for i=1,number do -- トンネルを掘るために何度も繰り返す
  94.                
  95.             mainWork(wall+1)
  96.             turtle.back()
  97.             placeTorch()
  98.             turtle.forward()
  99.             turtle.turnRight()
  100.             sideWork(length)
  101.             placeTorch()
  102.             spin()
  103.             travel(length)
  104.             sideDistance = 0
  105.             sideWork(length)
  106.             placeTorch()
  107.             spin()
  108.             travel(length)
  109.             turtle.turnLeft()
  110.                
  111.             if checkInventory() then -- スロットに空きがないなら一旦ホームにもどって集めたブロックを捨てる
  112.                 goHome()
  113.                 turtle.select(1)
  114.                 turtle.drop()
  115.                 for slot=3,16 do
  116.                     turtle.select(slot)
  117.                     turtle.drop()
  118.                 end
  119.                 turtle.select(1)
  120.                 spin()
  121.                 travel(mainDistance)
  122.                
  123.             end
  124.            
  125.         end
  126.        
  127.         goHome()
  128.            
  129.             for slot=1,16 do
  130.                 turtle.select(slot)
  131.                 turtle.drop()
  132.             end
  133.        
  134.         print("branch kansei tugi ha dousuru?")
  135.        
  136.     end
  137.  
  138.    
  139. main(tunnelNumber,tunnelLength,tunnelWall)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement