Restore nether_portal in spawnstruct list

This commit is contained in:
kay27 2022-01-17 20:03:46 +04:00
parent 6eb126da40
commit 30a0eb1d4a
4 changed files with 87 additions and 64 deletions

View File

@ -1,4 +1,4 @@
name = mcl_portals
description = Adds buildable portals to the Nether and End dimensions.
depends = mcl_mapgen, mcl_nether, mcl_end, mcl_particles, mcl_spawn, mcl_credits
depends = mcl_mapgen, mcl_nether, mcl_end, mcl_particles, mcl_spawn, mcl_credits, mcl_structures
optional_depends = awards, doc

View File

@ -355,7 +355,7 @@ function build_nether_portal(pos, width, height, orientation, name, clear_before
return pos
end
function mcl_portals.spawn_nether_portal(pos, rot, pr, name)
function mcl_portals.spawn_nether_portal(pos, rot, pr, placer)
if not pos then return end
local o = 0
if rot then
@ -365,6 +365,10 @@ function mcl_portals.spawn_nether_portal(pos, rot, pr, name)
o = random(0,1)
end
end
local name
if placer and placer:is_player() then
name = placer:get_player_name()
end
build_nether_portal(pos, nil, nil, o, name, true)
end
@ -753,6 +757,8 @@ local function teleport(obj, portal_pos)
minetest.after(DELAY, teleport_no_delay, obj, portal_pos)
end
mcl_structures.register_structure({name = "nether_portal", place_function = mcl_portals.spawn_nether_portal})
minetest.register_abm({
label = "Nether portal teleportation and particles",
nodenames = {PORTAL},

View File

@ -19,6 +19,74 @@ local on_finished_chunk_callbacks = {}
mcl_structures.perlin_noise = minetest.get_perlin(329, 3, 0.6, 100)
local spawnstruct_hint = S("Use /help spawnstruct to see a list of avaiable types.")
local function dir_to_rotation(dir)
local ax, az = math.abs(dir.x), math.abs(dir.z)
if ax > az then
if dir.x < 0 then
return "270"
end
return "90"
end
if dir.z < 0 then
return "180"
end
return "0"
end
local function spawnstruct_function(name, param)
local player = minetest.get_player_by_name(name)
if not player then return end
if param == "" then
minetest.chat_send_player(name, S("Error: No structure type given. Please use “/spawnstruct <type>”."))
minetest.chat_send_player(name, spawnstruct_hint)
return
end
local struct = registered_structures[param]
if not struct then
struct = registered_structures[name_prefix .. param]
end
if not struct then
minetest.chat_send_player(name, S("Error: Unknown structure type. Please use “/spawnstruct <type>”."))
minetest.chat_send_player(name, spawnstruct_hint)
return
end
local place = struct.place_function
if not place then return end
local pos = player:get_pos()
if not pos then return end
local pr = PseudoRandom(math.floor(pos.x * 333 + pos.y * 19 - pos.z + 4))
pos = vector.round(pos)
local dir = minetest.yaw_to_dir(player:get_look_horizontal())
local rot = dir_to_rotation(dir)
place(pos, rot, pr, player)
minetest.chat_send_player(name, S("Structure placed."))
end
local function update_spawnstruct_chatcommand()
local spawnstruct_params = ""
for _, registered_structure in pairs(registered_structures) do
if spawnstruct_params ~= "" then
spawnstruct_params = spawnstruct_params .. " | "
end
spawnstruct_params = spawnstruct_params .. registered_structure.short_name
end
local def = {
params = spawnstruct_params,
description = S("Generate a pre-defined structure near your position."),
privs = {debug = true},
func = spawnstruct_function,
}
local registered_chatcommands = minetest.registered_chatcommands
if registered_chatcommands["spawnstruct"] then
minetest.override_chatcommand("spawnstruct", def)
else
minetest.register_chatcommand("spawnstruct", def)
end
end
function process_mapgen_block_lvm(vm_context)
local nodes = minetest.find_nodes_in_area(vm_context.minp, vm_context.maxp, {"group:struct"}, true)
for node_name, pos_list in pairs(nodes) do
@ -54,14 +122,15 @@ end
-- decoration - decoration definition, to use as structure seed (thanks cora for the idea)
-- on_finished_block - callback, if needed, to use with decorations: funcion(vm_context, pos_list)
-- on_finished_chunk - next callback if needed: funcion(minp, maxp, seed, vm_context, pos_list)
-- place_function - callback to place schematic by /spawnstruct debug command: function(pos, rotation, pr)
-- place_function - callback to place schematic by /spawnstruct debug command: function(pos, rotation, pr, placer)
-- on_placed - useful when you want to process the area after placement: function(pos, rotation, pr, size)
function mcl_structures.register_structure(def)
local short_name = def.name
local name = "mcl_structures:" .. short_name
local decoration = def.decoration
local on_finished_block = def.on_finished_block
local on_finished_block = def.on_finished_block
local on_finished_chunk = def.on_finished_chunk
local place_function = def.place_function
if not name then
minetest.log('warning', 'Structure name is not passed for registration - ignoring')
return
@ -108,12 +177,13 @@ function mcl_structures.register_structure(def)
})
end
registered_structures[name] = {
place_function = def.place_function,
place_function = place_function,
on_finished_block = on_finished_block,
on_finished_chunk = on_finished_chunk,
decoration_id = decoration_id,
short_name = short_name,
}
update_spawnstruct_chatcommand()
if on_finished_block then
on_finished_block_callbacks[name] = on_finished_block
if not use_process_mapgen_block_lvm then
@ -535,62 +605,4 @@ function mcl_structures.generate_end_gateway_portal(pos, rot)
return mcl_structures.place_schematic(pos, path, rot or "0", nil, true)
end
local function dir_to_rotation(dir)
local ax, az = math.abs(dir.x), math.abs(dir.z)
if ax > az then
if dir.x < 0 then
return "270"
end
return "90"
end
if dir.z < 0 then
return "180"
end
return "0"
end
dofile(modpath .. "/structures.lua")
-- Debug command
local spawnstruct_params = ""
for _, registered_structure in pairs(registered_structures) do
if spawnstruct_params ~= "" then
spawnstruct_params = spawnstruct_params .. " | "
end
spawnstruct_params = spawnstruct_params .. registered_structure.short_name
end
local spawnstruct_hint = S("Use /help spawnstruct to see a list of avaiable types.")
minetest.register_chatcommand("spawnstruct", {
params = spawnstruct_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
if param == "" then
minetest.chat_send_player(name, S("Error: No structure type given. Please use “/spawnstruct <type>”."))
minetest.chat_send_player(name, spawnstruct_hint)
return
end
local struct = registered_structures[param]
if not struct then
struct = registered_structures[name_prefix .. param]
end
if not struct then
minetest.chat_send_player(name, S("Error: Unknown structure type. Please use “/spawnstruct <type>”."))
minetest.chat_send_player(name, spawnstruct_hint)
return
end
local place = struct.place_function
if not place then return end
local pos = player:get_pos()
if not pos then return end
local pr = PseudoRandom(math.floor(pos.x * 333 + pos.y * 19 - pos.z + 4))
pos = vector.round(pos)
local dir = minetest.yaw_to_dir(player:get_look_horizontal())
local rot = dir_to_rotation(dir)
place(pos, rot, pr)
minetest.chat_send_player(name, S("Structure placed."))
end
})

View File

@ -29,7 +29,12 @@ end
local stair_support_node = {name = "mcl_core:cobble"}
local function on_placed(p1, rotation, pr, size)
local p2 = {x = p1.x + sx - 1, y = p1.y + sy - 1, z = p1.z + sz - 1}
local p2
if rotation == "90" or rotation == "270" then
p2 = {x = p1.x + sz - 1, y = p1.y + sy - 1, z = p1.z + sx - 1}
else
p2 = {x = p1.x + sx - 1, y = p1.y + sy - 1, z = p1.z + sz - 1}
end
-- Support stairs
local y = p1.y + 5