Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-261429

Client fails to suggest any arguments when two or more sibling nodes have the "ASK_SERVER" customSuggestion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • None
    • 1.19.4
    • None
    • Unconfirmed

      The client fails to suggest any arguments when two or more sibling nodes have the "ASK_SERVER" customSuggestion. What happens is that these sibling nodes are asked to create a CompletableFuture using the ServerboundCommandSuggestionPacket to ask the server, as in the following code*:

      public CompletableFuture<Suggestions> customSuggestion(CommandContext<?> p_212423_) {
        if (this.pendingSuggestionsFuture != null) {
          this.pendingSuggestionsFuture.cancel(false);
        }
      
        this.pendingSuggestionsFuture = new CompletableFuture<>();
        int i = ++this.pendingSuggestionsId;
        this.connection.send(new ServerboundCommandSuggestionPacket(i, p_212423_.getInput()));
        return this.pendingSuggestionsFuture;
      }

      Since both nodes trigger this function, the later execution cancels the earlier one. In principle this is fine because the server would probably return the same result for both requests. The problem is that because a future is cancelled, the CommandDispatcher never runs the merge code:

      CompletableFuture.allOf(futures).thenRun(() -> {
          final List<Suggestions> suggestions = new ArrayList<>();
          for (final CompletableFuture<Suggestions> future : futures) {
              suggestions.add(future.join());
          }
          result.complete(Suggestions.merge(fullInput, suggestions));
      }); 

      thenRun only executes when all futures have completed normally, but this is not the case here: at least one of the futures has been cancelled. Thus, result will never be completed, and the client never sees any suggestions for this node group.

      It is not unusual for a (custom) command to have multiple sibling nodes that require the ASK_SERVER suggestion, because it is not possible for the server to single-sidedly register custom argument types. In vanilla, the use of sibling nodes happens regularly, such as in /teleport, but vanilla does not suffer from the same issue due to those arguments being able to be resolved at the client side.

      (* code is taken from Forge 1.19.3, so it might look different than in vanilla 1.19.4. But the behavior seems to be identical in both versions.)

            Unassigned Unassigned
            rickyboy320 rickyboy320
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: