-
Notifications
You must be signed in to change notification settings - Fork 0
Trains
A Furnace Minecart that has fuel and is on rails acts as a locomotive. Every tick, it scans for nearby minecarts behind it and attaches them as trailers, up to a maximum of 7 trailers (8 carts total including the locomotive).
Every tick the locomotive runs a two-pass scan, starting from itself and then from each already-attached trailer:
- First pass: any non-furnace minecart overlapping the anchor's bounding box (inflated by 0.2) that is not already in a train and is on a rail gets attached.
- Second pass (only if first finds nothing): a probe is stepped one rail segment behind the anchor, and the same filter runs on the probe's bounding box.
The whole chain of touching carts attaches in a single tick, so a line of 5 carts behind the locomotive couples on the same frame you place them.
Dispenser minecarts can be attached as trailers.
The locomotive places a single "probe" minecart at its own position with a velocity pointing backward along its yaw (magnitude 1.5). For each trailer in order:
- The trailer is ticked on its own rail physics (gives it a natural yaw and rail state).
- The probe is advanced one rail segment.
- If the trailer is within 4 blocks of the probe, it snaps to the probe's position, matches yaw and pitch, and takes a forward velocity matching the locomotive's current horizontal speed.
- If the trailer is farther than 4 blocks, the cascade stops for the rest of the chain this tick. The overshooting trailer remains in the train list and is still given a forward-along-yaw velocity, but is no longer position-snapped.
The probe walks the rail continuously; it is not reset per trailer. So the spacing along a curve is measured in rail distance, not straight-line distance.
Each cart in the train reduces the locomotive's max speed by 5%. Formula (with train.size being the number of trailers):
cap * (1 - 0.05 * (trainSize + 1))
Full 1+7 train: 60% of normal cap.
A trailer is removed from the train if any of these is true on a given tick:
- The trailer has been removed from the world.
- The trailer has lost its
traincommand tag. - The trailer is on the ground and its horizontal speed is below 0.01.
When a trailer is removed, all trailers behind it are removed as well, and a bamboo-break sound plays at each disconnection site.
A secondary age-based safety net clears the train and trainMove command tags of any minecart whose tickCount exceeds 60 without being controlled by a locomotive tick. This handles orphaned trailers if the locomotive despawns, unloads, or enters a portal.
When the locomotive's fuel drops below 100 ticks, it scans the first trailer. If that trailer is a chest minecart or hopper minecart, the locomotive:
- Iterates slots in order.
- Picks the first slot with a fuel item.
- Consumes 1 item (or replaces a lava bucket with an empty bucket).
- Adds the item's full burn duration to the locomotive's fuel.
- Stops scanning once one fuel item was pulled.
Only the first trailer is checked. If slots 2-7 of the train also contain fuel, they are not pulled from.
While a furnace minecart is on a powered rail and has fuel remaining, its lit state follows the rail's powered property each tick:
- Powered rail with
powered=true: cart stays lit. - Powered rail with
powered=false: cart extinguishes (fuel preserved).
Passing over an unpowered powered rail is a zero-cost way to park a train. Passing back over a powered-on rail relights it.
When a locomotive passes through a portal, the train breaks immediately: all trailer train and trainMove tags are cleared, the trailer list empties, and the trailers are left behind as normal minecarts.
If a player is riding a trailer (train tag) and they disconnect from the server, they are dismounted before the disconnect. This avoids carrying a ghost seat through logout.
The server broadcasts the train chain (locomotive UUID plus ordered trailer UUIDs) to all players tracking the locomotive whenever the chain composition changes, plus a heartbeat every 20 ticks.
The client stores chains in a cache with a 3-second stale window. Each cart drawn with a known predecessor gets a leash rendered from its body (offset 0.12 upward) to the predecessor's rope-hold anchor (offset 0.3 downward). The leash is rigid, not draped.
If no update arrives for a cart within 3 seconds, its leash stops rendering.
- Sharp 90-degree corners at high speed can drop the probe outside the 4-block snap radius, causing the cart behind to fall back to its own yaw-based momentum for a tick before re-syncing.
- The leash uses vanilla rendering, so it appears as the standard leash visual.
- Only one locomotive per train. Two furnace minecarts cannot jointly share a chain.
- Mounting logic uses vanilla interact, so right-clicking a trailer enters it as a passenger.
Start Here
Systems
Mechanics