From: Kahrl Date: Sat, 11 Feb 2012 17:10:13 +0000 (+0100) Subject: Allow replacements in cooking and fuel recipes X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=e070f1e5250b6853788cb827bb2f46ecdbe300a8;p=zefram%2Fminetest%2Fminetest_engine.git Allow replacements in cooking and fuel recipes --- diff --git a/src/craftdef.cpp b/src/craftdef.cpp index e8f67442..57a1851a 100644 --- a/src/craftdef.cpp +++ b/src/craftdef.cpp @@ -260,6 +260,7 @@ std::string CraftOutput::dump() const /* CraftReplacements */ + std::string CraftReplacements::dump() const { std::ostringstream os(std::ios::binary); @@ -276,6 +277,27 @@ std::string CraftReplacements::dump() const return os.str(); } +void CraftReplacements::serialize(std::ostream &os) const +{ + writeU16(os, pairs.size()); + for(u32 i=0; iregisterCraft(def); } /* @@ -4144,8 +4153,17 @@ static int l_register_craft(lua_State *L) float burntime = getfloatfield_default(L, table, "burntime", 1.0); + CraftReplacements replacements; + lua_getfield(L, table, "replacements"); + if(!lua_isnil(L, -1)) + { + if(!read_craft_replacements(L, -1, replacements)) + throw LuaError(L, "Invalid replacements" + " (fuel recipe=\"" + recipe + "\")"); + } + CraftDefinition *def = new CraftDefinitionFuel( - recipe, burntime); + recipe, burntime, replacements); craftdef->registerCraft(def); } else