Skip to content

Mathematical Expressions

Getting Started

In addition to simple variable reading, there is a more advanced option using mathematical expressions. You can experience the full power of this method using the rpt:expression model.

json
{
    "model": {
        "type": "rpt:expression",
        "value": "foo + 1",
        "cases": [
            {
                // can specify as a single value:
                "when": [ 6 ],
                // "all" defaults to false. If true, all conditions in "when" 
                // must be met for this case to be selected:
                "all": true 
                "model":  { ... }  // This model will update because 5 + 1 = 6!
            }
        ]
    },
    "rpt": {
        "variables": {
            "numbers": {
                "foo": 5
            }
        }
    }
}

Besides exact matching, in when you can specify other expressions for comparison, constants, and functions. You can find a list of all these in the EvalEx documentation.

json
{
    "model": {
        "type": "rpt:expression",
        "value": "SIN(5) + PI", 
        "cases": [
            {
                "when": [ ">=0" ], 
                "model": {
                    "type": "model",
                    "model": "item/diamond"
                }
            }
        ]
    }
}

Game Variables

Along with variables from rpt, game variables can also be used in expressions:

1. Global Variables and Time

VariableDescriptionDefault Value
gameTimeTotal game time in ticks since world creation.0
dayTimeTime of the current day in ticks (0 to 24000).0
seedUnique numeric seed for the current render context.Passed from context

2. Entity (Holder) Parameters

These parameters refer to the creature (player or mod) holding the item.

VariableDescriptionDefault Value
holderXX coordinate of the entity position in the world.0
holderYY coordinate of the entity position in the world.0
holderZZ coordinate of the entity position in the world.0
yawHorizontal rotation of the entity (in degrees).0
pitchVertical rotation of the entity (head tilt).0
healthCurrent health amount of the entity.20
maxHealthMaximum possible health of the entity.20
fallDistanceEntity fall distance.0
motionXSpeed along the X axis.0
motionYVertical speed (positive when jumping, negative when falling).0
motionZSpeed along the Z axis.0
speedTotal movement speed of the entity.0
horizontalSpeedHorizontal movement speed (X and Z).0
onGroundWhether the entity is on the ground (1 - yes, 0 - no).0
isSprintingWhether the entity is sprinting (1 - yes, 0 - no).0
isCrouchingWhether the entity is crouching (1 - yes, 0 - no).0
isInWaterWhether the entity is in water (1 - yes, 0 - no).0
isInLavaWhether the entity is in lava (1 - yes, 0 - no).0
isSwimmingWhether the entity is swimming (1 - yes, 0 - no).0
isFallFlyingWhether the entity is flying with elytra (1 - yes, 0 - no).0
isAliveWhether the entity is alive (1 - yes, 0 - no).0
isOnFireWhether the entity is on fire (1 - yes, 0 - no).0
isInvisibleWhether the entity is invisible (1 - yes, 0 - no).0
hurtTimeTime since damage was received (in ticks).0
deathTimeTime since death (in ticks).0
invulnerableTimeRemaining invulnerability time (in ticks).0
ageEntity age in ticks (relevant for passive mobs).0

3. Player Parameters

Available only if the item is held by a player. Otherwise, standard values are returned.

VariableDescriptionDefault Value
foodCurrent player hunger level (0 - 20).20
saturationPlayer saturation level (hidden food scale).5
experienceLevelCurrent experience level (number above experience bar).0
xpProgressProgress to next experience level (0.0 to 1.0).0.0
totalXpTotal player experience amount.0.0
armorTotal armor points value on the player.0
airCurrent air supply (in ticks).0
maxAirMaximum air supply (in ticks).0
attackCooldownCurrent attack readiness (0.0 to 1.0).0.0
sleepingWhether the player is sleeping (1 - yes, 0 - no).0
attackProgressAnimation progress of a hit from 0 to 1.0
usageProgressAnimation progress of using an item from 0 to 1.0
isSlimIs player arms slim: 1 - yes, 0 - no0

4. Environment and Lightin

VariableDescriptionDefault Value
lightSkySky lighting level at current position (0 - 15).0
lightBlockLighting level from blocks (torches, lamps) (0 - 15).0
lightTotalMaximum value between lightSky and lightBlock.0
biomeTempBase temperature of the biome where the entity is located.0
sunAngleSolar angle in the sky (0.0 to 1.0).0.0
moonPhaseCurrent moon phase (integer from 0 to 7).0

Released under the MIT License.