From b46e9095ceba373d6713805fe40ab9a11785e162 Mon Sep 17 00:00:00 2001 From: ponzu07 <16078128+ponzu07@users.noreply.github.com> Date: Wed, 5 Feb 2025 00:36:53 +0900 Subject: [PATCH 1/2] Create kikori.lua --- turtle/kikori.lua | 164 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 turtle/kikori.lua diff --git a/turtle/kikori.lua b/turtle/kikori.lua new file mode 100644 index 0000000..538012f --- /dev/null +++ b/turtle/kikori.lua @@ -0,0 +1,164 @@ +-- アイテムの定義 +BIRCH_SAPLING = "minecraft:birch_sapling" -- 白樺の苗木 +BIRCH_LOG = "minecraft:birch_log" -- 白樺の原木 +COBBLESTONE = "minecraft:cobblestone" -- 丸石 + +ROW_COUNT = 5 +ALL_COUNT = 15 +ueta = 0 + +-- 指定されたアイテムIDのスロットを探して選択する +function findItem(itemId) + for slot = 1, 16 do + local item = turtle.getItemDetail(slot) + if item and item.name == itemId then + turtle.select(slot) + return true + end + end + return false +end + +-- 木を上方向に向かって切る +function kikori() + if not turtle.dig() then return false end + if not turtle.forward() then return false end + local k_count = 0 + + while true do + local success, data = turtle.inspectUp() + if success and data and data.name == BIRCH_LOG then + if not turtle.digUp() then break end + if not turtle.up() then break end + k_count = k_count + 1 + else + -- 地上に戻る + for i = 1, k_count do + if not turtle.down() then break end + end + if not turtle.back() then return false end + ueru() + break + end + end + return true +end + +-- 苗木を植える +function ueru() + if findItem(BIRCH_SAPLING) then + if turtle.place() then + ukai() + return true + end + end + return false +end + +-- 次の位置に移動(障害物があれば回避) +function ukai() + if not turtle.up() then return false end + + -- 前方の移動(2ブロック)で障害物があれば掘る + for i = 1, 2 do + if turtle.detect() then + turtle.dig() + end + if not turtle.forward() then return false end + end + + if not turtle.down() then return false end + return true +end + +-- デバッグ用:インベントリの内容を表示 +function printInventory() + for slot = 1, 16 do + local item = turtle.getItemDetail(slot) + if item then + print(string.format("Slot %d: %s", slot, item.name)) + end + end +end + +-- 安全な前進(障害物があれば掘る) +function safeForward() + if turtle.detect() then + local success, block = turtle.inspect() + if success and block then + if block.name == BIRCH_SAPLING or block.name == BIRCH_LOG then + turtle.dig() + end + end + end + return turtle.forward() +end + +-- メインプログラム + +print("Current inventory:") +printInventory() + +local sayuu_f = 1 +safeForward() -- 最初の一歩 + +while true do + -- エリアの終了判定 + if ueta == ALL_COUNT then + turtle.turnRight() + turtle.turnRight() + ueta = 0 + end + + -- 苗木の確認 + if not findItem(BIRCH_SAPLING) then + print("Error: No saplings left") + break + end + + -- 列の終わりの処理 + if ueta ~= 0 and ueta % ROW_COUNT == 0 then + safeForward() + + if sayuu_f == 1 then + turtle.turnRight() + for i = 1, 6 do + safeForward() + end + turtle.turnRight() + else + turtle.turnLeft() + for i = 1, 6 do + safeForward() + end + turtle.turnLeft() + end + sayuu_f = -sayuu_f + end + + safeForward() + turtle.suck() + + -- 丸石の確認と作業実行 + local success, block = turtle.inspectDown() + if success and block and block.name == COBBLESTONE then + -- 原木があれば伐採 + local front_success, front_block = turtle.inspect() + if front_success and front_block and front_block.name == BIRCH_LOG then + kikori() + elseif not turtle.detect() then + ueru() + end + + -- 苗木があれば次の位置へ + local sapling_success, sapling_block = turtle.inspect() + if sapling_success and sapling_block and sapling_block.name == BIRCH_SAPLING then + ukai() + end + + ueta = ueta + 1 + end +end + +print("Program finished") +print("Total planted:", ueta) From 42ab3148606e8bfa942b6af8adf7f2c0c050c7d9 Mon Sep 17 00:00:00 2001 From: kazy157 Date: Wed, 5 Feb 2025 01:24:55 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=81=E3=82=A7=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=AB=E5=8E=9F=E6=9C=A8=E3=81=A8=E6=9C=A8=E3=81=AE=E6=A3=92?= =?UTF-8?q?=E3=82=92=E6=A0=BC=E7=B4=8D=E3=81=99=E3=82=8B=E3=81=A8=E3=81=93?= =?UTF-8?q?=E3=82=8D=E3=81=BE=E3=81=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- turtle/kikori.lua | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/turtle/kikori.lua b/turtle/kikori.lua index 538012f..886ce15 100644 --- a/turtle/kikori.lua +++ b/turtle/kikori.lua @@ -2,6 +2,9 @@ BIRCH_SAPLING = "minecraft:birch_sapling" -- 白樺の苗木 BIRCH_LOG = "minecraft:birch_log" -- 白樺の原木 COBBLESTONE = "minecraft:cobblestone" -- 丸石 +CHEST = "minecraft:chest" -- チェスト +STICK = "minecraft:stick" -- 木の棒 +BONE_MEAL_ID = "minecraft:bone_meal" -- 骨粉 ROW_COUNT = 5 ALL_COUNT = 15 @@ -19,6 +22,26 @@ function findItem(itemId) return false end +-- 指定されたアイテムIDを移動する +function dropItem (itemId) + if findItem (itemId) then + turtle.drop() + return true + else + return false + end +end + +-- 骨粉が手持ちにあれば使用する。 +function useBoneMeal() + if findItem("minecraft:bone_meal") then + turtle.place() + return true + else + return false + end +end + -- 木を上方向に向かって切る function kikori() if not turtle.dig() then return false end @@ -71,22 +94,12 @@ function ukai() return true end --- デバッグ用:インベントリの内容を表示 -function printInventory() - for slot = 1, 16 do - local item = turtle.getItemDetail(slot) - if item then - print(string.format("Slot %d: %s", slot, item.name)) - end - end -end - -- 安全な前進(障害物があれば掘る) function safeForward() if turtle.detect() then local success, block = turtle.inspect() if success and block then - if block.name == BIRCH_SAPLING or block.name == BIRCH_LOG then + if block.name == BIRCH_LOG then turtle.dig() end end @@ -97,7 +110,6 @@ end -- メインプログラム print("Current inventory:") -printInventory() local sayuu_f = 1 safeForward() -- 最初の一歩 @@ -105,6 +117,11 @@ safeForward() -- 最初の一歩 while true do -- エリアの終了判定 if ueta == ALL_COUNT then + local success, block = turtle.inspect() + if success and block and block.name == CHEST then + dropItem(BIRCH_LOG) + dropItem(STICK) + end turtle.turnRight() turtle.turnRight() ueta = 0 @@ -158,7 +175,5 @@ while true do ueta = ueta + 1 end + print("Total planted:", ueta) end - -print("Program finished") -print("Total planted:", ueta)