From 69d5d36718b42c8fcf1bd8bd83b734a1fc5cd018 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Fri, 5 Sep 2025 22:24:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(comparator):=20=E6=94=B9=E8=BF=9B=E6=AF=94?= =?UTF-8?q?=E8=BE=83=E5=99=A8=E6=A3=80=E6=B5=8B=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=89=E8=A3=85=E7=A8=8B=E5=BA=8F=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在test_comparator.lua和chest_sorter.lua中添加方法4检测redstone接口的比较器功能 - 为比较器名称查找添加更精确的匹配逻辑 - 更新installer.lua中的版本号至0.3.8 Beta 23 --- .../lua/rom/programs/chest_sorter.lua | 32 +++++++++++++++++-- .../lua/rom/programs/test_comparator.lua | 16 +++++++++- installer.lua | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/data/computercraft/lua/rom/programs/chest_sorter.lua b/data/computercraft/lua/rom/programs/chest_sorter.lua index eaad092..26e386e 100644 --- a/data/computercraft/lua/rom/programs/chest_sorter.lua +++ b/data/computercraft/lua/rom/programs/chest_sorter.lua @@ -52,7 +52,13 @@ if not comparator then print(colors.yellow .. "Method 1 failed. Trying peripheral.find..." .. colors.white) comparator = peripheral.find("comparator") if comparator then - comparator_name = peripheral.find("comparator") + -- 查找比较器名称 + for _, name in ipairs(peripherals) do + if peripheral.wrap(name) == comparator then + comparator_name = name + break + end + end print(colors.green .. "Comparator detected using peripheral.find!" .. colors.white) end end @@ -60,17 +66,37 @@ end -- 方法3: 尝试使用redstone比较器的其他可能名称 if not comparator then print(colors.yellow .. "Method 2 failed. Trying alternative names..." .. colors.white) - local alternative_names = {"redstone_comparator", "minecraft:comparator", "comparator_block"} + local alternative_names = {"redstone_comparator", "minecraft:comparator", "comparator_block", "comparator"} for _, alt_name in ipairs(alternative_names) do comparator = peripheral.find(alt_name) if comparator then - comparator_name = alt_name + -- 查找比较器名称 + for _, name in ipairs(peripherals) do + if peripheral.wrap(name) == comparator then + comparator_name = name + break + end + end print(colors.green .. "Comparator detected using alternative name: " .. alt_name .. "!" .. colors.white) break end end end +-- 方法4: 尝试检测redstone接口 +if not comparator then + print(colors.yellow .. "Method 3 failed. Trying redstone interface..." .. colors.white) + local redstone = peripheral.find("redstone") + if redstone then + -- 检查redstone接口是否有比较器功能 + if type(redstone.getComparatorOutput) == "function" then + comparator = redstone + comparator_name = "redstone_interface" + print(colors.green .. "Found redstone interface with comparator functionality!" .. colors.white) + end + end +end + if not comparator then -- 如果仍然没有找到比较器,列出所有连接的外围设备 print(colors.red .. "No comparator detected!" .. colors.white) diff --git a/data/computercraft/lua/rom/programs/test_comparator.lua b/data/computercraft/lua/rom/programs/test_comparator.lua index 1231427..4796376 100644 --- a/data/computercraft/lua/rom/programs/test_comparator.lua +++ b/data/computercraft/lua/rom/programs/test_comparator.lua @@ -65,7 +65,7 @@ end -- 方法3: 尝试使用redstone比较器的其他可能名称 if not comparator then print(colors.yellow .. "Method 2 failed. Trying alternative names..." .. colors.white) - local alternative_names = {"redstone_comparator", "minecraft:comparator", "comparator_block"} + local alternative_names = {"redstone_comparator", "minecraft:comparator", "comparator_block", "comparator"} for _, alt_name in ipairs(alternative_names) do comparator = peripheral.find(alt_name) if comparator then @@ -82,6 +82,20 @@ if not comparator then end end +-- 方法4: 尝试检测redstone接口 +if not comparator then + print(colors.yellow .. "Method 3 failed. Trying redstone interface..." .. colors.white) + local redstone = peripheral.find("redstone") + if redstone then + -- 检查redstone接口是否有比较器功能 + if type(redstone.getComparatorOutput) == "function" then + comparator = redstone + comparator_name = "redstone_interface" + print(colors.green .. "Found redstone interface with comparator functionality!" .. colors.white) + end + end +end + -- 显示结果 if not comparator then print(colors.red .. "No comparator detected!" .. colors.white) diff --git a/installer.lua b/installer.lua index dfd2790..7c6e81a 100644 --- a/installer.lua +++ b/installer.lua @@ -1,5 +1,5 @@ -- LeonOS installer -local INSTALLER_VERSION = "0.3.8 Beta 22" +local INSTALLER_VERSION = "0.3.8 Beta 23" local DEFAULT_ROM_DIR = "/leonos" print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")