mirror of
https://github.com/mt-mods/pipeworks.git
synced 2024-11-10 01:13:57 +01:00
add an enable/disable button to the autocrafter
the reaction time of the button might be a bit confusing though until minetest/minetest#2220 is being resolved
This commit is contained in:
parent
5ac0053f8c
commit
6d1bc7b3fc
@ -40,6 +40,16 @@ local function get_craft(pos, inventory, hash)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function start_crafter(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if meta:get_int("enabled") == 1 then
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
if not timer:is_started() then
|
||||||
|
timer:start(craft_time)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- note, that this function assumes allready being updated to virtual items
|
-- note, that this function assumes allready being updated to virtual items
|
||||||
-- and doesn't handle recipes with stacksizes > 1
|
-- and doesn't handle recipes with stacksizes > 1
|
||||||
local function on_recipe_change(pos, inventory)
|
local function on_recipe_change(pos, inventory)
|
||||||
@ -68,17 +78,11 @@ local function on_recipe_change(pos, inventory)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local timer = minetest.get_node_timer(pos)
|
start_crafter(pos)
|
||||||
if not timer:is_started() then
|
|
||||||
timer:start(craft_time)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_inventory_change(pos, inventory)
|
local function on_inventory_change(pos, inventory)
|
||||||
local timer = minetest.get_node_timer(pos)
|
start_crafter(pos)
|
||||||
if not timer:is_started() then
|
|
||||||
timer:start(craft_time)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function autocraft(inventory, craft)
|
local function autocraft(inventory, craft)
|
||||||
@ -137,6 +141,17 @@ local function update_autocrafter(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function set_formspec(meta, enabled)
|
||||||
|
local state = enabled and "on" or "off"
|
||||||
|
meta:set_string("formspec",
|
||||||
|
"size[8,11]"..
|
||||||
|
"list[context;recipe;0,0;3,3;]"..
|
||||||
|
"image_button[3,2;1,1;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" ..
|
||||||
|
"list[context;src;0,3.5;8,3;]"..
|
||||||
|
"list[context;dst;4,0;4,3;]"..
|
||||||
|
"list[current_player;main;0,7;8,4;]")
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("pipeworks:autocrafter", {
|
minetest.register_node("pipeworks:autocrafter", {
|
||||||
description = "Autocrafter",
|
description = "Autocrafter",
|
||||||
drawtype = "normal",
|
drawtype = "normal",
|
||||||
@ -158,12 +173,7 @@ minetest.register_node("pipeworks:autocrafter", {
|
|||||||
connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}},
|
connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}},
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("formspec",
|
set_formspec(meta)
|
||||||
"size[8,11]"..
|
|
||||||
"list[current_name;recipe;0,0;3,3;]"..
|
|
||||||
"list[current_name;src;0,3.5;8,3;]"..
|
|
||||||
"list[current_name;dst;4,0;4,3;]"..
|
|
||||||
"list[current_player;main;0,7;8,4;]")
|
|
||||||
meta:set_string("infotext", "unconfigured Autocrafter")
|
meta:set_string("infotext", "unconfigured Autocrafter")
|
||||||
meta:set_string("virtual_items", "1")
|
meta:set_string("virtual_items", "1")
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
@ -171,6 +181,21 @@ minetest.register_node("pipeworks:autocrafter", {
|
|||||||
inv:set_size("recipe", 3*3)
|
inv:set_size("recipe", 3*3)
|
||||||
inv:set_size("dst", 4*3)
|
inv:set_size("dst", 4*3)
|
||||||
end,
|
end,
|
||||||
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if fields.on then
|
||||||
|
meta:set_int("enabled", 0)
|
||||||
|
set_formspec(meta, false)
|
||||||
|
minetest.get_node_timer(pos):stop()
|
||||||
|
meta:set_string("infotext", text or "paused Autocrafter")
|
||||||
|
elseif fields.off then
|
||||||
|
meta:set_int("enabled", 1)
|
||||||
|
set_formspec(meta, true)
|
||||||
|
start_crafter(pos)
|
||||||
|
else -- update formspec on esc for now
|
||||||
|
set_formspec(meta, meta:get_int("enabled") == 1)
|
||||||
|
end
|
||||||
|
end,
|
||||||
on_punch = update_autocrafter,
|
on_punch = update_autocrafter,
|
||||||
can_dig = function(pos, player)
|
can_dig = function(pos, player)
|
||||||
update_autocrafter(pos)
|
update_autocrafter(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user