mirror of
https://github.com/CCLeonOS/LeonOS.git
synced 2026-03-03 15:17:01 +00:00
feat(乌龟程序): 添加燃料命令和更新安装程序版本
添加乌龟程序的燃料相关命令,包括帮助文档和实现代码 更新安装程序版本号至0.3.8 Beta 7
This commit is contained in:
@@ -29,6 +29,9 @@ turtle <command> [arguments]
|
|||||||
- **inventory**, **inv**: Show inventory
|
- **inventory**, **inv**: Show inventory
|
||||||
- **select** <slot>: Select slot (1-16)
|
- **select** <slot>: Select slot (1-16)
|
||||||
|
|
||||||
|
- **Fuel Commands:**
|
||||||
|
- **refuel** [amount]: Refuel using items from inventory (optional amount)
|
||||||
|
|
||||||
- **Utility Commands:**
|
- **Utility Commands:**
|
||||||
- **help**, **h**: Show this help message
|
- **help**, **h**: Show this help message
|
||||||
- **version**, **v**: Show program version
|
- **version**, **v**: Show program version
|
||||||
@@ -75,6 +78,16 @@ turtle select 5
|
|||||||
turtle digall
|
turtle digall
|
||||||
>>color white
|
>>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 ==
|
== Notes ==
|
||||||
|
|
||||||
- This program must be run on a turtle
|
- This program must be run on a turtle
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ local function show_help()
|
|||||||
print(" inventory, inv - Show inventory")
|
print(" inventory, inv - Show inventory")
|
||||||
print(" select <slot> - Select slot (1-16)")
|
print(" select <slot> - Select slot (1-16)")
|
||||||
print("")
|
print("")
|
||||||
|
print("Fuel Commands:")
|
||||||
|
print(" refuel [amount] - Refuel using items from inventory (optional amount)")
|
||||||
|
print("")
|
||||||
print("Utility Commands:")
|
print("Utility Commands:")
|
||||||
print(" help, h - Show this help message")
|
print(" help, h - Show this help message")
|
||||||
print(" version, v - Show program version")
|
print(" version, v - Show program version")
|
||||||
@@ -184,6 +187,51 @@ local function select_slot(slot)
|
|||||||
end
|
end
|
||||||
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 = {...}
|
local args = {...}
|
||||||
if #args == 0 then
|
if #args == 0 then
|
||||||
@@ -232,6 +280,12 @@ else
|
|||||||
else
|
else
|
||||||
error("Missing slot number", 0)
|
error("Missing slot number", 0)
|
||||||
end
|
end
|
||||||
|
elseif command == "refuel" then
|
||||||
|
if #args > 1 then
|
||||||
|
refuel(tonumber(args[2]))
|
||||||
|
else
|
||||||
|
refuel()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
error("Unknown command: " .. command, 0)
|
error("Unknown command: " .. command, 0)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-- LeonOS installer
|
-- LeonOS installer
|
||||||
local INSTALLER_VERSION = "0.3.8 Beta 6"
|
local INSTALLER_VERSION = "0.3.8 Beta 7"
|
||||||
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