2 -- This includes chorus flowers, chorus plant stem nodes and chorus fruit
7 local MAX_FLOWER_AGE
= 5 -- Maximum age of chorus flower before it dies
9 local chorus_flower_box
= {
12 {-0.5, -0.375, -0.375, 0.5, 0.375, 0.375},
13 {-0.375, -0.375, 0.375, 0.375, 0.375, 0.5},
14 {-0.375, -0.375, -0.5, 0.375, 0.375, -0.375},
15 {-0.375, 0.375, -0.375, 0.375, 0.5, 0.375},
16 {-0.375, -0.5, -0.375, 0.375, -0.375, 0.375},
20 minetest
.register_node("mcl_end:chorus_flower", {
21 description
= "Chorus Flower",
22 _doc_items_longdesc
= "A chorus flower is the living part of a chorus plant. It can grow into a tall chorus plant, step by step. When it grows, it may die on old age eventually. It also dies when it is unable to grow.",
23 _doc_items_usagehelp
= "Place it and wait for it to grow. It can only be placed on top of end stone, on top of a chorus plant stem, or at the side of exactly a chorus plant stem.",
25 "mcl_end_chorus_flower.png",
26 "mcl_end_chorus_flower.png",
27 "mcl_end_chorus_flower.png",
28 "mcl_end_chorus_flower.png",
29 "mcl_end_chorus_flower.png",
30 "mcl_end_chorus_flower.png",
34 sunlight_propagates
= true,
35 node_box
= chorus_flower_box
,
36 selection_box
= { type = "regular" },
37 sounds
= mcl_sounds
.node_sound_wood_defaults(),
38 groups
= {handy
=1,axey
=1, deco_block
= 1, dig_by_piston
= 1, destroy_by_lava_flow
= 1,},
40 node_placement_prediction
= "",
41 on_place
= function(itemstack
, placer
, pointed_thing
)
42 local node_under
= minetest
.get_node(pointed_thing
.under
)
43 local node_above
= minetest
.get_node(pointed_thing
.above
)
44 if placer
and not placer
:get_player_control().sneak
then
45 -- Use pointed node's on_rightclick function first, if present
46 if minetest
.registered_nodes
[node_under
.name
] and minetest
.registered_nodes
[node_under
.name
].on_rightclick
then
47 return minetest
.registered_nodes
[node_under
.name
].on_rightclick(pointed_thing
.under
, node_under
, placer
, itemstack
) or itemstack
51 --[[ Part 1: Check placement rules. Placement is legal is one of the following
53 1) On top of end stone or chorus plant
54 2) On top of air and horizontally adjacent to exactly 1 chorus plant ]]
56 if minetest
.registered_nodes
[node_under
.name
].buildable_to
then
57 pos
= pointed_thing
.under
59 pos
= pointed_thing
.above
63 local below
= {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
}
64 local node_below
= minetest
.get_node(below
)
65 local plant_ok
= false
67 if node_below
.name
== "mcl_end:chorus_plant" or node_below
.name
== "mcl_end:end_stone" then
70 elseif node_below
.name
== "air" then
77 local around_count
= 0
79 local pos_side
= vector
.add(pos
, around
[a
])
80 local node_side
= minetest
.get_node(pos_side
)
81 if node_side
.name
== "mcl_end:chorus_plant" then
82 around_count
= around_count
+ 1
83 if around_count
> 1 then
88 if around_count
== 1 then
93 -- Placement OK! Proceed normally
94 return minetest
.item_place(itemstack
, placer
, pointed_thing
)
99 _mcl_blast_resistance
= 2,
103 minetest
.register_node("mcl_end:chorus_flower_dead", {
104 description
= "Dead Chorus Flower",
105 _doc_items_longdesc
= "This is a part of a chorus plant. It doesn't grow. Chorus flowers die of old age or when they are unable to grow. A dead chorus flower can be harvested to obtain a fresh chorus flower which is able to grow again.",
107 "mcl_end_chorus_flower_dead.png",
108 "mcl_end_chorus_flower_dead.png",
109 "mcl_end_chorus_flower_dead.png",
110 "mcl_end_chorus_flower_dead.png",
111 "mcl_end_chorus_flower_dead.png",
112 "mcl_end_chorus_flower_dead.png",
114 drawtype
= "nodebox",
116 sunlight_propagates
= true,
117 node_box
= chorus_flower_box
,
118 selection_box
= { type = "regular" },
119 sounds
= mcl_sounds
.node_sound_wood_defaults(),
120 drop
= "mcl_end:chorus_flower",
121 groups
= {handy
=1,axey
=1, deco_block
= 1, dig_by_piston
= 1, destroy_by_lava_flow
= 1,},
122 _mcl_blast_resistance
= 2,
126 minetest
.register_node("mcl_end:chorus_plant", {
127 description
= "Chorus Plant Stem",
128 _doc_items_longdesc
= "A chorus plant stem is the part of a chorus plant which holds the whole plant together. It needs end stone as its soil. Stems are grown from chorus flowers.",
130 "mcl_end_chorus_plant.png",
131 "mcl_end_chorus_plant.png",
132 "mcl_end_chorus_plant.png",
133 "mcl_end_chorus_plant.png",
134 "mcl_end_chorus_plant.png",
135 "mcl_end_chorus_plant.png",
137 drawtype
= "nodebox",
139 sunlight_propagates
= true,
142 fixed
= { -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 }, -- Core
143 connect_top
= { -0.1875, 0.25, -0.1875, 0.1875, 0.5, 0.1875 },
144 connect_left
= { -0.5, -0.1875, -0.1875, -0.25, 0.1875, 0.1875 },
145 connect_right
= { 0.25, -0.1875, -0.1875, 0.5, 0.1875, 0.1875 },
146 connect_bottom
= { -0.1875, -0.5, -0.25, 0.1875, -0.25, 0.25 },
147 connect_front
= { -0.1875, -0.1875, -0.5, 0.1875, 0.1875, -0.25 },
148 connect_back
= { -0.1875, -0.1875, 0.25, 0.1875, 0.1875, 0.5 },
150 connect_sides
= { "top", "bottom", "front", "back", "left", "right" },
151 connects_to
= {"mcl_end:chorus_plant", "mcl_end:chorus_flower", "mcl_end:chorus_flower_dead", "mcl_end:end_stone"},
152 sounds
= mcl_sounds
.node_sound_wood_defaults(),
155 { items
= { "mcl_end:chorus_fruit"}, rarity
= 2 },
158 groups
= {handy
=1,axey
=1, not_in_creative_inventory
= 1, dig_by_piston
= 1, destroy_by_lava_flow
= 1 },
159 _mcl_blast_resistance
= 2,
165 minetest
.register_abm({
166 label
= "Chorus plant growth",
167 nodenames
= { "mcl_end:chorus_flower" },
170 action
= function(pos
, node
, active_object_count
, active_object_count_wider
)
171 local above
= { x
= pos
.x
, y
= pos
.y
+ 1, z
= pos
.z
}
172 local node_above
= minetest
.get_node(above
)
179 local air_around
= true
181 if minetest
.get_node(vector
.add(above
, around
[a
])).name
~= "air" then
187 if node_above
.name
== "air" and air_around
then
188 local branching
= false
191 local checkpos
= {x
=pos
.x
, y
=pos
.y
-y
, z
=pos
.z
}
192 local node
= minetest
.get_node(checkpos
)
193 if node
.name
== "mcl_end:chorus_plant" then
195 if not branching
then
197 local node_side
= minetest
.get_node(vector
.add(checkpos
, around
[a
]))
198 if node_side
.name
== "mcl_end:chorus_plant" then
211 elseif h
== 2 and branching
== false then
213 elseif h
== 2 and branching
== true then
215 elseif h
== 3 and branching
== false then
217 elseif h
== 3 and branching
== true then
219 elseif h
== 4 and branching
== false then
224 local new_flowers
= {}
225 local r
= math
.random(1, 100)
226 local age
= node
.param2
227 if r
<= grow_chance
then
228 table.insert(new_flowers
, above
)
232 if branching
== false then
233 branches
= math
.random(1, 4)
234 elseif branching
== true then
235 branches
= math
.random(0, 3)
237 local branch_grown
= false
239 local next_branch
= math
.random(1, #around
)
240 local branch
= vector
.add(pos
, around
[next_branch
])
241 local below_branch
= vector
.add(branch
, {x
=0,y
=-1,z
=0})
242 if minetest
.get_node(below_branch
).name
== "air" then
243 table.insert(new_flowers
, branch
)
248 for _
, f
in ipairs(new_flowers
) do
249 if age
>= MAX_FLOWER_AGE
then
250 minetest
.set_node(f
, {name
="mcl_end:chorus_flower_dead"})
253 minetest
.set_node(f
, {name
="mcl_end:chorus_flower", param2
= age
})
257 if #new_flowers
>= 1 then
258 minetest
.set_node(pos
, {name
="mcl_end:chorus_plant"})
264 minetest
.set_node(pos
, {name
= "mcl_end:chorus_flower_dead"})
270 minetest
.register_craftitem("mcl_end:chorus_fruit", {
271 description
= "Chorus Fruit",
272 _doc_items_longdesc
= "Chorus fruits are the fruits of the chorus plant which is home to the End. They can be eaten to restore a few hunger points.",
273 wield_image
= "mcl_end_chorus_fruit.png",
274 inventory_image
= "mcl_end_chorus_fruit.png",
275 -- TODO: Teleport player
276 on_place
= minetest
.item_eat(4),
277 on_secondary_use
= minetest
.item_eat(4),
278 groups
= { food
= 2, eatable
= 4, can_eat_when_full
= 1 },
279 _mcl_saturation
= 2.4,
283 minetest
.register_craftitem("mcl_end:chorus_fruit_popped", {
284 description
= "Popped Chorus Fruit",
285 _doc_items_longdesc
= doc
.sub
.items
.temp
.craftitem
,
286 wield_image
= "mcl_end_chorus_fruit_popped.png",
287 inventory_image
= "mcl_end_chorus_fruit_popped.png",
288 groups
= { craftitem
= 1 },
293 minetest
.register_craft({
295 output
= "mcl_end:chorus_fruit_popped",
296 recipe
= "mcl_end:chorus_fruit",