User Tools

Site Tools


tutorial:command_suggestions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
tutorials:commands:suggestions [2020/11/25 08:15] – Link to CompleteableFuture in JDK javadoc i509vcbtutorial:command_suggestions [2023/02/20 05:44] solidblock
Line 8: Line 8:
  
 A ''SuggestionProvider'' is used to make a list of suggestions that will be sent to the client. A suggestion provider is a functional interface that takes a ''CommandContext'' and a ''SuggestionBuilder'' and returns some ''Suggestions''. The ''SuggestionProvider'' returns a [[https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/concurrent/CompletableFuture.html|CompletableFuture]] as the suggestions may not be available immediately. A ''SuggestionProvider'' is used to make a list of suggestions that will be sent to the client. A suggestion provider is a functional interface that takes a ''CommandContext'' and a ''SuggestionBuilder'' and returns some ''Suggestions''. The ''SuggestionProvider'' returns a [[https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/concurrent/CompletableFuture.html|CompletableFuture]] as the suggestions may not be available immediately.
- 
  
 Suggestions can be contextual since a suggestion provider gives you access to the current command context. Suggestions can be contextual since a suggestion provider gives you access to the current command context.
Line 14: Line 13:
 ===== An example suggestion provider ===== ===== An example suggestion provider =====
  
-For example lets say you want to suggest all attributes an entity could have.+For example let'say you want to suggest all attributes an entity could have.
  
 <code java [enable_line_numbers="true", highlight_lines_extra="4"]> <code java [enable_line_numbers="true", highlight_lines_extra="4"]>
Line 33: Line 32:
     public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {     public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
         Identifier entityTypeId = context.getArgument("type", Identifier.class);         Identifier entityTypeId = context.getArgument("type", Identifier.class);
-        EntityType<?> entityType = Registry.ENTITY_TYPE.getOrEmpty(entityTypeId).orElse(null);+        EntityType<?> entityType = Registries.ENTITY_TYPE.getOrEmpty(entityTypeId).orElse(null); 
 +        // For versions before 1.19.3, use ''Registry.ENTITY_TYPE'' instead.
                  
         if (!DefaultAttributeContainer.hasDefinitionFor(entityType)) {         if (!DefaultAttributeContainer.hasDefinitionFor(entityType)) {
Line 42: Line 42:
         // You will need mixin to get the 'instances map'. Lets assume we can just access it for the sake of the tutorial         // You will need mixin to get the 'instances map'. Lets assume we can just access it for the sake of the tutorial
         for (EntityAttribute attribute : attributeContainer.instances().keySet()) {         for (EntityAttribute attribute : attributeContainer.instances().keySet()) {
-            Identifier attributeId = Registry.ATTRIBUTE.getId(attribute);+            Identifier attributeId = Registries.ATTRIBUTE.getId(attribute);
             if (attributeId != null) {             if (attributeId != null) {
             ...             ...
Line 51: Line 51:
 <code java [enable_line_numbers="true", highlight_lines_extra="4"]> <code java [enable_line_numbers="true", highlight_lines_extra="4"]>
 for (EntityAttribute attribute : attributeContainer.instances().keySet()) { for (EntityAttribute attribute : attributeContainer.instances().keySet()) {
-    Identifier attributeId = Registry.ATTRIBUTE.getId(attribute);+    Identifier attributeId = Registries.ATTRIBUTE.getId(attribute);
     if (attributeId != null) {     if (attributeId != null) {
        builder.suggest(attributeId.toString());        builder.suggest(attributeId.toString());
Line 73: Line 73:
     public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {     public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
         Identifier entityTypeId = context.getArgument("type", Identifier.class);         Identifier entityTypeId = context.getArgument("type", Identifier.class);
-        EntityType<?> entityType = Registry.ENTITY_TYPE.getOrEmpty(entityTypeId).orElse(null);+        EntityType<?> entityType = Registries.ENTITY_TYPE.getOrEmpty(entityTypeId).orElse(null);
                  
         if (!DefaultAttributeContainer.hasDefinitionFor(entityType)) {         if (!DefaultAttributeContainer.hasDefinitionFor(entityType)) {
Line 82: Line 82:
         // You will need mixin to get the 'instances map'. Lets assume we can just access it for the sake of the tutorial         // You will need mixin to get the 'instances map'. Lets assume we can just access it for the sake of the tutorial
         for (EntityAttribute attribute : attributeContainer.instances().keySet()) {         for (EntityAttribute attribute : attributeContainer.instances().keySet()) {
-            Identifier attributeId = Registry.ATTRIBUTE.getId(attribute);+            Identifier attributeId = Registries.ATTRIBUTE.getId(attribute);
             if (attributeId != null) {             if (attributeId != null) {
                 builder.suggest(attributeId.toString());                 builder.suggest(attributeId.toString());
Line 109: Line 109:
  
 ^ Type                ^ Field/Method                            ^ ^ Type                ^ Field/Method                            ^
-| Summonable entities | SuggestionProviders.SUMMONABLE_ENTITIES | +| Summonable entities | ''SuggestionProviders.SUMMONABLE_ENTITIES'' 
-| Available sounds    | SuggestionProviders.AVAILABLE_SOUNDS    | +| Available sounds    | ''SuggestionProviders.AVAILABLE_SOUNDS''    | 
-| Loot Tables         | LootCommand.SUGGESTION_PROVIDER         | +| Loot Tables         ''LootCommand.SUGGESTION_PROVIDER''         | 
-| Biomes              | SuggestionProviders.ALL_BIOMES          |+| Biomes              | ''SuggestionProviders.ALL_BIOMES''          |
  
 ===== Utilities in CommandSource ===== ===== Utilities in CommandSource =====
tutorial/command_suggestions.txt · Last modified: 2023/11/18 12:06 by solidblock