First pass on `mcl_structures` (there are still issues I can't resolve)

- use new vectors
- comment unused functions and variables (translator, etc)
- no longer redifine variables in a confusible way
- add (very) basic type annotations
- simplify some parts of the code
- make /spawnstruct command always return boolean + output instead of chant_send_player
- simplify /spawnstruct command code
This commit is contained in:
AFCMS 2022-11-11 10:35:25 +01:00
parent 589bf75e6a
commit 3a2ce2feb8
Signed by untrusted user: AFCMS
GPG Key ID: 8720389A25B652E3
14 changed files with 804 additions and 672 deletions

View File

@ -1,9 +1,7 @@
mcl_structures.registered_structures = {} mcl_structures.registered_structures = {}
local place_queue = {} local place_queue = {}
local disabled_structures = minetest.settings:get("mcl_disabled_structures") local disabled_structures = minetest.settings:get("mcl_disabled_structures"):split(",")
if disabled_structures then disabled_structures = disabled_structures:split(",")
else disabled_structures = {} end
local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false) local peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
local mob_cap_player = tonumber(minetest.settings:get("mcl_mob_cap_player")) or 75 local mob_cap_player = tonumber(minetest.settings:get("mcl_mob_cap_player")) or 75
@ -13,11 +11,13 @@ local logging = minetest.settings:get_bool("mcl_logging_structures",true)
local mg_name = minetest.get_mapgen_setting("mg_name") local mg_name = minetest.get_mapgen_setting("mg_name")
local modpath = minetest.get_modpath("mcl_structures")
local rotations = { local rotations = {
"0", "0",
"90", "90",
"180", "180",
"270" "270",
} }
function mcl_structures.is_disabled(structname) function mcl_structures.is_disabled(structname)
@ -26,17 +26,21 @@ end
local function ecb_place(blockpos, action, calls_remaining, param) local function ecb_place(blockpos, action, calls_remaining, param)
if calls_remaining >= 1 then return end if calls_remaining >= 1 then return end
minetest.place_schematic(param.pos, param.schematic, param.rotation, param.replacements, param.force_placement, param.flags) minetest.place_schematic(param.pos, param.schematic, param.rotation, param.replacements, param.force_placement,
param.flags)
if param.after_placement_callback and param.p1 and param.p2 then if param.after_placement_callback and param.p1 and param.p2 then
param.after_placement_callback(param.p1, param.p2, param.size, param.rotation, param.pr, param.callback_param) param.after_placement_callback(param.p1, param.p2, param.size, param.rotation, param.pr, param.callback_param)
end end
end end
function mcl_structures.place_schematic(pos, schematic, rotation, replacements, force_placement, flags, after_placement_callback, pr, callback_param) function mcl_structures.place_schematic(pos, schematic, rotation, replacements, force_placement, flags,
after_placement_callback, pr, callback_param)
if type(schematic) ~= "table" and not mcl_util.file_exists(schematic) then if type(schematic) ~= "table" and not mcl_util.file_exists(schematic) then
minetest.log("warning", "[mcl_structures] schematic file " .. tostring(schematic) .. " does not exist.") minetest.log("warning", "[mcl_structures] schematic file " .. tostring(schematic) .. " does not exist.")
return end return
local s = loadstring(minetest.serialize_schematic(schematic, "lua", {lua_use_comments = false, lua_num_indent_spaces = 0}) .. " return schematic")() end
local s = loadstring(minetest.serialize_schematic(schematic, "lua",
{ lua_use_comments = false, lua_num_indent_spaces = 0 }) .. " return schematic")()
if s and s.size then if s and s.size then
local x, z = s.size.x, s.size.z local x, z = s.size.x, s.size.z
if rotation then if rotation then
@ -50,23 +54,32 @@ function mcl_structures.place_schematic(pos, schematic, rotation, replacements,
x, z = z, x x, z = z, x
end end
end end
local p1 = {x=pos.x , y=pos.y , z=pos.z } local p1 = vector.copy(pos)
local p2 = {x=pos.x+x-1, y=pos.y+s.size.y-1, z=pos.z+z-1} local p2 = vector.offset(pos, x - 1, s.size.y - 1, z - 1)
minetest.log("verbose", "[mcl_structures] size=" ..minetest.pos_to_string(s.size) .. ", rotation=" .. tostring(rotation) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) minetest.log("verbose",
local param = {pos=vector.new(pos), schematic=s, rotation=rotation, replacements=replacements, force_placement=force_placement, flags=flags, p1=p1, p2=p2, after_placement_callback = after_placement_callback, size=vector.new(s.size), pr=pr, callback_param=callback_param} "[mcl_structures] size=" ..
minetest.pos_to_string(s.size) ..
", rotation=" ..
tostring(rotation) .. ", emerge from " .. minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2))
local param = { pos = vector.copy(pos), schematic = s, rotation = rotation, replacements = replacements,
force_placement = force_placement, flags = flags, p1 = p1, p2 = p2,
after_placement_callback = after_placement_callback, size = vector.copy(s.size), pr = pr,
callback_param = callback_param }
minetest.emerge_area(p1, p2, ecb_place, param) minetest.emerge_area(p1, p2, ecb_place, param)
return true return true
end end
end end
function mcl_structures.get_struct(file) function mcl_structures.get_struct(filename)
local localfile = modpath.."/schematics/"..file local localfile = modpath .. "/schematics/" .. filename
local file, errorload = io.open(localfile, "rb") local file, errorload = io.open(localfile, "rb")
if errorload then if errorload then
minetest.log("error", "[mcl_structures] Could not open this struct: " .. localfile) minetest.log("error", "[mcl_structures] Could not open this struct: " .. localfile)
return nil return nil
end end
assert(file)
local allnode = file:read("*a") local allnode = file:read("*a")
file:close() file:close()
@ -75,6 +88,7 @@ end
-- Call on_construct on pos. -- Call on_construct on pos.
-- Useful to init chests from formspec. -- Useful to init chests from formspec.
---@param pos Vector
local function init_node_construct(pos) local function init_node_construct(pos)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
@ -84,8 +98,13 @@ local function init_node_construct(pos)
end end
return false return false
end end
mcl_structures.init_node_construct = init_node_construct mcl_structures.init_node_construct = init_node_construct
---@param p1 Vector
---@param p2 Vector
---@param loot table
---@param pr PseudoRandom
function mcl_structures.fill_chests(p1, p2, loot, pr) function mcl_structures.fill_chests(p1, p2, loot, pr)
for it, lt in pairs(loot) do for it, lt in pairs(loot) do
local nodes = minetest.find_nodes_in_area(p1, p2, it) local nodes = minetest.find_nodes_in_area(p1, p2, it)
@ -99,6 +118,9 @@ function mcl_structures.fill_chests(p1,p2,loot,pr)
end end
end end
---@param pos Vector
---@param def table
---@param pr PseudoRandom
local function generate_loot(pos, def, pr) local function generate_loot(pos, def, pr)
local hl = def.sidelen local hl = def.sidelen
local p1 = vector.offset(pos, -hl, -hl, -hl) local p1 = vector.offset(pos, -hl, -hl, -hl)
@ -106,6 +128,9 @@ local function generate_loot(pos, def, pr)
if def.loot then mcl_structures.fill_chests(p1, p2, def.loot, pr) end if def.loot then mcl_structures.fill_chests(p1, p2, def.loot, pr) end
end end
---@param p1 Vector
---@param p2 Vector
---@param nodes string[]
function mcl_structures.construct_nodes(p1, p2, nodes) function mcl_structures.construct_nodes(p1, p2, nodes)
local nn = minetest.find_nodes_in_area(p1, p2, nodes) local nn = minetest.find_nodes_in_area(p1, p2, nodes)
for _, p in pairs(nn) do for _, p in pairs(nn) do
@ -113,11 +138,19 @@ function mcl_structures.construct_nodes(p1,p2,nodes)
end end
end end
---@param pos Vector
---@param def table
---@param pr PseudoRandom
local function construct_nodes(pos, def, pr) local function construct_nodes(pos, def, pr)
return mcl_structures.construct_nodes(vector.offset(pos,-def.sidelen/2,0,-def.sidelen/2),vector.offset(pos,def.sidelen/2,def.sidelen,def.sidelen/2),def.construct_nodes) return mcl_structures.construct_nodes(
vector.offset(pos, -def.sidelen / 2, 0, -def.sidelen / 2),
vector.offset(pos, def.sidelen / 2, def.sidelen, def.sidelen / 2),
def.construct_nodes
)
end end
---@param pp Vector[]
---@return integer
function mcl_structures.find_lowest_y(pp) function mcl_structures.find_lowest_y(pp)
local y = 31000 local y = 31000
for _, p in pairs(pp) do for _, p in pairs(pp) do
@ -126,6 +159,8 @@ function mcl_structures.find_lowest_y(pp)
return y return y
end end
---@param pp Vector[]
---@return integer
function mcl_structures.find_highest_y(pp) function mcl_structures.find_highest_y(pp)
local y = -31000 local y = -31000
for _, p in pairs(pp) do for _, p in pairs(pp) do
@ -134,12 +169,18 @@ function mcl_structures.find_highest_y(pp)
return y return y
end end
---@param nn Vector[]
---@param pos Vector
---@param plane? boolean
---@param amnt? integer
---@return Vector[]
local function smooth_cube(nn, pos, plane, amnt) local function smooth_cube(nn, pos, plane, amnt)
local r = {} local r = {}
local amnt = amnt or 9 amnt = amnt or 9
table.sort(nn, function(a, b) table.sort(nn, function(a, b)
if false or plane then if false or plane then
return vector.distance(vector.new(pos.x,0,pos.z), vector.new(a.x,0,a.z)) < vector.distance(vector.new(pos.x,0,pos.z), vector.new(b.x,0,b.z)) return vector.distance(vector.new(pos.x, 0, pos.z), vector.new(a.x, 0, a.z)) <
vector.distance(vector.new(pos.x, 0, pos.z), vector.new(b.x, 0, b.z))
else else
return vector.distance(pos, a) < vector.distance(pos, b) return vector.distance(pos, a) < vector.distance(pos, b)
end end
@ -148,24 +189,32 @@ local function smooth_cube(nn,pos,plane,amnt)
return r return r
end end
---@param pos Vector
---@param nn Vector[]
---@param gn string
---@return integer
local function find_ground(pos, nn, gn) local function find_ground(pos, nn, gn)
local r = 0 local r = 0
for _, v in pairs(nn) do for _, v in pairs(nn) do
local p=vector.new(v) local p = vector.copy(v)
repeat repeat
local n = minetest.get_node(p).name local n = minetest.get_node(p).name
p = vector.offset(p, 0, -1, 0) p = vector.offset(p, 0, -1, 0)
until not n or n == "mcl_core:bedrock" or n == "ignore" or n == gn until not n or n == "mcl_core:bedrock" or n == "ignore" or n == gn
--minetest.log(tostring(pos.y - p.y)) --minetest.log(tostring(pos.y - p.y))
if pos.y - p.y > r then r = pos.y - p.y end if pos.y - p.y > r then
r = pos.y - p.y
end
end end
return r return r
end end
local function get_foundation_nodes(ground_p1, ground_p2, pos, sidelen, node_stone) local function get_foundation_nodes(ground_p1, ground_p2, pos, sidelen, node_stone)
local replace = {"air","group:liquid","mcl_core:snow","group:tree","group:leaves","group:plant","grass_block","group:dirt"} local replace = { "air", "group:liquid", "mcl_core:snow", "group:tree", "group:leaves", "group:plant", "grass_block",
"group:dirt" }
local depth = find_ground(pos, minetest.find_nodes_in_area(ground_p1, ground_p2, replace), node_stone) local depth = find_ground(pos, minetest.find_nodes_in_area(ground_p1, ground_p2, replace), node_stone)
local nn = smooth_cube(minetest.find_nodes_in_area(vector.offset(ground_p1,0,-1,0),vector.offset(ground_p2,0,-depth,0),replace),vector.offset(pos,0,-depth,0),true,sidelen * 64) local nn = smooth_cube(minetest.find_nodes_in_area(vector.offset(ground_p1, 0, -1, 0),
vector.offset(ground_p2, 0, -depth, 0), replace), vector.offset(pos, 0, -depth, 0), true, sidelen * 64)
local stone = {} local stone = {}
local filler = {} local filler = {}
local top = {} local top = {}
@ -207,7 +256,7 @@ local function foundation(ground_p1,ground_p2,pos,sidelen)
end end
local stone, filler, top, dust = get_foundation_nodes(ground_p1, ground_p2, pos, sidelen, node_stone) local stone, filler, top, dust = get_foundation_nodes(ground_p1, ground_p2, pos, sidelen, node_stone)
minetest.bulk_set_node(top,{name=node_top},node_stone) minetest.bulk_set_node(top, { name = node_top })
if node_dust then if node_dust then
minetest.bulk_set_node(dust, { name = node_dust }) minetest.bulk_set_node(dust, { name = node_dust })
@ -216,6 +265,7 @@ local function foundation(ground_p1,ground_p2,pos,sidelen)
minetest.bulk_set_node(stone, { name = node_stone }) minetest.bulk_set_node(stone, { name = node_stone })
end end
--[[
local function process_queue() local function process_queue()
if #place_queue < 1 then return end if #place_queue < 1 then return end
local s = table.remove(place_queue) local s = table.remove(place_queue)
@ -226,6 +276,7 @@ local function process_queue()
end, s.pr) end, s.pr)
minetest.after(0.5, process_queue) minetest.after(0.5, process_queue)
end end
]]
function mcl_structures.spawn_mobs(mob, spawnon, p1, p2, pr, n, water) function mcl_structures.spawn_mobs(mob, spawnon, p1, p2, pr, n, water)
n = n or 1 n = n or 1
@ -270,10 +321,12 @@ function mcl_structures.place_structure(pos, def, pr, blockseed, rot)
local solid = minetest.find_nodes_in_area(ground_p1, ground_p2, { "group:solid" }) local solid = minetest.find_nodes_in_area(ground_p1, ground_p2, { "group:solid" })
if #solid < (def.sidelen * def.sidelen) then if #solid < (def.sidelen * def.sidelen) then
if def.make_foundation then if def.make_foundation then
foundation(vector.offset(pos,-def.sidelen/2 - 3,-1,-def.sidelen/2 - 3),vector.offset(pos,def.sidelen/2 + 3,-1,def.sidelen/2 + 3),pos,def.sidelen) foundation(vector.offset(pos, -def.sidelen / 2 - 3, -1, -def.sidelen / 2 - 3),
vector.offset(pos, def.sidelen / 2 + 3, -1, def.sidelen / 2 + 3), pos, def.sidelen)
else else
if log_enabled then if log_enabled then
minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pp).." not placed. No solid ground.") minetest.log("warning",
"[mcl_structures] " .. def.name .. " at " .. minetest.pos_to_string(pp) .. " not placed. No solid ground.")
end end
return false return false
end end
@ -281,7 +334,8 @@ function mcl_structures.place_structure(pos, def, pr, blockseed, rot)
end end
if def.on_place and not def.on_place(pos, def, pr, blockseed) then if def.on_place and not def.on_place(pos, def, pr, blockseed) then
if log_enabled then if log_enabled then
minetest.log("warning","[mcl_structures] "..def.name.." at "..minetest.pos_to_string(pp).." not placed. Conditions not satisfied.") minetest.log("warning",
"[mcl_structures] " .. def.name .. " at " .. minetest.pos_to_string(pp) .. " not placed. Conditions not satisfied.")
end end
return false return false
end end
@ -291,16 +345,17 @@ function mcl_structures.place_structure(pos, def, pr, blockseed, rot)
local file = def.filenames[r] local file = def.filenames[r]
if file then if file then
local rot = rotations[pr:next(1, #rotations)] local rot = rotations[pr:next(1, #rotations)]
local ap = function(pos,def,pr,blockseed) end local ap = function(_, _, _, _) end
if def.daughters then if def.daughters then
ap = function(pos,def,pr,blockseed) ap = function(pos, def, pr, _)
for _, d in pairs(def.daughters) do for _, d in pairs(def.daughters) do
local p = vector.add(pos, d.pos) local p = vector.add(pos, d.pos)
local rot = d.rot or 0 local rot = d.rot or 0
mcl_structures.place_schematic(p, d.files[pr:next(1,#d.files)], rot, nil, true, "place_center_x,place_center_z",function() mcl_structures.place_schematic(p, d.files[pr:next(1, #d.files)], rot, nil, true, "place_center_x,place_center_z",
if def.loot then generate_loot(pp,def,pr,blockseed) end function()
if def.construct_nodes then construct_nodes(pp,def,pr,blockseed) end if def.loot then generate_loot(pp, def, pr) end
if def.construct_nodes then construct_nodes(pp, def, pr) end
if def.after_place then if def.after_place then
def.after_place(pos, def, pr) def.after_place(pos, def, pr)
end end
@ -310,12 +365,13 @@ function mcl_structures.place_structure(pos, def, pr, blockseed, rot)
elseif def.after_place then elseif def.after_place then
ap = def.after_place ap = def.after_place
end end
mcl_structures.place_schematic(pp, file, rot, def.replacements, true, "place_center_x,place_center_z",function(p1, p2, size, rotation) mcl_structures.place_schematic(pp, file, rot, def.replacements, true, "place_center_x,place_center_z",
function(p1, p2, size, rotation)
if not def.daughters then if not def.daughters then
if def.loot then generate_loot(pp,def,pr,blockseed) end if def.loot then generate_loot(pp, def, pr) end
if def.construct_nodes then construct_nodes(pp,def,pr,blockseed) end if def.construct_nodes then construct_nodes(pp, def, pr) end
end end
return ap(pp,def,pr,blockseed,p1,p2,size,rotation) return ap(pp, def, pr, blockseed)
end, pr) end, pr)
if log_enabled then if log_enabled then
minetest.log("action", "[mcl_structures] " .. def.name .. " placed at " .. minetest.pos_to_string(pp)) minetest.log("action", "[mcl_structures] " .. def.name .. " placed at " .. minetest.pos_to_string(pp))
@ -324,8 +380,8 @@ function mcl_structures.place_structure(pos, def, pr, blockseed, rot)
end end
elseif def.place_func and def.place_func(pp, def, pr, blockseed) then elseif def.place_func and def.place_func(pp, def, pr, blockseed) then
if not def.after_place or (def.after_place and def.after_place(pp, def, pr, blockseed)) then if not def.after_place or (def.after_place and def.after_place(pp, def, pr, blockseed)) then
if def.loot then generate_loot(pp,def,pr,blockseed) end if def.loot then generate_loot(pp, def, pr) end
if def.construct_nodes then construct_nodes(pp,def,pr,blockseed) end if def.construct_nodes then construct_nodes(pp, def, pr) end
if log_enabled then if log_enabled then
minetest.log("action", "[mcl_structures] " .. def.name .. " placed at " .. minetest.pos_to_string(pp)) minetest.log("action", "[mcl_structures] " .. def.name .. " placed at " .. minetest.pos_to_string(pp))
end end
@ -366,7 +422,8 @@ function mcl_structures.register_structure(name,def,nospawn) --nospawn means it
y_max = def.y_max, y_max = def.y_max,
y_min = def.y_min y_min = def.y_min
}) })
minetest.register_node(":"..structblock, {drawtype="airlike", walkable = false, pointable = false,groups = sbgroups,sunlight_propagates = true,}) minetest.register_node(":" .. structblock,
{ drawtype = "airlike", walkable = false, pointable = false, groups = sbgroups, sunlight_propagates = true, })
def.structblock = structblock def.structblock = structblock
def.deco_id = minetest.get_decoration_id("mcl_structures:deco_" .. name) def.deco_id = minetest.get_decoration_id("mcl_structures:deco_" .. name)
minetest.set_gen_notify({ decoration = true }, { def.deco_id }) minetest.set_gen_notify({ decoration = true }, { def.deco_id })

View File

@ -1,7 +1,9 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
---@param pos Vector
---@param def table
---@param pr PseudoRandom
local function temple_placement_callback(pos, def, pr) local function temple_placement_callback(pos, def, pr)
local hl = def.sidelen / 2 local hl = def.sidelen / 2
local p1 = vector.offset(pos, -hl, -hl, -hl) local p1 = vector.offset(pos, -hl, -hl, -hl)
@ -9,10 +11,10 @@ local function temple_placement_callback(pos,def, pr)
-- Delete cacti leftovers: -- Delete cacti leftovers:
local cactus_nodes = minetest.find_nodes_in_area_under_air(p1, p2, "mcl_core:cactus") local cactus_nodes = minetest.find_nodes_in_area_under_air(p1, p2, "mcl_core:cactus")
if cactus_nodes and #cactus_nodes > 0 then if cactus_nodes and #cactus_nodes > 0 then
for _, pos in pairs(cactus_nodes) do for _, cpos in pairs(cactus_nodes) do
local node_below = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) local node_below = minetest.get_node(vector.offset(cpos, 0, -1, 0))
if node_below and node_below.name == "mcl_core:sandstone" then if node_below and node_below.name == "mcl_core:sandstone" then
minetest.swap_node(pos, {name="air"}) minetest.swap_node(cpos, { name = "air" })
end end
end end
end end
@ -81,6 +83,7 @@ mcl_structures.register_structure("desert_temple",{
{ itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 }, { itemstring = "mcl_core:sand", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 }, { itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 },
} }
}} }
}
} }
}) })

View File

@ -1,5 +1,4 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
local spawnon = { "mcl_end:purpur_block" } local spawnon = { "mcl_end:purpur_block" }
@ -28,7 +27,8 @@ mcl_structures.register_structure("end_shipwreck",{
filenames = { filenames = {
modpath .. "/schematics/mcl_structures_end_shipwreck_1.mts", modpath .. "/schematics/mcl_structures_end_shipwreck_1.mts",
}, },
construct_nodes = {"mcl_chests:ender_chest_small","mcl_chests:ender_chest","mcl_brewing:stand_000","mcl_chests:violet_shulker_box_small"}, construct_nodes = { "mcl_chests:ender_chest_small", "mcl_chests:ender_chest", "mcl_brewing:stand_000",
"mcl_chests:violet_shulker_box_small" },
after_place = function(pos, def, pr) after_place = function(pos, def, pr)
local fr = minetest.find_node_near(pos, def.sidelen, { "mcl_itemframes:item_frame" }) local fr = minetest.find_node_near(pos, def.sidelen, { "mcl_itemframes:item_frame" })
if fr then if fr then
@ -61,20 +61,34 @@ mcl_structures.register_structure("end_shipwreck",{
{ itemstring = "mcl_books:book", weight = 1, func = function(stack, pr) { itemstring = "mcl_books:book", weight = 1, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr)
end }, end },
{ itemstring = "mcl_tools:pick_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_tools:pick_iron_enchanted", weight = 3,
{ itemstring = "mcl_tools:shovel_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:sword_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_tools:shovel_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:helmet_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:chestplate_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_tools:sword_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:leggings_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:boots_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_armor:helmet_iron_enchanted", weight = 3,
{ itemstring = "mcl_tools:pick_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:shovel_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_armor:chestplate_iron_enchanted", weight = 3,
{ itemstring = "mcl_tools:sword_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:helmet_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_armor:leggings_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:chestplate_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:leggings_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_armor:boots_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:boots_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:pick_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:shovel_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:sword_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:helmet_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:chestplate_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:leggings_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:boots_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 },
{ itemstring = "mcl_mobitems:iron_horse_armor", weight = 1, }, { itemstring = "mcl_mobitems:iron_horse_armor", weight = 1, },
{ itemstring = "mcl_mobitems:gold_horse_armor", weight = 1, }, { itemstring = "mcl_mobitems:gold_horse_armor", weight = 1, },
@ -99,7 +113,8 @@ mcl_structures.register_structure("end_boat",{
modpath .. "/schematics/mcl_structures_end_boat.mts", modpath .. "/schematics/mcl_structures_end_boat.mts",
}, },
after_place = spawn_shulkers, after_place = spawn_shulkers,
construct_nodes = {"mcl_chests:ender_chest_small","mcl_chests:ender_chest","mcl_brewing:stand_000","mcl_chests:violet_shulker_box_small"}, construct_nodes = { "mcl_chests:ender_chest_small", "mcl_chests:ender_chest", "mcl_brewing:stand_000",
"mcl_chests:violet_shulker_box_small" },
loot = { loot = {
["mcl_chests:chest_small"] = { { ["mcl_chests:chest_small"] = { {
stacks_min = 2, stacks_min = 2,
@ -112,18 +127,30 @@ mcl_structures.register_structure("end_boat",{
{ itemstring = "mcl_core:diamond", weight = 3, amount_min = 2, amount_max = 7 }, { itemstring = "mcl_core:diamond", weight = 3, amount_min = 2, amount_max = 7 },
{ itemstring = "mcl_mobitems:saddle", weight = 3, }, { itemstring = "mcl_mobitems:saddle", weight = 3, },
{ itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 },
{ itemstring = "mcl_tools:pick_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_tools:pick_iron_enchanted", weight = 3,
{ itemstring = "mcl_tools:shovel_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:sword_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_tools:shovel_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:helmet_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:chestplate_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_tools:sword_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:leggings_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:boots_iron_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_armor:helmet_iron_enchanted", weight = 3,
{ itemstring = "mcl_tools:pick_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:shovel_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_armor:chestplate_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:helmet_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:leggings_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_armor:leggings_iron_enchanted", weight = 3,
{ itemstring = "mcl_armor:boots_diamond_enchanted", weight = 3,func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:boots_iron_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:pick_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_tools:shovel_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:helmet_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:leggings_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:boots_diamond_enchanted", weight = 3,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_core:emerald", weight = 2, amount_min = 1, amount_max = 3 },
{ itemstring = "mcl_mobitems:iron_horse_armor", weight = 1, }, { itemstring = "mcl_mobitems:iron_horse_armor", weight = 1, },
{ itemstring = "mcl_mobitems:gold_horse_armor", weight = 1, }, { itemstring = "mcl_mobitems:gold_horse_armor", weight = 1, },

View File

@ -1,13 +1,14 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
mcl_structures.register_structure("end_spawn_obsidian_platform", { mcl_structures.register_structure("end_spawn_obsidian_platform", {
static_pos = { mcl_vars.mg_end_platform_pos }, static_pos = { mcl_vars.mg_end_platform_pos },
place_func = function(pos, def, pr) place_func = function(pos, def, pr)
local obby = minetest.find_nodes_in_area(vector.offset(pos,-2,0,-2),vector.offset(pos,2,0,2),{"air","mcl_end:end_stone"}) local obby = minetest.find_nodes_in_area(vector.offset(pos, -2, 0, -2), vector.offset(pos, 2, 0, 2),
local air = minetest.find_nodes_in_area(vector.offset(pos,-2,1,-2),vector.offset(pos,2,3,2),{"air","mcl_end:end_stone"}) { "air", "mcl_end:end_stone" })
local air = minetest.find_nodes_in_area(vector.offset(pos, -2, 1, -2), vector.offset(pos, 2, 3, 2),
{ "air", "mcl_end:end_stone" })
minetest.bulk_set_node(obby, { name = "mcl_core:obsidian" }) minetest.bulk_set_node(obby, { name = "mcl_core:obsidian" })
minetest.bulk_set_node(air, { name = "air" }) minetest.bulk_set_node(air, { name = "air" })
return true return true
@ -65,7 +66,8 @@ local function get_tower(p,h,tbl)
end end
local function make_endspike(pos, width, height) local function make_endspike(pos, width, height)
local nn = minetest.find_nodes_in_area(vector.offset(pos,-width/2,0,-width/2),vector.offset(pos,width/2,0,width/2),{"air","group:solid"}) local nn = minetest.find_nodes_in_area(vector.offset(pos, -width / 2, 0, -width / 2),
vector.offset(pos, width / 2, 0, width / 2), { "air", "group:solid" })
table.sort(nn, function(a, b) table.sort(nn, function(a, b)
return vector.distance(pos, a) < vector.distance(pos, b) return vector.distance(pos, a) < vector.distance(pos, b)
end) end)
@ -77,7 +79,7 @@ local function make_endspike(pos,width,height)
return vector.offset(pos, 0, height, 0) return vector.offset(pos, 0, height, 0)
end end
function make_cage(pos,width) local function make_cage(pos, width)
local nodes = {} local nodes = {}
local nodes2 = {} local nodes2 = {}
local r = math.max(1, math.floor(width / 2) - 2) local r = math.max(1, math.floor(width / 2) - 2)
@ -85,7 +87,9 @@ function make_cage(pos,width)
if x == r or x == -r or z == r or z == -r then if x == r or x == -r or z == r or z == -r then
table.insert(nodes, vector.add(pos, vector.new(x, y, z))) table.insert(nodes, vector.add(pos, vector.new(x, y, z)))
end end
end end end end
end
end
if xpanes then if xpanes then
minetest.bulk_set_node(nodes, { name = "xpanes:bar_flat" }) minetest.bulk_set_node(nodes, { name = "xpanes:bar_flat" })
for _, p in pairs(nodes) do for _, p in pairs(nodes) do
@ -97,7 +101,8 @@ end
local function get_points_on_circle(pos, r, n) local function get_points_on_circle(pos, r, n)
local rt = {} local rt = {}
for i = 1, n do 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)) )) 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 end
return rt return rt
end end

View File

@ -7,10 +7,11 @@ local adjacents = {
vector.new(0, -1, 0) vector.new(0, -1, 0)
} }
---@param pos Vector
---@param node node
local function set_node_no_bedrock(pos, node) local function set_node_no_bedrock(pos, node)
local n = minetest.get_node(pos) if minetest.get_node(pos).name == "mcl_core:bedrock" then return end
if n.name == "mcl_core:bedrock" then return end minetest.set_node(pos, node)
return minetest.set_node(pos,node)
end end
local function makegeode(pos, def, pr) local function makegeode(pos, def, pr)
@ -43,7 +44,8 @@ local function makegeode(pos,def,pr)
set_node_no_bedrock(v, { name = "mcl_amethyst:budding_amethyst_block" }) set_node_no_bedrock(v, { name = "mcl_amethyst:budding_amethyst_block" })
end end
all_amethyst = false all_amethyst = false
elseif an.name ~= "mcl_amethyst:amethyst_block" and an.name ~= "air" and an.name ~= "mcl_amethyst:budding_amethyst_block" then elseif an.name ~= "mcl_amethyst:amethyst_block" and an.name ~= "air" and
an.name ~= "mcl_amethyst:budding_amethyst_block" then
all_amethyst = false all_amethyst = false
end end
end end
@ -52,18 +54,19 @@ local function makegeode(pos,def,pr)
end end
for _, v in pairs(calcite) do for _, v in pairs(calcite) do
for _,vv in pairs(minetest.find_nodes_in_area(vector.offset(v,-1,-1,-1),vector.offset(v,1,1,1),{"group:material_stone"})) do for _, vv in pairs(minetest.find_nodes_in_area(vector.offset(v, -1, -1, -1), vector.offset(v, 1, 1, 1),
{ "group:material_stone" })) do
set_node_no_bedrock(vv, { name = "mcl_blackstone:basalt_smooth" }) set_node_no_bedrock(vv, { name = "mcl_blackstone:basalt_smooth" })
end end
end end
for k,v in pairs(minetest.find_nodes_in_area_under_air(p1,p2,{"mcl_amethyst:amethyst_block","mcl_amethyst:budding_amethyst_block"})) do for k, v in pairs(minetest.find_nodes_in_area_under_air(p1, p2,
{ "mcl_amethyst:amethyst_block", "mcl_amethyst:budding_amethyst_block" })) do
local r = pr:next(1, 50) local r = pr:next(1, 50)
if r < 10 then if r < 10 then
set_node_no_bedrock(vector.offset(v, 0, 1, 0), { name = "mcl_amethyst:amethyst_cluster", param2 = 1 }) set_node_no_bedrock(vector.offset(v, 0, 1, 0), { name = "mcl_amethyst:amethyst_cluster", param2 = 1 })
end end
end end
return true
end) end)
return true return true
end end

View File

@ -1,10 +1,13 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
---@param pos Vector
---@param pr PseudoRandom
---@return boolean|nil
---@return string
function mcl_structures.generate_igloo_top(pos, pr) function mcl_structures.generate_igloo_top(pos, pr)
-- Furnace does ot work atm because apparently meta is not set. Need a bit of help with fixing this for furnaces, bookshelves, and brewing stands. -- Furnace does ot work atm because apparently meta is not set. Need a bit of help with fixing this for furnaces, bookshelves, and brewing stands.
local newpos = {x=pos.x,y=pos.y-2,z=pos.z} local newpos = vector.offset(pos, 0, -2, 0)
local path = modpath .. "/schematics/mcl_structures_igloo_top.mts" local path = modpath .. "/schematics/mcl_structures_igloo_top.mts"
local rotation = tostring(pr:next(0, 3) * 90) local rotation = tostring(pr:next(0, 3) * 90)
return mcl_structures.place_schematic(newpos, path, rotation, nil, true, nil, function() return mcl_structures.place_schematic(newpos, path, rotation, nil, true, nil, function()
@ -32,6 +35,10 @@ local function spawn_mobs(p1,p2,vi,zv)
end end
end end
---@param pos Vector
---@param orientation any
---@param loot any
---@param pr PseudoRandom
function mcl_structures.generate_igloo_basement(pos, orientation, loot, pr) function mcl_structures.generate_igloo_basement(pos, orientation, loot, pr)
-- TODO: Add monster eggs -- TODO: Add monster eggs
local path = modpath .. "/schematics/mcl_structures_igloo_basement.mts" local path = modpath .. "/schematics/mcl_structures_igloo_basement.mts"
@ -44,6 +51,9 @@ function mcl_structures.generate_igloo_basement(pos, orientation, loot, pr)
end, pr) end, pr)
end end
---@param pos Vector
---@param def table
---@param pr PseudoRandom
function mcl_structures.generate_igloo(pos, def, pr) function mcl_structures.generate_igloo(pos, def, pr)
-- Place igloo -- Place igloo
local success, rotation = mcl_structures.generate_igloo_top(pos, pr) local success, rotation = mcl_structures.generate_igloo_top(pos, pr)
@ -67,26 +77,26 @@ function mcl_structures.generate_igloo(pos, def, pr)
return success return success
end end
local depth = pr:next(19, buffer) local depth = pr:next(19, buffer)
local bpos = {x=pos.x, y=pos.y-depth, z=pos.z} local bpos = vector.offset(pos, 0, -depth, 0)
-- trapdoor position -- trapdoor position
local tpos local tpos
local dir, tdir local dir, tdir
if rotation == "0" then if rotation == "0" then
dir = {x=-1, y=0, z=0} dir = vector.new(-1, 0, 0)
tdir = {x=1, y=0, z=0} tdir = vector.new(1, 0, 0)
tpos = {x=pos.x+7, y=pos.y-2, z=pos.z+3} tpos = vector.offset(pos, 7, -2, 3)
elseif rotation == "90" then elseif rotation == "90" then
dir = {x=0, y=0, z=-1} dir = vector.new(0, 0, -1)
tdir = {x=0, y=0, z=-1} tdir = vector.new(0, 0, -1)
tpos = {x=pos.x+3, y=pos.y-2, z=pos.z+1} tpos = vector.offset(pos, 3, -2, 1)
elseif rotation == "180" then elseif rotation == "180" then
dir = {x=1, y=0, z=0} dir = vector.new(1, 0, 0)
tdir = {x=-1, y=0, z=0} tdir = vector.new(-1, 0, 0)
tpos = {x=pos.x+1, y=pos.y-2, z=pos.z+3} tpos = vector.offset(pos, 1, -2, 3)
elseif rotation == "270" then elseif rotation == "270" then
dir = {x=0, y=0, z=1} dir = vector.new(0, 0, 1)
tdir = {x=0, y=0, z=1} tdir = vector.new(0, 0, 1)
tpos = {x=pos.x+3, y=pos.y-2, z=pos.z+7} tpos = vector.offset(pos, 3, -2, 7)
else else
return success return success
end end
@ -109,14 +119,15 @@ function mcl_structures.generate_igloo(pos, def, pr)
end end
minetest.set_node(pos, { name = brick }) minetest.set_node(pos, { name = brick })
end end
local ladder_param2 = minetest.dir_to_wallmounted(tdir) local ladder_param2 = minetest.dir_to_wallmounted(tdir)
local real_depth = 0 local real_depth = 0
-- Check how deep we can actuall dig -- Check how deep we can actuall dig
for y = 1, depth - 5 do for y = 1, depth - 5 do
real_depth = real_depth + 1 real_depth = real_depth + 1
local node = minetest.get_node({x=tpos.x,y=tpos.y-y,z=tpos.z}) local node = minetest.get_node(vector.offset(tpos, 0, -y, 0))
local def = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
if not (def and def.walkable and def.liquidtype == "none" and def.is_ground_content) then if not (ndef and ndef.walkable and ndef.liquidtype == "none" and ndef.is_ground_content) then
bpos.y = tpos.y - y + 1 bpos.y = tpos.y - y + 1
break break
end end
@ -126,17 +137,17 @@ function mcl_structures.generate_igloo(pos, def, pr)
end end
-- Generate ladder to basement -- Generate ladder to basement
for y = 1, real_depth - 1 do for y = 1, real_depth - 1 do
set_brick({x=tpos.x-1,y=tpos.y-y,z=tpos.z }) set_brick(vector.offset(tpos, -1, -y, 0))
set_brick({x=tpos.x+1,y=tpos.y-y,z=tpos.z }) set_brick(vector.offset(tpos, 1, -y, 0))
set_brick({x=tpos.x ,y=tpos.y-y,z=tpos.z-1}) set_brick(vector.offset(tpos, 0, -y, -1))
set_brick({x=tpos.x ,y=tpos.y-y,z=tpos.z+1}) set_brick(vector.offset(tpos, 0, -y, 1))
minetest.set_node({x=tpos.x,y=tpos.y-y,z=tpos.z}, {name="mcl_core:ladder", param2=ladder_param2}) minetest.set_node(vector.offset(tpos, 0, -y, 0), { name = "mcl_core:ladder", param2 = ladder_param2 })
end end
-- Place basement -- Place basement
mcl_structures.generate_igloo_basement(bpos, rotation, def.loot, pr) mcl_structures.generate_igloo_basement(bpos, rotation, def.loot, pr)
-- Place hidden trapdoor -- Place hidden trapdoor
minetest.after(5, function(tpos, dir) minetest.after(5, function(tpos2, dir2)
minetest.set_node(tpos, {name="mcl_doors:trapdoor", param2=20+minetest.dir_to_facedir(dir)}) -- TODO: more reliable param2 minetest.set_node(tpos2, { name = "mcl_doors:trapdoor", param2 = 20 + minetest.dir_to_facedir(dir2) }) -- TODO: more reliable param2
end, tpos, dir) end, tpos, dir)
end end
return success return success

View File

@ -70,12 +70,16 @@ mcl_structures.register_structure("boulder",{
mcl_structures.register_structure("ice_spike_small", { mcl_structures.register_structure("ice_spike_small", {
filenames = { modpath .. "/schematics/mcl_structures_ice_spike_small.mts" }, filenames = { modpath .. "/schematics/mcl_structures_ice_spike_small.mts" },
}, true) --is spawned as a normal decoration. this is just for /spawnstruct }, true) --is spawned as a normal decoration. this is just for /spawnstruct
mcl_structures.register_structure("ice_spike_large", { mcl_structures.register_structure("ice_spike_large", {
sidelen = 6, sidelen = 6,
filenames = { modpath .. "/schematics/mcl_structures_ice_spike_large.mts" }, filenames = { modpath .. "/schematics/mcl_structures_ice_spike_large.mts" },
}, true) --is spawned as a normal decoration. this is just for /spawnstruct }, true) --is spawned as a normal decoration. this is just for /spawnstruct
-- Debug command
---Debug command
---@param dir Vector
---@return '"0"'|'"90"'|'"180"'|'"270"'
local function dir_to_rotation(dir) local function dir_to_rotation(dir)
local ax, az = math.abs(dir.x), math.abs(dir.z) local ax, az = math.abs(dir.x), math.abs(dir.z)
if ax > az then if ax > az then
@ -96,33 +100,39 @@ minetest.register_chatcommand("spawnstruct", {
privs = { debug = true }, privs = { debug = true },
func = function(name, param) func = function(name, param)
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return end
if not player then
return false, S("Player isn't online")
end
local pos = player:get_pos() local pos = player:get_pos()
if not pos then return end
pos = vector.round(pos) pos = vector.round(pos)
local dir = minetest.yaw_to_dir(player:get_look_horizontal()) local dir = minetest.yaw_to_dir(player:get_look_horizontal())
local rot = dir_to_rotation(dir) local rot = dir_to_rotation(dir)
local pr = PseudoRandom(pos.x + pos.y + pos.z) local pr = PseudoRandom(pos.x + pos.y + pos.z)
local errord = false local errord = false
local message = S("Structure placed.") local message = S("Structure placed.")
local uknown_struct_message = S("Error: Unknown structure type. Please use “/spawnstruct <type>”.") ..
"\n" .. S("Use /help spawnstruct to see a list of avaiable types.")
if param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then if param == "dungeon" and mcl_dungeons and mcl_dungeons.spawn_dungeon then
mcl_dungeons.spawn_dungeon(pos, rot, pr) mcl_dungeons.spawn_dungeon(pos, rot, pr)
elseif param == "" then
message = S("Error: No structure type given. Please use “/spawnstruct <type>”.")
errord = true
else else
for n,d in pairs(mcl_structures.registered_structures) do if mcl_structures.registered_structures[param] then
if n == param then mcl_structures.place_structure(pos, mcl_structures.registered_structures[param], pr, math.random(), rot)
mcl_structures.place_structure(pos,d,pr,math.random(),rot) else
return true,message message = uknown_struct_message
end
end
message = S("Error: Unknown structure type. Please use “/spawnstruct <type>”.")
errord = true errord = true
end end
minetest.chat_send_player(name, message) end
if errord then if errord then
minetest.chat_send_player(name, S("Use /help spawnstruct to see a list of avaiable types.")) return false, message
else
return true, message
end end
end end
}) })

View File

@ -1,5 +1,4 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
mcl_structures.register_structure("jungle_temple", { mcl_structures.register_structure("jungle_temple", {

View File

@ -1,5 +1,4 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
local cold_oceans = { local cold_oceans = {

View File

@ -1,7 +1,6 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_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 peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
local spawnon = { "mcl_core:stripped_oak", "mcl_stairs:slab_birchwood_top" } local spawnon = { "mcl_core:stripped_oak", "mcl_stairs:slab_birchwood_top" }
@ -58,7 +57,8 @@ mcl_structures.register_structure("pillager_outpost",{
items = { items = {
{ itemstring = "mcl_bows:crossbow" }, { itemstring = "mcl_bows:crossbow" },
} }
}} }
}
}, },
after_place = function(p, def, pr) after_place = function(p, def, pr)
local p1 = vector.offset(p, -9, 0, -9) local p1 = vector.offset(p, -9, 0, -9)

View File

@ -1,17 +1,22 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
---@param b Vector[]
---@param c integer
---@param pr PseudoRandom
---@return Vector[]
local function get_replacements(b, c, pr) local function get_replacements(b, c, pr)
local r = {} local r = {}
if not b then return r end if not b then return r end
for k,v in pairs(b) do for _, v in pairs(b) do
if pr:next(1, 100) < c then table.insert(r, v) end if pr:next(1, 100) < c then table.insert(r, v) end
end end
return r return r
end end
local def = { local def = {
place_on = {"group:grass_block","group:dirt","mcl_core:dirt_with_grass","group:grass_block","group:sand","group:grass_block_snow","mcl_core:snow"}, place_on = { "group:grass_block", "group:dirt", "mcl_core:dirt_with_grass", "group:grass_block", "group:sand",
"group:grass_block_snow", "mcl_core:snow" },
fill_ratio = 0.01, fill_ratio = 0.01,
flags = "place_center_x, place_center_z, all_floors", flags = "place_center_x, place_center_z, all_floors",
solid_ground = true, solid_ground = true,
@ -77,9 +82,13 @@ local def = {
} } } }
} }
} }
mcl_structures.register_structure("ruined_portal_overworld", def) mcl_structures.register_structure("ruined_portal_overworld", def)
local ndef = table.copy(def) local ndef = table.copy(def)
ndef.y_min = mcl_vars.mg_lava_nether_max + 10 ndef.y_min = mcl_vars.mg_lava_nether_max + 10
ndef.y_max = mcl_vars.mg_nether_max - 15 ndef.y_max = mcl_vars.mg_nether_max - 15
ndef.place_on = {"mcl_nether:netherrack","group:soul_block","mcl_blackstone:basalt,mcl_blackstone:blackstone","mcl_crimson:crimson_nylium","mcl_crimson:warped_nylium"}, ndef.place_on = { "mcl_nether:netherrack", "group:soul_block", "mcl_blackstone:basalt,mcl_blackstone:blackstone",
"mcl_crimson:crimson_nylium", "mcl_crimson:warped_nylium" }
mcl_structures.register_structure("ruined_portal_nether", ndef) mcl_structures.register_structure("ruined_portal_nether", ndef)

View File

@ -2,9 +2,9 @@ local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
--local S = minetest.get_translator(modname) --local S = minetest.get_translator(modname)
local seed = minetest.get_mapgen_setting("seed") --local seed = minetest.get_mapgen_setting("seed")
local water_level = minetest.get_mapgen_setting("water_level") local water_level = minetest.get_mapgen_setting("water_level")
local pr = PseudoRandom(seed) --local pr = PseudoRandom(seed)
--schematics by chmodsayshello --schematics by chmodsayshello
local schems = { local schems = {
@ -130,13 +130,17 @@ mcl_structures.register_structure("shipwreck",{
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 5, amount_min = 5, amount_max = 24 }, { itemstring = "mcl_mobitems:rotten_flesh", weight = 5, amount_min = 5, amount_max = 24 },
{ itemstring = "mcl_farming:potato_item", weight = 3, amount_min = 1, amount_max = 5 }, { itemstring = "mcl_farming:potato_item", weight = 3, amount_min = 1, amount_max = 5 },
{ itemstring = "mcl_armor:helmet_leather_enchanted", weight = 3, func = function(stack, pr) { itemstring = "mcl_armor:helmet_leather_enchanted", weight = 3, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" })
end },
{ itemstring = "mcl_armor:chestplate_leather_enchanted", weight = 3, func = function(stack, pr) { itemstring = "mcl_armor:chestplate_leather_enchanted", weight = 3, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" })
end },
{ itemstring = "mcl_armor:leggings_leather_enchanted", weight = 3, func = function(stack, pr) { itemstring = "mcl_armor:leggings_leather_enchanted", weight = 3, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" })
end },
{ itemstring = "mcl_armor:boots_leather_enchanted", weight = 3, func = function(stack, pr) { itemstring = "mcl_armor:boots_leather_enchanted", weight = 3, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}) end }, mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" })
end },
--{ itemstring = "TODO:bamboo", weight = 2, amount_min = 1, amount_max = 3 }, --{ itemstring = "TODO:bamboo", weight = 2, amount_min = 1, amount_max = 3 },
{ itemstring = "mcl_farming:pumpkin", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_farming:pumpkin", weight = 2, amount_min = 1, amount_max = 3 },
{ itemstring = "mcl_tnt:tnt", weight = 1, amount_min = 1, amount_max = 2 }, { itemstring = "mcl_tnt:tnt", weight = 1, amount_min = 1, amount_max = 2 },

View File

@ -1,5 +1,4 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_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 peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
@ -7,7 +6,8 @@ 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 local witch
if not peaceful then if not peaceful then
witch = minetest.add_entity(vector.offset(nn[math.random(#nn)], 0, 1, 0), "mobs_mc:witch"):get_luaentity() witch = minetest.add_entity(vector.offset(nn[math.random(#nn)], 0, 1, 0), "mobs_mc:witch"):get_luaentity()
@ -23,6 +23,9 @@ local function spawn_witch(p1,p2)
end end
end end
---@param pos Vector
---@param def table
---@param pr PseudoRandom
local function hut_placement_callback(pos, def, pr) local function hut_placement_callback(pos, def, pr)
local hl = def.sidelen / 2 local hl = def.sidelen / 2
local p1 = vector.offset(pos, -hl, -hl, -hl) local p1 = vector.offset(pos, -hl, -hl, -hl)

View File

@ -1,7 +1,6 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_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 peaceful = minetest.settings:get_bool("only_peaceful_mobs", false)
local spawnon = { "mcl_deepslate:deepslate", "mcl_core:birchwood", "mcl_wool:red_carpet", "mcl_wool:brown_carpet" } local spawnon = { "mcl_deepslate:deepslate", "mcl_core:birchwood", "mcl_wool:red_carpet", "mcl_wool:brown_carpet" }
@ -39,7 +38,8 @@ mcl_structures.register_structure("woodland_cabin",{
{ itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 }, { itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 }, { itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },
}},{ }
}, {
stacks_min = 1, stacks_min = 1,
stacks_max = 4, stacks_max = 4,
items = { items = {
@ -53,13 +53,15 @@ mcl_structures.register_structure("woodland_cabin",{
{ itemstring = "mcl_core:iron_ingot", weight = 10, amount_min = 1, amount_max = 4 }, { itemstring = "mcl_core:iron_ingot", weight = 10, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_buckets:bucket_empty", weight = 10, amount_min = 1, amount_max = 1 }, { itemstring = "mcl_buckets:bucket_empty", weight = 10, amount_min = 1, amount_max = 1 },
{ itemstring = "mcl_core:gold_ingot", weight = 5, amount_min = 1, amount_max = 4 }, { itemstring = "mcl_core:gold_ingot", weight = 5, amount_min = 1, amount_max = 4 },
}},{ }
}, {
stacks_min = 1, stacks_min = 1,
stacks_max = 4, stacks_max = 4,
items = { items = {
--{ itemstring = "FIXME:lead", weight = 20, amount_min = 1, amount_max = 1 }, --{ itemstring = "FIXME:lead", weight = 20, amount_min = 1, amount_max = 1 },
{ itemstring = "mcl_mobs:nametag", weight = 2, amount_min = 1, amount_max = 3 }, { itemstring = "mcl_mobs:nametag", weight = 2, amount_min = 1, amount_max = 3 },
{ itemstring = "mcl_books:book", weight = 1, func = function(stack, pr)mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr) end }, { itemstring = "mcl_books:book", weight = 1,
func = function(stack, pr) mcl_enchanting.enchant_uniform_randomly(stack, { "soul_speed" }, pr) end },
{ itemstring = "mcl_armor:chestplate_chain", weight = 1, }, { itemstring = "mcl_armor:chestplate_chain", weight = 1, },
{ itemstring = "mcl_armor:chestplate_diamond", weight = 1, }, { itemstring = "mcl_armor:chestplate_diamond", weight = 1, },
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2, }, { itemstring = "mcl_core:apple_gold_enchanted", weight = 2, },