StyleArgument .java

net.minecraft.commands.arguments.StyleArgument (class, 44 lines): members: ERROR_INVALID_STYLE, TAG_PARSER, getStyle, OPS, style, getExamples, EXAMPLES.

net.minecraft.commands.argumentsclass44 linescommonextends ParserBasedArgument<Style>1.7 KB

API Surface (3)

Style getStyle(final CommandContext<CommandSourceStack> context, final String name)
StyleArgument style(final CommandBuildContext context)
Collection<String> getExamples()

Fields & Constants (4)

EXAMPLES
ERROR_INVALID_STYLE
OPS
TAG_PARSER

String literals (3)

"{bold: true}"
"{color: 'red'}"
"argument.style.invalid"

Full Source

StyleArgument.java44 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands.arguments;
2
3
import com.mojang.brigadier.context.CommandContext;
4
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
5
import com.mojang.serialization.DynamicOps;
6
import java.util.Collection;
7
import java.util.List;
8
import net.minecraft.commands.CommandBuildContext;
9
import net.minecraft.commands.CommandSourceStack;
10
import net.minecraft.core.HolderLookup;
11
import net.minecraft.nbt.NbtOps;
12
import net.minecraft.nbt.SnbtGrammar;
13
import net.minecraft.nbt.Tag;
14
import net.minecraft.network.chat.Component;
15
import net.minecraft.network.chat.Style;
16
import net.minecraft.util.parsing.packrat.commands.CommandArgumentParser;
17
import net.minecraft.util.parsing.packrat.commands.ParserBasedArgument;
18
19
public class StyleArgument extends ParserBasedArgument<Style> {
20
	private static final Collection<String> EXAMPLES = List.of("{bold: true}", "{color: 'red'}", "{}");
21
	public static final DynamicCommandExceptionType ERROR_INVALID_STYLE = new DynamicCommandExceptionType(
22
		message -> Component.translatableEscape("argument.style.invalid", message)
23
	);
24
	private static final DynamicOps<Tag> OPS = NbtOps.INSTANCE;
25
	private static final CommandArgumentParser<Tag> TAG_PARSER = SnbtGrammar.createParser(OPS);
26
27
	private StyleArgument(final HolderLookup.Provider registries) {
28
		super(TAG_PARSER.withCodec(registries.createSerializationContext(OPS), TAG_PARSER, Style.Serializer.CODEC, ERROR_INVALID_STYLE));
29
	}
30
31
	public static Style getStyle(final CommandContext<CommandSourceStack> context, final String name) {
32
		return context.getArgument(name, Style.class);
33
	}
34
35
	public static StyleArgument style(final CommandBuildContext context) {
36
		return new StyleArgument(context);
37
	}
38
39
	@Override
40
	public Collection<String> getExamples() {
41
		return EXAMPLES;
42
	}
43
}
44

Decompiled Minecraft 26.3 source of StyleArgument (net/minecraft/commands/arguments/StyleArgument.java) with Mojang official mappings, stored verbatim on the site.