User Tools

Site Tools


mtr_addon:nte:js:train

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:train [2024/02/06 22:30] – создано weryskokmtr_addon:nte:js:train [2024/04/09 17:45] (current) weryskok
Line 20: Line 20:
 } }
 </code> </code>
 +
 In general, the parameters are the same as those required for regular resourcepacks for MTR, except for the ''script_files'' parameter. In general, the parameters are the same as those required for regular resourcepacks for MTR, except for the ''script_files'' parameter.
  
Line 33: Line 34:
  
 ===== Global Environment ===== ===== Global Environment =====
 +
 All trains of the same type use the same working environment (global variables and etc). All trains of the same type use the same working environment (global variables and etc).
  
Line 38: Line 40:
  
 ===== Called Functions ===== ===== Called Functions =====
 +
 Your script should include the following functions that the NTE will call as needed: Your script should include the following functions that the NTE will call as needed:
 +
 <code javascript> <code javascript>
 function create(ctx, state, train) { ... } function create(ctx, state, train) { ... }
Line 47: Line 51:
 ^ Functions ^ Description ^ ^ Functions ^ Description ^
 | ''create'' | It is called when the train is loaded at the client and can be used to perform some initialization operations, for example, to create dynamic textures. | | ''create'' | It is called when the train is loaded at the client and can be used to perform some initialization operations, for example, to create dynamic textures. |
-| ''render '' | It is called approximately once per frame. It is used for basic display logic. The code is executed in a separate thread so as not to slow down FPS, and if it takes too long to execute the code, it can be executed once every few frames. | +| ''render '' | It is called approximately once per frame. It is used for basic display logic. In practice however, the code is executed in a separate thread so as not to slow down FPS. If it takes too long to execute the code, it can be called once every few frames instead of every frame. | 
-| ''dispose'' | Called when a train goes out of sight. Can be used for things like deleting dynamic textures. |+| ''dispose'' | Called when a train goes out of sight. Can be used for things like releasing the dynamic textures to free up memory. |
  
 The NTE calls these functions with three parameters, each of which is described below. The NTE calls these functions with three parameters, each of which is described below.
Line 60: Line 64:
  
 ===== TrainScriptContext ===== ===== TrainScriptContext =====
 +
 The following functions are called to **control rendering**. The functions for rendering models should be called each time ''render'' is called. The following functions are called to **control rendering**. The functions for rendering models should be called each time ''render'' is called.
 +
   * <code javascript>   * <code javascript>
 TrainScriptContext.drawCarModel(model: ModelCluster, carIndex: int, poseStack: Matrices): void TrainScriptContext.drawCarModel(model: ModelCluster, carIndex: int, poseStack: Matrices): void
 </code> </code>
-    * Requests the NTE to render the car model.+    * Requests NTE to render the car model.
     * ''carIndex'': defines the car whose origin point will be used for rendering (''0'' — first car in front, ''train.trainCars() - 1'' — last). The origin point is in the middle of the car, 1 block above ground level.     * ''carIndex'': defines the car whose origin point will be used for rendering (''0'' — first car in front, ''train.trainCars() - 1'' — last). The origin point is in the middle of the car, 1 block above ground level.
     * ''poseStack'': transformation of model placement. If passed null, the model will be placed in the center without transformation.     * ''poseStack'': transformation of model placement. If passed null, the model will be placed in the center without transformation.
Line 79: Line 85:
  
 Call the following functions to **play sounds**. Call only when you need to start playback, repeated calls will cause multiple sounds to stack. Call the following functions to **play sounds**. Call only when you need to start playback, repeated calls will cause multiple sounds to stack.
 +
   * <code javascript>   * <code javascript>
 TrainScriptContext.playCarSound(sound: ResourceLocation, carIndex: int, x: float, y: float, z: float, volume: float, pitch: float): void TrainScriptContext.playCarSound(sound: ResourceLocation, carIndex: int, x: float, y: float, z: float, volume: float, pitch: float): void
Line 89: Line 96:
  
 In addition, there is a set of functions to **aid development and debugging**. In addition, there is a set of functions to **aid development and debugging**.
 +
   * <code javascript>   * <code javascript>
 TrainScriptContext.setDebugInfo(key: String, value: Object) TrainScriptContext.setDebugInfo(key: String, value: Object)
 </code> </code>
-    * Output debugging information in the upper left corner of the screen. You need to enable "Show JS debug info" in settings to display it. ''key'' is the name of the value, ''value'' is the content (''GraphicsTexture'' type will be displayed, others will be converted to string).+    * Output debugging information in the upper left corner of the screen. You need to enable "Show JS debug info" in NTE Settings to display it. ''key'' is the name of the value, ''value'' is the content (''GraphicsTexture'' type will be displayed, others will be converted to string).
  
 ^ Functions And Objects ^ Description ^ ^ Functions And Objects ^ Description ^
