From 06885e7bf030055ab7f09ec1b3dbbc783f7a694a Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Fri, 17 Apr 2020 04:50:04 -0400 Subject: [PATCH] Fix 2 generals problem with weather handling --- init.lua | 31 ++++++++++++++++++++++++------- weather_handling.lua | 6 ++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index 8dd2903..8823eea 100644 --- a/init.lua +++ b/init.lua @@ -1,14 +1,31 @@ ---first we join the necessary channels so the mod can "listen" to what the server says +--first we join the necessary channels so the mod can "listen" to what the server says and "talk" to it +weather_intake = minetest.mod_channel_join("weather_intake") weather = minetest.mod_channel_join("weather_nodes") weather_type = minetest.mod_channel_join("weather_type") running_send = minetest.mod_channel_join("running_send") player_movement_state = minetest.mod_channel_join("player.player_movement_state") ---we load everything seperately because it's easier to work on individual files than have everything jammed into one file ---not into seperate mods because that is unnecessary and cumbersome -local path = minetest.get_modpath("crafter_client") -dofile(path.."/player_input.lua") -dofile(path.."/weather_handling.lua") -dofile(path.."/environment_effects.lua") +local function initialize_all() + --first we tell the server we're ready + weather_intake:send_all("READY") + weather_intake:leave() + weather_intake = nil --leave the channel + + --next we load everything seperately because it's easier to work on individual files than have everything jammed into one file + --not into seperate mods because that is unnecessary and cumbersome + local path = minetest.get_modpath("crafter_client") + dofile(path.."/player_input.lua") + dofile(path.."/weather_handling.lua") + dofile(path.."/environment_effects.lua") +end +--we must delay initialization until the player's camera exists in the world +--since there does not seem to be any client_loaded function +local initialize = false +minetest.register_globalstep(function(dtime) + if not initialize and not vector.equals(minetest.camera:get_pos(),vector.new(0,0,0)) then + initialize = true + initialize_all() + end +end) diff --git a/weather_handling.lua b/weather_handling.lua index 1aca8e4..5f39c62 100644 --- a/weather_handling.lua +++ b/weather_handling.lua @@ -118,6 +118,7 @@ local spawn_rain = function(player) end end +--client runs through spawning weather particles minetest.register_globalstep(function(dtime) if do_effects then if snow or rain then @@ -138,10 +139,14 @@ end) minetest.register_on_modchannel_message(function(channel_name, sender, message) + --receive the initial packet which tells the client which nodes + --to spawn weather columns on if channel_name == "weather_nodes" then all_nodes = minetest.deserialize(message) do_effects = true + weather:leave() --leave the channel end + --receive the weather type if channel_name == "weather_type" then if message == "1" then rain = false @@ -154,6 +159,7 @@ minetest.register_on_modchannel_message(function(channel_name, sender, message) snow = false end end + --rain sound effect if not rain_sound_handle and rain == true then rain_sound_handle = minetest.sound_play("rain", {loop=true,gain=0}) minetest.sound_fade(rain_sound_handle, 0.5, 0.5) -- 2.44.0