diff --git a/init.lua b/init.lua index 3df6db1..25c1109 100644 --- a/init.lua +++ b/init.lua @@ -1,28 +1,34 @@ -local func = function() - local player = minetest.get_player_by_name("singleplayer") - local pos = player:get_pos() - local grav = 1 - if pos.y > 10 then grav = 10/pos.y end - player:set_physics_override({gravity=grav}) +--[[ +Lowers gravity the higher (and lower) you get above (or below) sea +level, max gravity at sea level. + +]]-- + + +local update = function() + for _, players in ipairs(minetest.get_connected_players()) do + local player = minetest.get_player_by_name("singleplayer") + local pos = player:get_pos() + local grav = 1 + if pos.y > 300 then grav = 300/pos.y end + if pos.y < -300 then grav = -300/pos.y end + player:set_physics_override({gravity=grav}) + end end -minetest.register_abm({ - nodenames = { - "air", - "default:stone", - "default:dirt", - "default:sand", - "default:water_source" - }, - neighbors = { - "air", - "default:stone", - "default:dirt", - "default:sand", - "default:water_source" - }, - interval = 1, - chance = 1, - action = func -}) +local gravity_timer = 0 +local action_timer = 0 + +local function gravity_globaltimer(dtime) + gravity_timer = gravity_timer + dtime + action_timer = action_timer + dtime + + if action_timer > 4 then + update() + action_timer = 0 + end +end + +minetest.register_globalstep(gravity_globaltimer) +