1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2024-12-28 07:30:17 +01:00

use after instead of globalstep

M  src/falling_snow.lua
M  src/snowball.lua
This commit is contained in:
HybridDog 2016-08-01 11:03:39 +02:00
parent a5ae53fbeb
commit 90e08fe0bc
2 changed files with 20 additions and 23 deletions

View File

@ -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)

View File

@ -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