From e92348b4db8d809ffeebb1c37799351ad303aa6b Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 2 Aug 2026 16:04:41 +0800 Subject: [PATCH] feat: add real-time ETA interpolation for block reader --- station_broadcast.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index 101baa8..016fa9e 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2247,6 +2247,14 @@ function Main.loop() if Peripherals.blockReader then local ok, data = pcall(Peripherals.blockReader.getBlockData) if ok and data and data.TrainStops then + -- Real-time interpolation: calculate exact current tick even if NBT is cached + if not State.lastRefreshed or State.lastRefreshed ~= data.LastRefreshed then + State.lastRefreshed = data.LastRefreshed + State.lastRefreshedEpoch = now + end + local elapsedTicks = math.floor((now - (State.lastRefreshedEpoch or now)) / 50) + local currentTick = (data.LastRefreshed or 0) + elapsedTicks + for k, v in pairs(State.announcedApproaching) do if now - v > 300000 then State.announcedApproaching[k] = nil @@ -2260,10 +2268,10 @@ function Main.loop() local destination = st.Destination or "Unknown" local platform = stop.StationInfo and stop.StationInfo.Platform or State.stationPlatform or "1" - -- Calculate ETA in seconds + -- Calculate ETA in seconds using interpolated currentTick local scheduledArrival = st.ScheduledArrival or 0 local realArrival = st.RealTimeArrival or 0 - local etaTicks = realArrival - (data.LastRefreshed or 0) + local etaTicks = realArrival - currentTick local etaSeconds = math.floor(etaTicks / 20) -- Calculate Delay in minutes