fix and tweak limit mobs reached that player spawns from "code tweaks"

* backport only the tweak of "code tweaks" of
  upstream commit 457eb1838cd1e694052298a42c84cd7b061d809d
  limit mobs reached that player spawns from creative or something
* add the check for player before send the chat msg, missing
  from upstream
main
general 2024-04-07 20:48:54 -04:00
parent fe3c543136
commit d871b18e8f
1 changed files with 15 additions and 12 deletions

27
api.lua
View File

@ -4546,11 +4546,16 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
pointed_thing.under, under, placer, itemstack, pointed_thing)
end
if pos
and not minetest.is_protected(pos, placer:get_player_name()) then
if pos and not minetest.is_protected(pos, placer:get_player_name()) then
if not minetest.registered_entities[mob] then
return -- TODO
if active_limit > 0 and active_mobs >= active_limit then
if is_player(placer) then
minetest.chat_send_player(placer:get_player_name(),
S("Active Mob Limit Reached!")
.. " (" .. active_mobs
.. " / " .. active_limit .. ")")
end
return
end
pos.y = pos.y + 1
@ -4599,16 +4604,14 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
if pos and not minetest.is_protected(pos, placer:get_player_name()) then
if not minetest.registered_entities[mob] then
return
end
-- have we reached active mob limit
if active_limit > 0 and active_mobs >= active_limit then
minetest.chat_send_player(placer:get_player_name(),
S("Active Mob Limit Reached!")
.. " (" .. active_mobs
.. " / " .. active_limit .. ")")
if is_player(placer) then
minetest.chat_send_player(placer:get_player_name(),
S("Active Mob Limit Reached!")
.. " (" .. active_mobs
.. " / " .. active_limit .. ")")
end
return
end