mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-25 20:11:06 +01:00
Add /spawnstruct support
This commit is contained in:
parent
8fa67e6b4f
commit
b0b8638a4c
3 changed files with 79 additions and 72 deletions
|
@ -8,7 +8,7 @@ local adjacents = {
|
|||
}
|
||||
|
||||
local function makegeode(pos,pr)
|
||||
local size = pr:next(3,18)
|
||||
local size = pr:next(4,12)
|
||||
local p1 = vector.offset(pos,-size,-size,-size)
|
||||
local p2 = vector.offset(pos,size,size,size)
|
||||
local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone"})
|
||||
|
@ -49,7 +49,7 @@ local function makegeode(pos,pr)
|
|||
end
|
||||
end
|
||||
|
||||
mcl_structures.register_structure("geodes",{
|
||||
mcl_structures.register_structure("geode",{
|
||||
place_on = {"mcl_core:stone"},
|
||||
spawn_by = {"air"},
|
||||
num_spawn_by = 2,
|
||||
|
@ -65,11 +65,3 @@ mcl_structures.register_structure("geodes",{
|
|||
makegeode(pos,pr)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("makegeode",{
|
||||
privs = { debug = true },
|
||||
func=function(n,p)
|
||||
local pos = pl:get_pos()
|
||||
makegeode(pos,PseudoRandom(minetest.get_mapgen_setting("seed")))
|
||||
end
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local registered_structures = {}
|
||||
mcl_structures.registered_structures = {}
|
||||
|
||||
--[[] structure def:
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ local registered_structures = {}
|
|||
}
|
||||
]]--
|
||||
|
||||
local function place_schem(pos, def, pr)
|
||||
function mcl_structures.place_structure(pos, def, pr)
|
||||
if not def then return end
|
||||
if type(def.y_offset) == "function" then
|
||||
y_offset = def.y_offset(pr)
|
||||
|
@ -67,12 +67,12 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it
|
|||
for _, pos in pairs(gennotify["decoration#"..deco_id] or {}) do
|
||||
local realpos = vector.offset(pos,0,-1,0)
|
||||
minetest.remove_node(realpos)
|
||||
place_schem(realpos,def,pr)
|
||||
mcl_structures.place_structure(realpos,def,pr)
|
||||
end
|
||||
end)
|
||||
end
|
||||
minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups})
|
||||
registered_structures[name] = def
|
||||
mcl_structures.registered_structures[name] = def
|
||||
end
|
||||
|
||||
--lbm for secondary structures (structblock included in base structure)
|
||||
|
@ -82,9 +82,9 @@ minetest.register_lbm({
|
|||
nodenames = {"group:structblock_lbm"},
|
||||
action = function(pos, node)
|
||||
local name = node.name:gsub("mcl_structures:structblock_","")
|
||||
local def = registered_structures[name]
|
||||
local def = mcl_structures.registered_structures[name]
|
||||
if not def then return end
|
||||
minetest.remove_node(pos)
|
||||
place_schem(pos)
|
||||
mcl_structures.place_structure(pos)
|
||||
end
|
||||
})
|
||||
|
|
|
@ -573,60 +573,75 @@ end
|
|||
|
||||
dofile(modpath.."/api.lua")
|
||||
|
||||
-- Debug command
|
||||
minetest.register_chatcommand("spawnstruct", {
|
||||
params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | nether_portal | dungeon",
|
||||
description = S("Generate a pre-defined structure near your position."),
|
||||
privs = {debug = true},
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
local pos = player:get_pos()
|
||||
if not pos then return end
|
||||
pos = vector.round(pos)
|
||||
local dir = minetest.yaw_to_dir(player:get_look_horizontal())
|
||||
local rot = dir_to_rotation(dir)
|
||||
local pr = PseudoRandom(pos.x+pos.y+pos.z)
|
||||
local errord = false
|
||||
local message = S("Structure placed.")
|
||||
if param == "desert_temple" then
|
||||
mcl_structures.generate_desert_temple(pos, rot, pr)
|
||||
elseif param == "desert_well" then
|
||||
mcl_structures.generate_desert_well(pos, rot)
|
||||
elseif param == "igloo" then
|
||||
mcl_structures.generate_igloo(pos, rot, pr)
|
||||
elseif param == "witch_hut" then
|
||||
mcl_structures.generate_witch_hut(pos, rot, pr)
|
||||
elseif param == "boulder" then
|
||||
mcl_structures.generate_boulder(pos, rot, pr)
|
||||
elseif param == "fossil" then
|
||||
mcl_structures.generate_fossil(pos, rot, pr)
|
||||
elseif param == "ice_spike_small" then
|
||||
mcl_structures.generate_ice_spike_small(pos, rot, pr)
|
||||
elseif param == "ice_spike_large" then
|
||||
mcl_structures.generate_ice_spike_large(pos, rot, pr)
|
||||
elseif param == "end_exit_portal" then
|
||||
mcl_structures.generate_end_exit_portal(pos, rot, pr)
|
||||
elseif param == "end_exit_portal_open" then
|
||||
mcl_structures.generate_end_exit_portal_open(pos, rot, pr)
|
||||
elseif param == "end_gateway_portal" then
|
||||
mcl_structures.generate_end_gateway_portal(pos, rot, pr)
|
||||
elseif param == "end_portal_shrine" then
|
||||
mcl_structures.generate_end_portal_shrine(pos, rot, pr)
|
||||
elseif param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then
|
||||
mcl_dungeons.spawn_dungeon(pos, rot, pr)
|
||||
elseif param == "nether_portal" and mcl_portals and mcl_portals.spawn_nether_portal then
|
||||
mcl_portals.spawn_nether_portal(pos, rot, pr, name)
|
||||
elseif param == "" then
|
||||
message = S("Error: No structure type given. Please use “/spawnstruct <type>”.")
|
||||
errord = true
|
||||
else
|
||||
message = S("Error: Unknown structure type. Please use “/spawnstruct <type>”.")
|
||||
errord = true
|
||||
end
|
||||
minetest.chat_send_player(name, message)
|
||||
if errord then
|
||||
minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types."))
|
||||
end
|
||||
minetest.register_on_mods_loaded(function()
|
||||
-- Debug command
|
||||
local chatcommand_params = "desert_temple | desert_well | igloo | witch_hut | boulder | ice_spike_small | ice_spike_large | fossil | end_exit_portal | end_exit_portal_open | end_gateway_portal | end_portal_shrine | nether_portal | dungeon"
|
||||
|
||||
for n,_ in pairs(mcl_structures.registered_structures) do
|
||||
chatcommand_params = chatcommand_params .. " | "..n
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("spawnstruct", {
|
||||
params = chatcommand_params,
|
||||
description = S("Generate a pre-defined structure near your position."),
|
||||
privs = {debug = true},
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
local pos = player:get_pos()
|
||||
if not pos then return end
|
||||
pos = vector.round(pos)
|
||||
local dir = minetest.yaw_to_dir(player:get_look_horizontal())
|
||||
local rot = dir_to_rotation(dir)
|
||||
local pr = PseudoRandom(pos.x+pos.y+pos.z)
|
||||
local errord = false
|
||||
local message = S("Structure placed.")
|
||||
if param == "desert_temple" then
|
||||
mcl_structures.generate_desert_temple(pos, rot, pr)
|
||||
elseif param == "desert_well" then
|
||||
mcl_structures.generate_desert_well(pos, rot)
|
||||
elseif param == "igloo" then
|
||||
mcl_structures.generate_igloo(pos, rot, pr)
|
||||
elseif param == "witch_hut" then
|
||||
mcl_structures.generate_witch_hut(pos, rot, pr)
|
||||
elseif param == "boulder" then
|
||||
mcl_structures.generate_boulder(pos, rot, pr)
|
||||
elseif param == "fossil" then
|
||||
mcl_structures.generate_fossil(pos, rot, pr)
|
||||
elseif param == "ice_spike_small" then
|
||||
mcl_structures.generate_ice_spike_small(pos, rot, pr)
|
||||
elseif param == "ice_spike_large" then
|
||||
mcl_structures.generate_ice_spike_large(pos, rot, pr)
|
||||
elseif param == "end_exit_portal" then
|
||||
mcl_structures.generate_end_exit_portal(pos, rot, pr)
|
||||
elseif param == "end_exit_portal_open" then
|
||||
mcl_structures.generate_end_exit_portal_open(pos, rot, pr)
|
||||
elseif param == "end_gateway_portal" then
|
||||
mcl_structures.generate_end_gateway_portal(pos, rot, pr)
|
||||
elseif param == "end_portal_shrine" then
|
||||
mcl_structures.generate_end_portal_shrine(pos, rot, pr)
|
||||
elseif param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then
|
||||
mcl_dungeons.spawn_dungeon(pos, rot, pr)
|
||||
elseif param == "nether_portal" and mcl_portals and mcl_portals.spawn_nether_portal then
|
||||
mcl_portals.spawn_nether_portal(pos, rot, pr, name)
|
||||
elseif param == "" then
|
||||
message = S("Error: No structure type given. Please use “/spawnstruct <type>”.")
|
||||
errord = true
|
||||
else
|
||||
for n,d in pairs(mcl_structures.registered_structures) do
|
||||
if n == param then
|
||||
mcl_structures.place_structure(pos,d,PseudoRandom(os.clock()))
|
||||
minetest.chat_send_player(name, message)
|
||||
return
|
||||
end
|
||||
end
|
||||
message = S("Error: Unknown structure type. Please use “/spawnstruct <type>”.")
|
||||
errord = true
|
||||
end
|
||||
minetest.chat_send_player(name, message)
|
||||
if errord then
|
||||
minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types."))
|
||||
end
|
||||
end
|
||||
})
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue