Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 整地
- -- 整地を行うプログラムです。
- os.loadAPI("const")
- os.loadAPI("try")
- local length, width, level = 16, 16, 0
- local torchInterval = 5
- local fPlaceDown = false
- --長さ
- local tArgs = { ... }
- if #tArgs > 0 then
- length = tonumber( tArgs[1] )
- if tArgs[1] == "help" or tArgs[1] == "?" or length == nil then
- print( "Usage: leveling <length> <width> <level> <Place Down flag : 0 or 1>" )
- print( " refuel is #"..const.refuelNm.." slot" )
- print( " [torch] is #"..const.torchNm.." slot" )
- print( " [chest] is #"..const.chestNm.." slot" )
- return
- end
- if length < 1 then
- print( "Leveling length must be positive" )
- return
- end
- end
- --幅
- if #tArgs > 1 then
- width = tonumber( tArgs[2] )
- if width < 1 then
- print( "Tunnel width must be positive" )
- return
- end
- else
- width = length
- end
- --掘り下げる高さ
- if #tArgs > 2 then
- level = tonumber( tArgs[3] )
- end
- --足場を作らないフラグ
- if #tArgs > 3 then
- fPlaceDown = tonumber( tArgs[4] )
- end
- -- 整地作業開始!
- print( "Leveling start." )
- local nextLevel = 0
- for x = 1, width do
- --lengthの長さの整地を行う
- for z = 1, length do
- --もし開始地点と同じ高さなのに空中だったら、下に足場を作る
- if level == 0 then
- if not fPlaceDown then
- turtle.select(1)
- try.placeDown()
- try.checkInventory()
- end
- --もし上にブロックがあったら
- while turtle.detectUp() or nextLevel > level do
- try.digUp()
- if try.isInventoryFull() then
- try.drop2chest(level)
- end
- try.up()
- level = level + 1
- end
- else
- --もし上にブロックがあったら
- while turtle.detectUp() do
- try.digUp()
- if try.isInventoryFull() then
- try.drop2chest(level)
- end
- try.up()
- level = level + 1
- end
- nextLevel = 0
- --もし開始地点の高さより高い位置で下にブロックがなかったら
- while level > 0 and not turtle.detectDown() do
- if turtle.detect() and nextLevel < level then
- nextLevel = level
- end
- turtle.digDown()
- try.down()
- level = level - 1
- end
- --もし開始地点の高さより高い位置だったら
- while level > 0 do
- if turtle.detect() and nextLevel < level then
- nextLevel = level
- end
- turtle.digDown()
- try.down()
- level = level - 1
- if try.isInventoryFull() then
- try.drop2chest(level)
- end
- end
- if level == 0 then
- try.placeDown()
- try.checkInventory()
- end
- end
- if z < length then
- if not fTorch then
- fTorch = (x % torchInterval == 1
- and z % torchInterval == 0 and try.torchPlace)
- end
- if level > 0 then
- while turtle.detect() or turtle.detectUp() do
- try.digUp()
- if try.isInventoryFull() then
- try.drop2chest(level)
- end
- try.up()
- level = level + 1
- end
- try.forward()
- else
- if try.isInventoryFull() then
- try.drop2chest(level)
- end
- --松明をたてるか?
- if fTorch then
- -- 松明をたてる場所の横に壁があると、その壁に松明を立ててしまい
- -- その壁を壊すと松明が取れてしまうため
- -- その壁を予め壊しておく
- if x < width then
- if x % 2 == 1 then
- turtle.turnRight()
- try.dig()
- turtle.turnLeft()
- else
- turtle.turnLeft()
- try.dig()
- turtle.turnRight()
- end
- end
- -- 氷ブロックなど松明が置けないブロックに対応するため
- -- 一度ブロックを破壊してから手持ちのブロックを設置
- turtle.digDown()
- try.placeDown()
- try.checkInventory()
- try.dig()
- try.forward()
- --回れ右して後ろを向く
- turtle.turnRight()
- turtle.turnRight()
- try.setTorch()
- --回れ右して正面を向き直す
- turtle.turnRight()
- turtle.turnRight()
- fTorch = false
- else
- try.dig()
- try.forward()
- end
- end
- end
- end
- if x % 2 == 1 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- if x < width then
- --次のラインの高さまで上がる
- while turtle.detect() do
- try.digUp()
- try.up()
- level = level + 1
- end
- try.forward()
- if x % 2 == 1 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- end
- while level > 0 do
- turtle.digDown()
- try.down()
- level = level - 1
- end
- try.drop2chest(level)
- print( "Leveling complete." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement