From d5ba7ebaf0683560cc93b650c5b9499fbcdacff7 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 6 Dec 2011 17:23:58 +0200 Subject: Random fixes to InvRef related stuff and a broken luafurnace --- data/mods/experimental/init.lua | 134 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) (limited to 'data/mods') diff --git a/data/mods/experimental/init.lua b/data/mods/experimental/init.lua index dd0d60f4e..2c28f89f9 100644 --- a/data/mods/experimental/init.lua +++ b/data/mods/experimental/init.lua @@ -56,6 +56,138 @@ minetest.register_on_placenode(function(pos, newnode, placer) end end) +minetest.register_abm({ + nodenames = {"experimental:luafurnace"}, + interval = 1.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local meta = minetest.env:get_meta(pos) + for i, name in ipairs({ + "fuel_totaltime", + "fuel_time", + "src_totaltime", + "src_time" + }) do + if not tonumber(meta:get_string(name)) then + meta:set_string(name, 0) + end + end + + local inv = meta:get_inventory() + + fuelitem = inv:get_stack("fuel", 1):peek_item() + srcitem = inv:get_stack("src", 1):peek_item() + + local cooked_something = false + + local src_cooktime = -1 + local result_stackstring = nil + + if srcitem then + local prop = nil + if srcitem.type == "node" then + prop = minetest.registered_nodes[srcitem.name] + elseif srcitem.type == "craft" then + prop = minetest.registered_craftitems[srcitem.name] + end + if prop and prop.cookresult_itemstring ~= "" then + result_stackstring = prop.cookresult_itemstring + src_cooktime = prop.furnace_cooktime or 3 + end + end + + if tonumber(meta:get_string("fuel_time")) < tonumber(meta:get_string("fuel_totaltime")) then + meta:set_string("fuel_time", tonumber(meta:get_string("fuel_time")) + 1) + meta:set_string("src_time", tonumber(meta:get_string("src_time")) + 1) + --print("result_stackstring="..dump(result_stackstring)) + --print('tonumber(meta:get_string("src_time"))='..dump(tonumber(meta:get_string("src_time")))) + --print("src_cooktime="..dump(src_cooktime)) + if result_stackstring and tonumber(meta:get_string("src_time")) >= src_cooktime and src_cooktime >= 0 then + for i=1,4 do + -- Put result in "dst" list + dststack = inv:get_stack("dst", i) + success = dststack:put_stackstring(result_stackstring) + inv:set_stack("dst", i, dststack) + -- If succeeded, take stuff from "src" list + if success then + srcstack = inv:get_stack("src", 1) + srcstack:take_item() + inv:set_stack("src", 1, srcstack) + break + end + end + meta:inventory_set_list("src", srclist) + meta:inventory_set_list("dst", dstlist) + meta:set_string("src_time", 0) + cooked_something = true + end + end + + if tonumber(meta:get_string("fuel_time")) < tonumber(meta:get_string("fuel_totaltime")) then + meta:set_infotext("Furnace active: "..(tonumber(meta:get_string("fuel_time"))/tonumber(meta:get_string("fuel_totaltime"))*100).."%") + return + end + + local srclist = meta:inventory_get_list("src") + _, srcitem = stackstring_take_item(srclist[1]) + + local src_cooktime = 0 + local result_stackstring = nil + + if srcitem then + if srcitem.type == "node" then + local prop = minetest.registered_nodes[srcitem.name] + if prop and prop.cookresult_itemstring ~= "" then + result_stackstring = prop.cookresult_itemstring + src_cooktime = prop.furnace_cooktime or 3 + end + elseif srcitem.type == "craft" then + local prop = minetest.registered_craftitems[srcitem.name] + if prop and prop.cookresult_itemstring ~= "" then + result_stackstring = prop.cookresult_itemstring + src_cooktime = prop.furnace_cooktime or 3 + end + end + end + + if not result_stackstring then + if cooked_something then + meta:set_infotext("Furnace is empty") + end + return + end + + local fuellist = meta:inventory_get_list("fuel") + _, fuelitem = stackstring_take_item(fuellist[1]) + + local burntime = -1 + if fuelitem then + if fuelitem.type == "node" then + local prop = minetest.registered_nodes[fuelitem.name] + if prop then + burntime = prop.furnace_burntime or -1 + end + elseif fuelitem.type == "craft" then + local prop = minetest.registered_craftitems[fuelitem.name] + if prop then + burntime = prop.furnace_burntime or -1 + end + end + end + + if burntime <= 0 then + meta:set_infotext("Furnace out of fuel") + return + end + + meta:set_string("fuel_totaltime", burntime) + meta:set_string("fuel_time", 0) + + fuellist[1], _ = stackstring_take_item(fuellist[1]) + meta:inventory_set_list("fuel", fuellist) + end, +}) +--[[ minetest.register_abm({ nodenames = {"experimental:luafurnace"}, interval = 1.0, @@ -110,7 +242,7 @@ minetest.register_abm({ meta:set_infotext("Lua Furnace: total cooked: "..total_cooked) end, }) - +--]] minetest.register_craft({ output = 'node "experimental:luafurnace" 1', recipe = { -- cgit v1.2.3