Line 104: Line 112:
 | ''train.width(): int'' | Width. Since the player also has a width [what?], a wagon that is 3 blocks wide has a value of 2 for this attribute. | | ''train.width(): int'' | Width. Since the player also has a width [what?], a wagon that is 3 blocks wide has a value of 2 for this attribute. |
 | ''train.trainCars(): int'' | Number of cars. | | ''train.trainCars(): int'' | Number of cars. |
-| ''train.accelerationConstant(): float'' | Acceleration. The unit of measurement is m/tick/tick, which is 1/400 m/s^2|+| ''train.accelerationConstant(): float'' | Acceleration. The unit of measurement is m/tick/tick, which is 1/400 m/s<sup>2</sup> |
 | ''train.manualAllowed(): boolean'' | Whether manual operation is allowed. | | ''train.manualAllowed(): boolean'' | Whether manual operation is allowed. |
 | ''train.maxManualSpeed(): int'' | The maximum speed at manual control. It corresponds to the ordering of track types from low to high. [what?] | | ''train.maxManualSpeed(): int'' | The maximum speed at manual control. It corresponds to the ordering of track types from low to high. [what?] |
Line 149: Line 157:
  
 ===== PathData ===== ===== PathData =====
 +
 ^ Functions And Objects ^ Description ^ ^ Functions And Objects ^ Description ^
 | ''PathData.rail: Rail'' | Rail. For more details, see the [[https://github.com/jonafanho/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/data/Rail.java|Rail.java]] source code from MTR. | | ''PathData.rail: Rail'' | Rail. For more details, see the [[https://github.com/jonafanho/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/data/Rail.java|Rail.java]] source code from MTR. |
 | ''PathData.rail.railType: RailType'' | Rail type (wood, stone, iron...) See the [[https://github.com/jonafanho/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/data/RailType.java|RailType.java]] source code from MTR. | | ''PathData.rail.railType: RailType'' | Rail type (wood, stone, iron...) See the [[https://github.com/jonafanho/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/data/RailType.java|RailType.java]] source code from MTR. |
-| ''PathData.rail.getModelKey(): String'' | The NTE path model used for this section. Not specified with an empty string, hidden as "null"[what?|+| ''PathData.rail.getModelKey(): String'' | The NTE path model used for this section.This will return an empty string if no NTE path model are assignedand "null" if the model in use are the (Hidden) track model. |
 | ''PathData.dwellTime: int'' | The amount of time a train has to stop if this section of track is a platform. 0 if it is not a platform, in *0.5s. | | ''PathData.dwellTime: int'' | The amount of time a train has to stop if this section of track is a platform. 0 if it is not a platform, in *0.5s. |
  
 ===== PlatformInfo ===== ===== PlatformInfo =====
 +
 ^ Functions And Objects ^ Description ^ ^ Functions And Objects ^ Description ^
 | ''platformInfo.route: Route'' | The route to which this platform belongs. If the reverse happens at the platform — the route after reversal is returned. See [[https://github.com/jonafanho/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/data/Route.java|Route.java]] source code from MTR. | | ''platformInfo.route: Route'' | The route to which this platform belongs. If the reverse happens at the platform — the route after reversal is returned. See [[https://github.com/jonafanho/Minecraft-Transit-Railway/blob/3.3.0/common/src/main/java/mtr/data/Route.java|Route.java]] source code from MTR. |
Line 167: Line 177:
 | ''PlatformInfo.destinationStation.name: String'' | The name of the terminus of the route to which the platform belongs. | | ''PlatformInfo.destinationStation.name: String'' | The name of the terminus of the route to which the platform belongs. |
 | ''PlatformInfo.destinationName: String'' | Name of the final station (including the possibility of customizing the text). | | ''PlatformInfo.destinationName: String'' | Name of the final station (including the possibility of customizing the text). |
-| ''PlatformInfo.distance: double'' | The distance from the depot to the platform, can be compared to railProgress. |+| ''PlatformInfo.distance: double'' | The distance from the depot to the platform, can be compared with ''railProgress''. |
 | ''PlatformInfo.reverseAtPlatform: boolean'' | Does the train reverse on the platform? | | ''PlatformInfo.reverseAtPlatform: boolean'' | Does the train reverse on the platform? |
  
 ===== Source ===== ===== Source =====
-  * https://www.zbx1425.cn/nautilus/mtr-nte/#/js-train+ 
 +  [[https://www.zbx1425.cn/nautilus/mtr-nte/#/js-train]] 
  
mtr_addon/nte/js/train.1707258624.txt.gz · Last modified: 2024/02/06 22:30 by weryskok