Class EntitySelectorOptionRegistry
java.lang.Object
net.fabricmc.fabric.api.command.v2.EntitySelectorOptionRegistry
Contains a function to register an entity selector option.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
register
(Identifier id, Text description, EntitySelectorOptions.SelectorHandler handler, Predicate<EntitySelectorReader> canUse) Registers an entity selector option.static void
registerNonRepeatable
(Identifier id, Text description, EntitySelectorOptions.SelectorHandler handler) Registers an entity selector option.
-
Method Details
-
register
public static void register(Identifier id, Text description, EntitySelectorOptions.SelectorHandler handler, Predicate<EntitySelectorReader> canUse) Registers an entity selector option. The added option is available under the underscore separated ID.Here's an example of a custom entity selector option. The option is registered under
example_min_health
and can be used like@e[example_min_health=5]
.EntitySelectorOptionRegistry.register( Identifier.of("example", "min_health"), Text.literal("Minimum entity health"), (reader) -> { final float minHealth = reader.getReader().readFloat(); if (minHealth > 0) { reader.setPredicate((entity) -> entity instanceof LivingEntity livingEntity && livingEntity.getHealth() >= minHealth); } }, (reader) -> true );
By default, a selector option can be used multiple times. To make a non-repeatable option, either use
FabricEntitySelectorReader
to flag the existence of an option and check it insidecanUse
, or useregisterNonRepeatable(net.minecraft.util.Identifier, net.minecraft.text.Text, net.minecraft.command.EntitySelectorOptions.SelectorHandler)
instead of this method.- Parameters:
id
- the ID of the optiondescription
- the description of the optionhandler
- the handler for the entity option that reads and sets the predicatecanUse
- the predicate that checks whether the option is syntactically valid
-
registerNonRepeatable
public static void registerNonRepeatable(Identifier id, Text description, EntitySelectorOptions.SelectorHandler handler) Registers an entity selector option. The added option is available under the underscore separated ID. The added option cannot be used multiple times within a single selector.- Parameters:
id
- the ID of the optiondescription
- the description of the optionhandler
- the handler for the entity option that reads and sets the predicate
-