User Tools

Site Tools


dev:core:funref:register_platform

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
dev:core:funref:register_platform [2019-07-02 12:33]
82.67.173.193 changed bold to monospace
dev:core:funref:register_platform [2019-10-02 20:16]
82.67.173.193 convert tabs to spaces
Line 27: Line 27:
  
 Both platforms aren't blocking trains, because they belong to the ''[[reference:not_blocking_trains|not_blocking_trains]]'' group. As well, they are in the ''[[reference:platform|platform]]'' group (with value 1 for low platform, 2 for high one). Both platforms aren't blocking trains, because they belong to the ''[[reference:not_blocking_trains|not_blocking_trains]]'' group. As well, they are in the ''[[reference:platform|platform]]'' group (with value 1 for low platform, 2 for high one).
 +
 +===== Example =====
 +<code lua>
 +-- Create a brick platform
 +advtrains.register_platform("my_platforms", "default:brick")
 +</code>
  
 ===== In source code ===== ===== In source code =====
Line 33: Line 39:
 <file lua register_platforms.lua> <file lua register_platforms.lua>
 function advtrains.register_platform(modprefix, preset) function advtrains.register_platform(modprefix, preset)
- local ndef=minetest.registered_nodes[preset] +    local ndef=minetest.registered_nodes[preset] 
- if not ndef then  +    if not ndef then  
- minetest.log("warning", " register_platform couldn't find preset node "..preset) +        minetest.log("warning", " register_platform couldn't find preset node "..preset) 
- return +        return 
- end +    end 
- local btex=ndef.tiles +    local btex=ndef.tiles 
- if type(btex)=="table" then +    if type(btex)=="table" then 
- btex=btex[1] +        btex=btex[1] 
- end +    end 
- local desc=ndef.description or "" +    local desc=ndef.description or "" 
- local nodename=string.match(preset, ":(.+)$"+    local nodename=string.match(preset, ":(.+)$"
- minetest.register_node(modprefix .. ":platform_low_"..nodename,+    minetest.register_node(modprefix .. ":platform_low_"..nodename,
- description = attrans("@1 Platform (low)", desc), +        description = attrans("@1 Platform (low)", desc), 
- tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex}, +        tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex}, 
- groups = {cracky = 1, not_blocking_trains = 1, platform=1}, +        groups = {cracky = 1, not_blocking_trains = 1, platform=1}, 
- sounds = default.node_sound_stone_defaults(), +        sounds = default.node_sound_stone_defaults(), 
- drawtype = "nodebox", +        drawtype = "nodebox", 
- node_box = { +        node_box = { 
- type = "fixed", +            type = "fixed", 
- fixed = { +            fixed = { 
- {-0.5, -0.1, -0.1, 0.5,  0  , 0.5}, +                {-0.5, -0.1, -0.1, 0.5,  0  , 0.5}, 
- {-0.5, -0.5,  0  , 0.5, -0.1, 0.5} +                {-0.5, -0.5,  0  , 0.5, -0.1, 0.5} 
- }, +            }, 
- }, +        }, 
- paramtype2="facedir", +        paramtype2="facedir", 
- paramtype = "light", +        paramtype = "light", 
- sunlight_propagates = true, +        sunlight_propagates = true, 
- }) +    }) 
- minetest.register_node(modprefix .. ":platform_high_"..nodename,+    minetest.register_node(modprefix .. ":platform_high_"..nodename,
- description = attrans("@1 Platform (high)", desc), +        description = attrans("@1 Platform (high)", desc), 
- tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex}, +        tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex}, 
- groups = {cracky = 1, not_blocking_trains = 1, platform=2}, +        groups = {cracky = 1, not_blocking_trains = 1, platform=2}, 
- sounds = default.node_sound_stone_defaults(), +        sounds = default.node_sound_stone_defaults(), 
- drawtype = "nodebox", +        drawtype = "nodebox", 
- node_box = { +        node_box = { 
- type = "fixed", +            type = "fixed", 
- fixed = { +            fixed = { 
- {-0.5,  0.3, -0.1, 0.5,  0.5, 0.5}, +                {-0.5,  0.3, -0.1, 0.5,  0.5, 0.5}, 
- {-0.5, -0.5,  0  , 0.5,  0.3, 0.5} +                {-0.5, -0.5,  0  , 0.5,  0.3, 0.5} 
- }, +            }, 
- }, +        }, 
- paramtype2="facedir", +        paramtype2="facedir", 
- paramtype = "light", +        paramtype = "light", 
- sunlight_propagates = true, +        sunlight_propagates = true, 
- }) +    }) 
- minetest.register_craft({ +    minetest.register_craft({ 
- type="shapeless", +        type="shapeless", 
- output = modprefix .. ":platform_high_"..nodename.." 4", +        output = modprefix .. ":platform_high_"..nodename.." 4", 
- recipe = { +        recipe = { 
- "dye:yellow", preset, preset +            "dye:yellow", preset, preset 
- }, +        }, 
- }) +    }) 
- minetest.register_craft({ +    minetest.register_craft({ 
- type="shapeless", +        type="shapeless", 
- output = modprefix .. ":platform_low_"..nodename.." 4", +        output = modprefix .. ":platform_low_"..nodename.." 4", 
- recipe = { +        recipe = { 
- "dye:yellow", preset +            "dye:yellow", preset 
- }, +        }, 
- })+    })
 end end
 </file> </file>
dev/core/funref/register_platform.txt · Last modified: 2020-01-22 10:53 by admin