forked from oott123/RoughlyEnoughCharacters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VanillaTextSearch.java
39 lines (32 loc) · 1.42 KB
/
VanillaTextSearch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.oott123.rechars.mixins;
import com.oott123.rechars.stubs.RecSuffixArray;
import net.minecraft.client.search.IdentifierSearchableContainer;
import net.minecraft.client.search.SuffixArray;
import net.minecraft.client.search.TextSearchableContainer;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.function.Function;
import java.util.stream.Stream;
@Mixin({TextSearchableContainer.class})
public abstract class VanillaTextSearch<T> extends IdentifierSearchableContainer<T> {
@Shadow
private SuffixArray<T> byText;
public VanillaTextSearch(Function<T, Stream<Identifier>> identifierFinder) {
super(identifierFinder);
}
@Inject(method = {"<init>"}, at = {@At("TAIL")})
private final void onInit(Function textFinder, Function identifierFinder, CallbackInfo info) {
this.reloadByTextWithRec();
}
@Inject(method = {"reload"}, at = {@At(target = "Lnet/minecraft/client/search/IdentifierSearchableContainer;reload()V", value = "INVOKE")})
private final void onReload(CallbackInfo info) {
this.reloadByTextWithRec();
}
private final void reloadByTextWithRec() {
this.byText = new RecSuffixArray();
}
}