Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #################################################################
- -- Huge wood cutter
- -- version 0.1
- -- hevohevo, License: MIT
- -- Twitter: @hevohevo, http://hevohevo.hatenablog.com/
- -- 説明
- -- このプログラムは、松の巨木(2x2)を2本を伐採するプログラムです。
- -- 使い方
- -- スロット1に松の苗木を64本入れる
- -- 以下の形に苗木とタートルを配置
- -- M: 松の苗木, T: タートル, 上が北向き(方角がとても重要)
- -- MM
- -- MM
- -- MMT
- -- MM
- -- サブ関数
- -- 上に伐採できるものがある限り、ずっと上に伐採しつつ上昇
- function cut2Up()
- repeat
- turtle.dig()
- turtle.up()
- until not turtle.digUp()
- end
- -- 隣接する場所にあるブロックの名称を調べてマッチしたらtrue
- -- 第1引数:ブロック名称(部分一致、複数可)テーブル、第2引数:調べる方角の関数
- -- 例: findBlock({"dirt", "grass"}, turtle.inspect) => true (正面に土があった)
- function findBlock(names, inspect_func)
- inspect_func = inspect_func or turtle.inspect
- local status, detail = inspect_func()
- if not status then return false end
- for i,name in ipairs(names) do
- if string.match(detail["name"],name) then
- return true
- end
- end
- return false
- end
- -- 下に土(草)ブロックを発見するまで下に伐採しつつ降りる
- function cut2Down()
- repeat
- turtle.dig()
- turtle.down()
- if findBlock({"dirt","grass"},turtle.inspectDown) then
- return
- end
- until not turtle.digDown()
- end
- -- スロット2から16のブロックを下に落とす
- function drop2_16()
- for i=2,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- end
- -- 汚いメイン関数、伐採したり、伐採後の地面に苗木を植えたり
- -- turtle.suck()を連発しているのは、少しでも落ちてくる苗木を回収するため
- function main()
- turtle.dig(); turtle.suck()
- turtle.forward()
- cut2Up()
- turtle.turnLeft()
- turtle.dig(); turtle.suck()
- turtle.forward()
- turtle.turnRight()
- cut2Up()
- cut2Down()
- turtle.dig(); turtle.suck()
- -- 伐採終了、苗木植える
- turtle.place(); turtle.suck()
- turtle.turnLeft()
- turtle.back()
- turtle.place(); turtle.suck()
- turtle.turnRight()
- turtle.place(); turtle.suck()
- turtle.back()
- turtle.place(); turtle.suck()
- end
- while true do
- -- 燃料が200未満だったり、スロット1のアイテムが4個未満ならエラー終了。
- assert(turtle.getFuelLevel()>200)
- assert(turtle.getItemCount(1)>4)
- drop2_16()
- for i=1,4 do
- local status, detail = turtle.inspect()
- if status and string.match(detail["name"],"minecraft:log") then
- main()
- drop2_16()
- end
- turtle.turnRight()
- end
- os.sleep(120)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement