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 |
|---|---|
staticMTR.ClientConfig.isChatAnnouncementEnabled(): boolean |
Whether in-chat next-station announcement is enabled. |
staticMTR.ClientConfig.isTtsAnnouncementEnabled(): boolean |
Whether text-to-speech (MC Narrator) for next-station announcement is enabled. |
staticMTR.ClientConfig.shouldHideTranslucentParts(): boolean |
Whether translucent model part in vehicle models should be hidden. |
staticMTR.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. |
staticMTR.ClientConfig.getDynamicTextureResolution(): int |
Returns the texture resolution level of dynamically-generated MTR Mod Signs (Like route map). 0 is the lowest, 8 is highest. |
staticMTR.ClientConfig.getVehicleOscillationMultiplier(): int |
Returns the oscillation multiplier for vehicles. Multiply by 10 to get the oscillation percentage level. (e.g. 9 = 90%) |
staticMTR.ClientConfig.getDefaultRail3D(): boolean |
Whether the 3D variant is used for the default MTR rail model. |
staticMTR.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.
Station Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.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. |
staticMTR.Data.getKnownStations(): List<Station> |
Returns a list of Station object that the client is aware of. |
Depot Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.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. |
staticMTR.Data.getKnownDepots(): List<Depot> |
Returns a list of Depot object that the client is aware of. |
Route Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.Data.getKnownRoutes(): List<SimplifiedRoute> |
Returns a list of SimplifiedRoute object that the client is aware of. |
staticMTR.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. |
Vehicle Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.Data.getPlayerMountedVehicle(): VehicleExtension? |
Obtain the VehicleExtension object that the client is onboard. Returns null if player is not onboard a vehicle. |
staticMTR.Data.getKnownVehicles(): List<VehicleExtension> |
Returns a list of VehicleExtension object that the client is aware of. |
staticMTR.Data.isPlayerMounted(vehicleId: long): boolean |
Whether a player is currently onboard a Vehicle/Lift. |
Lift Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.Data.getPlayerMountedLift(): Lift? |
Obtain the Lift object that the client is onboard. Returns null if player is not onboard a lift. |
staticMTR.Data.getKnownLifts(): List<Lift> |
Returns a list of Lift object that the client is aware of. |
Rail Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.Data.getKnownRails(): List<Rail> |
Returns a list of Rail object that the client is aware of. |
staticMTR.Data.isRailBlocked(railHexId: String): boolean |
Whether a rail segment is occupied. (Due to signal) |
staticMTR.Data.getKnownBlockedRails(): List<String> |
Returns a list of Rail Hex IDs whose rail is blocked. (Due to signal) |
staticMTR.Data.getBlockedSignalColors(railHexId: String): List<Long> |
Returns a list of signal color values (RGB) which is blocked within a rail segment. |
Platform Rail Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.Data.getKnownPlatforms(): List<Platform> |
Returns a list of Platform object that the client is aware of. |
staticMTR.Data.findNearbyPlatforms(pos: Vector3f, radius: int): List<Platform> |
Obtain a list of Platform object, that is within radius block of pos. |
Siding Rail Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.Data.getKnownSidings(): List<Siding> |
Returns a list of Siding object that the client is aware of. |
staticMTR.Data.findNearbySidings(pos: Vector3f, radius: int): List<Siding> |
Obtain a list of Siding object, that is within radius block of pos. |
Arrivals Related#
| Functions | Description |
|---|---|
staticMTR.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. |
staticMTR.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. |