1
0
Fork 0

`walkover` fixes

newmobs-master
AFCMS 2022-01-20 22:55:36 +01:00
parent 9cc088c940
commit e138d998ef
1 changed files with 18 additions and 20 deletions

View File

@ -2,47 +2,45 @@
local get_connected_players = minetest.get_connected_players local get_connected_players = minetest.get_connected_players
local get_node = minetest.get_node local get_node = minetest.get_node
local vector_add = vector.add local vector = vector
local ceil = math.ceil local ceil = math.ceil
local pairs = pairs local pairs = pairs
walkover = {} walkover = {}
walkover.registered_globals = {}
function walkover.register_global(func)
table.insert(walkover.registered_globals, func)
end
local on_walk = {} local on_walk = {}
local registered_globals = {} local registered_globals = {}
walkover.registered_globals = registered_globals
function walkover.register_global(func)
table.insert(registered_globals, func)
end
minetest.register_on_mods_loaded(function() minetest.register_on_mods_loaded(function()
for name,def in pairs(minetest.registered_nodes) do for name,def in pairs(minetest.registered_nodes) do
if def.on_walk_over then if def.on_walk_over then
on_walk[name] = def.on_walk_over on_walk[name] = def.on_walk_over
end end
end end
for _,func in ipairs(walkover.registered_globals) do --cache registered globals
table.insert(registered_globals, func)
end
end) end)
local timer = 0 local timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
timer = timer + dtime; timer = timer + dtime
if timer >= 0.3 then if timer >= 0.3 then
for _,player in pairs(get_connected_players()) do for _, player in pairs(get_connected_players()) do
local pp = player:get_pos() local ppos = player:get_pos()
pp.y = ceil(pp.y) ppos.y = ceil(ppos.y)
local loc = vector_add(pp, {x=0,y=-1,z=0}) local npos = vector.add(ppos, vector.new(0, -1, 0))
if loc then if npos then
local nodeiamon = get_node(loc) local node = get_node(npos)
if nodeiamon then if node then
if on_walk[nodeiamon.name] then if on_walk[node.name] then
on_walk[nodeiamon.name](loc, nodeiamon, player) on_walk[node.name](npos, node, player)
end end
for i = 1, #registered_globals do for i = 1, #registered_globals do
registered_globals[i](loc, nodeiamon, player) registered_globals[i](npos, node, player)
end end
end end
end end