From a98cf4b03d42d3836148da590bb0cde9f689037f Mon Sep 17 00:00:00 2001 From: cheapie Date: Sun, 2 Jan 2022 12:22:00 -0600 Subject: Add pulse gate Sends a mesecons signal of a fixed length (punch to adjust, like a delayer) when power is applied. Uses texture by numberZero from upstream #536 --- mesecons_gates/init.lua | 101 +++++++++++++++++++++ mesecons_gates/textures/jeija_gate_pulse.png | Bin 0 -> 122 bytes .../textures/mesecons_gates_pulse_setting_1.png | Bin 0 -> 4837 bytes .../textures/mesecons_gates_pulse_setting_2.png | Bin 0 -> 4817 bytes .../textures/mesecons_gates_pulse_setting_3.png | Bin 0 -> 4845 bytes .../textures/mesecons_gates_pulse_setting_4.png | Bin 0 -> 4832 bytes 6 files changed, 101 insertions(+) create mode 100644 mesecons_gates/textures/jeija_gate_pulse.png create mode 100644 mesecons_gates/textures/mesecons_gates_pulse_setting_1.png create mode 100644 mesecons_gates/textures/mesecons_gates_pulse_setting_2.png create mode 100644 mesecons_gates/textures/mesecons_gates_pulse_setting_3.png create mode 100644 mesecons_gates/textures/mesecons_gates_pulse_setting_4.png diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index c30f9f8..58872c8 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -165,3 +165,104 @@ register_gate("or", 2, function (val1, val2) return (val1 or val2) end, {"", "mesecons:mesecon", "mesecons:mesecon"}, {"mesecons:mesecon", "", ""}}, "OR Gate") + +local pulsetime = { 0.1, 0.3, 0.5, 1.0 } --Same as the delayer + +local function pulsegate_on(pos,node) + local basename = "mesecons_gates:pulse_" + if string.sub(node.name,1,#basename) ~= basename or string.sub(node.name,-2,-1) == "on" then + --Gate no longer exists or is already on + return + end + local delay = tonumber(string.sub(node.name,#basename+1,#basename+1)) + node.name = basename..delay.."_on" + minetest.swap_node(pos,node) + mesecon.receptor_on(pos,gate_get_output_rules(node)) + if delay and pulsetime[delay] then minetest.get_node_timer(pos):start(pulsetime[delay]) end +end + +local function pulsegate_off(pos) + local node = minetest.get_node(pos) + local basename = "mesecons_gates:pulse_" + if string.sub(node.name,1,#basename) ~= basename or string.sub(node.name,-3,-1) == "off" then + --Gate no longer exists or is already off + return + end + local delay = string.sub(node.name,#basename+1,#basename+1) + node.name = basename..delay.."_off" + minetest.swap_node(pos,node) + mesecon.receptor_off(pos,gate_get_output_rules(node)) +end + +for i=1,4,1 do + mesecon.register_node("mesecons_gates:pulse_"..i, { + description = "Logic Gate: Pulse", + inventory_image = "jeija_gate_off.png^jeija_gate_pulse.png", + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = false, + drawtype = "nodebox", + drop = "mesecons_gates:pulse_1_off", + selection_box = selection_box, + node_box = nodebox, + walkable = true, + sounds = default.node_sound_stone_defaults(), + onstate = "mesecons_gates:pulse_"..i.."_on", + offstate = "mesecons_gates:pulse_"..i.."_off", + after_dig_node = mesecon.do_cooldown, + },{ + tiles = { + "jeija_microcontroller_bottom.png^".."jeija_gate_off.png^".. + "jeija_gate_output_off.png^".."jeija_gate_pulse.png^".."mesecons_gates_pulse_setting_"..i..".png", + "jeija_microcontroller_bottom.png^".."jeija_gate_output_off.png^".. + "[transformFY", + "jeija_gate_side.png^".."jeija_gate_side_output_off.png", + "jeija_gate_side.png", + "jeija_gate_side.png", + "jeija_gate_side.png" + }, + on_punch = function(pos, node, puncher) + if minetest.is_protected(pos, puncher and puncher:get_player_name() or "") then + return + end + minetest.swap_node(pos, { + name = "mesecons_gates:pulse_"..tostring(i % 4 + 1).."_off", + param2 = node.param2 + }) + end, + groups = i == 1 and {dig_immediate = 2} or {dig_immediate = 2,not_in_creative_inventory = 1}, + mesecons = { receptor = { + state = "off", + rules = gate_get_output_rules + }, effector = { + rules = gate_get_input_rules_oneinput, + action_on = pulsegate_on, + }} + },{ + tiles = { + "jeija_microcontroller_bottom.png^".."jeija_gate_on.png^".. + "jeija_gate_output_on.png^".."jeija_gate_pulse.png^".."mesecons_gates_pulse_setting_"..i..".png", + "jeija_microcontroller_bottom.png^".."jeija_gate_output_on.png^".. + "[transformFY", + "jeija_gate_side.png^".."jeija_gate_side_output_on.png", + "jeija_gate_side.png", + "jeija_gate_side.png", + "jeija_gate_side.png" + }, + on_timer = pulsegate_off, + groups = {dig_immediate = 2, not_in_creative_inventory = 1}, + mesecons = { receptor = { + state = "on", + rules = gate_get_output_rules + }} + }) +end + +minetest.register_craft({ + output = "mesecons_gates:pulse_1_off", + recipe = { + {"group:mesecon_conductor_craftable","",""}, + {"mesecons_materials:silicon","mesecons_materials:silicon","group:mesecon_conductor_craftable"}, + {"group:mesecon_conductor_craftable","",""}, + }, +}) diff --git a/mesecons_gates/textures/jeija_gate_pulse.png b/mesecons_gates/textures/jeija_gate_pulse.png new file mode 100644 index 0000000..183ce4f Binary files /dev/null and b/mesecons_gates/textures/jeija_gate_pulse.png differ diff --git a/mesecons_gates/textures/mesecons_gates_pulse_setting_1.png b/mesecons_gates/textures/mesecons_gates_pulse_setting_1.png new file mode 100644 index 0000000..5c04ca1 Binary files /dev/null and b/mesecons_gates/textures/mesecons_gates_pulse_setting_1.png differ diff --git a/mesecons_gates/textures/mesecons_gates_pulse_setting_2.png b/mesecons_gates/textures/mesecons_gates_pulse_setting_2.png new file mode 100644 index 0000000..6f670d4 Binary files /dev/null and b/mesecons_gates/textures/mesecons_gates_pulse_setting_2.png differ diff --git a/mesecons_gates/textures/mesecons_gates_pulse_setting_3.png b/mesecons_gates/textures/mesecons_gates_pulse_setting_3.png new file mode 100644 index 0000000..67dc004 Binary files /dev/null and b/mesecons_gates/textures/mesecons_gates_pulse_setting_3.png differ diff --git a/mesecons_gates/textures/mesecons_gates_pulse_setting_4.png b/mesecons_gates/textures/mesecons_gates_pulse_setting_4.png new file mode 100644 index 0000000..0bee893 Binary files /dev/null and b/mesecons_gates/textures/mesecons_gates_pulse_setting_4.png differ -- cgit v1.2.3