Enhance event handling in craftItem function and improve broadcastState function to include stateVersion
This commit is contained in:
@@ -1176,7 +1176,7 @@ local function craftItem(recipeIdx)
|
||||
|
||||
while os.clock() < deadline do
|
||||
local timerId = os.startTimer(math.max(0.1, deadline - os.clock()))
|
||||
local event, p1, p2, p3, p4 = os.pullEvent()
|
||||
local event, p1, p2, p3, p4, p5 = os.pullEvent()
|
||||
|
||||
if event == "modem_message" then
|
||||
local channel = p2
|
||||
@@ -1184,6 +1184,9 @@ local function craftItem(recipeIdx)
|
||||
if channel == CRAFT_REPLY_CHANNEL and type(message) == "table" and message.type == "craft_result" then
|
||||
result = message
|
||||
break
|
||||
elseif channel == ORDER_CHANNEL then
|
||||
-- Re-queue so Task 12 picks it up after craftItem returns
|
||||
os.queueEvent(event, p1, p2, p3, p4, p5)
|
||||
end
|
||||
elseif event == "timer" and p1 == timerId then
|
||||
-- Timeout tick, loop will check deadline
|
||||
@@ -2481,13 +2484,14 @@ end
|
||||
-- Network broadcast (sends state to client displays)
|
||||
-------------------------------------------------
|
||||
|
||||
local function broadcastState(force)
|
||||
local function broadcastState()
|
||||
if not networkModem then return end
|
||||
ensureItemList()
|
||||
|
||||
-- Build dynamic state (always included)
|
||||
local state = {
|
||||
type = "state",
|
||||
stateVersion = stateVersion,
|
||||
cache = {
|
||||
itemList = cache.itemList,
|
||||
grandTotal = cache.grandTotal,
|
||||
@@ -2721,10 +2725,12 @@ local function main()
|
||||
-- Task 3: Auto-smelt
|
||||
function()
|
||||
while true do
|
||||
activity.smelting = true
|
||||
needsRedraw = true
|
||||
smelterNeedsRedraw = true
|
||||
local ok, didWork = pcall(autoSmelt)
|
||||
if ok and didWork then
|
||||
activity.smelting = true
|
||||
needsRedraw = true
|
||||
smelterNeedsRedraw = true
|
||||
end
|
||||
activity.smelting = false
|
||||
-- Update furnace status quickly after smelt cycle
|
||||
pcall(refreshFurnaceStatus)
|
||||
|
||||
Reference in New Issue
Block a user