From ea21ec6619c1207765765071a165747f9316aaa9 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 5 Dec 2024 21:08:38 -0600 Subject: [PATCH] Replace magic numbers with named constants, add missing 'local' --- mods/ITEMS/mcl_bows/arrow.lua | 3 ++- mods/ITEMS/mcl_potions/lingering.lua | 4 +++- mods/ITEMS/mcl_potions/splash.lua | 6 ++++-- mods/ITEMS/mcl_throwing/egg.lua | 2 +- mods/ITEMS/mcl_throwing/ender_pearl.lua | 2 +- mods/ITEMS/mcl_throwing/init.lua | 6 ++++-- mods/ITEMS/mcl_throwing/snowball.lua | 2 +- mods/ITEMS/vl_projectile/init.lua | 2 +- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 1e260443b..a06eae60d 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -8,6 +8,7 @@ local math = math local vector = vector local YAW_OFFSET = -math.pi/2 +local TRACER_THRESHOLD = 9 local mod_awards = minetest.get_modpath("awards") and minetest.get_modpath("mcl_achievements") local mod_button = minetest.get_modpath("mesecons_button") @@ -68,7 +69,7 @@ local arrow_entity = { return {fleshy = self._damage} end, hide_tracer = function(self) - return self._stuck or self._damage < 9 or self._in_player + return self._stuck or self._damage < TRACER_THRESHOLD or self._in_player end, tracer_texture = "mobs_mc_arrow_particle.png", behaviors = { diff --git a/mods/ITEMS/mcl_potions/lingering.lua b/mods/ITEMS/mcl_potions/lingering.lua index a12b9084e..23bd9bd27 100644 --- a/mods/ITEMS/mcl_potions/lingering.lua +++ b/mods/ITEMS/mcl_potions/lingering.lua @@ -1,6 +1,8 @@ local S = core.get_translator(core.get_current_modname()) local PARTICLE_DENSITY = 4 +local PLAYER_HEIGHT_OFFSET = 1.64 +local ACTIVE_REGION = 1.5 local mod_target = core.get_modpath("mcl_target") local function lingering_image(colorstring, opacity) @@ -215,7 +217,7 @@ function mcl_potions.register_lingering(name, descr, color, def) vl_projectile.collides_with_entities, vl_projectile.collides_with_solids, }, - grace_distance = 3.34, -- 1.5 active region + 1.64 height offset + 0.1 safety + grace_distance = ACTIVE_REGION + PLAYER_HEIGHT_OFFSET + 0.1, -- safety margin on_collide_with_entity = on_collide, on_collide_with_solid = function(self, pos, node) if mod_target and node.name == "mcl_target:target_off" then diff --git a/mods/ITEMS/mcl_potions/splash.lua b/mods/ITEMS/mcl_potions/splash.lua index f5147b4e5..67a5db673 100644 --- a/mods/ITEMS/mcl_potions/splash.lua +++ b/mods/ITEMS/mcl_potions/splash.lua @@ -1,6 +1,8 @@ local S = core.get_translator(core.get_current_modname()) local GRAVITY = tonumber(core.settings:get("movement_gravity")) local REDUX_MAP = {7/8,0.5,0.25} +local PLAYER_HEIGHT_OFFSET = 1.64 +local ACTIVE_REGION = 1.5 local PARTICLE_DIAMETER = 0.1 local PARTICLE_MIN_VELOCITY = vector.new(-2, 0, -2) local PARTICLE_MAX_VELOCITY = vector.new( 2, 2, 2) @@ -47,7 +49,7 @@ function mcl_potions.register_splash(name, descr, color, def) local pos = placer:get_pos(); minetest.sound_play("mcl_throwing_throw", {pos = pos, gain = 0.4, max_hear_distance = 16}, true) local obj = vl_projectile.create(id.."_flying",{ - pos = vector.offset(pos, dir.x, dir.y + 1.64, dir.z), + pos = vector.offset(pos, dir.x, dir.y + PLAYER_HEIGHT_OFFSET, dir.z), owner = placer, dir = dir, velocity = velocity, @@ -183,7 +185,7 @@ function mcl_potions.register_splash(name, descr, color, def) vl_projectile.collides_with_entities, vl_projectile.collides_with_solids, }, - grace_distance = 3.34, -- 1.5 active region + 1.64 height offset + 0.1 safety + grace_distance = ACTIVE_REGION + PLAYER_HEIGHT_OFFSET + 0.1, -- safety margin on_collide_with_solid = function(self, pos, node) splash_effects(self, pos, def, 4) diff --git a/mods/ITEMS/mcl_throwing/egg.lua b/mods/ITEMS/mcl_throwing/egg.lua index bd3dc54e2..344314b6c 100644 --- a/mods/ITEMS/mcl_throwing/egg.lua +++ b/mods/ITEMS/mcl_throwing/egg.lua @@ -77,5 +77,5 @@ vl_projectile.register("mcl_throwing:egg_entity",{ }, }, }) -mcl_throwing.register_throwable_object("mcl_throwing:egg", "mcl_throwing:egg_entity", 22) +mcl_throwing.register_throwable_object("mcl_throwing:egg", "mcl_throwing:egg_entity", mcl_throwing.default_velocity) diff --git a/mods/ITEMS/mcl_throwing/ender_pearl.lua b/mods/ITEMS/mcl_throwing/ender_pearl.lua index c8c337c6b..f270774c3 100644 --- a/mods/ITEMS/mcl_throwing/ender_pearl.lua +++ b/mods/ITEMS/mcl_throwing/ender_pearl.lua @@ -136,5 +136,5 @@ vl_projectile.register("mcl_throwing:ender_pearl_entity",{ on_collide_with_solid = on_collide, }, }) -mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", 22) +mcl_throwing.register_throwable_object("mcl_throwing:ender_pearl", "mcl_throwing:ender_pearl_entity", mcl_throwing.default_velocity) diff --git a/mods/ITEMS/mcl_throwing/init.lua b/mods/ITEMS/mcl_throwing/init.lua index ebc361638..f720ffbac 100644 --- a/mods/ITEMS/mcl_throwing/init.lua +++ b/mods/ITEMS/mcl_throwing/init.lua @@ -1,4 +1,6 @@ -mcl_throwing = {} +mcl_throwing = { + default_velocity = 22, +} local modpath = core.get_modpath(core.get_current_modname()) @@ -17,7 +19,7 @@ function mcl_throwing.register_throwable_object(name, entity, velocity) end function mcl_throwing.throw(throw_item, pos, dir, velocity, thrower) - velocity = velocity or velocities[throw_item] or 22 + velocity = velocity or velocities[throw_item] or mcl_throwing.default_velocity core.sound_play("mcl_throwing_throw", {pos=pos, gain=0.4, max_hear_distance=16}, true) local itemstring = ItemStack(throw_item):get_name() diff --git a/mods/ITEMS/mcl_throwing/snowball.lua b/mods/ITEMS/mcl_throwing/snowball.lua index 20f9879c7..6d3fca3ce 100644 --- a/mods/ITEMS/mcl_throwing/snowball.lua +++ b/mods/ITEMS/mcl_throwing/snowball.lua @@ -77,5 +77,5 @@ vl_projectile.register("mcl_throwing:snowball_entity", { damage_groups = {snowball_vulnerable = 3}, }, }) -mcl_throwing.register_throwable_object("mcl_throwing:snowball", "mcl_throwing:snowball_entity", 22) +mcl_throwing.register_throwable_object("mcl_throwing:snowball", "mcl_throwing:snowball_entity", mcl_throwing.default_velocity) diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index d800ec191..ca4197656 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -625,7 +625,7 @@ function mod.create(entity_id, options) end function mod.register(name, def) - def_vl_projectile = def._vl_projectile + local def_vl_projectile = def._vl_projectile assert(def_vl_projectile, "vl_projectile.register() requires definition to define _vl_projectile") local behaviors = def_vl_projectile.behaviors