From 16bb9b8901efe0ec7309667cd0fa859da6c0d6db Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 26 Jan 2018 22:20:15 +0100 Subject: [PATCH] Localize various unneeded global variables --- .../REDSTONE/mesecons_commandblock/init.lua | 2 +- mods/ITEMS/REDSTONE/mesecons_mvps/init.lua | 2 +- mods/ITEMS/REDSTONE/mesecons_pistons/init.lua | 8 ++--- mods/ITEMS/mcl_banners/patterncraft.lua | 2 +- mods/ITEMS/mcl_core/functions.lua | 2 +- mods/ITEMS/mcl_fire/init.lua | 2 +- mods/ITEMS/mcl_portals/portal_end.lua | 2 ++ mods/ITEMS/mcl_tools/init.lua | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 2 +- mods/PLAYER/mcl_sprint/init.lua | 34 +++++++++---------- 10 files changed, 30 insertions(+), 28 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua b/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua index 3bc1b9ac1..b7343c937 100644 --- a/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_commandblock/init.lua @@ -62,7 +62,7 @@ local function check_commands(commands, player_name) local cmddef = minetest.chatcommands[cmd] if not cmddef then -- Invalid chat command - msg = "Error: The command “"..cmd.."” does not exist; your command block has not been changed. Use the “help” chat command for a list of available commands." + local msg = "Error: The command “"..cmd.."” does not exist; your command block has not been changed. Use the “help” chat command for a list of available commands." if string.sub(cmd, 1, 1) == "/" then msg = msg .. " Hint: Try to remove the trailing slash." end diff --git a/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua b/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua index 3ef39b74d..40d713eb4 100644 --- a/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua @@ -241,7 +241,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti if first_dropper and id >= first_dropper then break end - np = vector.add(n.pos, movedir) + local np = vector.add(n.pos, movedir) minetest.add_node(np, n.node) minetest.get_meta(np):from_table(n.meta) end diff --git a/mods/ITEMS/REDSTONE/mesecons_pistons/init.lua b/mods/ITEMS/REDSTONE/mesecons_pistons/init.lua index 7ca1cea5a..e5b6045b2 100644 --- a/mods/ITEMS/REDSTONE/mesecons_pistons/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_pistons/init.lua @@ -1,7 +1,7 @@ local PISTON_MAXIMUM_PUSH = 12 -- Get mesecon rules of pistons -piston_rules = +local piston_rules = {{x=0, y=0, z=1}, --everything apart from z- (pusher side) {x=1, y=0, z=0}, {x=-1, y=0, z=0}, @@ -30,7 +30,7 @@ local piston_get_rules = function (node) return rules end -piston_facedir_direction = function (node) +local piston_facedir_direction = function (node) local rules = {{x = 0, y = 0, z = -1}} for i = 1, node.param2 do rules = mesecon.rotate_rules_left(rules) @@ -38,7 +38,7 @@ piston_facedir_direction = function (node) return rules[1] end -piston_get_direction = function (dir, node) +local piston_get_direction = function (dir, node) if type(dir) == "function" then return dir(node) else @@ -830,7 +830,7 @@ local piston_up_down_get_stopper = function (node, dir, stack, stackid) end local piston_get_stopper = function (node, dir, stack, stackid) - pistonspec = minetest.registered_nodes[node.name].mesecons_piston + local pistonspec = minetest.registered_nodes[node.name].mesecons_piston dir = piston_get_direction(pistonspec.dir, node) local pusherpos = vector.add(stack[stackid].pos, dir) local pushernode = minetest.get_node(pusherpos) diff --git a/mods/ITEMS/mcl_banners/patterncraft.lua b/mods/ITEMS/mcl_banners/patterncraft.lua index 9c4339b06..ef667d654 100644 --- a/mods/ITEMS/mcl_banners/patterncraft.lua +++ b/mods/ITEMS/mcl_banners/patterncraft.lua @@ -339,7 +339,7 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i -- For copying to be allowed, one banner has to have no layers while the other one has at least 1 layer. -- The banner with layers will be used as a source. - local src_banner, src_layers, src_desc, src_index + local src_banner, src_layers_raw, src_desc, src_index if #b1layers == 0 and #b2layers > 0 then src_banner = banner2 src_layers_raw = b2layers_raw diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 42d7c899e..d8eea101f 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -270,7 +270,7 @@ end function mcl_core.generate_v6_oak_tree(pos) local trunk = "mcl_core:tree" local leaves = "mcl_core:leaves" - node = {name = ""} + local node = {name = ""} for dy=1,4 do pos.y = pos.y+dy if minetest.get_node(pos).name ~= "air" then diff --git a/mods/ITEMS/mcl_fire/init.lua b/mods/ITEMS/mcl_fire/init.lua index 19bbd0946..2a7a81199 100644 --- a/mods/ITEMS/mcl_fire/init.lua +++ b/mods/ITEMS/mcl_fire/init.lua @@ -345,7 +345,7 @@ if not fire_enabled then chance = 2, catch_up = false, action = function(pos) - function try_ignite(airs) + local function try_ignite(airs) while #airs > 0 do local r = math.random(1, #airs) if minetest.find_node_near(airs[r], 1, {"group:flammable", "group:flammable_lava"}) then diff --git a/mods/ITEMS/mcl_portals/portal_end.lua b/mods/ITEMS/mcl_portals/portal_end.lua index 3c20345ef..b005a2409 100644 --- a/mods/ITEMS/mcl_portals/portal_end.lua +++ b/mods/ITEMS/mcl_portals/portal_end.lua @@ -140,6 +140,7 @@ local function check_end_portal_frame(pos) end end -- All checks survived! We have a valid portal! + local k if dir.x > 0 then k = 1 else @@ -158,6 +159,7 @@ local function check_end_portal_frame(pos) return false end end + local k if dir.z > 0 then k = 1 else diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 745ddbeab..974d96631 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -16,7 +16,7 @@ -- TODO: Add legacy support for Minetest Game groups like crumbly, snappy, cracky, etc. for all tools -- The hand -local groupcaps, range +local groupcaps, hand_range if minetest.settings:get_bool("creative_mode") then -- Instant breaking in creative mode groupcaps = { diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 012c43fab..e7500b7b0 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -1558,7 +1558,7 @@ local generate_underground_mushrooms = function(minp, maxp, seed) end local pr_nether = PseudoRandom(os.time()+667) -local nehter_wart_chance +local nether_wart_chance if mg_name == "v6" then nether_wart_chance = 85 else diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index 8208e230c..79ee234c1 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -39,6 +39,23 @@ minetest.register_on_leaveplayer(function(player) local playerName = player:get_player_name() players[playerName] = nil end) + +local function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting) + local player = minetest.get_player_by_name(playerName) + if players[playerName] then + players[playerName]["sprinting"] = sprinting + -- Don't overwrite physics when standing on soul sand or sleeping + if mcl_playerinfo[playerName].node_stand ~= "mcl_nether:soul_sand" and player:get_attribute("mcl_beds:sleeping") ~= "true" then + if sprinting == true then + player:set_physics_override({speed=mcl_sprint.SPEED}) + elseif sprinting == false then + player:set_physics_override({speed=1.0}) + end + return true + end + end + return false +end minetest.register_globalstep(function(dtime) --Get the gametime local gameTime = minetest.get_gametime() @@ -106,20 +123,3 @@ minetest.register_globalstep(function(dtime) end end end) - -function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting) - local player = minetest.get_player_by_name(playerName) - if players[playerName] then - players[playerName]["sprinting"] = sprinting - -- Don't overwrite physics when standing on soul sand or sleeping - if mcl_playerinfo[playerName].node_stand ~= "mcl_nether:soul_sand" and player:get_attribute("mcl_beds:sleeping") ~= "true" then - if sprinting == true then - player:set_physics_override({speed=mcl_sprint.SPEED}) - elseif sprinting == false then - player:set_physics_override({speed=1.0}) - end - return true - end - end - return false -end