ResourceLookupRule .java

net.minecraft.util.parsing.packrat.commands.ResourceLookupRule (class, 44 lines): members: validateElement, idParser, error, context, parse. imports: Rule.

net.minecraft.util.parsing.packrat.commandsclass44 linescommon1.5 KB

Implements

API Surface (1)

V validateElement(ImmutableStringReader reader, Identifier id)

Fields & Constants (3)

idParser
context
error

Code Graph: Dependencies (6)

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

Full Source

ResourceLookupRule.java44 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.parsing.packrat.commands;
2
3
import com.mojang.brigadier.ImmutableStringReader;
4
import com.mojang.brigadier.StringReader;
5
import com.mojang.brigadier.exceptions.CommandSyntaxException;
6
import net.minecraft.resources.Identifier;
7
import net.minecraft.util.parsing.packrat.DelayedException;
8
import net.minecraft.util.parsing.packrat.NamedRule;
9
import net.minecraft.util.parsing.packrat.ParseState;
10
import net.minecraft.util.parsing.packrat.Rule;
11
import org.jspecify.annotations.Nullable;
12
13
public abstract class ResourceLookupRule<C, V> implements Rule<StringReader, V>, ResourceSuggestion {
14
	private final NamedRule<StringReader, Identifier> idParser;
15
	protected final C context;
16
	private final DelayedException<CommandSyntaxException> error;
17
18
	protected ResourceLookupRule(final NamedRule<StringReader, Identifier> idParser, final C context) {
19
		this.idParser = idParser;
20
		this.context = context;
21
		this.error = DelayedException.create(Identifier.ERROR_INVALID);
22
	}
23
24
	@Override
25
	public @Nullable V parse(final ParseState<StringReader> state) {
26
		state.input().skipWhitespace();
27
		int mark = state.mark();
28
		Identifier id = state.parse(this.idParser);
29
		if (id != null) {
30
			try {
31
				return this.validateElement(state.input(), id);
32
			} catch (Exception e) {
33
				state.errorCollector().store(mark, this, e);
34
				return null;
35
			}
36
		} else {
37
			state.errorCollector().store(mark, this, this.error);
38
			return null;
39
		}
40
	}
41
42
	protected abstract V validateElement(ImmutableStringReader reader, Identifier id) throws Exception;
43
}
44

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