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