From 4eea0834b5c2a772381eee3520c55e4f5cc42440 Mon Sep 17 00:00:00 2001 From: DS Date: Sun, 30 Jan 2022 01:23:05 +0100 Subject: [PATCH 01/10] Fix torch rules (#581) --- mesecons_torch/init.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mesecons_torch/init.lua b/mesecons_torch/init.lua index 867c909..bbb8da5 100644 --- a/mesecons_torch/init.lua +++ b/mesecons_torch/init.lua @@ -27,9 +27,13 @@ local torch_get_output_rules = function(node) return rotate_torch_rules(rules, node.param2) end +local torch_input_rules_unrotated_horizontal = {vector.new(-2, 0, 0), vector.new(-1, 1, 0)} +local torch_input_rules_unrotated_vertical = {vector.new(-2, 0, 0)} + local torch_get_input_rules = function(node) - local rules = {{x = -2, y = 0, z = 0}, - {x = -1, y = 1, z = 0}} + local rules = (node.param2 == 0 or node.param2 == 1) + and torch_input_rules_unrotated_vertical + or torch_input_rules_unrotated_horizontal return rotate_torch_rules(rules, node.param2) end From 4c5b13a3473b970b639e7e63e4a09adfc7abcfe4 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sat, 29 Jan 2022 19:23:53 -0500 Subject: [PATCH 02/10] Fix conductor lighting when aliases are used (#582) --- mesecons/internal.lua | 11 ++--------- mesecons/util.lua | 16 ++++++++-------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/mesecons/internal.lua b/mesecons/internal.lua index 165c001..a584092 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -372,7 +372,6 @@ end local light_update_conductors -- Calculate the contents of the above set if they have not been calculated. --- This must be called before get_update_light_conductor. local function find_light_update_conductors() -- The expensive calculation is only done the first time. if light_update_conductors then return end @@ -415,12 +414,6 @@ local function find_light_update_conductors() end end --- This is the callback for swap_node_force in turnon and turnoff. It determines --- whether a conductor node necessitates a lighting update. -local function get_update_light_conductor(pos, name) - return light_update_conductors[name] ~= nil -end - -- Turn off an equipotential section starting at `pos`, which outputs in the direction of `link`. -- Breadth-first search. Map is abstracted away in a voxelmanip. -- Follow all all conductor paths replacing conductors that were already @@ -453,7 +446,7 @@ function mesecon.turnon(pos, link) end end - mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link), get_update_light_conductor) + mesecon.swap_node_force(f.pos, mesecon.get_conductor_on(node, f.link), light_update_conductors[node.name] ~= nil) end -- Only conductors with flat rules can be reliably skipped later @@ -527,7 +520,7 @@ function mesecon.turnoff(pos, link) end end - mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link), get_update_light_conductor) + mesecon.swap_node_force(f.pos, mesecon.get_conductor_off(node, f.link), light_update_conductors[node.name] ~= nil) end -- Only conductors with flat rules can be reliably skipped later diff --git a/mesecons/util.lua b/mesecons/util.lua index 7fb95cc..2e21a2e 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -389,10 +389,10 @@ end -- -- Existing param1, param2, and metadata are left alone. -- --- See mesecon.swap_node_force for documentation about get_update_light. -function mesecon.vm_swap_node(pos, name, get_update_light) +-- The swap will necessitate a light update unless update_light equals false. +function mesecon.vm_swap_node(pos, name, update_light) local tbl = vm_get_or_create_entry(pos) - tbl.update_light = tbl.update_light or (get_update_light == nil or get_update_light(pos, name)) + tbl.update_light = update_light ~= false or tbl.update_light local index = tbl.va:indexp(pos) tbl.data[index] = minetest.get_content_id(name) tbl.dirty = true @@ -426,15 +426,15 @@ end -- Outside a VM transaction, if the mapblock is not loaded, it is pulled into -- the server’s main map data cache and then accessed from there. -- --- Inside a VM transaction, the transaction’s VM cache is used. If a third --- argument is supplied, it may be called. If it returns false, the swap does --- not necessitate a lighting update. +-- Inside a VM transaction, the transaction’s VM cache is used. -- -- This function can only be used to change the node’s name, not its parameters -- or metadata. -function mesecon.swap_node_force(pos, name, get_update_light) +-- +-- The swap will necessitate a light update unless update_light equals false. +function mesecon.swap_node_force(pos, name, update_light) if vm_cache then - return mesecon.vm_swap_node(pos, name, get_update_light) + return mesecon.vm_swap_node(pos, name, update_light) else -- This serves to both ensure the mapblock is loaded and also hand us -- the old node table so we can preserve param2. From c9dd323207d7a4c6523b57022ea1b74a474fe165 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sat, 12 Feb 2022 14:11:26 -0500 Subject: [PATCH 03/10] Remove redundant on_placenode calls after movement (#586) --- mesecons_mvps/init.lua | 6 ++---- mesecons_pistons/init.lua | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua index 3792d26..2bec69b 100644 --- a/mesecons_mvps/init.lua +++ b/mesecons_mvps/init.lua @@ -47,10 +47,8 @@ local function on_mvps_move(moved_nodes) end function mesecon.mvps_process_stack(stack) - -- update mesecons for placed nodes ( has to be done after all nodes have been added ) - for _, n in ipairs(stack) do - mesecon.on_placenode(n.pos, minetest.get_node(n.pos)) - end + -- This function is kept for compatibility. + -- It used to call on_placenode on the moved nodes, but that is now done automatically. end -- tests if the node can be pushed into, e.g. air, water, grass diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index 66c74b2..dad70e3 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -93,7 +93,6 @@ local piston_on = function(pos, node) minetest.swap_node(pos, {param2 = node.param2, name = pistonspec.onname}) minetest.set_node(pusher_pos, {param2 = node.param2, name = pistonspec.pusher}) minetest.sound_play("piston_extend", { pos = pos, max_hear_distance = 20, gain = 0.3 }, true) - mesecon.mvps_process_stack(stack) mesecon.mvps_move_objects(pusher_pos, dir, oldstack) end From fb255d292ec2355b91a0a36a3f984bc109912a69 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sat, 12 Feb 2022 14:12:12 -0500 Subject: [PATCH 04/10] Add .luacheckrc and fix issues it pointed out (#589) --- .github/workflows/check-release.yml | 15 ++++++++++++ .luacheckrc | 36 +++++++++++++++++++++++++++++ mesecons/actionqueue.lua | 12 +++++----- mesecons/internal.lua | 4 ++-- mesecons/legacy.lua | 2 +- mesecons/oldwires.lua | 2 +- mesecons/services.lua | 2 +- mesecons/util.lua | 6 ++--- mesecons_blinkyplant/init.lua | 2 +- mesecons_commandblock/init.lua | 2 +- mesecons_detector/init.lua | 23 +++--------------- mesecons_doors/init.lua | 12 +++++----- mesecons_extrawires/crossover.lua | 30 +++++++++++------------- mesecons_extrawires/vertical.lua | 2 +- mesecons_fpga/init.lua | 6 ++--- mesecons_fpga/logic.lua | 4 ++-- mesecons_gates/init.lua | 1 - mesecons_hydroturbine/init.lua | 4 ++-- mesecons_luacontroller/init.lua | 19 +++++++-------- mesecons_materials/init.lua | 6 ++--- mesecons_microcontroller/init.lua | 30 +++++++++++------------- mesecons_movestones/init.lua | 6 ++--- mesecons_mvps/init.lua | 1 - mesecons_pistons/init.lua | 30 ++++-------------------- mesecons_powerplant/init.lua | 2 +- mesecons_pressureplates/init.lua | 4 +--- mesecons_random/init.lua | 2 +- mesecons_receiver/init.lua | 6 ++--- mesecons_stickyblocks/init.lua | 2 +- mesecons_wires/init.lua | 4 ++-- 30 files changed, 141 insertions(+), 136 deletions(-) create mode 100644 .github/workflows/check-release.yml create mode 100644 .luacheckrc diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml new file mode 100644 index 0000000..d43987a --- /dev/null +++ b/.github/workflows/check-release.yml @@ -0,0 +1,15 @@ +on: [push, pull_request] +name: Check & Release + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@main + - name: apt + run: sudo apt-get install -y luarocks + - name: luacheck install + run: luarocks install --local luacheck + - name: luacheck run + run: $HOME/.luarocks/bin/luacheck ./ diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..c8cccda --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,36 @@ +std = "lua51c" + +ignore = { + "21/_+", -- Unused variable, except "_", "__", etc. + "213", -- Unused loop variable + "421", -- Shadowing a local variable + "422", -- Shadowing an argument + "423", -- Shadowing a loop variable + "431", -- Shadowing an upvalue + "432", -- Shadowing an upvalue argument + "433", -- Shadowing an upvalue loop variable + "542", -- Empty if branch +} + +max_line_length = 200 + +read_globals = { + "default", + "digiline", + "doors", + "dump", + "jit", + "minetest", + "screwdriver", + "string.split", + "table.copy", + "table.insert_all", + "vector", + "VoxelArea", +} + +globals = {"mesecon"} + +files["mesecons/actionqueue.lua"] = { + globals = {"minetest.registered_globalsteps"}, +} diff --git a/mesecons/actionqueue.lua b/mesecons/actionqueue.lua index 5508095..72b464d 100644 --- a/mesecons/actionqueue.lua +++ b/mesecons/actionqueue.lua @@ -29,7 +29,7 @@ local queue = mesecon.queue queue.actions = {} -- contains all ActionQueue actions function queue:add_function(name, func) - queue.funcs[name] = func + self.funcs[name] = func end -- If add_action with twice the same overwritecheck and same position are called, the first one is overwritten @@ -51,17 +51,17 @@ function queue:add_action(pos, func, params, time, overwritecheck, priority) -- check if old action has to be overwritten / removed: if overwritecheck then - for i, ac in ipairs(queue.actions) do + for i, ac in ipairs(self.actions) do if vector.equals(pos, ac.pos) and mesecon.cmpAny(overwritecheck, ac.owcheck) then -- remove the old action - table.remove(queue.actions, i) + table.remove(self.actions, i) break end end end - table.insert(queue.actions, action) + table.insert(self.actions, action) end -- execute the stored functions on a globalstep @@ -133,8 +133,8 @@ end function queue:execute(action) -- ignore if action queue function name doesn't exist, -- (e.g. in case the action queue savegame was written by an old mesecons version) - if queue.funcs[action.func] then - queue.funcs[action.func](action.pos, unpack(action.params)) + if self.funcs[action.func] then + self.funcs[action.func](action.pos, unpack(action.params)) end end diff --git a/mesecons/internal.lua b/mesecons/internal.lua index a584092..e6d20e4 100644 --- a/mesecons/internal.lua +++ b/mesecons/internal.lua @@ -318,7 +318,7 @@ function mesecon.get_conductor_on(node_off, rulename) return conductor.states[tonumber(binstate,2)+1] end end - return offstate + return nil end function mesecon.get_conductor_off(node_on, rulename) @@ -334,7 +334,7 @@ function mesecon.get_conductor_off(node_on, rulename) return conductor.states[tonumber(binstate,2)+1] end end - return onstate + return nil end function mesecon.conductor_get_rules(node) diff --git a/mesecons/legacy.lua b/mesecons/legacy.lua index ad7093a..2a8eae6 100644 --- a/mesecons/legacy.lua +++ b/mesecons/legacy.lua @@ -11,4 +11,4 @@ local old_forceloaded_blocks = mesecon.file2table("mesecon_forceloaded") for hash, _ in pairs(old_forceloaded_blocks) do minetest.forceload_free_block(unhash_blockpos(hash)) end -os.remove(minetest.get_worldpath()..DIR_DELIM.."mesecon_forceloaded") +os.remove(minetest.get_worldpath().."/mesecon_forceloaded") diff --git a/mesecons/oldwires.lua b/mesecons/oldwires.lua index 8d6c6b1..28dd4ec 100644 --- a/mesecons/oldwires.lua +++ b/mesecons/oldwires.lua @@ -11,7 +11,7 @@ minetest.register_node("mesecons:mesecon_off", { fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}, }, groups = {dig_immediate=3, mesecon=1, mesecon_conductor_craftable=1}, - description="Mesecons", + description="Mesecons", mesecons = {conductor={ state = mesecon.state.off, onstate = "mesecons:mesecon_on" diff --git a/mesecons/services.lua b/mesecons/services.lua index cd47b0a..58e57b5 100644 --- a/mesecons/services.lua +++ b/mesecons/services.lua @@ -63,7 +63,7 @@ mesecon.on_dignode = function(pos, node) mesecon.execute_autoconnect_hooks_queue(pos, node) end -function mesecon.on_blastnode(pos, intensity) +function mesecon.on_blastnode(pos) local node = minetest.get_node(pos) minetest.remove_node(pos) mesecon.on_dignode(pos, node) diff --git a/mesecons/util.lua b/mesecons/util.lua index 2e21a2e..5215e8c 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -286,7 +286,7 @@ end -- File writing / reading utilities local wpath = minetest.get_worldpath() function mesecon.file2table(filename) - local f = io.open(wpath..DIR_DELIM..filename, "r") + local f = io.open(wpath.."/"..filename, "r") if f == nil then return {} end local t = f:read("*all") f:close() @@ -295,7 +295,7 @@ function mesecon.file2table(filename) end function mesecon.table2file(filename, table) - local f = io.open(wpath..DIR_DELIM..filename, "w") + local f = io.open(wpath.."/"..filename, "w") f:write(minetest.serialize(table)) f:close() end @@ -376,7 +376,7 @@ function mesecon.vm_get_node(pos) local tbl = vm_get_or_create_entry(pos) local index = tbl.va:indexp(pos) local node_value = tbl.data[index] - if node_value == core.CONTENT_IGNORE then + if node_value == minetest.CONTENT_IGNORE then return nil else local node_param1 = tbl.param1[index] diff --git a/mesecons_blinkyplant/init.lua b/mesecons_blinkyplant/init.lua index 80b6b7e..4e46750 100644 --- a/mesecons_blinkyplant/init.lua +++ b/mesecons_blinkyplant/init.lua @@ -32,7 +32,7 @@ mesecon.register_node("mesecons_blinkyplant:blinky_plant", { fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3}, }, on_timer = on_timer, - on_rightclick = function(pos, node, clicker) + on_rightclick = function(pos, _, clicker) if minetest.is_protected(pos, clicker and clicker:get_player_name() or "") then return end diff --git a/mesecons_commandblock/init.lua b/mesecons_commandblock/init.lua index f8acce8..fbab54b 100644 --- a/mesecons_commandblock/init.lua +++ b/mesecons_commandblock/init.lua @@ -79,7 +79,7 @@ local function after_place(pos, placer) end end -local function receive_fields(pos, formname, fields, sender) +local function receive_fields(pos, _, fields, sender) if not fields.submit then return end diff --git a/mesecons_detector/init.lua b/mesecons_detector/init.lua index 1234378..0a97684 100644 --- a/mesecons_detector/init.lua +++ b/mesecons_detector/init.lua @@ -12,7 +12,7 @@ local function object_detector_make_formspec(pos) "button_exit[7,0.75;2,3;;Save]") end -local function object_detector_on_receive_fields(pos, formname, fields, sender) +local function object_detector_on_receive_fields(pos, _, fields, sender) if not fields.scanname or not fields.digiline_channel then return end if minetest.is_protected(pos, sender:get_player_name()) then return end @@ -53,7 +53,7 @@ end -- set player name when receiving a digiline signal on a specific channel local object_detector_digiline = { effector = { - action = function(pos, node, channel, msg) + action = function(pos, _, channel, msg) local meta = minetest.get_meta(pos) if channel == meta:get_string("digiline_channel") then meta:set_string("scanname", msg) @@ -156,7 +156,7 @@ local function node_detector_make_formspec(pos) "button_exit[7,0.75;2,3;;Save]") end -local function node_detector_on_receive_fields(pos, fieldname, fields, sender) +local function node_detector_on_receive_fields(pos, _, fields, sender) if not fields.scanname or not fields.digiline_channel then return end if minetest.is_protected(pos, sender:get_player_name()) then return end @@ -238,23 +238,6 @@ local node_detector_digiline = { receptor = {} } -local function after_place_node_detector(pos, placer) - local placer_pos = placer:get_pos() - if not placer_pos then - return - end - - --correct for the player's height - if placer:is_player() then - placer_pos.y = placer_pos.y + 1.625 - end - - --correct for 6d facedir - local node = minetest.get_node(pos) - node.param2 = minetest.dir_to_facedir(vector.subtract(pos, placer_pos), true) - minetest.set_node(pos, node) -end - minetest.register_node("mesecons_detector:node_detector_off", { tiles = {"default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "jeija_node_detector_off.png"}, paramtype = "light", diff --git a/mesecons_doors/init.lua b/mesecons_doors/init.lua index 0f7bea7..3b0a36b 100644 --- a/mesecons_doors/init.lua +++ b/mesecons_doors/init.lua @@ -22,11 +22,11 @@ end local function meseconify_door(name) if minetest.registered_items[name .. "_b_1"] then -- old style double-node doors - local function toggle_state1 (pos, node) + local function toggle_state1 (pos) on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) end - local function toggle_state2 (pos, node) + local function toggle_state2 (pos) on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) end @@ -49,13 +49,13 @@ local function meseconify_door(name) -- new style mesh node based doors local override = { mesecons = {effector = { - action_on = function(pos, node) + action_on = function(pos) local door = doors.get(pos) if door then door:open() end end, - action_off = function(pos, node) + action_off = function(pos) local door = doors.get(pos) if door then door:close() @@ -93,13 +93,13 @@ end if doors and doors.get then local override = { mesecons = {effector = { - action_on = function(pos, node) + action_on = function(pos) local door = doors.get(pos) if door then door:open() end end, - action_off = function(pos, node) + action_off = function(pos) local door = doors.get(pos) if door then door:close() diff --git a/mesecons_extrawires/crossover.lua b/mesecons_extrawires/crossover.lua index 2656d61..1164955 100644 --- a/mesecons_extrawires/crossover.lua +++ b/mesecons_extrawires/crossover.lua @@ -1,15 +1,13 @@ -local function crossover_get_rules(node) - return { - {--first wire - {x=-1,y=0,z=0}, - {x=1,y=0,z=0}, - }, - {--second wire - {x=0,y=0,z=-1}, - {x=0,y=0,z=1}, - }, - } -end +local crossover_rules = { + {--first wire + {x=-1,y=0,z=0}, + {x=1,y=0,z=0}, + }, + {--second wire + {x=0,y=0,z=-1}, + {x=0,y=0,z=1}, + }, +} local crossover_states = { "mesecons_extrawires:crossover_off", @@ -38,7 +36,7 @@ minetest.register_node("mesecons_extrawires:crossover_off", { mesecons = { conductor = { states = crossover_states, - rules = crossover_get_rules(), + rules = crossover_rules, } }, on_blast = mesecon.on_blastnode, @@ -65,7 +63,7 @@ minetest.register_node("mesecons_extrawires:crossover_01", { mesecons = { conductor = { states = crossover_states, - rules = crossover_get_rules(), + rules = crossover_rules, } }, on_blast = mesecon.on_blastnode, @@ -92,7 +90,7 @@ minetest.register_node("mesecons_extrawires:crossover_10", { mesecons = { conductor = { states = crossover_states, - rules = crossover_get_rules(), + rules = crossover_rules, } }, on_blast = mesecon.on_blastnode, @@ -119,7 +117,7 @@ minetest.register_node("mesecons_extrawires:crossover_on", { mesecons = { conductor = { states = crossover_states, - rules = crossover_get_rules(), + rules = crossover_rules, } }, on_blast = mesecon.on_blastnode, diff --git a/mesecons_extrawires/vertical.lua b/mesecons_extrawires/vertical.lua index 52f2b6a..bdd77a7 100644 --- a/mesecons_extrawires/vertical.lua +++ b/mesecons_extrawires/vertical.lua @@ -69,7 +69,7 @@ local vertical_updatepos = function (pos) end end -local vertical_update = function (pos, node) +local vertical_update = function (pos) vertical_updatepos(pos) -- this one vertical_updatepos(vector.add(pos, vertical_rules[1])) -- above vertical_updatepos(vector.add(pos, vertical_rules[2])) -- below diff --git a/mesecons_fpga/init.lua b/mesecons_fpga/init.lua index 6ba8f80..d8849f3 100644 --- a/mesecons_fpga/init.lua +++ b/mesecons_fpga/init.lua @@ -96,7 +96,7 @@ plg.register_nodes({ meta:set_int("valid", 0) meta:set_string("infotext", "FPGA") end, - on_rightclick = function(pos, node, clicker) + on_rightclick = function(pos, _, clicker) if not minetest.is_player(clicker) then return end @@ -113,7 +113,7 @@ plg.register_nodes({ mesecons = { effector = { rules = {}, -- replaced later - action_change = function(pos, node, rule, newstate) + action_change = function(pos, _, rule, newstate) plg.ports_changed(pos, rule, newstate) plg.update(pos) end @@ -129,7 +129,7 @@ plg.register_nodes({ end end, on_blast = mesecon.on_blastnode, - on_rotate = function(pos, node, user, mode) + on_rotate = function(pos, _, user, mode) local abcd1 = {"A", "B", "C", "D"} local abcd2 = {A = 1, B = 2, C = 3, D = 4} local ops = {"op1", "op2", "dst"} diff --git a/mesecons_fpga/logic.lua b/mesecons_fpga/logic.lua index 106f779..0e268a2 100644 --- a/mesecons_fpga/logic.lua +++ b/mesecons_fpga/logic.lua @@ -10,10 +10,10 @@ local operations = { -- unary: Whether this gate only has one input { gate = "and", short = "&", fs_name = " AND", func = function(a, b) return a and b end }, { gate = "or", short = "|", fs_name = " OR", func = function(a, b) return a or b end }, - { gate = "not", short = "~", fs_name = " NOT", func = function(a, b) return not b end, unary = true }, + { gate = "not", short = "~", fs_name = " NOT", func = function(_, b) return not b end, unary = true }, { gate = "xor", short = "^", fs_name = " XOR", func = function(a, b) return a ~= b end }, { gate = "nand", short = "?", fs_name = "NAND", func = function(a, b) return not (a and b) end }, - { gate = "buf", short = "_", fs_name = " =", func = function(a, b) return b end, unary = true }, + { gate = "buf", short = "_", fs_name = " =", func = function(_, b) return b end, unary = true }, { gate = "xnor", short = "=", fs_name = "XNOR", func = function(a, b) return a == b end }, { gate = "nor", short = "!", fs_name = " NOR", func = function(a, b) return not (a or b) end }, } diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index c30f9f8..d6ecb3c 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -65,7 +65,6 @@ end local function register_gate(name, inputnumber, assess, recipe, description) local get_inputrules = inputnumber == 2 and gate_get_input_rules_twoinputs or gate_get_input_rules_oneinput - description = "Logic Gate: "..name local basename = "mesecons_gates:"..name mesecon.register_node(basename, { diff --git a/mesecons_hydroturbine/init.lua b/mesecons_hydroturbine/init.lua index afc7434..71cf805 100644 --- a/mesecons_hydroturbine/init.lua +++ b/mesecons_hydroturbine/init.lua @@ -72,7 +72,7 @@ minetest.register_abm({ nodenames = {"mesecons_hydroturbine:hydro_turbine_off"}, interval = 1, chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) + action = function(pos) local waterpos={x=pos.x, y=pos.y+1, z=pos.z} if is_flowing_water(waterpos) then minetest.set_node(pos, {name="mesecons_hydroturbine:hydro_turbine_on"}) @@ -85,7 +85,7 @@ minetest.register_abm({ nodenames = {"mesecons_hydroturbine:hydro_turbine_on"}, interval = 1, chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) + action = function(pos) local waterpos={x=pos.x, y=pos.y+1, z=pos.z} if not is_flowing_water(waterpos) then minetest.set_node(pos, {name="mesecons_hydroturbine:hydro_turbine_off"}) diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua index 1c411dd..f00ea93 100644 --- a/mesecons_luacontroller/init.lua +++ b/mesecons_luacontroller/init.lua @@ -60,7 +60,7 @@ local function update_real_port_states(pos, rule_name, new_state) if rule_name.x == nil then for _, rname in ipairs(rule_name) do local port = pos_to_side[rname.x + (2 * rname.z) + 3] - L[port] = (newstate == "on") and 1 or 0 + L[port] = (new_state == "on") and 1 or 0 end else local port = pos_to_side[rule_name.x + (2 * rule_name.z) + 3] @@ -172,7 +172,7 @@ local function burn_controller(pos) minetest.after(0.2, mesecon.receptor_off, pos, mesecon.rules.flat) end -local function overheat(pos, meta) +local function overheat(pos) if mesecon.do_overheat(pos) then -- If too hot burn_controller(pos) return true @@ -612,9 +612,8 @@ local function run_inner(pos, code, event) if overheat(pos) then return true, "" end if ignore_event(event, meta) then return true, "" end - -- Load code & mem from meta + -- Load mem from meta local mem = load_memory(meta) - local code = meta:get_string("code") -- 'Last warning' label. local warning = "" @@ -626,15 +625,17 @@ local function run_inner(pos, code, event) local itbl = {} local env = create_environment(pos, mem, event, itbl, send_warning) + local success, msg -- Create the sandbox and execute code - local f, msg = create_sandbox(code, env) + local f + f, msg = create_sandbox(code, env) if not f then return false, msg end -- Start string true sandboxing local onetruestring = getmetatable("") -- If a string sandbox is already up yet inconsistent, something is very wrong assert(onetruestring.__index == string) onetruestring.__index = env.string - local success, msg = pcall(f) + success, msg = pcall(f) onetruestring.__index = string -- End string true sandboxing if not success then return false, msg end @@ -748,7 +749,7 @@ local selection_box = { local digiline = { receptor = {}, effector = { - action = function(pos, node, channel, msg) + action = function(pos, _, channel, msg) msg = clean_and_weigh_digiline_message(msg) run(pos, {type = "digiline", channel = channel, msg = msg}) end @@ -766,7 +767,7 @@ local function set_program(pos, code) return run(pos, {type="program"}) end -local function on_receive_fields(pos, form_name, fields, sender) +local function on_receive_fields(pos, _, fields, sender) if not fields.program then return end @@ -871,7 +872,7 @@ for d = 0, 1 do c = c == 1, d = d == 1, }, - after_dig_node = function (pos, node) + after_dig_node = function (pos) mesecon.do_cooldown(pos) mesecon.receptor_off(pos, output_rules) end, diff --git a/mesecons_materials/init.lua b/mesecons_materials/init.lua index eb19c3e..f3aa01f 100644 --- a/mesecons_materials/init.lua +++ b/mesecons_materials/init.lua @@ -2,13 +2,13 @@ minetest.register_craftitem("mesecons_materials:glue", { image = "mesecons_glue.png", on_place_on_ground = minetest.craftitem_place_item, - description="Glue", + description="Glue", }) minetest.register_craftitem("mesecons_materials:fiber", { image = "mesecons_fiber.png", on_place_on_ground = minetest.craftitem_place_item, - description="Fiber", + description="Fiber", }) minetest.register_craft({ @@ -29,7 +29,7 @@ minetest.register_craft({ minetest.register_craftitem("mesecons_materials:silicon", { image = "mesecons_silicon.png", on_place_on_ground = minetest.craftitem_place_item, - description="Silicon", + description="Silicon", }) minetest.register_craft({ diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index f9ba979..89b0953 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -102,7 +102,7 @@ minetest.register_node(nodename, { for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0" meta:set_string("eeprom", r) end, - on_receive_fields = function(pos, formanme, fields, sender) + on_receive_fields = function(pos, _, fields, sender) local player_name = sender:get_player_name() if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(player_name, {protection_bypass=true}) then @@ -225,7 +225,6 @@ yc.parsecode = function(code, pos) local Lreal = yc.get_real_portstates(pos) local Lvirtual = yc.get_virtual_portstates(pos) if Lvirtual == nil then return nil end - local c local eeprom = meta:get_string("eeprom") while true do local command, params @@ -251,9 +250,9 @@ yc.parsecode = function(code, pos) if not params then return nil end end if command == "on" then - L = yc.command_on (params, Lvirtual) + Lvirtual = yc.command_on (params, Lvirtual) elseif command == "off" then - L = yc.command_off(params, Lvirtual) + Lvirtual = yc.command_off(params, Lvirtual) elseif command == "print" then local su = yc.command_print(params, eeprom, yc.merge_portstates(Lreal, Lvirtual)) if su ~= true then return nil end @@ -384,7 +383,6 @@ end --Commands yc.command_on = function(params, L) - local rules = {} for i, port in ipairs(params) do L = yc.set_portstate (port, true, L) end @@ -392,7 +390,6 @@ yc.command_on = function(params, L) end yc.command_off = function(params, L) - local rules = {} for i, port in ipairs(params) do L = yc.set_portstate (port, false, L) end @@ -405,7 +402,7 @@ yc.command_print = function(params, eeprom, L) if param:sub(1,1) == '"' and param:sub(#param, #param) == '"' then s = s..param:sub(2, #param-1) else - r = yc.command_parsecondition(param, L, eeprom) + local r = yc.command_parsecondition(param, L, eeprom) if r == "1" or r == "0" then s = s..r else return nil end @@ -469,8 +466,8 @@ yc.command_after_execute = function(params) if yc.parsecode(params.code, params.pos) == nil then meta:set_string("infotext", "Code in after() not valid!") else - if code ~= nil then - meta:set_string("infotext", "Working Microcontroller\n"..code) + if params.code ~= nil then + meta:set_string("infotext", "Working Microcontroller\n"..params.code) else meta:set_string("infotext", "Working Microcontroller") end @@ -543,8 +540,8 @@ yc.command_parsecondition = function(cond, L, eeprom) cond = string.gsub(cond, "!0", "1") cond = string.gsub(cond, "!1", "0") - local i = 2 - local l = string.len(cond) + i = 2 + l = string.len(cond) while i<=l do local s = cond:sub(i,i) local b = tonumber(cond:sub(i-1, i-1)) @@ -553,8 +550,7 @@ yc.command_parsecondition = function(cond, L, eeprom) if s == "=" then if a==nil then return nil end if b==nil then return nil end - if a == b then buf = "1" end - if a ~= b then buf = "0" end + local buf = a == b and "1" or "0" cond = string.gsub(cond, b..s..a, buf) i = 1 l = string.len(cond) @@ -562,8 +558,8 @@ yc.command_parsecondition = function(cond, L, eeprom) i = i + 1 end - local i = 2 - local l = string.len(cond) + i = 2 + l = string.len(cond) while i<=l do local s = cond:sub(i,i) local b = tonumber(cond:sub(i-1, i-1)) @@ -659,7 +655,7 @@ yc.set_portstate = function(port, state, L) return L end -yc.update_real_portstates = function(pos, node, rulename, newstate) +yc.update_real_portstates = function(pos, _, rulename, newstate) local meta = minetest.get_meta(pos) if rulename == nil then meta:set_int("real_portstates", 1) @@ -696,7 +692,7 @@ end yc.get_virtual_portstates = function(pos) -- portstates according to the name local name = minetest.get_node(pos).name - local b, a = string.find(name, ":microcontroller") + local _, a = string.find(name, ":microcontroller") if a == nil then return nil end a = a + 1 diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua index b7fb8f1..e1ccbd0 100644 --- a/mesecons_movestones/init.lua +++ b/mesecons_movestones/init.lua @@ -71,7 +71,7 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical) -- ### Step 3: If sticky, pull stack behind ### if is_sticky then local backpos = vector.subtract(pos, direction) - success, stack, oldstack = mesecon.mvps_pull_all(backpos, direction, max_pull, owner) + local success, _, oldstack = mesecon.mvps_pull_all(backpos, direction, max_pull, owner) if success then mesecon.mvps_move_objects(backpos, vector.multiply(direction, -1), oldstack, -1) end @@ -94,7 +94,7 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical) def.after_place_node = mesecon.mvps_set_owner - def.on_punch = function(pos, node, player) + def.on_punch = function(pos, _, player) local player_name = player and player.get_player_name and player:get_player_name() if mesecon.mvps_claim(pos, player_name) then minetest.get_node_timer(pos):start(timer_interval) @@ -102,7 +102,7 @@ function mesecon.register_movestone(name, def, is_sticky, is_vertical) end end - def.on_timer = function(pos, elapsed) + def.on_timer = function(pos) local sourcepos = mesecon.is_powered(pos) if not sourcepos then return diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua index 2bec69b..81795c6 100644 --- a/mesecons_mvps/init.lua +++ b/mesecons_mvps/init.lua @@ -271,7 +271,6 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti end function mesecon.mvps_move_objects(pos, dir, nodestack, movefactor) - local objects_to_move = {} local dir_k local dir_l for k, v in pairs(dir) do diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index dad70e3..732dd12 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -107,7 +107,7 @@ local function piston_off(pos, node) local dir = minetest.facedir_to_dir(node.param2) local pullpos = vector.add(pos, vector.multiply(dir, -2)) local meta = minetest.get_meta(pos) - local success, stack, oldstack = mesecon.mvps_pull_single(pullpos, dir, max_pull, meta:get_string("owner")) + local success, _, oldstack = mesecon.mvps_pull_single(pullpos, dir, max_pull, meta:get_string("owner")) if success then mesecon.mvps_move_objects(pullpos, vector.multiply(dir, -1), oldstack, -1) end @@ -234,7 +234,7 @@ local function piston_rotate_pusher(pos, node, player, mode) return piston_rotate_on(piston_pos, piston_node, player, mode) end -local function piston_punch(pos, node, player) +local function piston_punch(pos, _, player) local player_name = player and player.get_player_name and player:get_player_name() if mesecon.mvps_claim(pos, player_name) then minetest.chat_send_player(player_name, "Reclaimed piston") @@ -422,7 +422,7 @@ minetest.register_node("mesecons_pistons:piston_pusher_sticky", { -- Register pushers as stoppers if they would be seperated from the piston -local function piston_pusher_get_stopper(node, dir, stack, stackid) +local function piston_pusher_get_stopper(node, _, stack, stackid) if (stack[stackid + 1] and stack[stackid + 1].node.name == get_pistonspec(node.name, "pusher").onname and stack[stackid + 1].node.param2 == node.param2) @@ -434,32 +434,12 @@ local function piston_pusher_get_stopper(node, dir, stack, stackid) return true end -local function piston_pusher_up_down_get_stopper(node, dir, stack, stackid) - if (stack[stackid + 1] - and stack[stackid + 1].node.name == get_pistonspec(node.name, "pusher").onname) - or (stack[stackid - 1] - and stack[stackid - 1].node.name == get_pistonspec(node.name, "pusher").onname) then - return false - end - return true -end - mesecon.register_mvps_stopper("mesecons_pistons:piston_pusher_normal", piston_pusher_get_stopper) mesecon.register_mvps_stopper("mesecons_pistons:piston_pusher_sticky", piston_pusher_get_stopper) -- Register pistons as stoppers if they would be seperated from the stopper -local piston_up_down_get_stopper = function (node, dir, stack, stackid) - if (stack[stackid + 1] - and stack[stackid + 1].node.name == get_pistonspec(node.name, "onname").pusher) - or (stack[stackid - 1] - and stack[stackid - 1].node.name == get_pistonspec(node.name, "onname").pusher) then - return false - end - return true -end - -local function piston_get_stopper(node, dir, stack, stackid) +local function piston_get_stopper(node, _, stack, stackid) local pistonspec = get_pistonspec(node.name, "onname") local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1) local pusherpos = vector.add(stack[stackid].pos, dir) @@ -499,4 +479,4 @@ minetest.register_craft({ -- load legacy code -dofile(minetest.get_modpath("mesecons_pistons")..DIR_DELIM.."legacy.lua") +dofile(minetest.get_modpath("mesecons_pistons").."/legacy.lua") diff --git a/mesecons_powerplant/init.lua b/mesecons_powerplant/init.lua index 356fb12..dff19ad 100644 --- a/mesecons_powerplant/init.lua +++ b/mesecons_powerplant/init.lua @@ -11,7 +11,7 @@ minetest.register_node("mesecons_powerplant:power_plant", { walkable = false, groups = {dig_immediate=3, mesecon = 2}, light_source = minetest.LIGHT_MAX-9, - description="Power Plant", + description="Power Plant", selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, -0.5+0.7, 0.3}, diff --git a/mesecons_pressureplates/init.lua b/mesecons_pressureplates/init.lua index 8137676..6c22db2 100644 --- a/mesecons_pressureplates/init.lua +++ b/mesecons_pressureplates/init.lua @@ -8,7 +8,7 @@ local pp_box_on = { fixed = { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 }, } -local function pp_on_timer(pos, elapsed) +local function pp_on_timer(pos) local node = minetest.get_node(pos) local basename = minetest.registered_nodes[node.name].pressureplate_basename @@ -17,7 +17,6 @@ local function pp_on_timer(pos, elapsed) if not basename then return end local objs = minetest.get_objects_inside_radius(pos, 1) - local two_below = vector.add(pos, vector.new(0, -2, 0)) if objs[1] == nil and node.name == basename .. "_on" then minetest.set_node(pos, {name = basename .. "_off"}) @@ -46,7 +45,6 @@ end -- sounds: sound table function mesecon.register_pressure_plate(basename, description, textures_off, textures_on, image_w, image_i, recipe, groups, sounds) - local groups_off, groups_on if not groups then groups = {} end diff --git a/mesecons_random/init.lua b/mesecons_random/init.lua index 0536007..b2a1702 100644 --- a/mesecons_random/init.lua +++ b/mesecons_random/init.lua @@ -59,7 +59,7 @@ minetest.register_node("mesecons_random:ghoststone_active", { }}, on_construct = function(pos) -- remove shadow - shadowpos = vector.add(pos, vector.new(0, 1, 0)) + local shadowpos = vector.add(pos, vector.new(0, 1, 0)) if (minetest.get_node(shadowpos).name == "air") then minetest.dig_node(shadowpos) end diff --git a/mesecons_receiver/init.lua b/mesecons_receiver/init.lua index 476131d..6ac4eae 100644 --- a/mesecons_receiver/init.lua +++ b/mesecons_receiver/init.lua @@ -47,7 +47,7 @@ mesecon.register_node("mesecons_receiver:receiver", { walkable = false, on_rotate = false, selection_box = { - type = "fixed", + type = "fixed", fixed = { -3/16, -8/16, -8/16, 3/16, 3/16, 8/16 } }, node_box = { @@ -96,7 +96,7 @@ mesecon.register_node("mesecons_receiver:receiver_up", { walkable = false, on_rotate = false, selection_box = { - type = "fixed", + type = "fixed", fixed = up_rcvboxes }, node_box = { @@ -141,7 +141,7 @@ mesecon.register_node("mesecons_receiver:receiver_down", { walkable = false, on_rotate = false, selection_box = { - type = "fixed", + type = "fixed", fixed = down_rcvboxes }, node_box = { diff --git a/mesecons_stickyblocks/init.lua b/mesecons_stickyblocks/init.lua index 094af09..3e8b7c4 100644 --- a/mesecons_stickyblocks/init.lua +++ b/mesecons_stickyblocks/init.lua @@ -8,7 +8,7 @@ minetest.register_node("mesecons_stickyblocks:sticky_block_all", { tiles = {"mesecons_stickyblocks_sticky.png"}, is_ground_content = false, groups = {choppy=3, oddly_breakable_by_hand=2}, - mvps_sticky = function (pos, node) + mvps_sticky = function (pos) local connected = {} for _, r in ipairs(mesecon.rules.alldirs) do table.insert(connected, vector.add(pos, r)) diff --git a/mesecons_wires/init.lua b/mesecons_wires/init.lua index 20e6adb..66a2305 100644 --- a/mesecons_wires/init.lua +++ b/mesecons_wires/init.lua @@ -14,7 +14,7 @@ local wire_getconnect = function (from_pos, self_pos) if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].mesecons then -- rules of node to possibly connect to - local rules = {} + local rules if (minetest.registered_nodes[node.name].mesecon_wire) then rules = mesecon.rules.default else @@ -73,7 +73,7 @@ local update_on_place_dig = function (pos, node) end -- Update nodes around it - local rules = {} + local rules if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].mesecon_wire then rules = mesecon.rules.default From 3c27bb9350e5469f9bb8da862fec3e9e6f4749a8 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sat, 12 Feb 2022 18:19:33 -0500 Subject: [PATCH 05/10] Fix VM light update issue (#590) --- mesecons/util.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mesecons/util.lua b/mesecons/util.lua index 5215e8c..80afd09 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -326,6 +326,9 @@ end -- Nil if no VM-based transaction is in progress. local vm_cache = nil +-- Whether the current transaction will need a light update afterward. +local vm_update_light = false + -- Starts a VoxelManipulator-based transaction. -- -- During a VM transaction, calls to vm_get_node and vm_swap_node operate on a @@ -334,6 +337,7 @@ local vm_cache = nil -- vm_abort. function mesecon.vm_begin() vm_cache = {} + vm_update_light = false end -- Finishes a VoxelManipulator-based transaction, freeing the VMs and map data @@ -343,7 +347,7 @@ function mesecon.vm_commit() if tbl.dirty then local vm = tbl.vm vm:set_data(tbl.data) - vm:write_to_map(tbl.update_light) + vm:write_to_map(vm_update_light) vm:update_map() end end @@ -364,7 +368,7 @@ local function vm_get_or_create_entry(pos) local vm = minetest.get_voxel_manip(pos, pos) local min_pos, max_pos = vm:get_emerged_area() local va = VoxelArea:new{MinEdge = min_pos, MaxEdge = max_pos} - tbl = {vm = vm, va = va, data = vm:get_data(), param1 = vm:get_light_data(), param2 = vm:get_param2_data(), dirty = false, update_light = false} + tbl = {vm = vm, va = va, data = vm:get_data(), param1 = vm:get_light_data(), param2 = vm:get_param2_data(), dirty = false} vm_cache[hash] = tbl end return tbl @@ -391,8 +395,11 @@ end -- -- The swap will necessitate a light update unless update_light equals false. function mesecon.vm_swap_node(pos, name, update_light) + -- If one node needs a light update, all VMs should use light updates to + -- prevent newly calculated light from being overwritten by other VMs. + vm_update_light = vm_update_light or update_light ~= false + local tbl = vm_get_or_create_entry(pos) - tbl.update_light = update_light ~= false or tbl.update_light local index = tbl.va:indexp(pos) tbl.data[index] = minetest.get_content_id(name) tbl.dirty = true From 4dfadd9276d4681ef0a07fbcd016051a5c7fba81 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sat, 12 Feb 2022 14:15:04 -0500 Subject: [PATCH 06/10] Fix luacheck warning --- mesecons_mvps/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua index 81795c6..ab284da 100644 --- a/mesecons_mvps/init.lua +++ b/mesecons_mvps/init.lua @@ -46,9 +46,9 @@ local function on_mvps_move(moved_nodes) end end -function mesecon.mvps_process_stack(stack) +function mesecon.mvps_process_stack() -- This function is kept for compatibility. - -- It used to call on_placenode on the moved nodes, but that is now done automatically. + -- It used to call on_placenode on moved nodes, but that is now done automatically. end -- tests if the node can be pushed into, e.g. air, water, grass From 1d3089134995aafa7e908aac22be91027d8cb49d Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Fri, 28 Jan 2022 17:11:46 -0500 Subject: [PATCH 07/10] Move default dependency to individual mods that need it --- mesecons/mod.conf | 4 +++- mesecons_blinkyplant/mod.conf | 2 +- mesecons_button/mod.conf | 2 +- mesecons_commandblock/mod.conf | 2 +- mesecons_delayer/mod.conf | 2 +- mesecons_detector/mod.conf | 2 +- mesecons_fpga/mod.conf | 2 +- mesecons_gates/mod.conf | 2 +- mesecons_hydroturbine/mod.conf | 2 +- mesecons_insulated/mod.conf | 2 +- mesecons_lamp/mod.conf | 2 +- mesecons_lightstone/mod.conf | 2 +- mesecons_luacontroller/mod.conf | 2 +- mesecons_materials/mod.conf | 2 +- mesecons_microcontroller/mod.conf | 2 +- mesecons_movestones/mod.conf | 2 +- mesecons_noteblock/mod.conf | 2 +- mesecons_pistons/mod.conf | 2 +- mesecons_powerplant/mod.conf | 2 +- mesecons_pressureplates/mod.conf | 2 +- mesecons_random/mod.conf | 2 +- mesecons_receiver/mod.conf | 2 +- mesecons_solarpanel/mod.conf | 2 +- mesecons_stickyblocks/mod.conf | 2 +- mesecons_switch/mod.conf | 2 +- mesecons_torch/mod.conf | 2 +- mesecons_walllever/mod.conf | 2 +- mesecons_wires/mod.conf | 2 +- 28 files changed, 30 insertions(+), 28 deletions(-) diff --git a/mesecons/mod.conf b/mesecons/mod.conf index 61b628e..b49e9a8 100644 --- a/mesecons/mod.conf +++ b/mesecons/mod.conf @@ -1,2 +1,4 @@ name = mesecons -depends = default +# default is an optional dependency as some mods may expect it as a transitory +# dependency when they depend on mesecons. +optional_depends = default diff --git a/mesecons_blinkyplant/mod.conf b/mesecons_blinkyplant/mod.conf index 04997b9..8332c95 100644 --- a/mesecons_blinkyplant/mod.conf +++ b/mesecons_blinkyplant/mod.conf @@ -1,2 +1,2 @@ name = mesecons_blinkyplant -depends = mesecons +depends = default, mesecons diff --git a/mesecons_button/mod.conf b/mesecons_button/mod.conf index b98afd1..62c1e40 100644 --- a/mesecons_button/mod.conf +++ b/mesecons_button/mod.conf @@ -1,2 +1,2 @@ name = mesecons_button -depends = mesecons, mesecons_receiver +depends = default, mesecons, mesecons_receiver diff --git a/mesecons_commandblock/mod.conf b/mesecons_commandblock/mod.conf index 750a6e7..66f847d 100644 --- a/mesecons_commandblock/mod.conf +++ b/mesecons_commandblock/mod.conf @@ -1,2 +1,2 @@ name = mesecons_commandblock -depends = mesecons +depends = default, mesecons diff --git a/mesecons_delayer/mod.conf b/mesecons_delayer/mod.conf index b9b96d0..a6604ed 100644 --- a/mesecons_delayer/mod.conf +++ b/mesecons_delayer/mod.conf @@ -1,2 +1,2 @@ name = mesecons_delayer -depends = mesecons +depends = default, mesecons diff --git a/mesecons_detector/mod.conf b/mesecons_detector/mod.conf index 75456b3..0a43985 100644 --- a/mesecons_detector/mod.conf +++ b/mesecons_detector/mod.conf @@ -1,2 +1,2 @@ name = mesecons_detector -depends = mesecons, mesecons_materials +depends = default, mesecons, mesecons_materials diff --git a/mesecons_fpga/mod.conf b/mesecons_fpga/mod.conf index 707f7c7..c2e3a25 100644 --- a/mesecons_fpga/mod.conf +++ b/mesecons_fpga/mod.conf @@ -1,3 +1,3 @@ name = mesecons_fpga -depends = mesecons +depends = default, mesecons optional_depends = screwdriver diff --git a/mesecons_gates/mod.conf b/mesecons_gates/mod.conf index c57336f..399d832 100644 --- a/mesecons_gates/mod.conf +++ b/mesecons_gates/mod.conf @@ -1,2 +1,2 @@ name = mesecons_gates -depends = mesecons, mesecons_microcontroller, mesecons_delayer, mesecons_torch, mesecons_materials +depends = default, mesecons, mesecons_microcontroller, mesecons_delayer, mesecons_torch, mesecons_materials diff --git a/mesecons_hydroturbine/mod.conf b/mesecons_hydroturbine/mod.conf index ce221ea..2d1cfd8 100644 --- a/mesecons_hydroturbine/mod.conf +++ b/mesecons_hydroturbine/mod.conf @@ -1,2 +1,2 @@ name = mesecons_hydroturbine -depends = mesecons +depends = default, mesecons diff --git a/mesecons_insulated/mod.conf b/mesecons_insulated/mod.conf index d5965f0..7b33fe9 100644 --- a/mesecons_insulated/mod.conf +++ b/mesecons_insulated/mod.conf @@ -1,3 +1,3 @@ name = mesecons_insulated -depends = mesecons +depends = default, mesecons optional_depends = screwdriver diff --git a/mesecons_lamp/mod.conf b/mesecons_lamp/mod.conf index b469619..4312b8f 100644 --- a/mesecons_lamp/mod.conf +++ b/mesecons_lamp/mod.conf @@ -1,2 +1,2 @@ name = mesecons_lamp -depends = mesecons +depends = default, mesecons diff --git a/mesecons_lightstone/mod.conf b/mesecons_lightstone/mod.conf index 421f58d..e7a55c2 100644 --- a/mesecons_lightstone/mod.conf +++ b/mesecons_lightstone/mod.conf @@ -1,2 +1,2 @@ name = mesecons_lightstone -depends = mesecons, dye +depends = default, mesecons, dye diff --git a/mesecons_luacontroller/mod.conf b/mesecons_luacontroller/mod.conf index 0db7d72..0d95253 100644 --- a/mesecons_luacontroller/mod.conf +++ b/mesecons_luacontroller/mod.conf @@ -1,2 +1,2 @@ name = mesecons_luacontroller -depends = mesecons +depends = default, mesecons diff --git a/mesecons_materials/mod.conf b/mesecons_materials/mod.conf index 53d1e1d..827423a 100644 --- a/mesecons_materials/mod.conf +++ b/mesecons_materials/mod.conf @@ -1,2 +1,2 @@ name = mesecons_materials -depends = mesecons +depends = default, mesecons diff --git a/mesecons_microcontroller/mod.conf b/mesecons_microcontroller/mod.conf index 6a18b2c..2d72941 100644 --- a/mesecons_microcontroller/mod.conf +++ b/mesecons_microcontroller/mod.conf @@ -1,2 +1,2 @@ name = mesecons_microcontroller -depends = mesecons +depends = default, mesecons diff --git a/mesecons_movestones/mod.conf b/mesecons_movestones/mod.conf index 9e0cbc1..6583448 100644 --- a/mesecons_movestones/mod.conf +++ b/mesecons_movestones/mod.conf @@ -1,2 +1,2 @@ name = mesecons_movestones -depends = mesecons, mesecons_materials, mesecons_mvps +depends = default, mesecons, mesecons_materials, mesecons_mvps diff --git a/mesecons_noteblock/mod.conf b/mesecons_noteblock/mod.conf index 1288ca3..ad0b4c7 100644 --- a/mesecons_noteblock/mod.conf +++ b/mesecons_noteblock/mod.conf @@ -1,2 +1,2 @@ name = mesecons_noteblock -depends = mesecons +depends = default, mesecons diff --git a/mesecons_pistons/mod.conf b/mesecons_pistons/mod.conf index db118fe..c7399a9 100644 --- a/mesecons_pistons/mod.conf +++ b/mesecons_pistons/mod.conf @@ -1,2 +1,2 @@ name = mesecons_pistons -depends = mesecons, mesecons_mvps +depends = default, mesecons, mesecons_mvps diff --git a/mesecons_powerplant/mod.conf b/mesecons_powerplant/mod.conf index 1f0024f..a0949a3 100644 --- a/mesecons_powerplant/mod.conf +++ b/mesecons_powerplant/mod.conf @@ -1,2 +1,2 @@ name = mesecons_powerplant -depends = mesecons +depends = default, mesecons diff --git a/mesecons_pressureplates/mod.conf b/mesecons_pressureplates/mod.conf index 21ed926..99b8745 100644 --- a/mesecons_pressureplates/mod.conf +++ b/mesecons_pressureplates/mod.conf @@ -1,2 +1,2 @@ name = mesecons_pressureplates -depends = mesecons +depends = default, mesecons diff --git a/mesecons_random/mod.conf b/mesecons_random/mod.conf index 2d94c08..8d233f0 100644 --- a/mesecons_random/mod.conf +++ b/mesecons_random/mod.conf @@ -1,2 +1,2 @@ name = mesecons_random -depends = mesecons +depends = default, mesecons diff --git a/mesecons_receiver/mod.conf b/mesecons_receiver/mod.conf index c1200af..0bda4f6 100644 --- a/mesecons_receiver/mod.conf +++ b/mesecons_receiver/mod.conf @@ -1,2 +1,2 @@ name = mesecons_receiver -depends = mesecons +depends = default, mesecons diff --git a/mesecons_solarpanel/mod.conf b/mesecons_solarpanel/mod.conf index 399d904..2c6f98c 100644 --- a/mesecons_solarpanel/mod.conf +++ b/mesecons_solarpanel/mod.conf @@ -1,2 +1,2 @@ name = mesecons_solarpanel -depends = mesecons, mesecons_materials +depends = default, mesecons, mesecons_materials diff --git a/mesecons_stickyblocks/mod.conf b/mesecons_stickyblocks/mod.conf index c7da51a..5291e0a 100644 --- a/mesecons_stickyblocks/mod.conf +++ b/mesecons_stickyblocks/mod.conf @@ -1,2 +1,2 @@ name = mesecons_stickyblocks -depends = mesecons, mesecons_mvps +depends = default, mesecons, mesecons_mvps diff --git a/mesecons_switch/mod.conf b/mesecons_switch/mod.conf index f3b88d7..403fd22 100644 --- a/mesecons_switch/mod.conf +++ b/mesecons_switch/mod.conf @@ -1,2 +1,2 @@ name = mesecons_switch -depends = mesecons +depends = default, mesecons diff --git a/mesecons_torch/mod.conf b/mesecons_torch/mod.conf index 520a6ea..6b694a3 100644 --- a/mesecons_torch/mod.conf +++ b/mesecons_torch/mod.conf @@ -1,2 +1,2 @@ name = mesecons_torch -depends = mesecons +depends = default, mesecons diff --git a/mesecons_walllever/mod.conf b/mesecons_walllever/mod.conf index 3bf2e5c..d6ca0bc 100644 --- a/mesecons_walllever/mod.conf +++ b/mesecons_walllever/mod.conf @@ -1,2 +1,2 @@ name = mesecons_walllever -depends = mesecons, mesecons_receiver +depends = default, mesecons, mesecons_receiver diff --git a/mesecons_wires/mod.conf b/mesecons_wires/mod.conf index c537656..8e2c30b 100644 --- a/mesecons_wires/mod.conf +++ b/mesecons_wires/mod.conf @@ -1,2 +1,2 @@ name = mesecons_wires -depends = mesecons +depends = default, mesecons From f6b0de64b83871a6fa4e0b53af1894453f8ee7d0 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 19 Feb 2022 18:00:55 +0100 Subject: [PATCH 08/10] Update list of MVPS stoppers --- mesecons_mvps/init.lua | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua index ab284da..e3038a6 100644 --- a/mesecons_mvps/init.lua +++ b/mesecons_mvps/init.lua @@ -328,11 +328,31 @@ end -- TODO: load blocks instead, as with wires. mesecon.register_mvps_stopper("ignore") -mesecon.register_mvps_stopper("doors:door_steel_b_1") -mesecon.register_mvps_stopper("doors:door_steel_t_1") -mesecon.register_mvps_stopper("doors:door_steel_b_2") -mesecon.register_mvps_stopper("doors:door_steel_t_2") -mesecon.register_mvps_stopper("default:chest_locked") +-- All of the locked and internal nodes in Minetest Game +for _, name in ipairs({ + "default:chest_locked", + "default:chest_locked_open", + "doors:door_steel_b_1", -- old style doors + "doors:door_steel_b_2", -- + "doors:door_steel_t_1", -- + "doors:door_steel_t_2", -- + "doors:door_steel_a", -- new style doors + "doors:door_steel_b", -- + "doors:door_steel_c", -- + "doors:door_steel_d", -- + "doors:hidden", + "doors:trapdoor_steel", + "doors:trapdoor_steel_open", + "xpanes:door_steel_bar_a", + "xpanes:door_steel_bar_b", + "xpanes:door_steel_bar_c", + "xpanes:door_steel_bar_d", + "xpanes:trapdoor_steel_bar", + "xpanes:trapdoor_steel_bar_open", +}) do + mesecon.register_mvps_stopper(name) +end + mesecon.register_on_mvps_move(mesecon.move_hot_nodes) mesecon.register_on_mvps_move(function(moved_nodes) for i = 1, #moved_nodes do From fef5c8cf68905f87d7dea0ae463a420afc67fef1 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 19 Feb 2022 18:17:40 +0100 Subject: [PATCH 09/10] Resolve license information inconsistency Although the addition of "version 3 or later" to the README [1] predates the commit that added LICENSE.txt with the description "LGPLv3 for code" [2] I think it's safe to go with the latter since the terms were clarified again by the original author explicitly without the "or later" clause [3]. closes #575 [1]: May 2013 8be0d0e1d975ef93b38918f19b36b58b5c873b07 [2]: Sep 2013 c3082f660175bdeb6205f19418f0bf8b43ba10f6 [3]: May 2016 85bc62a65d05c6e6066fba12b6551364561ab207 --- README.md | 10 ++++++---- bower.json | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 80cf185..b198ccc 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ MESECONS by Jeija and contributors Mezzee-what? ------------ -[Mesecons](http://mesecons.net/)! They're yellow, they're conductive, and they'll add a whole new dimension to Minetest's gameplay. +[Mesecons](https://mesecons.net/)! They're yellow, they're conductive, and they'll add a whole new dimension to Minetest's gameplay. -Mesecons is a mod for [Minetest](http://minetest.net/) that implements a ton of items related to digital circuitry, such as wires, buttons, lights, and even programmable controllers. Among other things, there are also pistons, solar panels, pressure plates, and note blocks. +Mesecons is a mod for [Minetest](https://www.minetest.net/) that implements a ton of items related to digital circuitry, such as wires, buttons, lights, and even programmable controllers. Among other things, there are also pistons, solar panels, pressure plates, and note blocks. Mesecons has a similar goal to Redstone in Minecraft, but works in its own way, with different rules and mechanics. @@ -74,8 +74,10 @@ There are also a whole bunch of other people helping with everything from code t Alright, how can I use it? -------------------------- -All textures in this project are licensed under the CC-BY-SA 3.0 (Creative Commons Attribution-ShareAlike 3.0 Generic). That means you can distribute and remix them as much as you want to, under the condition that you give credit to the authors and the project, and that if you remix and release them, they must be under the same or similar license to this one. +All textures in this project are licensed under the CC-BY-SA 3.0 (Creative Commons Attribution-ShareAlike 3.0 Generic). +That means you can distribute and remix them as much as you want to, under the condition that you give credit to the authors and the project, and that if you remix and release them, they must be under the same or similar license to this one. -All code in this project is licensed under the LGPL version 3 or later. That means you have unlimited freedom to distribute and modify the work however you see fit, provided that if you decide to distribute it or any modified versions of it, you must also use the same license. The LGPL also grants the additional freedom to write extensions for the software and distribute them without the extensions being subject to the terms of the LGPL, although the software itself retains its license. +All code in this project is licensed under the LGPL version 3. +That means you have unlimited freedom to distribute and modify the work however you see fit, provided that if you decide to distribute it or any modified versions of it, you must also use the same license. The LGPL also grants the additional freedom to write extensions for the software and distribute them without the extensions being subject to the terms of the LGPL, although the software itself retains its license. No warranty is provided, express or implied, for any part of the project. diff --git a/bower.json b/bower.json index 1d94e61..8c850f5 100644 --- a/bower.json +++ b/bower.json @@ -1,9 +1,9 @@ { "name": "mesecons", "description": "Mesecons is a mod for Minetest that implements items related to digital circuitry: wires, buttons, lights, and programmable controllers.", - "homepage": "http://mesecons.net", - "authors": "Jeija", - "license": "LGPL-3.0+", + "homepage": "https://mesecons.net", + "authors": ["Jeija"], + "license": "LGPL-3.0", "keywords": [ "mesecons", "minetest", From 0d9e0274ae504e291e97e8a93481a5c88f4809f3 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sun, 27 Feb 2022 15:12:37 -0500 Subject: [PATCH 10/10] Prevent extra pin events with luacontrollers, microcontrollers, and FPGAs (#593) --- mesecons_fpga/init.lua | 17 ++++++++++++----- mesecons_luacontroller/init.lua | 24 ++++++++++++++---------- mesecons_microcontroller/init.lua | 19 ++++++++++++++----- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/mesecons_fpga/init.lua b/mesecons_fpga/init.lua index d8849f3..32412f4 100644 --- a/mesecons_fpga/init.lua +++ b/mesecons_fpga/init.lua @@ -114,8 +114,9 @@ plg.register_nodes({ effector = { rules = {}, -- replaced later action_change = function(pos, _, rule, newstate) - plg.ports_changed(pos, rule, newstate) - plg.update(pos) + if plg.ports_changed(pos, rule, newstate) then + plg.update(pos) + end end } }, @@ -326,8 +327,10 @@ plg.update = function(pos) plg.setports(pos, A, B, C, D) end +-- Updates the port states according to the signal change. +-- Returns whether the port states actually changed. plg.ports_changed = function(pos, rule, newstate) - if rule == nil then return end + if rule == nil then return false end local meta = minetest.get_meta(pos) local states @@ -347,10 +350,14 @@ plg.ports_changed = function(pos, rule, newstate) local portno = ({4, 1, nil, 3, 2})[3 + rule.x + 2*rule.z] states[portno] = (newstate == "on") - meta:set_string("portstates", + local new_portstates = (states[1] and "1" or "0") .. (states[2] and "1" or "0") .. (states[3] and "1" or "0") .. (states[4] and "1" or "0") - ) + if new_portstates ~= s then + meta:set_string("portstates", new_portstates) + return true + end + return false end plg.getports = function(pos) -- gets merged states of INPUT & OUTPUT diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua index f00ea93..8e60b1a 100644 --- a/mesecons_luacontroller/init.lua +++ b/mesecons_luacontroller/init.lua @@ -43,13 +43,16 @@ local rules = { ------------------ -- These helpers are required to set the port states of the luacontroller +-- Updates the real port states according to the signal change. +-- Returns whether the real port states actually changed. local function update_real_port_states(pos, rule_name, new_state) local meta = minetest.get_meta(pos) if rule_name == nil then meta:set_int("real_portstates", 1) - return + return true end - local n = meta:get_int("real_portstates") - 1 + local real_portstates = meta:get_int("real_portstates") + local n = real_portstates - 1 local L = {} for i = 1, 4 do L[i] = n % 2 @@ -66,12 +69,12 @@ local function update_real_port_states(pos, rule_name, new_state) local port = pos_to_side[rule_name.x + (2 * rule_name.z) + 3] L[port] = (new_state == "on") and 1 or 0 end - meta:set_int("real_portstates", - 1 + - 1 * L[1] + - 2 * L[2] + - 4 * L[3] + - 8 * L[4]) + local new_portstates = 1 + 1 * L[1] + 2 * L[2] + 4 * L[3] + 8 * L[4] + if new_portstates ~= real_portstates then + meta:set_int("real_portstates", new_portstates) + return true + end + return false end @@ -826,8 +829,9 @@ for d = 0, 1 do effector = { rules = input_rules[cid], action_change = function (pos, _, rule_name, new_state) - update_real_port_states(pos, rule_name, new_state) - run(pos, {type=new_state, pin=rule_name}) + if update_real_port_states(pos, rule_name, new_state) then + run(pos, {type=new_state, pin=rule_name}) + end end, }, receptor = { diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 89b0953..7134dc5 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -44,8 +44,9 @@ local mesecons = {effector = { rules = input_rules, action_change = function (pos, node, rulename, newstate) - yc.update_real_portstates(pos, node, rulename, newstate) - yc.update(pos) + if yc.update_real_portstates(pos, node, rulename, newstate) then + yc.update(pos) + end end }} if nodename ~= "mesecons_microcontroller:microcontroller0000" then @@ -655,13 +656,16 @@ yc.set_portstate = function(port, state, L) return L end +-- Updates the real port states according to the signal change. +-- Returns whether the real port states actually changed. yc.update_real_portstates = function(pos, _, rulename, newstate) local meta = minetest.get_meta(pos) if rulename == nil then meta:set_int("real_portstates", 1) - return + return true end - local n = meta:get_int("real_portstates") - 1 + local real_portstates = meta:get_int("real_portstates") + local n = real_portstates - 1 local L = {} for i = 1, 4 do L[i] = n%2 @@ -676,7 +680,12 @@ yc.update_real_portstates = function(pos, _, rulename, newstate) local port = ({4, 1, nil, 3, 2})[rulename.x+2*rulename.z+3] L[port] = (newstate == "on") and 1 or 0 end - meta:set_int("real_portstates", 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4]) + local new_portstates = 1 + L[1] + 2*L[2] + 4*L[3] + 8*L[4] + if new_portstates ~= real_portstates then + meta:set_int("real_portstates", new_portstates) + return true + end + return false end yc.get_real_portstates = function(pos) -- determine if ports are powered (by itself or from outside)