From 4473627de04ab3b0dddd740ea963281460cff8cf Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 26 Jun 2016 13:34:14 +0200 Subject: [PATCH] Remove unused and clean up missused variable-value assignments. * Unused variables * Unused values (assigned to variables, but overwritten before use) * Defining already defined variables instead of reassigning to them. --- mods/beds/functions.lua | 2 +- mods/beds/spawns.lua | 2 -- mods/boats/init.lua | 2 +- mods/bones/init.lua | 1 - mods/bucket/init.lua | 3 ++- mods/creative/init.lua | 1 - mods/default/craftitems.lua | 4 ++-- mods/default/furnace.lua | 3 +-- mods/default/trees.lua | 10 +++++----- mods/doors/init.lua | 7 ++----- mods/farming/api.lua | 2 -- mods/tnt/init.lua | 16 ++++++++-------- 12 files changed, 22 insertions(+), 31 deletions(-) diff --git a/mods/beds/functions.lua b/mods/beds/functions.lua index c383a3f2..96cebe81 100644 --- a/mods/beds/functions.lua +++ b/mods/beds/functions.lua @@ -100,7 +100,7 @@ end local function update_formspecs(finished) local ges = #minetest.get_connected_players() - local form_n = "" + local form_n local is_majority = (ges / 2) < player_in_bed if finished then diff --git a/mods/beds/spawns.lua b/mods/beds/spawns.lua index 2e27f21a..6b1f4041 100644 --- a/mods/beds/spawns.lua +++ b/mods/beds/spawns.lua @@ -32,8 +32,6 @@ function beds.read_spawns() beds.save_spawns() os.rename(file, file .. ".backup") file = org_file - else - spawns = {} end end diff --git a/mods/boats/init.lua b/mods/boats/init.lua index db8258bc..caaef578 100644 --- a/mods/boats/init.lua +++ b/mods/boats/init.lua @@ -167,7 +167,7 @@ function boat.on_step(self, dtime) local p = self.object:getpos() p.y = p.y - 0.5 - local new_velo = {x = 0, y = 0, z = 0} + local new_velo local new_acce = {x = 0, y = 0, z = 0} if not is_water(p) then local nodedef = minetest.registered_nodes[minetest.get_node(p).name] diff --git a/mods/bones/init.lua b/mods/bones/init.lua index 661bbab8..08a422d0 100644 --- a/mods/bones/init.lua +++ b/mods/bones/init.lua @@ -174,7 +174,6 @@ minetest.register_on_dieplayer(function(player) pos.z = math.floor(pos.z+0.5) local param2 = minetest.dir_to_facedir(player:get_look_dir()) local player_name = player:get_player_name() - local player_inv = player:get_inventory() if (not may_replace(pos, player)) then if (may_replace({x=pos.x, y=pos.y+1, z=pos.z}, player)) then diff --git a/mods/bucket/init.lua b/mods/bucket/init.lua index ad5e309c..3770be6a 100644 --- a/mods/bucket/init.lua +++ b/mods/bucket/init.lua @@ -80,8 +80,9 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name else -- not buildable to; place the liquid above -- check if the node above can be replaced + lpos = pointed_thing.above - local node = minetest.get_node_or_nil(lpos) + node = minetest.get_node_or_nil(lpos) local above_ndef = node and minetest.registered_nodes[node.name] if not above_ndef or not above_ndef.buildable_to then diff --git a/mods/creative/init.lua b/mods/creative/init.lua index 7f952d32..abb11aa5 100644 --- a/mods/creative/init.lua +++ b/mods/creative/init.lua @@ -197,7 +197,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) creative.update_creative_inventory(player_name) creative.set_creative_formspec(player, 0) else - local formspec = player:get_inventory_formspec() local start_i = player_inventory[player_name].start_i or 0 if fields.creative_prev then diff --git a/mods/default/craftitems.lua b/mods/default/craftitems.lua index 2fe59784..d821af06 100644 --- a/mods/default/craftitems.lua +++ b/mods/default/craftitems.lua @@ -15,7 +15,7 @@ local lpp = 14 -- Lines per book's page local function book_on_use(itemstack, user) local player_name = user:get_player_name() local data = minetest.deserialize(itemstack:get_metadata()) - local formspec, title, text, owner = "", "", "", player_name + local title, text, owner = "", "", player_name local page, page_max, lines, string = 1, 1, {}, "" if data then @@ -38,6 +38,7 @@ local function book_on_use(itemstack, user) end end + local formspec if owner == player_name then formspec = "size[8,8]" .. default.gui_bg .. default.gui_bg_img .. @@ -152,7 +153,6 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv return end - local copy = ItemStack("default:book_written") local original local index for i = 1, player:get_inventory():get_size("craft") do diff --git a/mods/default/furnace.lua b/mods/default/furnace.lua index 3047dc41..b5bca889 100644 --- a/mods/default/furnace.lua +++ b/mods/default/furnace.lua @@ -111,7 +111,6 @@ local function furnace_node_timer(pos, elapsed) local inv = meta:get_inventory() local srclist = inv:get_list("src") local fuellist = inv:get_list("fuel") - local dstlist = inv:get_list("dst") -- -- Cooking @@ -172,7 +171,7 @@ local function furnace_node_timer(pos, elapsed) -- Update formspec, infotext and node -- local formspec = inactive_formspec - local item_state = "" + local item_state local item_percent = 0 if cookable then item_percent = math.floor(src_time / cooked.time * 100) diff --git a/mods/default/trees.lua b/mods/default/trees.lua index 1e0df1bc..07071c74 100644 --- a/mods/default/trees.lua +++ b/mods/default/trees.lua @@ -176,8 +176,8 @@ function default.grow_tree(pos, is_apple_tree, bad) local vm = minetest.get_voxel_manip() local minp, maxp = vm:read_from_map( - {x = pos.x - 2, y = pos.y, z = pos.z - 2}, - {x = pos.x + 2, y = pos.y + height + 1, z = pos.z + 2} + {x = x - 2, y = y, z = z - 2}, + {x = x + 2, y = y + height + 1, z = z + 2} ) local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) local data = vm:get_data() @@ -211,8 +211,8 @@ function default.grow_jungle_tree(pos, bad) local vm = minetest.get_voxel_manip() local minp, maxp = vm:read_from_map( - {x = pos.x - 3, y = pos.y - 1, z = pos.z - 3}, - {x = pos.x + 3, y = pos.y + height + 1, z = pos.z + 3} + {x = x - 3, y = y - 1, z = z - 3}, + {x = x + 3, y = y + height + 1, z = z + 3} ) local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) local data = vm:get_data() @@ -331,7 +331,7 @@ function default.grow_pine_tree(pos, snow) end end - local dev = 2 + dev = 2 for yy = my + 1, my + 2 do for zz = z - dev, z + dev do local vi = a:index(x - dev, yy, zz) diff --git a/mods/doors/init.lua b/mods/doors/init.lua index 1e682e1d..f39cedff 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -156,7 +156,6 @@ function _doors.door_toggle(pos, node, clicker) end end - local old = state -- until Lua-5.2 we have no bitwise operators :( if state % 2 == 1 then state = state - 1 @@ -186,7 +185,6 @@ end local function on_place_node(place_to, newnode, placer, oldnode, itemstack, pointed_thing) -- Run script hook - local _, callback for _, callback in ipairs(core.registered_on_placenodes) do -- Deepcopy pos, node and pointed_thing because callback can modify them local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z} @@ -250,7 +248,7 @@ function doors.register(name, def) inventory_image = def.inventory_image, on_place = function(itemstack, placer, pointed_thing) - local pos = nil + local pos if not pointed_thing.type == "node" then return itemstack @@ -314,7 +312,6 @@ function doors.register(name, def) meta:set_int("state", state) if def.protected then - local pn = placer:get_player_name() meta:set_string("doors_owner", pn) meta:set_string("infotext", "Owned by " .. pn) end @@ -347,7 +344,7 @@ function doors.register(name, def) return true end local meta = minetest.get_meta(pos) - local name = "" + local name if digger then name = digger:get_player_name() end diff --git a/mods/farming/api.lua b/mods/farming/api.lua index 69c6769b..901f7245 100644 --- a/mods/farming/api.lua +++ b/mods/farming/api.lua @@ -319,11 +319,9 @@ farming.register_plant = function(name, def) nodegroups[pname] = i local next_plant = nil - local on_timer = nil if i < def.steps then next_plant = mname .. ":" .. pname .. "_" .. (i + 1) - on_timer = farming.grow_plant lbm_nodes[#lbm_nodes + 1] = mname .. ":" .. pname .. "_" .. i end diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index e343d055..023a39b1 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -153,7 +153,7 @@ local function entity_physics(pos, radius, drops) local dir = vector.normalize(vector.subtract(obj_pos, pos)) local moveoff = vector.multiply(dir, dist + 1.0) local newpos = vector.add(pos, moveoff) - local newpos = vector.add(newpos, {x = 0, y = 0.2, z = 0}) + newpos = vector.add(newpos, {x = 0, y = 0.2, z = 0}) obj:setpos(newpos) obj:set_hp(obj:get_hp() - damage) @@ -261,7 +261,7 @@ function tnt.burn(pos) end local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast) - local pos = vector.round(pos) + pos = vector.round(pos) -- scan for adjacent TNT nodes first, and enlarge the explosion local vm1 = VoxelManip() local p1 = vector.subtract(pos, 2) @@ -298,11 +298,11 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast) -- perform the explosion local vm = VoxelManip() local pr = PseudoRandom(os.time()) - local p1 = vector.subtract(pos, radius) - local p2 = vector.add(pos, radius) - local minp, maxp = vm:read_from_map(p1, p2) - local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) - local data = vm:get_data() + p1 = vector.subtract(pos, radius) + p2 = vector.add(pos, radius) + minp, maxp = vm:read_from_map(p1, p2) + a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp}) + data = vm:get_data() local drops = {} local on_blast_queue = {} @@ -515,7 +515,7 @@ if enable_tnt then end function tnt.register_tnt(def) - local name = "" + local name if not def.name:find(':') then name = "tnt:" .. def.name else