Difference between revisions of "TrainCarts/Signs/Statements"

From BergerHealer Wiki
Jump to navigation Jump to search
(Marked this version for translation)
 
(3 intermediate revisions by 3 users not shown)
Line 5: Line 5:
  
 
<!--T:2-->
 
<!--T:2-->
The [http://www.minecraftwiki.net/wiki/Bukkit/TrainCarts/Signs/Switcher switcher] and [http://www.minecraftwiki.net/wiki/Bukkit/TrainCarts/Signs/Detector detector] signs use statements to perform a certain task. In the case of the switcher sign, toggling the lever and tracks. The third and fourth lines are used to put these statements, which are parsed by the plugin automatically.There are multiple syntax rules, which will be expanded whenever something new needs to be evaluated.
+
The [[TrainCarts/Signs/Switcher|switcher]], [[TrainCarts/Signs/Detector|detector]] and [[TrainCarts/Signs/Skip|skip]] signs use statements to conditionally switch track, toggle levers or perform other kinds of actions. Typically the third and fourth lines of signs are used to put these statements. You can also typically add additional signs below the sign to expand the number of statements indefinitely.
 
 
<!--T:3-->
 
The third and fourth lines act as a logical ''or'' when toggling the lever. When either of the two statements are correct, it will toggle the lever. You can use the output of this lever to power another sign, possibly making complete logic routines using minecarts.
 
 
 
  
 
=== Use cases === <!--T:4-->
 
=== Use cases === <!--T:4-->
  
 
<!--T:5-->
 
<!--T:5-->
Generally you won't need to use statements. The internal path finding can do most of the required path finding, and anything else can be done using redstone. But, if you have to categorize carts based on certain properties, using these statements is inevitable. A few examples where this can be used.
+
For routing trains around your Minecraft world, the [[TrainCarts/PathFinding|path finding]] feature is more than adequate. If you need to categorize carts based on certain attributes and then conditionally activate certain signs or send the train a certain way, then statements cover that gap. A few examples where this can be used.
 
 
  
 
==== Remove empty minecarts ==== <!--T:6-->
 
==== Remove empty minecarts ==== <!--T:6-->
Line 21: Line 16:
 
<!--T:7-->
 
<!--T:7-->
 
If the minecart contains no passenger, a destructor sign is powered.
 
If the minecart contains no passenger, a destructor sign is powered.
 
  
 
==== Send the train once it contains items ==== <!--T:8-->
 
==== Send the train once it contains items ==== <!--T:8-->
Line 27: Line 21:
 
<!--T:9-->
 
<!--T:9-->
 
Once the train contains an item, power a station sign.
 
Once the train contains an item, power a station sign.
 
  
 
==== Send a train to a certain player ==== <!--T:10-->
 
==== Send a train to a certain player ==== <!--T:10-->
Line 33: Line 26:
 
<!--T:11-->
 
<!--T:11-->
 
If the cart is owned by a set player, the track is toggled to lead to that player.
 
If the cart is owned by a set player, the track is toggled to lead to that player.
 
  
 
== Syntax == <!--T:12-->
 
== Syntax == <!--T:12-->
Line 131: Line 123:
 
| One of the players has one of the items in his hand
 
| One of the players has one of the items in his hand
 
|-
 
|-
|ed@<directions>
+
| ed@<directions>
 
|The minecart is moving into a given direction (switcher: upon entering the sign)
 
|The minecart is moving into a given direction (switcher: upon entering the sign)
 
|-
 
|-
Line 137: Line 129:
 
| The sign is powered from one of the directions specified
 
| The sign is powered from one of the directions specified
 
|-
 
|-
| rand@30%
+
| rand@0.3
| Has a 30% chance of turning on (instead of the default 50%)
+
| Has a 30% chance of turning on (instead of the default 50%) (1.0 is equivalent to 100%)
 
|-
 
|-
 
| anything<br>t@<tags>
 
| anything<br>t@<tags>
 
| For anything else the plugin checks if the train has it set as a tag
 
| For anything else the plugin checks if the train has it set as a tag
 
|}
 
|}
 
  
 
== And logic == <!--T:16-->
 
== And logic == <!--T:16-->

Latest revision as of 04:21, 31 December 2023

Other languages:

Introduction

