1 local S
= minetest
.get_translator("hades_fertilizer")
3 local farms
= { "wheat", "cotton", "spice", "potato", "tomato", "strawberry" }
5 -- Register tables for all plant variants
6 local plants_rotate
= {}
13 table.insert(t
, "hades_farming:seed_"..farms
[f
])
15 table.insert(t
, "hades_farming:"..farms
[f
].."_"..i
)
17 table.insert(plants_rotate
, t
)
20 t
= { true, "hades_grass:seed_grass", "hades_grass:grass_1", "hades_grass:grass_2", "hades_grass:grass_3", "hades_grass:grass_4", "hades_grass:grass_5" }
21 table.insert(plants_rotate
, t
)
23 t
= { true, "hades_refruit:bud_apple", "hades_refruit:flower_apple", "hades_trees:apple" }
24 table.insert(plants_rotate
, t
)
26 t
= { true, "hades_refruit:bud_olive", "hades_refruit:flower_olive", "hades_trees:olive" }
27 table.insert(plants_rotate
, t
)
29 t
= { true, "hades_refruit:bud_orange", "hades_refruit:flower_orange", "hades_trees:orange" }
30 table.insert(plants_rotate
, t
)
32 t
= { true, "hades_refruit:bud_banana", "hades_refruit:flower_banana", "hades_trees:banana" }
33 table.insert(plants_rotate
, t
)
35 t
= { true, "hades_refruit:bud_cocoa", "hades_refruit:flower_cocoa", "hades_trees:cocoa_pod" }
36 table.insert(plants_rotate
, t
)
38 t
= { true, "hades_refruit:bud_coconut", "hades_refruit:flower_coconut", "hades_trees:coconut" }
39 table.insert(plants_rotate
, t
)
43 table.insert(t
, "hades_grass:grass_"..i
)
45 table.insert(plants_rotate
, t
)
48 local plant_mappings
= {}
49 for p
=1, #plants_rotate
do
50 local rotate
= plants_rotate
[p
]
51 local super
= rotate
[1]
54 plant_mappings
[rotate
[r]]
= { rotate
[nextr
], super
}
58 -- Call minetest.set_node(pos, node), but only if pos is not protected by playername
59 local set_node_protected
= function(pos
, node
, playername
)
60 if not (minetest
.is_protected(pos
, playername
) and not minetest
.check_player_privs(playername
, "protection_bypass")) then
61 minetest
.set_node(pos
, node
)
67 -- Returns an on_place function for fertilizer.
68 -- 'super' parameter is true for Super Fertilizer and false for normal fertilizer
69 local get_apply_fertilizer
= function(super
)
70 return function(itemstack
, placer
, pointed_thing
)
71 if not pointed_thing
or pointed_thing
.type ~= "node" or not placer
then
74 local name
= placer
:get_player_name()
75 local pos
= pointed_thing
.under
76 local nnode
= minetest
.get_node(pos
)
77 local nname
= nnode
.name
79 -- Boilerplate to check pointed node's on rightlick function
80 local def
= minetest
.registered_nodes
[nname
]
81 if def
and def
.on_rightclick
and
82 ((not placer
) or (placer
and not placer
:get_player_control().sneak
)) then
83 return def
.on_rightclick(pos
, nnode
, placer
, itemstack
,
84 pointed_thing
) or itemstack
87 if minetest
.is_protected(pos
, name
) and not minetest
.check_player_privs(name
, "protection_bypass") then
88 minetest
.record_protection_violation(pos
, name
)
92 if plant_mappings
[nname
] then
94 -- Restrict usable plants if not super fertilizer
95 if plant_mappings
[nname
][2] == true then return itemstack
end
96 if math
.random(1,3) == 1 then return itemstack
end
98 -- Add plant growth stage
99 set_node_protected(pos
, {name
=plant_mappings
[nname
][1], param2
=nnode
.param2
}, name
)
100 elseif minetest
.get_item_group(nname
, "sapling") ~= 0 then
101 if not super
and math
.random(1,5) ~= 1 then return itemstack
end
102 -- Grow sapling to tree
103 if minetest
.is_protected(pos
, name
) and not minetest
.check_player_privs(name
, "protection_bypass") then
106 hades_trees
.grow_sapling(pos
, false)
108 elseif nname
== "hades_flowerpots:flower_pot" then
109 if not super
then return itemstack
end
110 -- [SUPER] Grow random flower in empty flowerpot
112 "red", "white", "yellow", "orange", "yellow", "violet",
114 local flower
= flowers
[math
.random(1, #flowers
)]
115 set_node_protected(pos
, {name
="hades_flowerpots:flower_pot_"..flower
}, name
)
116 elseif minetest
.get_item_group(nname
, "leaves") == 1 then
117 if not super
then return itemstack
end
118 -- [SUPER] Grow leaves
128 local ppos
= vector
.add(pos
, posses
[p
])
129 if minetest
.get_node(ppos
).name
== "air" then
130 set_node_protected(ppos
, {name
=nname
, param2
=nnode
.param2
}, name
)
133 elseif nname
== "hades_core:papyrus" or nname
== "hades_core:sugarcane" or nname
== "hades_core:cactus" or minetest
.get_item_group(nname
, "tree") == 1 then
134 if not super
then return itemstack
end
135 -- [SUPER] Grow reeds and tree trunks upwards
138 above
= {x
=pos
.x
,y
=pos
.y
+i
,z
=pos
.z
}
139 local node
= minetest
.get_node(above
)
140 if node
.name
== "air" then
141 set_node_protected(above
, {name
=nname
}, name
)
143 elseif node
.name
~= nname
then
147 elseif minetest
.get_item_group(nname
, "vines") ~= 0 or nname
== "hades_vines:root" then
148 if not super
then return itemstack
end
149 -- [SUPER] Grow vines
150 local param2
= nnode
.param2
151 if param2
>= 2 or def
.paramtype2
~= "wallmounted" then
155 below
= {x
=pos
.x
,y
=pos
.y
-i
,z
=pos
.z
}
156 local node
= minetest
.get_node(below
)
157 if node
.name
== "air" then
158 set_node_protected(below
, {name
=nname
, param2
=param2
}, name
)
160 elseif node
.name
~= nname
then
165 elseif nname
== "hades_core:dirt" or minetest
.get_item_group(nname
, "dirt_with_grass") > 1 or nname
== "hades_core:stone" or nname
== "hades_core:tuff" or nname
== "hades_core:cobble" or nname
== "hades_walls:cobble" then
166 -- Grow grass cover on dirt
167 -- [SUPER] also grow moss
170 local dwg2
= minetest
.get_item_group(nname
, "dirt_with_grass")
171 local d2
= minetest
.get_item_group(nname
, "dirt")
175 if d2
== 0 and dwg2
== 0 then
180 local season_color
= hades_core
.get_seasonal_grass_color_param2()
181 for x
= pos
.x
- minmax
, pos
.x
+ minmax
do
182 for y
= pos
.y
, pos
.y
do
183 for z
= pos
.z
- minmax
, pos
.z
+ minmax
do
184 local ppos
= {x
= x
, y
= y
, z
= z
}
185 if vector
.distance(pos
, ppos
) <= 2.3 then
186 local node
= minetest
.get_node(ppos
)
187 local above_node
= minetest
.get_node({x
= x
, y
= y
+ 1, z
= z
})
188 -- Apply change to same or "compatible" node type as the pointed
189 -- node only, e.g. dirt is "compatible" with dirt-with-grass
190 local d1
= minetest
.get_item_group(node
.name
, "dirt")
191 local dwg1
= minetest
.get_item_group(node
.name
, "dirt_with_grass")
192 if ((node
.name
== nname
) or ((dwg1
> 1 or d1
> 0) and (dwg2
> 1 or d2
> 0))) and
193 (nname
~= "hades_core:dirt" or
194 (minetest
.registered_nodes
[above_node
.name
] and
195 minetest
.registered_nodes
[above_node
.name
].walkable
== false)) then
196 if nname
== "hades_core:dirt" then
197 node
.name
= "hades_core:dirt_with_grass"
198 node
.param2
= season_color
200 node
.name
= "hades_core:dirt_with_grass"
201 node
.param2
= season_color
202 elseif nname
== "hades_core:stone" then
203 node
.name
= "hades_core:mossystone"
204 elseif nname
== "hades_core:tuff" then
205 node
.name
= "hades_core:mossytuff"
206 elseif nname
== "hades_core:cobble" then
207 node
.name
= "hades_core:mossycobble"
208 elseif nname
== "hades_walls:cobble" then
209 node
.name
= "hades_walls:mossycobble"
211 set_node_protected(ppos
, node
, name
)
217 elseif nname
== "hades_grass:grass" or nname
== "hades_core:dirt_with_grass" or nname
== "hades_core:fertile_sand" or nname
== "hades_core:ash" or nname
== "hades_core:volcanic_sand" or nname
== "hades_core:gravel" or nname
== "hades_core:gravel_volcanic" or nname
== "hades_farming:soil" or nname
== "hades_farming:soil_wet" then
218 -- Grow grass, flowers and other random plants
219 for x
= pos
.x
- 2, pos
.x
+ 2 do
220 for y
= pos
.y
, pos
.y
do
221 for z
= pos
.z
- 2, pos
.z
+ 2 do
222 local ppos
= {x
= x
, y
= y
, z
= z
}
223 if vector
.distance(pos
, ppos
) <= 2.3 then
224 local node
= minetest
.get_node(ppos
)
225 local pos_above
= {x
= x
, y
= y
+ 1, z
= z
}
226 local above_node
= minetest
.get_node(pos_above
)
227 if above_node
.name
== "air" and math
.random() < 0.2 and node
.name
== nname
then
229 local p2season
= hades_core
.get_seasonal_grass_color_param2()
230 if (node
.name
== "hades_grass:grass" or node
.name
== "hades_core:dirt_with_grass") then
233 {"hades_grass:grass_1", p2season
},
234 {"hades_grass:grass_2", p2season
},
235 {"hades_grass:grass_3", p2season
},
236 {"hades_grass:grass_4", p2season
},
237 {"hades_grass:grass_5", p2season
},
238 {"hades_grass:grass_1", p2season
},
239 {"hades_grass:grass_2", p2season
},
240 {"hades_grass:grass_3", p2season
},
241 {"hades_grass:grass_4", p2season
},
242 {"hades_grass:grass_5", p2season
},
243 {"hades_grass:grass_1", p2season
},
244 {"hades_grass:grass_2", p2season
},
245 {"hades_grass:grass_3", p2season
},
246 {"hades_grass:grass_4", p2season
},
247 {"hades_grass:grass_5", p2season
},
248 {"hades_grass:grass_1", p2season
},
249 {"hades_grass:grass_2", p2season
},
250 {"hades_grass:grass_3", p2season
},
251 {"hades_grass:grass_4", p2season
},
252 {"hades_grass:grass_5", p2season
},
253 {"hades_grass:junglegrass"},
254 {"hades_grass:junglegrass"},
255 {"hades_grass:junglegrass"},
256 {"hades_grass:junglegrass"},
257 {"hades_flowers:flowergrass"},
258 {"hades_flowers:red"},
259 {"hades_flowers:white"},
260 {"hades_flowers:yellow"},
261 {"hades_flowers:orange"},
262 {"hades_flowers:violet"},
263 {"hades_flowers:blue"},
267 {"hades_grass:grass_1", p2season
},
268 {"hades_grass:grass_2", p2season
},
269 {"hades_grass:grass_3", p2season
},
270 {"hades_grass:grass_4", p2season
},
271 {"hades_grass:grass_5", p2season
},
274 elseif (node
.name
== "hades_core:ash" or node
.name
== "hades_core:volcanic_sand" or node
.name
== "hades_core:gravel_volcanic") then
275 if not super
then return itemstack
end
277 { "hades_bushes:branch_bush"},
279 elseif (node
.name
== "hades_core:fertile_sand" or node
.name
== "hade_core:gravel") then
280 if not super
then return itemstack
end
282 { "hades_bushes:branch_bush"},
283 { "hades_grass:grass_1", p2season
},
285 elseif (node
.name
== "hades_farming:soil" or node
.name
== "hades_farming:soil_wet") then
286 if not super
then return itemstack
end
288 {"hades_farming:seed_wheat"},
289 {"hades_farming:seed_cotton"},
290 {"hades_farming:seed_tomato"},
291 {"hades_farming:seed_strawberry"},
292 {"hades_farming:seed_spice"},
293 {"hades_farming:seed_potato"},
297 local rnd
= math
.random(1, #plants
)
298 local plant
= plants
[rnd
][1]
299 local pdef
= minetest
.registered_nodes
[plant
]
301 if plants
[rnd
][2] then
304 p2
= pdef
.place_param2
306 local nnode
= {name
= plant
, param2
= p2
}
307 set_node_protected(pos_above
, nnode
, name
)
314 elseif minetest
.get_item_group(nname
, "waterlily") ~= 0 or minetest
.get_item_group(nname
, "seaweed") ~= 0 then
315 if not super
then return itemstack
end
316 -- [SUPER] Spread waterlilies and seaweed on water
317 for x
= pos
.x
- 3, pos
.x
+ 3 do
318 for y
= pos
.y
, pos
.y
do
319 for z
= pos
.z
- 3, pos
.z
+ 3 do
320 local ppos
= {x
= x
, y
= y
, z
= z
}
321 if vector
.distance(pos
, ppos
) <= 3.0 then
322 local node
= minetest
.get_node(ppos
)
323 local below_node
= minetest
.get_node({x
= x
, y
= y
- 1, z
= z
})
324 if node
.name
== "air" and
325 math
.random() < 0.1 and
326 minetest
.get_item_group(below_node
.name
, "water") >= 1 and
327 minetest
.registered_nodes
[below_node
.name
].liquidtype
== "source" then
329 node
.param2
= math
.random(0,3)
330 set_node_protected(ppos
, node
, name
)
338 if not super
and not minetest
.is_creative_enabled(placer
:get_player_name()) then
339 itemstack
:take_item()
345 -- Fertilizer helps grow a few plants
346 minetest
.register_craftitem("hades_fertilizer:fertilizer", {
347 description
= S("Fertilizer"),
348 _tt_help
= S("Makes plants grow"),
349 inventory_image
= "hades_fertilizer_fertilizer.png",
350 on_place
= get_apply_fertilizer(false),
351 groups
= { tool
= 1 },
354 -- Super Fertilizer makes almost everything grow; only for Creative Mode
355 minetest
.register_craftitem("hades_fertilizer:super_fertilizer", {
356 description
= S("Super Fertilizer"),
357 _tt_help
= S("Makes a lot of plants grow"),
358 inventory_image
= "hades_fertilizer_super_fertilizer.png",
359 on_place
= get_apply_fertilizer(true),
360 groups
= { tool
= 1 },