Aaron Suen ca694993c9 Un-delay inverted ABMs
Instead of queueing inverted ABMs and then running
them out-of-band, run them inside the normal ABM
schedule time.  This should:
- Prevent ABM mux lookup problems caused by nodes
  changing after a delayed inverted ABM schedule and
  the action actually running
- Allow the ABM scheduler to better account for the
  time spent running inverted ABM actions, to ensure
  that they properly count against the default 0.2s
  ABM runtime budget and can't spike lag up higher.
2021-12-05 14:11:01 -05:00

40 lines
927 B
Lua

-- LUALOCALS < ---------------------------------------------------------
local ipairs, minetest, nodecore
= ipairs, minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local hash = minetest.hash_node_position
local oldreg = minetest.register_abm
function minetest.register_abm(def, ...)
if not def.neighbors_invert then return oldreg(def, ...) end
local nnames = def.nodenames
def.nodenames = def.neighbors
def.neighbors = nnames
local oldact = def.action
local dirty
local blocked = {}
function def.action(pos)
if not dirty then
dirty = true
minetest.after(0, function()
blocked = {}
dirty = nil
end)
end
for _, npos in ipairs(nodecore.find_nodes_around(pos, nnames, 1)) do
local key = hash(npos)
if not blocked[key] then
blocked[key] = true
oldact(npos, minetest.get_node(npos))
end
end
end
return oldreg(def, ...)
end