Repository navigation
World position
Where the train is in the world, in world coordinates, not sub level ones.
The point the carriage body turns around, as {x, y, z}.
It is the physics center, not the corner of any block, so it falls between block coordinates rather than on them.
One point for the whole carriage. To find one block, use getWorldPosOf below.
local p = train.getWorldPos()
print(string.format("%.1f %.1f %.1f", p.x, p.y, p.z))123.5 71.0 -840.2
Distance from the train to a fixed point:
local p = train.getWorldPos()
local dx, dz = p.x - 100, p.z - 250
print(string.format("%.1f blocks from the depot", math.sqrt(dx * dx + dz * dz)))1090.4 blocks from the depot
Every block matching blockId anywhere in the consist, as a list of {x, y, z}
tables in world coordinates.
Use full ids only. "minecraft:chest", never "chest".
Only blocks with a block entity are found. It reads each carriage's list of block entities, so a
chest, a tank or a controller is found and a plain minecraft:stone is not.
It searches the whole train, every carriage, not only the one with the axle.
An empty list when nothing matches, not nil, so test with #result == 0 and it is
safe to loop over either way.
It has its own name rather than an argument because Lua has no overloading.
for i, pos in ipairs(train.getWorldPosOf("minecraft:chest")) do
print(string.format("chest %d at %.1f %.1f %.1f", i, pos.x, pos.y, pos.z))
endchest 1 at 122.5 71.5 -838.5
chest 2 at 122.5 71.5 -839.5
chest 3 at 124.5 71.5 -841.5
ipairs reads a plain list in order, 1, 2, 3, which is what this returns. To
count them instead:
local chests = train.getWorldPosOf("minecraft:chest")
print(#chests .. " chests aboard")3 chests aboard
Start here
Reading the train
- Identity
- Motion
- State
- Station
- Signals
- Track ahead
- Orientation
- World position
- Carriages
- Consist wide cargo
Driving the train
Schedules
Doors and body
Links
The whole railway
Reacting to changes
Programs and reference
Start here
Controlling the plate
Automatic modes
Reading the turntable
Reference