aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/mods/experimental/init.lua134
1 files changed, 133 insertions, 1 deletions
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
@@ -62,6 +62,138 @@ minetest.register_abm({
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,
+ chance = 1,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ local meta = minetest.env:get_meta(pos)
local fuellist = meta:inventory_get_list("fuel")
local srclist = meta:inventory_get_list("src")
local dstlist = meta:inventory_get_list("dst")
@@ -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 = {