mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 06:47:00 +00:00
fix(comparator): 改进比较器检测逻辑并更新安装程序版本
- 在test_comparator.lua和chest_sorter.lua中添加方法4检测redstone接口的比较器功能 - 为比较器名称查找添加更精确的匹配逻辑 - 更新installer.lua中的版本号至0.3.8 Beta 23
This commit is contained in:
@@ -52,7 +52,13 @@ if not comparator then
|
|||||||
print(colors.yellow .. "Method 1 failed. Trying peripheral.find..." .. colors.white)
|
print(colors.yellow .. "Method 1 failed. Trying peripheral.find..." .. colors.white)
|
||||||
comparator = peripheral.find("comparator")
|
comparator = peripheral.find("comparator")
|
||||||
if comparator then
|
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)
|
print(colors.green .. "Comparator detected using peripheral.find!" .. colors.white)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -60,17 +66,37 @@ end
|
|||||||
-- 方法3: 尝试使用redstone比较器的其他可能名称
|
-- 方法3: 尝试使用redstone比较器的其他可能名称
|
||||||
if not comparator then
|
if not comparator then
|
||||||
print(colors.yellow .. "Method 2 failed. Trying alternative names..." .. colors.white)
|
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
|
for _, alt_name in ipairs(alternative_names) do
|
||||||
comparator = peripheral.find(alt_name)
|
comparator = peripheral.find(alt_name)
|
||||||
if comparator then
|
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)
|
print(colors.green .. "Comparator detected using alternative name: " .. alt_name .. "!" .. colors.white)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
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
|
if not comparator then
|
||||||
-- 如果仍然没有找到比较器,列出所有连接的外围设备
|
-- 如果仍然没有找到比较器,列出所有连接的外围设备
|
||||||
print(colors.red .. "No comparator detected!" .. colors.white)
|
print(colors.red .. "No comparator detected!" .. colors.white)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ end
|
|||||||
-- 方法3: 尝试使用redstone比较器的其他可能名称
|
-- 方法3: 尝试使用redstone比较器的其他可能名称
|
||||||
if not comparator then
|
if not comparator then
|
||||||
print(colors.yellow .. "Method 2 failed. Trying alternative names..." .. colors.white)
|
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
|
for _, alt_name in ipairs(alternative_names) do
|
||||||
comparator = peripheral.find(alt_name)
|
comparator = peripheral.find(alt_name)
|
||||||
if comparator then
|
if comparator then
|
||||||
@@ -82,6 +82,20 @@ if not comparator then
|
|||||||
end
|
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
|
if not comparator then
|
||||||
print(colors.red .. "No comparator detected!" .. colors.white)
|
print(colors.red .. "No comparator detected!" .. colors.white)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-- LeonOS installer
|
-- LeonOS installer
|
||||||
local INSTALLER_VERSION = "0.3.8 Beta 22"
|
local INSTALLER_VERSION = "0.3.8 Beta 23"
|
||||||
local DEFAULT_ROM_DIR = "/leonos"
|
local DEFAULT_ROM_DIR = "/leonos"
|
||||||
|
|
||||||
print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")
|
print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")
|
||||||
|
|||||||
Reference in New Issue
Block a user