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
This commit is contained in:
general 2024-04-07 20:48:54 -04:00
parent fe3c543136
commit d871b18e8f

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) pointed_thing.under, under, placer, itemstack, pointed_thing)
end end
if pos if pos and not minetest.is_protected(pos, placer:get_player_name()) then
and not minetest.is_protected(pos, placer:get_player_name()) then
if not minetest.registered_entities[mob] then if active_limit > 0 and active_mobs >= active_limit then
return -- TODO 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 end
pos.y = pos.y + 1 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 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 -- have we reached active mob limit
if active_limit > 0 and active_mobs >= active_limit then if active_limit > 0 and active_mobs >= active_limit then
minetest.chat_send_player(placer:get_player_name(), if is_player(placer) then
S("Active Mob Limit Reached!") minetest.chat_send_player(placer:get_player_name(),
.. " (" .. active_mobs S("Active Mob Limit Reached!")
.. " / " .. active_limit .. ")") .. " (" .. active_mobs
.. " / " .. active_limit .. ")")
end
return return
end end