local node_box = {type = "fixed", fixed = {{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}}};

-- REGISTER BUSH
function natural_habitat.register_bush(id, data)

    for stage, def in pairs(data.stages) do
    
        if (m7a.get_game_info().id == "minetest") then
            data.color = stage.mts_color or data.mts_color;
        elseif (m7a.get_game_info().id == "mineclonia") then
            data.color = stage.mcl_color or data.mcl_color;
        end;
        
        core.register_node("natural_habitat:"..id.."_"..stage, {
            description = data.name.." "..def.description,
            drawtype = def.drawtype or data.drawtype or "mesh",
            waving = 2,
            mesh = def.mesh or data.mesh or "nbt_bush.obj",
            tiles = {
                {
                    name = def.textures[1] or "nbt_bush_leaves.png", 
                    color = def.color or data.color or "#FFFFFF",
                },
                {
                    name = def.textures[1] or "nbt_bush_leaves.png", 
                    color = def.color or data.color or "#FFFFFF",
                },
                def.textures[2] or "",
            },
            use_texture_alpha = "clip",
            drop = "",
            on_punch = function(pos, node, puncher, pointed_thing)
            
                m7a.particle_punch(pos, "nbt_particle_leaf.png", {
                    { 
                        name = "nbt_particle_leaf.png", 
                        animation = { type="vertical_frames", aspect_w=5, aspect_h=5, length=1.3 },
                    }
                }, 1.5);
                
                if (m7a.get_game_info().is == "minetest") then
                    if (core.get_item_group(puncher:get_wielded_item():get_name(), "sword") > 0) then
                        for i = 0, math.random(3) do
                            core.add_item( vector.add(
                                pos, vector.new(math.random()-0.5, 0, math.random()-0.5)
                                ), ItemStack(def.drop or dp.stick)
                            );
                            core.set_node(pos, { name="air" });
                        end;
                    end;
                end;
            end,
            after_dig_node = function(pos, oldnode, oldmetadata, digger)
                local dig_item = "natural_habitat:"..id.."_"..stage;
                
                if (core.get_item_group(digger:get_wielded_item():get_name(), "sword") > 0) then
                    for i = 0, math.random(5) do
                        core.add_item( vector.add(
                            pos, vector.new(math.random()-0.5, 0, math.random()-0.5)
                            ), ItemStack(def.drop or dp.stick)
                        );
                    end;
                else
                    if (m7a.get_game_info().is == "minetest") then
                        m7a.add_item_to_inventory(digger, dig_item);
                    elseif (m7a.get_game_info().is == "mineclonia") then
                        core.add_item( vector.add(
                            pos, vector.new(math.random()-0.5, 0, math.random()-0.5)
                            ), ItemStack(dig_item)
                        );
                    end;
                end;
            end,
            paramtype = def.paramtype or data.paramtype or "light",
            paramtype2 = def.paramtype2 or data.paramtype2 or "facedir",
            walkable = def.walkable or data.walkable or true,
            buildable_to =  def.buildable_to or data.buildable_to or false,
            groups = def.groups or data.groups or m7a.impact(
                { bush=1, snappy=3, flammable=2, leaves=1, blossoming=1, },
                {
                    ["mineclonia"] = {
                        bush=1, handy=1, swordy=1, dig_by_piston=1, deco_block=1, 
                        flammable=2, fire_encouragement=30, fire_flammability=60,
                        compostability=50, unsticky=1, blossoming=1, leaves=3,
                    }
                }
            ),
            node_box = def.node_box or data.node_box or node_box,
            selection_box = def.node_box or data.node_box or node_box,
            on_place = function(itemstack, placer, pointed_thing)
                return m7a.place_item(itemstack, placer, pointed_thing).itemstack;
            end,
            sounds = natural_habitat.sound_leaves(),
            
            _mcl_hardness = 0.2,
        });
    end;
end;