From 90e08fe0bca00065f92e63f7f166e7ba35baa993 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Mon, 1 Aug 2016 11:03:39 +0200 Subject: [PATCH] use after instead of globalstep M src/falling_snow.lua M src/snowball.lua --- src/falling_snow.lua | 12 ++++-------- src/snowball.lua | 31 ++++++++++++++++--------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/falling_snow.lua b/src/falling_snow.lua index 5f3de51..0c0cc0f 100644 --- a/src/falling_snow.lua +++ b/src/falling_snow.lua @@ -61,13 +61,7 @@ end weather_legacy = read_weather_legacy() or "" -local timer = 0 -minetest.register_globalstep(function(dtime) - timer = timer+dtime - if timer < 2 then - return - end - timer = 0 +local function leg_step() if weather_legacy == "snow" then if math.random(1000) == 1 then weather_legacy = "none" @@ -77,7 +71,9 @@ minetest.register_globalstep(function(dtime) weather_legacy = "snow" save_weather_legacy() end -end) + minetest.after(2, leg_step) +end +minetest.after(4, leg_step) local function infolog(msg) minetest.log("info", "[snow] falling_snow: "..msg) diff --git a/src/snowball.lua b/src/snowball.lua index 0509d38..b8008de 100644 --- a/src/snowball.lua +++ b/src/snowball.lua @@ -31,8 +31,7 @@ local function get_gravity() return grav*snowball_gravity end -local someone_throwing -local timer = 0 +local someone_throwing, just_acitvated --Shoot snowball local function snow_shoot_snowball(item, player) @@ -49,7 +48,7 @@ local function snow_shoot_snowball(item, player) if creative_mode then if not someone_throwing then someone_throwing = true - timer = -0.5 + just_acitvated = true end return end @@ -58,13 +57,7 @@ local function snow_shoot_snowball(item, player) end if creative_mode then - local function update_step(dtime) - timer = timer+dtime - if timer < 0.006 then - return - end - timer = 0 - + local function update_step() local active for _,player in pairs(minetest.get_connected_players()) do if player:get_player_control().LMB then @@ -84,13 +77,21 @@ if creative_mode then end end - -- do automatic throwing using a globalstep - minetest.register_globalstep(function(dtime) + -- do automatic throwing using minetest.after + local function do_step() + local timer -- only if one holds left click - if someone_throwing then - update_step(dtime) + if someone_throwing + and not just_acitvated then + update_step() + timer = 0.006 + else + timer = 0.5 + just_acitvated = false end - end) + minetest.after(timer, do_step) + end + minetest.after(3, do_step) end --The snowball Entity