From fbd4aaf0349d93dd3e9aa98b7d472a6b51413ec5 Mon Sep 17 00:00:00 2001 From: Niklp <89982526+Niklp09@users.noreply.github.com> Date: Thu, 26 Oct 2023 17:53:09 +0200 Subject: [PATCH] Remove biome_lib dep from dryplants (#63) --- .luacheckrc | 2 +- dryplants/init.lua | 12 --- dryplants/juncus.lua | 113 +++++++++++--------- dryplants/meadowvariation.lua | 33 ++---- dryplants/mod.conf | 2 +- dryplants/moregrass.lua | 42 +++----- dryplants/reedmace.lua | 190 +++++++++++++++++++--------------- 7 files changed, 201 insertions(+), 193 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 1a1dfc6..a8b6e7c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -5,7 +5,7 @@ max_line_length = 185 exclude_files = {".luacheckrc"} globals = { - "biome_lib", "abstract_dryplants", + "biome_lib", "bushes_classic", } diff --git a/dryplants/init.lua b/dryplants/init.lua index 11235e4..5b808c0 100644 --- a/dryplants/init.lua +++ b/dryplants/init.lua @@ -1,13 +1,3 @@ --- by Mossmanikin --- textures & ideas partly by Neuromancer - --- Contains code from: default, farming --- Looked at code from: darkage, sickle, stairs --- Dependencies: default, farming, biome_lib --- Supports: ------------------------------------------------------------------------------------------------ -abstract_dryplants = {} - -- support for i18n local S = minetest.get_translator("dryplants") @@ -191,5 +181,3 @@ minetest.register_abm({ end end, }) - -abstract_dryplants.loaded = true diff --git a/dryplants/juncus.lua b/dryplants/juncus.lua index a2f0166..4a73861 100644 --- a/dryplants/juncus.lua +++ b/dryplants/juncus.lua @@ -1,21 +1,12 @@ ------------------------------------------------------------------------------------------------ --- Grasses - Juncus 0.0.5 ------------------------------------------------------------------------------------------------ --- by Mossmanikin --- textures & ideas partly by Neuromancer - --- Contains code from: biome_lib --- Looked at code from: default ------------------------------------------------------------------------------------------------ - -- support for i18n local S = minetest.get_translator("dryplants") -abstract_dryplants.grow_juncus = function(pos) +local function grow_juncus(pos) local juncus_type = math.random(2,3) local right_here = {x=pos.x, y=pos.y+1, z=pos.z} - if minetest.get_node(right_here).name == "air" -- instead of check_air = true, - or minetest.get_node(right_here).name == "default:junglegrass" then + + local nodename = minetest.get_node(right_here).name + if nodename == "air" or nodename == "default:junglegrass" then if juncus_type == 2 then minetest.swap_node(right_here, {name="dryplants:juncus_02"}) else @@ -70,6 +61,7 @@ minetest.register_node("dryplants:juncus", { return itemstack end, }) + minetest.register_node("dryplants:juncus_02", { description = S("Juncus"), drawtype = "plantlike", @@ -96,44 +88,69 @@ minetest.register_node("dryplants:juncus_02", { -- GENERATE SMALL JUNCUS ----------------------------------------------------------------------------------------------- -- near water or swamp -biome_lib.register_on_generate({ - surface = { +minetest.register_decoration({ + name = "dryplants:juncus_water", + decoration = {"air"}, + fill_ratio = 0.16, + y_min = 1, + y_max = 40, + place_on = { "default:dirt_with_grass", - --"default:desert_sand", - --"default:sand", "stoneage:grass_with_silex", "sumpf:peat", "sumpf:sumpf" }, - max_count = 70, - rarity = 101 - 75, - min_elevation = 1, -- above sea level - near_nodes = {"default:water_source","sumpf:dirtywater_source","sumpf:sumpf"}, - near_nodes_size = 2, - near_nodes_vertical = 1, - near_nodes_count = 1, - plantlife_limit = -0.9, - }, - abstract_dryplants.grow_juncus -) --- at dunes/beach -biome_lib.register_on_generate({ - surface = { - --"default:dirt_with_grass", - --"default:desert_sand", - "default:sand", - --"stoneage:grass_with_silex", - --"sumpf:peat", - --"sumpf:sumpf" + deco_type = "simple", + flags = "all_floors", + spawn_by = { + "default:water_source", + "sumpf:dirtywater_source", + "sumpf:sumpf" }, - max_count = 70, - rarity = 101 - 75, - min_elevation = 1, -- above sea level - near_nodes = {"default:dirt_with_grass"}, - near_nodes_size = 2, - near_nodes_vertical = 1, - near_nodes_count = 1, - plantlife_limit = -0.9, - }, - abstract_dryplants.grow_juncus -) + check_offset = -1, + num_spawn_by = 1 +}) + +-- at dunes/beach +minetest.register_decoration({ + name = "dryplants:juncus_beach", + decoration = {"air"}, + fill_ratio = 0.08, + y_min = 1, + y_max = 40, + place_on = { + "default:sand", + }, + deco_type = "simple", + flags = "all_floors", + spawn_by = {"default:dirt_with_grass"}, + check_offset = -1, + num_spawn_by = 1 +}) + +local did, did2 +minetest.register_on_mods_loaded(function() + did = minetest.get_decoration_id("dryplants:juncus_water") + did2 = minetest.get_decoration_id("dryplants:juncus_beach") + minetest.set_gen_notify("decoration", {did, did2}) +end) + +minetest.register_on_generated(function(minp, maxp, blockseed) + local g = minetest.get_mapgen_object("gennotify") + local locations = {} + + local deco_locations_1 = g["decoration#" .. did] or {} + local deco_locations_2 = g["decoration#" .. did2] or {} + + for _, pos in pairs(deco_locations_1) do + locations[#locations+1] = pos + end + for _, pos in pairs(deco_locations_2) do + locations[#locations+1] = pos + end + + if #locations == 0 then return end + for _, pos in ipairs(locations) do + grow_juncus(pos) + end +end) \ No newline at end of file diff --git a/dryplants/meadowvariation.lua b/dryplants/meadowvariation.lua index d11d7da..c9ebf1c 100644 --- a/dryplants/meadowvariation.lua +++ b/dryplants/meadowvariation.lua @@ -1,25 +1,12 @@ ------------------------------------------------------------------------------------------------ --- Grasses - Meadow Variation 0.0.1 ------------------------------------------------------------------------------------------------ --- by Mossmanikin - --- Contains code from: biome_lib --- Looked at code from: default ------------------------------------------------------------------------------------------------ - -abstract_dryplants.grow_grass_variation = function(pos) - local right_here = {x=pos.x, y=pos.y, z=pos.z} - minetest.swap_node(right_here, {name="dryplants:grass_short"}) -end - -biome_lib.register_on_generate({ - surface = { +-- @reviewer: couldn't even find using biome_lib +minetest.register_decoration({ + decoration = {"dryplants:grass_short"}, + fill_ratio = 0.8, + y_min = 1, + y_max = 40, + place_on = { "default:dirt_with_grass", }, - max_count = 4800, - rarity = 25, - min_elevation = 1, -- above sea level - plantlife_limit = -0.9, - }, - abstract_dryplants.grow_grass_variation -) + deco_type = "simple", + flags = "all_floors" +}) diff --git a/dryplants/mod.conf b/dryplants/mod.conf index 3011ab6..e190197 100644 --- a/dryplants/mod.conf +++ b/dryplants/mod.conf @@ -1,3 +1,3 @@ name = dryplants -depends = default, biome_lib +depends = default optional_depends = farming diff --git a/dryplants/moregrass.lua b/dryplants/moregrass.lua index 2f574a4..5e27a9c 100644 --- a/dryplants/moregrass.lua +++ b/dryplants/moregrass.lua @@ -1,30 +1,20 @@ ------------------------------------------------------------------------------------------------ --- Grasses - More Tall Grass 0.0.2 ------------------------------------------------------------------------------------------------ --- by Mossmanikin - --- Contains code from: biome_lib --- Looked at code from: default ------------------------------------------------------------------------------------------------ - -biome_lib.register_on_generate( - { - surface = { - "default:dirt_with_grass", - "stoneage:grass_with_silex", - "sumpf:peat", - "sumpf:sumpf" - }, - max_count = 4800, - rarity = 101 - 75, - min_elevation = 1, -- above sea level - plantlife_limit = -0.9, - check_air = true, - }, - { "default:grass_1", +minetest.register_decoration({ + decoration = { + "default:grass_1", "default:grass_2", "default:grass_3", "default:grass_4", "default:grass_5" - } -) + }, + fill_ratio = 0.8, + y_min = 1, + y_max = 40, + place_on = { + "default:dirt_with_grass", + "stoneage:grass_with_silex", + "sumpf:peat", + "sumpf:sumpf" + }, + deco_type = "simple", + flags = "all_floors" +}) diff --git a/dryplants/reedmace.lua b/dryplants/reedmace.lua index e9547be..79054c0 100644 --- a/dryplants/reedmace.lua +++ b/dryplants/reedmace.lua @@ -1,13 +1,3 @@ ------------------------------------------------------------------------------------------------ --- Grasses - Reedmace 0.1.1 ------------------------------------------------------------------------------------------------ --- by Mossmanikin --- textures & ideas partly by Neuromancer - --- Contains code from: biome_lib --- Looked at code from: default, trees ------------------------------------------------------------------------------------------------ - -- NOTES (from wikipedia, some of this might get implemented) -- rhizomes are edible -- outer portion of young plants can be peeled and the heart can be eaten raw or boiled and eaten like asparagus @@ -24,14 +14,16 @@ local S = minetest.get_translator("dryplants") -- REEDMACE SHAPES ----------------------------------------------------------------------------------------------- -abstract_dryplants.grow_reedmace = function(pos) +local function grow_reedmace(pos) local size = math.random(1,3) local spikes = math.random(1,3) local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z} local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z} local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z} - if minetest.get_node(pos_01).name == "air" -- bug fix - or minetest.get_node(pos_01).name == "dryplants:reedmace_sapling" then + + local nodename = minetest.get_node(pos_01).name + if nodename == "air" -- bug fix + or nodename == "dryplants:reedmace_sapling" then if minetest.get_node(pos_02).name ~= "air" then minetest.swap_node(pos_01, {name="dryplants:reedmace_top"}) elseif minetest.get_node(pos_03).name ~= "air" then @@ -50,14 +42,16 @@ abstract_dryplants.grow_reedmace = function(pos) end end -abstract_dryplants.grow_reedmace_water = function(pos) +local function grow_reedmace_water(pos) local size = math.random(1,3) local spikes = math.random(1,3) local pos_01 = {x = pos.x, y = pos.y + 1, z = pos.z} local pos_02 = {x = pos.x, y = pos.y + 2, z = pos.z} local pos_03 = {x = pos.x, y = pos.y + 3, z = pos.z} local pos_04 = {x = pos.x, y = pos.y + 4, z = pos.z} + minetest.add_entity(pos_01, "dryplants:reedmace_water_entity") + if minetest.get_node(pos_02).name == "air" then -- bug fix if minetest.get_node(pos_03).name ~= "air" then minetest.swap_node(pos_02, {name="dryplants:reedmace_top"}) @@ -284,11 +278,11 @@ minetest.register_abm({ or string.find(minetest.get_node({x = pos.x - 1, y = pos.y, z = pos.z }).name, "default:water") or string.find(minetest.get_node({x = pos.x, y = pos.y, z = pos.z - 1}).name, "default:water") then if minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name == "air" then - abstract_dryplants.grow_reedmace_water({x = pos.x, y = pos.y - 1, z = pos.z}) + grow_reedmace_water({x = pos.x, y = pos.y - 1, z = pos.z}) end minetest.swap_node({x=pos.x, y=pos.y, z=pos.z}, {name="default:water_source"}) else - abstract_dryplants.grow_reedmace({x = pos.x, y = pos.y - 1, z = pos.z}) + grow_reedmace({x = pos.x, y = pos.y - 1, z = pos.z}) end end }) @@ -326,89 +320,121 @@ minetest.register_entity("dryplants:reedmace_water_entity",{ end, }) ----------------------------------------------------------------------------------------------- --- SPAWN REEDMACE ------------------------------------------------------------------------------------------------ ---[[biome_lib.register_active_spawner({ - spawn_delay = 1200, - spawn_plants = {"dryplants:reedmace_sapling"}, - spawn_chance = 400, - spawn_surfaces = { - "default:dirt_with_grass", - "default:desert_sand", - "default:sand", - "dryplants:grass_short", - "stoneage:grass_with_silex" - }, - seed_diff = 329, - near_nodes = {"default:water_source"}, - near_nodes_size = 2, - near_nodes_vertical = 1, - near_nodes_count = 1, -})]] ------------------------------------------------------------------------------------------------ -- GENERATE REEDMACE ----------------------------------------------------------------------------------------------- -- near water or swamp -biome_lib.register_on_generate({ - surface = { +minetest.register_decoration({ + name = "dryplants:reedmace_swamp", + decoration = {"air"}, + fill_ratio = "0.1", + y_min = 1, + y_max = 40, + place_on = { "default:dirt_with_grass", "default:desert_sand", "stoneage:grass_with_silex", "sumpf:peat", "sumpf:sumpf" }, - max_count = 35, - rarity = 101 - 40, - --rarity = 60, - min_elevation = 1, -- above sea level - near_nodes = {"default:water_source","sumpf:dirtywater_source","sumpf:sumpf"}, - near_nodes_size = 2, - near_nodes_vertical = 1, - near_nodes_count = 1, - plantlife_limit = -0.9, - }, - abstract_dryplants.grow_reedmace -) + deco_type = "simple", + flags = "all_floors", + spawn_by = { + "default:water_source", + "sumpf:dirtywater_source", + "sumpf:sumpf" + }, + check_offset = -1, + num_spawn_by = 1 +}) + -- in water -biome_lib.register_on_generate({ - surface = { +minetest.register_decoration({ + name = "dryplants:reedmace_water", + decoration = {"air"}, + fill_ratio = "0.01", + y_min = 0, + y_max = 0, + place_on = { "default:dirt", "default:dirt_with_grass", - --"default:desert_sand", - --"stoneage:grass_with_silex", "stoneage:sand_with_silex", "sumpf:peat", "sumpf:sumpf" }, - max_count = 35, - rarity = 101 - 65, - --rarity = 35, - min_elevation = 0, -- a bit below sea level - max_elevation = 0, -- "" - near_nodes = {"default:water_source","sumpf:dirtywater_source"}, - near_nodes_size = 1, - near_nodes_count = 1, - plantlife_limit = -0.9, - }, - abstract_dryplants.grow_reedmace_water -) + deco_type = "simple", + flags = "all_floors", + spawn_by = { + "default:water_source", + "sumpf:dirtywater_source" + }, + check_offset = -1, + num_spawn_by = 1 +}) + -- for oases & tropical beaches & tropical swamps -biome_lib.register_on_generate({ - surface = { +minetest.register_decoration({ + name = "dryplants:reedmace_beach", + decoration = {"air"}, + fill_ratio = "0.1", + y_min = 1, + y_max = 40, + place_on = { "default:sand", "sumpf:sumpf" }, - max_count = 35, - rarity = 101 - 90, - --rarity = 10, - neighbors = {"default:water_source","sumpf:dirtywater_source","sumpf:sumpf"}, - ncount = 1, - min_elevation = 1, -- above sea level - near_nodes = {"default:desert_sand","sumpf:sumpf"}, - near_nodes_size = 2, - near_nodes_vertical = 1, - near_nodes_count = 1, - plantlife_limit = -0.9, - }, - abstract_dryplants.grow_reedmace -) + deco_type = "simple", + flags = "all_floors", + spawn_by = { + "default:water_source", + "sumpf:dirtywater_source", + "sumpf:sumpf", + "default:desert_sand" + }, + check_offset = -1, + num_spawn_by = 1 +}) + +local did, did2, did3 +minetest.register_on_mods_loaded(function() + did = minetest.get_decoration_id("dryplants:reedmace_swamp") + did2 = minetest.get_decoration_id("dryplants:reedmace_water") + did3 = minetest.get_decoration_id("dryplants:reedmace_beach") + minetest.set_gen_notify("decoration", {did, did2, did3}) +end) + +minetest.register_on_generated(function(minp, maxp, blockseed) + local g = minetest.get_mapgen_object("gennotify") + local locations = {} + + local deco_locations_1 = g["decoration#" .. did] or {} + local deco_locations_3 = g["decoration#" .. did3] or {} + + for _, pos in pairs(deco_locations_1) do + locations[#locations+1] = pos + end + for _, pos in pairs(deco_locations_3) do + locations[#locations+1] = pos + end + + if #locations == 0 then return end + for _, pos in ipairs(locations) do + print(minetest.pos_to_string(pos)) + grow_reedmace(pos) + end +end) + +minetest.register_on_generated(function(minp, maxp, blockseed) + local g = minetest.get_mapgen_object("gennotify") + local locations = {} + + local deco_locations_2 = g["decoration#" .. did2] or {} + + for _, pos in pairs(deco_locations_2) do + locations[#locations+1] = pos + end + + if #locations == 0 then return end + for _, pos in ipairs(locations) do + grow_reedmace_water(pos) + end +end)