The switcher, detector and skip signs use statements to conditionally switch track, toggle levers or perform other kinds of actions. Typically the third and fourth lines of signs are used to put these statements. You can also typically add additional signs below the sign to expand the number of statements indefinitely.

Use cases

For routing trains around your Minecraft world, the path finding feature is more than adequate. If you need to categorize carts based on certain attributes and then conditionally activate certain signs or send the train a certain way, then statements cover that gap. A few examples where this can be used.

Remove empty minecarts

If the minecart contains no passenger, a destructor sign is powered.

Send the train once it contains items

Once the train contains an item, power a station sign.

Send a train to a certain player

If the cart is owned by a set player, the track is toggled to lead to that player.

Syntax

You can put a !-sign in front of the statement to act as a NOT. You can read 'the train' as 'the cart' if [cart] is used on the first line. Statements with the format name@<array> are called array statements and can operate on multiple of a certain property. For example, i@wood operates on the items in the train, and checks if there is wood in there. For multiple items, delimit using a semicolon ( ; ), for example ed@north;south will match trains moving towards north or south only.

Most statements also support operators. Operators are:

  • = equals
  • != not equals
  • >= greater or equal than
  • <= smaller or equal than
  • > greater than
  • < smaller than

To use an operator, append it after the statement. For example, minecarts>=5 will check if there are more than 5 minecarts in the train. trainsize>=5 also counts storage and powered minecarts. You can even use it in arrays. Using i@stone=64 you can check if there are exactly 64 stone in the train. All statements that can be interpreted as an amount have operator support, including counting the amount of mobs in the train: m@cow>5. If no operator is given the default operator >0 is used, or in the case of items, the amount that is specified in front of the item name.

Statement Meaning
passenger The train has a passenger
items The train contains a chest and has items
empty The train has no passenger and no items
fuel The train contains a furnace which has fuel
trainsize The train cart count matches (e.g.: trainsize>=3)
chest_minecart The train has a number of chest minecarts (e.g.: chest_minecart>=1). Also works for hoppers/powered/etc. types.
velocity
speed
The train velocity (movement speed) can be evaluated, or gets if the train is moving
powered The train contains a powered minecart
storage The train contains a storage minecart
minecart The train contains a regular minecart
redstone The sign is powered by redstone
maxspeed Evaluate the maximum speed set
mobenter Checks the mob enter property
playerenter Checks the player enter property
playerexit Checks the player exit property
destination Checks if a destination is set on the train
random Has a 50% chance of turning on
n@<names>
name@<names>
The train name equals one of the names specified
i@<items> The train contains one of the items specified
o@<owner> The train contains this owner
d@<destination> One cart in the train has this destination set
p@<player> The train is occupied by this player
m@<mobnames> The train is occupied by one of these mobs
pi@<items> One of the players has one of the items in his inventory
ph@<items> One of the players has one of the items in his hand
ed@<directions> The minecart is moving into a given direction (switcher: upon entering the sign)
rs@<directions> The sign is powered from one of the directions specified
[email protected] Has a 30% chance of turning on (instead of the default 50%) (1.0 is equivalent to 100%)
anything
t@<tags>
For anything else the plugin checks if the train has it set as a tag

And logic

Since everything is evaluated as an OR, how can you check if the train has two of the same? The easiest method is to invert two statements, toggling a lever which powers an inverted sign. For example:

Signtemplate.png
[cart]
switcher
!o@me
!a
Signtemplate.png
[!cart]
chest in
If not owned by 'me' or not has tag 'a' then not transfer items
If owned by 'me' and has tag 'a' transfer items

If this proves too hard to do (you need to evaluate more than 3 statements), you will have to use a redstone circuit and multiple switcher signs instead.


Tags

For all statements other than in the syntax table above, the name is compared to tags on the train. To find the tags, you can use wildcards to check for multiple tags at once:

 * - has a tag
 !* - has no tags
 *a - has a tag ending with 'a'
 a* - has a tag starting with 'a'
 *a* - has a tag containing 'a'
 *ab*cd* - has a tag containing both 'ab' and 'cd'

For example, the following sign uses tags to switch tracks. If the train contains a tag starting with station it goes left, if it contains a tag containing main it will go right. If it contains both, it will go straight ahead.

Signtemplate.png
[!train]
switcher
station*
*main*