1
0
Fork 0

Don't spawn structure mobs in peaceful mode

This commit is contained in:
cora 2022-09-06 12:45:38 +02:00
parent 6675f9fd40
commit 962425faa5
3 changed files with 31 additions and 22 deletions

View File

@ -434,7 +434,7 @@ local function spawn_check(pos,spawn_def)
is_ground = minetest.get_item_group(gotten_node,"solid") ~= 0 is_ground = minetest.get_item_group(gotten_node,"solid") ~= 0
end end
pos.y = pos.y + 1 pos.y = pos.y + 1
local has_room = #minetest.find_nodes_in_area(pos,vector.offset(pos,0,1,0),{"air"}) or 0 >= 2
local is_water = get_item_group(gotten_node, "water") ~= 0 local is_water = get_item_group(gotten_node, "water") ~= 0
local is_lava = get_item_group(gotten_node, "lava") ~= 0 local is_lava = get_item_group(gotten_node, "lava") ~= 0
local is_leaf = get_item_group(gotten_node, "leaves") ~= 0 local is_leaf = get_item_group(gotten_node, "leaves") ~= 0
@ -452,6 +452,7 @@ local function spawn_check(pos,spawn_def)
and biome_check(spawn_def.biomes, gotten_biome) and biome_check(spawn_def.biomes, gotten_biome)
and (is_ground or spawn_def.type_of_spawning ~= "ground") and (is_ground or spawn_def.type_of_spawning ~= "ground")
and (spawn_def.type_of_spawning ~= "ground" or not is_leaf) and (spawn_def.type_of_spawning ~= "ground" or not is_leaf)
and (spawn_def.type_of_spawning ~= "ground" or has_room)
and (spawn_def.check_position and spawn_def.check_position(pos) or true) and (spawn_def.check_position and spawn_def.check_position(pos) or true)
and (not is_farm_animal(spawn_def.name) or is_grass) and (not is_farm_animal(spawn_def.name) or is_grass)
and (spawn_def.type_of_spawning ~= "water" or is_water) and (spawn_def.type_of_spawning ~= "water" or is_water)

View File

@ -1,6 +1,7 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname) local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
mcl_structures.register_structure("pillager_outpost",{ mcl_structures.register_structure("pillager_outpost",{
place_on = {"group:grass_block","group:dirt","mcl_core:dirt_with_grass","group:sand"}, place_on = {"group:grass_block","group:dirt","mcl_core:dirt_with_grass","group:sand"},
@ -55,26 +56,28 @@ mcl_structures.register_structure("pillager_outpost",{
}} }}
}, },
after_place = function(p,def,pr) after_place = function(p,def,pr)
local p1 = vector.offset(p,-7,0,-7) if not peaceful then
local p2 = vector.offset(p,7,14,7) local p1 = vector.offset(p,-7,0,-7)
local spawnon = {"mcl_core:stripped_oak"} local p2 = vector.offset(p,7,14,7)
local sp = minetest.find_nodes_in_area_under_air(p1,p2,spawnon) local spawnon = {"mcl_core:stripped_oak"}
for _,n in pairs(minetest.find_nodes_in_area(p1,p2,{"group:wall"})) do local sp = minetest.find_nodes_in_area_under_air(p1,p2,spawnon)
local def = minetest.registered_nodes[minetest.get_node(n).name:gsub("_%d+$","")] for _,n in pairs(minetest.find_nodes_in_area(p1,p2,{"group:wall"})) do
if def and def.on_construct then local def = minetest.registered_nodes[minetest.get_node(n).name:gsub("_%d+$","")]
def.on_construct(n) if def and def.on_construct then
end def.on_construct(n)
end
if sp and #sp > 0 then
for i=1,5 do
local pos = sp[pr:next(1,#sp)]
if pos then
minetest.add_entity(pos,"mobs_mc:pillager")
end end
end end
local pos = sp[pr:next(1,#sp)] if sp and #sp > 0 then
if pos then for i=1,5 do
minetest.add_entity(pos,"mobs_mc:evoker") local pos = sp[pr:next(1,#sp)]
if pos then
minetest.add_entity(pos,"mobs_mc:pillager")
end
end
local pos = sp[pr:next(1,#sp)]
if pos then
minetest.add_entity(pos,"mobs_mc:evoker")
end
end end
end end
end end

View File

@ -2,14 +2,19 @@ local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname) local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
local function spawn_witch(p1,p2) local function spawn_witch(p1,p2)
local c = minetest.find_node_near(p1,15,{"mcl_cauldrons:cauldron"}) local c = minetest.find_node_near(p1,15,{"mcl_cauldrons:cauldron"})
if c then if c then
local nn = minetest.find_nodes_in_area_under_air(vector.new(p1.x,c.y-1,p1.z),vector.new(p2.x,c.y-1,p2.z),{"mcl_core:sprucewood"}) local nn = minetest.find_nodes_in_area_under_air(vector.new(p1.x,c.y-1,p1.z),vector.new(p2.x,c.y-1,p2.z),{"mcl_core:sprucewood"})
local witch = minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:witch"):get_luaentity() local witch
if not peaceful then
witch = minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:witch"):get_luaentity()
witch._home = c
witch.can_despawn = false
end
local cat = minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:cat"):get_luaentity() local cat = minetest.add_entity(vector.offset(nn[math.random(#nn)],0,1,0),"mobs_mc:cat"):get_luaentity()
witch._home = c
witch.can_despawn = false
cat.object:set_properties({textures = {"mobs_mc_cat_black.png"}}) cat.object:set_properties({textures = {"mobs_mc_cat_black.png"}})
cat.owner = "!witch!" --so it's not claimable by player cat.owner = "!witch!" --so it's not claimable by player
cat._home = c cat._home = c