]> git.lizzy.rs Git - Crafter.git/commitdiff
Fix minetest engine memory leak causing clientmods to not initalize (safety net)
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 24 May 2020 06:32:41 +0000 (02:32 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 24 May 2020 06:32:41 +0000 (02:32 -0400)
README.md
mods/weather/init.lua

index 76401d9733cc334c26f151af76d24cd4913ea91f..4aa20f6a2f93df03120a93e5bfcd686441150272 100644 (file)
--- a/README.md
+++ b/README.md
@@ -140,6 +140,9 @@ enable_mod_channels = true
 - Make player model's head pitch follow the player's look pitch
 - Make music play during certain parts of the day/night
 - Tweaked collision detection for mobs and make slime collision radius fit their size
+- FINALLY fix client not initializing properly in the world - fixes clientmods not loading on first startup and randomly failing to load :D :D :D
+- Add in safety net to client not initializing clientmods from game memory leak
+- 
 ---
 
 
index 18a5812a165e301826948a92a125434751d477c4..c9d36553d4e3eda630cb3e7be4d260b661a54094 100644 (file)
@@ -3,11 +3,15 @@ local weather_intake = minetest.mod_channel_join("weather_intake")
 local weather_nodes_channel = minetest.mod_channel_join("weather_nodes")
 
 
+weather_channel:send_all("")
+weather_intake:send_all("")
+weather_nodes_channel:send_all("")
+
 local weather_max = 2
 
 local mod_storage = minetest.get_mod_storage()
 
-weather_type = 0
+weather_type = mod_storage:get_int("weather_type")
 
 local path = minetest.get_modpath(minetest.get_current_modname())
 dofile(path.."/commands.lua")
@@ -86,6 +90,15 @@ minetest.register_on_modchannel_message(function(channel_name, sender, message)
 end)
 
 
+minetest.register_on_joinplayer(function(player)
+       minetest.after(3,function()
+               local all_nodes_serialized = minetest.serialize(all_nodes)
+               weather_nodes_channel:send_all(all_nodes_serialized)
+               function_send_weather_type()
+               update_player_sky()
+       end)
+end)
+
 --spawn snow nodes
 local pos
 local area = vector.new(80,40,80)
@@ -230,8 +243,9 @@ end)
 --this sets random weather
 local initial_run = true
 local function randomize_weather()
-       if initial_run == false then
+       if not initial_run then
                weather_type = math.random(0,weather_max)
+               mod_storage:set_int("weather_type", weather_type)
        else
                initial_run = false
        end
@@ -244,16 +258,14 @@ local function randomize_weather()
        end)
 end
 
-minetest.register_on_mods_loaded(function()    
+minetest.register_on_mods_loaded(function()
        if mod_storage:get_int("weather_initialized") == 0 then
                mod_storage:set_int("weather_initialized",1)
                weather_type = math.random(0,weather_max)
-       else
-               weather_type = mod_storage:get_int("weather_type")
+               mod_storage:set_int("weather_type", weather_type)
        end
-       minetest.after(0,function()
-               randomize_weather()
-       end)
+
+       randomize_weather()
 end)
 
 minetest.register_on_shutdown(function()