From 00031064a5ef66306fe49eb7ee5fa6dfe1454238 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Sun, 26 Jul 2020 18:53:16 +0200 Subject: Do not unload wagons when a player that is logged in sits in it --- advtrains/wagons.lua | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index ba746ef..95582d0 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -486,15 +486,26 @@ function wagon:on_step(dtime) -- unload entity if out of range (because relevant pr won't be merged in engine) -- This is a WORKAROUND! - local outofrange = true - for _,p in pairs(minetest.get_connected_players()) do - if vector.distance(p:get_pos(),pos)<=unload_wgn_range then - outofrange = false + local players_in = false + for sno,pname in pairs(data.seatp) do + if minetest.get_player_by_name(pname) then + -- Fix: If the RTT is too high, a wagon might be recognized out of range even if a player sits in it + -- (client updates position not fast enough) + players_in = true + break end end - if outofrange then - --atdebug("wagon",self.id,"unloading (too far away)") - self.object:remove() + if not players_in then + local outofrange = true + for _,p in pairs(minetest.get_connected_players()) do + if vector.distance(p:get_pos(),pos)<=unload_wgn_range then + outofrange = false + end + end + if outofrange then + --atdebug("wagon",self.id,"unloading (too far away)") + self.object:remove() + end end end -- cgit v1.2.3