Skip to content

Conditions

McHorse edited this page Jun 20, 2021 · 10 revisions

Conditions is a Mappet mechanism that allows to check something, kind of like expressions do, but using GUI and different condition blocks. If you're not good with coding, you may try using conditions instead of expressions.

Conditions are available in every checker component.

Mechanics

Conditions can have multiple condition blocks, which examine the current context and return a boolean value (which basically means yes or no, on or off, positive or negative, true or false, 1 or 0).

Condition goes over those blocks and evaluate them one by one from top to bottom. By default if all blocks return a positive then condition works and enables whatever it should've enabled (for example enabling redstone signal in an emitter). Individual blocks can be inverted or compared using OR (meaning instead comparing using OR instead of AND), and even nested by using condition block.

Demonstration

Let's say we have following condition:

Simple condition

By default, this will read as: if player "Holds a Grass Block" and "Is day?" Only in case when all of these conditions are true, i.e. the player is actually holding a block and it's day (the world time is between 0 and 12000).

This scenario can be summarized by following table:

Block Result
Holds Grass Block true
Is day? true

But once one of those becomes false, for example player stops holding a grass block, then the condition will return a negative result. But, if you want the player to hold grass block or it should be day, in that case you'll need to mark "Is day?" block as OR like this:

Marking as OR

Then the condition will send a positive result either, if the player will hold a grass block, or it's day. It will read as: if player "Holds a Grass Block" or "Is day?" The ❗ allows to invert the result returned by a block, so if we'll go to "Holds Grass Block" block and enable inversion:

Marking as NOT

Then the condition will read as: if player not "Holds a Grass Block" or "Is day?" So the emitter will emit the redstone signal, if the player doesn't hold a grass block, or it's day. If you'll add into this nested conditions, it will get even more crazier. What I would recommend in such situations is reading those blocks out loud, and seeing if it makes sense.

Editing

When a checker component is toggled in a condition state (when Edit condition... button is present) click on the Edit condition... button and it will open condition editor modal:

Empty condition editor

By right clicking where it says Right click here... and Add a condition... will allow you to add a condition. Try adding a World time condition block. After adding the block, on the left you will see condition block list, and on the right the condition block editor.

Condition editor

By right clicking you can also remove and copy/paste conditions. If you have multiple condition blocks in the list, you can also sort them by drag and dropping.

Condition blocks

At the moment of writing of this documentation, condition editor supports following condition blocks:

  • Quest block, this block allows to check whether player(s) (or the world) has no quests in-progress or completed (i.e. absent), in-progress quests or completed quests.
  • State block, this block allows to compare a state of a player or of the world.
  • Dialogue block, this block allows to check whether a player read a dialogue.
  • Faction block, this block allows to check player's relationship with a faction.
  • Item block, this block allows to check whether a player holds, equips or has an item in the inventory.
  • World time block, this block allows to check world's time.
  • Entity block, this block allows to compare entity's property.
  • Condition block, this block allows to setup nested conditions.

Every condition block has two icon buttons similar to ❗ and 🔀 emojis. ❗ allows you to inverse the result of the block, while 🔀 allows you to mark the block to be combined with previous result using OR instead of AND.

Quest block

In a quest block, you can pick quest's ID, the completion state (absent, present or completed) and the target player (see below for more information about target).

State block

In a state block, you can pick the key of a state, target where to look for the state (see below for more information about target) and comparison mode (see below for more information about comparison modes).

Dialogue block

In a dialogue block, you can pick dialogue's ID, the marker ID and the target player (see below for more information about target).

Faction block

In a faction block, you can pick faction's ID, faction comparison mode, the target player (see below for more information about target) and comparison mode (see below for more information about comparison modes)

Faction comparison mode can be:

  • Aggressive checks whether attitude towards found player is aggressive.
  • Passive checks whether attitude towards found player is passive.
  • Friendly checks whether attitude towards found player is friendly.
  • Score checks faction scare of the found player using comparison mode.

Item block

In an item block, you can pick any item stack, item comparison mode and the target player (see below for more information about target).

