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 have type-specific properties that can be checked using specialized sub-predicates. Here are some examples:
Available type-specific checks include:
axolotlTypeSpecific
- Axolotl variantscatTypeSpecific
- Cat variantsfishingHookTypeSpecific
- Fishing hook propertiesfoxTypeSpecific
- Fox variantsfrogTypeSpecific
- Frog variantshorseTypeSpecific
- Horse variantslightningTypeSpecific
- Lightning propertiesllamaTypeSpecific
- Llama variantsmooshroomTypeSpecific
- Mooshroom variantspaintingTypeSpecific
- Painting variantsparrotTypeSpecific
- Parrot variantsplayerTypeSpecific
- Player properties (gamemode, recipes, input)rabbitTypeSpecific
- Rabbit variantsraiderTypeSpecific
- Raider propertiessalmonTypeSpecific
- Salmon variantssheepTypeSpecific
- Sheep propertiesslimeTypeSpecific
- Slime sizetropicalFishTypeSpecific
- Tropical fish variantsvillagerTypeSpecific
- Villager typeswolfTypeSpecific
- Wolf variants
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.