tutorial:command_argument_types
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:command_argument_types [2023/11/18 12:59] – [Specifying suggestions] solidblock | tutorial:command_argument_types [2024/04/15 07:03] – [Custom argument serializer] solidblock | ||
---|---|---|---|
Line 90: | Line 90: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | ArgumentTypeRegistry.registerArgumentType(new Identifier(" | + | ArgumentTypeRegistry.registerArgumentType( |
+ | | ||
+ | | ||
// The argument should be what will create the ArgumentType. | // The argument should be what will create the ArgumentType. | ||
</ | </ | ||
Line 251: | Line 253: | ||
@Override | @Override | ||
- | public ArgumentSerializer< | + | public ArgumentSerializer< |
- | | + | |
+ | return Serializer.this; | ||
} | } | ||
} | } | ||
Line 258: | Line 261: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | And now you can register it like this: | ||
+ | <code java> | ||
+ | ArgumentTypeRegistry.registerArgumentType(new Identifier(" | ||
+ | </ | ||
+ | |||
+ | ==== Another possible way to define serializer ==== | ||
If the argument does not require '' | If the argument does not require '' | ||
Line 275: | Line 285: | ||
@Override | @Override | ||
public ArgumentSerializer< | public ArgumentSerializer< | ||
- | return | + | |
+ | | ||
} | } | ||
public static class Serializer implements ArgumentSerializer< | public static class Serializer implements ArgumentSerializer< | ||
+ | public static final Serializer INSTANCE = new Serializer(); | ||
+ | private Serializer() {} | ||
+ | | ||
@Override | @Override | ||
public void writePacket(ExampleArgumentType properties, PacketByteBuf buf) { | public void writePacket(ExampleArgumentType properties, PacketByteBuf buf) { | ||
Line 301: | Line 315: | ||
} | } | ||
} | } | ||
+ | </ | ||
+ | |||
+ | And now you can register it like this: | ||
+ | <code java> | ||
+ | ArgumentTypeRegistry.registerArgumentType(new Identifier(" | ||
</ | </ |
tutorial/command_argument_types.txt · Last modified: 2024/04/15 07:21 by solidblock