From 0c4a12019145a0975c1d0c7c3d4e182f8ffc8060 Mon Sep 17 00:00:00 2001 From: kno10 Date: Sat, 31 Aug 2024 23:51:58 +0200 Subject: [PATCH] More fixes, make shulkers spawn on the floor. --- mods/ENTITIES/mobs_mc/shulker.lua | 3 +-- mods/MAPGEN/mcl_structures/end_city.lua | 8 +++--- mods/MAPGEN/vl_structures/spawning.lua | 36 ++++++++++++++++++++++++- mods/MAPGEN/vl_structures/util.lua | 35 ------------------------ 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/shulker.lua b/mods/ENTITIES/mobs_mc/shulker.lua index 78959b717..a8ef395b2 100644 --- a/mods/ENTITIES/mobs_mc/shulker.lua +++ b/mods/ENTITIES/mobs_mc/shulker.lua @@ -114,10 +114,9 @@ mcl_mobs.register_mob("mobs_mc:shulker", { for n=1, math.min(64, #nodes) do local r = pr:next(1, #nodes) local nodepos = nodes[r] - local tg = vector.offset(nodepos,0,1,0) + local tg = vector.offset(nodepos,0,0.5,0) if check_spot(tg) then telepos = tg - node_ok = true end end if telepos then diff --git a/mods/MAPGEN/mcl_structures/end_city.lua b/mods/MAPGEN/mcl_structures/end_city.lua index 29be3ebec..cce9770b8 100644 --- a/mods/MAPGEN/mcl_structures/end_city.lua +++ b/mods/MAPGEN/mcl_structures/end_city.lua @@ -7,14 +7,14 @@ local function spawn_shulkers(pos,def,pr,p1,p2) vl_structures.spawn_mobs("mobs_mc:shulker",spawnon,p1,p2,pr,1) local guard = minetest.find_nodes_in_area(p1,p2,{"mcl_itemframes:item_frame"}) if #guard > 0 then - minetest.add_entity(vector.offset(guard[1],0,-0.5,0),"mobs_mc:shulker") -- fixme: MCLA uses -0.5? + minetest.add_entity(vector.offset(guard[1],0,-1.5,0),"mobs_mc:shulker") end end vl_structures.register_structure("end_shipwreck",{ place_on = {"mcl_end:end_stone"}, flags = "place_center_x, place_center_z, all_floors", - y_offset = function(pr) return pr:next(20,50) end, + y_offset = function(pr) return pr:next(15,40) end, force_placement = false, prepare = { foundation = false, clear = false }, chunk_probability = 25, @@ -83,7 +83,7 @@ vl_structures.register_structure("end_shipwreck",{ vl_structures.register_structure("end_boat",{ place_on = {"mcl_end:end_stone"}, flags = "place_center_x, place_center_z, all_floors", - y_offset = function(pr) return pr:next(15,30) end, + y_offset = function(pr) return pr:next(10,20) end, force_placement = false, prepare = { foundation = false, clear = false }, chunk_probability = 10, @@ -143,7 +143,7 @@ vl_structures.register_structure("small_end_city",{ flags = "place_center_x, place_center_z, all_floors", y_offset = 0, chunk_probability = 30, - prepare = { foundation = 2 }, + prepare = { foundation = -1, tolerance = 15 }, biomes = { "End", "EndHighlands", "EndMidlands", "EndBarrens", "EndSmallIslands" }, sidelen = 20, filenames = { diff --git a/mods/MAPGEN/vl_structures/spawning.lua b/mods/MAPGEN/vl_structures/spawning.lua index 5f15d0909..1d40218e8 100644 --- a/mods/MAPGEN/vl_structures/spawning.lua +++ b/mods/MAPGEN/vl_structures/spawning.lua @@ -1,6 +1,7 @@ -- todo: move this mostly to the mcl_mobs module? local mob_cap_player = tonumber(minetest.settings:get("mcl_mob_cap_player")) or 75 local mob_cap_animal = tonumber(minetest.settings:get("mcl_mob_cap_animal")) or 10 +local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false) local mg_name = minetest.get_mapgen_setting("mg_name") local vector_offset = vector.offset @@ -43,8 +44,41 @@ function vl_structures.register_structure_spawn(def) end local mobdef = minetest.registered_entities[def.name] if mobdef.can_spawn and not mobdef.can_spawn(p) then return end - minetest.add_entity(p, def.name) + minetest.add_entity(vector_offset(p, 0, -0.5, 0), def.name) end, }) end +--- Spawn mobs for a structure +-- @param mob string: mob to spawn +-- @param spawnon string or table: nodes to spawn on +-- @param p1 vector: Lowest coordinates of range +-- @param p2 vector: Highest coordinates of range +-- @param pr PseudoRandom: random generator +-- @param n number: Number of mobs to spawn +-- @param water boolean: Spawn water mobs +function vl_structures.spawn_mobs(mob,spawnon,p1,p2,pr,n,water) + n = n or 1 + local sp = {} + if water then + local nn = minetest.find_nodes_in_area(p1,p2,spawnon) + for k,v in pairs(nn) do + if minetest.get_item_group(minetest.get_node(vector_offset(v,0,1,0)).name,"water") > 0 then + table.insert(sp,v) + end + end + else + sp = minetest.find_nodes_in_area_under_air(p1,p2,spawnon) + end + table.shuffle(sp) + local count = 0 + local mob_def = minetest.registered_entities[mob] + local enabled = (not peaceful) or (mob_def and mob_spawn_class ~= "hostile") + for _, node in pairs(sp) do + if enabled and count < n and minetest.add_entity(vector_offset(node, 0, 0.5, 0), mob) then + count = count + 1 + end + minetest.get_meta(node):set_string("spawnblock", "yes") -- note: also in peaceful mode! + end +end + diff --git a/mods/MAPGEN/vl_structures/util.lua b/mods/MAPGEN/vl_structures/util.lua index 2bf93d9f4..a4b921946 100644 --- a/mods/MAPGEN/vl_structures/util.lua +++ b/mods/MAPGEN/vl_structures/util.lua @@ -1,5 +1,3 @@ -local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false) - local floor = math.floor local vector_offset = vector.offset @@ -97,36 +95,3 @@ function vl_structures.fill_chests(p1,p2,loot,pr) end end ---- Spawn mobs for a structure --- @param mob string: mob to spawn --- @param spawnon string or table: nodes to spawn on --- @param p1 vector: Lowest coordinates of range --- @param p2 vector: Highest coordinates of range --- @param pr PseudoRandom: random generator --- @param n number: Number of mobs to spawn --- @param water boolean: Spawn water mobs -function vl_structures.spawn_mobs(mob,spawnon,p1,p2,pr,n,water) - n = n or 1 - local sp = {} - if water then - local nn = minetest.find_nodes_in_area(p1,p2,spawnon) - for k,v in pairs(nn) do - if minetest.get_item_group(minetest.get_node(vector_offset(v,0,1,0)).name,"water") > 0 then - table.insert(sp,v) - end - end - else - sp = minetest.find_nodes_in_area_under_air(p1,p2,spawnon) - end - table.shuffle(sp) - local count = 0 - local mob_def = minetest.registered_entities[mob] - local enabled = (not peaceful) or (mob_def and mob_spawn_class ~= "hostile") - for _, node in pairs(sp) do - if enabled and count < n and minetest.add_entity(vector_offset(node, 0, 1, 0), mob) then - count = count + 1 - end - minetest.get_meta(node):set_string("spawnblock", "yes") -- note: also in peaceful mode! - end -end -