f893f613c3
- Make node match operate on only one of node or stack, depending on whether node defers to stack via is_stack_only. This should hopefully prevent future pummel recipe issues. - Add new core stack API. Needs to be deployed in a lot of places. - Start work on system for allowing flammable containers; they eject their potentially non-flammable contents.
68 lines
1.9 KiB
Lua
68 lines
1.9 KiB
Lua
-- LUALOCALS < ---------------------------------------------------------
|
|
local minetest, nodecore, pairs, type
|
|
= minetest, nodecore, pairs, type
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
local match_skip = {
|
|
name = true,
|
|
param2 = true,
|
|
param = true,
|
|
groups = true,
|
|
stack = true,
|
|
count = true,
|
|
wear = true
|
|
}
|
|
|
|
function nodecore.match(thing, crit)
|
|
if not thing then return end
|
|
|
|
if type(crit) == "string" then crit = {name = crit} end
|
|
|
|
thing.count = thing.count or 1
|
|
|
|
if not thing.name then
|
|
thing = nodecore.underride(thing, minetest.get_node(thing))
|
|
end
|
|
local def = minetest.registered_items[thing.name]
|
|
if (not thing.stackcheck) and def.groups and def.groups.is_stack_only then
|
|
local stack = minetest.get_meta(thing):get_inventory():get_stack("solo", 1)
|
|
if stack and not stack:is_empty() then
|
|
thing.name = stack:get_name()
|
|
def = minetest.registered_items[thing.name]
|
|
thing.count = stack:get_count()
|
|
thing.wear = stack:get_wear()
|
|
end
|
|
thing.stackcheck = true
|
|
end
|
|
|
|
if crit.name and thing.name ~= crit.name then return end
|
|
if crit.param2 and thing.param2 ~= crit.param2 then return end
|
|
if crit.param and thing.param ~= crit.param then return end
|
|
if crit.count and thing.count ~= crit.count then return end
|
|
if crit.count == nil and thing.count ~= 1 then return end
|
|
if crit.wear then
|
|
if crit.wear < 1 then crit.wear = crit.wear * 65535 end
|
|
if thing.wear > crit.wear then return end
|
|
end
|
|
|
|
if crit.groups then
|
|
if not def or not def.groups then return end
|
|
for k, v in pairs(crit.groups) do
|
|
if v == true then
|
|
if not def.groups[k] then return end
|
|
elseif v == false then
|
|
if def.groups[k] then return end
|
|
else
|
|
if def.groups[k] ~= v then return end
|
|
end
|
|
end
|
|
end
|
|
for k, v in pairs(crit) do
|
|
if not match_skip[k] then
|
|
if not def or def[k] ~= v then return end
|
|
end
|
|
end
|
|
|
|
return thing
|
|
end
|