1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-06 02:20:24 +01:00
server-nalc/mods/plantlife_modpack/nature_classic/blossom.lua

76 lines
2.3 KiB
Lua
Raw Normal View History

-- Blossoms and such
2014-10-28 18:01:32 +01:00
local function spawn_apple_under(pos)
local below = {
x = pos.x,
y = pos.y - 1,
z = pos.z,
}
if minetest.get_node(below).name == "air" then
minetest.set_node(below, { name = "default:apple" })
end
end
minetest.register_node(":"..nature.blossom_node, {
2014-10-28 18:01:32 +01:00
description = "Apple blossoms",
drawtype = "allfaces_optional",
tiles = nature.blossom_textures,
2014-10-28 18:01:32 +01:00
paramtype = "light",
groups = { snappy = 3, leafdecay = 3, flammable = 2, leafdecay = 3 },
2014-10-28 18:01:32 +01:00
sounds = default.node_sound_leaves_defaults(),
waving = 1
})
minetest.register_craft({
type = "fuel",
recipe = nature.blossom_node,
2014-10-28 18:01:32 +01:00
burntime = 2,
})
-- these ABMs can get heavy, so just enqueue the nodes
-- Adding Blossoms
2015-06-20 21:24:55 +02:00
-- Limit mass changes after block has not been loaded for some time:
-- Run ABM with higher frequency, but don't enqueue all blocks
2014-10-28 18:01:32 +01:00
minetest.register_abm({
nodenames = { nature.blossom_leaves },
2015-06-20 21:24:55 +02:00
interval = nature.blossom_delay / nature.leaves_blossom_chance,
chance = nature.leaves_blossom_chance,
2014-10-28 18:01:32 +01:00
action = function(pos, node, active_object_count, active_object_count_wider)
2015-06-20 21:24:55 +02:00
if math.random(nature.leaves_blossom_chance) == 1 then
nature.enqueue_node(pos, node, nature.blossom_node)
end
2014-10-28 18:01:32 +01:00
end
})
-- Removing blossoms
2015-06-20 21:24:55 +02:00
-- Limit mass changes after block has not been loaded for some time:
-- Run ABM with higher frequency, but don't enqueue all blocks
2014-10-28 18:01:32 +01:00
minetest.register_abm({
nodenames = { nature.blossom_node },
2015-06-20 21:24:55 +02:00
interval = nature.blossom_delay / nature.blossom_leaves_chance,
chance = nature.blossom_leaves_chance,
2014-10-28 18:01:32 +01:00
action = function(pos, node, active_object_count, active_object_count_wider)
2015-06-20 21:24:55 +02:00
if math.random(nature.blossom_leaves_chance) == 1 then
nature.enqueue_node(pos, node, nature.blossom_leaves)
end
2014-10-28 18:01:32 +01:00
end
})
-- Spawning apples
2015-06-20 21:24:55 +02:00
-- Limit mass changes after block has not been loaded for some time:
-- spawn apples with 10% chance, but with 10 times higher frequency
2014-10-28 18:01:32 +01:00
minetest.register_abm({
nodenames = { nature.blossom_node },
2015-06-20 21:24:55 +02:00
interval = nature.blossom_delay / 10,
chance = nature.apple_chance,
2014-10-28 18:01:32 +01:00
action = function(pos, node, active_object_count, active_object_count_wider)
2015-06-20 21:24:55 +02:00
if math.random(10) == 0 and nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then
2014-10-28 18:01:32 +01:00
spawn_apple_under(pos)
end
end
})