User Tools

Site Tools


Sidebar



Minetest Forum
Content Database
Git Repository
Bug Tracker
Website

dev:core:funref:register_platform

advtrains.register_platform

Registers an Advtrains platform node.

Note: this page has been written for Advtrains 2.0.1 TSS and Minetest 5.1.0. Examples and practices described in this page don't take advantage of improvements introduced in later releases.

Syntax

advtrains.register_platform(modprefix, preset)

Extended description

Allows the use of node preset as an Advtrains platform.

Parameters

  • 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.

Errors and warnings

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

A startup error is raised if modprefix is nil or does not designate a mod name.

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.

Both platforms aren't blocking trains, because they belong to the not_blocking_trains group. As well, they are in the platform group (with value 1 for low platform, 2 for high one).

Example

-- Create a brick platform
advtrains.register_platform("my_platforms", "default:brick")

In source code

advtrains/misc_nodes.lua, lines 3 to 63:

register_platforms.lua
function advtrains.register_platform(modprefix, preset)
    local ndef=minetest.registered_nodes[preset]
    if not ndef then 
        minetest.log("warning", " register_platform couldn't find preset node "..preset)
        return
    end
    local btex=ndef.tiles
    if type(btex)=="table" then
        btex=btex[1]
    end
    local desc=ndef.description or ""
    local nodename=string.match(preset, ":(.+)$")
    minetest.register_node(modprefix .. ":platform_low_"..nodename, {
        description = attrans("@1 Platform (low)", desc),
        tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex},
        groups = {cracky = 1, not_blocking_trains = 1, platform=1},
        sounds = default.node_sound_stone_defaults(),
        drawtype = "nodebox",
        node_box = {
            type = "fixed",
            fixed = {
                {-0.5, -0.1, -0.1, 0.5,  0  , 0.5},
                {-0.5, -0.5,  0  , 0.5, -0.1, 0.5}
            },
        },
        paramtype2="facedir",
        paramtype = "light",
        sunlight_propagates = true,
    })
    minetest.register_node(modprefix .. ":platform_high_"..nodename, {
        description = attrans("@1 Platform (high)", desc),
        tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex},
        groups = {cracky = 1, not_blocking_trains = 1, platform=2},
        sounds = default.node_sound_stone_defaults(),
        drawtype = "nodebox",
        node_box = {
            type = "fixed",
            fixed = {
                {-0.5,  0.3, -0.1, 0.5,  0.5, 0.5},
                {-0.5, -0.5,  0  , 0.5,  0.3, 0.5}
            },
        },
        paramtype2="facedir",
        paramtype = "light",
        sunlight_propagates = true,
    })
    minetest.register_craft({
        type="shapeless",
        output = modprefix .. ":platform_high_"..nodename.." 4",
        recipe = {
            "dye:yellow", preset, preset
        },
    })
    minetest.register_craft({
        type="shapeless",
        output = modprefix .. ":platform_low_"..nodename.." 4",
        recipe = {
            "dye:yellow", preset
        },
    })
end
dev/core/funref/register_platform.txt · Last modified: 2020-01-22 09:53 by admin