Merge pull request 'Zombie piglin no longer prevent sleep unless hostile.' (#3731) from allow_sleep_near_ziglin into master

Reviewed-on: MineClone2/MineClone2#3731
This commit is contained in:
ancientmarinerdev 2023-05-17 19:55:50 +00:00
commit 681ea9b515
1 changed files with 9 additions and 5 deletions

View File

@ -117,19 +117,23 @@ local function lay_down(player, pos, bed_pos, state, skip)
end end
-- No sleeping if monsters nearby. -- No sleeping if monsters nearby.
-- The exceptions above apply.
-- Zombie piglin only prevent sleep while they are hostle.
for _, obj in pairs(minetest.get_objects_inside_radius(bed_pos, 8)) do for _, obj in pairs(minetest.get_objects_inside_radius(bed_pos, 8)) do
if obj and not obj:is_player() then if obj and not obj:is_player() then
local ent = obj:get_luaentity() local ent = obj:get_luaentity()
local mobname = ent.name local mobname = ent.name
local def = minetest.registered_entities[mobname] local def = minetest.registered_entities[mobname]
-- Approximation of monster detection range -- Approximation of monster detection range
if def.is_mob and ((mobname ~= "mobs_mc:pigman" and def.type == "monster" and not monster_exceptions[mobname]) or (mobname == "mobs_mc:pigman" and ent.state == "attack")) then if def.is_mob and (def.type == "monster" or mobname == "mobs_mc:zombified_piglin") then
if math.abs(bed_pos.y - obj:get_pos().y) <= 5 then if monster_exceptions[mobname] or
return false, S("You can't sleep now, monsters are nearby!") (mobname == "mobs_mc:zombified_piglin" and ent.state ~= "attack") then
-- Some exceptions do not prevent sleep. Zombie piglin only prevent sleep while they are hostile.
else
if math.abs(bed_pos.y - obj:get_pos().y) <= 5 then
return false, S("You can't sleep now, monsters are nearby!")
end
end end
end end
end end
end end
end end