Add mob spawning test structures

/spawnstruct spawncircle and spawncircle_lit
This commit is contained in:
cora 2022-11-14 20:46:57 +01:00
parent 6f2cc2fd8e
commit c1e7d0ba76
2 changed files with 75 additions and 2 deletions

View File

@ -1,4 +1,13 @@
math.randomseed(os.time()) math.randomseed(os.time())
local function get_point_on_circle(pos,r,n)
local rt = {}
for i=1, n do
table.insert(rt,vector.offset(pos,r * math.cos(((i-1)/n) * (2*math.pi)),0, r* math.sin(((i-1)/n) * (2*math.pi)) ))
end
return rt[math.random(#rt)]
end
minetest.register_chatcommand("mobtest",{ minetest.register_chatcommand("mobtest",{
description="Spawns all available mobs", description="Spawns all available mobs",
privs={server=true}, privs={server=true},
@ -7,7 +16,7 @@ minetest.register_chatcommand("mobtest",{
local pos=p:get_pos() local pos=p:get_pos()
for k,v in pairs(minetest.registered_entities) do for k,v in pairs(minetest.registered_entities) do
if v.is_mob then if v.is_mob then
local spos=vector.add(pos,vector.new(math.random(100)-50,0,math.random(100)-50)) local spos=vector.add(pos,get_point_on_circle(pos,28,32))
local o = mcl_mobs.spawn(spos,v.name) local o = mcl_mobs.spawn(spos,v.name)
if o then if o then
local l=o:get_luaentity() local l=o:get_luaentity()
@ -19,3 +28,67 @@ minetest.register_chatcommand("mobtest",{
end end
end end
end}) end})
mcl_structures.register_structure("spawncircle",{
place_func = function(pos,def,pr)
local p1 = vector.offset(pos,-36,-5,-36)
local p2 = vector.offset(pos,36,5,36)
local nn1 = minetest.find_nodes_in_area_under_air(p1,p2,{"group:solid","group:plant","group:leaves","group:tree","group:mushroom"})
local c1 = {}
local c2 = {}
for k,v in pairs(nn1) do
local dst1=vector.distance(vector.round(vector.new(pos.x,0,pos.z)),vector.round(vector.new(v.x,0,v.z)))
local dst2=vector.distance(vector.round(vector.new(pos.x,0,pos.z)),vector.round(vector.new(v.x,0,v.z)))
if dst1 > 20 and dst1 < 22 then
table.insert(c1,v)
elseif dst2 > 33 and dst2 < 35 then
table.insert(c2,v)
end
end
local cobble = {}
local brick = {}
for k,v in pairs(c1) do
for i=1,6 do table.insert(cobble,vector.offset(v,0,(i-1),0)) end
minetest.set_node(vector.offset(v,0,6,0),{name="mcl_stairs:slab_andesite_smooth"})
end
for k,v in pairs(c2) do
for i=1,8 do table.insert(brick,vector.offset(v,0,(i-1),0)) end
minetest.set_node(vector.offset(v,0,8,0),{name="mcl_stairs:slab_diorite_smooth"})
end
minetest.bulk_set_node(cobble,{name="mcl_core:cobble"})
minetest.bulk_set_node(brick,{name="mcl_core:stonebrick"})
minetest.set_node(vector.offset(pos,0,-1,0),{name="mcl_core:obsidian"})
end
},true)
mcl_structures.register_structure("spawncircle_lit",{
place_func = function(pos,def,pr)
local p1 = vector.offset(pos,-33,-5,-33)
local p2 = vector.offset(pos,33,5,33)
local nn1 = minetest.find_nodes_in_area_under_air(p1,p2,{"group:solid","group:plant","group:leaves","group:tree","group:mushroom"})
local c1 = {}
local c2 = {}
for k,v in pairs(nn1) do
local dst1=vector.distance(vector.round(vector.new(pos.x,0,pos.z)),vector.round(vector.new(v.x,0,v.z)))
local dst2=vector.distance(vector.round(vector.new(pos.x,0,pos.z)),vector.round(vector.new(v.x,0,v.z)))
if dst1 > 23 and dst1 < 25 then
table.insert(c1,v)
elseif dst2 > 31 and dst2 < 33 then
table.insert(c2,v)
end
end
local cobble = {}
local brick = {}
for k,v in pairs(c1) do
for i=1,6 do table.insert(cobble,vector.offset(v,0,(i-1),0)) end
minetest.set_node(vector.offset(v,0,6,0),{name="mcl_stairs:slab_andesite_smooth"})
end
for k,v in pairs(c2) do
for i=1,8 do table.insert(brick,vector.offset(v,0,(i-1),0)) end
minetest.set_node(vector.offset(v,0,8,0),{name="mcl_stairs:slab_diorite_smooth"})
end
minetest.bulk_set_node(cobble,{name="mcl_nether:glowstone"})
minetest.bulk_set_node(brick,{name="mcl_ocean:sea_lantern"})
minetest.set_node(vector.offset(pos,0,-1,0),{name="mcl_core:obsidian"})
end
},true)

View File

@ -1,2 +1,2 @@
name = mobtest name = mobtest
depends = mcl_mobs depends = mcl_mobs, mcl_structures