diff --git a/data/computercraft/lua/rom/programs/turtle_farmer.lua b/data/computercraft/lua/rom/programs/turtle_farmer.lua index e6f9a61..4a10c71 100644 --- a/data/computercraft/lua/rom/programs/turtle_farmer.lua +++ b/data/computercraft/lua/rom/programs/turtle_farmer.lua @@ -65,6 +65,41 @@ local function isInventoryFull() end +-- 从背包中寻找燃料并填充 +local function refuelFromInventory() + print(colors.yellow .. "Fuel low! Searching for fuel in inventory..." .. colors.white) + local initial_slot = turtle.getSelectedSlot() + local fuel_found = false + + -- 遍历所有16个背包槽位 + for slot = 1, 16 do + if turtle.getItemCount(slot) > 0 then + turtle.select(slot) + local itemDetail = turtle.getItemDetail() + + -- 检查物品是否可以作为燃料 + if itemDetail and itemDetail.fuel ~= nil and itemDetail.fuel > 0 then + print(colors.green .. "Found fuel in slot " .. slot .. ": " .. itemDetail.name .. " (" .. itemDetail.fuel .. " fuel)" .. colors.white) + + -- 填充燃料 + local success = turtle.refuel(1) + if success then + print(colors.green .. "Refueled successfully! Current fuel: " .. turtle.getFuelLevel() .. colors.white) + fuel_found = true + break -- 找到燃料后退出循环 + else + print(colors.red .. "Failed to refuel with slot " .. slot .. colors.white) + end + end + end + end + + -- 恢复原来选择的槽位 + turtle.select(initial_slot) + + return fuel_found +end + -- 检查燃料是否充足 local function checkFuel() local currentFuel = turtle.getFuelLevel() @@ -75,7 +110,8 @@ local function checkFuel() return true end - return false + -- 尝试从背包中寻找燃料 + return refuelFromInventory() end -- 检测前方是否有成熟的麦子 diff --git a/installer.lua b/installer.lua index 94279c9..bb59558 100644 --- a/installer.lua +++ b/installer.lua @@ -1,5 +1,5 @@ -- LeonOS installer -local INSTALLER_VERSION = "0.3.8 Beta 16" +local INSTALLER_VERSION = "0.3.8 Beta 17" local DEFAULT_ROM_DIR = "/leonos" print("Start loading LeonOS installer ("..INSTALLER_VERSION..")...")