package net.minecraft.client.searchtree; import com.google.common.collect.ImmutableList; import java.util.Comparator; import java.util.List; import java.util.function.Function; import java.util.function.ToIntFunction; import java.util.stream.Stream; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.Util; import net.minecraft.resources.ResourceLocation; @Environment(EnvType.CLIENT) public class IdSearchTree implements SearchTree { protected final Comparator additionOrder; protected final ResourceLocationSearchTree resourceLocationSearchTree; public IdSearchTree(Function> idGetter, List contents) { ToIntFunction toIntFunction = Util.createIndexLookup(contents); this.additionOrder = Comparator.comparingInt(toIntFunction); this.resourceLocationSearchTree = ResourceLocationSearchTree.create(contents, idGetter); } @Override public List search(String string) { int i = string.indexOf(58); return i == -1 ? this.searchPlainText(string) : this.searchResourceLocation(string.substring(0, i).trim(), string.substring(i + 1).trim()); } protected List searchPlainText(String query) { return this.resourceLocationSearchTree.searchPath(query); } protected List searchResourceLocation(String namespace, String path) { List list = this.resourceLocationSearchTree.searchNamespace(namespace); List list2 = this.resourceLocationSearchTree.searchPath(path); return ImmutableList.copyOf(new IntersectionIterator<>(list.iterator(), list2.iterator(), this.additionOrder)); } }