Move door handling from cache to filter framework
This commit is contained in:
parent
8ff56a3322
commit
cbd843311a
@ -8,26 +8,7 @@ cache.citems = {}
|
||||
-----------------------------------------------------
|
||||
-- Add an Item to the cache
|
||||
-----------------------------------------------------
|
||||
function cache.add_item(def)
|
||||
|
||||
-- special handling for doors. In inventory the item should be displayed instead of the node_a/node_b
|
||||
local item_def
|
||||
|
||||
if def.groups and def.groups.door then
|
||||
if def.door then
|
||||
item_def = minetest.registered_items[def.door.name]
|
||||
elseif def.drop and type(def.drop) == "string" then
|
||||
item_def = minetest.registered_items[def.drop]
|
||||
else
|
||||
item_def = def
|
||||
end
|
||||
if not item_def then
|
||||
minetest.log("[smart_inventory] Buggy door found: "..def.name)
|
||||
item_def = def
|
||||
end
|
||||
else
|
||||
item_def = def
|
||||
end
|
||||
function cache.add_item(item_def)
|
||||
|
||||
-- already in cache. Skip duplicate processing
|
||||
if cache.citems[item_def.name] then
|
||||
@ -49,7 +30,7 @@ function cache.add_item(def)
|
||||
cache.citems[item_def.name] = entry
|
||||
-- classify the item
|
||||
for _, flt in pairs(filter.registered_filter) do
|
||||
local filter_result = flt:check_item_by_def(def)
|
||||
local filter_result = flt:check_item_by_def(item_def)
|
||||
if filter_result then
|
||||
if filter_result == true then
|
||||
cache.assign_to_group(flt.name, item_def, flt)
|
||||
|
@ -216,8 +216,17 @@ end
|
||||
filter.register_filter({
|
||||
name = "shape",
|
||||
check_item_by_def = function(self, def)
|
||||
local door_groups
|
||||
if shaped_groups["door"] then
|
||||
local door_filter = filter.get("door")
|
||||
door_groups = door_filter:check_item_by_def(def)
|
||||
if door_groups and door_groups.door then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(def.groups) do
|
||||
if shaped_groups[k] then
|
||||
if k ~= "door" and shaped_groups[k] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -356,6 +365,45 @@ filter.register_filter({
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
local door_groups
|
||||
local function fill_door_groups()
|
||||
door_groups = {}
|
||||
for _, extend_def in pairs(minetest.registered_items) do
|
||||
local base_def
|
||||
if extend_def.groups and extend_def.groups.door then
|
||||
if extend_def.door then
|
||||
base_def = minetest.registered_items[extend_def.door.name]
|
||||
elseif extend_def.drop and type(extend_def.drop) == "string" then
|
||||
base_def = minetest.registered_items[extend_def.drop]
|
||||
end
|
||||
end
|
||||
if base_def then
|
||||
door_groups[base_def.name] = extend_def
|
||||
door_groups[extend_def.name] = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
filter.register_filter({
|
||||
name = "door",
|
||||
check_item_by_def = function(self, def)
|
||||
if not door_groups then
|
||||
fill_door_groups()
|
||||
end
|
||||
if not door_groups[def.name] then
|
||||
return
|
||||
end
|
||||
|
||||
local group_filter = filter.get("group")
|
||||
local ret = group_filter:check_item_by_def(door_groups[def.name])
|
||||
if ret then
|
||||
ret["not_in_creative_inventory"] = nil
|
||||
return ret
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
----------------
|
||||
return filter
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user