Distributor filter command added

This commit is contained in:
Joachim Stolberg 2018-07-01 21:56:39 +02:00
parent e372cdccce
commit a01c14beff
3 changed files with 38 additions and 3 deletions

@ -94,6 +94,21 @@ sl_controller.register_action("send_cmnd", {
' example: $send_cmnd("1234", "on")' ' example: $send_cmnd("1234", "on")'
}) })
sl_controller.register_action("set_filter", {
cmnd = function(self, num, slot, val)
num = tostring(num or "")
slot = tostring(slot or "red")
val = tostring(val or "on")
tubelib.send_message(num, self.meta.owner, nil, "filter", {slot=slot, val=val})
end,
help = " $set_filter(num, slot, val)\n"..
' Turn on/off a Distributor filter slot.\n'..
" For more help, see:\n"..
" https://github.com/joe7575/techpack/wiki/nodes\n"..
' example: $set_filter("1234", "red", "off")'
})
sl_controller.register_action("display", { sl_controller.register_action("display", {
cmnd = function(self, num, row, text1, text2, text3) cmnd = function(self, num, row, text1, text2, text3)
text1 = tostring(text1 or "") text1 = tostring(text1 or "")

@ -92,9 +92,9 @@ minetest.register_node("sl_controller:server", {
minetest.register_craft({ minetest.register_craft({
output = "sl_controller:server", output = "sl_controller:server",
recipe = { recipe = {
{"", "", ""}, {"", "dye:black", ""},
{"default:mese_crystal_fragment", "tubelib:wlanchip", "default:mese_crystal_fragment"}, {"default:mese_crystal", "tubelib:wlanchip", "default:mese_crystal"},
{"", "default:copper_ingot", ""}, {"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"},
}, },
}) })

@ -311,6 +311,24 @@ local function on_receive_fields(pos, formname, fields, player)
end end
end end
-- tubelib command to turn on/off filter channels
local function change_filter_settings(pos, slot, val)
local slots = {["red"] = 1, ["green"] = 2, ["blue"] = 3, ["yellow"] = 4}
local meta = minetest.get_meta(pos)
local filter = minetest.deserialize(meta:get_string("filter"))
local num = slots[slot] or 1
if num >= 1 and num <= 4 then
filter[num] = val == "on"
end
meta:set_string("filter", minetest.serialize(filter))
filter_settings(pos)
local running = meta:get_int("running")
meta:set_string("formspec", distributor_formspec(tubelib.state(running), filter))
return true
end
minetest.register_node("tubelib:distributor", { minetest.register_node("tubelib:distributor", {
description = "Tubelib Distributor", description = "Tubelib Distributor",
tiles = { tiles = {
@ -442,6 +460,8 @@ tubelib.register_node("tubelib:distributor", {"tubelib:distributor_active"}, {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local running = meta:get_int("running") local running = meta:get_int("running")
return tubelib.statestring(running) return tubelib.statestring(running)
elseif topic == "filter" then
return change_filter_settings(pos, payload.slot, payload.val)
else else
return "unsupported" return "unsupported"
end end