2022-02-05 00:58:05 +01:00
|
|
|
local radius_min = 3
|
|
|
|
local radius_max = mcl_mapgen.HALF_BS
|
|
|
|
local layers = {
|
|
|
|
{
|
2022-02-05 17:49:45 +01:00
|
|
|
[8] = "mcl_blackstone:basalt_polished",
|
|
|
|
[92] = "mcl_deepslate:deepslate",
|
2022-02-05 00:58:05 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
[100] = "mcl_amethyst:calcite",
|
|
|
|
},
|
|
|
|
{
|
2022-02-05 02:34:59 +01:00
|
|
|
[85] = "mcl_amethyst:amethyst_block",
|
|
|
|
[15] = "mcl_amethyst:budding_amethyst_block",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[98] = "mcl_amethyst:amethyst_block",
|
|
|
|
[2] = "mcl_amethyst:budding_amethyst_block",
|
2022-02-05 00:58:05 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
[100] = "air",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 01:03:22 +01:00
|
|
|
local function round(v)
|
|
|
|
if v < 0 then
|
|
|
|
return math.ceil(v - 0.5)
|
|
|
|
end
|
|
|
|
return math.floor(v + 0.5)
|
|
|
|
end
|
|
|
|
|
2022-02-05 00:58:05 +01:00
|
|
|
local function place(pos, rotation, pr)
|
2022-02-05 01:56:17 +01:00
|
|
|
local radius1 = vector.new(
|
|
|
|
-pr:next(radius_min, radius_max),
|
|
|
|
-pr:next(radius_min, radius_max),
|
|
|
|
-pr:next(radius_min, radius_max)
|
|
|
|
)
|
|
|
|
local radius2 = vector.new(
|
|
|
|
pr:next(radius_min, radius_max),
|
|
|
|
pr:next(radius_min, radius_max),
|
|
|
|
pr:next(radius_min, radius_max)
|
|
|
|
)
|
|
|
|
local layer_radius = pr:next(radius_min, radius_max)
|
|
|
|
local radius1_normalized = vector.normalize(radius1)
|
|
|
|
local radius2_normalized = vector.normalize(radius2)
|
|
|
|
local pos = vector.subtract(pos, radius1)
|
|
|
|
for x = radius1.x, radius2.x do
|
|
|
|
local max_x = (x < 0) and radius1.x or radius2.x
|
|
|
|
for y = radius1.y, radius2.y do
|
|
|
|
local max_y = (y < 0) and radius1.y or radius2.y
|
|
|
|
for z = radius1.z, radius2.z do
|
|
|
|
local max_z = (z < 0) and radius1.z or radius2.z
|
|
|
|
local normal_abs = vector.new(x / max_x, y / max_y, z / max_z)
|
|
|
|
local inverted_layer = round(vector.length(normal_abs) * layer_radius)
|
|
|
|
if inverted_layer <= layer_radius then
|
|
|
|
local layer = math.min(math.max(1, layer_radius - inverted_layer + 1), #layers)
|
|
|
|
local offset = vector.new(x, y, z)
|
|
|
|
local node_pos = pos + offset
|
2022-02-05 00:58:05 +01:00
|
|
|
local node_candidates = layers[layer]
|
|
|
|
local node_name
|
|
|
|
local chance_index = pr:next(1, 100)
|
|
|
|
local current_weight = 0
|
|
|
|
for chance, node_name_iterated in pairs(node_candidates) do
|
2022-02-05 01:16:30 +01:00
|
|
|
if chance_index <= current_weight + chance then
|
2022-02-05 00:58:05 +01:00
|
|
|
node_name = node_name_iterated
|
|
|
|
break
|
|
|
|
end
|
|
|
|
current_weight = current_weight + chance
|
|
|
|
end
|
|
|
|
minetest.swap_node(node_pos, {name = node_name})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mcl_structures.register_structure({
|
|
|
|
name = "amethyst_geode",
|
|
|
|
place_function = place,
|
|
|
|
})
|
2022-02-05 02:34:59 +01:00
|
|
|
|
|
|
|
local decrease_scan_area = 1
|
2022-02-05 03:27:23 +01:00
|
|
|
local mapblock_opacity_placement_threshold = 0.98
|
2022-02-05 02:34:59 +01:00
|
|
|
local threshold = math.floor(((mcl_mapgen.BS - 2 * decrease_scan_area)^3) * mapblock_opacity_placement_threshold)
|
2022-02-05 17:49:45 +01:00
|
|
|
local upper_than = mcl_mapgen.overworld.bedrock_max
|
2022-02-05 02:34:59 +01:00
|
|
|
mcl_mapgen.register_mapgen_block(function(minp, maxp, blockseed)
|
|
|
|
local y = minp.y
|
2022-02-05 17:49:45 +01:00
|
|
|
if y <= upper_than then return end
|
2022-02-05 02:34:59 +01:00
|
|
|
local pr = PseudoRandom(blockseed + 143)
|
2022-02-05 03:27:23 +01:00
|
|
|
if pr:next(1, 120) ~= 54 then return end
|
2022-02-05 02:34:59 +01:00
|
|
|
local opacity_counter = #minetest.find_nodes_in_area(vector.add(minp, decrease_scan_area), vector.subtract(maxp, decrease_scan_area), "group:opaque")
|
|
|
|
if opacity_counter < threshold then return end
|
2022-02-05 03:27:23 +01:00
|
|
|
place(minp, nil, pr)
|
2022-02-05 02:34:59 +01:00
|
|
|
end)
|