Skip to content

MTR Access API#

Sometimes your script may need more surrounding context from the MTR Mod. For example you may want to find the station at a given position, or you want to check the preference of the MTR Mod, so your script can cater towards it.

Historically this is done by invoking MTR Mod's Java Class methods. However since they are not designed for outside use, it makes it easy to break between MTR versions, requiring rework of scripts.

The MTR Access API aims to provides a set of API for scripts to more trivially retrieve data from MTR Mod, while reducing the need to invoke MTR's internal classes.

This API ought to remain stable across versions to avoid breaking scripts as much as possible.

API Reference#

Classes listed below are exposed to all scripts, you may invoke them at any time.

MTR.ClientConfig#

This allows you to retrieve options & preferences the player has configured for the MTR Mod.

Functions Description
static
MTR.ClientConfig.isChatAnnouncementEnabled(): boolean
Whether in-chat next-station announcement is enabled.
static
MTR.ClientConfig.isTtsAnnouncementEnabled(): boolean
Whether text-to-speech (MC Narrator) for next-station announcement is enabled.
static
MTR.ClientConfig.shouldHideTranslucentParts(): boolean
Whether translucent model part in vehicle models should be hidden.
static
MTR.ClientConfig.getLanguageDisplay(): string
Returns the preferred language used for railway signs display.
Possible values are:
- NORMAL - Multilingual (CJK + English)
- CJK_ONLY - Only display CJK characters.
- NON_CJK_ONLY - Only display non-CJK characters.
static
MTR.ClientConfig.getDynamicTextureResolution(): int
Returns the texture resolution level of dynamically-generated MTR Mod Signs (Like route map).
0 is the lowest, 8 is highest.
static
MTR.ClientConfig.getVehicleOscillationMultiplier(): int
Returns the oscillation multiplier for vehicles.
Multiply by 10 to get the oscillation percentage level. (e.g. 9 = 90%)
static
MTR.ClientConfig.getDefaultRail3D(): boolean
Whether the 3D variant is used for the default MTR rail model.
static
MTR.ClientConfig.isCustomFontEnabled(): boolean
Whether MTR Mod components that use Minecraft Vanilla's text drawing should adapt to the MTR font.

MTR.Data#

This allows you to retrieve various client data of MTR.

Data Knowledge

MTR 4 only fetches the minimal data needed for the operation. This means the client usually only has knowledge of nearby/connecting station areas & routes, instead of having access to the full set of MTR data in the world.

Many functions may return null if the data is not known to client, even though it may exist on the server-side.

Functions Description
static
MTR.Data.findStation(pos: Vector3f): Station?
Find the Station object that covers the given pos location.
Returns null if there's no station in that area that the client is aware of.
static
MTR.Data.getStation(stationId: long): Station?
Obtain the Station object from a station ID.
Returns null if there's no station with the given id that the client is aware of.
static
MTR.Data.getKnownStations(): List<Station>
Returns a list of Station object that the client is aware of.
Functions Description
static
MTR.Data.findDepot(pos: Vector3f): Depot?
Find the Depot object that covers the given pos location.
Returns null if there's no depot in that area that the client is aware of.
static
MTR.Data.getDepot(stationId: long): Depot?
Obtain the Depot object from a depot ID.
Returns null if there's no depot with the given id that the client is aware of.
static
MTR.Data.getKnownDepots(): List<Depot>
Returns a list of Depot object that the client is aware of.
Functions Description
static
MTR.Data.getRoute(routeId: long): SimplifiedRoute?
Obtain the SimplifiedRoute object from a route ID.
Returns null if there's no route with the given id that the client is aware of.
static
MTR.Data.getKnownRoutes(): List<SimplifiedRoute>
Returns a list of SimplifiedRoute object that the client is aware of.
static
MTR.Data.getKnownRoutesPassingPlatform(platformId: long): List<SimplifiedRoute>
Returns a list of SimplifiedRoute object that the client is aware of, which passes through platform with id platformId.
Functions Description
static
MTR.Data.getVehicle(vehicleId: long): VehicleExtension?
Obtain the VehicleExtension object from a vehicle ID.
Returns null if there's no vehicle with the given id that the client is aware of.
static
MTR.Data.getPlayerMountedVehicle(): VehicleExtension?
Obtain the VehicleExtension object that the client is onboard.
Returns null if player is not onboard a vehicle.
static
MTR.Data.getKnownVehicles(): List<VehicleExtension>
Returns a list of VehicleExtension object that the client is aware of.
static
MTR.Data.isPlayerMounted(vehicleId: long): boolean
Whether a player is currently onboard a Vehicle/Lift.
Functions Description
static
MTR.Data.getLift(liftId: long): Lift?
Obtain the Lift object from a lift ID.
Returns null if there's no lift with the given id that the client is aware of.
static
MTR.Data.getPlayerMountedLift(): Lift?
Obtain the Lift object that the client is onboard.
Returns null if player is not onboard a lift.
static
MTR.Data.getKnownLifts(): List<Lift>
Returns a list of Lift object that the client is aware of.
Functions Description
static
MTR.Data.getRailFromPath(path: PathData): Rail
Obtain a Rail object from a PathData.
This function tries to look up an instance of the Rail with more details, such as the rail models applied.
If failed, it will return the original rail with PathData.
static
MTR.Data.getKnownRails(): List<Rail>
Returns a list of Rail object that the client is aware of.
static
MTR.Data.isRailBlocked(railHexId: String): boolean
Whether a rail segment is occupied. (Due to signal)
static
MTR.Data.getKnownBlockedRails(): List<String>
Returns a list of Rail Hex IDs whose rail is blocked. (Due to signal)
static
MTR.Data.getBlockedSignalColors(railHexId: String): List<Long>
Returns a list of signal color values (RGB) which is blocked within a rail segment.
Functions Description
static
MTR.Data.getPlatform(platformId: long): Platform?
Obtain a Platform object from a Platform ID.
Returns null if there's no platform with the given id that the client is aware of.
static
MTR.Data.getKnownPlatforms(): List<Platform>
Returns a list of Platform object that the client is aware of.
static
MTR.Data.findNearbyPlatforms(pos: Vector3f, radius: int): List<Platform>
Obtain a list of Platform object, that is within radius block of pos.
Functions Description
static
MTR.Data.getSiding(sidingId: long): Siding?
Obtain a Siding object from a Platform ID.
Returns null if there's no platform with the given id that the client is aware of.
static
MTR.Data.getKnownSidings(): List<Siding>
Returns a list of Siding object that the client is aware of.
static
MTR.Data.findNearbySidings(pos: Vector3f, radius: int): List<Siding>
Obtain a list of Siding object, that is within radius block of pos.
Functions Description
static
MTR.Data.getArrivals(platformId: long): ArrivalEntries
Obtain arrivals of a single platform. Returns an ArrivalEntries, identical to the one obtained via pids.arrivals() in JCM PIDS scripting.
static
MTR.Data.getArrivals(platformIds: long[]): ArrivalEntries
Obtain arrivals of multiple platforms. Returns an ArrivalEntries, identical to the one obtained via pids.arrivals() in JCM PIDS scripting.