Add mesecons checkbox for quarry

This commit is contained in:
SX 2022-07-19 18:41:52 +03:00 committed by Buckaroo Banzai
parent 2ebb2172d9
commit 6e12a05748

View File

@ -20,9 +20,12 @@ local quarry_formspec =
"label[0,0;"..machine_name.."]".. "label[0,0;"..machine_name.."]"..
"button[6,0.9;2,1;restart;"..S("Restart").."]" "button[6,0.9;2,1;restart;"..S("Restart").."]"
local mesecons_checkbox = minetest.get_modpath("mesecons")
and function(state) return "checkbox[4.3,3.9;mesecons;"..S("Controlled by Mesecon Signal")..";"..state.."]" end
or function() return "" end
if has_digilines then if has_digilines then
quarry_formspec = quarry_formspec quarry_formspec = quarry_formspec .. "field[4.3,3.4;4,1;channel;Channel;${channel}]"
.. "field[4.3,3.4;4,1;channel;Channel;${channel}]"
end end
-- hard-coded spiral dig pattern for up to 17x17 dig area -- hard-coded spiral dig pattern for up to 17x17 dig area
@ -106,6 +109,7 @@ local function set_quarry_status(pos)
meta:set_string("infotext", S("@1 Disabled", machine_name)) meta:set_string("infotext", S("@1 Disabled", machine_name))
meta:set_int("HV_EU_demand", 0) meta:set_int("HV_EU_demand", 0)
end end
formspec = formspec .. mesecons_checkbox(meta:get("mesecons") or "true")
meta:set_string("formspec", formspec.."label[0,4.1;"..minetest.formspec_escape(status).."]") meta:set_string("formspec", formspec.."label[0,4.1;"..minetest.formspec_escape(status).."]")
end end
@ -134,6 +138,9 @@ local function quarry_receive_fields(pos, formname, fields, sender)
end end
end end
if fields.mesecons then
meta:set_string("mesecons", fields.mesecons == "false" and "false" or "")
end
if fields.channel then if fields.channel then
meta:set_string("channel", fields.channel) meta:set_string("channel", fields.channel)
end end
@ -523,13 +530,17 @@ minetest.register_node("technic:quarry", {
effector = { effector = {
action_on = function(pos) action_on = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("enabled", 1) if meta:get("mesecons") ~= "false" then
set_quarry_status(pos) meta:set_int("enabled", 1)
set_quarry_status(pos)
end
end, end,
action_off = function(pos) action_off = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("enabled", 0) if meta:get("mesecons") ~= "false" then
set_quarry_status(pos) meta:set_int("enabled", 0)
set_quarry_status(pos)
end
end end
} }
}, },