From 4a3f1032cacf9476c643e2f6e6acf380600578c4 Mon Sep 17 00:00:00 2001 From: kay27 Date: Wed, 19 Jan 2022 03:41:22 +0400 Subject: [PATCH] Add ice spikes for v6 --- mods/MAPGEN/mcl_structures/desert_temple.lua | 1 - mods/MAPGEN/mcl_structures/desert_well.lua | 1 - .../MAPGEN/mcl_structures/ice_spike_large.lua | 66 +++++++++++++++++++ .../MAPGEN/mcl_structures/ice_spike_small.lua | 65 ++++++++++++++++++ mods/MAPGEN/mcl_structures/igloo.lua | 1 - mods/MAPGEN/mcl_structures/init.lua | 9 --- mods/MAPGEN/mcl_structures/jungle_temple.lua | 1 - .../mcl_structures/nice_jungle_temple.lua | 1 - mods/MAPGEN/mcl_structures/structures.lua | 2 + mods/MAPGEN/mcl_structures/witch_hut.lua | 1 - 10 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 mods/MAPGEN/mcl_structures/ice_spike_large.lua create mode 100644 mods/MAPGEN/mcl_structures/ice_spike_small.lua diff --git a/mods/MAPGEN/mcl_structures/desert_temple.lua b/mods/MAPGEN/mcl_structures/desert_temple.lua index 53b86acbc..bb4c08b3a 100644 --- a/mods/MAPGEN/mcl_structures/desert_temple.lua +++ b/mods/MAPGEN/mcl_structures/desert_temple.lua @@ -168,7 +168,6 @@ mcl_structures.register_structure({ end end end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/desert_well.lua b/mods/MAPGEN/mcl_structures/desert_well.lua index 93769f458..af57c8183 100644 --- a/mods/MAPGEN/mcl_structures/desert_well.lua +++ b/mods/MAPGEN/mcl_structures/desert_well.lua @@ -87,7 +87,6 @@ mcl_structures.register_structure({ end end end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/ice_spike_large.lua b/mods/MAPGEN/mcl_structures/ice_spike_large.lua new file mode 100644 index 000000000..b46f09465 --- /dev/null +++ b/mods/MAPGEN/mcl_structures/ice_spike_large.lua @@ -0,0 +1,66 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_chunk = 5 +local random_offset = 24435 +local struct_threshold = chance_per_chunk - 1 +local noise_params = { + offset = 0, + scale = 1, + spread = { + x = 1000, + y = 1000, + z = 1000, + }, + scale = 0.01, + seed = 29313, + octaves = 2, + persistence = 0.7, +} + +local node_list = {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"} +local schematic = modpath.."/schematics/mcl_structures_ice_spike_large.mts" + +minetest_find_nodes_in_area = minetest.find_nodes_in_area + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = pos, schematic = schematic, rotation = rotation, pr = pr}) +end + +local function is_place_ok(p) + -- Check surface + local floor = {x=p.x+4, y=p.y-1, z=p.z+4} + local surface = #minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, node_list, false) + if surface < 9 then return end + + -- Check for collision with spruce + local spruce_collisions = #minetest_find_nodes_in_area({x=p.x+1,y=p.y+2,z=p.z+1}, {x=p.x+4, y=p.y+6, z=p.z+4}, {"group:tree"}, false) + if spruce_collisions > 0 then return end + + return true +end + +local def = mcl_mapgen.v6 and { + decoration = { + deco_type = "simple", + place_on = node_list, + noise_params = noise_params, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, + height = 1, + }, + on_finished_chunk = mcl_mapgen.v6 and function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + if random_number < struct_threshold then return end + for i = 1, #pos_list do + local pos = pos_list[i] + if is_place_ok(pos) then + place(pos, nil, pr) + end + end + end, +} or {} +def.name = "ice_spike_large" +def.place_function = place +mcl_structures.register_structure(def) diff --git a/mods/MAPGEN/mcl_structures/ice_spike_small.lua b/mods/MAPGEN/mcl_structures/ice_spike_small.lua new file mode 100644 index 000000000..801c5f66e --- /dev/null +++ b/mods/MAPGEN/mcl_structures/ice_spike_small.lua @@ -0,0 +1,65 @@ +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) + +local chance_per_chunk = 3 +local random_offset = 1264 +local struct_threshold = chance_per_chunk - 1 +local noise_params = { + offset = 0, + scale = 1, + spread = { + x = mcl_mapgen.CS, + y = mcl_mapgen.CS, + z = mcl_mapgen.CS, + }, + scale = 0.3, + seed = 32931, + octaves = 2, + persistence = 0.7, +} + +local node_list = {"mcl_core:snowblock", "mcl_core:dirt_with_grass_snow"} +local schematic = modpath.."/schematics/mcl_structures_ice_spike_small.mts" + +minetest_find_nodes_in_area = minetest.find_nodes_in_area + +local function place(pos, rotation, pr) + mcl_structures.place_schematic({pos = pos, schematic = schematic, rotation = rotation, pr = pr}) +end + +local function is_place_ok(p) + local floor = {x=p.x+6, y=p.y-1, z=p.z+6} + local surface = #minetest_find_nodes_in_area({x=p.x+1,y=p.y-1,z=p.z+1}, floor, node_list, false) + if surface < 25 then return end + + -- Check for collision with spruce + local spruce_collisions = #minetest_find_nodes_in_area({x=p.x+1,y=p.y+1,z=p.z+1}, {x=p.x+6, y=p.y+6, z=p.z+6}, {"group:tree"}, false) + if spruce_collisions > 0 then return end + + return true +end + +local def = mcl_mapgen.v6 and { + decoration = { + deco_type = "simple", + place_on = node_list, + noise_params = noise_params, + y_min = mcl_mapgen.overworld.min, + y_max = mcl_mapgen.overworld.max, + height = 1, + }, + on_finished_chunk = mcl_mapgen.v6 and function(minp, maxp, seed, vm_context, pos_list) + local pr = PseudoRandom(seed + random_offset) + local random_number = pr:next(1, chance_per_chunk) + if random_number < struct_threshold then return end + for i = 1, #pos_list do + local pos = pos_list[i] + if is_place_ok(pos) then + place(pos, nil, pr) + end + end + end, +} or {} +def.name = "ice_spike_small" +def.place_function = place +mcl_structures.register_structure(def) diff --git a/mods/MAPGEN/mcl_structures/igloo.lua b/mods/MAPGEN/mcl_structures/igloo.lua index 9f2b26672..4f6c9574f 100644 --- a/mods/MAPGEN/mcl_structures/igloo.lua +++ b/mods/MAPGEN/mcl_structures/igloo.lua @@ -189,7 +189,6 @@ mcl_structures.register_structure({ end end if count < 0 then return end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 27c38df0a..c43640fd1 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -339,10 +339,6 @@ function mcl_structures.call_struct(pos, struct_style, rotation, pr, callback) end if struct_style == "witch_hut" then return mcl_structures.generate_witch_hut(pos, rotation) - elseif struct_style == "ice_spike_small" then - return mcl_structures.generate_ice_spike_small(pos, rotation) - elseif struct_style == "ice_spike_large" then - return mcl_structures.generate_ice_spike_large(pos, rotation) elseif struct_style == "boulder" then return mcl_structures.generate_boulder(pos, rotation, pr) elseif struct_style == "end_exit_portal" then @@ -405,11 +401,6 @@ function mcl_structures.generate_witch_hut(pos, rotation, pr) mcl_structures.place_schematic(pos, path, rotation, nil, true, nil, hut_placement_callback, pr) end -function mcl_structures.generate_ice_spike_small(pos, rotation) - local path = modpath.."/schematics/mcl_structures_ice_spike_small.mts" - return minetest.place_schematic(pos, path, rotation or "random", nil, false) -- don't serialize schematics for registered biome decorations, for MT 5.4.0 -end - function mcl_structures.generate_ice_spike_large(pos, rotation) local path = modpath.."/schematics/mcl_structures_ice_spike_large.mts" return minetest.place_schematic(pos, path, rotation or "random", nil, false) -- don't serialize schematics for registered biome decorations, for MT 5.4.0 diff --git a/mods/MAPGEN/mcl_structures/jungle_temple.lua b/mods/MAPGEN/mcl_structures/jungle_temple.lua index daedcb16f..635f35670 100644 --- a/mods/MAPGEN/mcl_structures/jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/jungle_temple.lua @@ -197,7 +197,6 @@ mcl_structures.register_structure({ end end if count < 0 then return end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua index 019224815..dd8df05d3 100644 --- a/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua +++ b/mods/MAPGEN/mcl_structures/nice_jungle_temple.lua @@ -203,7 +203,6 @@ mcl_structures.register_structure({ end end if count < 0 then return end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place, diff --git a/mods/MAPGEN/mcl_structures/structures.lua b/mods/MAPGEN/mcl_structures/structures.lua index 2bccd3923..94fad4230 100644 --- a/mods/MAPGEN/mcl_structures/structures.lua +++ b/mods/MAPGEN/mcl_structures/structures.lua @@ -6,6 +6,8 @@ if not mcl_mapgen.singlenode then dofile(modpath .. "/desert_well.lua") dofile(modpath .. "/fossil.lua") dofile(modpath .. "/igloo.lua") + dofile(modpath .. "/ice_spike_small.lua") + dofile(modpath .. "/ice_spike_large.lua") dofile(modpath .. "/jungle_temple.lua") dofile(modpath .. "/nice_jungle_temple.lua") dofile(modpath .. "/noise_indicator.lua") diff --git a/mods/MAPGEN/mcl_structures/witch_hut.lua b/mods/MAPGEN/mcl_structures/witch_hut.lua index e4287e652..f6dc6ec9b 100644 --- a/mods/MAPGEN/mcl_structures/witch_hut.lua +++ b/mods/MAPGEN/mcl_structures/witch_hut.lua @@ -130,7 +130,6 @@ mcl_structures.register_structure({ end end end - local pr = PseudoRandom(vm_context.chunkseed) place(pos, nil, pr) end, place_function = place,