Replace magic numbers with named constants, add missing 'local'

This commit is contained in:
teknomunk 2024-12-05 21:08:38 -06:00
parent 430cd8dffa
commit ea21ec6619
8 changed files with 17 additions and 10 deletions

@ -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 = {

@ -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

@ -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)

@ -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)

@ -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)

@ -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()

@ -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)

@ -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