From cc125d8eac2544c1f2a4cc188e37b6973ecbb8d4 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 3 Jan 2025 15:33:18 -0600 Subject: [PATCH] Fix all luacheck findings except two empty if branches, two references to math.round and the *_physics variables from optional mods (each guarded by modpath checks) --- mods/ENTITIES/mcl_minecarts/carts.lua | 2 +- mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua | 3 +-- mods/ENTITIES/mcl_minecarts/functions.lua | 14 ++++---------- mods/ENTITIES/mcl_minecarts/movement.lua | 5 ++--- mods/ENTITIES/mcl_minecarts/rails/activator.lua | 1 - mods/ENTITIES/mcl_minecarts/rails/detector.lua | 1 - mods/ENTITIES/mcl_minecarts/rails/normal.lua | 1 - mods/ENTITIES/mcl_minecarts/rails/powered.lua | 1 - 8 files changed, 8 insertions(+), 20 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/carts.lua b/mods/ENTITIES/mcl_minecarts/carts.lua index 907412854..efb72af86 100644 --- a/mods/ENTITIES/mcl_minecarts/carts.lua +++ b/mods/ENTITIES/mcl_minecarts/carts.lua @@ -463,7 +463,7 @@ local function register_minecart_craftitem(itemstring, def) stack_max = 1, _mcl_dropper_on_drop = dropper_place_minecart, on_place = function(itemstack, placer, pointed_thing) - if not pointed_thing.type == "node" then + if pointed_thing.type ~= "node" then return end diff --git a/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua b/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua index ac00807e3..5487d7bb3 100644 --- a/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua +++ b/mods/ENTITIES/mcl_minecarts/carts/with_hopper.lua @@ -29,7 +29,7 @@ local function hopper_take_item(self, dtime) if objs then mcl_log("there is an itemstring. Number of objs: ".. #objs) - for k, v in pairs(objs) do + for _, v in pairs(objs) do local ent = v:get_luaentity() if ent and not ent._removed and ent.itemstring and ent.itemstring ~= "" then @@ -87,7 +87,6 @@ local function hopper_take_item(self, dtime) mcl_log("We have more than enough space. Now holds: " .. new_stack_size) inv:set_stack("main", i, stack) - items_remaining = 0 ent.object:get_luaentity().itemstring = "" ent.object:remove() diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index 0b04824bc..952629b0e 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -212,8 +212,8 @@ local function get_rail_connections(pos, opt) -- Check for sloped rail one block down local below_neighbor = vector.offset(neighbor, 0, -1, 0) - local node = force_get_node(below_neighbor) - local nodedef = minetest.registered_nodes[node.name] + node = force_get_node(below_neighbor) + nodedef = minetest.registered_nodes[node.name] if mcl_minecarts.is_rail(below_neighbor) and ( legacy or get_path(nodedef, "_mcl_minecarts", "get_next_dir" ) ) then local rev_dir = vector.direction(dir, vector.zero()) if ignore_neighbor_connections or is_connection(below_neighbor, rev_dir) then @@ -229,7 +229,7 @@ local function apply_connection_rules(node, nodedef, pos, rules, connections) -- Select the best allowed connection local rule = nil local score = 0 - for k,r in pairs(rules) do + for _,r in pairs(rules) do if check_connection_rule(pos, connections, r) then if r.score > score then --print("Best rule so far is "..dump(r)) @@ -351,7 +351,6 @@ local function update_rail_connections(pos, opt) if opt and opt.convert_neighbors == false then return end -- Check if the open end of this rail runs into a corner or a tee and convert that node into a tee or a cross - local neighbors = {} for i=1,#CONNECTIONS do local dir = CONNECTIONS[i] if is_connection(pos, dir) then @@ -367,11 +366,6 @@ local function update_rail_connections(pos, opt) end mod.update_rail_connections = update_rail_connections -local north = vector.new(0,0,1) -local south = vector.new(0,0,-1) -local east = vector.new(1,0,0) -local west = vector.new(-1,0,0) - local function is_ahead_slope(pos, dir) local ahead = vector.add(pos,dir) if mcl_minecarts.is_rail(ahead) then return false end @@ -518,7 +512,7 @@ function mod.reverse_cart_direction(staticdata) staticdata.distance = 1 - (staticdata.distance or 0) -- recalculate direction - local next_dir,_ = mod:get_rail_direction(staticdata.connected_at, next_dir) + next_dir = mod:get_rail_direction(staticdata.connected_at, next_dir) staticdata.dir = next_dir end diff --git a/mods/ENTITIES/mcl_minecarts/movement.lua b/mods/ENTITIES/mcl_minecarts/movement.lua index 17cf6e91c..92cc88c28 100644 --- a/mods/ENTITIES/mcl_minecarts/movement.lua +++ b/mods/ENTITIES/mcl_minecarts/movement.lua @@ -74,7 +74,7 @@ local function handle_cart_enter_exit(staticdata, pos, next_dir, event) if luaentity then local hook = luaentity["_mcl_minecarts_"..event] if hook then hook(luaentity, pos, staticdata) end - else + --else --minetest.log("warning", "TODO: change _mcl_minecarts_"..event.." calling so it is not dependent on the existence of a luaentity") end end @@ -145,7 +145,7 @@ local function handle_cart_collision(cart1_staticdata, prev_pos, next_dir) local carts = minetest.deserialize(meta:get_string("_mcl_minecarts_carts")) or {} local cart_uuid = nil local dirty = false - for uuid,v in pairs(carts) do + for uuid,_ in pairs(carts) do -- Clean up dead carts local data = get_cart_data(uuid) if not data or not data.connected_at then @@ -160,7 +160,6 @@ local function handle_cart_collision(cart1_staticdata, prev_pos, next_dir) meta:set_string("_mcl_minecarts_carts",minetest.serialize(carts)) end - meta = minetest.get_meta(vector.add(pos,next_dir)) if not cart_uuid then return end -- Don't collide with the train car in front of you diff --git a/mods/ENTITIES/mcl_minecarts/rails/activator.lua b/mods/ENTITIES/mcl_minecarts/rails/activator.lua index 605ba4a2f..6658c32e7 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/activator.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/activator.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() -local modpath = minetest.get_modpath(modname) local mod = mcl_minecarts local S = minetest.get_translator(modname) diff --git a/mods/ENTITIES/mcl_minecarts/rails/detector.lua b/mods/ENTITIES/mcl_minecarts/rails/detector.lua index 443cecf07..6d4e9b3c5 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/detector.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/detector.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() -local modpath = minetest.get_modpath(modname) local mod = mcl_minecarts local S = minetest.get_translator(modname) diff --git a/mods/ENTITIES/mcl_minecarts/rails/normal.lua b/mods/ENTITIES/mcl_minecarts/rails/normal.lua index 58ff60758..698e0898b 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/normal.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/normal.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() -local modpath = minetest.get_modpath(modname) local mod = mcl_minecarts local S = minetest.get_translator(modname) diff --git a/mods/ENTITIES/mcl_minecarts/rails/powered.lua b/mods/ENTITIES/mcl_minecarts/rails/powered.lua index e76aff2c7..f249799bb 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/powered.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/powered.lua @@ -1,5 +1,4 @@ local modname = minetest.get_current_modname() -local modpath = minetest.get_modpath(modname) local mod = mcl_minecarts local S = minetest.get_translator(modname)