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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* Roughly Enough Items by Danielshe.
* Licensed under the MIT License.
*/
package me.shedaniel.rei.impl;
import com.google.common.collect.Lists;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.annotations.Internal;
import me.shedaniel.rei.gui.widget.QueuedTooltip;
import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
@Deprecated
@Internal
public class SearchArgument {
public static final SearchArgument ALWAYS = new SearchArgument(ArgumentType.ALWAYS, "", true);
@Deprecated
private static List<Item> searchBlacklisted = Lists.newArrayList();
private ArgumentType argumentType;
private String text;
public final Function<String, Boolean> INCLUDE = s -> s.contains(text);
public final Function<String, Boolean> NOT_INCLUDE = s -> !s.contains(text);
private boolean include;
public SearchArgument(ArgumentType argumentType, String text, boolean include) {
this(argumentType, text, include, true);
}
public SearchArgument(ArgumentType argumentType, String text, boolean include, boolean autoLowerCase) {
this.argumentType = argumentType;
this.text = autoLowerCase ? text.toLowerCase(Locale.ROOT) : text;
this.include = include;
}
@Deprecated
public static String tryGetEntryStackName(EntryStack stack) {
if (stack.getType() == EntryStack.Type.ITEM)
return tryGetItemStackName(stack.getItemStack());
else if (stack.getType() == EntryStack.Type.FLUID)
return tryGetFluidName(stack.getFluid());
return "";
}
@Deprecated
public static String tryGetEntryStackTooltip(EntryStack stack) {
QueuedTooltip tooltip = stack.getTooltip(0, 0);
if (tooltip != null) return CollectionUtils.joinToString(tooltip.getText(), "\n");
return "";
}
@Deprecated
public static String tryGetFluidName(Fluid fluid) {
Identifier id = Registry.FLUID.getId(fluid);
if (I18n.hasTranslation("block." + id.toString().replaceFirst(":", ".")))
return I18n.translate("block." + id.toString().replaceFirst(":", "."));
return CollectionUtils.mapAndJoinToString(id.getPath().split("_"), StringUtils::capitalize, " ");
}
@Deprecated
public static List<String> tryGetItemStackToolTip(ItemStack itemStack, boolean careAboutAdvanced) {
if (!searchBlacklisted.contains(itemStack.getItem()))
try {
return CollectionUtils.map(itemStack.getTooltip(MinecraftClient.getInstance().player, MinecraftClient.getInstance().options.advancedItemTooltips && careAboutAdvanced ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL), Text::asFormattedString);
} catch (Throwable e) {
e.printStackTrace();
searchBlacklisted.add(itemStack.getItem());
}
return Collections.singletonList(tryGetItemStackName(itemStack));
}
@Deprecated
public static String tryGetItemStackName(ItemStack stack) {
if (!searchBlacklisted.contains(stack.getItem()))
try {
return stack.getName().asFormattedString();
} catch (Throwable e) {
e.printStackTrace();
searchBlacklisted.add(stack.getItem());
}
try {
return I18n.translate("item." + Registry.ITEM.getId(stack.getItem()).toString().replace(":", "."));
} catch (Throwable e) {
e.printStackTrace();
}
return "ERROR";
}
public Function<String, Boolean> getFunction(boolean include) {
return include ? INCLUDE : NOT_INCLUDE;
}
public ArgumentType getArgumentType() {
return argumentType;
}
public String getText() {
return text;
}
public boolean isInclude() {
return include;
}
@Override
public String toString() {
return String.format("Argument[%s]: name = %s, include = %b", argumentType.name(), text, include);
}
public enum ArgumentType {
TEXT,
MOD,
TOOLTIP,
TAG,
ALWAYS
}
@Deprecated
@Internal
public static class SearchArguments {
public static final SearchArguments ALWAYS = new SearchArguments(new SearchArgument[]{SearchArgument.ALWAYS});
private SearchArgument[] arguments;
public SearchArguments(SearchArgument[] arguments) {
this.arguments = arguments;
}
public SearchArgument[] getArguments() {
return arguments;
}
}
}
|