| 1 | package net.minecraft.commands.arguments.selector;
|
| 2 |
|
| 3 | import com.google.common.primitives.Doubles;
|
| 4 | import com.mojang.brigadier.StringReader;
|
| 5 | import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
| 6 | import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
| 7 | import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
| 8 | import com.mojang.brigadier.suggestion.Suggestions;
|
| 9 | import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
| 10 | import java.util.ArrayList;
|
| 11 | import java.util.Collections;
|
| 12 | import java.util.List;
|
| 13 | import java.util.UUID;
|
| 14 | import java.util.concurrent.CompletableFuture;
|
| 15 | import java.util.function.BiConsumer;
|
| 16 | import java.util.function.BiFunction;
|
| 17 | import java.util.function.Consumer;
|
| 18 | import java.util.function.Function;
|
| 19 | import java.util.function.Predicate;
|
| 20 | import net.fabricmc.fabric.api.command.v2.FabricEntitySelectorParser;
|
| 21 | import net.minecraft.advancements.predicates.MinMaxBounds;
|
| 22 | import net.minecraft.commands.arguments.selector.options.EntitySelectorOptions;
|
| 23 | import net.minecraft.commands.arguments.selector.options.InvertableSetOptionState;
|
| 24 | import net.minecraft.commands.arguments.selector.options.SetOnceOptionState;
|
| 25 | import net.minecraft.network.chat.Component;
|
| 26 | import net.minecraft.server.level.ServerPlayer;
|
| 27 | import net.minecraft.server.permissions.PermissionSetSupplier;
|
| 28 | import net.minecraft.server.permissions.Permissions;
|
| 29 | import net.minecraft.util.Mth;
|
| 30 | import net.minecraft.util.ToFloatFunction;
|
| 31 | import net.minecraft.world.entity.Entity;
|
| 32 | import net.minecraft.world.entity.EntityType;
|
| 33 | import net.minecraft.world.entity.EntityTypes;
|
| 34 | import net.minecraft.world.phys.AABB;
|
| 35 | import net.minecraft.world.phys.Vec3;
|
| 36 | import org.jspecify.annotations.Nullable;
|
| 37 |
|
| 38 | public class EntitySelectorParser implements FabricEntitySelectorParser {
|
| 39 | public static final char SYNTAX_SELECTOR_START = '@';
|
| 40 | private static final char SYNTAX_OPTIONS_START = '[';
|
| 41 | private static final char SYNTAX_OPTIONS_END = ']';
|
| 42 | public static final char SYNTAX_OPTIONS_KEY_VALUE_SEPARATOR = '=';
|
| 43 | private static final char SYNTAX_OPTIONS_SEPARATOR = ',';
|
| 44 | public static final char SYNTAX_NOT = '!';
|
| 45 | public static final char SYNTAX_TAG = '#';
|
| 46 | private static final char SELECTOR_NEAREST_PLAYER = 'p';
|
| 47 | private static final char SELECTOR_ALL_PLAYERS = 'a';
|
| 48 | private static final char SELECTOR_RANDOM_PLAYERS = 'r';
|
| 49 | private static final char SELECTOR_CURRENT_ENTITY = 's';
|
| 50 | private static final char SELECTOR_ALL_ENTITIES = 'e';
|
| 51 | private static final char SELECTOR_NEAREST_ENTITY = 'n';
|
| 52 | public static final SimpleCommandExceptionType ERROR_INVALID_NAME_OR_UUID = new SimpleCommandExceptionType(Component.translatable("argument.entity.invalid"));
|
| 53 | public static final DynamicCommandExceptionType ERROR_UNKNOWN_SELECTOR_TYPE = new DynamicCommandExceptionType(
|
| 54 | type -> Component.translatableEscape("argument.entity.selector.unknown", type)
|
| 55 | );
|
| 56 | public static final SimpleCommandExceptionType ERROR_SELECTORS_NOT_ALLOWED = new SimpleCommandExceptionType(
|
| 57 | Component.translatable("argument.entity.selector.not_allowed")
|
| 58 | );
|
| 59 | public static final SimpleCommandExceptionType ERROR_MISSING_SELECTOR_TYPE = new SimpleCommandExceptionType(
|
| 60 | Component.translatable("argument.entity.selector.missing")
|
| 61 | );
|
| 62 | public static final SimpleCommandExceptionType ERROR_EXPECTED_END_OF_OPTIONS = new SimpleCommandExceptionType(
|
| 63 | Component.translatable("argument.entity.options.unterminated")
|
| 64 | );
|
| 65 | public static final DynamicCommandExceptionType ERROR_EXPECTED_OPTION_VALUE = new DynamicCommandExceptionType(
|
| 66 | name -> Component.translatableEscape("argument.entity.options.valueless", name)
|
| 67 | );
|
| 68 | public static final BiConsumer<Vec3, List<? extends Entity>> ORDER_NEAREST = (p, c) -> c.sort(
|
| 69 | (a, b) -> Doubles.compare(a.distanceToSqr(p), b.distanceToSqr(p))
|
| 70 | );
|
| 71 | public static final BiConsumer<Vec3, List<? extends Entity>> ORDER_FURTHEST = (p, c) -> c.sort(
|
| 72 | (a, b) -> Doubles.compare(b.distanceToSqr(p), a.distanceToSqr(p))
|
| 73 | );
|
| 74 | public static final BiConsumer<Vec3, List<? extends Entity>> ORDER_RANDOM = (p, c) -> Collections.shuffle(c);
|
| 75 | public static final BiFunction<SuggestionsBuilder, Consumer<SuggestionsBuilder>, CompletableFuture<Suggestions>> SUGGEST_NOTHING = (b, s) -> b.buildFuture();
|
| 76 | private final StringReader reader;
|
| 77 | private final boolean allowSelectors;
|
| 78 | private int maxResults;
|
| 79 | private boolean includesEntities;
|
| 80 | private boolean worldLimited;
|
| 81 | private MinMaxBounds.@Nullable Doubles distance;
|
| 82 | private MinMaxBounds.@Nullable Ints level;
|
| 83 | private @Nullable Double x;
|
| 84 | private @Nullable Double y;
|
| 85 | private @Nullable Double z;
|
| 86 | private @Nullable Double deltaX;
|
| 87 | private @Nullable Double deltaY;
|
| 88 | private @Nullable Double deltaZ;
|
| 89 | private MinMaxBounds.@Nullable FloatDegrees rotX;
|
| 90 | private MinMaxBounds.@Nullable FloatDegrees rotY;
|
| 91 | private final List<Predicate<Entity>> predicates = new ArrayList<>();
|
| 92 | private BiConsumer<Vec3, List<? extends Entity>> order = EntitySelector.ORDER_ARBITRARY;
|
| 93 | private boolean currentEntity;
|
| 94 | private @Nullable String playerName;
|
| 95 | private int startPosition;
|
| 96 | private @Nullable UUID entityUUID;
|
| 97 | private BiFunction<SuggestionsBuilder, Consumer<SuggestionsBuilder>, CompletableFuture<Suggestions>> suggestions = SUGGEST_NOTHING;
|
| 98 | private final InvertableSetOptionState nameOption = new InvertableSetOptionState();
|
| 99 | private final SetOnceOptionState limitedOption = new SetOnceOptionState();
|
| 100 | private final SetOnceOptionState sortedOption = new SetOnceOptionState();
|
| 101 | private final InvertableSetOptionState gamemodeOption = new InvertableSetOptionState();
|
| 102 | private final InvertableSetOptionState teamOption = new InvertableSetOptionState();
|
| 103 | private @Nullable EntityType<?> type;
|
| 104 | private final InvertableSetOptionState typeOption = new InvertableSetOptionState();
|
| 105 | private final SetOnceOptionState scoresOption = new SetOnceOptionState();
|
| 106 | private final SetOnceOptionState advancementsOption = new SetOnceOptionState();
|
| 107 | private boolean usesSelectors;
|
| 108 |
|
| 109 | public EntitySelectorParser(final StringReader reader, final boolean allowSelectors) {
|
| 110 | this.reader = reader;
|
| 111 | this.allowSelectors = allowSelectors;
|
| 112 | }
|
| 113 |
|
| 114 | public static <S> boolean allowSelectors(final S source) {
|
| 115 | return source instanceof PermissionSetSupplier sender && sender.permissions().hasPermission(Permissions.COMMANDS_ENTITY_SELECTORS);
|
| 116 | }
|
| 117 |
|
| 118 | @Deprecated
|
| 119 | public static boolean allowSelectors(final PermissionSetSupplier source) {
|
| 120 | return source.permissions().hasPermission(Permissions.COMMANDS_ENTITY_SELECTORS);
|
| 121 | }
|
| 122 |
|
| 123 | public EntitySelector getSelector() {
|
| 124 | AABB aabb;
|
| 125 | if (this.deltaX == null && this.deltaY == null && this.deltaZ == null) {
|
| 126 | if (this.distance != null && this.distance.max().isPresent()) {
|
| 127 | double maxRange = (Double)this.distance.max().get();
|
| 128 | aabb = new AABB(-maxRange, -maxRange, -maxRange, maxRange + 1.0, maxRange + 1.0, maxRange + 1.0);
|
| 129 | } else {
|
| 130 | aabb = null;
|
| 131 | }
|
| 132 | } else {
|
| 133 | aabb = this.createAabb(this.deltaX == null ? 0.0 : this.deltaX, this.deltaY == null ? 0.0 : this.deltaY, this.deltaZ == null ? 0.0 : this.deltaZ);
|
| 134 | }
|
| 135 |
|
| 136 | Function<Vec3, Vec3> position;
|
| 137 | if (this.x == null && this.y == null && this.z == null) {
|
| 138 | position = o -> o;
|
| 139 | } else {
|
| 140 | position = o -> new Vec3(this.x == null ? o.x : this.x, this.y == null ? o.y : this.y, this.z == null ? o.z : this.z);
|
| 141 | }
|
| 142 |
|
| 143 | return new EntitySelector(
|
| 144 | this.maxResults,
|
| 145 | this.includesEntities,
|
| 146 | this.worldLimited,
|
| 147 | List.copyOf(this.predicates),
|
| 148 | this.distance,
|
| 149 | position,
|
| 150 | aabb,
|
| 151 | this.order,
|
| 152 | this.currentEntity,
|
| 153 | this.playerName,
|
| 154 | this.entityUUID,
|
| 155 | this.type,
|
| 156 | this.usesSelectors
|
| 157 | );
|
| 158 | }
|
| 159 |
|
| 160 | private AABB createAabb(final double x, final double y, final double z) {
|
| 161 | boolean xNeg = x < 0.0;
|
| 162 | boolean yNeg = y < 0.0;
|
| 163 | boolean zNeg = z < 0.0;
|
| 164 | double xMin = xNeg ? x : 0.0;
|
| 165 | double yMin = yNeg ? y : 0.0;
|
| 166 | double zMin = zNeg ? z : 0.0;
|
| 167 | double xMax = (xNeg ? 0.0 : x) + 1.0;
|
| 168 | double yMax = (yNeg ? 0.0 : y) + 1.0;
|
| 169 | double zMax = (zNeg ? 0.0 : z) + 1.0;
|
| 170 | return new AABB(xMin, yMin, zMin, xMax, yMax, zMax);
|
| 171 | }
|
| 172 |
|
| 173 | private void finalizePredicates() {
|
| 174 | if (this.rotX != null) {
|
| 175 | this.predicates.add(this.createRotationPredicate(this.rotX, Entity::getXRot));
|
| 176 | }
|
| 177 |
|
| 178 | if (this.rotY != null) {
|
| 179 | this.predicates.add(this.createRotationPredicate(this.rotY, Entity::getYRot));
|
| 180 | }
|
| 181 |
|
| 182 | if (this.level != null) {
|
| 183 | this.predicates.add(e -> e instanceof ServerPlayer serverPlayer && this.level.matches(serverPlayer.experienceLevel));
|
| 184 | }
|
| 185 | }
|
| 186 |
|
| 187 | private Predicate<Entity> createRotationPredicate(final MinMaxBounds.FloatDegrees range, final ToFloatFunction<Entity> function) {
|
| 188 | float min = Mth.wrapDegrees(range.min().orElse(0.0F));
|
| 189 | float max = Mth.wrapDegrees(range.max().orElse(359.0F));
|
| 190 | return e -> {
|
| 191 | float rotation = Mth.wrapDegrees(function.applyAsFloat(e));
|
| 192 | return min > max ? rotation >= min || rotation <= max : rotation >= min && rotation <= max;
|
| 193 | };
|
| 194 | }
|
| 195 |
|
| 196 | protected void parseSelector() throws CommandSyntaxException {
|
| 197 | this.usesSelectors = true;
|
| 198 | this.suggestions = this::suggestSelector;
|
| 199 | if (!this.reader.canRead()) {
|
| 200 | throw ERROR_MISSING_SELECTOR_TYPE.createWithContext(this.reader);
|
| 201 | }
|
| 202 |
|
| 203 | int start = this.reader.getCursor();
|
| 204 | char type = this.reader.read();
|
| 205 |
|
| 206 | if (switch (type) {
|
| 207 | case 'a' -> {
|
| 208 | this.maxResults = Integer.MAX_VALUE;
|
| 209 | this.includesEntities = false;
|
| 210 | this.order = EntitySelector.ORDER_ARBITRARY;
|
| 211 | this.limitToType(EntityTypes.PLAYER);
|
| 212 | yield false;
|
| 213 | }
|
| 214 | default -> {
|
| 215 | this.reader.setCursor(start);
|
| 216 | throw ERROR_UNKNOWN_SELECTOR_TYPE.createWithContext(this.reader, "@" + type);
|
| 217 | }
|
| 218 | case 'e' -> {
|
| 219 | this.maxResults = Integer.MAX_VALUE;
|
| 220 | this.includesEntities = true;
|
| 221 | this.order = EntitySelector.ORDER_ARBITRARY;
|
| 222 | yield true;
|
| 223 | }
|
| 224 | case 'n' -> {
|
| 225 | this.maxResults = 1;
|
| 226 | this.includesEntities = true;
|
| 227 | this.order = ORDER_NEAREST;
|
| 228 | yield true;
|
| 229 | }
|
| 230 | case 'p' -> {
|
| 231 | this.maxResults = 1;
|
| 232 | this.includesEntities = false;
|
| 233 | this.order = ORDER_NEAREST;
|
| 234 | this.limitToType(EntityTypes.PLAYER);
|
| 235 | yield false;
|
| 236 | }
|
| 237 | case 'r' -> {
|
| 238 | this.maxResults = 1;
|
| 239 | this.includesEntities = false;
|
| 240 | this.order = ORDER_RANDOM;
|
| 241 | this.limitToType(EntityTypes.PLAYER);
|
| 242 | yield false;
|
| 243 | }
|
| 244 | case 's' -> {
|
| 245 | this.maxResults = 1;
|
| 246 | this.includesEntities = true;
|
| 247 | this.currentEntity = true;
|
| 248 | yield false;
|
| 249 | }
|
| 250 | }) {
|
| 251 | this.predicates.add(Entity::isAlive);
|
| 252 | }
|
| 253 |
|
| 254 | this.suggestions = this::suggestOpenOptions;
|
| 255 | if (this.reader.canRead() && this.reader.peek() == '[') {
|
| 256 | this.reader.skip();
|
| 257 | this.suggestions = this::suggestOptionsKeyOrClose;
|
| 258 | this.parseOptions();
|
| 259 | }
|
| 260 | }
|
| 261 |
|
| 262 | protected void parseNameOrUUID() throws CommandSyntaxException {
|
| 263 | if (this.reader.canRead()) {
|
| 264 | this.suggestions = this::suggestName;
|
| 265 | }
|
| 266 |
|
| 267 | int start = this.reader.getCursor();
|
| 268 | String name = this.reader.readString();
|
| 269 |
|
| 270 | try {
|
| 271 | this.entityUUID = UUID.fromString(name);
|
| 272 | this.includesEntities = true;
|
| 273 | } catch (IllegalArgumentException ex) {
|
| 274 | if (name.isEmpty() || name.length() > 16) {
|
| 275 | this.reader.setCursor(start);
|
| 276 | throw ERROR_INVALID_NAME_OR_UUID.createWithContext(this.reader);
|
| 277 | }
|
| 278 |
|
| 279 | this.includesEntities = false;
|
| 280 | this.playerName = name;
|
| 281 | }
|
| 282 |
|
| 283 | this.maxResults = 1;
|
| 284 | }
|
| 285 |
|
| 286 | protected void parseOptions() throws CommandSyntaxException {
|
| 287 | this.suggestions = this::suggestOptionsKey;
|
| 288 | this.reader.skipWhitespace();
|
| 289 |
|
| 290 | while (this.reader.canRead() && this.reader.peek() != ']') {
|
| 291 | this.reader.skipWhitespace();
|
| 292 | int start = this.reader.getCursor();
|
| 293 | String key = this.reader.readString();
|
| 294 | EntitySelectorOptions.Modifier modifier = EntitySelectorOptions.get(this, key, start);
|
| 295 | this.reader.skipWhitespace();
|
| 296 | if (!this.reader.canRead() || this.reader.peek() != '=') {
|
| 297 | this.reader.setCursor(start);
|
| 298 | throw ERROR_EXPECTED_OPTION_VALUE.createWithContext(this.reader, key);
|
| 299 | }
|
| 300 |
|
| 301 | this.reader.skip();
|
| 302 | this.reader.skipWhitespace();
|
| 303 | this.suggestions = SUGGEST_NOTHING;
|
| 304 | modifier.handle(this);
|
| 305 | this.reader.skipWhitespace();
|
| 306 | this.suggestions = this::suggestOptionsNextOrClose;
|
| 307 | if (this.reader.canRead()) {
|
| 308 | if (this.reader.peek() != ',') {
|
| 309 | if (this.reader.peek() != ']') {
|
| 310 | throw ERROR_EXPECTED_END_OF_OPTIONS.createWithContext(this.reader);
|
| 311 | }
|
| 312 | break;
|
| 313 | }
|
| 314 |
|
| 315 | this.reader.skip();
|
| 316 | this.suggestions = this::suggestOptionsKey;
|
| 317 | }
|
| 318 | }
|
| 319 |
|
| 320 | if (this.reader.canRead()) {
|
| 321 | this.reader.skip();
|
| 322 | this.suggestions = SUGGEST_NOTHING;
|
| 323 | } else {
|
| 324 | throw ERROR_EXPECTED_END_OF_OPTIONS.createWithContext(this.reader);
|
| 325 | }
|
| 326 | }
|
| 327 |
|
| 328 | public boolean shouldInvertValue() {
|
| 329 | this.reader.skipWhitespace();
|
| 330 | if (this.reader.canRead() && this.reader.peek() == '!') {
|
| 331 | this.reader.skip();
|
| 332 | this.reader.skipWhitespace();
|
| 333 | return true;
|
| 334 | } else {
|
| 335 | return false;
|
| 336 | }
|
| 337 | }
|
| 338 |
|
| 339 | public boolean isTag() {
|
| 340 | this.reader.skipWhitespace();
|
| 341 | if (this.reader.canRead() && this.reader.peek() == '#') {
|
| 342 | this.reader.skip();
|
| 343 | this.reader.skipWhitespace();
|
| 344 | return true;
|
| 345 | } else {
|
| 346 | return false;
|
| 347 | }
|
| 348 | }
|
| 349 |
|
| 350 | public StringReader getReader() {
|
| 351 | return this.reader;
|
| 352 | }
|
| 353 |
|
| 354 | public void addPredicate(final Predicate<Entity> predicate) {
|
| 355 | this.predicates.add(predicate);
|
| 356 | }
|
| 357 |
|
| 358 | public void setWorldLimited() {
|
| 359 | this.worldLimited = true;
|
| 360 | }
|
| 361 |
|
| 362 | public MinMaxBounds.@Nullable Doubles getDistance() {
|
| 363 | return this.distance;
|
| 364 | }
|
| 365 |
|
| 366 | public void setDistance(final MinMaxBounds.Doubles distance) {
|
| 367 | this.distance = distance;
|
| 368 | }
|
| 369 |
|
| 370 | public MinMaxBounds.@Nullable Ints getLevel() {
|
| 371 | return this.level;
|
| 372 | }
|
| 373 |
|
| 374 | public void setLevel(final MinMaxBounds.Ints level) {
|
| 375 | this.level = level;
|
| 376 | }
|
| 377 |
|
| 378 | public MinMaxBounds.@Nullable FloatDegrees getRotX() {
|
| 379 | return this.rotX;
|
| 380 | }
|
| 381 |
|
| 382 | public void setRotX(final MinMaxBounds.FloatDegrees rotX) {
|
| 383 | this.rotX = rotX;
|
| 384 | }
|
| 385 |
|
| 386 | public MinMaxBounds.@Nullable FloatDegrees getRotY() {
|
| 387 | return this.rotY;
|
| 388 | }
|
| 389 |
|
| 390 | public void setRotY(final MinMaxBounds.FloatDegrees rotY) {
|
| 391 | this.rotY = rotY;
|
| 392 | }
|
| 393 |
|
| 394 | public @Nullable Double getX() {
|
| 395 | return this.x;
|
| 396 | }
|
| 397 |
|
| 398 | public @Nullable Double getY() {
|
| 399 | return this.y;
|
| 400 | }
|
| 401 |
|
| 402 | public @Nullable Double getZ() {
|
| 403 | return this.z;
|
| 404 | }
|
| 405 |
|
| 406 | public void setX(final double x) {
|
| 407 | this.x = x;
|
| 408 | }
|
| 409 |
|
| 410 | public void setY(final double y) {
|
| 411 | this.y = y;
|
| 412 | }
|
| 413 |
|
| 414 | public void setZ(final double z) {
|
| 415 | this.z = z;
|
| 416 | }
|
| 417 |
|
| 418 | public void setDeltaX(final double deltaX) {
|
| 419 | this.deltaX = deltaX;
|
| 420 | }
|
| 421 |
|
| 422 | public void setDeltaY(final double deltaY) {
|
| 423 | this.deltaY = deltaY;
|
| 424 | }
|
| 425 |
|
| 426 | public void setDeltaZ(final double deltaZ) {
|
| 427 | this.deltaZ = deltaZ;
|
| 428 | }
|
| 429 |
|
| 430 | public @Nullable Double getDeltaX() {
|
| 431 | return this.deltaX;
|
| 432 | }
|
| 433 |
|
| 434 | public @Nullable Double getDeltaY() {
|
| 435 | return this.deltaY;
|
| 436 | }
|
| 437 |
|
| 438 | public @Nullable Double getDeltaZ() {
|
| 439 | return this.deltaZ;
|
| 440 | }
|
| 441 |
|
| 442 | public void setMaxResults(final int maxResults) {
|
| 443 | this.maxResults = maxResults;
|
| 444 | }
|
| 445 |
|
| 446 | public void setIncludesEntities(final boolean includesEntities) {
|
| 447 | this.includesEntities = includesEntities;
|
| 448 | }
|
| 449 |
|
| 450 | public BiConsumer<Vec3, List<? extends Entity>> getOrder() {
|
| 451 | return this.order;
|
| 452 | }
|
| 453 |
|
| 454 | public void setOrder(final BiConsumer<Vec3, List<? extends Entity>> order) {
|
| 455 | this.order = order;
|
| 456 | }
|
| 457 |
|
| 458 | public EntitySelector parse() throws CommandSyntaxException {
|
| 459 | this.startPosition = this.reader.getCursor();
|
| 460 | this.suggestions = this::suggestNameOrSelector;
|
| 461 | if (this.reader.canRead() && this.reader.peek() == '@') {
|
| 462 | if (!this.allowSelectors) {
|
| 463 | throw ERROR_SELECTORS_NOT_ALLOWED.createWithContext(this.reader);
|
| 464 | }
|
| 465 |
|
| 466 | this.reader.skip();
|
| 467 | this.parseSelector();
|
| 468 | } else {
|
| 469 | this.parseNameOrUUID();
|
| 470 | }
|
| 471 |
|
| 472 | this.finalizePredicates();
|
| 473 | return this.getSelector();
|
| 474 | }
|
| 475 |
|
| 476 | private static void fillSelectorSuggestions(final SuggestionsBuilder builder) {
|
| 477 | builder.suggest("@p", Component.translatable("argument.entity.selector.nearestPlayer"));
|
| 478 | builder.suggest("@a", Component.translatable("argument.entity.selector.allPlayers"));
|
| 479 | builder.suggest("@r", Component.translatable("argument.entity.selector.randomPlayer"));
|
| 480 | builder.suggest("@s", Component.translatable("argument.entity.selector.self"));
|
| 481 | builder.suggest("@e", Component.translatable("argument.entity.selector.allEntities"));
|
| 482 | builder.suggest("@n", Component.translatable("argument.entity.selector.nearestEntity"));
|
| 483 | }
|
| 484 |
|
| 485 | private CompletableFuture<Suggestions> suggestNameOrSelector(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 486 | names.accept(builder);
|
| 487 | if (this.allowSelectors) {
|
| 488 | fillSelectorSuggestions(builder);
|
| 489 | }
|
| 490 |
|
| 491 | return builder.buildFuture();
|
| 492 | }
|
| 493 |
|
| 494 | private CompletableFuture<Suggestions> suggestName(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 495 | SuggestionsBuilder sub = builder.createOffset(this.startPosition);
|
| 496 | names.accept(sub);
|
| 497 | return builder.add(sub).buildFuture();
|
| 498 | }
|
| 499 |
|
| 500 | private CompletableFuture<Suggestions> suggestSelector(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 501 | SuggestionsBuilder sub = builder.createOffset(builder.getStart() - 1);
|
| 502 | fillSelectorSuggestions(sub);
|
| 503 | builder.add(sub);
|
| 504 | return builder.buildFuture();
|
| 505 | }
|
| 506 |
|
| 507 | private CompletableFuture<Suggestions> suggestOpenOptions(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 508 | builder.suggest(String.valueOf('['));
|
| 509 | return builder.buildFuture();
|
| 510 | }
|
| 511 |
|
| 512 | private CompletableFuture<Suggestions> suggestOptionsKeyOrClose(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 513 | builder.suggest(String.valueOf(']'));
|
| 514 | EntitySelectorOptions.suggestNames(this, builder);
|
| 515 | return builder.buildFuture();
|
| 516 | }
|
| 517 |
|
| 518 | private CompletableFuture<Suggestions> suggestOptionsKey(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 519 | EntitySelectorOptions.suggestNames(this, builder);
|
| 520 | return builder.buildFuture();
|
| 521 | }
|
| 522 |
|
| 523 | private CompletableFuture<Suggestions> suggestOptionsNextOrClose(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 524 | builder.suggest(String.valueOf(','));
|
| 525 | builder.suggest(String.valueOf(']'));
|
| 526 | return builder.buildFuture();
|
| 527 | }
|
| 528 |
|
| 529 | private CompletableFuture<Suggestions> suggestEquals(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 530 | builder.suggest(String.valueOf('='));
|
| 531 | return builder.buildFuture();
|
| 532 | }
|
| 533 |
|
| 534 | public boolean isCurrentEntity() {
|
| 535 | return this.currentEntity;
|
| 536 | }
|
| 537 |
|
| 538 | public void setSuggestions(final BiFunction<SuggestionsBuilder, Consumer<SuggestionsBuilder>, CompletableFuture<Suggestions>> suggestions) {
|
| 539 | this.suggestions = suggestions;
|
| 540 | }
|
| 541 |
|
| 542 | public CompletableFuture<Suggestions> fillSuggestions(final SuggestionsBuilder builder, final Consumer<SuggestionsBuilder> names) {
|
| 543 | return this.suggestions.apply(builder.createOffset(this.reader.getCursor()), names);
|
| 544 | }
|
| 545 |
|
| 546 | public InvertableSetOptionState nameOption() {
|
| 547 | return this.nameOption;
|
| 548 | }
|
| 549 |
|
| 550 | public SetOnceOptionState limitedOption() {
|
| 551 | return this.limitedOption;
|
| 552 | }
|
| 553 |
|
| 554 | public SetOnceOptionState sortedOption() {
|
| 555 | return this.sortedOption;
|
| 556 | }
|
| 557 |
|
| 558 | public InvertableSetOptionState gamemodeOption() {
|
| 559 | return this.gamemodeOption;
|
| 560 | }
|
| 561 |
|
| 562 | public InvertableSetOptionState teamOption() {
|
| 563 | return this.teamOption;
|
| 564 | }
|
| 565 |
|
| 566 | public void limitToType(final EntityType<?> type) {
|
| 567 | this.type = type;
|
| 568 | }
|
| 569 |
|
| 570 | public InvertableSetOptionState typeOption() {
|
| 571 | return this.typeOption;
|
| 572 | }
|
| 573 |
|
| 574 | public SetOnceOptionState scoresOption() {
|
| 575 | return this.scoresOption;
|
| 576 | }
|
| 577 |
|
| 578 | public SetOnceOptionState advancementsOption() {
|
| 579 | return this.advancementsOption;
|
| 580 | }
|
| 581 | }
|
| 582 |
|