Trains - morelandjo/Railways-Untold GitHub Wiki

Trains

Railways Untold places a starting train on the generated track when a world is first loaded. Train designs are defined via data packs, allowing you to add custom Create train schematics. Multiple train definitions can coexist, with weighted random selection and biome filtering determining which train spawns.

How It Works

The mod loads train definitions from data packs at startup and on /reload. When the starting train needs to be placed, the mod selects a train using weighted random selection filtered by the biome at the placement position. If multiple train definitions are valid for the biome, one is chosen randomly based on their weights. The random selection is seeded from the world seed, so the same world seed always produces the same train choice.

Config Settings

This setting remains in config/railways-untold/config.toml:

Setting Default Description
startingTrain true Whether to place a train at the starting track position when the world is first generated.

File Location

Place your train definition JSON file at:

data/<namespace>/railwaysuntold/trains/<name>.json

Place the corresponding .nbt schematic file at:

data/<namespace>/structure/<path>.nbt

For example, in a data pack called my_train:

my_train/
  pack.mcmeta
  data/
    my_train/
      railwaysuntold/
        trains/
          custom_train.json
      structure/
        trains/
          custom_train.nbt

JSON Format

{
  "schematic": "my_train:trains/custom_train",
  "front_facing": "auto",
  "weight": 10,
  "biome_whitelist": [],
  "biome_blacklist": [],
  "loot": {
    "by_tag": {
      "cargo": "my_train:trains/cargo_loot"
    }
  }
}

Field Reference

Field Type Required Default Description
schematic string Yes Resource location of the .nbt schematic. Resolves to data/<namespace>/structure/<path>.nbt. For example, "my_train:trains/custom_train" loads data/my_train/structure/trains/custom_train.nbt.
front_facing string No "auto" Which direction the front of the train faces in the schematic. See Front Facing Detection below.
weight integer No 10 Relative weight for random selection. Higher weight = more likely to be chosen. A train with weight 20 is twice as likely as one with weight 10.
biome_whitelist string[] No [] If non-empty, this train is only eligible in these biomes. Accepts biome IDs (e.g. "minecraft:plains") or biome tags prefixed with # (e.g. "#minecraft:is_forest").
biome_blacklist string[] No [] This train is excluded from these biomes. Same format as whitelist. Blacklist is checked after whitelist.
loot object No (none) Loot table configuration for containers in this train's schematic. See Loot Tables below.

Front Facing Values

Value Description
auto Auto-detect using smokestack blocks, then steam whistle blocks, then control seats.
north The front of the train faces north in the schematic.
south The front of the train faces south in the schematic.
east The front of the train faces east in the schematic.
west The front of the train faces west in the schematic.

Schematic Requirements

Train schematics must be saved as assembled Create trains (not loose blocks):

  1. Build and assemble your train in-game using Create's train assembly system
  2. The train must have at least one carriage contraption with bogeys
  3. Use a schematic tool (like Create's Schematic and Quill) to save the assembled train

The schematic is validated on load. The mod checks for:

  • Valid carriage_contraption entities in the NBT data
  • Proper bogey layout and spacing
  • Assembly direction detection

If validation fails, the mod falls back to the built-in default train and logs a warning.

Multi-Carriage Trains

Multi-carriage trains are supported. The mod detects carriage boundaries by analyzing bogey positions and entity fingerprints, then calculates inter-carriage spacing for proper assembly on the track.

Front Facing Detection

When front_facing is set to "auto", the mod detects the front of the train by searching for these blocks in order:

  1. Smokestack blocks — blocks with "smokestack" in the name
  2. Steam whistle blocks — blocks with "steam_whistle" in the name
  3. Control seats — the FrontControls flag on carriage contraptions

If auto-detection produces the wrong result, use an explicit direction value.

Built-In Default

The mod ships with a built-in default train definition:

data/railwaysuntold/railwaysuntold/trains/default_train.json

{
  "schematic": "railwaysuntold:train",
  "front_facing": "auto"
}

This uses the bundled train.nbt schematic with the default weight of 10 and no biome restrictions. To add additional trains, simply create a data pack with more train definitions — they will all participate in weighted random selection.

Weighted Random Selection

When the starting train is placed, the mod:

  1. Collects all valid train definitions from all data packs
  2. Filters out trains whose biome whitelist/blacklist excludes the placement biome
  3. Selects one train from the remaining candidates using weighted random selection
  4. If no candidates match, falls back to the built-in default train.nbt

The selection uses the world seed as the random seed, so the same world seed always produces the same train.

Weight Examples

Train A Weight Train B Weight Train A Chance Train B Chance
10 10 50% 50%
20 10 67% 33%
1 99 1% 99%

Examples

Multiple Train Variants

Add several trains that spawn with equal probability:

data/my_trains/railwaysuntold/trains/steam_locomotive.json

{
  "schematic": "my_trains:trains/steam_locomotive",
  "front_facing": "auto",
  "weight": 10
}

data/my_trains/railwaysuntold/trains/diesel_engine.json

{
  "schematic": "my_trains:trains/diesel_engine",
  "front_facing": "north",
  "weight": 10
}

Biome-Specific Trains

A snow train that only spawns in snowy biomes:

data/my_trains/railwaysuntold/trains/snow_train.json

{
  "schematic": "my_trains:trains/snow_train",
  "front_facing": "auto",
  "weight": 10,
  "biome_whitelist": ["#minecraft:is_overworld", "#c:is_snowy"]
}

A desert cargo train excluded from cold biomes:

data/my_trains/railwaysuntold/trains/desert_cargo.json

{
  "schematic": "my_trains:trains/desert_cargo",
  "front_facing": "auto",
  "weight": 5,
  "biome_blacklist": ["#c:is_snowy", "#c:is_cold/overworld"]
}

Rare Train

A special train that spawns rarely (1 in 11 chance alongside the default):

data/my_trains/railwaysuntold/trains/golden_express.json

{
  "schematic": "my_trains:trains/golden_express",
  "front_facing": "auto",
  "weight": 1
}

Loot Tables

You can assign loot tables to containers (chests, barrels, etc.) on train carriages. The loot system works identically to event loot tables — see the Events documentation for full details on the loot configuration format, container tagging, and resolution order.

Loot tables on trains are applied during assembly. The loot is deferred — items are generated when a player first opens the container on the train, using vanilla Minecraft's loot table mechanism.

Example: Cargo Train with Loot

{
  "schematic": "my_trains:trains/cargo_train",
  "front_facing": "auto",
  "weight": 10,
  "loot": {
    "by_type": {
      "minecraft:chest": "my_trains:loot/cargo_chest"
    },
    "by_tag": {
      "coal_supply": "my_trains:loot/coal",
      "iron_supply": "my_trains:loot/iron_ingots"
    }
  }
}

Reloading

Train definitions are loaded as part of Minecraft's data pack system. Changes take effect:

  • When starting/loading a world
  • After running the /reload command

Note that the starting train is only placed once when the world is first generated. Reloading the definition does not replace an already-placed train.

Dependencies

Some train features (non-standard bogey types, custom track materials) may require the Steam 'n' Rails mod. If the schematic references blocks from mods that aren't installed, the mod logs warnings but still attempts to load the train.

⚠️ **GitHub.com Fallback** ⚠️