Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.55 KB | None | 0 0
  1. -- 整地
  2. -- 整地を行うプログラムです。
  3.  
  4. os.loadAPI("const")
  5. os.loadAPI("try")
  6.  
  7. local length, width, level = 16, 16, 0
  8. local torchInterval = 5
  9. local fPlaceDown = false
  10.  
  11. --長さ
  12. local tArgs = { ... }
  13. if #tArgs > 0 then
  14.     length = tonumber( tArgs[1] )
  15.     if tArgs[1] == "help" or tArgs[1] == "?" or length == nil then
  16.         print( "Usage: leveling <length> <width> <level> <Place Down flag : 0 or 1>" )
  17.         print( "  refuel is #"..const.refuelNm.." slot" )
  18.         print( "  [torch] is #"..const.torchNm.." slot" )
  19.         print( "  [chest] is #"..const.chestNm.." slot" )
  20.         return
  21.     end
  22.     if length < 1 then
  23.         print( "Leveling length must be positive" )
  24.         return
  25.     end
  26. end
  27.  
  28. --幅
  29. if #tArgs > 1 then
  30.     width = tonumber( tArgs[2] )
  31.     if width < 1 then
  32.         print( "Tunnel width must be positive" )
  33.         return
  34.     end
  35. else
  36.     width = length
  37. end
  38.  
  39. --掘り下げる高さ
  40. if #tArgs > 2 then
  41.     level = tonumber( tArgs[3] )
  42. end
  43.  
  44. --足場を作らないフラグ
  45. if #tArgs > 3 then
  46.     fPlaceDown = tonumber( tArgs[4] )
  47. end
  48.  
  49. -- 整地作業開始!
  50. print( "Leveling start." )
  51.  
  52. local nextLevel = 0
  53.  
  54. for x = 1, width do
  55.  
  56.     --lengthの長さの整地を行う
  57.     for z = 1, length do
  58.        
  59.         --もし開始地点と同じ高さなのに空中だったら、下に足場を作る
  60.  
  61.         if level == 0 then
  62.             if not fPlaceDown then
  63.                 turtle.select(1)
  64.                 try.placeDown()
  65.                 try.checkInventory()
  66.             end
  67.  
  68.             --もし上にブロックがあったら
  69.             while turtle.detectUp() or nextLevel > level do
  70.                 try.digUp()
  71.                 if try.isInventoryFull() then
  72.                     try.drop2chest(level)
  73.                 end
  74.                 try.up()
  75.                 level = level + 1
  76.             end
  77.  
  78.         else
  79.            
  80.             --もし上にブロックがあったら
  81.             while turtle.detectUp() do
  82.                 try.digUp()
  83.                 if try.isInventoryFull() then
  84.                     try.drop2chest(level)
  85.                 end
  86.                 try.up()
  87.                 level = level + 1
  88.             end
  89.  
  90.             nextLevel = 0
  91.  
  92.             --もし開始地点の高さより高い位置で下にブロックがなかったら
  93.             while level > 0 and not turtle.detectDown() do
  94.                 if turtle.detect() and nextLevel < level then
  95.                     nextLevel = level
  96.                 end
  97.                 turtle.digDown()
  98.                 try.down()
  99.                 level = level - 1
  100.             end
  101.  
  102.             --もし開始地点の高さより高い位置だったら
  103.             while level > 0 do
  104.                 if turtle.detect() and nextLevel < level then
  105.                     nextLevel = level
  106.                 end
  107.                 turtle.digDown()
  108.                 try.down()
  109.                 level = level - 1
  110.                 if try.isInventoryFull() then
  111.                     try.drop2chest(level)
  112.                 end
  113.             end
  114.  
  115.             if level == 0 then
  116.                 try.placeDown()
  117.                 try.checkInventory()
  118.             end
  119.  
  120.         end
  121.  
  122.         if z < length then
  123.  
  124.             if not fTorch then
  125.                 fTorch = (x % torchInterval == 1
  126.                     and z % torchInterval == 0 and try.torchPlace)
  127.             end
  128.  
  129.             if level > 0 then
  130.  
  131.                 while turtle.detect() or turtle.detectUp() do
  132.                     try.digUp()
  133.                     if try.isInventoryFull() then
  134.                         try.drop2chest(level)
  135.                     end
  136.                        
  137.                     try.up()
  138.                     level = level + 1
  139.                 end
  140.                 try.forward()
  141.  
  142.             else
  143.  
  144.                 if try.isInventoryFull() then
  145.                     try.drop2chest(level)
  146.                 end
  147.                
  148.                 --松明をたてるか?
  149.                 if fTorch then
  150.                
  151.                     -- 松明をたてる場所の横に壁があると、その壁に松明を立ててしまい
  152.                     -- その壁を壊すと松明が取れてしまうため
  153.                     -- その壁を予め壊しておく
  154.                     if x < width then
  155.                         if x % 2 == 1 then
  156.                             turtle.turnRight()
  157.                             try.dig()
  158.                             turtle.turnLeft()
  159.                         else
  160.                             turtle.turnLeft()
  161.                             try.dig()
  162.                             turtle.turnRight()
  163.                         end
  164.                     end
  165.  
  166.                     -- 氷ブロックなど松明が置けないブロックに対応するため
  167.                     -- 一度ブロックを破壊してから手持ちのブロックを設置
  168.                     turtle.digDown()
  169.                     try.placeDown()
  170.                     try.checkInventory()
  171.  
  172.                     try.dig()
  173.                     try.forward()
  174.  
  175.                     --回れ右して後ろを向く
  176.                     turtle.turnRight()
  177.                     turtle.turnRight()
  178.                    
  179.                     try.setTorch()
  180.  
  181.                     --回れ右して正面を向き直す
  182.                     turtle.turnRight()
  183.                     turtle.turnRight()
  184.  
  185.                     fTorch = false
  186.                
  187.                 else
  188.                     try.dig()
  189.                     try.forward()
  190.                 end
  191.             end
  192.         end
  193.  
  194.     end
  195.  
  196.     if x % 2 == 1 then
  197.         turtle.turnRight()
  198.     else
  199.         turtle.turnLeft()
  200.     end
  201.  
  202.     if x < width then
  203.  
  204.         --次のラインの高さまで上がる
  205.         while turtle.detect() do
  206.             try.digUp()
  207.             try.up()
  208.             level = level + 1
  209.         end
  210.         try.forward()
  211.         if x % 2 == 1 then
  212.             turtle.turnRight()
  213.         else
  214.             turtle.turnLeft()
  215.         end
  216.     end
  217.  
  218. end
  219.  
  220. while level > 0 do
  221.     turtle.digDown()
  222.     try.down()
  223.     level = level - 1
  224. end
  225.  
  226. try.drop2chest(level)
  227.  
  228. print( "Leveling complete." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement