move `item_matches` into api.
move function `item_matches` from `bg_crafting` into `bg_api`, since it'll be useful in many other places.
This commit is contained in:
parent
7df5d33d02
commit
d197e1f1e3
|
@ -13,6 +13,7 @@ load_file("util_random")
|
||||||
load_file("util_vector")
|
load_file("util_vector")
|
||||||
|
|
||||||
load_file("util_node")
|
load_file("util_node")
|
||||||
|
load_file("util_item")
|
||||||
|
|
||||||
load_file("wrappers")
|
load_file("wrappers")
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
function blockgame.item_matches (name, options)
|
||||||
|
return blockgame.any(options, function (option)
|
||||||
|
if name == option then return true end
|
||||||
|
|
||||||
|
if blockgame.starts_with(option, "group:") then
|
||||||
|
local group = string.sub(option, 7)
|
||||||
|
return minetest.get_item_group(name, group) > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end)
|
||||||
|
end
|
|
@ -1,5 +1,9 @@
|
||||||
local api = blockgame.crafting
|
local api = blockgame.crafting
|
||||||
|
|
||||||
|
-- LOCALS
|
||||||
|
|
||||||
|
local matches = blockgame.item_matches
|
||||||
|
|
||||||
-- pummeling is heavily based on nodecore by Warr1024 (both the mechanic itself and the code here implementing it).
|
-- pummeling is heavily based on nodecore by Warr1024 (both the mechanic itself and the code here implementing it).
|
||||||
|
|
||||||
local pummel_recipes = {}
|
local pummel_recipes = {}
|
||||||
|
@ -21,22 +25,10 @@ function api.register_pummel_recipe (def)
|
||||||
table.insert(api.registered_recipes, def)
|
table.insert(api.registered_recipes, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: extract this function into general api
|
|
||||||
local function item_matches (nodename, options)
|
|
||||||
return blockgame.any(options, function (option)
|
|
||||||
if nodename == option then return true end
|
|
||||||
if blockgame.starts_with(option, "group:") then
|
|
||||||
local group = string.sub(option, 7)
|
|
||||||
return minetest.get_item_group(nodename, group) > 0
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TODO: add support for pummel recipes using groups instead of just specific node names.
|
-- TODO: add support for pummel recipes using groups instead of just specific node names.
|
||||||
function api.pummel_check (pos, used, target_node)
|
function api.pummel_check (pos, used, target_node)
|
||||||
for _, def in pairs(pummel_recipes) do
|
for _, def in pairs(pummel_recipes) do
|
||||||
if item_matches(used, def.used) and item_matches(target_node.name, def.target) then
|
if matches(used, def.used) and matches(target_node.name, def.target) then
|
||||||
if type(def.check) == "function" and not def.check(pos, used, target_node) then
|
if type(def.check) == "function" and not def.check(pos, used, target_node) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue