Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
e7f5cdf9
Commit
e7f5cdf9
authored
11 years ago
by
RealBadAngel
Committed by
kwolekr
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Bugfixes to get_craft_recipe and get_all_craft_recipes.
Improvements to get_all_craft_recipes (see api doc)
parent
dda2071c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/lua_api.txt
+17
-4
17 additions, 4 deletions
doc/lua_api.txt
src/scriptapi_craft.cpp
+17
-18
17 additions, 18 deletions
src/scriptapi_craft.cpp
with
34 additions
and
22 deletions
doc/lua_api.txt
+
17
−
4
View file @
e7f5cdf9
...
...
@@ -1002,10 +1002,23 @@ minetest.get_craft_recipe(output) -> input
^ input.items = for example { stack 1, stack 2, stack 3, stack 4,
stack 5, stack 6, stack 7, stack 8, stack 9 }
^ input.items = nil if no recipe found
minetest.get_all_craft_recipes(output) -> table or nil
^ returns table with all registered recipes for output item (node)
^ returns nil if no recipe was found
^ table entries have same format as minetest.get_craft_recipe
minetest.get_all_craft_recipes(query item) -> table or nil
^ returns indexed table with all registered recipes for query item (node)
or nil if no recipe was found
recipe entry table:
{
method = 'normal' or 'cooking' or 'fuel'
width = 0-3, 0 means shapeless recipe
items = indexed [1-9] table with recipe items
output = string with item name and quantity
}
Example query for default:gold_ingot will return table:
{
1={type = "cooking", width = 3, output = "default:gold_ingot",
items = {1 = "default:gold_lump"}},
2={type = "normal", width = 1, output = "default:gold_ingot 9",
items = {1 = "default:goldblock"}}
}
minetest.handle_node_drops(pos, drops, digger)
^ drops: list of itemstrings
^ Handles drops from nodes after digging: Default action is to put them into
...
...
This diff is collapsed.
Click to expand it.
src/scriptapi_craft.cpp
+
17
−
18
View file @
e7f5cdf9
...
...
@@ -330,8 +330,7 @@ int l_get_craft_result(lua_State *L)
// get_craft_recipe(result item)
int
l_get_craft_recipe
(
lua_State
*
L
)
{
int
k
=
0
;
char
tmp
[
20
];
int
k
=
1
;
int
input_i
=
1
;
std
::
string
o_item
=
luaL_checkstring
(
L
,
input_i
);
...
...
@@ -351,8 +350,7 @@ int l_get_craft_recipe(lua_State *L)
{
continue
;
}
sprintf
(
tmp
,
"%d"
,
k
);
lua_pushstring
(
L
,
tmp
);
lua_pushinteger
(
L
,
k
);
lua_pushstring
(
L
,
i
->
name
.
c_str
());
lua_settable
(
L
,
-
3
);
}
...
...
@@ -383,9 +381,7 @@ int l_get_craft_recipe(lua_State *L)
// get_all_craft_recipes(result item)
int
l_get_all_craft_recipes
(
lua_State
*
L
)
{
char
tmp
[
20
];
int
input_i
=
1
;
std
::
string
o_item
=
luaL_checkstring
(
L
,
input_i
);
std
::
string
o_item
=
luaL_checkstring
(
L
,
1
);
IGameDef
*
gdef
=
get_server
(
L
);
ICraftDefManager
*
cdef
=
gdef
->
cdef
();
CraftInput
input
;
...
...
@@ -402,7 +398,7 @@ int l_get_all_craft_recipes(lua_State *L)
int
table_insert
=
lua_gettop
(
L
);
lua_newtable
(
L
);
int
table
=
lua_gettop
(
L
);
for
(
std
::
vector
<
CraftDefinition
*>::
const_iterator
for
(
std
::
vector
<
CraftDefinition
*>::
const_iterator
i
=
recipes_list
.
begin
();
i
!=
recipes_list
.
end
();
i
++
)
{
...
...
@@ -411,28 +407,29 @@ int l_get_all_craft_recipes(lua_State *L)
tmpout
.
time
=
0
;
CraftDefinition
*
def
=
*
i
;
tmpout
=
def
->
getOutput
(
input
,
gdef
);
if
(
tmpout
.
item
.
substr
(
0
,
output
.
item
.
length
())
==
output
.
item
)
std
::
string
query
=
tmpout
.
item
;
char
*
fmtpos
,
*
fmt
=
&
query
[
0
];
if
(
strtok_r
(
fmt
,
" "
,
&
fmtpos
)
==
output
.
item
)
{
input
=
def
->
getInput
(
output
,
gdef
);
lua_pushvalue
(
L
,
table_insert
);
lua_pushvalue
(
L
,
table
);
lua_newtable
(
L
);
int
k
=
0
;
int
k
=
1
;
lua_newtable
(
L
);
for
(
std
::
vector
<
ItemStack
>::
const_iterator
i
=
input
.
items
.
begin
();
i
!=
input
.
items
.
end
();
i
++
,
k
++
)
{
if
(
i
->
empty
())
continue
;
sprintf
(
tmp
,
"%d"
,
k
)
;
lua_push
string
(
L
,
tmp
);
lua_pushstring
(
L
,
i
->
name
.
c_str
());
if
(
i
->
empty
())
continue
;
lua_push
integer
(
L
,
k
);
lua_pushstring
(
L
,
i
->
name
.
c_str
());
lua_settable
(
L
,
-
3
);
}
lua_setfield
(
L
,
-
2
,
"items"
);
setintfield
(
L
,
-
1
,
"width"
,
input
.
width
);
switch
(
input
.
method
)
{
switch
(
input
.
method
)
{
case
CRAFT_METHOD_NORMAL
:
lua_pushstring
(
L
,
"normal"
);
break
;
...
...
@@ -446,8 +443,10 @@ int l_get_all_craft_recipes(lua_State *L)
lua_pushstring
(
L
,
"unknown"
);
}
lua_setfield
(
L
,
-
2
,
"type"
);
if
(
lua_pcall
(
L
,
2
,
0
,
0
))
script_error
(
L
,
"error: %s"
,
lua_tostring
(
L
,
-
1
));
lua_pushstring
(
L
,
&
tmpout
.
item
[
0
]);
lua_setfield
(
L
,
-
2
,
"output"
);
if
(
lua_pcall
(
L
,
2
,
0
,
0
))
script_error
(
L
,
"error: %s"
,
lua_tostring
(
L
,
-
1
));
}
}
return
1
;
...
...
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