User Tools

Site Tools


mtr_addon:nte:js:util

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
mtr_addon:nte:js:util [2024/02/06 14:38] – another translation weryskokmtr_addon:nte:js:util [2024/11/03 11:02] (current) – Fix getNTEVersionInt() errata lx862
Line 1: Line 1:
 ====== Utilities ====== ====== Utilities ======
 +
 NTE provides a number of helper classes to provide some information or to implement functions more simply. NTE provides a number of helper classes to provide some information or to implement functions more simply.
  
 ===== Output of test information ===== ===== Output of test information =====
 +
   * <code javascript>   * <code javascript>
 static print(params: Object...): void static print(params: Object...): void
Line 9: Line 11:
  
 ===== Versions ===== ===== Versions =====
 +
 Functions are provided where you can get the version number to ensure compatibility with different versions of mods (if any). Functions are provided where you can get the version number to ensure compatibility with different versions of mods (if any).
 +
 ^ Functions ^ Description ^ ^ Functions ^ Description ^
 | ''static Resources.getMTRVersion(): String'' | Returns the version of the MTR, for example, ''1.19.2-3.1.1.0-hotfix-1''. | | ''static Resources.getMTRVersion(): String'' | Returns the version of the MTR, for example, ''1.19.2-3.1.1.0-hotfix-1''. |
 | ''static Resources.getNTEVersion(): String'' | Returns the version of the NTE, for example, ''0.4.0+1.19.2''. | | ''static Resources.getNTEVersion(): String'' | Returns the version of the NTE, for example, ''0.4.0+1.19.2''. |
-| ''static Resources.getNTEVersionInt(): int'' | Returns the NTE version as a number for easy comparison. For example, 0.4.0 would be 4000, 1.9.1 would be 19100. |+| ''static Resources.getNTEVersionInt(): int'' | Returns the NTE version as a number for easy comparison. For example, 0.4.0 would be 400, 1.9.1 would be 10901. |
 | ''static Resources.getNTEProtoVersion(): int'' | Returns the NTE protocol version. | | ''static Resources.getNTEProtoVersion(): int'' | Returns the NTE protocol version. |
  
 ===== TextUtil ===== ===== TextUtil =====
 +
 MTR uses the station naming format ''Name in CJK|Name in another language||EXTRA'', so NTE provides functions to separate these parts. MTR uses the station naming format ''Name in CJK|Name in another language||EXTRA'', so NTE provides functions to separate these parts.
  
Line 32: Line 37:
  
 ===== Timing ===== ===== Timing =====
 +
   * <code javascript>   * <code javascript>
 static Timing.elapsed(): double static Timing.elapsed(): double
Line 42: Line 48:
  
 ===== StateTracker ===== ===== StateTracker =====
 +
 Sometimes it is necessary to take transition states into account. For example, to play an animation only once when a certain condition is reached (because ''if (...distance < 300) ctx.play...'' would be satisfied every frame after the condition was met, and then play every frame after that, which would result in hundreds of animations), or to play an animation in the first second after a page switch. Sometimes it is necessary to take transition states into account. For example, to play an animation only once when a certain condition is reached (because ''if (...distance < 300) ctx.play...'' would be satisfied every frame after the condition was met, and then play every frame after that, which would result in hundreds of animations), or to play an animation in the first second after a page switch.
  
-Since each train must have its own tracker, you would probably want to store it in the train's ''state''+Since each train must have its own tracker, you would probably want to store it in the train's ''state''.
  
   * <code javascript>   * <code javascript>
Line 72: Line 79:
  
 ===== CycleTracker ===== ===== CycleTracker =====
 +
 This is a ''StateTracker'' that automatically switches on a cyclic basis by time. This is a ''StateTracker'' that automatically switches on a cyclic basis by time.
  
-Since each train must have its own tracker, you would probably want to store it in the train's ''state''+Since each train must have its own tracker, you would probably want to store it in the train's ''state''.
  
   * <code javascript>   * <code javascript>
Line 102: Line 110:
  
 ===== RateLimit ===== ===== RateLimit =====
 +
 Some tasks do not require too frequent execution, for example, the display may not be updated every frame, but only 10 times per second. Therefore, you can limit the frequency of their execution to improve performance. Some tasks do not require too frequent execution, for example, the display may not be updated every frame, but only 10 times per second. Therefore, you can limit the frequency of their execution to improve performance.
  
-Since each train must have its own data, you would probably want to store it in the train's ''state''+Since each train must have its own data, you would probably want to store it in the train's ''state''.
  
   * <code javascript>   * <code javascript>
Line 120: Line 129:
  
 ===== MTRClientData ===== ===== MTRClientData =====
 +
 Client data from MTR that can be used to read routes, transfers, etc. See the source code of [[https://github.com/Minecraft-Transit-Railway/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/client/ClientData.java|ClientData.java]] from MTR. Client data from MTR that can be used to read routes, transfers, etc. See the source code of [[https://github.com/Minecraft-Transit-Railway/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/client/ClientData.java|ClientData.java]] from MTR.
  
 ===== MinecraftClient ===== ===== MinecraftClient =====
 +
 Due to obfuscation, there is no way to directly provide a client class for use. Therefore, several helper methods are created: Due to obfuscation, there is no way to directly provide a client class for use. Therefore, several helper methods are created:
  
Line 137: Line 148:
 </code> </code>
     * Returns the in-game world time in ticks.     * Returns the in-game world time in ticks.
 +  * <code javascript>
 +static MinecraftClient.narrate(message: String): void
 +</code>
 +  * This calls the Minecraft narrator to narrate the message
 +  * <code javascript>
 +static MinecraftClient.displayMessage(message: String, actionBar: boolean): void
 +</code>
 +  * This displays the message as an in-game chat message. If action bar is true, it will display on the action bar instead. (Above inventory hotbar)
  
 ===== Source ===== ===== Source =====
-* https://www.zbx1425.cn/nautilus/mtr-nte/#/js-util+ 
 +[[https://www.zbx1425.cn/nautilus/mtr-nte/#/js-util]] 
  
mtr_addon/nte/js/util.1707230327.txt.gz · Last modified: 2024/02/06 14:38 by weryskok