90fbdabdf2
The new method of intercepting item addition into player inventories hooks into the base metatables for the userdata types only once per type, instead of trying to substitute every inventory object with a table (which crashed some things) and does a lookup to find the player per inv. This should hopefully be more reliable, and avoid some of the leaks to rearrangement we had before. If we can finally stop hitting the player inv rearrange safety net then it can be removed.
37 lines
834 B
Lua
37 lines
834 B
Lua
-- LUALOCALS < ---------------------------------------------------------
|
|
local getmetatable, minetest, nodecore, pairs
|
|
= getmetatable, minetest, nodecore, pairs
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
local publicfields = {
|
|
formspec = true,
|
|
infotext = true
|
|
}
|
|
|
|
local function hook(meta)
|
|
for k, v in pairs(meta) do
|
|
if k:sub(1, 4) == "set_" then
|
|
meta[k] = function(data, name, ...)
|
|
if not publicfields[name] then
|
|
data:mark_as_private(name)
|
|
end
|
|
return v(data, name, ...)
|
|
end
|
|
nodecore.log("action", "auto-privatized meta " .. k)
|
|
end
|
|
end
|
|
end
|
|
|
|
local rawmeta = minetest.get_meta
|
|
function minetest.get_meta(...)
|
|
local raw = rawmeta(...)
|
|
if raw then
|
|
local meta = getmetatable(raw)
|
|
if meta then
|
|
hook(meta)
|
|
minetest.get_meta = rawmeta
|
|
end
|
|
end
|
|
return raw
|
|
end
|