Why sometimes is ":" in front of modname at register_node?

User avatar
Drachenbauer32
Member
 
Posts: 96
Joined: Wed Aug 28, 2019 18:11

Why sometimes is ":" in front of modname at register_node?

by Drachenbauer32 » Mon Oct 28, 2019 17:46

Hello

In the stairs-mod i found this:
Code: Select all
minetest.register_node(":stairs:slab_" .. subname, {
        description = description .. " Slab",
        drawtype = "nodebox",
        tiles = slab_images,
        paramtype = "light",
        paramtype2 = "facedir",
        is_ground_content = false,
        groups = new_groups,
        sounds = sounds,
        node_box = {
            type = "fixed",
            fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 },
        },
        on_place = function(itemstack, placer, pointed_thing)
            local under = minetest.get_node(pointed_thing.under)
            local wield_item = itemstack:get_name()
            local player_name = placer and placer:get_player_name() or ""
            local creative_enabled = (creative and creative.is_enabled_for
                    and creative.is_enabled_for(player_name))

            if under and under.name:find("^stairs:slab_") then
                -- place slab using under node orientation
                local dir = minetest.dir_to_facedir(vector.subtract(pointed_thing.above, pointed_thing.under), true)

                local p2 = under.param2

                -- Placing a slab on an upside down slab should make it right-side up.
                if p2 >= 20 and dir == 8 then
                    p2 = p2 - 20
                    -- same for the opposite case: slab below normal slab
                elseif p2 <= 3 and dir == 4 then
                    p2 = p2 + 20
                end

                -- else attempt to place node with proper param2
                minetest.item_place_node(ItemStack(wield_item), placer, pointed_thing, p2)
                if not creative_enabled then
                    itemstack:take_item()
                end
                return itemstack
            else
                return rotate_and_place(itemstack, placer, pointed_thing)
            end
        end,
    })


Now i wonder, that there is a ":" in front of the modname in the nodename in the first line of this code-snippet.

What is the reason for this?
 

User avatar
rubenwardy
Moderator
 
Posts: 5859
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Why sometimes is ":" in front of modname at register_nod

by rubenwardy » Mon Oct 28, 2019 18:32

This is called the override character. It's used to disable the name checks, allowing you to replace the definition of existing items or create an item which isn't in your namespace. It's used in the stairs mod to low other mods to create items in the stairs namespace via the API call - this is actually bad practice, stairs should be designed to register them in the namespace they are called from not the stairs namespace

By item namespace, I'm referring to the modname before the normal colon. For example, default:dirt is in the default item namespace
 

User avatar
Drachenbauer32
Member
 
Posts: 96
Joined: Wed Aug 28, 2019 18:11

Re: Why sometimes is ":" in front of modname at register_nod

by Drachenbauer32 » Mon Oct 28, 2019 20:57

actually now i used it in a noncubic mod to add such shapes from my own custom materials and call the function from my own material mod.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 4 guests