From e2a60909c6d438f1289e11932b7b216a5d025e09 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Fri, 5 Sep 2025 21:21:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(turtle=5Ffarmer):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BB=8E=E8=83=8C=E5=8C=85=E5=AF=BB=E6=89=BE?= =?UTF-8?q?=E7=87=83=E6=96=99=E5=8A=9F=E8=83=BD=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E7=A8=8B=E5=BA=8F=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为乌龟农夫程序添加自动从背包中寻找燃料的功能,当燃料不足时会自动搜索可用燃料物品 同时将安装程序版本更新至0.3.8 Beta 17 --- .../lua/rom/programs/turtle_farmer.lua | 38 ++++++++++++++++++- installer.lua | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) 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..")...")