User Tools

Site Tools


tutorial:command_argument_types

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
tutorial:command_argument_types [2024/04/15 06:58] – [Custom argument serializer] solidblocktutorial:command_argument_types [2024/04/15 07:15] solidblock
Line 80: Line 80:
         // Brigadier has support to show examples for what the argument should look like,         // Brigadier has support to show examples for what the argument should look like,
         // this should contain a Collection of only the argument this type will return.         // this should contain a Collection of only the argument this type will return.
-        // This is mainly used to calculate ambiguous commands which share the exact same.+        // This is mainly used to detect ambiguity, which means an argument of this type may be parsed as another type.
         return EXAMPLES;         return EXAMPLES;
     }     }
Line 168: Line 168:
         // Brigadier has support to show examples for what the argument should look like,         // Brigadier has support to show examples for what the argument should look like,
         // this should contain a Collection of only the argument this type will return.         // this should contain a Collection of only the argument this type will return.
-        // This is mainly used to calculate ambiguous commands which share the exact same.+        // This is mainly used to detect ambiguity, which means an argument of this type may be parsed as another type.
         return EXAMPLES;         return EXAMPLES;
     }     }
Line 253: Line 253:
  
       @Override       @Override
-      public ArgumentSerializer<ExampleArgumentType, ?> getSerializer() { +      public ArgumentSerializer<ExampleArgumentType, Serializer.Properties> getSerializer() { 
-        return new Serializer();+        // Do not create a new ''Serializer'' object here. 
 +        return Serializer.this;
       }       }
     }     }
Line 260: Line 261:
 } }
 </code> </code>
 +
 +And now you can register it like this:
 +<code java>
 +ArgumentTypeRegistry.registerArgumentType(new Identifier("tutorial", "example"), ExampleArgumentType.class, new ExampleArgumentType.Serializer());
 +</code>
 +
 +==== Another possible way to define serializer ====
  
 If the argument does not require ''CommandRegistryAccess'', it itself may extend ''ArgumentSerializer.ArgumentTypeProperties'': If the argument does not require ''CommandRegistryAccess'', it itself may extend ''ArgumentSerializer.ArgumentTypeProperties'':
Line 307: Line 315:
   }   }
 } }
 +</code>
 +
 +And now you can register it like this:
 +<code java>
 +ArgumentTypeRegistry.registerArgumentType(new Identifier("tutorial", "example"), ExampleArgumentType.class, ExampleArgumentType.Serializer.INSTANCE);
 </code> </code>
tutorial/command_argument_types.txt · Last modified: 2024/04/15 07:21 by solidblock