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 voidregister(net.minecraft.resources.Identifier id, net.minecraft.network.chat.Component description, net.minecraft.commands.arguments.selector.options.EntitySelectorOptions.Modifier modifier, Predicate<net.minecraft.commands.arguments.selector.EntitySelectorParser> canUse) Registers an entity selector option.static voidregisterNonRepeatable(net.minecraft.resources.Identifier id, net.minecraft.network.chat.Component description, net.minecraft.commands.arguments.selector.options.EntitySelectorOptions.Modifier modifier) Registers an entity selector option.
-
Method Details
-
register
public static void register(net.minecraft.resources.Identifier id, net.minecraft.network.chat.Component description, net.minecraft.commands.arguments.selector.options.EntitySelectorOptions.Modifier modifier, Predicate<net.minecraft.commands.arguments.selector.EntitySelectorParser> 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_healthand can be used like@e[example_min_health=5].EntitySelectorOptionRegistry.register( Identifier.fromNamespaceAndPath("modid", "min_health"), Component.literal("Minimum entity health"), (parser) -> { final float minHealth = parser.getReader().readFloat(); if (minHealth > 0) { parser.addPredicate((entity) -> entity instanceof LivingEntity livingEntity && livingEntity.getHealth() >= minHealth); } }, (parser) -> true );By default, a selector option can be used multiple times. To make a non-repeatable option, either use
FabricEntitySelectorParserto flag the existence of an option and check it insidecanUse, or useregisterNonRepeatable(Identifier, Component, EntitySelectorOptions.Modifier)instead of this method.- Parameters:
id- the ID of the optiondescription- the description of the optionmodifier- the modifier 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(net.minecraft.resources.Identifier id, net.minecraft.network.chat.Component description, net.minecraft.commands.arguments.selector.options.EntitySelectorOptions.Modifier modifier) 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 optionmodifier- the modifier for the entity option that reads and sets the predicate
-