2 -- This includes chorus flowers, chorus plant stem nodes and chorus fruit
4 local chorus_flower_box
= {
7 {-0.5, -0.375, -0.375, 0.5, 0.375, 0.375},
8 {-0.375, -0.375, 0.375, 0.375, 0.375, 0.5},
9 {-0.375, -0.375, -0.5, 0.375, 0.375, -0.375},
10 {-0.375, 0.375, -0.375, 0.375, 0.5, 0.375},
11 {-0.375, -0.5, -0.375, 0.375, -0.375, 0.375},
15 minetest
.register_node("mcl_end:chorus_flower", {
16 description
= "Chorus Flower",
18 "mcl_end_chorus_flower.png",
19 "mcl_end_chorus_flower.png",
20 "mcl_end_chorus_flower.png",
21 "mcl_end_chorus_flower.png",
22 "mcl_end_chorus_flower.png",
23 "mcl_end_chorus_flower.png",
27 sunlight_propagates
= true,
28 node_box
= chorus_flower_box
,
29 selection_box
= { type = "regular" },
30 sounds
= mcl_sounds
.node_sound_wood_defaults(),
31 groups
= {handy
=1,axey
=1, deco_block
= 1, dig_by_piston
= 1, destroy_by_lava_flow
= 1,},
33 node_placement_prediction
= "",
34 on_place
= function(itemstack
, placer
, pointed_thing
)
35 local node_under
= minetest
.get_node(pointed_thing
.under
)
36 local node_above
= minetest
.get_node(pointed_thing
.above
)
37 if placer
and not placer
:get_player_control().sneak
then
38 -- Use pointed node's on_rightclick function first, if present
39 if minetest
.registered_nodes
[node_under
.name
] and minetest
.registered_nodes
[node_under
.name
].on_rightclick
then
40 return minetest
.registered_nodes
[node_under
.name
].on_rightclick(pointed_thing
.under
, node_under
, placer
, itemstack
) or itemstack
44 --[[ Part 1: Check placement rules. Placement is legal is one of the following
46 1) On top of end stone or chorus plant
47 2) On top of air and horizontally adjacent to exactly 1 chorus plant ]]
49 if minetest
.registered_nodes
[node_under
.name
].buildable_to
then
50 pos
= pointed_thing
.under
52 pos
= pointed_thing
.above
56 local below
= {x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
}
57 local node_below
= minetest
.get_node(below
)
58 local plant_ok
= false
60 if node_below
.name
== "mcl_end:chorus_plant" or node_below
.name
== "mcl_end:end_stone" then
63 elseif node_below
.name
== "air" then
70 local around_count
= 0
72 local pos_side
= vector
.add(pos
, around
[a
])
73 local node_side
= minetest
.get_node(pos_side
)
74 if node_side
.name
== "mcl_end:chorus_plant" then
75 around_count
= around_count
+ 1
76 if around_count
> 1 then
81 if around_count
== 1 then
86 -- Placement OK! Proceed normally
87 return minetest
.item_place(itemstack
, placer
, pointed_thing
)
92 _mcl_blast_resistance
= 2,
96 minetest
.register_abm({
97 label
= "Chorus plant growth",
98 nodenames
= { "mcl_end:chorus_flower" },
101 action
= function(pos
, node
, active_object_count
, active_object_count_wider
)
102 local above
= { x
= pos
.x
, y
= pos
.y
+ 1, z
= pos
.z
}
103 local node_above
= minetest
.get_node(above
)
110 local air_around
= true
112 if minetest
.get_node(vector
.add(above
, around
[a
])).name
~= "air" then
118 if node_above
.name
== "air" and air_around
then
119 local branching
= false
122 local checkpos
= {x
=pos
.x
, y
=pos
.y
-y
, z
=pos
.z
}
123 local node
= minetest
.get_node(checkpos
)
124 if node
.name
== "mcl_end:chorus_plant" then
126 if not branching
then
128 local node_side
= minetest
.get_node(vector
.add(checkpos
, around
[a
]))
129 if node_side
.name
== "mcl_end:chorus_plant" then
142 elseif h
== 2 and branching
== false then
144 elseif h
== 2 and branching
== true then
146 elseif h
== 3 and branching
== false then
148 elseif h
== 3 and branching
== true then
150 elseif h
== 4 and branching
== false then
155 local new_flowers
= {}
156 local r
= math
.random(1, 100)
157 local age
= node
.param2
158 if r
<= grow_chance
then
159 table.insert(new_flowers
, above
)
163 if branching
== false then
164 branches
= math
.random(1, 4)
165 elseif branching
== true then
166 branches
= math
.random(0, 3)
168 local branch_grown
= false
170 local next_branch
= math
.random(1, #around
)
171 local branch
= vector
.add(pos
, around
[next_branch
])
172 local below_branch
= vector
.add(branch
, {x
=0,y
=-1,z
=0})
173 if minetest
.get_node(below_branch
).name
== "air" then
174 table.insert(new_flowers
, branch
)
179 for _
, f
in ipairs(new_flowers
) do
181 minetest
.set_node(f
, {name
="mcl_end:chorus_flower_dead"})
184 minetest
.set_node(f
, {name
="mcl_end:chorus_flower", param2
= age
})
188 if #new_flowers
>= 1 then
189 minetest
.set_node(pos
, {name
="mcl_end:chorus_plant"})
195 minetest
.set_node(pos
, {name
= "mcl_end:chorus_flower_dead"})
200 minetest
.register_node("mcl_end:chorus_flower_dead", {
201 description
= "Dead Chorus Flower",
203 "mcl_end_chorus_flower_dead.png",
204 "mcl_end_chorus_flower_dead.png",
205 "mcl_end_chorus_flower_dead.png",
206 "mcl_end_chorus_flower_dead.png",
207 "mcl_end_chorus_flower_dead.png",
208 "mcl_end_chorus_flower_dead.png",
210 drawtype
= "nodebox",
212 sunlight_propagates
= true,
213 node_box
= chorus_flower_box
,
214 selection_box
= { type = "regular" },
215 sounds
= mcl_sounds
.node_sound_wood_defaults(),
216 drop
= "mcl_end:chorus_flower",
217 groups
= {handy
=1,axey
=1, deco_block
= 1, dig_by_piston
= 1, destroy_by_lava_flow
= 1,},
218 _mcl_blast_resistance
= 2,
222 minetest
.register_node("mcl_end:chorus_plant", {
223 description
= "Chorus Plant Stem",
225 "mcl_end_chorus_plant.png",
226 "mcl_end_chorus_plant.png",
227 "mcl_end_chorus_plant.png",
228 "mcl_end_chorus_plant.png",
229 "mcl_end_chorus_plant.png",
230 "mcl_end_chorus_plant.png",
232 drawtype
= "nodebox",
234 sunlight_propagates
= true,
235 -- TODO: Maybe improve nodebox a bit to look more “natural”
238 fixed
= { -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 }, -- Core
239 connect_top
= { -0.1875, 0.25, -0.1875, 0.1875, 0.5, 0.1875 },
240 connect_left
= { -0.5, -0.1875, -0.1875, -0.25, 0.1875, 0.1875 },
241 connect_right
= { 0.25, -0.1875, -0.1875, 0.5, 0.1875, 0.1875 },
242 connect_bottom
= { -0.1875, -0.5, -0.25, 0.1875, -0.25, 0.25 },
243 connect_front
= { -0.1875, -0.1875, -0.5, 0.1875, 0.1875, -0.25 },
244 connect_back
= { -0.1875, -0.1875, 0.25, 0.1875, 0.1875, 0.5 },
246 connect_sides
= { "top", "bottom", "front", "back", "left", "right" },
247 connects_to
= {"mcl_end:chorus_plant", "mcl_end:chorus_flower", "mcl_end:chorus_flower_dead", "mcl_end:end_stone"},
248 sounds
= mcl_sounds
.node_sound_wood_defaults(),
251 { items
= { "mcl_end:chorus_fruit"}, rarity
= 2 },
254 groups
= {handy
=1,axey
=1, not_in_creative_inventory
= 1, dig_by_piston
= 1, destroy_by_lava_flow
= 1 },
255 _mcl_blast_resistance
= 2,
260 minetest
.register_craftitem("mcl_end:chorus_fruit", {
261 description
= "Chorus Fruit",
262 _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.",
263 wield_image
= "mcl_end_chorus_fruit.png",
264 inventory_image
= "mcl_end_chorus_fruit.png",
265 -- TODO: Teleport player
266 on_place
= minetest
.item_eat(4),
267 on_secondary_use
= minetest
.item_eat(4),
268 groups
= { food
= 2, eatable
= 4, can_eat_when_full
= 1 },
269 _mcl_saturation
= 2.4,
273 minetest
.register_craftitem("mcl_end:chorus_fruit_popped", {
274 description
= "Popped Chorus Fruit",
275 _doc_items_longdesc
= doc
.sub
.items
.temp
.craftitem
,
276 wield_image
= "mcl_end_chorus_fruit_popped.png",
277 inventory_image
= "mcl_end_chorus_fruit_popped.png",
278 groups
= { craftitem
= 1 },
282 minetest
.register_craft({
284 output
= "mcl_end:chorus_fruit_popped",
285 recipe
= "mcl_end:chorus_fruit",