mirror of
https://github.com/minetest/minetest.git
synced 2024-11-04 23:03:46 +01:00
Allow groups in crafting recipes
This commit is contained in:
parent
7631918a12
commit
a435cfcd82
@ -363,8 +363,7 @@ effective towards.
|
|||||||
|
|
||||||
Groups in crafting recipes
|
Groups in crafting recipes
|
||||||
---------------------------
|
---------------------------
|
||||||
- Not implemented yet. (TODO)
|
An example:
|
||||||
- Will probably look like this:
|
|
||||||
{
|
{
|
||||||
output = 'food:meat_soup_raw',
|
output = 'food:meat_soup_raw',
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -372,7 +371,7 @@ Groups in crafting recipes
|
|||||||
{'group:water'},
|
{'group:water'},
|
||||||
{'group:bowl'},
|
{'group:bowl'},
|
||||||
},
|
},
|
||||||
preserve = {'group:bowl'},
|
preserve = {'group:bowl'}, -- Not implemented yet (TODO)
|
||||||
}
|
}
|
||||||
|
|
||||||
Special groups
|
Special groups
|
||||||
@ -1210,19 +1209,19 @@ Node definition (register_node)
|
|||||||
^ default: minetest.node_metadata_inventory_take_allow_all
|
^ default: minetest.node_metadata_inventory_take_allow_all
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe: (register_craft)
|
Recipe for register_craft: (shaped)
|
||||||
{
|
{
|
||||||
output = 'default:pick_stone',
|
output = 'default:pick_stone',
|
||||||
recipe = {
|
recipe = {
|
||||||
{'default:cobble', 'default:cobble', 'default:cobble'},
|
{'default:cobble', 'default:cobble', 'default:cobble'},
|
||||||
{'', 'default:stick', ''},
|
{'', 'default:stick', ''},
|
||||||
{'', 'default:stick', ''},
|
{'', 'default:stick', ''}, -- Also groups; eg. 'group:crumbly'
|
||||||
},
|
},
|
||||||
replacements = <optional list of item pairs,
|
replacements = <optional list of item pairs,
|
||||||
replace one input item with another item on crafting>
|
replace one input item with another item on crafting>
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe (shapeless):
|
Recipe for register_craft (shapeless)
|
||||||
{
|
{
|
||||||
type = "shapeless",
|
type = "shapeless",
|
||||||
output = 'mushrooms:mushroom_stew',
|
output = 'mushrooms:mushroom_stew',
|
||||||
@ -1235,13 +1234,13 @@ Recipe (shapeless):
|
|||||||
replace one input item with another item on crafting>
|
replace one input item with another item on crafting>
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe (tool repair):
|
Recipe for register_craft (tool repair)
|
||||||
{
|
{
|
||||||
type = "toolrepair",
|
type = "toolrepair",
|
||||||
additional_wear = -0.02,
|
additional_wear = -0.02,
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe (cooking):
|
Recipe for register_craft (cooking)
|
||||||
{
|
{
|
||||||
type = "cooking",
|
type = "cooking",
|
||||||
output = "default:glass",
|
output = "default:glass",
|
||||||
@ -1249,7 +1248,7 @@ Recipe (cooking):
|
|||||||
cooktime = 3,
|
cooktime = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe (furnace fuel):
|
Recipe for register_craft (furnace fuel)
|
||||||
{
|
{
|
||||||
type = "fuel",
|
type = "fuel",
|
||||||
recipe = "default:leaves",
|
recipe = "default:leaves",
|
||||||
|
@ -496,6 +496,14 @@ minetest.register_craftitem("experimental:tester_tool_1", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = 'experimental:tester_tool_1',
|
||||||
|
recipe = {
|
||||||
|
{'group:crumbly'},
|
||||||
|
{'group:crumbly'},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
minetest.log("experimental modname="..dump(minetest.get_current_modname()))
|
minetest.log("experimental modname="..dump(minetest.get_current_modname()))
|
||||||
minetest.log("experimental modpath="..dump(minetest.get_modpath("experimental")))
|
minetest.log("experimental modpath="..dump(minetest.get_modpath("experimental")))
|
||||||
minetest.log("experimental worldpath="..dump(minetest.get_worldpath()))
|
minetest.log("experimental worldpath="..dump(minetest.get_worldpath()))
|
||||||
|
@ -27,6 +27,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "gamedef.h"
|
#include "gamedef.h"
|
||||||
#include "inventory.h"
|
#include "inventory.h"
|
||||||
|
|
||||||
|
// Check if input matches recipe
|
||||||
|
// Takes recipe groups into account
|
||||||
|
static bool inputItemMatchesRecipe(const std::string &inp_name,
|
||||||
|
const std::string &rec_name, IItemDefManager *idef)
|
||||||
|
{
|
||||||
|
// Exact name
|
||||||
|
if(inp_name == rec_name)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Group
|
||||||
|
if(rec_name.substr(0,6) == "group:" && idef->isKnown(inp_name)){
|
||||||
|
std::string rec_group = rec_name.substr(6);
|
||||||
|
const struct ItemDefinition &def = idef->get(inp_name);
|
||||||
|
if(itemgroup_get(def.groups, rec_group) != 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Didn't match
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Deserialize an itemstring then return the name of the item
|
// Deserialize an itemstring then return the name of the item
|
||||||
static std::string craftGetItemName(const std::string &itemstring, IGameDef *gamedef)
|
static std::string craftGetItemName(const std::string &itemstring, IGameDef *gamedef)
|
||||||
@ -403,9 +423,9 @@ bool CraftDefinitionShaped::check(const CraftInput &input, IGameDef *gamedef) co
|
|||||||
unsigned int rec_x = rec_min_x + x;
|
unsigned int rec_x = rec_min_x + x;
|
||||||
unsigned int rec_y = rec_min_y + y;
|
unsigned int rec_y = rec_min_y + y;
|
||||||
|
|
||||||
if(
|
if(!inputItemMatchesRecipe(
|
||||||
inp_names[inp_y * inp_width + inp_x] !=
|
inp_names[inp_y * inp_width + inp_x],
|
||||||
rec_names[rec_y * rec_width + rec_x]
|
rec_names[rec_y * rec_width + rec_x], gamedef->idef())
|
||||||
){
|
){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user