-- rnd 2015: -- this node works as a reverse of crafting process with a 25% loss of items (aka recycling). You can select which recipe to use when recycling. -- There is a fuel cost to recycle local recycler_process = function(pos) local node = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name; local meta = minetest.get_meta(pos);local inv = meta:get_inventory(); -- FUEL CHECK local fuel = meta:get_float("fuel"); if fuel-1<0 then -- we need new fuel, check chest below local fuellist = inv:get_list("fuel") if not fuellist then return end local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) local supply=0; if fueladd.time == 0 then -- no fuel inserted, try look for outlet -- No valid fuel in fuel list supply = basic_machines.check_power({x=pos.x,y=pos.y-1,z=pos.z},1) or 0; if supply>0 then fueladd.time = 40*supply -- same as 10 coal else meta:set_string("infotext", "Please insert fuel."); return; end else if supply==0 then -- Take fuel from fuel list if no supply available inv:set_stack("fuel", 1, afterfuel.items[1]) fueladd.time = fueladd.time*0.1; -- thats 4 for coal end end if fueladd.time>0 then fuel=fuel + fueladd.time meta:set_float("fuel",fuel); meta:set_string("infotext", "added fuel furnace burn time " .. fueladd.time .. ", fuel status " .. fuel); end if fuel-1<0 then return end end -- RECYCLING: check out inserted items local stack = inv:get_stack("src",1); if stack:is_empty() then return end; -- nothing to do local src_item = stack:to_string(); local p=string.find(src_item," "); if p then src_item = string.sub(src_item,1,p-1) end -- take first word to determine what item was -- look if we already handled this item local known_recipe=true; if src_item~=meta:get_string("node") then-- did we already handle this? if yes read from cache meta:set_string("node",src_item); meta:set_string("itemlist","{}"); meta:set_int("reqcount",0); known_recipe=false; end local itemlist, reqcount; reqcount = 1; -- needed count of materials for recycle to work if not known_recipe then local recipe = minetest.get_all_craft_recipes( src_item ); local recipe_id = tonumber(meta:get_int("recipe")) or 1; if not recipe then return else itemlist = recipe[recipe_id]; if not itemlist then meta:set_string("node","") return end; itemlist=itemlist.items; end local output = recipe[recipe_id].output or ""; if string.find(output," ") then local par = string.find(output," "); --if (tonumber(string.sub(output, par)) or 0)>1 then itemlist = {} end if par then reqcount = tonumber(string.sub(output, par)) or 1; end end -- cause if for example output is "default:mese 9" we dont want to get meseblock from just 1 mese.. meta:set_string("itemlist",minetest.serialize(itemlist)); -- read cached itemlist meta:set_int("reqcount",reqcount); else itemlist=minetest.deserialize(meta:get_string("itemlist")) or {}; reqcount = meta:get_int("reqcount") or 1; end if stack:get_count()