fix(comparator): 改进比较器检测逻辑并更新安装程序版本

- 在test_comparator.lua和chest_sorter.lua中添加方法4检测redstone接口的比较器功能
- 为比较器名称查找添加更精确的匹配逻辑
- 更新installer.lua中的版本号至0.3.8 Beta 23
This commit is contained in:
2025-09-05 22:24:24 +08:00
parent ece13d7bd4
commit 69d5d36718
3 changed files with 45 additions and 5 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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..")...")