From 4a664289986115c2ddca1ae827128dcf99ea066e Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Wed, 14 Feb 2024 16:59:01 -0500 Subject: [PATCH] Fix early return causing loop to break, disable falling vines on willow tree --- api.lua | 26 ++++ mapgen_coral_forest_under.lua | 91 ++++++------ mapgen_crystal_forest_under.lua | 228 ++++++++++++++----------------- mapgen_cursed_lands_under.lua | 90 +++++------- mapgen_forsaken_tundra_ocean.lua | 4 +- mapgen_forsaken_tundra_under.lua | 90 +++++------- vines.lua | 11 +- 7 files changed, 255 insertions(+), 285 deletions(-) diff --git a/api.lua b/api.lua index 108cd2f..7fbde41 100644 --- a/api.lua +++ b/api.lua @@ -2154,3 +2154,29 @@ function Everness.add_to_queue_on_generated(self, def) table.insert(self.on_generated_queue, def) end + +function Everness.find_irecursive(table, c_id) + local found = false + + for i, v in ipairs(table) do + if type(v) == 'table' then + Everness.find_irecursive(v, c_id) + end + + if c_id == v then + found = true + break + end + end + + return found +end + +---Merge two tables with key/value pair +---@param t1 table +---@param t2 table +---@return table +function Everness.mergeTables(t1, t2) + for k, v in pairs(t2) do t1[k] = v end + return t1 +end diff --git a/mapgen_coral_forest_under.lua b/mapgen_coral_forest_under.lua index 7accf94..48bd4a9 100644 --- a/mapgen_coral_forest_under.lua +++ b/mapgen_coral_forest_under.lua @@ -243,63 +243,48 @@ Everness:add_to_queue_on_generated({ local marker_node = minetest.get_node(marker_pos) local place_on_node = minetest.get_node(pos) - if not marker_node then - return - end + if marker_node and marker_node.name == 'everness:marker' then + -- remove marker + minetest.remove_node(marker_pos) - if marker_node.name ~= 'everness:marker' then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if table.indexof(bioluminescent_tree_place_on, place_on_node.name) ~= -1 then + -- enough air to place structure ? + local positions = minetest.find_nodes_in_area( + vector.new( + pos.x - bioluminescent_tree_size_x, + pos.y - bioluminescent_tree_y_dis, + pos.z - bioluminescent_tree_size_z + ), + vector.new( + pos.x + bioluminescent_tree_size_x, + pos.y - bioluminescent_tree_y_dis + coral_bioluminescent_tree_size.y, + pos.z + bioluminescent_tree_size_z + ), + { + 'air', + 'everness:coral_tree' + }, + true + ) - minetest.remove_node(marker_pos) + local air = positions.air or {} + local tree = positions['everness:coral_tree'] or {} - if table.indexof(bioluminescent_tree_place_on, place_on_node.name) == -1 then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + -- do not overlap another tree + if #tree == 0 and #air > bioluminescent_tree_safe_volume then + minetest.place_schematic_on_vmanip( + vm, + vector.new(marker_pos.x, marker_pos.y - bioluminescent_tree_y_dis, marker_pos.z), + schem_bioluminescent_tree, + 'random', + nil, + true, + 'place_center_x, place_center_z' + ) - -- no need to check for the floor "big enough" size since its a tree and has ~ 1x1 base size - - -- enough air to place structure ? - local positions = minetest.find_nodes_in_area( - vector.new( - pos.x - bioluminescent_tree_size_x, - pos.y - bioluminescent_tree_y_dis, - pos.z - bioluminescent_tree_size_z - ), - vector.new( - pos.x + bioluminescent_tree_size_x, - pos.y - bioluminescent_tree_y_dis + coral_bioluminescent_tree_size.y, - pos.z + bioluminescent_tree_size_z - ), - { - 'air', - 'everness:coral_tree' - }, - true - ) - - local air = positions.air or {} - local tree = positions['everness:coral_tree'] or {} - - if #tree > 1 then - -- will overlap another tree - return - end - - if #air > bioluminescent_tree_safe_volume then - minetest.place_schematic_on_vmanip( - vm, - vector.new(marker_pos.x, marker_pos.y - bioluminescent_tree_y_dis, marker_pos.z), - schem_bioluminescent_tree, - 'random', - nil, - true, - 'place_center_x, place_center_z' - ) - - -- minetest.log('action', '[Everness] Coral Tree Bioluminescent was placed at ' .. pos:to_string()) + -- minetest.log('action', '[Everness] Coral Tree Bioluminescent was placed at ' .. pos:to_string()) + end + end end end end diff --git a/mapgen_crystal_forest_under.lua b/mapgen_crystal_forest_under.lua index b851229..993d8c6 100644 --- a/mapgen_crystal_forest_under.lua +++ b/mapgen_crystal_forest_under.lua @@ -265,67 +265,58 @@ Everness:add_to_queue_on_generated({ local marker_node = minetest.get_node(marker_pos) local place_on_node = minetest.get_node(pos) - if not marker_node then - return - end + if marker_node and marker_node.name == 'everness:marker' then + -- remove marker + minetest.remove_node(marker_pos) - if marker_node.name ~= 'everness:marker' then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if table.indexof(crystal_cluster_place_on, place_on_node.name) ~= -1 then + -- enough air to place structure ? + local positions = minetest.find_nodes_in_area( + vector.new( + pos.x - crystal_cluster_size_x, + pos.y, + pos.z - crystal_cluster_size_z + ), + vector.new( + pos.x + crystal_cluster_size_x, + pos.y + crystal_cluster_size.y, + pos.z + crystal_cluster_size_z + ), + { + 'air' + }, + true + ) - minetest.remove_node(marker_pos) + local air = positions.air or {} - if table.indexof(crystal_cluster_place_on, place_on_node.name) == -1 then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if #air > crystal_cluster_safe_volume then + local replacements + local rand_color - -- enough air to place structure ? - local positions = minetest.find_nodes_in_area( - vector.new( - pos.x - crystal_cluster_size_x, - pos.y, - pos.z - crystal_cluster_size_z - ), - vector.new( - pos.x + crystal_cluster_size_x, - pos.y + crystal_cluster_size.y, - pos.z + crystal_cluster_size_z - ), - { - 'air' - }, - true - ) + if rand:next(0, 100) < 25 then + local colors = { 'purple', 'cyan' } + rand_color = colors[rand:next(1, #colors)] - local air = positions.air or {} + replacements = { + ['everness:crystal_block_orange'] = 'everness:crystal_block_' .. rand_color, + ['everness:crystal_orange'] = 'everness:crystal_' .. rand_color + } + end - if #air > crystal_cluster_safe_volume then - local replacements - local rand_color + minetest.place_schematic_on_vmanip( + vm, + vector.new(marker_pos.x, marker_pos.y, marker_pos.z), + schem_crystal_cluster, + 'random', + replacements, + true, + 'place_center_x, place_center_z' + ) - if rand:next(0, 100) < 25 then - local colors = { 'purple', 'cyan' } - rand_color = colors[rand:next(1, #colors)] - - replacements = { - ['everness:crystal_block_orange'] = 'everness:crystal_block_' .. rand_color, - ['everness:crystal_orange'] = 'everness:crystal_' .. rand_color - } + -- minetest.log('action', '[Everness] Crystal Cluster ' .. (rand_color or 'orange') .. ' was placed at ' .. pos:to_string()) + end end - - minetest.place_schematic_on_vmanip( - vm, - vector.new(marker_pos.x, marker_pos.y, marker_pos.z), - schem_crystal_cluster, - 'random', - replacements, - true, - 'place_center_x, place_center_z' - ) - - -- minetest.log('action', '[Everness] Crystal Cluster ' .. (rand_color or 'orange') .. ' was placed at ' .. pos:to_string()) end end @@ -339,84 +330,75 @@ Everness:add_to_queue_on_generated({ local place_on_node = minetest.get_node(pos) local crystal_sphere_cluster_y_dis = rand:next(5, 9) - if not marker_node then - return - end + if marker_node and marker_node.name == 'everness:marker' then + -- remove marker + minetest.remove_node(marker_pos) - if marker_node.name ~= 'everness:marker' then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if table.indexof(crystal_sphere_cluster_place_on, place_on_node.name) ~= -1 then + -- enough air to place structure ? + local positions = minetest.find_nodes_in_area( + vector.new( + pos.x - crystal_sphere_cluster_size_x, + pos.y - crystal_sphere_cluster_y_dis, + pos.z - crystal_sphere_cluster_size_z + ), + vector.new( + pos.x + crystal_sphere_cluster_size_x, + pos.y - crystal_sphere_cluster_y_dis + crystal_sphere_cluster_size.y, + pos.z + crystal_sphere_cluster_size_z + ), + { + 'air', + 'everness:coral_tree', + 'everness:crystal_block_orange', + 'everness:crystal_block_purple', + 'everness:crystal_block_cyan', + }, + true + ) - minetest.remove_node(marker_pos) + local air = positions.air or {} + local tree = positions['everness:coral_tree'] or {} + local block_orange = positions['everness:crystal_block_orange'] or {} + local block_purple = positions['everness:crystal_block_purple'] or {} + local block_cyan = positions['everness:crystal_block_cyan'] or {} - if table.indexof(crystal_sphere_cluster_place_on, place_on_node.name) == -1 then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if + #air > crystal_sphere_cluster_safe_volume + -- do not overlap + and not ( + #tree > 0 + or #block_orange > 0 + or #block_purple > 0 + or #block_cyan > 0 + ) + then + local replacements + local rand_color - -- enough air to place structure ? - local positions = minetest.find_nodes_in_area( - vector.new( - pos.x - crystal_sphere_cluster_size_x, - pos.y - crystal_sphere_cluster_y_dis, - pos.z - crystal_sphere_cluster_size_z - ), - vector.new( - pos.x + crystal_sphere_cluster_size_x, - pos.y - crystal_sphere_cluster_y_dis + crystal_sphere_cluster_size.y, - pos.z + crystal_sphere_cluster_size_z - ), - { - 'air', - 'everness:coral_tree', - 'everness:crystal_block_orange', - 'everness:crystal_block_purple', - 'everness:crystal_block_cyan', - }, - true - ) + if rand:next(0, 100) < 25 then + local colors = { 'orange', 'cyan' } + rand_color = colors[rand:next(1, #colors)] - local air = positions.air or {} - local tree = positions['everness:coral_tree'] or {} - local block_orange = positions['everness:crystal_block_orange'] or {} - local block_purple = positions['everness:crystal_block_purple'] or {} - local block_cyan = positions['everness:crystal_block_cyan'] or {} + replacements = { + ['everness:crystal_block_purple'] = 'everness:crystal_block_' .. rand_color, + ['everness:crystal_purple'] = 'everness:crystal_' .. rand_color + } + end - if #tree > 0 - or #block_orange > 0 - or #block_purple > 0 - or #block_cyan > 0 - then - -- will overlap - return - end + minetest.place_schematic_on_vmanip( + vm, + vector.new(marker_pos.x, marker_pos.y - crystal_sphere_cluster_y_dis, marker_pos.z), + schem_crystal_sphere_cluster, + 'random', + replacements, + true, + 'place_center_x, place_center_z' + ) - if #air > crystal_sphere_cluster_safe_volume then - local replacements - local rand_color - - if rand:next(0, 100) < 25 then - local colors = { 'orange', 'cyan' } - rand_color = colors[rand:next(1, #colors)] - - replacements = { - ['everness:crystal_block_purple'] = 'everness:crystal_block_' .. rand_color, - ['everness:crystal_purple'] = 'everness:crystal_' .. rand_color - } + -- minetest.log('action', '[Everness] Crystal Sphere Cluster ' .. (rand_color or 'orange') .. ' was placed at ' .. pos:to_string()) + end end - - minetest.place_schematic_on_vmanip( - vm, - vector.new(marker_pos.x, marker_pos.y - crystal_sphere_cluster_y_dis, marker_pos.z), - schem_crystal_sphere_cluster, - 'random', - replacements, - true, - 'place_center_x, place_center_z' - ) - - -- minetest.log('action', '[Everness] Crystal Sphere Cluster ' .. (rand_color or 'orange') .. ' was placed at ' .. pos:to_string()) end end end diff --git a/mapgen_cursed_lands_under.lua b/mapgen_cursed_lands_under.lua index ba327fc..d62883d 100644 --- a/mapgen_cursed_lands_under.lua +++ b/mapgen_cursed_lands_under.lua @@ -249,63 +249,47 @@ Everness:add_to_queue_on_generated({ local marker_node = minetest.get_node(marker_pos) local place_on_node = minetest.get_node(pos) - if not marker_node then - return - end + if marker_node and marker_node.name == 'everness:marker' then + -- remove marker + minetest.remove_node(marker_pos) - if marker_node.name ~= 'everness:marker' then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if table.indexof(cursed_dream_tree_place_on, place_on_node.name) ~= -1 then + -- enough air to place structure ? + local positions = minetest.find_nodes_in_area( + vector.new( + pos.x - cursed_dream_tree_size_x, + pos.y - cursed_dream_tree_y_dis, + pos.z - cursed_dream_tree_size_z + ), + vector.new( + pos.x + cursed_dream_tree_size_x, + pos.y - cursed_dream_tree_y_dis + cursed_dream_tree_size.y, + pos.z + cursed_dream_tree_size_z + ), + { + 'air', + 'everness:dry_tree' + }, + true + ) - minetest.remove_node(marker_pos) + local air = positions.air or {} + local tree = positions['everness:dry_tree'] or {} - if table.indexof(cursed_dream_tree_place_on, place_on_node.name) == -1 then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if #air > cursed_dream_tree_safe_volume and #tree <= 1 then + minetest.place_schematic_on_vmanip( + vm, + vector.new(marker_pos.x, marker_pos.y - cursed_dream_tree_y_dis, marker_pos.z), + schem_cursed_dream_tree, + 'random', + nil, + true, + 'place_center_x, place_center_z' + ) - -- no need to check for the floor "big enough" size since its a tree and has ~ 1x1 base size - - -- enough air to place structure ? - local positions = minetest.find_nodes_in_area( - vector.new( - pos.x - cursed_dream_tree_size_x, - pos.y - cursed_dream_tree_y_dis, - pos.z - cursed_dream_tree_size_z - ), - vector.new( - pos.x + cursed_dream_tree_size_x, - pos.y - cursed_dream_tree_y_dis + cursed_dream_tree_size.y, - pos.z + cursed_dream_tree_size_z - ), - { - 'air', - 'everness:dry_tree' - }, - true - ) - - local air = positions.air or {} - local tree = positions['everness:dry_tree'] or {} - - if #tree > 1 then - -- will overlap another tree - return - end - - if #air > cursed_dream_tree_safe_volume then - minetest.place_schematic_on_vmanip( - vm, - vector.new(marker_pos.x, marker_pos.y - cursed_dream_tree_y_dis, marker_pos.z), - schem_cursed_dream_tree, - 'random', - nil, - true, - 'place_center_x, place_center_z' - ) - - -- minetest.log('action', '[Everness] Cursed Dream Tree was placed at ' .. pos:to_string()) + -- minetest.log('action', '[Everness] Cursed Dream Tree was placed at ' .. pos:to_string()) + end + end end end end diff --git a/mapgen_forsaken_tundra_ocean.lua b/mapgen_forsaken_tundra_ocean.lua index 69eb804..d79edfb 100644 --- a/mapgen_forsaken_tundra_ocean.lua +++ b/mapgen_forsaken_tundra_ocean.lua @@ -67,7 +67,7 @@ Everness:register_ore({ octaves = 1, persist = 0.0 }, - biomes = { 'everness_forsaken_tundra_ocean' } + biomes = { 'everness:forsaken_tundra_ocean' } }) -- @@ -87,7 +87,7 @@ Everness:register_decoration({ octaves = 3, persist = 0.7, }, - biomes = { 'everness_forsaken_tundra_ocean' }, + biomes = { 'everness:forsaken_tundra_ocean' }, y_max = y_max, y_min = y_min, place_offset_y = -1, diff --git a/mapgen_forsaken_tundra_under.lua b/mapgen_forsaken_tundra_under.lua index f2363a6..851b9fe 100644 --- a/mapgen_forsaken_tundra_under.lua +++ b/mapgen_forsaken_tundra_under.lua @@ -308,63 +308,47 @@ Everness:add_to_queue_on_generated({ local marker_node = minetest.get_node(marker_pos) local place_on_node = minetest.get_node(pos) - if not marker_node then - return - end + if marker_node and marker_node.name == 'everness:marker' then + -- remove marker + minetest.remove_node(marker_pos) - if marker_node.name ~= 'everness:marker' then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if table.indexof(willow_tree_place_on, place_on_node.name) ~= -1 then + -- enough air to place structure ? + local positions = minetest.find_nodes_in_area( + vector.new( + pos.x - size_x, + pos.y - y_dis, + pos.z - size_z + ), + vector.new( + pos.x + size_x, + pos.y - y_dis + size.y, + pos.z + size_z + ), + { + 'air', + 'everness:willow_tree' + }, + true + ) - minetest.remove_node(marker_pos) + local air = positions.air or {} + local tree = positions['everness:willow_tree'] or {} - if table.indexof(willow_tree_place_on, place_on_node.name) == -1 then - -- not a valid "place_on" position (e.g. something else was placed there) - return - end + if #air > safe_volume and #tree == 0 then + minetest.place_schematic_on_vmanip( + vm, + vector.new(marker_pos.x, marker_pos.y - y_dis, marker_pos.z), + willow_tree_schem, + 'random', + nil, + true, + 'place_center_x, place_center_z' + ) - -- no need to check for the floor "big enough" size since its a tree and has ~ 1x1 base size - - -- enough air to place structure ? - local positions = minetest.find_nodes_in_area( - vector.new( - pos.x - size_x, - pos.y - y_dis, - pos.z - size_z - ), - vector.new( - pos.x + size_x, - pos.y - y_dis + size.y, - pos.z + size_z - ), - { - 'air', - 'everness:willow_tree' - }, - true - ) - - local air = positions.air or {} - local tree = positions['everness:willow_tree'] or {} - - if #tree > 1 then - -- will overlap another tree - return - end - - if #air > safe_volume then - minetest.place_schematic_on_vmanip( - vm, - vector.new(marker_pos.x, marker_pos.y - y_dis, marker_pos.z), - willow_tree_schem, - 'random', - nil, - true, - 'place_center_x, place_center_z' - ) - - -- minetest.log('action', '[Everness] Willow Tree was placed at ' .. pos:to_string()) + -- minetest.log('action', '[Everness] Willow Tree was placed at ' .. pos:to_string()) + end + end end end end diff --git a/vines.lua b/vines.lua index 00acb38..d93aaea 100644 --- a/vines.lua +++ b/vines.lua @@ -58,6 +58,11 @@ local function register_vine(name, def, overrides) -- ALL flammable = 2, } + + if _overrides.groups then + Everness.mergeTables(_def.groups, _overrides.groups) + end + -- MCL _def._mcl_shears_drop = true _def._mcl_blast_resistance = 0.2 @@ -66,7 +71,7 @@ local function register_vine(name, def, overrides) return false end _def.sounds = Everness.node_sound_leaves_defaults() - _def.waving = 2 + _def.waving = 1 _def.on_destruct = function(pos) local pos_below = vector.new(pos.x, pos.y - 1, pos.z) local node_below = minetest.get_node(pos_below) @@ -183,6 +188,10 @@ register_vine('bulb_vine', { register_vine('willow_vine', { description = S('Willow Vine') +}, { + groups = { + falling_vines = 0 + } }) -- Eye Vine