IdSearchTree .java

net.minecraft.client.searchtree.IdSearchTree (class, 41 lines): members: identifierSearchTree, additionOrder, searchIdentifier, searchPlainText, search.

net.minecraft.client.searchtreeclass41 linesclient1.6 KB

Implements

API Surface (3)

List<T> search(final String text)
List<T> searchPlainText(final String text)
List<T> searchIdentifier(final String namespace, final String path)

Fields & Constants (2)

additionOrder
identifierSearchTree

Code Graph: Dependencies (4)

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

Full Source

IdSearchTree.java41 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.searchtree;
2
3
import com.google.common.collect.ImmutableList;
4
import java.util.Comparator;
5
import java.util.List;
6
import java.util.function.Function;
7
import java.util.function.ToIntFunction;
8
import java.util.stream.Stream;
9
import net.fabricmc.api.EnvType;
10
import net.fabricmc.api.Environment;
11
import net.minecraft.resources.Identifier;
12
import net.minecraft.util.Util;
13
14
@Environment(EnvType.CLIENT)
15
public class IdSearchTree<T> implements SearchTree<T> {
16
	protected final Comparator<T> additionOrder;
17
	protected final IdentifierSearchTree<T> identifierSearchTree;
18
19
	public IdSearchTree(final Function<T, Stream<Identifier>> idGetter, final List<T> contents) {
20
		ToIntFunction<T> indexLookup = Util.createIndexLookup(contents);
21
		this.additionOrder = Comparator.comparingInt(indexLookup);
22
		this.identifierSearchTree = IdentifierSearchTree.create(contents, idGetter);
23
	}
24
25
	@Override
26
	public List<T> search(final String text) {
27
		int colon = text.indexOf(58);
28
		return colon == -1 ? this.searchPlainText(text) : this.searchIdentifier(text.substring(0, colon).trim(), text.substring(colon + 1).trim());
29
	}
30
31
	protected List<T> searchPlainText(final String text) {
32
		return this.identifierSearchTree.searchPath(text);
33
	}
34
35
	protected List<T> searchIdentifier(final String namespace, final String path) {
36
		List<T> namespaces = this.identifierSearchTree.searchNamespace(namespace);
37
		List<T> paths = this.identifierSearchTree.searchPath(path);
38
		return ImmutableList.copyOf(new IntersectionIterator<>(namespaces.iterator(), paths.iterator(), this.additionOrder));
39
	}
40
}
41

Decompiled Minecraft 26.3 source of IdSearchTree (net/minecraft/client/searchtree/IdSearchTree.java) with Mojang official mappings, stored verbatim on the site.