diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-10-12 15:41:27 +0200 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-10-12 15:41:27 +0200 |
commit | 964b0a7ab6e7e5756adef4f126f229995bd9210c (patch) | |
tree | a3970ea0c5bcf2e0a5bdd09c90cf9b9a742d6f6b /advtrains | |
parent | dcf5b8670e19ad7603a0e305ec8515653555084f (diff) | |
download | advtrains-964b0a7ab6e7e5756adef4f126f229995bd9210c.tar.gz advtrains-964b0a7ab6e7e5756adef4f126f229995bd9210c.tar.bz2 advtrains-964b0a7ab6e7e5756adef4f126f229995bd9210c.zip |
Remove couple entities when out of range from players
Work around the entity flood bug caused by improper engine handling of
static_save=false
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/couple.lua | 4 | ||||
-rw-r--r-- | advtrains/wagons.lua | 22 |
2 files changed, 19 insertions, 7 deletions
diff --git a/advtrains/couple.lua b/advtrains/couple.lua index 1b213c2..5116bac 100644 --- a/advtrains/couple.lua +++ b/advtrains/couple.lua @@ -106,6 +106,10 @@ minetest.register_entity("advtrains:couple", { end, on_step=function(self, dtime) return advtrains.pcall(function() + if advtrains.outside_range(self.object:getpos()) then + self.object:remove() + return + end advtrains.atprint_context_tid=self.train_id_1 if not self.train_id_1 or not self.train_id_2 then atprint("Couple: train ids not set!") self.object:remove() return end diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 6b59293..5564fa5 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -15,6 +15,20 @@ advtrains.wagon_prototypes = {} advtrains.wagon_objects = {} local unload_wgn_range = advtrains.wagon_load_range + 32 +function advtrains.outside_range(pos) -- returns true if the object is outside of unload_wgn_range of any player + -- this is part of a workaround until mintest core devs decide to fix a bug with static_save=false. + local outofrange = true + if not pos then + return true + end + for _,p in pairs(minetest.get_connected_players()) do + if vector.distance(p:get_pos(),pos)<=unload_wgn_range then + outofrange = false + break + end + end + return outofrange +end local setting_show_ids = minetest.settings:get_bool("advtrains_show_ids") @@ -511,13 +525,7 @@ function wagon:on_step(dtime) end end 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 + if advtrains.outside_range(pos) then --atdebug("wagon",self.id,"unloading (too far away)") self.object:remove() end |