- 'name' is the internal name of the wagon. It is registered inside the 'advtrains:' namespace.
Example: A wagon with name="engine_tgv" will be registered as "advtrains:engine_tgv".
- 'prototype' is the lua entity prototype. The regular definition keys for luaentites apply. Additional required and optional properties see below. DO NOT define 'on_step', 'on_activate', 'on_punch', 'on_rightclick' and 'get_staticdata' since these will be overridden. Use 'custom_*' instead.
- 'description' is the description of the inventory item that is used to place the wagon.
- 'inventory_image' is the inventory image of said item.
# Wagon prototype properties
{
... all regular luaentity properties (mesh, textures, collisionbox a.s.o)...
drives_on = {default=true},
^- used to define the tracktypes (see below) that wagon can drive on. The tracktype identifiers are given as keys, similar to privileges)
max_speed = 10,
^- optional, default 10: defines the maximum speed this wagon can drive. The maximum speed of a train is determined by the wagon with the lowest max_speed value.
^- Function that should return the formspec to be displayed when <player> requests to open the wagon's inventory
^- Use "list[detached:advtrains_wgn_"..self.unique_id..";<list_name>;<X>,<Y>;<W>,<H>;<Start>]" to display a wagon's inventory list.
custom_on_step = function(self, dtime) end
^- optional: Execute custom code on every step
custom_on_activate = function(self, dtime_s) end
^- optional: Execute custom code on activate. Staticdata does not need to be saved and restored since all properties written in 'self' are preserved over unloads.
update_animation = function(self, velocity) end
^- optional: Function that is called whenever the train's velocity changes or every 2 seconds. Used to call 'self.object:update_animation()' if needed.
}
# Notes on wagons
- Every wagon has the field 'unique_id' which assigns each wagon a random id.
- All properties written in the lua entity (self) are saved and restored automatically. Minetest's internal staticdata is only used to save the unique_id of the wagon, which serves as a key in an externally saved table.
- Assuming Z Axis as the axis parallel to the tracks and Y Axis as the one pointing into the sky, wagon models should be dimensioned in a way that:
- their origin is centered in X and Z direction
- their origin lies 0.5 units above the bottom of the model
- the overall extent in X and Y direction is <=3 units
- wagon_span is then the distance between the model origin and the Z axis extent.
If the advanced seating behavior is active, clicking on a wagon will immediately get you on that wagon depending on the entries in assign_to_seat_group.
If all seat groups are full, if the doors are closed or if you are not authorized to enter this seat group(e.g. driver stands), will show a warning.
On a train, right-clicking the wagon will make you get off the train unless:
- the doors are closed and it requires open doors.
- you have access to a seat group specified in access_to (you may enter it and it's not full)
- you are the owner and can access the wagon preferences
In case there's no possibility, does nothing.
In case there are multiple possibilities, will show a form.
If you can't enter or leave a train because the doors are closed, holding the Sneak key while right-clicking bypasses the "doors have to be open" enforcement.
Most modders will be satisfied with the built-in tracks. If cog railways, maglev trains and mine trains are added, it is necessary to understand the definition of tracks. Although the tracks API is there, explaining it would require more effort than me creating the wanted definitions myself. Contact me if you need to register your own rails using my registration functions.
However, it is still possible to register single rails by understanding the node properties of rails.
minetest.register_node(nodename, {
... usual node definition ...
groups = {
advtrains_track_<tracktype>=1
^- this group tells that the node is a track
not_blocking_trains=1,
^- this group tells that the node should not block trains although it's walkable.
},
connect1 = 0,
connect2 = 8,
^- These values tell the direction (horizontal) the rail ends are pointing to. 0 means +Z, then rotation values increase clockwise. For a translation of directions to positions see helpers.lua.
rely1=0,
rely2=0,
^- the Y height of the rail end 1/2. A value of >=1 means that the rail end points to the next y layer at rely-1
railheight=0,
^- the height value of this rail that is saved in the path. usually the median of rely1 and rely2.