Predicates
Predicates in Minecraft are used to check if certain conditions are met. They can be used in various features like advancements, loot tables, and commands. Kore provides a type-safe way to create predicates with a simple DSL.
Basic Usage
Here's a simple example of creating a predicate that checks if a player is holding a diamond pickaxe:
Conditions
Predicates can have multiple conditions that must be met. You can combine them using allOf
or anyOf
:
You can also use the inverted
condition to invert the result of a predicate:
Available Conditions
allOf
- Evaluates a list of predicates and passes if all of them passanyOf
- Evaluates a list of predicates and passes if any one of them passesblockStateProperty
- Checks the mined block and its block statesdamageSourceProperties
- Checks properties of the damage sourceenchantmentActiveCheck
- Checks if an enchantment is activeentityProperties
- Checks properties of an entityentityScores
- Checks the scoreboard scores of an entityinverted
- Inverts another predicate conditionkilledByPlayer
- Checks if there is an attacking player entitylocationCheck
- Checks the current location against location criteriamatchTool
- Checks tool used to mine the blockrandomChance
- Generates a random number between 0.0 and 1.0randomChanceWithEnchantedBonus
- Random chance with enchantment bonusreference
- Invokes another predicate file and returns its resultsurvivesExplosion
- Returns success with probability based on explosion radiustableBonus
- Passes with probability picked from a list, indexed by enchantment powertimeCheck
- Compares the current day time against given valuesvalueCheck
- Compares a number against another number or range of numbersweatherCheck
- Checks the current game weather
Each condition has specific requirements and contexts where it can be used. Some conditions require specific loot context data to be available, while others can be invoked from any context.
Entity Properties
The entityProperties
condition allows you to check various properties of an entity:
Sub-Predicates
Sub-predicates are nested data structures that allow you to define specific properties to check within a predicate condition. Each condition type can have its own set of sub-predicates.
Entity Sub-Predicates
The entityProperties
condition supports various sub-predicates to check different aspects of an entity:
distance
- Check distance between entitieseffects
- Check potion effectsequipment
- Check equipped itemsflags
- Check entity flags (baby, on fire, etc.)location
- Check entity locationmovement
- Check entity movementmovementAffectedBy
- Check what affects entity movementnbt
- Check entity NBT datapassenger
- Check entity passengerperiodicTicks
- Check entity periodic ticksslots
- Check specific inventory slotssteppingOn
- Check block the entity is standing ontargetedEntity
- Check entity being targetedteam
- Check entity teamtype
- Check entity typetypeSpecific
- Check type-specific propertiesvehicle
- Check entity vehicle
The Entity
class will provide all the functions for these sub-predicates.
Entity Type-Specific Properties
Entities can still expose a handful of hard-coded type-specific predicates (mainly utility ones such as fishing hooks, lightning, player, raider, sheep and slime). All the visual variant checks that existed before snapshot 25w04a were migrated by Mojang to the new components system. Kore therefore removed the dedicated helpers (axolotlTypeSpecific
, catTypeSpecific
, …) in favor of component matching.
Component-based variant checks (25w04a +)
You can now query an entity’s data components directly from entityProperties
with the components
block:
Any component you can put on an item can be matched on an entity in exactly the same way – just call the corresponding extension inside the components {}
scope.
Remaining built-in typeSpecific
helpers
These helpers are still available because they cover information that is not represented by components:
fishingHookTypeSpecific
– Fishing-hook propertieslightningTypeSpecific
– Lightning bolt propertiesplayerTypeSpecific
– Player properties (gamemode, recipes, input)raiderTypeSpecific
– Raider propertiessheepTypeSpecific
– Sheep shear flagslimeTypeSpecific
– Slime size
Note All former
*TypeSpecific
helpers that dealt with variants (axolotl, cat, fox, frog, horse, llama, mooshroom, painting, parrot, pig, rabbit, salmon, tropical fish, villager, wolf) have been removed. Update your predicates to use component matching instead.
Item Sub-Predicates
When using matchTool
or checking equipment, you can use item sub-predicates. There are two main ways to check item properties:
- Basic item properties:
- Component Matchers - A powerful system to check component properties:
Component Matchers allow you to check various item components like:
- Attribute modifiers
- Container contents (bundles, shulker boxes)
- Damage and durability
- Enchantments
- Firework properties
- Book contents
- And many more
Each matcher corresponds to a component type in Minecraft and provides type-safe ways to check their properties. For a complete list of available matchers, refer to the arguments.components.matchers
package in the source code.
Using Predicates in Commands
You can use predicates in commands using the execute command:
Item Predicates
You can also create predicates for items with enchantments:
Best Practices
- Give your predicates descriptive names that reflect their purpose
- Use
allOf
andanyOf
to combine multiple conditions logically - Keep predicates focused and reusable
- Test your predicates in-game to ensure they work as expected
Remember that predicates are powerful tools for creating complex conditions in your datapack. They can be used to create sophisticated game mechanics and enhance player experience.