Change naming convention to be modname:* instead of modname_* (sorry modders!)
authorPerttu Ahola <celeron55@gmail.com>
Sat, 3 Dec 2011 09:41:52 +0000 (11:41 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 3 Dec 2011 09:41:52 +0000 (11:41 +0200)
data/mods/bucket/init.lua
data/mods/default/init.lua
data/mods/experimental/init.lua
src/scriptapi.cpp

index 33beb699d0cae35c4afcb57bc0a692e6c4842508..3b1eefb37e952b259392a03791829be5a97ce397 100644 (file)
@@ -1,12 +1,12 @@
 minetest.register_craft({
-       output = 'craft "bucket_empty" 1',
+       output = 'craft "bucket:bucket_empty" 1',
        recipe = {
                {'craft "steel_ingot"', '', 'craft "steel_ingot"'},
                {'', 'craft "steel_ingot"', ''},
        }
 })
 
-minetest.register_craftitem("bucket_empty", {
+minetest.register_craftitem("bucket:bucket_empty", {
        image = "bucket.png",
        stack_max = 1,
        liquids_pointable = true,
@@ -16,11 +16,11 @@ minetest.register_craftitem("bucket_empty", {
                        n = minetest.env:get_node(pointed_thing.under)
                        if n.name == "water_source" then
                                minetest.env:add_node(pointed_thing.under, {name="air"})
-                               player:add_to_inventory_later('craft "bucket_water" 1')
+                               player:add_to_inventory_later('craft "bucket:bucket_water" 1')
                                return true
                        elseif n.name == "lava_source" then
                                minetest.env:add_node(pointed_thing.under, {name="air"})
-                               player:add_to_inventory_later('craft "bucket_lava" 1')
+                               player:add_to_inventory_later('craft "bucket:bucket_lava" 1')
                                return true
                        end
                end
@@ -28,8 +28,8 @@ minetest.register_craftitem("bucket_empty", {
        end,
 })
 
-minetest.register_craftitem("bucket_water", {
-       image = "bucket_water.png",
+minetest.register_craftitem("bucket:bucket_water", {
+       image = "bucket:bucket_water.png",
        stack_max = 1,
        liquids_pointable = true,
        on_place_on_ground = minetest.craftitem_place_item,
@@ -43,15 +43,15 @@ minetest.register_craftitem("bucket_water", {
                        else
                                minetest.env:add_node(pointed_thing.above, {name="water_source"})
                        end
-                       player:add_to_inventory_later('craft "bucket_empty" 1')
+                       player:add_to_inventory_later('craft "bucket:bucket_empty" 1')
                        return true
                end
                return false
        end,
 })
 
-minetest.register_craftitem("bucket_lava", {
-       image = "bucket_lava.png",
+minetest.register_craftitem("bucket:bucket_lava", {
+       image = "bucket:bucket_lava.png",
        stack_max = 1,
        liquids_pointable = true,
        on_place_on_ground = minetest.craftitem_place_item,
@@ -65,7 +65,7 @@ minetest.register_craftitem("bucket_lava", {
                        else
                                minetest.env:add_node(pointed_thing.above, {name="lava_source"})
                        end
-                       player:add_to_inventory_later('craft "bucket_empty" 1')
+                       player:add_to_inventory_later('craft "bucket:bucket_empty" 1')
                        return true
                end
                return false
index e0cc3598bf90591e7d200bfe9ab8da1071a74527..3baafff63a55097e3478f6737a15371c92ca0331 100644 (file)
 --
 -- Naming convention for registered textual names
 -- ----------------------------------------------
--- "modname_<whatever>"
+-- "modname:<whatever>" (<whatever> can have characters a-zA-Z0-9_)
 --
 -- This is to prevent conflicting names from corrupting maps and is
 -- enforced by the mod loader.
 --
 -- Example: mod "experimental", ideal item/node/entity name "tnt":
---          -> the name should be "experimental_tnt".
+--          -> the name should be "experimental:tnt".
 --
 -- Enforcement can be overridden by prefixing the name with ":". This can
 -- be used for overriding the registrations of some other mod.
 --
+-- Example: Any mod can redefine experimental:tnt by using the name
+--          ":experimental:tnt" when registering it.
+-- (also that mods is required to have "experimental" as a dependency)
+--
 -- Default mod uses ":" for maintaining backwards compatibility.
 --
 -- Textures
@@ -1426,7 +1430,7 @@ function nodeupdate_single(p)
                n_bottom = minetest.env:get_node(p_bottom)
                if n_bottom.name == "air" then
                        minetest.env:remove_node(p)
-                       minetest.env:add_luaentity(p, "default_falling_"..n.name)
+                       minetest.env:add_luaentity(p, "default:falling_"..n.name)
                        nodeupdate(p)
                end
        end
@@ -1448,7 +1452,7 @@ end
 --
 
 function register_falling_node(nodename, texture)
-       minetest.register_entity("default_falling_"..nodename, {
+       minetest.register_entity("default:falling_"..nodename, {
                -- Static definition
                physical = true,
                collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
index 207b38cbf0b6a464f4ca6d21ca026f94893ac22d..326fe1b754094ad23974e17b9429890bb0b4984a 100644 (file)
@@ -4,7 +4,7 @@
 
 -- An example furnace-thing implemented in Lua
 
-minetest.register_node("experimental_luafurnace", {
+minetest.register_node("experimental:luafurnace", {
        tile_images = {"lava.png", "furnace_side.png", "furnace_side.png",
                "furnace_side.png", "furnace_side.png", "furnace_front.png"},
        --inventory_image = "furnace_front.png",
@@ -15,7 +15,7 @@ minetest.register_node("experimental_luafurnace", {
 })
 
 minetest.register_on_placenode(function(pos, newnode, placer)
-       if newnode.name == "experimental_luafurnace" then
+       if newnode.name == "experimental:luafurnace" then
                print("get_meta");
                local meta = minetest.env:get_meta(pos)
                print("inventory_set_list");
@@ -42,7 +42,7 @@ minetest.register_on_placenode(function(pos, newnode, placer)
 end)
 
 minetest.register_abm({
-       nodenames = {"experimental_luafurnace"},
+       nodenames = {"experimental:luafurnace"},
        interval = 1.0,
        chance = 1,
        action = function(pos, node, active_object_count, active_object_count_wider)
@@ -97,7 +97,7 @@ minetest.register_abm({
 })
 
 minetest.register_craft({
-       output = 'node "experimental_luafurnace" 1',
+       output = 'node "experimental:luafurnace" 1',
        recipe = {
                {'node "cobble"', 'node "cobble"', 'node "cobble"'},
                {'node "cobble"', 'node "cobble"', 'node "cobble"'},
@@ -132,7 +132,7 @@ minetest.register_craft({
        }
 })
 
-minetest.register_node("experimental_somenode", {
+minetest.register_node("experimental:somenode", {
        tile_images = {"lava.png", "mese.png", "stone.png", "grass.png", "cobble.png", "tree_top.png"},
        inventory_image = "treeprop.png",
        material = {
@@ -151,7 +151,7 @@ minetest.register_node("experimental_somenode", {
 --
 
 minetest.register_craft({
-       output = 'node "experimental_tnt" 4',
+       output = 'node "experimental:tnt" 4',
        recipe = {
                {'node "wood" 1'},
                {'craft "lump_of_coal" 1'},
@@ -159,7 +159,7 @@ minetest.register_craft({
        }
 })
 
-minetest.register_node("experimental_tnt", {
+minetest.register_node("experimental:tnt", {
        tile_images = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png", "tnt_side.png", "tnt_side.png", "tnt_side.png"},
        inventory_image = "tnt_side.png",
        dug_item = '', -- Get nothing
@@ -169,9 +169,9 @@ minetest.register_node("experimental_tnt", {
 })
 
 minetest.register_on_punchnode(function(p, node)
-       if node.name == "experimental_tnt" then
+       if node.name == "experimental:tnt" then
                minetest.env:remove_node(p)
-               minetest.env:add_luaentity(p, "experimental_tnt")
+               minetest.env:add_luaentity(p, "experimental:tnt")
                nodeupdate(p)
        end
 end)
@@ -235,13 +235,13 @@ end
 
 --print("TNT dump: "..dump(TNT))
 --print("Registering TNT");
-minetest.register_entity("experimental_tnt", TNT)
+minetest.register_entity("experimental:tnt", TNT)
 
 --
 -- A test entity for testing animated and yaw-modulated sprites
 --
 
-minetest.register_entity("experimental_testentity", {
+minetest.register_entity("experimental:testentity", {
        -- Static definition
        physical = true, -- Collides with things
        -- weight = 5,
index be136673783029c26da33ad7d08c13203866ed91..c9f132f4affccbce7af3102827d8595b00a9f94e 100644 (file)
@@ -153,11 +153,18 @@ void check_modname_prefix(lua_State *L, std::string &name)
        // For __builtin, anything goes
        if(modname == "__builtin")
                return;
-
-       if(name.substr(0, modname.size()+1) != modname + "_")
+       
+       if(name.substr(0, modname.size()+1) != modname + ":")
+               throw LuaError(L, std::string("Name \"")+name
+                               +"\" does not follow naming conventions: "
+                               +"\"modname:\" or \":\" prefix required)");
+       
+       std::string subname = name.substr(modname.size()+1);
+       if(!string_allowed(subname, "abcdefghijklmnopqrstuvwxyz"
+                       "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"))
                throw LuaError(L, std::string("Name \"")+name
                                +"\" does not follow naming conventions: "
-                               +"\"modname_\" or \":\" prefix required)");
+                               +"\"contains unallowed characters)");
 }
 
 static v3f readFloatPos(lua_State *L, int index)