From 5d17a6b699613e2c0972a6df2011decbb6181109 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 16 Mar 2021 17:35:46 +0100 Subject: [PATCH] fix SO MANY pairs/ipairs --- mods/ENTITIES/mcl_burning/init.lua | 2 +- mods/ENTITIES/mcl_item_entity/init.lua | 4 ++-- mods/ENTITIES/mcl_mobs/api.lua | 6 +++--- mods/ENTITIES/mobs_mc/2_throwing.lua | 2 +- mods/ENVIRONMENT/mcl_weather/nether_dust.lua | 2 +- mods/HUD/mcl_hbarmor/init.lua | 2 +- mods/ITEMS/mcl_beds/functions.lua | 5 ++--- mods/ITEMS/mcl_bows/bow.lua | 2 +- mods/ITEMS/mcl_cauldrons/init.lua | 2 +- mods/ITEMS/mcl_clock/init.lua | 5 ++--- mods/ITEMS/mcl_compass/init.lua | 5 ++--- mods/ITEMS/mcl_doors/api_doors.lua | 2 +- 12 files changed, 18 insertions(+), 21 deletions(-) diff --git a/mods/ENTITIES/mcl_burning/init.lua b/mods/ENTITIES/mcl_burning/init.lua index 61ed12837..672036c78 100644 --- a/mods/ENTITIES/mcl_burning/init.lua +++ b/mods/ENTITIES/mcl_burning/init.lua @@ -22,7 +22,7 @@ minetest.register_entity("mcl_burning:fire", { }) minetest.register_globalstep(function(dtime) - for _, player in ipairs(minetest.get_connected_players()) do + for _, player in pairs(minetest.get_connected_players()) do mcl_burning.tick(player, dtime) end end) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index e5863abbc..e73e29da6 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -54,14 +54,14 @@ local disable_physics = function(object, luaentity, ignore_check, reset_movement end minetest.register_globalstep(function(dtime) - for _,player in ipairs(minetest.get_connected_players()) do + for _,player in pairs(minetest.get_connected_players()) do if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then local pos = player:get_pos() local inv = player:get_inventory() local checkpos = {x=pos.x,y=pos.y + item_drop_settings.player_collect_height,z=pos.z} --magnet and collection - for _,object in ipairs(minetest.get_objects_inside_radius(checkpos, item_drop_settings.xp_radius_magnet)) do + for _,object in pairs(minetest.get_objects_inside_radius(checkpos, item_drop_settings.xp_radius_magnet)) do if not object:is_player() and vector.distance(checkpos, object:get_pos()) < item_drop_settings.radius_magnet and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" and object:get_luaentity()._magnet_timer and (object:get_luaentity()._insta_collect or (object:get_luaentity().age > item_drop_settings.age)) then object:get_luaentity()._magnet_timer = object:get_luaentity()._magnet_timer + dtime local collected = false diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 0c8953079..e8ff728d4 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -226,7 +226,7 @@ local collision = function(self) local z = 0 local width = -self.collisionbox[1] + self.collisionbox[4] + 0.5 - for _,object in ipairs(minetest.get_objects_inside_radius(pos, width)) do + for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do if object:is_player() or (object:get_luaentity()._cmi_is_mob == true and object ~= self.object) then @@ -4576,9 +4576,9 @@ local timer = 0 minetest.register_globalstep(function(dtime) timer = timer + dtime if timer < 1 then return end - for _, player in ipairs(minetest.get_connected_players()) do + for _, player in pairs(minetest.get_connected_players()) do local pos = player:get_pos() - for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 47)) do + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do local lua = obj:get_luaentity() if lua and lua._cmi_is_mob then lua.lifetimer = math.max(20, lua.lifetimer) diff --git a/mods/ENTITIES/mobs_mc/2_throwing.lua b/mods/ENTITIES/mobs_mc/2_throwing.lua index fd55fa32c..23ae86d80 100644 --- a/mods/ENTITIES/mobs_mc/2_throwing.lua +++ b/mods/ENTITIES/mobs_mc/2_throwing.lua @@ -122,7 +122,7 @@ local arrows = { } local throwing_shoot_arrow = function(itemstack, player) - for _,arrow in ipairs(arrows) do + for _,arrow in pairs(arrows) do if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then if not minetest.is_creative_enabled(player:get_player_name()) then player:get_inventory():remove_item("main", arrow[1]) diff --git a/mods/ENVIRONMENT/mcl_weather/nether_dust.lua b/mods/ENVIRONMENT/mcl_weather/nether_dust.lua index 735676454..16cdc9487 100644 --- a/mods/ENVIRONMENT/mcl_weather/nether_dust.lua +++ b/mods/ENVIRONMENT/mcl_weather/nether_dust.lua @@ -27,7 +27,7 @@ minetest.register_globalstep(function(dtime) if timer < 0.7 then return end timer = 0 - for _, player in ipairs(minetest.get_connected_players()) do + for _, player in pairs(minetest.get_connected_players()) do if not mcl_worlds.has_dust(player:get_pos()) then return false end diff --git a/mods/HUD/mcl_hbarmor/init.lua b/mods/HUD/mcl_hbarmor/init.lua index 57978359c..4434f5dad 100644 --- a/mods/HUD/mcl_hbarmor/init.lua +++ b/mods/HUD/mcl_hbarmor/init.lua @@ -118,7 +118,7 @@ minetest.register_globalstep(function(dtime) if main_timer > mcl_hbarmor.tick or timer > 4 then if minetest.settings:get_bool("enable_damage") then if main_timer > mcl_hbarmor.tick then main_timer = 0 end - for _,player in ipairs(minetest.get_connected_players()) do + for _,player in pairs(minetest.get_connected_players()) do local name = player:get_player_name() if mcl_hbarmor.player_active[name] == true then local ret = mcl_hbarmor.get_armor(player) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 33c38c6cb..86f6a6852 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -36,7 +36,7 @@ local function check_in_beds(players) players = minetest.get_connected_players() end - for n, player in ipairs(players) do + for n, player in pairs(players) do local name = player:get_player_name() if not in_bed[name] then return false @@ -102,8 +102,7 @@ local function lay_down(player, pos, bed_pos, state, skip) -- No sleeping if monsters nearby. -- The exceptions above apply. -- Zombie pigmen only prevent sleep while they are hostle. - local objs = minetest.get_objects_inside_radius(bed_pos, 8) - for _, obj in ipairs(objs) do + for _, obj in pairs(minetest.get_objects_inside_radius(bed_pos, 8)) do if obj ~= nil and not obj:is_player() then local ent = obj:get_luaentity() local mobname = ent.name diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 4ea2066b0..87820071d 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -341,7 +341,7 @@ controls.register_on_hold(function(player, key, time) end) minetest.register_globalstep(function(dtime) - for _, player in ipairs(minetest.get_connected_players()) do + for _, player in pairs(minetest.get_connected_players()) do local name = player:get_player_name() local wielditem = player:get_wielded_item() local wieldindex = player:get_wield_index() diff --git a/mods/ITEMS/mcl_cauldrons/init.lua b/mods/ITEMS/mcl_cauldrons/init.lua index 5c8d93160..f4356d27b 100644 --- a/mods/ITEMS/mcl_cauldrons/init.lua +++ b/mods/ITEMS/mcl_cauldrons/init.lua @@ -131,7 +131,7 @@ minetest.register_abm({ interval = 0.5, chance = 1, action = function(pos, node) - for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 0.4)) do + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.4)) do if mcl_burning.is_burning(obj) then mcl_burning.extinguish(obj) local new_group = minetest.get_item_group(node.name, "cauldron_filled") - 1 diff --git a/mods/ITEMS/mcl_clock/init.lua b/mods/ITEMS/mcl_clock/init.lua index 0532bf5f7..d53d75076 100644 --- a/mods/ITEMS/mcl_clock/init.lua +++ b/mods/ITEMS/mcl_clock/init.lua @@ -94,9 +94,8 @@ minetest.register_globalstep(function(dtime) watch.old_time = now - local players = minetest.get_connected_players() - for p, player in ipairs(players) do - for s, stack in ipairs(player:get_inventory():get_list("main")) do + for p, player in pairs(minetest.get_connected_players()) do + for s, stack in pairs(player:get_inventory():get_list("main")) do local dim = mcl_worlds.pos_to_dimension(player:get_pos()) local frame -- Clocks do not work in certain zones diff --git a/mods/ITEMS/mcl_compass/init.lua b/mods/ITEMS/mcl_compass/init.lua index b0cf5627e..f19bfe6a6 100644 --- a/mods/ITEMS/mcl_compass/init.lua +++ b/mods/ITEMS/mcl_compass/init.lua @@ -14,15 +14,14 @@ local random_frame = math.random(0, compass_frames-1) minetest.register_globalstep(function(dtime) random_timer = random_timer + dtime - local players = minetest.get_connected_players() if random_timer >= random_timer_trigger then random_frame = (random_frame + math.random(-1, 1)) % compass_frames random_timer = 0 end - for i,player in ipairs(players) do + for i,player in pairs(minetest.get_connected_players()) do local function has_compass(player) - for _,stack in ipairs(player:get_inventory():get_list("main")) do + for _,stack in pairs(player:get_inventory():get_list("main")) do if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then return true end diff --git a/mods/ITEMS/mcl_doors/api_doors.lua b/mods/ITEMS/mcl_doors/api_doors.lua index 716fb22ec..f3dd0f469 100644 --- a/mods/ITEMS/mcl_doors/api_doors.lua +++ b/mods/ITEMS/mcl_doors/api_doors.lua @@ -4,7 +4,7 @@ local S = minetest.get_translator("mcl_doors") local function on_place_node(place_to, newnode, placer, oldnode, itemstack, pointed_thing) -- Run script hook - for _, callback in ipairs(minetest.registered_on_placenodes) do + for _, callback in pairs(minetest.registered_on_placenodes) do -- Deep-copy 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} local newnode_copy =