From 2cfca0518679b32b82b31986a90a837e3bb0746d Mon Sep 17 00:00:00 2001 From: kay27 Date: Sun, 16 Jan 2022 19:20:42 +0400 Subject: [PATCH] Move noise indicator into separate file --- mods/MAPGEN/mcl_mapgen_core/structures.lua | 38 ----------------- mods/MAPGEN/mcl_structures/desert_temple.lua | 6 ++- mods/MAPGEN/mcl_structures/init.lua | 4 +- .../MAPGEN/mcl_structures/noise_indicator.lua | 42 +++++++++++++++++++ mods/MAPGEN/mcl_structures/structures.lua | 8 +++- 5 files changed, 55 insertions(+), 43 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/noise_indicator.lua diff --git a/mods/MAPGEN/mcl_mapgen_core/structures.lua b/mods/MAPGEN/mcl_mapgen_core/structures.lua index 5f751db50..3a25d1cfd 100644 --- a/mods/MAPGEN/mcl_mapgen_core/structures.lua +++ b/mods/MAPGEN/mcl_mapgen_core/structures.lua @@ -268,30 +268,6 @@ local function spawn_spikes_in_v6(p, nn, pr) end local function generate_structures(vm_context) - -local levels = { - [-9] = "black", - [-8] = "brown", - [-7] = "brown", - [-6] = "gray", - [-5] = "gray", - [-4] = "red", - [-3] = "orange", - [-2] = "purple", - [-1] = "magenta", - [0] = "pink", - [1] = "yellow", - [2] = "green", - [3] = "lime", - [4] = "blue", - [5] = "cyan", - [6] = "light_blue", - [7] = "silver", - [8] = "silver", - [9] = "white", - } - - -- local pr = PcgRandom(vm_context.blockseed) local pr = PcgRandom(vm_context.chunkseed) -- chunk_has_desert_struct = false -- chunk_has_desert_temple = false @@ -304,20 +280,6 @@ local levels = { local DIVLEN = 5 for x0 = minp.x, maxp.x, DIVLEN do for z0 = minp.z, maxp.z, DIVLEN do -- Determine amount from perlin noise - local noise = perlin_structures:get_2d({x=x0, y=z0}) - local amount - if noise < 0 then - amount = math_max(math_ceil(noise * 9), -9) - else - amount = math_min(math_floor(noise * 9), 9) - end - -- local amount = math_floor(perlin_structures:get_2d({x=x0, y=z0}) * 9) - - local y1 = maxp.y - 9 + amount - for x1 = x0, x0 + DIVLEN - 1, 1 do for z1 = z0, z0 + DIVLEN - 1, 1 do - minetest.set_node({x=x1, y=y1, z=z1}, {name = "mcl_core:glass_"..levels[amount]}) - end end - -- Find random positions based on this random local p, ground_y, nn for i = 0, 24 do diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index 399cc4666..682af9d4d 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -121,11 +121,12 @@ mcl_structures.register_structure({ deco_type = "simple", place_on = node_list, flags = "all_floors", - fill_ratio = 0.00003, + --fill_ratio = 0.00003, + fill_ratio = 0.003, y_min = 3, y_max = mcl_mapgen.overworld.max, height = 1, - biomes = { + biomes = not mcl_mapgen.v6 and { "ColdTaiga_beach", "ColdTaiga_beach_water", "Desert", @@ -146,6 +147,7 @@ mcl_structures.register_structure({ on_finished_chunk = function(minp, maxp, seed, vm_context, pos_list) local a = seed % 14 local b = (math.floor(seed / 39) + 4) % 12 + minetest.chat_send_all("seed=" .. tostring(seed) .. ", a=" .. tostring(a) .. ", b=" ..tostring(b)) if a ~= b then return end local pos = pos_list[1] if #pos_list > 1 then diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 1011b4cbe..65e538024 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -17,6 +17,8 @@ local use_process_mapgen_chunk = false local on_finished_block_callbacks = {} local on_finished_chunk_callbacks = {} +mcl_structures.perlin_noise = minetest.get_perlin(329, 3, 0.6, 100) + 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 @@ -70,7 +72,7 @@ function mcl_structures.register_structure(def) local decoration_id if decoration then minetest.register_node(':' .. name, { - drawtype = "airlike", + -- drawtype = "airlike", sunlight_propagates = true, pointable = false, walkable = false, diff --git a/mods/MAPGEN/mcl_structures/noise_indicator.lua b/mods/MAPGEN/mcl_structures/noise_indicator.lua new file mode 100644 index 000000000..3f45040c0 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/noise_indicator.lua @@ -0,0 +1,42 @@ +local levels = { + [-9] = "black", + [-8] = "brown", + [-7] = "brown", + [-6] = "gray", + [-5] = "gray", + [-4] = "red", + [-3] = "orange", + [-2] = "purple", + [-1] = "magenta", + [0] = "pink", + [1] = "yellow", + [2] = "green", + [3] = "lime", + [4] = "blue", + [5] = "cyan", + [6] = "light_blue", + [7] = "silver", + [8] = "silver", + [9] = "white", +} + +local math_min, math_max = math.min, math.max +local math_floor, math_ceil = math.floor, math.ceil + +mcl_mapgen.register_mapgen(function(minp, maxp, seed, vm_context) + mcl_structures.perlin_noise = mcl_structures.perlin_noise or minetest.get_perlin(329, 3, 0.6, 100) + local perlin_noise = mcl_structures.perlin_noise + for x0 = minp.x, maxp.x do + for z0 = minp.z, maxp.z do + local current_noise_level = perlin_noise:get_2d({x=x0, y=z0}) + local amount + if current_noise_level < 0 then + amount = math_max(math_ceil(current_noise_level * 9), -9) + else + amount = math_min(math_floor(current_noise_level * 9), 9) + end + local y0 = maxp.y - 9 + amount + minetest.set_node({x=x0, y=y0, z=z0}, {name = "mcl_core:glass_"..levels[amount]}) + end + end +end, -1) diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index c0f1b3d3e..91f0022cb 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -1,5 +1,9 @@ local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) -dofile(modpath .. "/desert_temple.lua") -dofile(modpath .. "/stronghold.lua") +if not mcl_mapgen.singlenode then + dofile(modpath .. "/desert_temple.lua") + dofile(modpath .. "/stronghold.lua") + + dofile(modpath .. "/noise_indicator.lua") +end