Get electric furnace working and add progress bars

This commit is contained in:
Valentin Anger 2018-01-06 23:52:25 +01:00
parent b1600a73a9
commit 0630e56de4

View File

@ -1,3 +1,6 @@
local modifier = 10 -- Cooking cost modifier
local time_modifier = 1.5 -- Cooking time modifier
local formspec =
"size[8,6.5]"..
"list[current_name;source;0,0;1,2;]" ..
@ -38,6 +41,32 @@ local function ongetitem(pos)
timer:start(1.0)
end
local function update_formspec(pos)
local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory()
local cfmsp = formspec
local energy = meta:get_int("energy")
cfmsp = cfmsp ..
sparktech.makebar("energy2.png", 0, 2.1, 9.75, 0.25,
energy, minetest.get_item_group(minetest.get_node(pos).name, "sparktech_energy_max")
, 0)
for item=1, 2 do -- Later this should only be done when a player looks into the block
local cooked
local aftercooked
local progress = meta:get_int("progress_" .. item)
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = {inventory:get_stack("source", item)}})
cfmsp = cfmsp ..
sparktech.makebar("progress2.png", 0, -1 + item, 1, 1,
progress, math.ceil(cooked.time * time_modifier), 0)
end
meta:set_string("formspec", cfmsp)
end
local function mytime(pos, elapsed)
local meta = minetest.get_meta(pos)
local energy = meta:get_int("energy")
@ -52,9 +81,9 @@ local function mytime(pos, elapsed)
local cooked
local aftercooked
local progress = meta:get_int("progress_" .. item)
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = inventory:get_stack("source", item)}) --errors here, dunno what it wants instead
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = {inventory:get_stack("source", item)}})
--source and product assigned
if progress == cooked.time then
if progress >= math.ceil(cooked.time * time_modifier) then
if inventory:room_for_item("product", cooked.item) then
inventory:add_item("product", cooked.item)
inventory:set_stack("source", item, aftercooked.items[1])
@ -64,11 +93,14 @@ local function mytime(pos, elapsed)
end
else
meta:set_int("progress_" .. item, progress + 1)
energy = energy -1
energy = energy - 1 * modifier
meta:set_int("energy", energy)
end
minetest.debug(pos .." : " ..item)
-- minetest.debug(dump(pos) .. " : " .. dump(item))
end
update_formspec(pos)
if counter == 2 then
newcycle = false -- this meens that both finished cooking and the other inventory is full
end
@ -117,15 +149,20 @@ minetest.register_node(minetest.get_current_modname() .. ":lv_furnace", {
--end,
on_construct = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",formspec) --gonna replace this with crafting the formspec on rightclick instead
local inventory = meta:get_inventory()
inventory:set_size('source',2)
inventory:set_size('product',2)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",formspec) --gonna replace this with crafting the formspec on rightclick instead
local inventory = meta:get_inventory()
inventory:set_size('source',2)
inventory:set_size('product',2)
end,
on_rightclick = function(pos, clicker) -- Requires Version >0.4.16 to trigger because a custom formspec is set
minetest.debug("Ping!")
return false
end,
allow_metadata_inventory_put = is_item_allowed,
allow_metadata_inventory_move = is_item_allowed_move,
--on_metadata_inventory_move = ongetitem, --doesnt seem necesarry to me, if the item moves in the inventory schould not change the cooking process
on_metadata_inventory_put = ongetitem
})
})