local S = core.get_translator(core.get_current_modname());
local dp = natural_habitat.dupes;

local function eat(itemstack, user, pointed_thing)
    return core.do_item_eat(2, nil, itemstack, user, pointed_thing);
end;

core.register_node("natural_habitat:mushroom_glow", {
    description = S("Glow Mushroom"),
    inventory_image = "nbt_glow_mushroom_inv.png",
    drawtype = "mesh",
    mesh = "nbt_glow_mushroom.obj",
    tiles = {"nbt_glow_mushroom.png"},
    paramtype = "light",
    paramtype2 = "facedir",
    groups = m7a.impact(
        { mushroom=1, food_mushroom=1, snappy=1, attached_node=1, flammable=1 }, {
            ["mineclonia"] = {
                handy=1, food=2, eatable=2, attached_node=1, deco_block=1, 
                destroy_by_lava_flow=1, dig_by_water=1, dig_by_piston=1, 
                unsticky=1, mushroom=1, enderman_takable=1, compostability=65,
            },
        }
    ),
    sunlight_propagates = true,
    walkable = false,
    light_source = 7,
    sounds = natural_habitat.sound_leaves(),
    selection_box = {
        type = "fixed",
        fixed = { -0.4, -0.5, -0.4, 0.4, 0.3, 0.4 },
    },
    rotation = "random",
    on_use = m7a.impact(nil, { ["minetest"] = eat, ["asuna"] = eat, }),
    on_place = function(itemstack, placer, pointed_thing)
        if (not pointed_thing.under) and (m7a.get_game_info().id == "mineclonia") then
            return core.do_item_eat(2, nil, itemstack, placer, pointed_thing);
        end
        
        return m7a.place_item(itemstack, placer, pointed_thing).itemstack;
    end;
    
    _mcl_hardness = 0;
    _mcl_saturation = 1.2;
});

local y_mix = m7a.impact(-31000, { ["mineclonia"] = -130 }); 

core.register_decoration({
    deco_type = "simple",
    decoration = "natural_habitat:mushroom_glow",
    place_on = { dp.mossycobble, dp.cobble, dp.stone, dp.stone_deep },
    fill_ratio = 0.002,
    biomes = {},
    spawn_by = "air",
    num_spawn_by = 1,
    flags = "all_floors",
    y_max = 0,
    y_min = y_mix/2,
    rotation = "random",
});

core.register_decoration({
    deco_type = "simple",
    decoration = "natural_habitat:mushroom_glow",
    place_on = { dp.mossycobble, dp.cobble, dp.stone, dp.stone_deep },
    fill_ratio = 0.005,
    biomes = {},
    spawn_by = "air",
    num_spawn_by = 1,
    flags = "all_floors",
    y_max = y_mix/2,
    y_min = y_mix,
    rotation = "random",
});