mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-01-25 00:30:19 +01:00
replace :distance with get_distance() function
This commit is contained in:
parent
17dafff8ef
commit
87d13c857f
10
api.lua
10
api.lua
@ -14,7 +14,7 @@ local use_vh1 = minetest.get_modpath("visual_harm_1ndicators")
|
|||||||
-- Global
|
-- Global
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20240301",
|
version = "20240303",
|
||||||
translate = S,
|
translate = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||||
node_snow = minetest.registered_aliases["mapgen_snow"]
|
node_snow = minetest.registered_aliases["mapgen_snow"]
|
||||||
@ -272,7 +272,7 @@ function mob_class:collision()
|
|||||||
|
|
||||||
pos2 = player:get_pos()
|
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}
|
vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}
|
||||||
force = (width + 0.5) - vector.distance(
|
force = (width + 0.5) - vector.distance(
|
||||||
@ -2253,7 +2253,7 @@ function mob_class:do_states(dtime)
|
|||||||
|
|
||||||
local player_pos = player:get_pos()
|
local player_pos = player:get_pos()
|
||||||
|
|
||||||
if player_pos:distance(s) <= 3 then
|
if get_distance(player_pos, s) <= 3 then
|
||||||
lp = player_pos
|
lp = player_pos
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -3342,7 +3342,7 @@ function mob_class:mob_expire(pos, dtime)
|
|||||||
-- only despawn away from player
|
-- only despawn away from player
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
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
|
self.lifetimer = 20
|
||||||
return
|
return
|
||||||
end
|
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
|
-- only spawn a set distance away from player
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
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)
|
--print("--- player too close", name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
12
spawner.lua
12
spawner.lua
@ -11,6 +11,16 @@ local function is_player(player)
|
|||||||
end
|
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
|
-- mob spawner
|
||||||
local spawner_default = "mobs_animal:pumba 10 15 0 0 0"
|
local spawner_default = "mobs_animal:pumba 10 15 0 0 0"
|
||||||
|
|
||||||
@ -161,7 +171,7 @@ minetest.register_abm({
|
|||||||
|
|
||||||
player = players[i]
|
player = players[i]
|
||||||
|
|
||||||
if player:get_pos():distance(pos) <= pla then
|
if get_distance(player:get_pos(), pos) <= pla then
|
||||||
|
|
||||||
in_range = true
|
in_range = true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user