//Selectors
介紹
Traincarts增加了可用於列車或列車乘客的目標選擇器,類似於原版Minecraft中的@e選擇器的功能。除了通常基於位置的目標選擇器參數外,還可以使用其他列車屬性來選擇符合特定條件的列車。這些選擇器可以與其他插件一起使用。若一個選擇器針對多個玩家或列車,那麼整個命令會針對每個玩家或列車重複執行。
存在兩個選擇器:@train和@ptrain。兩者都使用相同的選擇器條件,這將在下文詳述。
要快速預覽遊戲中可用的條件,請使用/train info --train @ptrain[等Traincarts命令,該命令會顯示支持的條件。
快速命令示例
| 實例 | 描述 |
|---|---|
| /say hello @ptrain[distance=..5] | 向5格及以內的列車上的乘客發送「hello」。 |
| /kick @ptrain[name=train23] | 踢出名為「train23」的列車上的乘客。 |
| /train destroy --train @train[destination=InterState5] | 銷毀目的地為「InterState5」的列車。 |
| /train eject --train @train[dx=-2..2,dy=-3..3,dz=-2..2] | 在以命令執行者為中心設置的長方體範圍內彈出列車。 |
| /train launch 0.5 --options 2 --train @train[tag=express] | 將帶有「express」標籤的列車在2格後啟動到0.5的速度。 |
條件
可以指定多個條件,條件之間為邏輯與。所有基於數值的條件都支持Minecraft範圍語法:a..b。例如,-5..5(-5到5),..6(6或更小)和12..(12或更大)。在條件前面加上!會反轉條件,檢測某條件是否「不」滿足。
在下面的所有示例中,若要針對列車上的乘客,可以將@train替換為@ptrain。
長方體
x/y/z條件指定了世界上要選擇的列車的位置,其指定的是一個長方體區域。也可以指定dx/dy/dz來擴大長方體。如果僅指定 dx/dy/dz,則使用命令執行者的 x/y/z 坐標。可以使用world(世界)條件在特定世界上運行,或從無法推斷世界的服務器控制台運行。
| @train[x=10..12,y=23..56,z=-100..-80] | All trains in cuboid (10, 23, -100) -> (12, 56, 80) |
| @train[x=10,y=23,z=-100,dx=2,dy=33,dz=20] | Same as above, but specified with dx/dy/dz to 'grow' the cuboid |
| @train[x=10,y=10,z=10,dx=-2..2,dy=-10..10,dz=-2..2] | Complex use: grows the cuboid from point (10, 10, 10) in both directions. This becomes cuboid (8, 0, 8) -> (12, 20, 12) |
| @train[dx=-10..10,dy=-5..5,dz=-10..10] | Selects a cuboid around the sender (command block / player) of the command |
| @train[world=world_the_end,x=10,y=89,z=-20,dx=-10..10,dy=-10..10,dz=-10..10] | The world name to target can be used to target trains on other worlds |
Distance
The distance condition filters trains based on distance to the sender, or a cuboid specified. This is a spherical distance.
| @train[distance=..10] | All trains 10 blocks or less away from the sender |
| @train[distance=1000..] | All trains 1000 blocks away or more from the sender |
| @train[x=100,y=50,z=-100,distance=..5] | All trains 5 blocks or less away from coordinate (100, 50, -100) |
| @train[x=10,y=10,z=10,dx=50,dz=50,distance=..10] | All trains 10 blocks or less away from cuboid (10, 10, 10) -> (60, 10, 60) |
Sort and Limit
The sort and limit conditions can be used to pick a single result from many based on distance, or to pick limited results at random. Sort supports conditions nearest, furthest and random. Limit must be a natural integer.
| @train[distance=..100,sort=random,limit=1] | Picks a single random train 100 blocks away or less |
| @train[distance=..100,sort=nearest,limit=2] | Picks at most 2 nearest trains, 100 blocks away or less |
| @train[distance=1000..,sort=furthest,limit=10] | Picks at most 10 trains furthest away, 1000 blocks distance away or more |
Train Name
The name condition can be used to select trains by name, or a name pattern. Supports the same wildcard pattern rules as the remote control syntax.
| @train[name=train12] | Selects train with name 'train12' |
| @train[name=Intercity*Express] | Selects trains with name starting with "Intercity" and ending with "Express" |
| @train[name=*] | Selects all trains on the world |
Train Tags
The tag condition, which can be specified multiple times, can be used to select the tags assigned to trains and filter on those. Like the name condition, this supports a wildcard pattern. This only checks that a particular tag is or isn't present, not that it is the only tag present.
| @train[tag=mytag] | Selects trains that have tag 'mytag' |
| @train[tag=*fast,tag=!express] | Selects trains that have a tag ending with 'fast', but do not have tag 'express' |
Passenger Count
The passengers and playerpassengers conditions select the trains that meet a certain number of (player) passengers. This supports the range command to check for 'at least' a number of passengers, such as @train[passengers=5..]
Derailed
The derailed condition selects trains that have derailed. For example: @train[derailed=1] or @train[derailed=true]
Unloaded
The unloaded condition selects trains that are inside unloaded chunks and are therefore no longer simulated. Example: @train[unloaded=1] or @train[unloaded=true].
Trains that keep chunks loaded do not unload.
Speed
The speed condition (alias: velocity) selects trains that move at a certain speed. This is the actual movement speed, which is at most the speed limit set for the train. Example: @train[speed=0] for trains that are not moving.
Miscellaneous Properties
More might be added in the future, but the additional properties can be used to filter the selection
| destination | Destination set for the train |
| friction | Friction modifier of the train (default: 1) |
| gravity | Gravity modifier of the train (default: 1) |
| keepchunksloaded | Whether the train keeps nearby chunks loaded |
| speedlimit | Speed limit set for the train |
| ticket | Same checks as for tags, but for ticket names instead |