From 981f3d5d74ed49a9748cee3d168c8626bab1fd61 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 25 May 2021 10:51:46 +0200 Subject: [PATCH 01/14] fix some codestyle issues --- mods/CORE/mcl_worlds/init.lua | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/mods/CORE/mcl_worlds/init.lua b/mods/CORE/mcl_worlds/init.lua index 435ce51c7f..ec81447941 100644 --- a/mods/CORE/mcl_worlds/init.lua +++ b/mods/CORE/mcl_worlds/init.lua @@ -33,15 +33,15 @@ end -- If the Y coordinate is not located in any dimension, it will return: -- nil, "void" function mcl_worlds.y_to_layer(y) - if y >= mcl_vars.mg_overworld_min then - return y - mcl_vars.mg_overworld_min, "overworld" - elseif y >= mcl_vars.mg_nether_min and y <= mcl_vars.mg_nether_max+128 then - return y - mcl_vars.mg_nether_min, "nether" - elseif y >= mcl_vars.mg_end_min and y <= mcl_vars.mg_end_max then - return y - mcl_vars.mg_end_min, "end" - else - return nil, "void" - end + if y >= mcl_vars.mg_overworld_min then + return y - mcl_vars.mg_overworld_min, "overworld" + elseif y >= mcl_vars.mg_nether_min and y <= mcl_vars.mg_nether_max+128 then + return y - mcl_vars.mg_nether_min, "nether" + elseif y >= mcl_vars.mg_end_min and y <= mcl_vars.mg_end_max then + return y - mcl_vars.mg_end_min, "end" + else + return nil, "void" + end end -- Takes a pos and returns the dimension it belongs to (same as above) @@ -55,38 +55,38 @@ end -- MineClone 2. -- mc_dimension is one of "overworld", "nether", "end" (default: "overworld"). function mcl_worlds.layer_to_y(layer, mc_dimension) - if mc_dimension == "overworld" or mc_dimension == nil then - return layer + mcl_vars.mg_overworld_min - elseif mc_dimension == "nether" then - return layer + mcl_vars.mg_nether_min - elseif mc_dimension == "end" then - return layer + mcl_vars.mg_end_min - end + if mc_dimension == "overworld" or mc_dimension == nil then + return layer + mcl_vars.mg_overworld_min + elseif mc_dimension == "nether" then + return layer + mcl_vars.mg_nether_min + elseif mc_dimension == "end" then + return layer + mcl_vars.mg_end_min + end end -- Takes a position and returns true if this position can have weather function mcl_worlds.has_weather(pos) - -- Weather in the Overworld and the high part of the void below - return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 + -- Weather in the Overworld and the high part of the void below + return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 end -- Takes a position and returns true if this position can have Nether dust function mcl_worlds.has_dust(pos) - -- Weather in the Overworld and the high part of the void below - return pos.y <= mcl_vars.mg_nether_max + 138 and pos.y >= mcl_vars.mg_nether_min - 10 + -- Weather in the Overworld and the high part of the void below + return pos.y <= mcl_vars.mg_nether_max + 138 and pos.y >= mcl_vars.mg_nether_min - 10 end -- Takes a position (pos) and returns true if compasses are working here function mcl_worlds.compass_works(pos) - -- It doesn't work in Nether and the End, but it works in the Overworld and in the high part of the void below - local _, dim = mcl_worlds.y_to_layer(pos.y) - if dim == "nether" or dim == "end" then - return false - elseif dim == "void" then - return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 - else - return true - end + -- It doesn't work in Nether and the End, but it works in the Overworld and in the high part of the void below + local _, dim = mcl_worlds.y_to_layer(pos.y) + if dim == "nether" or dim == "end" then + return false + elseif dim == "void" then + return pos.y <= mcl_vars.mg_overworld_max and pos.y >= mcl_vars.mg_overworld_min - 64 + else + return true + end end -- Takes a position (pos) and returns true if clocks are working here @@ -112,11 +112,11 @@ local last_dimension = {} -- * player: Player who changed the dimension -- * dimension: New dimension ("overworld", "nether", "end", "void") function mcl_worlds.dimension_change(player, dimension) - local playername = player:get_player_name() + local playername = player:get_player_name() for i=1, #mcl_worlds.registered_on_dimension_change do mcl_worlds.registered_on_dimension_change[i](player, dimension, last_dimension[playername]) end - last_dimension[playername] = dimension + last_dimension[playername] = dimension end ----------------------- INTERNAL STUFF ---------------------- From 388ab6d8dffea8c7daa5760e962ee0ebf3cbaeb1 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 25 May 2021 10:56:06 +0200 Subject: [PATCH 02/14] fix some codestyle issues --- mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua | 4 ++-- .../mcl_mobs/api/mob_functions/animation.lua | 2 +- .../mcl_mobs/api/mob_functions/breeding.lua | 4 +--- .../mcl_mobs/api/mob_functions/environment.lua | 16 +++++++--------- .../mcl_mobs/api/mob_functions/head_logic.lua | 2 +- .../mcl_mobs/api/mob_functions/movement.lua | 2 +- mods/ENTITIES/mcl_mobs/api/spawning.lua | 2 +- mods/HUD/mcl_experience/init.lua | 6 +++--- mods/ITEMS/mcl_enchanting/engine.lua | 2 +- mods/MAPGEN/mcl_structures/init.lua | 2 +- mods/MAPGEN/mcl_villages/buildings.lua | 4 ++-- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 12 files changed, 22 insertions(+), 26 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index df2ccade25..ef26874552 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -416,7 +416,7 @@ local swim_turn_check = function(self,dtime) local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 - return(green_flag_1) + return green_flag_1 end --this is to swap the built in engine acceleration modifier @@ -561,7 +561,7 @@ local fly_turn_check = function(self,dtime) local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 - return(green_flag_1) + return green_flag_1 end --this is to swap the built in engine acceleration modifier diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua index 8f2ea9e310..cea6d838b2 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua @@ -157,7 +157,7 @@ local calculate_pitch = function(self) return false end - return(minetest_dir_to_yaw(vector_new(vector_distance(vector_new(pos.x,0,pos.z),vector_new(pos2.x,0,pos2.z)),0,pos.y - pos2.y)) + HALF_PI) + return minetest_dir_to_yaw(vector_new(vector_distance(vector_new(pos.x,0,pos.z),vector_new(pos2.x,0,pos2.z)),0,pos.y - pos2.y)) + HALF_PI end --this is a helper function used to make mobs pitch rotation dynamically flow when flying/swimming diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/breeding.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/breeding.lua index 57650a9c95..c50fb63001 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/breeding.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/breeding.lua @@ -140,9 +140,7 @@ mobs.look_for_mate = function(self) winner_mate = mate end end - - return(winner_mate) - + return winner_mate end --make the baby grow up diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua index 3b204a4bf8..5c431135e8 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua @@ -76,8 +76,7 @@ mobs.detect_closest_player_within_radius = function(self, line_of_sight, radius, winner_player = player end end - - return(winner_player) + return winner_player end @@ -104,14 +103,13 @@ mobs.jump_check = function(self,dtime) if green_flag_1 and green_flag_2 then --can jump over node - return(1) + return 1 elseif green_flag_1 and not green_flag_2 then --wall in front of mob - return(2) + return 2 end - --nothing to jump over - return(0) + return 0 end -- a helper function to quickly turn neutral passive mobs hostile @@ -223,12 +221,12 @@ mobs.check_for_player_within_area = function(self, radius) local distance = vector_distance(pos1,pos2) if distance < radius then --found a player - return(true) + return true end end end --did not find a player - return(false) + return false end @@ -236,7 +234,7 @@ end mobs.get_2d_distance = function(pos1,pos2) pos1.y = 0 pos2.y = 0 - return(vector_distance(pos1, pos2)) + return vector_distance(pos1, pos2) end -- fall damage onto solid ground diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua index 13bc6584dd..0f5615504d 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua @@ -3,7 +3,7 @@ local vector = vector --converts yaw to degrees local degrees = function(yaw) - return(yaw*180.0/math.pi) + return yaw*180.0/math.pi end mobs.do_head_logic = function(self,dtime) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua index 72612b1ebd..893f8eeded 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua @@ -312,7 +312,7 @@ mobs.calculate_pitch = function(pos1, pos2) return false end - return(minetest_dir_to_yaw(vector.new(vector.distance(vector.new(pos1.x,0,pos1.z),vector.new(pos2.x,0,pos2.z)),0,pos1.y - pos2.y)) + HALF_PI) + return minetest_dir_to_yaw(vector.new(vector.distance(vector.new(pos1.x,0,pos1.z),vector.new(pos2.x,0,pos2.z)),0,pos1.y - pos2.y)) + HALF_PI end --make mobs fly up or down based on their y difference diff --git a/mods/ENTITIES/mcl_mobs/api/spawning.lua b/mods/ENTITIES/mcl_mobs/api/spawning.lua index 08b161527a..bf7176b999 100644 --- a/mods/ENTITIES/mcl_mobs/api/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/api/spawning.lua @@ -501,7 +501,7 @@ local position_calculation = function(pos) pos.z = pos.z + math_random(inner,outer)*int[math_random(1,2)] pos.x = pos.x + math_random(-outer,outer) end - return(pos) + return pos end --[[ diff --git a/mods/HUD/mcl_experience/init.lua b/mods/HUD/mcl_experience/init.lua index 53376c63f7..a40599d17c 100644 --- a/mods/HUD/mcl_experience/init.lua +++ b/mods/HUD/mcl_experience/init.lua @@ -120,9 +120,9 @@ end hud_manager.hud_exists = function(player,hud_name) local name = player:get_player_name() if player_huds[name] and player_huds[name][hud_name] then - return(true) + return true else - return(false) + return false end end ------------------- @@ -150,7 +150,7 @@ end) function mcl_experience.get_player_xp_level(player) local name = player:get_player_name() - return(pool[name].level) + return pool[name].level end function mcl_experience.set_player_xp_level(player,level) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 47db36870c..d2db2281a4 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -7,7 +7,7 @@ end function mcl_enchanting.get_enchantments(itemstack) if not itemstack then - return({}) + return {} end return minetest.deserialize(itemstack:get_meta():get_string("mcl_enchanting:enchantments")) or {} end diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index e3f6b48298..f939b9c1a1 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -15,7 +15,7 @@ local function ecb_place(blockpos, action, calls_remaining, param) end end mcl_structures.place_schematic = function(pos, schematic, rotation, replacements, force_placement, flags, after_placement_callback, pr, callback_param) - local s = loadstring(minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return(schematic)")() + local s = loadstring(minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic")() if s and s.size then local x, z = s.size.x, s.size.z if rotation then diff --git a/mods/MAPGEN/mcl_villages/buildings.lua b/mods/MAPGEN/mcl_villages/buildings.lua index 9d8e7580fe..3f4490bf9f 100644 --- a/mods/MAPGEN/mcl_villages/buildings.lua +++ b/mods/MAPGEN/mcl_villages/buildings.lua @@ -14,7 +14,7 @@ function settlements.build_schematic(vm, data, va, pos, building, replace_wall, -- schematic conversion to lua local schem_lua = minetest.serialize_schematic(building, "lua", - {lua_use_comments = false, lua_num_indent_spaces = 0}).." return(schematic)" + {lua_use_comments = false, lua_num_indent_spaces = 0}).." return schematic" -- replace material if replace_wall == "y" then schem_lua = schem_lua:gsub("mcl_core:cobble", material) @@ -228,7 +228,7 @@ function settlements.place_schematics(settlement_info, pr) -- schematic conversion to lua local schem_lua = minetest.serialize_schematic(building, "lua", - {lua_use_comments = false, lua_num_indent_spaces = 0}).." return(schematic)" + {lua_use_comments = false, lua_num_indent_spaces = 0}).." return schematic" schem_lua = schem_lua:gsub("mcl_core:stonebrickcarved", "mcl_villages:stonebrickcarved") -- replace material if replace_wall then diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 3ad6ba6e80..40752b8351 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -49,7 +49,7 @@ local player_collision = function(player) end end - return({x,z}) + return {x,z} end -- converts yaw to degrees From 9e074af07f542adfadbc3e16456571b31579309e Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 25 May 2021 12:52:25 +0200 Subject: [PATCH 03/14] unify code style [1] --- CONTRIBUTING.md | 2 +- mods/CORE/_mcl_autogroup/init.lua | 2 +- mods/CORE/mcl_attached/init.lua | 21 ++++--- mods/CORE/mcl_util/init.lua | 4 +- mods/ENTITIES/mcl_item_entity/init.lua | 12 ++-- mods/ENTITIES/mcl_minecarts/init.lua | 4 +- mods/ENTITIES/mcl_minecarts/rails.lua | 2 +- .../mcl_mobs/api/mob_functions/ai.lua | 28 ++++----- mods/ENTITIES/mcl_mobs/api/spawning.lua | 8 +-- mods/ITEMS/REDSTONE/mesecons/presets.lua | 4 +- mods/ITEMS/REDSTONE/mesecons/services.lua | 6 +- mods/ITEMS/REDSTONE/mesecons_button/init.lua | 2 +- mods/ITEMS/mcl_fences/init.lua | 4 +- mods/ITEMS/mcl_fire/init.lua | 2 +- mods/ITEMS/mcl_fishing/init.lua | 11 ++-- mods/ITEMS/xpanes/init.lua | 2 +- mods/MAPGEN/mcl_biomes/init.lua | 8 +-- mods/MAPGEN/mcl_mapgen_core/init.lua | 16 ++--- mods/MAPGEN/mcl_strongholds/init.lua | 4 +- mods/MAPGEN/mcl_structures/init.lua | 61 ++++++++++--------- mods/MAPGEN/mcl_villages/const.lua | 2 +- mods/MAPGEN/tsm_railcorridors/gameconfig.lua | 2 +- mods/MAPGEN/tsm_railcorridors/init.lua | 6 +- mods/PLAYER/mcl_playerinfo/init.lua | 4 +- mods/PLAYER/mcl_playerplus/init.lua | 5 +- mods/PLAYER/mcl_skins/init.lua | 11 ++-- mods/PLAYER/mcl_sprint/init.lua | 2 +- 27 files changed, 118 insertions(+), 117 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21facbd1b1..5758d194f3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ # Contributing to MineClone 2 -So you want to MineClone 2? +So you want to contribute to MineClone 2? Wow, thank you! :-) But first, some things to note: diff --git a/mods/CORE/_mcl_autogroup/init.lua b/mods/CORE/_mcl_autogroup/init.lua index e6b3aa2d0f..76c68122b0 100644 --- a/mods/CORE/_mcl_autogroup/init.lua +++ b/mods/CORE/_mcl_autogroup/init.lua @@ -298,7 +298,7 @@ function mcl_autogroup.get_wear(toolname, diggroup) return math.ceil(65535 / uses) end -local overwrite = function() +local function overwrite() for nname, ndef in pairs(minetest.registered_nodes) do local newgroups = table.copy(ndef.groups) if (nname ~= "ignore" and ndef.diggable) then diff --git a/mods/CORE/mcl_attached/init.lua b/mods/CORE/mcl_attached/init.lua index 146cb22514..4f538e104b 100644 --- a/mods/CORE/mcl_attached/init.lua +++ b/mods/CORE/mcl_attached/init.lua @@ -1,17 +1,21 @@ +local vector = vector + +local facedir_to_dir = minetest.facedir_to_dir +local get_item_group = minetest.get_item_group +local remove_node = minetest.remove_node +local get_node = minetest.get_node + local original_function = minetest.check_single_for_falling -minetest.check_single_for_falling = function(pos) +function minetest.check_single_for_falling(pos) local ret_o = original_function(pos) - local ret = false local node = minetest.get_node(pos) - if minetest.get_item_group(node.name, "attached_node_facedir") ~= 0 then - local dir = minetest.facedir_to_dir(node.param2) + if get_item_group(node.name, "attached_node_facedir") ~= 0 then + local dir = facedir_to_dir(node.param2) if dir then - local cpos = vector.add(pos, dir) - local cnode = minetest.get_node(cpos) - if minetest.get_item_group(cnode.name, "solid") == 0 then - minetest.remove_node(pos) + if get_item_group(get_node(vector.add(pos, dir)).name, "solid") == 0 then + remove_node(pos) local drops = minetest.get_node_drops(node.name, "") for dr=1, #drops do minetest.add_item(pos, drops[dr]) @@ -20,7 +24,6 @@ minetest.check_single_for_falling = function(pos) end end end - return ret_o or ret end diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 0168229f2c..1ac2c1f9b6 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -150,7 +150,7 @@ function mcl_util.get_eligible_transfer_item_slot(src_inventory, src_list, dst_i end -- Returns true if itemstack is a shulker box -local is_not_shulker_box = function(itemstack) +local function is_not_shulker_box(itemstack) local g = minetest.get_item_group(itemstack:get_name(), "shulker_box") return g == 0 or g == nil end @@ -212,7 +212,7 @@ function mcl_util.move_item_container(source_pos, destination_pos, source_list, end -- Normalize double container by forcing to always use the left segment first - local normalize_double_container = function(pos, node, ctype) + local function normalize_double_container(pos, node, ctype) if ctype == 6 then pos = mcl_util.get_double_container_neighbor_pos(pos, node.param2, "right") if not pos then diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 0c26c38c8e..a73f586e9c 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -1,5 +1,5 @@ --these are lua locals, used for higher performance -local minetest,math,vector,ipairs = minetest,math,vector,ipairs +local minetest, math, vector, ipairs = minetest, math, vector, ipairs --this is used for the player pool in the sound buffer local pool = {} @@ -38,7 +38,7 @@ item_drop_settings.drop_single_item = false --if true, the drop control dro item_drop_settings.magnet_time = 0.75 -- how many seconds an item follows the player before giving up -local get_gravity = function() +local function get_gravity() return tonumber(minetest.settings:get("movement_gravity")) or 9.81 end @@ -60,7 +60,7 @@ mcl_item_entity.register_pickup_achievement("mcl_mobitems:blaze_rod", "mcl:blaze mcl_item_entity.register_pickup_achievement("mcl_mobitems:leather", "mcl:killCow") mcl_item_entity.register_pickup_achievement("mcl_core:diamond", "mcl:diamonds") -local check_pickup_achievements = function(object, player) +local function check_pickup_achievements(object, player) if has_awards then local itemname = ItemStack(object:get_luaentity().itemstring):get_name() local playername = player:get_player_name() @@ -72,7 +72,7 @@ local check_pickup_achievements = function(object, player) end end -local enable_physics = function(object, luaentity, ignore_check) +local function enable_physics(object, luaentity, ignore_check) if luaentity.physical_state == false or ignore_check == true then luaentity.physical_state = true object:set_properties({ @@ -83,7 +83,7 @@ local enable_physics = function(object, luaentity, ignore_check) end end -local disable_physics = function(object, luaentity, ignore_check, reset_movement) +local function disable_physics(object, luaentity, ignore_check, reset_movement) if luaentity.physical_state == true or ignore_check == true then luaentity.physical_state = false object:set_properties({ @@ -98,13 +98,11 @@ end minetest.register_globalstep(function(dtime) - tick = not tick for _,player in pairs(minetest.get_connected_players()) do if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then - local name = player:get_player_name() local pos = player:get_pos() diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index e741fb0bc2..6fd98f5501 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -496,7 +496,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o end -- Place a minecart at pointed_thing -mcl_minecarts.place_minecart = function(itemstack, pointed_thing, placer) +function mcl_minecarts.place_minecart(itemstack, pointed_thing, placer) if not pointed_thing.type == "node" then return end @@ -540,7 +540,7 @@ mcl_minecarts.place_minecart = function(itemstack, pointed_thing, placer) end -local register_craftitem = function(itemstring, entity_id, description, tt_help, longdesc, usagehelp, icon, creative) +local function register_craftitem(itemstring, entity_id, description, tt_help, longdesc, usagehelp, icon, creative) entity_mapping[itemstring] = entity_id local groups = { minecart = 1, transport = 1 } diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index 4c26aea8c0..53ec86d946 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -1,7 +1,7 @@ local S = minetest.get_translator("mcl_minecarts") -- Template rail function -local register_rail = function(itemstring, tiles, def_extras, creative) +local function register_rail(itemstring, tiles, def_extras, creative) local groups = {handy=1,pickaxey=1, attached_node=1,rail=1,connect_to_raillike=minetest.raillike_group("rail"),dig_by_water=1,destroy_by_lava_flow=1, transport=1} if creative == false then groups.not_in_creative_inventory = 1 diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index ef26874552..894a1f5e41 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -13,9 +13,8 @@ local minetest_get_node_light = minetest.get_node_light local DOUBLE_PI = math.pi * 2 local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125 - --a simple helper function which is too small to move into movement.lua -local quick_rotate = function(self,dtime) +local function quick_rotate(self,dtime) self.yaw = self.yaw + THIRTY_SECONDTH_PI if self.yaw > DOUBLE_PI then self.yaw = self.yaw - DOUBLE_PI @@ -39,7 +38,7 @@ end ]]-- --this is basically reverse jump_check -local cliff_check = function(self,dtime) +local function cliff_check(self,dtime) --mobs will flip out if they are falling without this if self.object:get_velocity().y ~= 0 then return false @@ -115,7 +114,7 @@ local function land_state_switch(self, dtime) end -- states are executed here -local land_state_execution = function(self,dtime) +local function land_state_execution(self, dtime) --[[ -- this is a debug which shows the timer and makes mobs breed 100 times faster print(self.breed_timer) @@ -391,7 +390,7 @@ end -- state switching logic (stand, walk, run, attacks) local swim_state_list_wandering = {"stand", "swim"} -local swim_state_switch = function(self, dtime) +local function swim_state_switch(self, dtime) self.state_timer = self.state_timer - dtime if self.state_timer <= 0 then self.state_timer = math.random(4,10) + math.random() @@ -401,7 +400,7 @@ end --check if a mob needs to turn while swimming -local swim_turn_check = function(self,dtime) +local function swim_turn_check(self,dtime) local pos = self.object:get_pos() pos.y = pos.y + 0.1 @@ -420,8 +419,7 @@ local swim_turn_check = function(self,dtime) end --this is to swap the built in engine acceleration modifier -local swim_physics_swapper = function(self,inside_swim_node) - +local function swim_physics_swapper(self, inside_swim_node) --should be swimming, gravity is applied, switch to floating if inside_swim_node and self.object:get_acceleration().y ~= 0 then self.object:set_acceleration(vector.new(0,0,0)) @@ -435,7 +433,7 @@ end local random_pitch_multiplier = {-1,1} -- states are executed here -local swim_state_execution = function(self,dtime) +local function swim_state_execution(self, dtime) local pos = self.object:get_pos() @@ -452,7 +450,7 @@ local swim_state_execution = function(self,dtime) end --turn gravity on or off - swim_physics_swapper(self,inside_swim_node) + swim_physics_swapper(self, inside_swim_node) --swim properly if inside swim node if inside_swim_node then @@ -530,7 +528,7 @@ ______ _ -- state switching logic (stand, walk, run, attacks) local fly_state_list_wandering = {"stand", "fly"} -local fly_state_switch = function(self, dtime) +local function fly_state_switch(self, dtime) if self.hostile and self.attacking then self.state = "attack" @@ -546,7 +544,7 @@ end --check if a mob needs to turn while flying -local fly_turn_check = function(self,dtime) +local function fly_turn_check(self, dtime) local pos = self.object:get_pos() pos.y = pos.y + 0.1 @@ -565,7 +563,7 @@ local fly_turn_check = function(self,dtime) end --this is to swap the built in engine acceleration modifier -local fly_physics_swapper = function(self,inside_fly_node) +local function fly_physics_swapper(self, inside_fly_node) --should be flyming, gravity is applied, switch to floating if inside_fly_node and self.object:get_acceleration().y ~= 0 then @@ -580,7 +578,7 @@ end local random_pitch_multiplier = {-1,1} -- states are executed here -local fly_state_execution = function(self,dtime) +local function fly_state_execution(self, dtime) local pos = self.object:get_pos() pos.y = pos.y + 0.1 local current_node = minetest_get_node(pos).name @@ -794,7 +792,7 @@ ___ ___ _ _ _ ]]-- --the main loop -mobs.mob_step = function(self, dtime) +function mobs.mob_step(self, dtime) --do not continue if non-existent if not self or not self.object or not self.object:get_luaentity() then diff --git a/mods/ENTITIES/mcl_mobs/api/spawning.lua b/mods/ENTITIES/mcl_mobs/api/spawning.lua index bf7176b999..70167b4213 100644 --- a/mods/ENTITIES/mcl_mobs/api/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/api/spawning.lua @@ -167,7 +167,7 @@ Overworld regular: -- count how many mobs are in an area -local count_mobs = function(pos) +local function count_mobs(pos) local num = 0 for _,object in pairs(get_objects_inside_radius(pos, aoc_range)) do if object and object:get_luaentity() and object:get_luaentity()._cmi_is_mob then @@ -242,8 +242,7 @@ function mobs:spawn_specific(name, dimension, type_of_spawning, biomes, min_ligh end --[[ - local spawn_action - spawn_action = function(pos, node, active_object_count, active_object_count_wider, name) + local function spawn_action(pos, node, active_object_count, active_object_count_wider, name) local orig_pos = table.copy(pos) -- is mob actually registered? @@ -486,7 +485,8 @@ local axis local inner = 15 local outer = 64 local int = {-1,1} -local position_calculation = function(pos) + +local function position_calculation(pos) pos = vector_floor(pos) diff --git a/mods/ITEMS/REDSTONE/mesecons/presets.lua b/mods/ITEMS/REDSTONE/mesecons/presets.lua index f624c52fe5..d9d8418d80 100644 --- a/mods/ITEMS/REDSTONE/mesecons/presets.lua +++ b/mods/ITEMS/REDSTONE/mesecons/presets.lua @@ -96,12 +96,12 @@ local function rules_from_dir(ruleset, dir) if dir.z == -1 then return ruleset.zn end end -mesecon.rules.buttonlike_get = function(node) +function mesecon.rules.buttonlike_get(node) local dir = minetest.facedir_to_dir(node.param2) return rules_from_dir(rules_buttonlike, dir) end -mesecon.rules.wallmounted_get = function(node) +function mesecon.rules.wallmounted_get(node) local dir = minetest.wallmounted_to_dir(node.param2) return rules_from_dir(rules_wallmounted, dir) end diff --git a/mods/ITEMS/REDSTONE/mesecons/services.lua b/mods/ITEMS/REDSTONE/mesecons/services.lua index 1e3e6237b8..7d1fce2d8c 100644 --- a/mods/ITEMS/REDSTONE/mesecons/services.lua +++ b/mods/ITEMS/REDSTONE/mesecons/services.lua @@ -1,6 +1,6 @@ -- Dig and place services -mesecon.on_placenode = function(pos, node) +function mesecon.on_placenode(pos, node) mesecon.execute_autoconnect_hooks_now(pos, node) -- Receptors: Send on signal when active @@ -70,7 +70,7 @@ mesecon.on_placenode = function(pos, node) end end -mesecon.on_dignode = function(pos, node) +function mesecon.on_dignode(pos, node) if mesecon.is_conductor_on(node) then mesecon.receptor_off(pos, mesecon.conductor_get_rules(node)) elseif mesecon.is_receptor_on(node.name) then @@ -95,7 +95,7 @@ mesecon.on_dignode = function(pos, node) mesecon.execute_autoconnect_hooks_queue(pos, node) end -mesecon.on_blastnode = function(pos, node) +function mesecon.on_blastnode(pos, node) local node = minetest.get_node(pos) minetest.remove_node(pos) mesecon.on_dignode(pos, node) diff --git a/mods/ITEMS/REDSTONE/mesecons_button/init.lua b/mods/ITEMS/REDSTONE/mesecons_button/init.lua index 377a24c00a..a8c671004a 100644 --- a/mods/ITEMS/REDSTONE/mesecons_button/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_button/init.lua @@ -21,7 +21,7 @@ local boxes_on = { } -- Push the button -mesecon.push_button = function(pos, node) +function mesecon.push_button(pos, node) -- No-op if button is already pushed if mesecon.is_receptor_on(node) then return diff --git a/mods/ITEMS/mcl_fences/init.lua b/mods/ITEMS/mcl_fences/init.lua index e607822152..ddd85d470c 100644 --- a/mods/ITEMS/mcl_fences/init.lua +++ b/mods/ITEMS/mcl_fences/init.lua @@ -20,7 +20,7 @@ local cz2 = {-2/16, -0.5, 2/16, 2/16, 1.01, 0.5} --unten(quer) z mcl_fences = {} -mcl_fences.register_fence = function(id, fence_name, texture, groups, hardness, blast_resistance, connects_to, sounds) +function mcl_fences.register_fence(id, fence_name, texture, groups, hardness, blast_resistance, connects_to, sounds) local cgroups = table.copy(groups) if cgroups == nil then cgroups = {} end cgroups.fence = 1 @@ -72,7 +72,7 @@ mcl_fences.register_fence = function(id, fence_name, texture, groups, hardness, return fence_id end -mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close) +function mcl_fences.register_fence_gate(id, fence_gate_name, texture, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close) local meta2 local state2 = 0 diff --git a/mods/ITEMS/mcl_fire/init.lua b/mods/ITEMS/mcl_fire/init.lua index 176fb250c9..f1a95fec6b 100644 --- a/mods/ITEMS/mcl_fire/init.lua +++ b/mods/ITEMS/mcl_fire/init.lua @@ -522,7 +522,7 @@ end -- * pointed_thing: Pointed thing to ignite -- * player: Player who sets fire or nil if nobody -- * allow_on_fire: If false, can't ignite fire on fire (default: true) -mcl_fire.set_fire = function(pointed_thing, player, allow_on_fire) +function mcl_fire.set_fire(pointed_thing, player, allow_on_fire) local pname if player == nil then pname = "" diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index cc7c5cca51..567e96e96b 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -305,7 +305,7 @@ local flying_bobber_ENTITY={ } -- Movement function of flying bobber -local flying_bobber_on_step = function(self, dtime) +local function flying_bobber_on_step(self, dtime) self.timer=self.timer+dtime local pos = self.object:get_pos() local node = minetest.get_node(pos) @@ -315,12 +315,9 @@ local flying_bobber_on_step = function(self, dtime) -- Destroy when hitting a solid node if self._lastpos.x~=nil then if (def and (def.walkable or def.liquidtype == "flowing" or def.liquidtype == "source")) or not def then - local make_child= function(object) - local ent = object:get_luaentity() - ent.player = self._thrower - ent.child = true - end - make_child(minetest.add_entity(self._lastpos, "mcl_fishing:bobber_entity")) + local ent = minetest.add_entity(self._lastpos, "mcl_fishing:bobber_entity"):get_luaentity() + ent.player = self._thrower + ent.child = true self.object:remove() return end diff --git a/mods/ITEMS/xpanes/init.lua b/mods/ITEMS/xpanes/init.lua index b7faffb3bb..472b3efdf1 100644 --- a/mods/ITEMS/xpanes/init.lua +++ b/mods/ITEMS/xpanes/init.lua @@ -170,7 +170,7 @@ end local canonical_color = "yellow" -- Register glass pane (stained and unstained) -local pane = function(description, node, append) +local function pane(description, node, append) local texture1, longdesc, entry_name, create_entry local is_canonical = true -- Special case: Default (unstained) glass texture diff --git a/mods/MAPGEN/mcl_biomes/init.lua b/mods/MAPGEN/mcl_biomes/init.lua index 4e01df5f2a..9108b75c14 100644 --- a/mods/MAPGEN/mcl_biomes/init.lua +++ b/mods/MAPGEN/mcl_biomes/init.lua @@ -1775,7 +1775,7 @@ local function register_biomelike_ores() -- Mesa strata (registered as sheet ores) -- Helper function to create strata. - local stratum = function(y_min, height, color, seed, is_perfect) + local function stratum(y_min, height, color, seed, is_perfect) if not height then height = 1 end @@ -3079,7 +3079,7 @@ local function register_decorations() }) -- Doubletall grass - local register_doubletall_grass = function(offset, scale, biomes) + local function register_doubletall_grass(offset, scale, biomes) for b=1, #biomes do local param2 = minetest.registered_biomes[biomes[b]]._mcl_palette_index @@ -3115,7 +3115,7 @@ local function register_decorations() register_doubletall_grass(-0.0005, -0.03, {"Savanna", "SavannaM"}) -- Large ferns - local register_double_fern = function(offset, scale, biomes) + local function register_double_fern(offset, scale, biomes) for b=1, #biomes do local param2 = minetest.registered_biomes[biomes[b]]._mcl_palette_index minetest.register_decoration({ @@ -3149,7 +3149,7 @@ local function register_decorations() register_double_fern(0.15, 0.1, { "JungleM" }) -- Large flowers - local register_large_flower = function(name, biomes, seed, offset, flower_forest_offset) + local function register_large_flower(name, biomes, seed, offset, flower_forest_offset) local maxi if flower_forest_offset then maxi = 2 diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 285da25c23..b3db122e6e 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -765,7 +765,7 @@ local function register_mgv6_decorations() }) -- Large flowers - local register_large_flower = function(name, seed, offset) + local function register_large_flower(name, seed, offset) minetest.register_decoration({ deco_type = "schematic", schematic = { @@ -1169,7 +1169,7 @@ end -- minp and maxp (from an on_generated callback) and returns the real world coordinates -- as X, Z. -- Inverse function of xz_to_biomemap ---[[local biomemap_to_xz = function(index, minp, maxp) +--[[local function biomemap_to_xz(index, minp, maxp) local xwidth = maxp.x - minp.x + 1 local zwidth = maxp.z - minp.z + 1 local x = ((index-1) % xwidth) + minp.x @@ -1180,7 +1180,7 @@ end]] -- Takes x and z coordinates and minp and maxp of a generated chunk -- (in on_generated callback) and returns a biomemap index) -- Inverse function of biomemap_to_xz -local xz_to_biomemap_index = function(x, z, minp, maxp) +local function xz_to_biomemap_index(x, z, minp, maxp) local xwidth = maxp.x - minp.x + 1 local zwidth = maxp.z - minp.z + 1 local minix = x % xwidth @@ -1404,7 +1404,7 @@ local function generate_structures(minp, maxp, blockseed, biomemap) -- TODO: Spawn witch in or around hut when the mob sucks less. - local place_tree_if_free = function(pos, prev_result) + local function place_tree_if_free(pos, prev_result) local nn = minetest.get_node(pos).name if nn == "mcl_flowers:waterlily" or nn == "mcl_core:water_source" or nn == "mcl_core:water_flowing" or nn == "air" then minetest.set_node(pos, {name="mcl_core:tree", param2=0}) @@ -1720,7 +1720,7 @@ end -- Generate mushrooms in caves manually. -- Minetest's API does not support decorations in caves yet. :-( -local generate_underground_mushrooms = function(minp, maxp, seed) +local function generate_underground_mushrooms(minp, maxp, seed) local pr_shroom = PseudoRandom(seed-24359) -- Generate rare underground mushrooms -- TODO: Make them appear in groups, use Perlin noise @@ -1754,7 +1754,7 @@ else end -- Generate Nether decorations manually: Eternal fire, mushrooms, nether wart -- Minetest's API does not support decorations in caves yet. :-( -local generate_nether_decorations = function(minp, maxp, seed) +local function generate_nether_decorations(minp, maxp, seed) local pr_nether = PseudoRandom(seed+667) if minp.y > mcl_vars.mg_nether_max or maxp.y < mcl_vars.mg_nether_min then @@ -1771,7 +1771,7 @@ local generate_nether_decorations = function(minp, maxp, seed) local ssand = minetest.find_nodes_in_area_under_air(minp, maxp, {"mcl_nether:soul_sand"}) -- Helper function to spawn “fake” decoration - local special_deco = function(nodes, spawn_func) + local function special_deco(nodes, spawn_func) for n = 1, #nodes do bpos = {x = nodes[n].x, y = nodes[n].y + 1, z = nodes[n].z } @@ -1912,7 +1912,7 @@ end local bedrock_check if mcl_vars.mg_bedrock_is_rough then - bedrock_check = function(pos, _, pr) + function bedrock_check(pos, _, pr) local y = pos.y -- Bedrock layers with increasing levels of roughness, until a perfecly flat bedrock later at the bottom layer -- This code assumes a bedrock height of 5 layers. diff --git a/mods/MAPGEN/mcl_strongholds/init.lua b/mods/MAPGEN/mcl_strongholds/init.lua index e465b2e407..083172a3cb 100644 --- a/mods/MAPGEN/mcl_strongholds/init.lua +++ b/mods/MAPGEN/mcl_strongholds/init.lua @@ -25,7 +25,7 @@ local superflat = mg_name == "flat" and minetest.get_mapgen_setting("mcl_superfl -- The stronghold positions are based on the world seed. -- The actual position might be offset by a few blocks because it might be shifted -- to make sure the end portal room is completely within the boundaries of a mapchunk. -local init_strongholds = function() +local function init_strongholds() if strongholds_inited then return end @@ -67,7 +67,7 @@ local init_strongholds = function() end -- Stronghold generation for register_on_generated. -local generate_strongholds = function(minp, maxp, blockseed) +local function generate_strongholds(minp, maxp, blockseed) local pr = PseudoRandom(blockseed) for s=1, #strongholds do if not strongholds[s].generated then diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index f939b9c1a1..dfb7da24bf 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -1,5 +1,9 @@ -local S = minetest.get_translator("mcl_structures") -mcl_structures ={} +local modname = minetest.get_current_modname() +local S = minetest.get_translator(modname) +local modpath = minetest.get_modpath(modname) + +mcl_structures = {} + local rotations = { "0", "90", @@ -14,7 +18,8 @@ local function ecb_place(blockpos, action, calls_remaining, param) param.after_placement_callback(param.p1, param.p2, param.size, param.rotation, param.pr, param.callback_param) end end -mcl_structures.place_schematic = function(pos, schematic, rotation, replacements, force_placement, flags, after_placement_callback, pr, callback_param) + +function mcl_structures.place_schematic(pos, schematic, rotation, replacements, force_placement, flags, after_placement_callback, pr, callback_param) local s = loadstring(minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic")() if s and s.size then local x, z = s.size.x, s.size.z @@ -37,7 +42,7 @@ mcl_structures.place_schematic = function(pos, schematic, rotation, replacements end end -mcl_structures.get_struct = function(file) +function mcl_structures.get_struct(file) local localfile = minetest.get_modpath("mcl_structures").."/schematics/"..file local file, errorload = io.open(localfile, "rb") if errorload ~= nil then @@ -53,7 +58,7 @@ end -- Call on_construct on pos. -- Useful to init chests from formspec. -local init_node_construct = function(pos) +local function init_node_construct(pos) local node = minetest.get_node(pos) local def = minetest.registered_nodes[node.name] if def and def.on_construct then @@ -64,7 +69,7 @@ local init_node_construct = function(pos) end -- The call of Struct -mcl_structures.call_struct = function(pos, struct_style, rotation, pr) +function mcl_structures.call_struct(pos, struct_style, rotation, pr) minetest.log("action","[mcl_structures] call_struct " .. struct_style.." at "..minetest.pos_to_string(pos)) if not rotation then rotation = "random" @@ -96,13 +101,13 @@ mcl_structures.call_struct = function(pos, struct_style, rotation, pr) end end -mcl_structures.generate_desert_well = function(pos, rot) +function mcl_structures.generate_desert_well(pos, rot) local newpos = {x=pos.x,y=pos.y-2,z=pos.z} - local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_desert_well.mts" + local path = modpath.."/schematics/mcl_structures_desert_well.mts" return mcl_structures.place_schematic(newpos, path, rot or "0", nil, true) end -mcl_structures.generate_igloo = function(pos, rotation, pr) +function mcl_structures.generate_igloo(pos, rotation, pr) -- Place igloo local success, rotation = mcl_structures.generate_igloo_top(pos, pr) -- Place igloo basement with 50% chance @@ -148,7 +153,7 @@ mcl_structures.generate_igloo = function(pos, rotation, pr) else return success end - local set_brick = function(pos) + local function set_brick(pos) local c = pr:next(1, 3) -- cracked chance local m = pr:next(1, 10) -- chance for monster egg local brick @@ -198,11 +203,11 @@ mcl_structures.generate_igloo = function(pos, rotation, pr) return success end -mcl_structures.generate_igloo_top = function(pos, pr) +function mcl_structures.generate_igloo_top(pos, pr) -- FIXME: This spawns bookshelf instead of furnace. Fix this! -- Furnace does ot work atm because apparently meta is not set. :-( local newpos = {x=pos.x,y=pos.y-1,z=pos.z} - local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_igloo_top.mts" + local path = modpath.."/schematics/mcl_structures_igloo_top.mts" local rotation = tostring(pr:next(0,3)*90) return mcl_structures.place_schematic(newpos, path, rotation, nil, true), rotation end @@ -250,22 +255,22 @@ local function igloo_placement_callback(p1, p2, size, orientation, pr) mcl_loot.fill_inventory(inv, "main", lootitems, pr) end -mcl_structures.generate_igloo_basement = function(pos, orientation, pr) +function mcl_structures.generate_igloo_basement(pos, orientation, pr) -- TODO: Add brewing stand -- TODO: Add monster eggs -- TODO: Spawn villager and zombie villager - local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_igloo_basement.mts" + local path = modpath.."/schematics/mcl_structures_igloo_basement.mts" mcl_structures.place_schematic(pos, path, orientation, nil, true, nil, igloo_placement_callback, pr) end -mcl_structures.generate_boulder = function(pos, rotation, pr) +function mcl_structures.generate_boulder(pos, rotation, pr) -- Choose between 2 boulder sizes (2×2×2 or 3×3×3) local r = pr:next(1, 10) local path if r <= 3 then - path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_boulder_small.mts" + path = modpath.."/schematics/mcl_structures_boulder_small.mts" else - path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_boulder.mts" + path = modpath.."/schematics/mcl_structures_boulder.mts" end local newpos = {x=pos.x,y=pos.y-1,z=pos.z} @@ -284,22 +289,22 @@ local function hut_placement_callback(p1, p2, size, orientation, pr) end end -mcl_structures.generate_witch_hut = function(pos, rotation, pr) +function mcl_structures.generate_witch_hut(pos, rotation, pr) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_witch_hut.mts" mcl_structures.place_schematic(pos, path, rotation, nil, true, nil, hut_placement_callback, pr) end -mcl_structures.generate_ice_spike_small = function(pos, rotation) +function mcl_structures.generate_ice_spike_small(pos, rotation) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_ice_spike_small.mts" return minetest.place_schematic(pos, path, rotation or "random", nil, false) -- don't serialize schematics for registered biome decorations, for MT 5.4.0 end -mcl_structures.generate_ice_spike_large = function(pos, rotation) +function mcl_structures.generate_ice_spike_large(pos, rotation) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_ice_spike_large.mts" return minetest.place_schematic(pos, path, rotation or "random", nil, false) -- don't serialize schematics for registered biome decorations, for MT 5.4.0 end -mcl_structures.generate_fossil = function(pos, rotation, pr) +function mcl_structures.generate_fossil(pos, rotation, pr) -- Generates one out of 8 possible fossil pieces local newpos = {x=pos.x,y=pos.y-1,z=pos.z} local fossils = { @@ -317,17 +322,17 @@ mcl_structures.generate_fossil = function(pos, rotation, pr) return mcl_structures.place_schematic(newpos, path, rotation or "random", nil, true) end -mcl_structures.generate_end_exit_portal = function(pos, rot) +function mcl_structures.generate_end_exit_portal(pos, rot) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_exit_portal.mts" return mcl_structures.place_schematic(pos, path, rot or "0", {["mcl_portals:portal_end"] = "air"}, true) end -mcl_structures.generate_end_exit_portal_open = function(pos, rot) +function mcl_structures.generate_end_exit_portal_open(pos, rot) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_exit_portal.mts" return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) end -mcl_structures.generate_end_gateway_portal = function(pos, rot) +function mcl_structures.generate_end_gateway_portal(pos, rot) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_gateway_portal.mts" return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) end @@ -410,7 +415,7 @@ local function shrine_placement_callback(p1, p2, size, rotation, pr) end end -mcl_structures.generate_end_portal_shrine = function(pos, rotation, pr) +function mcl_structures.generate_end_portal_shrine(pos, rotation, pr) local offset = {x=6, y=4, z=6} --local size = {x=13, y=8, z=13} local newpos = { x = pos.x - offset.x, y = pos.y, z = pos.z - offset.z } @@ -493,7 +498,7 @@ local function temple_placement_callback(p1, p2, size, rotation, pr) end end -mcl_structures.generate_desert_temple = function(pos, rotation, pr) +function mcl_structures.generate_desert_temple(pos, rotation, pr) -- No Generating for the temple ... Why using it ? No Change local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_desert_temple.mts" local newpos = {x=pos.x,y=pos.y-12,z=pos.z} @@ -517,7 +522,7 @@ Format of return value: TODO: Implement this function for all other structure types as well. ]] -mcl_structures.get_registered_structures = function(structure_type) +function mcl_structures.get_registered_structures(structure_type) if registered_structures[structure_type] then return table.copy(registered_structures[structure_type]) else @@ -527,7 +532,7 @@ end -- Register a structures table for the given type. The table format is the same as for -- mcl_structures.get_registered_structures. -mcl_structures.register_structures = function(structure_type, structures) +function mcl_structures.register_structures(structure_type, structures) registered_structures[structure_type] = structures end diff --git a/mods/MAPGEN/mcl_villages/const.lua b/mods/MAPGEN/mcl_villages/const.lua index e5cbc9b391..eb7806209d 100644 --- a/mods/MAPGEN/mcl_villages/const.lua +++ b/mods/MAPGEN/mcl_villages/const.lua @@ -1,5 +1,5 @@ -- switch for debugging -settlements.debug = function(message) +function settlements.debug(message) -- minetest.chat_send_all(message) -- minetest.log("warning", "[mcl_villages] "..message) minetest.log("verbose", "[mcl_villages] "..message) diff --git a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua index 904c3af08c..168ecf535a 100644 --- a/mods/MAPGEN/tsm_railcorridors/gameconfig.lua +++ b/mods/MAPGEN/tsm_railcorridors/gameconfig.lua @@ -27,7 +27,7 @@ if mg_name == "v6" then } else -- This generates dark oak wood in mesa biomes and oak wood everywhere else. - tsm_railcorridors.nodes.corridor_woods_function = function(pos, node) + function tsm_railcorridors.nodes.corridor_woods_function(pos, node) if minetest.get_item_group(node.name, "hardened_clay") ~= 0 then return "mcl_core:darkwood", "mcl_fences:dark_oak_fence" else diff --git a/mods/MAPGEN/tsm_railcorridors/init.lua b/mods/MAPGEN/tsm_railcorridors/init.lua index 550167dc32..d7a074a009 100644 --- a/mods/MAPGEN/tsm_railcorridors/init.lua +++ b/mods/MAPGEN/tsm_railcorridors/init.lua @@ -681,11 +681,11 @@ local function create_corridor_section(waypoint, axis, sign, up_or_down, up_or_d railsegcount = segcount end for i=1,railsegcount do - local p = {x=waypoint.x+vek.x*i, y=waypoint.y+vek.y*i-1, z=waypoint.z+vek.z*i} + local p = {x = waypoint.x + vek.x * i, y = waypoint.y + vek.y * i-1, z = waypoint.z + vek.z * i} -- Randomly returns either the left or right side of the main rail. -- Also returns offset as second return value. - local left_or_right = function(pos, vek) + local function left_or_right(pos, vek) local off if pr:next(1, 2) == 1 then -- left @@ -765,7 +765,7 @@ local function create_corridor_section(waypoint, axis, sign, up_or_down, up_or_d -- Place cobwebs left and right in the corridor if place_cobwebs and tsm_railcorridors.nodes.cobweb then -- Helper function to place a cobweb at the side (based on chance an Perlin noise) - local cobweb_at_side = function(basepos, vek) + local function cobweb_at_side(basepos, vek) if pr:next(1,5) == 1 then local h = pr:next(0, 2) -- 3 possible cobweb heights local cpos = {x=basepos.x+vek.x, y=basepos.y+h, z=basepos.z+vek.z} diff --git a/mods/PLAYER/mcl_playerinfo/init.lua b/mods/PLAYER/mcl_playerinfo/init.lua index 5086f3195b..9c5d1433f3 100644 --- a/mods/PLAYER/mcl_playerinfo/init.lua +++ b/mods/PLAYER/mcl_playerinfo/init.lua @@ -1,3 +1,5 @@ +local table = table + -- Player state for public API mcl_playerinfo = {} @@ -21,7 +23,7 @@ end local time = 0 -local get_player_nodes = function(player_pos) +local function get_player_nodes(player_pos) local work_pos = table.copy(player_pos) -- what is around me? diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 40752b8351..ceaef63460 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -25,7 +25,7 @@ local mcl_playerplus_internal = {} local time = 0 local look_pitch = 0 -local player_collision = function(player) +local function player_collision(player) local pos = player:get_pos() --local vel = player:get_velocity() @@ -48,7 +48,6 @@ local player_collision = function(player) z = z + (vec.z * force) end end - return {x,z} end @@ -57,7 +56,7 @@ local function degrees(rad) return rad * 180.0 / math.pi end -local dir_to_pitch = function(dir) +local function dir_to_pitch(dir) --local dir2 = vector.normalize(dir) local xz = math.abs(dir.x) + math.abs(dir.z) return -math.atan2(-dir.y, xz) diff --git a/mods/PLAYER/mcl_skins/init.lua b/mods/PLAYER/mcl_skins/init.lua index 0f23519abc..fb91d74d38 100644 --- a/mods/PLAYER/mcl_skins/init.lua +++ b/mods/PLAYER/mcl_skins/init.lua @@ -70,7 +70,7 @@ while true do id = id + 1 end -mcl_skins.cycle_skin = function(player) +function mcl_skins.cycle_skin(player) local skin_id = tonumber(player:get_meta():get_string("mcl_skins:skin_id")) if not skin_id then skin_id = 0 @@ -82,7 +82,7 @@ mcl_skins.cycle_skin = function(player) mcl_skins.set_player_skin(player, skin_id) end -mcl_skins.set_player_skin = function(player, skin_id) +function mcl_skins.set_player_skin(player, skin_id) if not player then return false end @@ -124,7 +124,7 @@ mcl_skins.set_player_skin = function(player, skin_id) return true end -mcl_skins.update_player_skin = function(player) +function mcl_skins.update_player_skin(player) if not player then return end @@ -134,7 +134,6 @@ end -- load player skin on join minetest.register_on_joinplayer(function(player) - local name = player:get_player_name() local skin_id = player:get_meta():get_string("mcl_skins:skin_id") local set_skin @@ -156,7 +155,7 @@ end) mcl_skins.registered_on_set_skins = {} -mcl_skins.register_on_set_skin = function(func) +function mcl_skins.register_on_set_skin(func) table.insert(mcl_skins.registered_on_set_skins, func) end @@ -231,7 +230,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end end) -mcl_skins.show_formspec = function(playername) +function mcl_skins.show_formspec(playername) local formspec = "size[7,8.5]" formspec = formspec .. "label[2,2;" .. minetest.formspec_escape(minetest.colorize("#383838", S("Select player skin:"))) .. "]" diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index 12d0394e50..546a5f4f04 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -16,7 +16,7 @@ local players = {} -- Returns true if the player with the given name is sprinting, false if not. -- Returns nil if player does not exist. -mcl_sprint.is_sprinting = function(playername) +function mcl_sprint.is_sprinting(playername) if players[playername] then return players[playername].sprinting else From 49044ac15e8bcc01044a4caf9ffa2c405723d02f Mon Sep 17 00:00:00 2001 From: AFCMS Date: Tue, 25 May 2021 13:18:12 +0200 Subject: [PATCH 04/14] unify codestyle [2] --- CONTRIBUTING.md | 22 ++++++++++++++++++++++ mods/ENVIRONMENT/mcl_moon/init.lua | 4 ++-- mods/ENVIRONMENT/mcl_weather/rain.lua | 24 +++++++++++------------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5758d194f3..023d89de89 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,6 +46,28 @@ Your commit names should be relatively descriptive, e.g. when saying "Fix #issue Contributors will be credited in `CREDITS.md`. +## Code Style + +Each mod must provide `mod.conf`. +Each mod which add API functions should store functions inside a global table named like the mod. +Object oriented API shoud be avoided e.g.:`function mobs.register_mod(self)` +Functions should be defined in this way: +``` +function mcl_xyz.stuff(param) end +``` +Insteed of this way: +``` +mcl_xyz.stuff = function(param) end +``` +Indentation must be unified, more likely with tabs. + +Time sensitive mods should make a local copy of most used API functions to improve performances. +``` +local vector = vector +local get_node = minetest.get_node +``` + + ## Features > 1.12 If you want to make a feature that was added in a Minecraft version later than 1.12, you should fork MineClone5 (mineclone5 branch in the repository) and add your changes to this. diff --git a/mods/ENVIRONMENT/mcl_moon/init.lua b/mods/ENVIRONMENT/mcl_moon/init.lua index 1a5030b4e6..200c6ca419 100644 --- a/mods/ENVIRONMENT/mcl_moon/init.lua +++ b/mods/ENVIRONMENT/mcl_moon/init.lua @@ -13,7 +13,7 @@ minetest.log("info", "[mcl_moon] Moon phase offset of this world: "..phase_offse mcl_moon = {} mcl_moon.MOON_PHASES = MOON_PHASES -mcl_moon.get_moon_phase = function() +function mcl_moon.get_moon_phase() local after_midday = 0 -- Moon phase changes after midday local tod = minetest.get_timeofday() @@ -23,7 +23,7 @@ mcl_moon.get_moon_phase = function() return (minetest.get_day_count() + phase_offset + after_midday) % MOON_PHASES end -local get_moon_texture = function() +local function get_moon_texture() local phase = mcl_moon.get_moon_phase() local x = phase % MOON_PHASES_HALF local y diff --git a/mods/ENVIRONMENT/mcl_weather/rain.lua b/mods/ENVIRONMENT/mcl_weather/rain.lua index 786e08fa96..c128da942a 100644 --- a/mods/ENVIRONMENT/mcl_weather/rain.lua +++ b/mods/ENVIRONMENT/mcl_weather/rain.lua @@ -20,7 +20,7 @@ mcl_weather.rain = { init_done = false, } -mcl_weather.rain.sound_handler = function(player) +function mcl_weather.rain.sound_handler(player) return minetest.sound_play("weather_rain", { to_player = player:get_player_name(), loop = true, @@ -28,7 +28,7 @@ mcl_weather.rain.sound_handler = function(player) end -- set skybox based on time (uses skycolor api) -mcl_weather.rain.set_sky_box = function() +function mcl_weather.rain.set_sky_box() if mcl_weather.state == "rain" then mcl_weather.skycolor.add_layer( "weather-pack-rain-sky", @@ -46,8 +46,7 @@ end -- creating manually parctiles instead of particles spawner because of easier to control -- spawn position. -mcl_weather.rain.add_rain_particles = function(player) - +function mcl_weather.rain.add_rain_particles(player) mcl_weather.rain.last_rp_count = 0 for i=mcl_weather.rain.particles_count, 1,-1 do local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player) @@ -70,7 +69,7 @@ mcl_weather.rain.add_rain_particles = function(player) end -- Simple random texture getter -mcl_weather.rain.get_texture = function() +function mcl_weather.rain.get_texture() local texture_name local random_number = math.random() if random_number > 0.33 then @@ -85,7 +84,7 @@ end -- register player for rain weather. -- basically needs for origin sky reference and rain sound controls. -mcl_weather.rain.add_player = function(player) +function mcl_weather.rain.add_player(player) if mcl_weather.players[player:get_player_name()] == nil then local player_meta = {} player_meta.origin_sky = {player:get_sky()} @@ -95,7 +94,7 @@ end -- remove player from player list effected by rain. -- be sure to remove sound before removing player otherwise soundhandler reference will be lost. -mcl_weather.rain.remove_player = function(player) +function mcl_weather.rain.remove_player(player) local player_meta = mcl_weather.players[player:get_player_name()] if player_meta ~= nil and player_meta.origin_sky ~= nil then player:set_clouds({color="#FFF0F0E5"}) @@ -119,7 +118,7 @@ end) -- adds and removes rain sound depending how much rain particles around player currently exist. -- have few seconds delay before each check to avoid on/off sound too often -- when player stay on 'edge' where sound should play and stop depending from random raindrop appearance. -mcl_weather.rain.update_sound = function(player) +function mcl_weather.rain.update_sound(player) local player_meta = mcl_weather.players[player:get_player_name()] if player_meta ~= nil then if player_meta.sound_updated ~= nil and player_meta.sound_updated + 5 > minetest.get_gametime() then @@ -140,7 +139,7 @@ mcl_weather.rain.update_sound = function(player) end -- rain sound removed from player. -mcl_weather.rain.remove_sound = function(player) +function mcl_weather.rain.remove_sound(player) local player_meta = mcl_weather.players[player:get_player_name()] if player_meta ~= nil and player_meta.sound_handler ~= nil then minetest.sound_fade(player_meta.sound_handler, -0.5, 0.0) @@ -150,7 +149,7 @@ mcl_weather.rain.remove_sound = function(player) end -- callback function for removing rain -mcl_weather.rain.clear = function() +function mcl_weather.rain.clear() mcl_weather.rain.raining = false mcl_weather.rain.sky_last_update = -1 mcl_weather.rain.init_done = false @@ -166,11 +165,10 @@ minetest.register_globalstep(function(dtime) if mcl_weather.state ~= "rain" then return false end - mcl_weather.rain.make_weather() end) -mcl_weather.rain.make_weather = function() +function mcl_weather.rain.make_weather() if mcl_weather.rain.init_done == false then mcl_weather.rain.raining = true mcl_weather.rain.set_sky_box() @@ -190,7 +188,7 @@ mcl_weather.rain.make_weather = function() end -- Switch the number of raindrops: "thunder" for many raindrops, otherwise for normal raindrops -mcl_weather.rain.set_particles_mode = function(mode) +function mcl_weather.rain.set_particles_mode(mode) if mode == "thunder" then mcl_weather.rain.particles_count = PARTICLES_COUNT_THUNDER else From 6105a9ef2292efe1a8a6da1a695d2e5d9baab322 Mon Sep 17 00:00:00 2001 From: NO11 Date: Tue, 25 May 2021 20:00:06 +0000 Subject: [PATCH 05/14] Fix function code style in mcl:core/crafting.lua --- mods/ITEMS/mcl_core/crafting.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_core/crafting.lua b/mods/ITEMS/mcl_core/crafting.lua index f031c7ca2f..cec26e7474 100644 --- a/mods/ITEMS/mcl_core/crafting.lua +++ b/mods/ITEMS/mcl_core/crafting.lua @@ -4,7 +4,7 @@ -- Crafting definition -- -local craft_planks = function(output, input) +local function craft_planks(output, input) minetest.register_craft({ output = "mcl_core:"..output.."wood 4", recipe = { From 4c9eeed499d225552bd7e35a4433dc1c892383bc Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 26 May 2021 16:25:16 +0200 Subject: [PATCH 06/14] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 023d89de89..1b5098a4f1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,7 +50,7 @@ Contributors will be credited in `CREDITS.md`. Each mod must provide `mod.conf`. Each mod which add API functions should store functions inside a global table named like the mod. -Object oriented API shoud be avoided e.g.:`function mobs.register_mod(self)` +Public functions should not use self references but rather just access the table directly. Functions should be defined in this way: ``` function mcl_xyz.stuff(param) end From fd387a65af861e7e8fbd099f067cb9152c69b349 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 26 May 2021 16:42:12 +0200 Subject: [PATCH 07/14] fix some codestyle issues in hudbars --- mods/HUD/hudbars/init.lua | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mods/HUD/hudbars/init.lua b/mods/HUD/hudbars/init.lua index 6f90aa03d8..a88d14dcfe 100644 --- a/mods/HUD/hudbars/init.lua +++ b/mods/HUD/hudbars/init.lua @@ -1,17 +1,22 @@ -local S = minetest.get_translator("hudbars") +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local S = minetest.get_translator(modname) local N = function(s) return s end -hb = {} +local math = math +local table = table -hb.hudtables = {} - --- number of registered HUD bars -hb.hudbars_count = 0 - --- table which records which HUD bar slots have been “registered” so far; used for automatic positioning -hb.registered_slots = {} - -hb.settings = {} +hb = { + hudtables = {}, + -- number of registered HUD bars + hudbars_count = 0, + -- table which records which HUD bar slots have been “registered” so far; used for automatic positioning + registered_slots = {}, + settings = {}, + -- Table which contains all players with active default HUD bars (only for internal use) + players = {}, +} function hb.load_setting(sname, stype, defaultval, valid_values) local sval @@ -45,7 +50,8 @@ function hb.load_setting(sname, stype, defaultval, valid_values) end -- Load default settings -dofile(minetest.get_modpath("hudbars").."/default_settings.lua") +dofile(modpath.."/default_settings.lua") + if minetest.get_modpath("mcl_experience") and not minetest.is_creative_enabled("") then -- reserve some space for experience bar: hb.settings.start_offset_left.y = hb.settings.start_offset_left.y - 20 @@ -85,9 +91,6 @@ local function make_label(format_string, format_string_config, label, start_valu return ret end --- Table which contains all players with active default HUD bars (only for internal use) -hb.players = {} - function hb.value_to_barlength(value, max) if max == 0 then return 0 From ee9577b62597bab6368b66bf32985f03f7c6da5d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 26 May 2021 16:43:36 +0200 Subject: [PATCH 08/14] fix functions in mcl_hbarmor --- mods/HUD/mcl_hbarmor/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/HUD/mcl_hbarmor/init.lua b/mods/HUD/mcl_hbarmor/init.lua index 9e5aa634b8..f8fa6e619b 100644 --- a/mods/HUD/mcl_hbarmor/init.lua +++ b/mods/HUD/mcl_hbarmor/init.lua @@ -21,11 +21,11 @@ if tonumber(set) ~= nil then end -local must_hide = function(playername, arm) +local function must_hide(playername, arm) return arm == 0 end -local arm_printable = function(arm) +local function arm_printable(arm) return math.ceil(math.floor(arm+0.5)) end From 5fc3256930545d28eca105eec0ec785558e39b1b Mon Sep 17 00:00:00 2001 From: AFCMS Date: Wed, 26 May 2021 16:55:32 +0200 Subject: [PATCH 09/14] fix codestyle in mcl_hbarmor --- mods/HUD/mcl_hbarmor/init.lua | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/mods/HUD/mcl_hbarmor/init.lua b/mods/HUD/mcl_hbarmor/init.lua index f8fa6e619b..422a409fbc 100644 --- a/mods/HUD/mcl_hbarmor/init.lua +++ b/mods/HUD/mcl_hbarmor/init.lua @@ -1,23 +1,26 @@ -local S = minetest.get_translator("mcl_hbarmor") +local S = minetest.get_translator(minetest.get_current_modname()) -local mcl_hbarmor = {} +local math = math +local tonumber = tonumber --- HUD statbar values -mcl_hbarmor.armor = {} +local get_connected_players = minetest.get_connected_players --- Stores if player's HUD bar has been initialized so far. -mcl_hbarmor.player_active = {} +local mcl_hbarmor = { + -- HUD statbar values + armor = {}, + -- Stores if player's HUD bar has been initialized so far. + player_active = {}, + -- Time difference in seconds between updates to the HUD armor bar. + -- Increase this number for slow servers. + tick = 0.1, + -- If true, the armor bar is hidden when the player does not wear any armor + autohide = true, +} --- Time difference in seconds between updates to the HUD armor bar. --- Increase this number for slow servers. -mcl_hbarmor.tick = 0.1 +local tick_config = minetest.settings:get("mcl_hbarmor_tick") --- If true, the armor bar is hidden when the player does not wear any armor -mcl_hbarmor.autohide = true - -set = minetest.settings:get("mcl_hbarmor_tick") -if tonumber(set) ~= nil then - mcl_hbarmor.tick = tonumber(set) +if tonumber(tick_config) ~= nil then + mcl_hbarmor.tick = tonumber(tick_config) end @@ -106,12 +109,13 @@ end) local main_timer = 0 local timer = 0 minetest.register_globalstep(function(dtime) + --TODO: replace this by playerglobalstep API then implemented main_timer = main_timer + dtime timer = timer + 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 pairs(minetest.get_connected_players()) do + for _,player in pairs(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) From bb77443892805a39471bc7d2776639cd2b72c87f Mon Sep 17 00:00:00 2001 From: NO11 Date: Wed, 26 May 2021 17:43:42 +0000 Subject: [PATCH 10/14] [mcl_core] fix function codestyle in functions.lua --- mods/ITEMS/mcl_core/functions.lua | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 7f9a83bc93..f66240b94f 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -53,7 +53,7 @@ minetest.register_abm({ -- -- Functions -mcl_core.grow_cactus = function(pos, node) +function mcl_core.grow_cactus(pos, node) pos.y = pos.y-1 local name = minetest.get_node(pos).name if minetest.get_item_group(name, "sand") ~= 0 then @@ -71,7 +71,7 @@ mcl_core.grow_cactus = function(pos, node) end end -mcl_core.grow_reeds = function(pos, node) +function mcl_core.grow_reeds(pos, node) pos.y = pos.y-1 local name = minetest.get_node(pos).name if minetest.get_item_group(name, "soil_sugarcane") ~= 0 then @@ -114,8 +114,8 @@ local function drop_attached_node(p) end -- Helper function for node actions for liquid flow -local liquid_flow_action = function(pos, group, action) - local check_detach = function(pos, xp, yp, zp) +local function liquid_flow_action(pos, group, action) + local function check_detach(pos, xp, yp, zp) local p = {x=pos.x+xp, y=pos.y+yp, z=pos.z+zp} local n = minetest.get_node_or_nil(p) if not n then @@ -594,13 +594,13 @@ function mcl_core.generate_v6_spruce_tree(pos) vm:write_to_map() end -mcl_core.generate_spruce_tree = function(pos) +function mcl_core.generate_spruce_tree(pos) local r = math.random(1, 3) local path = minetest.get_modpath("mcl_core") .. "/schematics/mcl_core_spruce_"..r..".mts" minetest.place_schematic({ x = pos.x - 3, y = pos.y - 1, z = pos.z - 3 }, path, "0", nil, false) end -mcl_core.generate_huge_spruce_tree = function(pos) +function mcl_core.generate_huge_spruce_tree(pos) local r1 = math.random(1, 2) local r2 = math.random(1, 4) local path @@ -911,7 +911,7 @@ minetest.register_lbm({ -------------------------- local treelight = 9 -local sapling_grow_action = function(tree_id, soil_needed, one_by_one, two_by_two, sapling) +local function sapling_grow_action(tree_id, soil_needed, one_by_one, two_by_two, sapling) return function(pos) local meta = minetest.get_meta(pos) if meta:get("grown") then return end @@ -953,7 +953,7 @@ local sapling_grow_action = function(tree_id, soil_needed, one_by_one, two_by_tw -- This sapling grows in a special way when there are 4 saplings in a 2×2 pattern if two_by_two then -- Check 8 surrounding saplings and try to find a 2×2 pattern - local is_sapling = function(pos, sapling) + local function is_sapling(pos, sapling) return minetest.get_node(pos).name == sapling end local p2 = {x=pos.x+1, y=pos.y, z=pos.z} @@ -1040,7 +1040,7 @@ local grow_birch = sapling_grow_action(BIRCH_TREE_ID, 1, true, false) -- pos: Position -- node: Node table of the node at this position, from minetest.get_node -- Returns true on success and false on failure -mcl_core.grow_sapling = function(pos, node) +function mcl_core.grow_sapling(pos, node) local grow if node.name == "mcl_core:sapling" then grow = grow_oak @@ -1245,7 +1245,7 @@ minetest.register_abm({ end -- Add vines below pos (if empty) - local spread_down = function(origin, target, dir, node) + local function spread_down(origin, target, dir, node) if math.random(1, 2) == 1 then if minetest.get_node(target).name == "air" then minetest.add_node(target, {name = "mcl_core:vine", param2 = node.param2}) @@ -1254,7 +1254,7 @@ minetest.register_abm({ end -- Add vines above pos if it is backed up - local spread_up = function(origin, target, dir, node) + local function spread_up(origin, target, dir, node) local vines_in_area = minetest.find_nodes_in_area({x=origin.x-4, y=origin.y-1, z=origin.z-4}, {x=origin.x+4, y=origin.y+1, z=origin.z+4}, "mcl_core:vine") -- Less then 4 vines blocks around the ticked vines block (remember the ticked block is counted by above function as well) if #vines_in_area < 5 then @@ -1273,7 +1273,7 @@ minetest.register_abm({ end end - local spread_horizontal = function(origin, target, dir, node) + local function spread_horizontal(origin, target, dir, node) local vines_in_area = minetest.find_nodes_in_area({x=origin.x-4, y=origin.y-1, z=origin.z-4}, {x=origin.x+4, y=origin.y+1, z=origin.z+4}, "mcl_core:vine") -- Less then 4 vines blocks around the ticked vines block (remember the ticked block is counted by above function as well) if #vines_in_area < 5 then @@ -1310,7 +1310,7 @@ minetest.register_abm({ }) -- Returns true of the node supports vines -mcl_core.supports_vines = function(nodename) +function mcl_core.supports_vines(nodename) local def = minetest.registered_nodes[nodename] -- Rules: 1) walkable 2) full cube return def.walkable and @@ -1530,7 +1530,7 @@ end -- -- The snowable nodes also MUST have _mcl_snowed defined to contain the name -- of the snowed node. -mcl_core.register_snowed_node = function(itemstring_snowed, itemstring_clear, tiles, sounds, clear_colorization, desc) +function mcl_core.register_snowed_node(itemstring_snowed, itemstring_clear, tiles, sounds, clear_colorization, desc) local def = table.copy(minetest.registered_nodes[itemstring_clear]) local create_doc_alias if def.description then @@ -1593,7 +1593,7 @@ end -- Reverts a snowed dirtlike node at pos to its original snow-less form. -- This function assumes there is no snow cover node above. This function -- MUST NOT be called if there is a snow cover node above pos. -mcl_core.clear_snow_dirt = function(pos, node) +function mcl_core.clear_snow_dirt(pos, node) local def = minetest.registered_nodes[node.name] if def._mcl_snowless then minetest.swap_node(pos, {name = def._mcl_snowless, param2=node.param2}) @@ -1605,7 +1605,7 @@ end -- on_construct -- Makes constructed snowable node snowed if placed below a snow cover node. -mcl_core.on_snowable_construct = function(pos) +function mcl_core.on_snowable_construct(pos) -- Myself local node = minetest.get_node(pos) @@ -1633,7 +1633,7 @@ end -- on_construct -- Makes snowable node below snowed. -mcl_core.on_snow_construct = function(pos) +function mcl_core.on_snow_construct(pos) local npos = {x=pos.x, y=pos.y-1, z=pos.z} local node = minetest.get_node(npos) local def = minetest.registered_nodes[node.name] @@ -1643,7 +1643,7 @@ mcl_core.on_snow_construct = function(pos) end -- after_destruct -- Clears snowed dirtlike node below. -mcl_core.after_snow_destruct = function(pos) +function mcl_core.after_snow_destruct(pos) local nn = minetest.get_node(pos).name -- No-op if snow was replaced with snow if minetest.get_item_group(nn, "snow_cover") == 1 then From 211b078d3a112c47be808afe313247c8aafc5868 Mon Sep 17 00:00:00 2001 From: NO11 Date: Wed, 26 May 2021 17:51:24 +0000 Subject: [PATCH 11/14] [mcl_core] fix function codestyle in nodes_base.lua --- mods/ITEMS/mcl_core/nodes_base.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index 39015e53b4..9baa6c33e4 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -86,7 +86,7 @@ minetest.register_node("mcl_core:stone_with_gold", { }) local redstone_timer = 68.28 -local redstone_ore_activate = function(pos) +local function redstone_ore_activate(pos) minetest.swap_node(pos, {name="mcl_core:stone_with_redstone_lit"}) local t = minetest.get_node_timer(pos) t:start(redstone_timer) @@ -124,7 +124,7 @@ minetest.register_node("mcl_core:stone_with_redstone", { } }) -local redstone_ore_reactivate = function(pos) +local function redstone_ore_reactivate(pos) local t = minetest.get_node_timer(pos) t:start(redstone_timer) end @@ -864,7 +864,7 @@ minetest.register_node("mcl_core:packed_ice", { -- Frosted Ice (4 nodes) for i=0,3 do local ice = {} - ice.increase_age = function(pos, ice_near, first_melt) + function ice.increase_age(pos, ice_near, first_melt) -- Increase age of frosted age or turn to water source if too old local nn = minetest.get_node(pos).name local age = tonumber(string.sub(nn, -1)) From 5b433038732317304c91fa3b78505b6ebd2910ce Mon Sep 17 00:00:00 2001 From: NO11 Date: Wed, 26 May 2021 17:54:58 +0000 Subject: [PATCH 12/14] [mcl_core] fix function codestyle in nodes_climb.lua --- mods/ITEMS/mcl_core/nodes_climb.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_core/nodes_climb.lua b/mods/ITEMS/mcl_core/nodes_climb.lua index 3b2d3ab60e..ad861b4f2d 100644 --- a/mods/ITEMS/mcl_core/nodes_climb.lua +++ b/mods/ITEMS/mcl_core/nodes_climb.lua @@ -1,7 +1,7 @@ -- Climbable nodes local S = minetest.get_translator("mcl_core") -local rotate_climbable = function(pos, node, user, mode) +local function rotate_climbable(pos, node, user, mode) if mode == screwdriver.ROTATE_FACE then local r = screwdriver.rotate.wallmounted(pos, node, mode) node.param2 = r From 90bab9026b5f7c2b89a930368d0784f1d67f0857 Mon Sep 17 00:00:00 2001 From: NO11 Date: Wed, 26 May 2021 17:57:43 +0000 Subject: [PATCH 13/14] [mcl_core] fix function codestyle in nodes_liquid.lua --- mods/ITEMS/mcl_core/nodes_liquid.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_core/nodes_liquid.lua b/mods/ITEMS/mcl_core/nodes_liquid.lua index 99d33cf594..42276685e3 100644 --- a/mods/ITEMS/mcl_core/nodes_liquid.lua +++ b/mods/ITEMS/mcl_core/nodes_liquid.lua @@ -212,7 +212,7 @@ S("• When lava is directly above water, the water turns into stone."), _mcl_hardness = -1, }) -local emit_lava_particle = function(pos) +local function emit_lava_particle(pos) local node = minetest.get_node(pos) if minetest.get_item_group(node.name, "lava_source") == 0 then return From 656891ec61412f64e3339d24e19b95954c56078a Mon Sep 17 00:00:00 2001 From: NO11 Date: Wed, 26 May 2021 18:02:28 +0000 Subject: [PATCH 14/14] [mcl_core] fix function codestyle in nodes_trees.lua --- mods/ITEMS/mcl_core/nodes_trees.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_trees.lua b/mods/ITEMS/mcl_core/nodes_trees.lua index cc64cd9cf7..a72935f056 100644 --- a/mods/ITEMS/mcl_core/nodes_trees.lua +++ b/mods/ITEMS/mcl_core/nodes_trees.lua @@ -8,7 +8,7 @@ if mod_screwdriver then end -- Register tree trunk (wood) and bark -local register_tree_trunk = function(subname, description_trunk, description_bark, longdesc, tile_inner, tile_bark, stripped_varient) +local function register_tree_trunk(subname, description_trunk, description_bark, longdesc, tile_inner, tile_bark, stripped_varient) minetest.register_node("mcl_core:"..subname, { description = description_trunk, _doc_items_longdesc = longdesc, @@ -91,7 +91,7 @@ local register_stripped_trunk = function(subname, description_stripped_trunk, de }) end -local register_wooden_planks = function(subname, description, tiles) +local function register_wooden_planks(subname, description, tiles) minetest.register_node("mcl_core:"..subname, { description = description, _doc_items_longdesc = doc.sub.items.temp.build, @@ -106,7 +106,7 @@ local register_wooden_planks = function(subname, description, tiles) }) end -local register_leaves = function(subname, description, longdesc, tiles, sapling, drop_apples, sapling_chances, leafdecay_distance) +local function register_leaves(subname, description, longdesc, tiles, sapling, drop_apples, sapling_chances, leafdecay_distance) if leafdecay_distance == nil then leafdecay_distance = 4 end @@ -173,7 +173,7 @@ local register_leaves = function(subname, description, longdesc, tiles, sapling, }) end -local register_sapling = function(subname, description, longdesc, tt_help, texture, selbox) +local function register_sapling(subname, description, longdesc, tt_help, texture, selbox) minetest.register_node("mcl_core:"..subname, { description = description, _tt_help = tt_help,