feat(installer): 更新安装程序版本至0.3.8 Beta 18

docs: 添加箱子分类器教程和程序文件
This commit is contained in:
2025-09-05 21:43:49 +08:00
parent e2a60909c6
commit d95eba3cf8
3 changed files with 361 additions and 1 deletions

View File

@@ -0,0 +1,94 @@
# Chest Sorter Tutorial
## Overview
The Chest Sorter program allows you to automatically sort items from an input chest into different output chests based on categories you define. This tutorial will guide you through setting up and using the program.
## Required Materials
- 1 Computer (any tier)
- 1 Comparator
- At least 2 Chests (more recommended for better organization)
- Redstone dust (for connections)
- Items to sort (coal, iron ore, tools, etc.)
## Hardware Setup
1. Place the computer on the ground.
2. Place the comparator next to the computer.
3. Connect the comparator to all chests you want to use:
- Input chest (where you'll place items to sort)
- Output chests (for different categories)
4. Ensure all chests are within 12 blocks of the comparator for wireless connection.
- Alternatively, use redstone cables to connect chests further away.
## Program Installation
The Chest Sorter program is included in LeonOS. To access it:
1. Turn on the computer.
2. Type `chest_sorter` and press Enter to run the program.
## First Time Setup Wizard
When you run the program for the first time, you'll go through a setup wizard:
1. **Select Input Chest**:
- The program will list all connected chests.
- Enter the number corresponding to the chest you want to use as input.
2. **Assign Output Chests**:
- For each remaining chest, you'll be prompted to assign a category.
- Enter a descriptive category name (e.g., 'coal', 'tools', 'food').
- Type 'done' when you've assigned all desired categories.
3. **Configuration Saved**:
- Your settings will be saved to `/chest_sorter_config.json`.
- You can re-run the setup by deleting this file.
## Using the Program
1. After setup, the program will start automatically sorting items.
2. Place items in the input chest.
3. The program will:
- Detect items in the input chest
- Identify the appropriate category based on item name
- Move the item to the corresponding output chest
4. Press `Ctrl+T` to stop the program.
## Category Matching Rules
The program matches items to categories using simple string matching:
- It checks if the category name appears in the item's internal name or display name
- Example: A category named 'coal' will match 'minecraft:coal' and 'minecraft:charcoal'
- Example: A category named 'tool' will match 'minecraft:iron_pickaxe' and 'minecraft:gold_axe'
## Best Practices
- Use specific category names for better sorting (e.g., 'iron_ore' instead of 'ore')
- Create separate categories for similar items (e.g., 'swords', 'pickaxes')
- Label your output chests physically to remember which category is which
- Regularly empty output chests to prevent them from becoming full
## Troubleshooting
- **No chests detected**:
- Check that all chests are properly connected to the comparator
- Ensure the comparator is connected to the computer
- **Items not sorting correctly**:
- Check that category names match item names appropriately
- Verify that output chests are not full
- **Program stops unexpectedly**:
- Check the computer's fuel level (for advanced computers)
- Make sure no redstone signal is interrupting the computer
## Running the Tutorial In-Game
You can view this tutorial in-game by running:
```
chest_sorter tutorial
```
## Example Setup
Here's an example of a good setup:
- Input chest: chest_0
- Output chests:
- 'coal': chest_1
- 'iron': chest_2
- 'tools': chest_3
- 'food': chest_4
This would sort all coal-related items to chest_1, iron-related items to chest_2, etc.
Happy sorting!

View File

@@ -0,0 +1,266 @@
-- Chest Sorter Program
-- Part of LeonOS for CC Tweaked
local term = require("term")
local colors = require("colors")
local peripheral = require("peripheral")
local textutils = require("textutils")
local os = require("os")
local fs = require("fs")
-- 配置文件路径
local CONFIG_FILE = "/chest_sorter_config.json"
-- 保存当前颜色设置
local old_fg = term.getTextColor()
local old_bg = term.getBackgroundColor()
-- 设置名称栏颜色并显示
term.setTextColor(colors.white)
term.setBackgroundColor(colors.blue)
term.at(1, 1).clearLine()
term.at(1, 1).write("=== Chest Sorter ===")
-- 恢复颜色设置
term.setTextColor(old_fg)
term.setBackgroundColor(old_bg)
term.at(1, 2)
-- 检查是否有调解器(comparator)连接
local comparators = peripheral.find("comparator")
if not comparators then
error("No comparator detected. Please connect a comparator to the computer.", 0)
end
-- 定义配置变量
local config = {
input_chest = nil,
output_chests = {}
}
-- 加载配置
local function loadConfig()
if fs.exists(CONFIG_FILE) then
local file = fs.open(CONFIG_FILE, "r")
local content = file.readAll()
file.close()
config = textutils.unserialiseJSON(content)
return true
end
return false
end
-- 保存配置
local function saveConfig()
local file = fs.open(CONFIG_FILE, "w")
file.write(textutils.serialiseJSON(config))
file.close()
end
-- 设置向导
local function setupWizard()
print(colors.yellow .. "First time setup wizard..." .. colors.white)
print("This will guide you through setting up your chest sorter.")
print("")
-- 列出所有连接的箱子
local chests = peripheral.getNames()
if #chests == 0 then
error("No chests detected. Please connect at least one chest.", 0)
end
print("Available chests:")
for i, chest in ipairs(chests) do
print(i .. ". " .. chest)
end
print("")
-- 选择输入箱
print("Please select the input chest (where items will be placed for sorting):")
local input_index = tonumber(io.read())
while not input_index or input_index < 1 or input_index > #chests do
print(colors.red .. "Invalid selection. Please enter a number between 1 and " .. #chests .. colors.white)
input_index = tonumber(io.read())
end
config.input_chest = chests[input_index]
print("Input chest set to: " .. config.input_chest)
print("")
-- 选择输出箱并分配类别
print("Now, let's set up output chests for different item categories.")
print("Enter 'done' when finished.")
print("")
config.output_chests = {}
local remaining_chests = {}
for i, chest in ipairs(chests) do
if i ~= input_index then
table.insert(remaining_chests, chest)
end
end
while #remaining_chests > 0 do
print("Available output chests:")
for i, chest in ipairs(remaining_chests) do
print(i .. ". " .. chest)
end
print("Enter 'done' to finish setup.")
print("")
print("Select a chest to assign a category (or 'done'):")
local selection = io.read()
if selection == "done" then
break
end
local chest_index = tonumber(selection)
if chest_index and chest_index >= 1 and chest_index <= #remaining_chests then
local selected_chest = remaining_chests[chest_index]
print("Enter a category name for this chest (e.g., 'coal', 'tools', 'food'):")
local category = io.read()
while category == "" do
print(colors.red .. "Category name cannot be empty. Please enter a valid name." .. colors.white)
category = io.read()
end
config.output_chests[category] = selected_chest
print("Assigned chest '" .. selected_chest .. "' to category '" .. category .. "'")
print("")
-- 从剩余箱子中移除已分配的箱子
table.remove(remaining_chests, chest_index)
else
print(colors.red .. "Invalid selection. Please try again." .. colors.white)
end
end
-- 保存配置
saveConfig()
print(colors.green .. "Setup complete! Configuration saved." .. colors.white)
print("")
end
-- 自动分类函数
local function autoSort()
print(colors.green .. "Starting auto-sorting..." .. colors.white)
print("Press Ctrl+T to stop.")
-- 捕获Ctrl+T中断
local success, error = pcall(function()
while true do
-- 检查输入箱中的物品
local input_inventory = peripheral.wrap(config.input_chest)
if not input_inventory then
print(colors.red .. "Failed to connect to input chest." .. colors.white)
break
end
-- 遍历输入箱的所有槽位
local items_found = false
for slot = 1, 16 do
local item = input_inventory.getItemDetail(slot)
if item then
items_found = true
print("Found item: " .. item.name)
-- 尝试找到匹配的类别
local category_found = false
for category, chest_name in pairs(config.output_chests) do
if string.find(item.name, category) or string.find(item.displayName, category) then
local output_inventory = peripheral.wrap(chest_name)
if output_inventory then
print("Moving to '" .. category .. "' chest...")
input_inventory.pushItems(chest_name, slot)
category_found = true
break
else
print(colors.red .. "Failed to connect to '" .. category .. "' chest." .. colors.white)
end
end
end
if not category_found then
print(colors.yellow .. "No matching category found for '" .. item.name .. "'." .. colors.white)
end
-- 短暂延迟避免过快处理
os.sleep(0.1)
end
end
-- 如果没有找到物品,稍作等待
if not items_found then
os.sleep(1)
end
end
end)
if not success then
print(colors.red .. "Program interrupted: " .. tostring(error) .. "" .. colors.white)
end
print(colors.yellow .. "Auto-sorting stopped." .. colors.white)
end
-- 显示教程
local function showTutorial()
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.blue)
term.clearLine()
term.write("=== Chest Sorter Tutorial ===")
term.setTextColor(old_fg)
term.setBackgroundColor(old_bg)
term.setCursorPos(1, 2)
print("")
print("How to use the Chest Sorter:")
print("")
print("1. Connect your computer to a comparator.")
print("2. Connect the comparator to all chests you want to use.")
print("3. Run the program: 'chest_sorter'")
print("4. Follow the setup wizard to:")
print(" a. Select an input chest (where you'll place items to sort)")
print(" b. Assign output chests to categories (e.g., 'coal', 'tools')")
print("5. After setup, the program will automatically sort items:")
print(" - Items in the input chest will be moved to the appropriate output chest")
print(" - Based on the category names you assigned")
print("")
print("Tips:")
print("- Use specific category names for better sorting (e.g., 'iron_ore' instead of 'ore')")
print("- You can edit the configuration later by deleting '" .. CONFIG_FILE .. "'")
print(" and running the program again to restart the setup wizard.")
print("- Press Ctrl+T to stop the program.")
print("")
print("Press any key to continue...")
io.read()
end
-- 主程序
local function main()
-- 检查是否需要显示教程
if #({...}) > 0 and ({...})[1] == "tutorial" then
showTutorial()
return
end
-- 加载配置或运行设置向导
if not loadConfig() then
setupWizard()
end
-- 显示当前配置
print(colors.cyan .. "Current Configuration:" .. colors.white)
print("Input chest: " .. config.input_chest)
print("Output chests:")
for category, chest in pairs(config.output_chests) do
print(" - '" .. category .. "': " .. chest)
end
print("")
-- 开始自动分类
autoSort()
end
-- 运行主程序
main()

View File

@@ -1,5 +1,5 @@
-- LeonOS installer -- LeonOS installer
local INSTALLER_VERSION = "0.3.8 Beta 17" local INSTALLER_VERSION = "0.3.8 Beta 18"
local DEFAULT_ROM_DIR = "/leonos" local DEFAULT_ROM_DIR = "/leonos"
print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...") print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")