Advertisement
jam_san

cyclone4

Jun 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. -- cyclone3
  2. -- 複数回サイクロン型直下掘り
  3.  
  4. -- ######### Config #########
  5. local maxDepth = 55 -- 真下に掘り進む回数
  6. local n = 5  -- 直下掘りする回数
  7. FUEL_SLOT = 1   --燃料スロット
  8.  
  9.  
  10. -- ######### Function #########
  11. function Fuel(num) -- 燃料補給の際、燃料がある一定量以下の場合のみ給油する
  12.   turtle.select(1)
  13.   local limit = 2000
  14.   local fuel = turtle.getFuelLevel()
  15.   print (fuel)
  16.   if tonumber(fuel) <= tonumber(limit) then
  17.     r,e = turtle.refuel(num)
  18.     print (e)
  19.   else
  20.     print (fuel)
  21.   end
  22. end
  23.  
  24. function kaitenChokkabori(shita)  -- shita回だけ回転直下掘り
  25.   local countDepth = 0
  26.   for i=1,shita do
  27.     for j=1,4 do  -- 一回転しつつ正面採掘
  28.       turtle.turnLeft()
  29.       turtle.dig()
  30.     end
  31.  
  32.     turtle.digDown() -- 直下掘りして真下移動
  33.     if turtle.down() then  -- タートルが下に移動した分だけカウント
  34.         countDepth = countDepth + 1
  35.     else
  36.       break  -- これ以上下がる必要がないのでbreak
  37.     end
  38.   end
  39.   return countDepth
  40. end
  41.  
  42. function backToHome(ue)  -- ue回だけ上昇する
  43.   for i=1,ue do
  44.     turtle.up()
  45.   end
  46. end
  47.  
  48. function inChest(...)
  49.    for i=2,16 do               --スロット1の燃料は預けない
  50.        turtle.select(i)
  51.        r,e = turtle.dropDown() --rはtrueかfalseを返してくれる
  52.        print (e)
  53.    end
  54. end
  55.  
  56. -- ######### Main #########
  57. -- 直下掘り
  58. Fuel(((maxDepth*2 + 3 * n*(n+1))/80) + 1) -- 必要分を引数に燃料補給
  59. local count = 1
  60. -- 以下をn回繰り返す
  61. for i=1,n do
  62.   -- チェストから収穫ポイントまで移動する
  63.     for j=1,count do
  64.       turtle.forward()
  65.       turtle.forward()
  66.       turtle.forward()
  67.     end
  68.   -- 回転直下掘り
  69.     local depth = kaitenChokkabori(maxDepth)
  70.     print("depth: ", depth)
  71.     backToHome(depth)
  72.   -- 一旦地上に戻ってきたら、チェストまで戻る
  73.     turtle.turnLeft()
  74.     turtle.turnLeft()
  75.     for j=1,count do
  76.       turtle.forward()
  77.       turtle.forward()
  78.       turtle.forward()
  79.     end
  80.     turtle.turnLeft()
  81.     turtle.turnLeft()
  82.   -- アイテムをチェストにしまう
  83.     inChest()
  84.     count = count + 1
  85. end
  86.  
  87. -- ######### Todo #########
  88. -- 例外処理, エラー処理
  89. -- プレイヤーと衝突したときなど
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement