summaryrefslogtreecommitdiff
path: root/nature_classic/blossom.lua
blob: 7accd5e8dcd6eae3134db554a2e0ebf0677ee9b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- support for i18n
local S = plantlife_i18n.gettext
-- Blossoms and such

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.swap_node(below, { name = "default:apple" })
    end
end

minetest.register_node(":"..nature.blossom_node, {
    description = S("Apple blossoms"),
    drawtype = "allfaces_optional",
    tiles = nature.blossom_textures,
    paramtype = "light",
    groups = nature.blossom_groups,
    sounds = default.node_sound_leaves_defaults(),
	waving = 1
})

default.register_leafdecay({
	trunks = { nature.blossom_trunk },
	leaves = { nature.blossom_node, nature.blossom_leaves },
	radius = nature.blossom_decay,
})

minetest.register_craft({
    type = "fuel",
    recipe = nature.blossom_node,
    burntime = 2,
})

-- these ABMs can get heavy, so just enqueue the nodes

-- Adding Blossoms
-- Limit mass changes after block has not been loaded for some time:
-- Run ABM with higher frequency, but don't enqueue all blocks
minetest.register_abm({
    nodenames = { nature.blossom_leaves },
    interval = nature.blossom_delay / nature.leaves_blossom_chance,
    chance = nature.leaves_blossom_chance,

    action = function(pos, node, active_object_count, active_object_count_wider)
			if math.random(nature.leaves_blossom_chance) == 1 then
				nature.enqueue_node(pos, node, nature.blossom_node)
			end
    end
})

-- Removing blossoms
-- Limit mass changes after block has not been loaded for some time:
-- Run ABM with higher frequency, but don't enqueue all blocks
minetest.register_abm({
    nodenames = { nature.blossom_node },
    interval = nature.blossom_delay / nature.blossom_leaves_chance,
    chance = nature.blossom_leaves_chance,

    action = function(pos, node, active_object_count, active_object_count_wider)
			if math.random(nature.blossom_leaves_chance) == 1 then
				nature.enqueue_node(pos, node, nature.blossom_leaves)
			end
    end
})

-- Spawning apples
-- Limit mass changes after block has not been loaded for some time:
-- spawn apples with 25% chance, but with 4 times higher frequency
minetest.register_abm({
    nodenames = { nature.blossom_node },
    interval = nature.apple_delay / 4,
    chance = nature.apple_chance,

    action = function(pos, node, active_object_count, active_object_count_wider)
		if math.random(4) == 1 and nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then
			spawn_apple_under(pos)
		end
    end
})