Advertisement
yokmama

saikyo-branchmininng

Jul 29th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. haba = 3
  2. nagasa = 15
  3.  
  4. -- ブランチの数を入力
  5. io.write("branch no kazu?")
  6. branch = io.read()
  7.  
  8.  
  9. homeKyori = 0
  10. branchKyori = 0
  11.  
  12.  -- 横のトンネルを作る, トンネルの距離を引数にする
  13. function branchWork(kyori)
  14.     for i=1,kyori do
  15.         -- 砂があるかもしれないのでなくなるまで掘る
  16.         while turtle.detect() do
  17.             turtle.dig()
  18.         end
  19.         turtle.forward()
  20.         branchKyori = branchKyori +1
  21.         turtle.digDown()
  22.         if i % 8 == 0 then
  23.             placeTorch()
  24.         end
  25.     end
  26. end
  27.  
  28. -- メインのトンネルを作る, トンネルの長さを引数にする
  29. function mainWork()
  30.     for i=1, haba+1 do
  31.         -- 砂があるかもしれないのでなくなるまで掘る
  32.         while turtle.detect() do
  33.             turtle.dig()
  34.         end
  35.         turtle.forward()
  36.         homeKyori = homeKyori + 1
  37.         turtle.digDown()
  38.     end
  39. end
  40.  
  41. -- kyoriだけ進む
  42. function skip(kyori)
  43.     for i=1, kyori do
  44.         repeat
  45.         until turtle.forward() == true
  46.     end
  47. end
  48.  
  49. -- 方向転換
  50. function spin()
  51.     turtle.turnRight()
  52.     turtle.turnRight()
  53. end
  54.  
  55. -- トーチを設置
  56. function placeTorch()
  57.     turtle.select(1)
  58.     turtle.placeDown()
  59. end
  60.  
  61. -- インベントリを確認
  62. function checkInventory()
  63.     if turtle.getItemCount(15) > 0 then
  64.         return true
  65.     end
  66. end
  67.  
  68. -- メイントンネルからスタートの位置へ戻る
  69. function goHome()
  70.     skip(homeKyori)
  71.     turtle.turnRight()
  72.     turtle.down()
  73.     for slot=2,16 do
  74.         turtle.select(slot)
  75.         turtle.drop()
  76.     end
  77.     turtle.turnRight()
  78. end
  79.  
  80. -- メインのトンネルへ戻る
  81. function goToMain()
  82.     spin()
  83.     skip(branchKyori)
  84. end
  85.  
  86. -- メインの処理
  87. turtle.up()
  88. for i=1,branch do
  89.    
  90.     --メインのトンネルを1ブランチ分掘る  
  91.     mainWork()
  92.  
  93.     -- ブランチ部分にトーチを置く
  94.     placeTorch()
  95.  
  96.     -- 右のブランチを掘る
  97.     turtle.turnRight()
  98.     branchKyori = 0
  99.     branchWork(nagasa)
  100.     goToMain()
  101.  
  102.     -- 左のブランチを掘る
  103.     branchKyori = 0
  104.     branchWork(nagasa)
  105.     goToMain()
  106.        
  107.     -- スロットに空きがないなら一旦ホームにもどって集めたブロックを捨てる
  108.     if checkInventory() then
  109.         turtle.turnRight()          
  110.         goHome()
  111.         turtle.up()
  112.         skip(homeKyori)
  113.     else
  114.         turtle.turnLeft()          
  115.     end
  116.    
  117. end
  118. --折り返してホームに帰る
  119. spin()
  120. goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement