Page 1 of 1

mods in /usr/share/ override mods in ~/

PostPosted: Sun Sep 09, 2012 04:37
by LlubNek
mods in /usr/share/minetest/games/minetest_game/mods override mods in ~/.minetest/mods/minetest.

For example, if I have a mod named 'stairs' in ~/.minetest/mods/minetest/stairs/, my stairs mod will not run, but the default stairs mod in /usr/share/minetest/games/minetest_game/mods/stairs will.

could we get this changed so it checks the world directory first (~/.minetest/worlds/WORLDNAME/mods/), then the per user folder (~/.minetest/mods/minetest/), then the global folder (/usr/share/minetest/games/GAME/mods)?


Also, the stairs mod needs to use minetest.get_current_modname() in it's stairs.register_* functions in order to play nice with other mods.

code like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- add glass and desert stone stairs and slabs
stairs.register_stair_and_slab(
    "desert_stone",
    "default:desert_stone",
    {cracky=3},
    {"default_desert_stone.png"},
    "Desert Stone Stair",
    "Desert Stone Slab")

stairs.register_stair_and_slab(
    "glass",
    "default:glass",
    {snappy=2,cracky=3,oddly_breakable_by_hand=3},
    {"default_glass.png"},
    "Glass Stair",
    "Glass Slab")

in another mod gives errors like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
00:04:52: ERROR[main]: ========== ERROR FROM LUA ===========
00:04:52: ERROR[main]: Failed to load and run script from
00:04:52: ERROR[main]: /home/user/.minetest/mods/minetest/llubnek/init.lua:
00:04:52: ERROR[main]: /usr/share/minetest/builtin/misc_register.lua:62: Name stairs:stair_desert_stone does not follow naming conventions: "modname:" or ":" prefix required
00:04:52: ERROR[main]: stack traceback:
00:04:52: ERROR[main]:     [C]: in function 'error'
00:04:52: ERROR[main]:     /usr/share/minetest/builtin/misc_register.lua:62: in function 'check_modname_prefix'
00:04:52: ERROR[main]:     /usr/share/minetest/builtin/misc_register.lua:98: in function 'register_item'
00:04:52: ERROR[main]:     /usr/share/minetest/builtin/misc_register.lua:154: in function 'register_node'
00:04:52: ERROR[main]:     ...re/minetest/games/minetest_game/mods/stairs/init.lua:8: in function 'register_stair'
00:04:52: ERROR[main]:     ...re/minetest/games/minetest_game/mods/stairs/init.lua:114: in function 'register_stair_and_slab'
00:04:52: ERROR[main]:     ...ome/user/.minetest/mods/minetest/llubnek/init.lua:36: in main chunk
00:04:52: ERROR[main]: =======END OF ERROR FROM LUA ========


here's a modified init.lua that should fix this (maybe... see first bug for why this isn't tested):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Minetest 0.4 mod: stairs
-- See README.txt for licensing and other information.

stairs = {}

-- Node will be called stairs:stair_<subname>
function stairs.register_stair(subname, recipeitem, groups, images, description)
    minetest.register_node(minetest.get_current_modname()..":stair_" .. subname, {
        description = description,
        drawtype = "nodebox",
        tiles = images,
        paramtype = "light",
        paramtype2 = "facedir",
        is_ground_content = true,
        groups = groups,
        node_box = {
            type = "fixed",
            fixed = {
                {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
                {-0.5, 0, 0, 0.5, 0.5, 0.5},
            },
        },
    })

    minetest.register_craft({
        output = minetest.get_current_modname()..':stair_' .. subname .. ' 4',
        recipe = {
            {recipeitem, "", ""},
            {recipeitem, recipeitem, ""},
            {recipeitem, recipeitem, recipeitem},
        },
    })

    -- Flipped recipe for the silly minecrafters
    minetest.register_craft({
        output = minetest.get_current_modname()..':stair_' .. subname .. ' 4',
        recipe = {
            {"", "", recipeitem},
            {"", recipeitem, recipeitem},
            {recipeitem, recipeitem, recipeitem},
        },
    })
end

-- Node will be called stairs:slab_<subname>
function stairs.register_slab(subname, recipeitem, groups, images, description)
    minetest.register_node(minetest.get_current_modname()..":slab_" .. subname, {
        description = description,
        drawtype = "nodebox",
        tiles = images,
        paramtype = "light",
        is_ground_content = true,
        groups = groups,
        node_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
        selection_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
        on_place = function(itemstack, placer, pointed_thing)
            if pointed_thing.type ~= "node" then
                return itemstack
            end

            -- If it's being placed on an another similar one, replace it with
            -- a full block
            local slabpos = nil
            local slabnode = nil
            local p0 = pointed_thing.under
            local p1 = pointed_thing.above
            local n0 = minetest.env:get_node(p0)
            local n1 = minetest.env:get_node(p1)
            if n0.name == minetest.get_current_modname()..":slab_" .. subname then
                slabpos = p0
                slabnode = n0
            elseif n1.name == minetest.get_current_modname()..":slab_" .. subname then
                slabpos = p1
                slabnode = n1
            end
            if slabpos then
                -- Remove the slab at slabpos
                minetest.env:remove_node(slabpos)
                -- Make a fake stack of a single item and try to place it
                local fakestack = ItemStack(recipeitem)
                pointed_thing.above = slabpos
                fakestack = minetest.item_place(fakestack, placer, pointed_thing)
                -- If the item was taken from the fake stack, decrement original
                if not fakestack or fakestack:is_empty() then
                    itemstack:take_item(1)
                -- Else put old node back
                else
                    minetest.env:set_node(slabpos, slabnode)
                end
                return itemstack
            end

            -- Otherwise place regularly
            return minetest.item_place(itemstack, placer, pointed_thing)
        end,
    })

    minetest.register_craft({
        output = minetest.get_current_modname()..':slab_' .. subname .. ' 3',
        recipe = {
            {recipeitem, recipeitem, recipeitem},
        },
    })
end

-- Nodes will be called stairs:{stair,slab}_<subname>
function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab)
    stairs.register_stair(subname, recipeitem, groups, images, desc_stair)
    stairs.register_slab(subname, recipeitem, groups, images, desc_slab)
end

stairs.register_stair_and_slab("wood", "default:wood",
        {snappy=2,choppy=2,oddly_breakable_by_hand=2},
        {"default_wood.png"},
        "Wooden stair",
        "Wooden slab")

stairs.register_stair_and_slab("stone", "default:stone",
        {cracky=3},
        {"default_stone.png"},
        "Stone stair",
        "Stone slab")

stairs.register_stair_and_slab("cobble", "default:cobble",
        {cracky=3},
        {"default_cobble.png"},
        "Cobble stair",
        "Cobble slab")

stairs.register_stair_and_slab("brick", "default:brick",
        {cracky=3},
        {"default_brick.png"},
        "Brick stair",
        "Brick slab")

stairs.register_stair_and_slab("sandstone", "default:sandstone",
        {crumbly=2,cracky=2},
        {"default_sandstone.png"},
        "Sandstone stair",
        "Sandstone slab")


PostPosted: Sun Sep 09, 2012 07:32
by Calinou
Easy fix: use a self-compiled run-in-place version. 8)

Anyway; the folder ~/.minetest/worlds/WORLD_NAME/worldmods always gets checked before ~/.minetest/mods/minetest, which gets checked before /usr/share/games/minetest/games/minetest_game/mods.

PostPosted: Sun Sep 09, 2012 07:56
by LlubNek
Calinou wrote:Anyway; the folder ~/.minetest/worlds/WORLD_NAME/worldmods always gets checked before ~/.minetest/mods/minetest, which gets checked before /usr/share/games/minetest/games/minetest_game/mods.

Checked that, but it looks like it's the other way around.
I made a mod in ~/.minetest/mods/minetest/stairs with an init.lua like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
print("hello from "..minetest.get_current_modname().." at "..minetest.get_modpath(minetest.get_current_modname()).."!")

and watched stdout.

That code never runs, but if I move it from ~/.minetest/mods/minetest/stairs to ~/.minetest/mods/minetest/mystairs, it does. There were no error messages either way.

PostPosted: Sun Sep 09, 2012 08:42
by Topywo
Calinou wrote:Easy fix: use a self-compiled run-in-place version. 8)


Advantages (for me):
- I don't need to sudo for installing mods, so easy to delete and insert mods
- Very easy to make x copies of minetest in your home directory to try out different mods, textures etc.

PostPosted: Sun Sep 09, 2012 08:55
by LlubNek
Topywo wrote:Advantages (for me):
- I don't need to sudo for installing mods, so easy to delete and insert mods
- Very easy to make x copies of minetest in your home directory to try out different mods, textures etc.

You would have the same advantages with the world mods and home directory mods overriding the global mods without the need to have multiple copies of minetest itself. You could use different sets of mods by using the per-world mods.

PostPosted: Sun Sep 09, 2012 09:22
by Topywo
I didn't know that. I sometimes like to try out changes in the init.lua's of for example the minetest_game mods. When I screw up, I've plenty of original init.lua's to restore it, or I just delete the whole folder. I guess I'm compensating my lack of knowledge with disk space :-/

So you dont' need to sudo every time you install a mod? It has been a while ago I used a non-self compiled Mintest.

Btw, I agree with your proposed checking order.

PostPosted: Sun Sep 09, 2012 11:05
by LlubNek
LlubNek wrote:here's a modified init.lua that should fix this (maybe... see first bug for why this isn't tested):


It was close, but not quite right. See http://minetest.net/forum/viewtopic.php?id=2998 for a working mod that fixes stairs.

stairs itself, if modified, would look like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Minetest 0.4 mod: stairs
-- See README.txt for licensing and other information.

stairs = {}

-- Node will be called stairs:stair_<subname>
function stairs.register_stair(subname, recipeitem, groups, images, description)
    local name = minetest.get_current_modname()..":stair_" .. subname
    minetest.register_node(name, {
        description = description,
        drawtype = "nodebox",
        tiles = images,
        paramtype = "light",
        paramtype2 = "facedir",
        is_ground_content = true,
        groups = groups,
        node_box = {
            type = "fixed",
            fixed = {
                {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
                {-0.5, 0, 0, 0.5, 0.5, 0.5},
            },
        },
    })

    minetest.register_craft({
        output = name .. ' 4',
        recipe = {
            {recipeitem, "", ""},
            {recipeitem, recipeitem, ""},
            {recipeitem, recipeitem, recipeitem},
        },
    })

    -- Flipped recipe for the silly minecrafters
    minetest.register_craft({
        output = name .. ' 4',
        recipe = {
            {"", "", recipeitem},
            {"", recipeitem, recipeitem},
            {recipeitem, recipeitem, recipeitem},
        },
    })
end

-- Node will be called stairs:slab_<subname>
function stairs.register_slab(subname, recipeitem, groups, images, description)
    local name = minetest.get_current_modname()..":slab_" .. subname

    minetest.register_node(name, {
        description = description,
        drawtype = "nodebox",
        tiles = images,
        paramtype = "light",
        is_ground_content = true,
        groups = groups,
        node_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
        selection_box = {
            type = "fixed",
            fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
        },
        on_place = function(itemstack, placer, pointed_thing)
            if pointed_thing.type ~= "node" then
                return itemstack
            end

            -- If it's being placed on an another similar one, replace it with
            -- a full block
            local slabpos = nil
            local slabnode = nil
            local p0 = pointed_thing.under
            local p1 = pointed_thing.above
            local n0 = minetest.env:get_node(p0)
            local n1 = minetest.env:get_node(p1)
            if n0.name == name then
                slabpos = p0
                slabnode = n0
            elseif n1.name == name then
                slabpos = p1
                slabnode = n1
            end
            if slabpos then
                -- Remove the slab at slabpos
                minetest.env:remove_node(slabpos)
                -- Make a fake stack of a single item and try to place it
                local fakestack = ItemStack(recipeitem)
                pointed_thing.above = slabpos
                fakestack = minetest.item_place(fakestack, placer, pointed_thing)
                -- If the item was taken from the fake stack, decrement original
                if not fakestack or fakestack:is_empty() then
                    itemstack:take_item(1)
                -- Else put old node back
                else
                    minetest.env:set_node(slabpos, slabnode)
                end
                return itemstack
            end

            -- Otherwise place regularly
            return minetest.item_place(itemstack, placer, pointed_thing)
        end,
    })

    minetest.register_craft({
        output = name .. ' 3',
        recipe = {
            {recipeitem, recipeitem, recipeitem},
        },
    })
end

-- Nodes will be called stairs:{stair,slab}_<subname>
function stairs.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab)
    stairs.register_stair(subname, recipeitem, groups, images, desc_stair)
    stairs.register_slab(subname, recipeitem, groups, images, desc_slab)
end


stairs.register_stair_and_slab("wood", "default:wood",
        {snappy=2,choppy=2,oddly_breakable_by_hand=2},
        {"default_wood.png"},
        "Wooden stair",
        "Wooden slab")

stairs.register_stair_and_slab("stone", "default:stone",
        {cracky=3},
        {"default_stone.png"},
        "Stone stair",
        "Stone slab")

stairs.register_stair_and_slab("cobble", "default:cobble",
        {cracky=3},
        {"default_cobble.png"},
        "Cobble stair",
        "Cobble slab")

stairs.register_stair_and_slab("brick", "default:brick",
        {cracky=3},
        {"default_brick.png"},
        "Brick stair",
        "Brick slab")

stairs.register_stair_and_slab("sandstone", "default:sandstone",
        {crumbly=2,cracky=2},
        {"default_sandstone.png"},
        "Sandstone stair",
        "Sandstone slab")