//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] | 選擇所有在(10,23,-100)->(12,56,80)內部的列車。 |
| @train[x=10,y=23,z=-100,dx=2,dy=33,dz=20] | 同上,但使用dx/dy/dz來「擴大」長方體。 |
| @train[x=10,y=10,z=10,dx=-2..2,dy=-10..10,dz=-2..2] | 複雜用法:以點(10,10,10)為中心,在x和z軸的正方向和負方向上各延伸2格,在y軸的正方向和負方向上各延伸10格。將長方體變為(8,0,8)->(12,20,12)。 |
| @train[dx=-10..10,dy=-5..5,dz=-10..10] | 在命令執行者(命令方塊或玩家)周圍選擇的長方體。 |
| @train[world=world_the_end,x=10,y=89,z=-20,dx=-10..10,dy=-10..10,dz=-10..10] | 指定世界名稱可用於定位其他世界的列車。 |
距離
distance(距離)條件根據與命令執行者之間的距離(球面距離)或指定的長方體來選擇列車。
| @train[distance=..10] | 距離命令執行者10格及以內的所有列車。 |
| @train[distance=1000..] | 距離命令執行者1000格及以外的所有列車。 |
| @train[x=100,y=50,z=-100,distance=..5] | 距離坐標(100, 50, -100)5格及以內的所有列車。 |
| @train[x=10,y=10,z=10,dx=50,dz=50,distance=..10] | 距離長方體(10, 10, 10)->(60, 10, 60)10格及以內的所有列車。 |
排序和限制
sort(排序)和limit(限制)條件可根據距離從多個結果中選取一個結果,或隨機選取有限的結果。Sort支持nearest(最近)、furthest(最遠)和random(隨機)條件。Limit必須為一個自然整數。
| @train[distance=..100,sort=random,limit=1] | 隨機選擇100格及以內的1輛列車。 |
| @train[distance=..100,sort=nearest,limit=2] | 至多選擇100格及以內的最近的2輛列車。 |
| @train[distance=1000..,sort=furthest,limit=10] | 至多選擇1000格及以外的最遠的10輛列車。 |
列車名稱
name(名稱)條件按名稱或名稱模式選擇列車。支持遠程控制語法中的通配符。
| @train[name=train12] | 選擇名為「train12」的列車。 |
| @train[name=Intercity*Express] | 選擇名稱以「Intercity」開頭且以「Express」結尾的列車。 |
| @train[name=*] | 選擇世界上所有的列車。 |
列車標籤
tag(標籤)條件可以多次指定,可選擇列車標籤並對其進行篩選。與name(名稱)條件相同,支持通配符。該條件只檢測特定標籤是否存在,而不是表示是否只存在某一標籤。
| @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 |