2021-05-29 16:12:33 +02:00
local S = minetest.get_translator ( minetest.get_current_modname ( ) )
2019-03-08 00:22:28 +01:00
2022-04-30 05:48:00 +02:00
local modpath = minetest.get_modpath ( minetest.get_current_modname ( ) )
local schempath = modpath .. " /schematics/ "
2017-06-09 20:50:25 +02:00
local on_place = mcl_util.generate_on_place_plant_function ( function ( place_pos , place_node )
local soil_node = minetest.get_node_or_nil ( { x = place_pos.x , y = place_pos.y - 1 , z = place_pos.z } )
if not soil_node then return false end
local snn = soil_node.name -- soil node name
2017-03-31 19:30:18 +02:00
-- Placement rules:
-- * Always allowed on podzol or mycelimu
-- * Otherwise, must be solid, opaque and have daylight light level <= 12
2017-03-31 20:02:50 +02:00
local light = minetest.get_node_light ( place_pos , 0.5 )
2017-03-31 19:30:18 +02:00
local light_ok = false
if light and light <= 12 then
light_ok = true
end
2017-06-09 20:50:25 +02:00
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 ) )
end )
2017-03-31 19:30:18 +02:00
2022-04-30 05:48:00 +02:00
-- Try to grow huge mushroom
local function apply_bonemeal ( pos , schematic , offset )
-- Must be on a dirt-type block
local below = minetest.get_node ( vector.offset ( pos , 0 , - 1 , 0 ) )
if minetest.get_item_group ( below.name , " grass_block " ) ~= 1
and below.name ~= " mcl_core:mycelium "
and below.name ~= " mcl_core:dirt "
and below.name ~= " mcl_core:coarse_dirt "
and below.name ~= " mcl_core:podzol " then
return false
end
-- 40% chance
if math.random ( 1 , 100 ) <= 40 then
-- Check space requirements
for i = 1 , 3 do
local cpos = vector.offset ( pos , 0 , i , 0 )
if minetest.get_node ( cpos ) . name ~= " air " then
return false
end
end
local minp = vector.offset ( pos , - 3 , 3 , - 3 )
local maxp = vector.offset ( pos , 3 , 8 , 3 )
local diff = maxp - minp
local goodnodes = minetest.find_nodes_in_area ( minp , maxp , { " air " , " group:leaves " } )
if # goodnodes < ( diff.x + 1 ) * ( diff.y + 1 ) * ( diff.z + 1 ) then
return false
end
-- Place the huge mushroom
minetest.remove_node ( pos )
return minetest.place_schematic ( pos + offset , schematic , 0 , nil , false )
end
return false
end
2019-03-08 00:22:28 +01:00
local longdesc_intro_brown = S ( " 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. " )
local longdesc_intro_red = S ( " 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. " )
2017-04-01 01:23:55 +02:00
2019-03-08 00:22:28 +01:00
local longdesc_append = S ( " 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. " ) .. " \n " ..
S ( " Mushrooms will eventually uproot at a light level of 12 or higher. On mycelium or podzol, they survive and spread at any light level. " )
2017-04-01 01:23:55 +02:00
2020-02-19 04:54:17 +01:00
local tt_help = S ( " Grows on podzol, mycelium and other blocks " ) .. " \n " .. S ( " Spreads in darkness " )
2019-03-15 09:50:32 +01:00
local usagehelp = S ( " This mushroom can be placed on mycelium and podzol at any light level. It 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. " )
2017-04-01 01:23:55 +02:00
2017-03-01 01:16:52 +01:00
minetest.register_node ( " mcl_mushrooms:mushroom_brown " , {
2019-03-08 00:22:28 +01:00
description = S ( " Brown Mushroom " ) ,
2017-05-24 23:11:14 +02:00
_doc_items_longdesc = longdesc_intro_brown .. " \n \n " .. longdesc_append ,
2017-04-01 01:23:55 +02:00
_doc_items_usagehelp = usagehelp ,
2020-02-19 04:54:17 +01:00
_tt_help = tt_help ,
2015-06-29 19:55:56 +02:00
drawtype = " plantlike " ,
tiles = { " farming_mushroom_brown.png " } ,
inventory_image = " farming_mushroom_brown.png " ,
wield_image = " farming_mushroom_brown.png " ,
sunlight_propagates = true ,
paramtype = " light " ,
walkable = false ,
Add `compostability` to node definition group.
* mcl_cake/init.lua (cake);
* mcl_core/craftitems.lua (apple);
* mcl_core/nodes_base.lua (dirt with grass);
* mcl_core/nodes_cactuscane.lua (cactus, sugarcane);
* mcl_core/nodes_climb.lua (vines);
* mcl_core/nodes_trees.lua (leaves, saplings);
* mcl_dye/init.lua (cocoa beans);
* mcl_farming/beetroot.lua (beetroot, & seeds);
* mcl_farming/carrots.lua (carrot);
* mcl_farming/melon.lua (melon, & slice, & seeds);
* mcl_farming/potatoes.lua (potato, baked potato);
* mcl_farming/pumpkin.lua (pumpkin, carved &, & seeds, & pie);
* mcl_farming/wheat.lua (wheat, cookie, bread, hay block);
* mcl_flowers/init.lua (flowers, ferns, grass, & tall variants);
* mcl_mushrooms/small.lua (red and brown mushrooms);
* mcl_mushrooms/huge.lua (red and brown huge mushrooms);
* mcl_nether/init.lua (nether wart block);
* mcl_nether/nether_wart.lua (nether wart);
* mcl_ocean/kelp.lua (kelp, dried &, & block);
* mcl_ocean/sea_pickle.lua (sea pickle);
* mcl_ocean/seagrass.lua (seagrass).
2022-03-29 12:54:51 +02:00
groups = {
attached_node = 1 , deco_block = 1 , destroy_by_lava_flow = 1 ,
dig_immediate = 3 , dig_by_water = 1 , dig_by_piston = 1 ,
mushroom = 1 , enderman_takable = 1 , compostability = 65
} ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_leaves_defaults ( ) ,
2017-01-04 10:11:35 +01:00
light_source = 1 ,
2015-06-29 19:55:56 +02:00
selection_box = {
type = " fixed " ,
2017-03-31 19:44:10 +02:00
fixed = { - 3 / 16 , - 0.5 , - 3 / 16 , 3 / 16 , - 2 / 16 , 3 / 16 } ,
2015-06-29 19:55:56 +02:00
} ,
2017-03-31 19:30:18 +02:00
node_placement_prediction = " " ,
on_place = on_place ,
2022-04-30 05:48:00 +02:00
_mcl_on_bonemealing = function ( pointed_thing , placer )
local schematic = schempath .. " mcl_mushrooms_huge_brown.mts "
local offset = vector.new ( - 3 , - 1 , - 3 )
return apply_bonemeal ( pointed_thing.under , schematic , offset )
end ,
2017-02-22 16:03:59 +01:00
_mcl_blast_resistance = 0 ,
2015-06-29 19:55:56 +02:00
} )
2017-03-01 01:16:52 +01:00
minetest.register_node ( " mcl_mushrooms:mushroom_red " , {
2019-03-08 00:22:28 +01:00
description = S ( " Red Mushroom " ) ,
2017-05-24 23:24:03 +02:00
_doc_items_longdesc = longdesc_intro_red .. " \n \n " .. longdesc_append ,
2017-04-01 01:23:55 +02:00
_doc_items_usagehelp = usagehelp ,
2020-02-19 04:54:17 +01:00
_tt_help = tt_help ,
2015-06-29 19:55:56 +02:00
drawtype = " plantlike " ,
tiles = { " farming_mushroom_red.png " } ,
inventory_image = " farming_mushroom_red.png " ,
wield_image = " farming_mushroom_red.png " ,
sunlight_propagates = true ,
paramtype = " light " ,
walkable = false ,
Add `compostability` to node definition group.
* mcl_cake/init.lua (cake);
* mcl_core/craftitems.lua (apple);
* mcl_core/nodes_base.lua (dirt with grass);
* mcl_core/nodes_cactuscane.lua (cactus, sugarcane);
* mcl_core/nodes_climb.lua (vines);
* mcl_core/nodes_trees.lua (leaves, saplings);
* mcl_dye/init.lua (cocoa beans);
* mcl_farming/beetroot.lua (beetroot, & seeds);
* mcl_farming/carrots.lua (carrot);
* mcl_farming/melon.lua (melon, & slice, & seeds);
* mcl_farming/potatoes.lua (potato, baked potato);
* mcl_farming/pumpkin.lua (pumpkin, carved &, & seeds, & pie);
* mcl_farming/wheat.lua (wheat, cookie, bread, hay block);
* mcl_flowers/init.lua (flowers, ferns, grass, & tall variants);
* mcl_mushrooms/small.lua (red and brown mushrooms);
* mcl_mushrooms/huge.lua (red and brown huge mushrooms);
* mcl_nether/init.lua (nether wart block);
* mcl_nether/nether_wart.lua (nether wart);
* mcl_ocean/kelp.lua (kelp, dried &, & block);
* mcl_ocean/sea_pickle.lua (sea pickle);
* mcl_ocean/seagrass.lua (seagrass).
2022-03-29 12:54:51 +02:00
groups = {
attached_node = 1 , deco_block = 1 , destroy_by_lava_flow = 1 ,
dig_immediate = 3 , dig_by_water = 1 , dig_by_piston = 1 ,
mushroom = 1 , enderman_takable = 1 , compostability = 65
} ,
2017-02-11 18:46:23 +01:00
sounds = mcl_sounds.node_sound_leaves_defaults ( ) ,
2015-06-29 19:55:56 +02:00
selection_box = {
type = " fixed " ,
2017-03-31 19:44:10 +02:00
fixed = { - 3 / 16 , - 0.5 , - 3 / 16 , 3 / 16 , - 2 / 16 , 3 / 16 } ,
2015-06-29 19:55:56 +02:00
} ,
2017-03-31 19:30:18 +02:00
node_placement_prediction = " " ,
on_place = on_place ,
2022-04-30 05:48:00 +02:00
_mcl_on_bonemealing = function ( pointed_thing , placer )
local schematic = schempath .. " mcl_mushrooms_huge_red.mts "
local offset = vector.new ( - 2 , - 1 , - 2 )
return apply_bonemeal ( pointed_thing.under , schematic , offset )
end ,
2017-02-22 16:03:59 +01:00
_mcl_blast_resistance = 0 ,
2015-06-29 19:55:56 +02:00
} )
2017-03-01 01:16:52 +01:00
minetest.register_craftitem ( " mcl_mushrooms:mushroom_stew " , {
2019-03-08 00:22:28 +01:00
description = S ( " Mushroom Stew " ) ,
_doc_items_longdesc = S ( " Mushroom stew is a healthy soup which can be consumed to restore some hunger points. " ) ,
2017-01-20 18:38:12 +01:00
inventory_image = " farming_mushroom_stew.png " ,
2017-02-16 17:45:33 +01:00
on_place = minetest.item_eat ( 6 , " mcl_core:bowl " ) ,
on_secondary_use = minetest.item_eat ( 6 , " mcl_core:bowl " ) ,
2017-02-16 15:08:26 +01:00
groups = { food = 3 , eatable = 6 } ,
2017-05-21 03:26:51 +02:00
_mcl_saturation = 7.2 ,
2017-01-16 23:34:40 +01:00
stack_max = 1 ,
2015-06-29 19:55:56 +02:00
} )
minetest.register_craft ( {
type = " shapeless " ,
2017-03-01 01:16:52 +01:00
output = " mcl_mushrooms:mushroom_stew " ,
2021-05-29 16:12:33 +02:00
recipe = { " mcl_core:bowl " , " mcl_mushrooms:mushroom_brown " , " mcl_mushrooms:mushroom_red " }
2017-01-04 10:11:35 +01:00
} )
2017-03-01 01:16:52 +01:00
2017-04-01 00:55:48 +02:00
--[[ Mushroom spread and death
Code based on information gathered from Minecraft Wiki
< http : // minecraft.gamepedia . com / Tutorials / Mushroom_farming # Videos >
] ]
minetest.register_abm ( {
2017-09-05 04:03:23 +02:00
label = " Mushroom spread and death " ,
2017-04-01 00:55:48 +02:00
nodenames = { " mcl_mushrooms:mushroom_brown " , " mcl_mushrooms:mushroom_red " } ,
interval = 11 ,
chance = 50 ,
action = function ( pos , node )
2017-09-05 04:03:23 +02:00
local node_soil = minetest.get_node ( { x = pos.x , y = pos.y - 1 , z = pos.z } ) . name
-- Mushrooms uproot in light except on podzol or mycelium
if node_soil ~= " mcl_core:podzol " and node_soil ~= " mcl_core:mycelium " and
node_soil ~= " mcl_core:podzol_snow " and node_soil ~= " mcl_core:mycelium_snow " and minetest.get_node_light ( pos , nil ) > 12 then
2017-04-01 01:04:53 +02:00
minetest.dig_node ( pos )
2017-04-01 00:55:48 +02:00
return
end
local pos0 = vector.add ( pos , { x =- 4 , y =- 1 , z =- 4 } )
local pos1 = vector.add ( pos , { x = 4 , y = 1 , z = 4 } )
-- Stop mushroom spread if a 9× 3× 9 box is too crowded
if # minetest.find_nodes_in_area ( pos0 , pos1 , node.name ) >= 5 then
return
end
local selected_pos = table.copy ( pos )
-- Do two random selections which may place the new mushroom in a 5× 5× 5 cube
local random = {
x = selected_pos.x + math.random ( - 1 , 1 ) ,
y = selected_pos.y + math.random ( 0 , 1 ) - math.random ( 0 , 1 ) ,
z = selected_pos.z + math.random ( - 1 , 1 )
}
local random_node = minetest.get_node_or_nil ( random )
if not random_node or random_node.name ~= " air " then
return
end
local node_under = minetest.get_node_or_nil ( { x = random.x , y = random.y - 1 , z = random.z } )
if not node_under then
return
end
2017-03-01 01:16:52 +01:00
2017-04-01 00:55:48 +02:00
if minetest.get_node_light ( random , 0.5 ) > 12 or ( minetest.get_item_group ( node_under.name , " opaque " ) == 0 ) then
return
end
local random2 = {
x = random.x + math.random ( - 1 , 1 ) ,
y = random.y ,
z = random.z + math.random ( - 1 , 1 )
}
random_node = minetest.get_node_or_nil ( random2 )
if not random_node or random_node.name ~= " air " then
return
end
node_under = minetest.get_node_or_nil ( { x = random2.x , y = random2.y - 1 , z = random2.z } )
if not node_under then
return
end
2017-04-01 01:34:45 +02:00
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
2017-04-01 00:55:48 +02:00
return
end
minetest.set_node ( random2 , { name = node.name } )
end
} )