Get electric furnace working and add progress bars
This commit is contained in:
parent
b1600a73a9
commit
0630e56de4
@ -1,3 +1,6 @@
|
|||||||
|
local modifier = 10 -- Cooking cost modifier
|
||||||
|
local time_modifier = 1.5 -- Cooking time modifier
|
||||||
|
|
||||||
local formspec =
|
local formspec =
|
||||||
"size[8,6.5]"..
|
"size[8,6.5]"..
|
||||||
"list[current_name;source;0,0;1,2;]" ..
|
"list[current_name;source;0,0;1,2;]" ..
|
||||||
@ -38,6 +41,32 @@ local function ongetitem(pos)
|
|||||||
timer:start(1.0)
|
timer:start(1.0)
|
||||||
end
|
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 function mytime(pos, elapsed)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local energy = meta:get_int("energy")
|
local energy = meta:get_int("energy")
|
||||||
@ -52,9 +81,9 @@ local function mytime(pos, elapsed)
|
|||||||
local cooked
|
local cooked
|
||||||
local aftercooked
|
local aftercooked
|
||||||
local progress = meta:get_int("progress_" .. item)
|
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
|
--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
|
if inventory:room_for_item("product", cooked.item) then
|
||||||
inventory:add_item("product", cooked.item)
|
inventory:add_item("product", cooked.item)
|
||||||
inventory:set_stack("source", item, aftercooked.items[1])
|
inventory:set_stack("source", item, aftercooked.items[1])
|
||||||
@ -64,11 +93,14 @@ local function mytime(pos, elapsed)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
meta:set_int("progress_" .. item, progress + 1)
|
meta:set_int("progress_" .. item, progress + 1)
|
||||||
energy = energy -1
|
energy = energy - 1 * modifier
|
||||||
meta:set_int("energy", energy)
|
meta:set_int("energy", energy)
|
||||||
end
|
end
|
||||||
minetest.debug(pos .." : " ..item)
|
-- minetest.debug(dump(pos) .. " : " .. dump(item))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
update_formspec(pos)
|
||||||
|
|
||||||
if counter == 2 then
|
if counter == 2 then
|
||||||
newcycle = false -- this meens that both finished cooking and the other inventory is full
|
newcycle = false -- this meens that both finished cooking and the other inventory is full
|
||||||
end
|
end
|
||||||
@ -124,6 +156,11 @@ minetest.register_node(minetest.get_current_modname() .. ":lv_furnace", {
|
|||||||
inventory:set_size('product',2)
|
inventory:set_size('product',2)
|
||||||
end,
|
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_put = is_item_allowed,
|
||||||
allow_metadata_inventory_move = is_item_allowed_move,
|
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_move = ongetitem, --doesnt seem necesarry to me, if the item moves in the inventory schould not change the cooking process
|
||||||
|
Loading…
x
Reference in New Issue
Block a user