Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kif_custom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Minetest
kif_custom
Commits
601fd38e
Commit
601fd38e
authored
Dec 20, 2020
by
Peter Nerlich
Browse files
Options
Downloads
Patches
Plain Diff
fix recipe util function, print message if recipes are not added
parent
2f7b7695
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
util.lua
+79
-7
79 additions, 7 deletions
util.lua
with
79 additions
and
7 deletions
util.lua
+
79
−
7
View file @
601fd38e
kif
.
get_item_name_from_string
=
function
(
str
)
local
space
=
string.find
(
str
,
' '
)
if
space
==
nil
then
return
str
else
return
string.sub
(
str
,
1
,
space
-
1
)
end
end
kif
.
is_group_string
=
function
(
str
)
local
group
=
'group:'
if
string.sub
(
str
,
1
,
#
group
)
==
group
then
return
string.sub
(
str
,
#
group
+
1
)
else
return
false
end
end
local
debug
=
function
(
msg
,
item
)
if
item
==
nil
then
item
=
''
else
item
=
" "
..
kif
.
get_item_name_from_string
(
tostring
(
item
))
end
print
(
"kif.register_craft_if_items_exist() "
..
msg
..
item
)
end
kif
.
discovered_item_groups
=
{}
kif
.
group_exists
=
function
(
group
)
-- all desired items have to have been registered already to discover their groups (obviously)
-- you might need to include these mods as optional dependencies
if
kif
.
discovered_item_groups
[
group
]
==
group
then
return
true
end
for
name
,
item
in
pairs
(
minetest
.
registered_items
)
do
if
type
(
item
.
groups
)
==
"table"
then
for
group
,
rating
in
pairs
(
item
.
groups
)
do
kif
.
discovered_item_groups
[
group
]
=
group
end
end
if
kif
.
discovered_item_groups
[
group
]
==
group
then
local
n
=
0
for
k
,
v
in
pairs
(
kif
.
discovered_item_groups
)
do
n
=
n
+
1
end
return
true
end
end
return
false
end
kif
.
register_craft_if_items_exist
=
function
(
def
)
if
def
.
output
and
minetest
.
registered_items
[
tostring
(
def
.
output
)]
==
nil
then
if
def
.
output
and
minetest
.
registered_items
[
kif
.
get_item_name_from_string
(
def
.
output
)]
==
nil
then
debug
(
"[FAIL] unknown output"
,
def
.
output
)
return
false
end
if
def
.
recipe
then
if
type
(
def
.
recipe
)
~=
"table"
then
if
minetest
.
registered_items
[
tostring
(
def
.
recipe
)]
==
nil
then
local
recipe_item
=
kif
.
get_item_name_from_string
(
def
.
recipe
)
if
minetest
.
registered_items
[
recipe_item
]
==
nil
then
local
group
=
kif
.
is_group_string
(
recipe_item
)
if
not
(
group
and
kif
.
group_exists
(
group
))
then
debug
(
"[FAIL] unknown recipe"
,
recipe_item
)
return
false
end
end
else
for
y
,
row
in
ipairs
(
def
.
recipe
)
do
if
type
(
row
)
~=
"table"
then
if
row
~=
""
and
minetest
.
registered_items
[
tostring
(
row
)]
==
nil
then
local
row_item
=
kif
.
get_item_name_from_string
(
row
)
if
minetest
.
registered_items
[
row_item
]
==
nil
then
local
group
=
kif
.
is_group_string
(
row_item
)
if
not
(
group
and
kif
.
group_exists
(
group
))
then
debug
(
"[FAIL] unknown row item"
,
row_item
)
return
false
end
end
else
for
x
,
col
in
ipairs
(
row
)
do
if
col
~=
""
and
minetest
.
registered_items
[
tostring
(
col
)]
==
nil
then
local
col_item
=
kif
.
get_item_name_from_string
(
col
)
if
col
~=
""
and
minetest
.
registered_items
[
col_item
]
==
nil
then
local
group
=
kif
.
is_group_string
(
col_item
)
if
not
(
group
and
kif
.
group_exists
(
group
))
then
debug
(
"[FAIL] unknown item"
,
col
)
return
false
end
end
end
end
end
end
-- still here? recipe is fine then!
minetest
.
register_craft
(
def
)
return
true
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment