Drop TODO in chorus_plant.lua
[MineClone/MineClone2.git] / mods / ITEMS / mcl_end / chorus_plant.lua
blob002477b0c4fe2661980aa6557d297657f9e7caa0
1 -- Chorus plants
2 -- This includes chorus flowers, chorus plant stem nodes and chorus fruit
5 --- Plant parts ---
7 local MAX_FLOWER_AGE = 5 -- Maximum age of chorus flower before it dies
9 local chorus_flower_box = {
10 type = "fixed",
11 fixed = {
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 tiles = {
23 "mcl_end_chorus_flower.png",
24 "mcl_end_chorus_flower.png",
25 "mcl_end_chorus_flower.png",
26 "mcl_end_chorus_flower.png",
27 "mcl_end_chorus_flower.png",
28 "mcl_end_chorus_flower.png",
30 drawtype = "nodebox",
31 paramtype = "light",
32 sunlight_propagates = true,
33 node_box = chorus_flower_box,
34 selection_box = { type = "regular" },
35 sounds = mcl_sounds.node_sound_wood_defaults(),
36 groups = {handy=1,axey=1, deco_block = 1, dig_by_piston = 1, destroy_by_lava_flow = 1,},
38 node_placement_prediction = "",
39 on_place = function(itemstack, placer, pointed_thing)
40 local node_under = minetest.get_node(pointed_thing.under)
41 local node_above = minetest.get_node(pointed_thing.above)
42 if placer and not placer:get_player_control().sneak then
43 -- Use pointed node's on_rightclick function first, if present
44 if minetest.registered_nodes[node_under.name] and minetest.registered_nodes[node_under.name].on_rightclick then
45 return minetest.registered_nodes[node_under.name].on_rightclick(pointed_thing.under, node_under, placer, itemstack) or itemstack
46 end
47 end
49 --[[ Part 1: Check placement rules. Placement is legal is one of the following
50 conditions is met:
51 1) On top of end stone or chorus plant
52 2) On top of air and horizontally adjacent to exactly 1 chorus plant ]]
53 local pos
54 if minetest.registered_nodes[node_under.name].buildable_to then
55 pos = pointed_thing.under
56 else
57 pos = pointed_thing.above
58 end
61 local below = {x=pos.x, y=pos.y-1, z=pos.z}
62 local node_below = minetest.get_node(below)
63 local plant_ok = false
64 -- Condition 1
65 if node_below.name == "mcl_end:chorus_plant" or node_below.name == "mcl_end:end_stone" then
66 plant_ok = true
67 -- Condition 2
68 elseif node_below.name == "air" then
69 local around = {
70 { x= 1, y=0, z= 0 },
71 { x=-1, y=0, z= 0 },
72 { x= 0, y=0, z= 1 },
73 { x= 0, y=0, z=-1 },
75 local around_count = 0
76 for a=1, #around do
77 local pos_side = vector.add(pos, around[a])
78 local node_side = minetest.get_node(pos_side)
79 if node_side.name == "mcl_end:chorus_plant" then
80 around_count = around_count + 1
81 if around_count > 1 then
82 break
83 end
84 end
85 end
86 if around_count == 1 then
87 plant_ok = true
88 end
89 end
90 if plant_ok then
91 -- Placement OK! Proceed normally
92 return minetest.item_place(itemstack, placer, pointed_thing)
93 else
94 return itemstack
95 end
96 end,
97 _mcl_blast_resistance = 2,
98 _mcl_hardness = 0.4,
101 minetest.register_node("mcl_end:chorus_flower_dead", {
102 description = "Dead Chorus Flower",
103 tiles = {
104 "mcl_end_chorus_flower_dead.png",
105 "mcl_end_chorus_flower_dead.png",
106 "mcl_end_chorus_flower_dead.png",
107 "mcl_end_chorus_flower_dead.png",
108 "mcl_end_chorus_flower_dead.png",
109 "mcl_end_chorus_flower_dead.png",
111 drawtype = "nodebox",
112 paramtype = "light",
113 sunlight_propagates = true,
114 node_box = chorus_flower_box,
115 selection_box = { type = "regular" },
116 sounds = mcl_sounds.node_sound_wood_defaults(),
117 drop = "mcl_end:chorus_flower",
118 groups = {handy=1,axey=1, deco_block = 1, dig_by_piston = 1, destroy_by_lava_flow = 1,},
119 _mcl_blast_resistance = 2,
120 _mcl_hardness = 0.4,
123 minetest.register_node("mcl_end:chorus_plant", {
124 description = "Chorus Plant Stem",
125 tiles = {
126 "mcl_end_chorus_plant.png",
127 "mcl_end_chorus_plant.png",
128 "mcl_end_chorus_plant.png",
129 "mcl_end_chorus_plant.png",
130 "mcl_end_chorus_plant.png",
131 "mcl_end_chorus_plant.png",
133 drawtype = "nodebox",
134 paramtype = "light",
135 sunlight_propagates = true,
136 node_box = {
137 type = "connected",
138 fixed = { -0.25, -0.25, -0.25, 0.25, 0.25, 0.25 }, -- Core
139 connect_top = { -0.1875, 0.25, -0.1875, 0.1875, 0.5, 0.1875 },
140 connect_left = { -0.5, -0.1875, -0.1875, -0.25, 0.1875, 0.1875 },
141 connect_right = { 0.25, -0.1875, -0.1875, 0.5, 0.1875, 0.1875 },
142 connect_bottom = { -0.1875, -0.5, -0.25, 0.1875, -0.25, 0.25 },
143 connect_front = { -0.1875, -0.1875, -0.5, 0.1875, 0.1875, -0.25 },
144 connect_back = { -0.1875, -0.1875, 0.25, 0.1875, 0.1875, 0.5 },
146 connect_sides = { "top", "bottom", "front", "back", "left", "right" },
147 connects_to = {"mcl_end:chorus_plant", "mcl_end:chorus_flower", "mcl_end:chorus_flower_dead", "mcl_end:end_stone"},
148 sounds = mcl_sounds.node_sound_wood_defaults(),
149 drop = {
150 items = {
151 { items = { "mcl_end:chorus_fruit"}, rarity = 2 },
154 groups = {handy=1,axey=1, not_in_creative_inventory = 1, dig_by_piston = 1, destroy_by_lava_flow = 1 },
155 _mcl_blast_resistance = 2,
156 _mcl_hardness = 0.4,
160 --- ABM ---
161 minetest.register_abm({
162 label = "Chorus plant growth",
163 nodenames = { "mcl_end:chorus_flower" },
164 interval = 35.0,
165 chance = 4.0,
166 action = function(pos, node, active_object_count, active_object_count_wider)
167 local above = { x = pos.x, y = pos.y + 1, z = pos.z }
168 local node_above = minetest.get_node(above)
169 local around = {
170 { x=-1, y=0, z= 0 },
171 { x= 1, y=0, z= 0 },
172 { x= 0, y=0, z=-1 },
173 { x= 0, y=0, z= 1 },
175 local air_around = true
176 for a=1, #around do
177 if minetest.get_node(vector.add(above, around[a])).name ~= "air" then
178 air_around = false
179 break
182 local grown = false
183 if node_above.name == "air" and air_around then
184 local branching = false
185 local h = 0
186 for y=1, 4 do
187 local checkpos = {x=pos.x, y=pos.y-y, z=pos.z}
188 local node = minetest.get_node(checkpos)
189 if node.name == "mcl_end:chorus_plant" then
190 h = y
191 if not branching then
192 for a=1, #around do
193 local node_side = minetest.get_node(vector.add(checkpos, around[a]))
194 if node_side.name == "mcl_end:chorus_plant" then
195 branching = true
199 else
200 break
204 local grow_chance
205 if h <= 1 then
206 grow_chance = 100
207 elseif h == 2 and branching == false then
208 grow_chance = 60
209 elseif h == 2 and branching == true then
210 grow_chance = 50
211 elseif h == 3 and branching == false then
212 grow_chance = 40
213 elseif h == 3 and branching == true then
214 grow_chance = 25
215 elseif h == 4 and branching == false then
216 grow_chance = 20
219 if grow_chance then
220 local new_flowers = {}
221 local r = math.random(1, 100)
222 local age = node.param2
223 if r <= grow_chance then
224 table.insert(new_flowers, above)
225 else
226 age = age + 1
227 local branches
228 if branching == false then
229 branches = math.random(1, 4)
230 elseif branching == true then
231 branches = math.random(0, 3)
233 local branch_grown = false
234 for b=1, branches do
235 local next_branch = math.random(1, #around)
236 local branch = vector.add(pos, around[next_branch])
237 local below_branch = vector.add(branch, {x=0,y=-1,z=0})
238 if minetest.get_node(below_branch).name == "air" then
239 table.insert(new_flowers, branch)
244 for _, f in ipairs(new_flowers) do
245 if age >= MAX_FLOWER_AGE then
246 minetest.set_node(f, {name="mcl_end:chorus_flower_dead"})
247 grown = true
248 else
249 minetest.set_node(f, {name="mcl_end:chorus_flower", param2 = age})
250 grown = true
253 if #new_flowers >= 1 then
254 minetest.set_node(pos, {name="mcl_end:chorus_plant"})
255 grown = true
259 if not grown then
260 minetest.set_node(pos, {name = "mcl_end:chorus_flower_dead"})
262 end,
265 --- Craftitems ---
266 minetest.register_craftitem("mcl_end:chorus_fruit", {
267 description = "Chorus Fruit",
268 _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.",
269 wield_image = "mcl_end_chorus_fruit.png",
270 inventory_image = "mcl_end_chorus_fruit.png",
271 -- TODO: Teleport player
272 on_place = minetest.item_eat(4),
273 on_secondary_use = minetest.item_eat(4),
274 groups = { food = 2, eatable = 4, can_eat_when_full = 1 },
275 _mcl_saturation = 2.4,
276 stack_max = 64,
279 minetest.register_craftitem("mcl_end:chorus_fruit_popped", {
280 description = "Popped Chorus Fruit",
281 _doc_items_longdesc = doc.sub.items.temp.craftitem,
282 wield_image = "mcl_end_chorus_fruit_popped.png",
283 inventory_image = "mcl_end_chorus_fruit_popped.png",
284 groups = { craftitem = 1 },
285 stack_max = 64,
288 --- Crafting ---
289 minetest.register_craft({
290 type = "cooking",
291 output = "mcl_end:chorus_fruit_popped",
292 recipe = "mcl_end:chorus_fruit",
293 cooktime = 10,