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-06-30 20:48]
82.67.173.193 fixed syntax
dev:core:funref:register_platform [2019-10-02 20:16]
82.67.173.193 convert tabs to spaces
Line 10: Line 10:
  
 ===== Extended description ===== ===== Extended description =====
-Allows the use of node **preset** as an Advtrains [[usage:nodes:platform|platform]].+Allows the use of node ''preset'' as an Advtrains [[usage:nodes:platform|platform]].
  
 ===== Parameters ===== ===== Parameters =====
-  * **modprefix** //(string)//: a string designating the name of the caller's mod. +  * ''modprefix'' //(string)//: a string designating the name of the caller's mod. 
-  * **preset** //(string)//: a node name which will be used as base for the platform.+  * ''preset'' //(string)//: a node name which will be used as base for the platform.
  
 ===== Errors and warnings ===== ===== Errors and warnings =====
-It gives a warning if the referenced node **preset** is nil, or has not been registered:+It gives a warning if the referenced node ''preset'' is nil, or has not been registered:
  
 > 2019-01-01 15:00:00: WARNING[Server]:  register_platform couldn't find preset node unknown:node > 2019-01-01 15:00:00: WARNING[Server]:  register_platform couldn't find preset node unknown:node
  
-A startup error is raised if **modprefix** is nil or does not designate a mod name.+A startup error is raised if ''modprefix'' is nil or does not designate a mod name.
  
 ===== How it works internally ===== ===== How it works internally =====
 This Lua function registers two nodes: a low and a high platform. The low platform is half height while the high one is full height. The function takes the texture used by the face at the top as a base for the all platform faces, but also adds a yellow line on the top, referenced by **advtrains_platform.png** in the code. This Lua function registers two nodes: a low and a high platform. The low platform is half height while the high one is full height. The function takes the texture used by the face at the top as a base for the all platform faces, but also adds a yellow line on the top, referenced by **advtrains_platform.png** in the code.
  
-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