update to furnace
This commit is contained in:
parent
c7a7fd3771
commit
59ff7b80f6
@ -1,130 +1,115 @@
|
|||||||
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;]" ..
|
||||||
"list[current_name;product;7,0;1,2;]" ..
|
"list[current_name;product;7,0;1,2;]" ..
|
||||||
"list[current_player;main;0,2.5;8,3;8]" ..
|
"list[current_player;main;0,2.5;8,3;8]" ..
|
||||||
"list[current_player;main;0,5.7;8,1;]"..
|
"list[current_player;main;0,5.7;8,1;]"..
|
||||||
"bgcolor[#FC05E344;false]" ..
|
"bgcolor[#FC05E344;false]" ..
|
||||||
"listcolors[#fc059db0;#fc059dd0]"
|
"listcolors[#fc059db0;#fc059dd0]"
|
||||||
|
|
||||||
local function is_smeltable(items)
|
local function is_smeltable(items)
|
||||||
local cooked
|
local cooked
|
||||||
local aftercooked
|
local aftercooked
|
||||||
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = items})
|
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = items})
|
||||||
return cooked.time ~= 0
|
return cooked.time ~= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_item_allowed(pos, target, _, stack)
|
local function is_item_allowed(pos, target, _, stack)
|
||||||
if target == "product" then return 0 end
|
if target == "product" then return 0 end --so no items get moved into the souce inventory by the user
|
||||||
|
|
||||||
if stack == nil or not is_smeltable({stack}) then
|
if stack == nil or not is_smeltable({stack}) then --invalid or unsmeltable items dont get in
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_item_allowed_move(pos, src, sidx, target, tidx, c, p)
|
local function is_item_allowed_move(pos, src, sidx, target, tidx, c, p)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local stack = inv:get_stack(src, sidx)
|
local stack = inv:get_stack(src, sidx)
|
||||||
return is_item_allowed(pos, target, tidx, stack, p)
|
return is_item_allowed(pos, target, tidx, stack, p)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ongetitem(pos)
|
local function ongetitem(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if meta:get_int("energy") == 0 then return end
|
if meta:get_int("energy") == 0 then return end
|
||||||
local timer = minetest.get_node_timer(pos)
|
local timer = minetest.get_node_timer(pos)
|
||||||
timer:start(1.0)
|
timer:start(1.0)
|
||||||
end
|
|
||||||
|
|
||||||
local function storeprogress(progress) --store the progress of burning in the node meta, burning items aren't take from source, they simply cant be removed any longer when starting to burn
|
|
||||||
for x=1,table_getn(progress),1
|
|
||||||
do
|
|
||||||
meta.get_string("cookprogess_" + i.progress[x])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function restoreprogress(meta,count)
|
|
||||||
local progress = {}
|
|
||||||
for x=1,count,1
|
|
||||||
do
|
|
||||||
progress[x] = meta:get_string("cookprogess_" .. x)
|
|
||||||
end
|
|
||||||
return progress
|
|
||||||
end
|
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")
|
||||||
local inventory = meta:get_inventory()
|
local inventory = meta:get_inventory()
|
||||||
local source = inventory:get_list("source")
|
local source = inventory:get_list("source")
|
||||||
local progress = restoreprogress(meta,table.getn(source))
|
local progress = restoreprogress(meta,table.getn(source))
|
||||||
local product = inventory:get_list("product")
|
local product = inventory:get_list("product")
|
||||||
|
|
||||||
local newcycle = false -- this is false, if we feel that we need a new cycle we set this to true so that the furnace may cook again (e.g enough fuel and items are available)
|
|
||||||
|
|
||||||
--TODO: start cook logic (if there is any energy available start to cook (progress[inventoryslot]++ and commit to meta after all were processed
|
|
||||||
|
|
||||||
meta:set_string("formspec", formspec ..
|
local newcycle = false -- this is false, if we feel that we need a new cycle we set this to true so that the furnace may cook again (e.g enough fuel and items are available)
|
||||||
sparktech.makebar("energy.png", 0, 2.1, 9.75, 0.25,
|
|
||||||
energy, minetest.get_item_group(minetest.get_node(pos).name, "sparktech_energy_max")
|
|
||||||
, 2))
|
|
||||||
|
|
||||||
if (newcycle) then
|
--TODO: start cook logic (if there is any energy available start to cook (progress[inventoryslot]++ and commit to meta after all were processed
|
||||||
minetest.get_node_timer(pos):start(1.0)
|
|
||||||
end
|
--meta:set_string("formspec", formspec ..
|
||||||
return
|
--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))
|
||||||
|
|
||||||
|
if (newcycle) then
|
||||||
|
minetest.get_node_timer(pos):start(1.0) -- it was determined that a new cycle is required, this is the case if energy and material to cook is available
|
||||||
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function maytake(pos, listname, index, stack, player)
|
local function maytake(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if listname == "product" then
|
if listname == "product" then
|
||||||
return tonumber(stack:get_count()) --sure, take the stuff that the furnace has cooked for you :D
|
return tonumber(stack:get_count()) --sure, take the stuff that the furnace has cooked for you :D
|
||||||
end
|
end
|
||||||
local table = restoreprogress(meta,2)
|
-- TODO: code to stop people from taking halfcooked items, they'd burn their fingers
|
||||||
if table[pos] == nil then return stack:get_count() end
|
|
||||||
if listname == "source" then
|
|
||||||
if table[pos] > 0 then
|
|
||||||
return tonumber(stack:get_count() -1)
|
|
||||||
end
|
|
||||||
return tonumber(stack:get_count())
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node(minetest.get_current_modname() .. ":lv_furnace", {
|
minetest.register_node(minetest.get_current_modname() .. ":lv_furnace", {
|
||||||
description = "Electric furnace",
|
description = "Electric furnace",
|
||||||
tiles = {
|
|
||||||
"furnace2.png",
|
|
||||||
"furnace2.png",
|
|
||||||
"furnace2.png",
|
|
||||||
"furnace2.png",
|
|
||||||
"furnace2.png",
|
|
||||||
"furnace.png"
|
|
||||||
},
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {
|
|
||||||
sparktech_techy = 1,
|
|
||||||
sparktech_energy_type = 4,
|
|
||||||
sparktech_net_trigger = 1,
|
|
||||||
sparktech_energy_max = 300,
|
|
||||||
spark_energy_timer = 2
|
|
||||||
},
|
|
||||||
|
|
||||||
on_timer = mytime, -- add a mytimer function
|
tiles = {
|
||||||
allow_metadata_inventory_take = maytake,
|
"furnace2.png",
|
||||||
|
"furnace2.png",
|
||||||
|
"furnace2.png",
|
||||||
|
"furnace2.png",
|
||||||
|
"furnace2.png",
|
||||||
|
"furnace.png"
|
||||||
|
},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
|
||||||
on_construct = function(pos, placer)
|
groups = {
|
||||||
local meta = minetest.get_meta(pos)
|
sparktech_techy = 1,
|
||||||
meta:set_string("formspec",formspec)
|
sparktech_energy_type = 4,
|
||||||
local inventory = meta:get_inventory()
|
sparktech_net_trigger = 1,
|
||||||
inventory:set_size('source',2)
|
sparktech_energy_max = 300,
|
||||||
inventory:set_size('product',2)
|
spark_energy_timer = 2
|
||||||
end,
|
},
|
||||||
allow_metadata_inventory_put = is_item_allowed,
|
|
||||||
allow_metadata_inventory_move = is_item_allowed_move,
|
on_timer = mytime, -- add a mytimer function
|
||||||
on_metadata_inventory_move = ongetitem, --TODO: test these
|
allow_metadata_inventory_take = maytake,
|
||||||
on_metadata_inventory_put = ongetitem
|
|
||||||
})
|
--on_righclick = function(pos, node, player, itemstack, pointed_thing)
|
||||||
|
--TODO show formspec here, and store that a formspec is open in meta, the mytimer function schould update the formspec if it is open, recievefields schould mark it as closed
|
||||||
|
|
||||||
|
--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)
|
||||||
|
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
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user