Skip to content

Math Expressions

Getting Started

Beyond simply reading variables, there is a more advanced way to work with them using math expressions. You can experience the full power of this approach with the rpt:expression model:

json
{
    "model": {
        "type": "rpt:expression",
        "value": "foo + 1",
        "cases": [
            {
                "when": [ 6 ], 
                "model":  { ... }  // This model will be used because 5 + 1 = 6!
            }
        ]
    },
    "rpt": {
        "variables": {
            "numbers": {
                "foo": 5
            }
        }
    }
}

In addition to exact comparisons, you can use other comparison expressions, constants, and functions in when. You can find a full list in the EvalEx documentation.

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

Game Variables

Along with variables from rpt, you can also use game variables in expressions:

1. Global Variables and Time

VariableDescriptionDefault Value
gameTimeTotal game time in ticks since the world was created.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 relate to the entity (player or mob) holding the item.

VariableDescriptionDefault Value
holderXX coordinate of the entity's position in the world.0
holderYY coordinate of the entity's position in the world.0
holderZZ coordinate of the entity's position in the world.0
yawHorizontal rotation of the entity (in degrees).0
pitchVertical rotation of the entity (head tilt).0
healthCurrent health of the entity.20
maxHealthMaximum possible health of the entity.20
motionYVertical velocity (positive when jumping, negative when falling).0
ageAge of the entity in ticks (relevant for passive mobs).0

3. Player Parameters

Only available if the item is held by a player. Otherwise, default values are returned.

VariableDescriptionDefault Value
foodCurrent hunger level of the player (0–20).20
saturationSaturation level of the player (hidden food scale).5
experienceLevelCurrent experience level (number above the XP bar).0
armorTotal armor points on the player.0

4. Environment and Lighting

VariableDescriptionDefault Value
lightSkySky light level at the current position (0–15).0
lightBlockBlock light level (torches, lamps, etc.) (0–15).0
lightTotalMaximum value between lightSky and lightBlock.0
biomeTempBase temperature of the biome the entity is in.0
sunAngleSun 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.