diff --git a/README.md b/README.md index b9a6e87..a6728bc 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ Adds nodes to control the flow of digiline messages. ## TODO -- limiter and router +- router (sorting tube for digiline messages) - crossing and double corner insulated wires - compatibility for replacing `digiline_routing` - craft recipes -- isulated wires from `digistuff` (when not installed) +- insulated wires from `digistuff` (when not installed) ## License diff --git a/filter.lua b/filter.lua index b4416e5..7f38589 100644 --- a/filter.lua +++ b/filter.lua @@ -28,19 +28,13 @@ minetest.register_node("digicontrol:filter", { end, digiline = { semiconductor = { - rules = function(node, pos, from, channel) + rules = function(node, pos, _, channel) local setchannel = minetest.get_meta(pos):get_string("channel") if channel ~= setchannel then return {} end - local side = digicontrol.get_side(pos, from, node.param2) - if side == 3 then - return { - digicontrol.get_rule(1, node.param2) - } - else - return { - digicontrol.get_rule(3, node.param2) - } - end + return { + digicontrol.get_rule(1, node.param2), + digicontrol.get_rule(3, node.param2) + } end }, wire = { diff --git a/init.lua b/init.lua index 595564f..00d044d 100644 --- a/init.lua +++ b/init.lua @@ -45,5 +45,5 @@ dofile(MP.."/diode.lua") dofile(MP.."/splitter.lua") dofile(MP.."/trisplitter.lua") dofile(MP.."/filter.lua") ---dofile(MP.."/limiter.lua") +dofile(MP.."/limiter.lua") --dofile(MP.."/router.lua") diff --git a/limiter.lua b/limiter.lua new file mode 100644 index 0000000..6e7f39a --- /dev/null +++ b/limiter.lua @@ -0,0 +1,58 @@ + +minetest.register_node("digicontrol:limiter", { + description = "Digilines Limiter", + inventory_image = "digicontrol_limiter.png", + tiles = { + "digicontrol_limiter.png", + "digicontrol_bottom.png", + "digicontrol_side_port.png", + "digicontrol_side_port.png", + "digicontrol_side.png", + "digicontrol_side.png" + }, + drawtype = "nodebox", + node_box = digicontrol.node_box, + selection_box = digicontrol.selection_box, + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = false, + groups = {digicontrol = 1, dig_immediate = 2}, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", "field[limit;Message Limit (messages/second);${limit}]") + meta:set_string("limit", "1") + end, + on_receive_fields = function(pos, _, fields, sender) + if minetest.is_protected(pos, sender:get_player_name()) then return end + if fields.limit then + local limit = tonumber(fields.limit) + if limit then + minetest.get_meta(pos):set_string("limit", math.min(limit, 10)) + end + end + end, + digiline = { + semiconductor = { + rules = function(node, pos) + local timer = minetest.get_node_timer(pos) + local limit = tonumber(minetest.get_meta(pos):get_string("limit")) + if not limit or limit == 0 or timer:is_started() then return {} end + if limit > 0 then + timer:start(1 / limit) + end + return { + digicontrol.get_rule(1, node.param2), + digicontrol.get_rule(3, node.param2) + } + end + }, + wire = { + rules = function(node) + return { + digicontrol.get_rule(1, node.param2), + digicontrol.get_rule(3, node.param2) + } + end + } + } +}) diff --git a/textures/digicontrol_limiter.png b/textures/digicontrol_limiter.png new file mode 100644 index 0000000..7546bef Binary files /dev/null and b/textures/digicontrol_limiter.png differ