From 117ae0933a24271a21ff59e56eb0bf8134b21ee9 Mon Sep 17 00:00:00 2001 From: sys4 Date: Sat, 13 Jun 2020 22:16:45 +0200 Subject: [PATCH] =?UTF-8?q?[nalc=5Fflowers]=20R=C3=A9=C3=A9criture=20du=20?= =?UTF-8?q?mod=20et=20supprime=20la=20d=C3=A9pendance=20biome=5Flib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les nénuphars custom ont 1/5 chance de se régénérer toute les 600 secondes près d'un bloc de jungletree. --- nalc_flowers/depends.txt | 2 +- nalc_flowers/init.lua | 144 +++++++++++++++------------------------ nalc_flowers/mod.conf | 3 + 3 files changed, 60 insertions(+), 89 deletions(-) create mode 100644 nalc_flowers/mod.conf diff --git a/nalc_flowers/depends.txt b/nalc_flowers/depends.txt index 5ca1f17..abb01ae 100644 --- a/nalc_flowers/depends.txt +++ b/nalc_flowers/depends.txt @@ -1,2 +1,2 @@ default -biome_lib? +flowers diff --git a/nalc_flowers/init.lua b/nalc_flowers/init.lua index 3b314d7..c4ebe53 100644 --- a/nalc_flowers/init.lua +++ b/nalc_flowers/init.lua @@ -1,29 +1,9 @@ -local lilypad_def = { - description = "Lily Pad", - drawtype = "nodebox", - tiles = { "flowers_lily_pad.png" }, - inventory_image = "flowers_lily_pad.png", - wield_image = "flowers_lily_pad.png", - wield_scale = {x = 1, y = 1, z = 0.001}, - sunlight_propagates = true, - paramtype = "light", - paramtype2 = "facedir", - liquids_pointable = true, - walkable = false, - buildable_to = true, - floodable = true, - groups = {snappy = 3, flammable = 1, flower = 1}, - sounds = default.node_sound_leaves_defaults(), - node_placement_prediction = "", - node_box = { - type = "fixed", - fixed = {-0.5, -0.45, -0.5, 0.5, -0.4375, 0.5}, - }, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}, - }, - on_place = function(itemstack, placer, pointed_thing) +local lilypad_def = table.copy(minetest.registered_nodes["flowers:waterlily"]) +lilypad_def.description = "Lily Pad" +lilypad_def.tiles = {"flowers_lily_pad.png"} +lilypad_def.inventory_image = "flowers_lily_pad.png" +lilypad_def.wield_image = "flowers_lily_pad.png" +lilypad_def.on_place = function(itemstack, placer, pointed_thing) local pos = pointed_thing.above local node = minetest.get_node(pointed_thing.under) local def = minetest.registered_nodes[node.name] @@ -51,8 +31,7 @@ local lilypad_def = { end return itemstack - end -} +end local lilypad_waving_def = table.copy(lilypad_def) lilypad_waving_def.waving = 3 @@ -62,69 +41,58 @@ lilypad_waving_def.groups.not_in_creative_inventory = 1 minetest.register_node("nalc_flowers:lily_pad", lilypad_def) minetest.register_node("nalc_flowers:lily_pad_waving", lilypad_waving_def) -if biome_lib then - local grow_lily_pad = function(pos) - minetest.swap_node( - {x=pos.x, y=pos.y+1, z=pos.z}, - { - name="nalc_flowers:lily_pad_waving", - param2=math.random(0,3) - } - ) +local function lily_pad_spread(pos, node) + if minetest.get_node_light(pos, nil) < 9 then + return end - biome_lib:register_generate_plant({ - surface = {"default:water_source"}, - max_count = 320, - rarity = 33, - min_elevation = 1, - max_elevation = 40, - near_nodes = {"default:dirt_with_grass", "default:dry_dirt_with_dry_grass", "default:jungletree"}, - near_nodes_size = 4, - near_nodes_vertical = 1, - near_nodes_count = 1, - plantlife_limit = -0.9, - temp_max = -0.22, - temp_min = 0.22, - }, - grow_lily_pad - ) - -- spawn ABM registration - biome_lib:spawn_on_surfaces({ - spawn_delay = 500, - spawn_plants = {"nalc_flowers:lily_pad_waving"}, - avoid_radius = 2.5, - spawn_chance = 800, - spawn_surfaces = {"default:water_source"}, - avoid_nodes = {"group:flower", "group:flora"}, - seed_diff = 330, - light_min = 9, - depth_max = 2, - random_facedir = {0,3}, - }) -else - minetest.register_decoration({ - name = "nalc_flowers:lily_pad", - deco_type = "simple", - place_on = {"default:dirt"}, - sidelen = 16, - noise_params = { - offset = -0.12, - scale = 0.3, - spread = {x=200, y=200, z=200}, - seed = 34, - octaves = 3, - persist = 0.7 - }, - biomes = {"rainforest_swamp", "savanna_shore", "deciduous_forest_shore"}, - y_min = 0, - y_max = 0, - decoration = "nalc_flowers:lily_pad_waving", - param2 = 0, - param2_max = 3, - place_offset_y = 1, - }) + local positions = minetest.find_nodes_in_area_under_air( + {x = pos.x - 1, y = pos.y-1, z = pos.z - 1}, + {x = pos.x + 1, y = pos.y-1, z = pos.z + 1}, + {"default:water_source"}) + + if #positions == 0 then return end + + local pos2 = positions[math.random(#positions)] + pos2.y = pos2.y+1 + if minetest.get_node_light(pos2, nil) >= 9 then + minetest.set_node(pos2, {name = node.name}) + end end + +-- spawn ABM registration +minetest.register_abm({ + label = "Lilypad spread", + nodenames = {"nalc_flowers:lily_pad_waving"}, + neighbors = {"default:jungletree"}, + interval = 600, + chance = 5, + action = function(...) + lily_pad_spread(...) + end, +}) + +minetest.register_decoration({ + name = "nalc_flowers:lily_pad", + deco_type = "simple", + place_on = {"default:dirt"}, + sidelen = 16, + noise_params = { + offset = -0.12, + scale = 0.3, + spread = {x=200, y=200, z=200}, + seed = 34, + octaves = 3, + persist = 0.7 + }, + biomes = {"rainforest_swamp"}, + y_min = 0, + y_max = 0, + decoration = "nalc_flowers:lily_pad_waving", + param2 = 0, + param2_max = 3, + place_offset_y = 1, +}) minetest.register_alias("flowers:lily_pad", "nalc_flowers:lily_pad") minetest.register_alias("nalc:lily_pad", "nalc_flowers:lily_pad") diff --git a/nalc_flowers/mod.conf b/nalc_flowers/mod.conf new file mode 100644 index 0000000..db6a4e8 --- /dev/null +++ b/nalc_flowers/mod.conf @@ -0,0 +1,3 @@ +name = nalc_flowers +description = NALC mod: nalc_flowers +depends = default,flowers