NumberRunParseRule .java

net.minecraft.util.parsing.packrat.commands.NumberRunParseRule (class): members: underscoreNotAllowedError, noValueError, isAccepted, parse. imports: Rule.

net.minecraft.util.parsing.packrat.commandsclass47 linescommon1.6 KB

Implements

API Surface (0)

No public/protected methods detected (fields or constants only).

Fields & Constants (2)

noValueError
underscoreNotAllowedError

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

NumberRunParseRule.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.parsing.packrat.commands;
2
3
import com.mojang.brigadier.StringReader;
4
import com.mojang.brigadier.exceptions.CommandSyntaxException;
5
import net.minecraft.util.parsing.packrat.DelayedException;
6
import net.minecraft.util.parsing.packrat.ParseState;
7
import net.minecraft.util.parsing.packrat.Rule;
8
import org.jspecify.annotations.Nullable;
9
10
public abstract class NumberRunParseRule implements Rule<StringReader, String> {
11
	private final DelayedException<CommandSyntaxException> noValueError;
12
	private final DelayedException<CommandSyntaxException> underscoreNotAllowedError;
13
14
	public NumberRunParseRule(
15
		final DelayedException<CommandSyntaxException> noValueError, final DelayedException<CommandSyntaxException> underscoreNotAllowedError
16
	) {
17
		this.noValueError = noValueError;
18
		this.underscoreNotAllowedError = underscoreNotAllowedError;
19
	}
20
21
	public @Nullable String parse(final ParseState<StringReader> state) {
22
		StringReader input = state.input();
23
		input.skipWhitespace();
24
		String fullString = input.getString();
25
		int start = input.getCursor();
26
		int pos = start;
27
28
		while (pos < fullString.length() && this.isAccepted(fullString.charAt(pos))) {
29
			pos++;
30
		}
31
32
		int length = pos - start;
33
		if (length == 0) {
34
			state.errorCollector().store(state.mark(), this.noValueError);
35
			return null;
36
		} else if (fullString.charAt(start) != '_' && fullString.charAt(pos - 1) != '_') {
37
			input.setCursor(pos);
38
			return fullString.substring(start, pos);
39
		} else {
40
			state.errorCollector().store(state.mark(), this.underscoreNotAllowedError);
41
			return null;
42
		}
43
	}
44
45
	protected abstract boolean isAccepted(char c);
46
}
47

Decompiled Minecraft 26.3 source of NumberRunParseRule (net/minecraft/util/parsing/packrat/commands/NumberRunParseRule.java) with Mojang official mappings, stored verbatim on the site.