package net.minecraft.util.parsing.packrat.commands; import com.mojang.brigadier.ImmutableStringReader; import com.mojang.brigadier.StringReader; import java.util.Optional; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.parsing.packrat.Atom; import net.minecraft.util.parsing.packrat.ParseState; import net.minecraft.util.parsing.packrat.Rule; public abstract class ResourceLookupRule implements Rule, ResourceSuggestion { private final Atom idParser; protected final C context; protected ResourceLookupRule(Atom idParser, C context) { this.idParser = idParser; this.context = context; } @Override public Optional parse(ParseState parseState) { parseState.input().skipWhitespace(); int i = parseState.mark(); Optional optional = parseState.parse(this.idParser); if (optional.isPresent()) { try { return Optional.of(this.validateElement(parseState.input(), (ResourceLocation)optional.get())); } catch (Exception var5) { parseState.errorCollector().store(i, this, var5); return Optional.empty(); } } else { parseState.errorCollector().store(i, this, ResourceLocation.ERROR_INVALID.createWithContext(parseState.input())); return Optional.empty(); } } protected abstract V validateElement(ImmutableStringReader reader, ResourceLocation elementType) throws Exception; }