Item comparison mode can be:

  • Held (hands) checks whether the player must hold in hands (stack count isn't accounted for).
  • Equipment (armor) checks whether the player has an item stack equipped in an armor slot (i.e. helmet, chestplate, leggings or feet).
  • Inventory checks whether the player has an item stack in the inventory.

World time block

In a world time block, you can pick time condition mode, and range (but only if time condition range is Range).

Time condition mode can be:

  • Is day? checks whether it's day in the world (012000).
  • Is night? checks whether it's night in the world (1200024000).
  • Range checks whether world's time is between minimum (the left field) and maximum (the right field).

Entity block

In an entity block, you can pick the property of given target (see below for more information about target) and compare the value of that entity's property using comparison.

Entity block supports following properties here are two lists of common and player-only properties. Player-only properties:

  • Armor, how much armor points does the player has, it should between 0 and 20, where 20 is when player wears a full diamond armor set.
  • Experience level, how many levels (the number in the middle of the level bar) does the player has.
  • Hunger, how many hunger points does the player has, 20 is the full hunger bar.
  • Total experience, how many experience points in total did a player accumulate, see this page for more information about exact values.

If player properties will be used with entities that aren't players, then the output value will be 0. Common entity properties:

  • Health, how many health points does the entity has, zombies, skeletons and players have 20 health points by default (10 hearts).
  • Is on ground, boolean of whether the entity is on the ground (either walks or idles).
  • Is sneaking, boolean of whether the entity is sneaking.
  • Is sprinting, boolean of whether the entity is sprinting (technically any entity can sprint, but only players can sprint on regular basis).
  • Light (sky), what is the sky lighting value the entity is currently on. It outputs a value between 0 (fully underground) and 15 (fully on the sunlight/moonlight, basically outside).
  • Light (torch), what is the light source (torch, glowstone, lamps, etc.) lighting value the entity is currently on. It outputs a value between 13 (standing next to a light source) and 0 (fully out of any light source reach).
  • Ticks existed, for how many ticks did an entity existed during runtime (this means that this value is lost once the server shutdown or player exits the world).
  • X head rotation (pitch), what is the entity's vertical head rotation, it should be between -90 (fully looking up) and 90 (fully looking down).
  • Y head rotation (yaw), what is the entity's horizontal head rotation, it should be between -180 and 180, where 0 is south, -90 is east, 90 is west, and -180/180 is north. North is a special case, so if you want to check whether player looks at north, use expression comparison mode with x > 179 || x < -179 expression.

Note: boolean is a number that is either 1 (true) or 0 (false). For boolean properties, you can use Is true an Is false comparison modes.

Condition block

In a condition time block, you can edit the nested condition by clicking Edit condition... button which will open another condition editor on top of current condition editor. There you can edit conditions.

Targeting

In most condition block editors, there is Target button which allows to toggle between different targeting modes.

  • Global targets the world/server.
  • Subject targets the subject entity in event's context.
  • Object targets the object entity in event's context.
  • Selector targets one player by given target selector (if target selector finds more than one player it return voids the check of the block).
  • Player targets the first player, i.e. if subject is a player, it will target subject, if object is a player, but subject is an NPC, then it will target object.
  • NPC targets the first NPC, i.e. if subject is an NPC, it will target subject, if object is an NPC, but subject is a player, then it will target object.

Comparison

In some condition block editors, there is Comparison module which allows setup comparison of found value. The value field allows to set the target value against which the comparison will be evaluated. Consider that found and target are variables, then comparison operators will work like this:

  • found < target (<), true if found is less than target
  • found <= target (<=), true if found is less than or equals to target
  • found == target (==), true if found equals to target
  • found >= target (>=), true if found is greater than or equals to target
  • found > target (>), true if found is greater than target
  • Is true, true if found is not 0
  • Is false, true if found is 0

Expression comparison

Expression comparison mode allows you to input custom math expression that should evaluate to any non-zero value for true. x and/or value variables can be used to compare the value given from a condition block for comparison.

For example, let's say you want to check whether player looks at the horizon. This can be easily checked by adding an Entity condition block, pick the property X head rotation (pitch), configure the target, switch to Expression comparison mode, and input x < 7 && x > -7 (assuming that 14 degrees is enough to consider looking at the horizon).

Looking at horizon condition

Once the condition is setup, if I'll look at the horizon (or anywhere in between -7 and 7 degrees vertically), the emitter block will emit the redstone signal. If I'll look below -7 or above 7, the emitter block will stop emitting the redstone signal.

Redstone signal emission