1 local on_place
= mcl_util
.generate_on_place_plant_function(function(place_pos
, place_node
)
2 local soil_node
= minetest
.get_node_or_nil({x
=place_pos
.x
, y
=place_pos
.y
-1, z
=place_pos
.z
})
3 if not soil_node
then return false end
4 local snn
= soil_node
.name
-- soil node name
5 local sd
= minetest
.registered_nodes
[snn
] -- soil definition
8 -- * Always allowed on podzol or mycelimu
9 -- * Otherwise, must be solid, opaque and have daylight light level <= 12
10 local light
= minetest
.get_node_light(place_pos
, 0.5)
11 local light_ok
= false
12 if light
and light
<= 12 then
15 return ((snn
== "mcl_core:podzol" or snn
== "mcl_core:podzol_snow" or snn
== "mcl_core:mycelium" or snn
== "mcl_core:mycelium_snow") or (light_ok
and minetest
.get_item_group(snn
, "solid") == 1 and minetest
.get_item_group(snn
, "opaque") == 1))
18 local longdesc_intro_brown
= [[Brown mushrooms are fungi which grow and spread in darkness, but are sensitive to light. They are inedible as such, but they can be used to craft food items.]]
19 local longdesc_intro_red
= [[Red mushrooms are fungi which grow and spread in darkness, but are sensitive to light. They are inedible as such, but they can be used to craft food items.]]
21 local longdesc_append
= [[A single mushroom of this species will slowly spread over time towards a random solid opaque block with a light level of 12 or lower in a 3×3×3 cube around the mushroom. It stops spreading when there are 5 or more mushrooms of the same species within an area of 9×3×9 blocks around the mushroom.
22 Mushrooms will eventually uproot at a light level of 12 or higher. On mycelium or podzol, they survive and spread at any light level.]]
24 local usagehelp
= "This mushroom can be placed on mycelium and podzol at any light level. They can also be placed on blocks which are both solid and opaque, as long as the light level at daytime is not higher than 12."
26 minetest
.register_node("mcl_mushrooms:mushroom_brown", {
27 description
= "Brown Mushroom",
28 _doc_items_longdesc
= longdesc_intro_brown
.. "\n\n" .. longdesc_append
,
29 _doc_items_usagehelp
= usagehelp
,
30 drawtype
= "plantlike",
31 tiles
= { "farming_mushroom_brown.png" },
32 inventory_image
= "farming_mushroom_brown.png",
33 wield_image
= "farming_mushroom_brown.png",
34 sunlight_propagates
= true,
37 groups
= {dig_immediate
=3,mushroom
=1,attached_node
=1,dig_by_water
=1,destroy_by_lava_flow
=1,dig_by_piston
=1,enderman_takable
=1,deco_block
=1},
38 sounds
= mcl_sounds
.node_sound_leaves_defaults(),
42 fixed
= { -3/16, -0.5, -3/16, 3/16, -2/16, 3/16 },
44 node_placement_prediction
= "",
46 _mcl_blast_resistance
= 0,
49 minetest
.register_node("mcl_mushrooms:mushroom_red", {
50 description
= "Red Mushroom",
51 _doc_items_longdesc
= longdesc_intro_red
.. "\n\n" .. longdesc_append
,
52 _doc_items_usagehelp
= usagehelp
,
53 drawtype
= "plantlike",
54 tiles
= { "farming_mushroom_red.png" },
55 inventory_image
= "farming_mushroom_red.png",
56 wield_image
= "farming_mushroom_red.png",
57 sunlight_propagates
= true,
60 groups
= {dig_immediate
=3,mushroom
=1,attached_node
=1,dig_by_water
=1,destroy_by_lava_flow
=1,dig_by_piston
=1,enderman_takable
=1,deco_block
=1},
61 sounds
= mcl_sounds
.node_sound_leaves_defaults(),
64 fixed
= { -3/16, -0.5, -3/16, 3/16, -2/16, 3/16 },
66 node_placement_prediction
= "",
68 _mcl_blast_resistance
= 0,
71 minetest
.register_craftitem("mcl_mushrooms:mushroom_stew", {
72 description
= "Mushroom Stew",
73 _doc_items_longdesc
= "Mushroom stew is a healthy soup which can be consumed to restore some hunger points.",
74 inventory_image
= "farming_mushroom_stew.png",
75 on_place
= minetest
.item_eat(6, "mcl_core:bowl"),
76 on_secondary_use
= minetest
.item_eat(6, "mcl_core:bowl"),
77 groups
= { food
= 3, eatable
= 6 },
78 _mcl_saturation
= 7.2,
82 minetest
.register_craft({
84 output
= "mcl_mushrooms:mushroom_stew",
85 recipe
= {'mcl_core:bowl', 'mcl_mushrooms:mushroom_brown', 'mcl_mushrooms:mushroom_red'}
88 --[[ Mushroom spread and death
89 Code based on information gathered from Minecraft Wiki
90 <http://minecraft.gamepedia.com/Tutorials/Mushroom_farming#Videos>
92 minetest
.register_abm({
93 label
= "Mushroom spread and death",
94 nodenames
= {"mcl_mushrooms:mushroom_brown", "mcl_mushrooms:mushroom_red"},
97 action
= function(pos
, node
)
98 local node_soil
= minetest
.get_node({x
=pos
.x
, y
=pos
.y
-1, z
=pos
.z
}).name
99 -- Mushrooms uproot in light except on podzol or mycelium
100 if node_soil
~= "mcl_core:podzol" and node_soil
~= "mcl_core:mycelium" and
101 node_soil
~= "mcl_core:podzol_snow" and node_soil
~= "mcl_core:mycelium_snow" and minetest
.get_node_light(pos
, nil) > 12 then
102 minetest
.dig_node(pos
)
106 local pos0
= vector
.add(pos
, {x
=-4, y
=-1, z
=-4})
107 local pos1
= vector
.add(pos
, {x
=4, y
=1, z
=4})
109 -- Stop mushroom spread if a 9×3×9 box is too crowded
110 if #minetest
.find_nodes_in_area(pos0
, pos1
, node
.name
) >= 5 then
114 local selected_pos
= table.copy(pos
)
116 -- Do two random selections which may place the new mushroom in a 5×5×5 cube
118 x
= selected_pos
.x
+ math
.random(-1, 1),
119 y
= selected_pos
.y
+ math
.random(0, 1) - math
.random(0, 1),
120 z
= selected_pos
.z
+ math
.random(-1, 1)
122 local random_node
= minetest
.get_node_or_nil(random)
123 if not random_node
or random_node
.name
~= "air" then
126 local node_under
= minetest
.get_node_or_nil({x
= random.x
, y
= random.y
- 1, z
= random.z
})
127 if not node_under
then
131 if minetest
.get_node_light(random, 0.5) > 12 or (minetest
.get_item_group(node_under
.name
, "opaque") == 0) then
135 x
= random.x
+ math
.random(-1, 1),
137 z
= random.z
+ math
.random(-1, 1)
139 random_node
= minetest
.get_node_or_nil(random2
)
140 if not random_node
or random_node
.name
~= "air" then
143 node_under
= minetest
.get_node_or_nil({x
= random2
.x
, y
= random2
.y
- 1, z
= random2
.z
})
144 if not node_under
then
147 if minetest
.get_node_light(random2
, 0.5) > 12 or (minetest
.get_item_group(node_under
.name
, "opaque") == 0) or (minetest
.get_item_group(node_under
.name
, "solid") == 0) then
151 minetest
.set_node(random2
, {name
= node
.name
})