From 012a7f207895b012011864e0f9dce2a7907b42a8 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Wed, 3 Sep 2025 22:08:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=B9=8C=E9=BE=9F=E7=A8=8B=E5=BA=8F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=87=83=E6=96=99=E5=91=BD=E4=BB=A4=E5=92=8C?= =?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 添加乌龟程序的燃料相关命令,包括帮助文档和实现代码 更新安装程序版本号至0.3.8 Beta 7 --- data/computercraft/lua/rom/help/turtle.hlp | 13 +++++ .../computercraft/lua/rom/programs/turtle.lua | 54 +++++++++++++++++++ installer.lua | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/data/computercraft/lua/rom/help/turtle.hlp b/data/computercraft/lua/rom/help/turtle.hlp index fb347ab..2d15d04 100644 --- a/data/computercraft/lua/rom/help/turtle.hlp +++ b/data/computercraft/lua/rom/help/turtle.hlp @@ -29,6 +29,9 @@ turtle [arguments] - **inventory**, **inv**: Show inventory - **select** : Select slot (1-16) +- **Fuel Commands:** + - **refuel** [amount]: Refuel using items from inventory (optional amount) + - **Utility Commands:** - **help**, **h**: Show this help message - **version**, **v**: Show program version @@ -75,6 +78,16 @@ turtle select 5 turtle digall >>color white +9. Refuel with maximum amount: +>>color yellow +turtle refuel +>>color white + +10. Refuel with specific amount: +>>color yellow +turtle refuel 10 +>>color white + == Notes == - This program must be run on a turtle diff --git a/data/computercraft/lua/rom/programs/turtle.lua b/data/computercraft/lua/rom/programs/turtle.lua index 246c1c7..84032d7 100644 --- a/data/computercraft/lua/rom/programs/turtle.lua +++ b/data/computercraft/lua/rom/programs/turtle.lua @@ -51,6 +51,9 @@ local function show_help() print(" inventory, inv - Show inventory") print(" select - Select slot (1-16)") print("") + print("Fuel Commands:") + print(" refuel [amount] - Refuel using items from inventory (optional amount)") + print("") print("Utility Commands:") print(" help, h - Show this help message") print(" version, v - Show program version") @@ -184,6 +187,51 @@ local function select_slot(slot) end end +-- 燃料命令 +local function refuel(amount) + expect(1, amount, "number", "nil") + amount = amount or 64 -- 默认使用最大数量 + + print("Current fuel level: " .. turtle.getFuelLevel() .. "/" .. turtle.getFuelLimit()) + print("Searching for fuel...") + + local initial_slot = turtle.getSelectedSlot() + local found_fuel = false + + for slot = 1, 16 do + if turtle.getItemCount(slot) > 0 then + turtle.select(slot) + local itemDetail = turtle.getItemDetail() + if itemDetail and itemDetail.fuel then + found_fuel = true + print("Found fuel in slot " .. slot .. ": " .. itemDetail.name) + local fuelAmount = math.min(amount, turtle.getItemCount(slot)) + print("Refueling with " .. fuelAmount .. " items...") + if turtle.refuel(fuelAmount) then + print(colors.green .. "Success! Fuel level: " .. turtle.getFuelLevel() .. colors.white) + if turtle.getFuelLevel() >= turtle.getFuelLimit() then + print("Fuel tank is full!") + break + end + amount = amount - fuelAmount + if amount <= 0 then + break + end + else + print(colors.red .. "Failed to refuel with this item." .. colors.white) + end + end + end + end + + -- 恢复原来选中的槽位 + turtle.select(initial_slot) + + if not found_fuel then + print(colors.red .. "No fuel found in inventory." .. colors.white) + end +end + -- 主程序 local args = {...} if #args == 0 then @@ -232,6 +280,12 @@ else else error("Missing slot number", 0) end + elseif command == "refuel" then + if #args > 1 then + refuel(tonumber(args[2])) + else + refuel() + end else error("Unknown command: " .. command, 0) end diff --git a/installer.lua b/installer.lua index d600995..7a000c1 100644 --- a/installer.lua +++ b/installer.lua @@ -1,5 +1,5 @@ -- LeonOS installer -local INSTALLER_VERSION = "0.3.8 Beta 6" +local INSTALLER_VERSION = "0.3.8 Beta 7" local DEFAULT_ROM_DIR = "/leonos" print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")