From a285363c924bf55cac6fcace5f15f774e0f8ae71 Mon Sep 17 00:00:00 2001 From: OgelGames Date: Sun, 24 Jan 2021 17:55:47 +1100 Subject: [PATCH] add limiter, simplify filter code --- README.md | 4 +-- filter.lua | 16 +++------ init.lua | 2 +- limiter.lua | 58 +++++++++++++++++++++++++++++++ textures/digicontrol_limiter.png | Bin 0 -> 10006 bytes 5 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 limiter.lua create mode 100644 textures/digicontrol_limiter.png 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 0000000000000000000000000000000000000000..7546bef0c59147730e325ff2b0dc13a9bbd36bef GIT binary patch literal 10006 zcmd^lc~nzbvu_;&B#Z$CiHzx1fo?@X5eKH&ia4~23ZgQDg31&{24%?U7C}Y887Bl= zMHHD-WDYc=q5>-OoCX0I!x+Zo?SuAxU*G$^zTdlRy|vz2U;fBR_O4x3d+%RW?W%pw zo9#4}5?2%l0I988HthirLO+FoLOlExHzoq8H*ejv!Q8K*zxn(f`OneaLzAt}173q2 z>N*h-yW2xF+meJ=s~@xe-mm)jd8>;T{F`**DMI3-Eq#^mYx=@tV<|i8gctLcxUa9< zKDN%g$I!yNylcAZss<^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