replace biome_lib ABM's (#48)

* replace biome_lib ABM's

* fix some params

* remove 'group:flora' from poisonivy avoid list

* fixes
This commit is contained in:
Niklp 2023-07-21 17:09:53 +02:00 committed by GitHub
parent 3b7fa4e8ea
commit 2af1d996d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 150 additions and 73 deletions

View File

@ -30,12 +30,19 @@ local modpath = minetest.get_modpath('bushes_classic')
dofile(modpath..'/cooking.lua')
dofile(modpath..'/nodes.lua')
biome_lib.register_active_spawner({
spawn_delay = 3600,
spawn_plants = bushes_classic.spawn_list,
avoid_radius = 10,
spawn_chance = 100,
spawn_surfaces = {
local spawn_plants = bushes_classic.spawn_list
local function get_biome_data(pos, perlin_fertile)
local fertility = perlin_fertile:get_2d({x=pos.x, y=pos.z})
local data = minetest.get_biome_data(pos)
-- Original values this method returned were +1 (lowest) to -1 (highest)
-- so we need to convert the 0-100 range from get_biome_data() to that.
return fertility, 1 - (data.heat / 100 * 2), 1 - (data.humidity / 100 * 2)
end
minetest.register_abm({
nodenames = {
"default:dirt_with_grass",
"woodsoils:dirt_with_leaves_1",
"woodsoils:grass_with_leaves_1",
@ -43,14 +50,31 @@ biome_lib.register_active_spawner({
"farming:soil",
"farming:soil_wet"
},
avoid_nodes = {"group:bush"},
seed_diff = 545342534, -- chosen by a fair mashing of the keyboard - guaranteed to be random :P
plantlife_limit = -0.1,
light_min = 10,
temp_min = 0.15, -- approx 20C
temp_max = -0.15, -- approx 35C
humidity_min = 0, -- 50% RH
humidity_max = -1, -- 100% RH
interval = 3600,
chance = 100,
label = "[bushes_classic] spawn bushes",
min_y = -16,
max_y = 48,
action = function(pos, node)
local p_top = {x = pos.x, y = pos.y + 1, z = pos.z}
local n_top = minetest.get_node_or_nil(p_top)
if not n_top or n_top.name ~= "air" then return end
local perlin_fertile_area = minetest.get_perlin(545342534, 3, 0.6, 100)
local fertility, temperature, humidity = get_biome_data(pos, perlin_fertile_area)
local pos_biome_ok = fertility > -0.1 and temperature <= 0.15 and temperature >= -0.15 and humidity <= 0 and humidity >= -1
if not pos_biome_ok then return end
if minetest.find_node_near(p_top, 10 + math.random(-1.5,2), {"group:bush"}) then
return -- Nodes to avoid are nearby
end
local plant_to_spawn = spawn_plants[math.random(1, #spawn_plants)]
minetest.swap_node(p_top, {name = plant_to_spawn, param2 = 0})
end
})
minetest.register_alias("bushes:basket_pies", "bushes:basket_strawberry")

View File

@ -1,3 +1,2 @@
name = bushes_classic
depends = biome_lib
optional_depends = farming, farming_plus

View File

@ -75,13 +75,10 @@ create_nodes()
-- Spawning
-----------------------------------------------------------------------------------------------
if abstract_ferns.config.enable_horsetails_spawning == true then
biome_lib.register_active_spawner({
spawn_delay = 1200,
spawn_plants = node_names,
spawn_chance = 400,
spawn_surfaces = {
minetest.register_abm({
nodenames = {
"default:dirt_with_grass",
"default:dirt_with_coniferous_litter", -- minetest >= 0.5
"default:dirt_with_coniferous_litter",
"default:desert_sand",
"default:sand",
"dryplants:grass_short",
@ -89,13 +86,28 @@ if abstract_ferns.config.enable_horsetails_spawning == true then
"default:mossycobble",
"default:gravel"
},
seed_diff = 329,
min_elevation = 1, -- above sea level
near_nodes = {"default:water_source","default:river_water_source","default:gravel"},
near_nodes_size = 2,
near_nodes_vertical = 1,
near_nodes_count = 1,
--random_facedir = { 0, 179 },
interval = 1200,
chance = 400,
label = "[ferns] spawn horsetails",
min_y = 1,
max_y = 48,
action = function(pos, node)
local p_top = {x = pos.x, y = pos.y + 1, z = pos.z}
local n_top = minetest.get_node_or_nil(p_top)
if not n_top or n_top.name ~= "air" then return end
local NEAR_DST = 2
if #minetest.find_nodes_in_area(
{x=pos.x-NEAR_DST, y=pos.y-1, z=pos.z-NEAR_DST},
{x=pos.x+NEAR_DST, y=pos.y+1, z=pos.z+NEAR_DST},
{"default:water_source","default:river_water_source","default:gravel"}
) < 1 then return
end
local plant_to_spawn = node_names[math.random(1, #node_names)]
minetest.swap_node(p_top, {name = plant_to_spawn, param2 = 0})
end
})
end

View File

@ -6,6 +6,9 @@ pl_seaweed = {}
local seaweed_max_count = tonumber(minetest.settings:get("pl_seaweed_max_count")) or 320
local seaweed_rarity = tonumber(minetest.settings:get("pl_seaweed_rarity")) or 33
local function get_ndef(name)
return minetest.registered_nodes[name] or {}
end
local algae_list = { {nil}, {2}, {3}, {4} }
@ -59,22 +62,21 @@ for i in ipairs(algae_list) do
local under_node = minetest.get_node(pt.under)
local above_node = minetest.get_node(pt.above)
local top_node = minetest.get_node(top_pos)
if biome_lib.get_nodedef_field(under_node.name, "buildable_to") then
if get_ndef(under_node.name)["buildable_to"] then
if under_node.name ~= "default:water_source" then
place_pos = pt.under
elseif top_node.name ~= "default:water_source"
and biome_lib.get_nodedef_field(top_node.name, "buildable_to") then
elseif top_node.name ~= "default:water_source" and get_ndef(top_node.name)["buildable_to"] then
place_pos = top_pos
else
return
end
elseif biome_lib.get_nodedef_field(above_node.name, "buildable_to") then
elseif get_ndef(above_node.name)["buildable_to"] then
place_pos = pt.above
end
if not place_pos then return end -- something went wrong :P
if not minetest.is_protected(place_pos, placer:get_player_name()) then
local pname = placer:get_player_name()
if not minetest.is_protected(place_pos, pname) then
local nodename = "default:cobble" -- :D
@ -96,7 +98,7 @@ for i in ipairs(algae_list) do
minetest.swap_node(place_pos, {name = "flowers:seaweed", param2 = fdir})
end
if not biome_lib.expect_infinite_stacks then
if not minetest.is_creative_enabled(pname) then
itemstack:take_item()
end
return itemstack

View File

@ -6,6 +6,9 @@ pl_waterlilies = {}
local lilies_max_count = tonumber(minetest.settings:get("pl_waterlilies_max_count")) or 320
local lilies_rarity = tonumber(minetest.settings:get("pl_waterlilies_rarity")) or 33
local function get_ndef(name)
return minetest.registered_nodes[name] or {}
end
local lilies_list = {
{ nil , nil , 1 },
@ -72,20 +75,20 @@ for i in ipairs(lilies_list) do
local above_node = minetest.get_node(pt.above)
local top_node = minetest.get_node(top_pos)
if biome_lib.get_nodedef_field(under_node.name, "buildable_to") then
if get_ndef(under_node.name)["buildable_to"] then
if under_node.name ~= "default:water_source" then
place_pos = pt.under
elseif top_node.name ~= "default:water_source"
and biome_lib.get_nodedef_field(top_node.name, "buildable_to") then
elseif top_node.name ~= "default:water_source" and get_ndef(top_node.name)["buildable_to"] then
place_pos = top_pos
else
return
end
elseif biome_lib.get_nodedef_field(above_node.name, "buildable_to") then
elseif get_ndef(above_node.name)["buildable_to"] then
place_pos = pt.above
end
if place_pos and not minetest.is_protected(place_pos, placer:get_player_name()) then
local pname = placer:get_player_name()
if place_pos and not minetest.is_protected(place_pos, pname) then
local nodename = "default:cobble" -- if this block appears, something went....wrong :-)
@ -114,7 +117,7 @@ for i in ipairs(lilies_list) do
minetest.swap_node(place_pos, {name = "flowers:waterlily", param2 = fdir})
end
if not biome_lib.expect_infinite_stacks then
if not minetest.is_creative_enabled(pname) then
itemstack:take_item()
end
return itemstack

View File

@ -3,11 +3,6 @@
-- support for i18n
local S = minetest.get_translator("poisonivy")
local SPAWN_DELAY = 1000
local SPAWN_CHANCE = 200
local GROW_DELAY = 500
local GROW_CHANCE = 30
local poisonivy_seed_diff = 339
local walls_list = {
"default:dirt",
"default:dirt_with_grass",
@ -69,33 +64,75 @@ minetest.register_node('poisonivy:climbing', {
buildable_to = true,
})
biome_lib.register_active_spawner({
spawn_delay = SPAWN_DELAY,
spawn_plants = {"poisonivy:seedling"},
avoid_radius = 10,
spawn_chance = SPAWN_CHANCE/10,
spawn_surfaces = {"default:dirt_with_grass"},
avoid_nodes = {"group:poisonivy", "group:flower", "group:flora"},
seed_diff = poisonivy_seed_diff,
light_min = 7,
alt_wallnode = "poisonivy:climbing",
verticals_list = walls_list
local function find_adjacent_wall(pos, verticals, randomflag)
local verts = dump(verticals)
if string.find(verts, minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z }).name) then return 3 end
if string.find(verts, minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z }).name) then return 2 end
if string.find(verts, minetest.get_node({x=pos.x , y=pos.y, z=pos.z-1}).name) then return 5 end
if string.find(verts, minetest.get_node({x=pos.x , y=pos.y, z=pos.z+1}).name) then return 4 end
return nil
end
minetest.register_abm({
nodenames = {"default:dirt_with_grass"},
interval = 1000,
chance = 20,
label = "[poisoninvy] spawn plants",
min_y = -16,
max_y = 48,
action = function(pos, node)
local p_top = {x = pos.x, y = pos.y + 1, z = pos.z}
local n_top = minetest.get_node_or_nil(p_top)
if not n_top or n_top.name ~= "air" then return end
local n_light = minetest.get_node_light(p_top)
if n_light < 7 then
return
end
if minetest.find_node_near(p_top, 10 + math.random(-1.5,2), {"group:poisonivy", "group:flower"}) then
return -- Nodes to avoid are nearby
end
local walldir = find_adjacent_wall(p_top, walls_list)
if walldir then
minetest.swap_node(p_top, {name = "poisonivy:climbing", param2 = walldir})
return
end
minetest.swap_node(p_top, {name = "poisonivy:seedling", param2 = 0})
end
})
biome_lib.update_plant({
grow_delay = SPAWN_DELAY,
grow_chance = GROW_CHANCE,
grow_plant = "poisonivy:seedling",
grow_result = "poisonivy:sproutling",
grow_nodes = {"default:dirt_with_grass"}
minetest.register_abm({
nodenames = {"poisonivy:seedling"},
interval = 1000,
chance = 30,
label = "grow poisonivy",
action = function(pos, node)
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
local n_top = minetest.get_node(p_top)
if n_top.name == "air" then
minetest.swap_node(pos, {name = "poisonivy:sproutling"})
end
end
})
biome_lib.update_plant({
grow_delay = GROW_DELAY,
grow_chance = GROW_CHANCE*2,
grow_plant = "poisonivy:climbing",
need_wall = true,
grow_vertically = true,
verticals_list = walls_list,
ground_nodes = {"default:dirt_with_grass"}
})
minetest.register_abm({
nodenames = {"poisonivy:climbing"},
interval = 500,
chance = 60,
label = "grow climbing poisonivy",
action = function(pos, node)
local p_top = {x=pos.x, y=pos.y+1, z=pos.z}
local n_top = minetest.get_node(p_top)
local walldir = find_adjacent_wall(p_top, walls_list)
if n_top.name == "air" and walldir then
minetest.swap_node(p_top, {name = "poisonivy:climbing", param2 = walldir})
end
end
})

View File

@ -1,2 +1,2 @@
name = poisonivy
depends = biome_lib
depends = default