replace :distance with get_distance() function

This commit is contained in:
tenplus1 2024-03-03 17:09:30 +00:00
parent 17dafff8ef
commit 87d13c857f
2 changed files with 16 additions and 6 deletions

10
api.lua
View File

@ -14,7 +14,7 @@ local use_vh1 = minetest.get_modpath("visual_harm_1ndicators")
-- Global
mobs = {
mod = "redo",
version = "20240301",
version = "20240303",
translate = S,
invis = minetest.global_exists("invisibility") and invisibility or {},
node_snow = minetest.registered_aliases["mapgen_snow"]
@ -272,7 +272,7 @@ function mob_class:collision()
pos2 = player:get_pos()
if pos2:distance(pos) < width then
if get_distance(pos2, pos) < width then
vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
force = (width + 0.5) - vector.distance(
@ -2253,7 +2253,7 @@ function mob_class:do_states(dtime)
local player_pos = player:get_pos()
if player_pos:distance(s) <= 3 then
if get_distance(player_pos, s) <= 3 then
lp = player_pos
break
end
@ -3342,7 +3342,7 @@ function mob_class:mob_expire(pos, dtime)
-- only despawn away from player
for _,player in pairs(minetest.get_connected_players()) do
if player:get_pos():distance(pos) <= 15 then
if get_distance(player:get_pos(), pos) <= 15 then
self.lifetimer = 20
return
end
@ -4069,7 +4069,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
-- only spawn a set distance away from player
for _,player in pairs(minetest.get_connected_players()) do
if player:get_pos():distance(pos) <= mob_nospawn_range then
if get_distance(player:get_pos(), pos) <= mob_nospawn_range then
--print("--- player too close", name)
return
end

View File

@ -11,6 +11,16 @@ local function is_player(player)
end
local get_distance = function(a, b)
if not a or not b then return 50 end -- nil check and default distance
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
return square(x * x + y * y + z * z)
end
-- mob spawner
local spawner_default = "mobs_animal:pumba 10 15 0 0 0"
@ -161,7 +171,7 @@ minetest.register_abm({
player = players[i]
if player:get_pos():distance(pos) <= pla then
if get_distance(player:get_pos(), pos) <= pla then
in_range = true