aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/impl/SearchArgument.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/shedaniel/rei/impl/SearchArgument.java')
-rw-r--r--src/main/java/me/shedaniel/rei/impl/SearchArgument.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/impl/SearchArgument.java b/src/main/java/me/shedaniel/rei/impl/SearchArgument.java
index 7771ad8e4..74d4bf8fc 100644
--- a/src/main/java/me/shedaniel/rei/impl/SearchArgument.java
+++ b/src/main/java/me/shedaniel/rei/impl/SearchArgument.java
@@ -5,8 +5,24 @@
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;
@@ -15,6 +31,8 @@ import java.util.function.Function;
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);
@@ -31,6 +49,59 @@ public class SearchArgument {
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;
}
@@ -59,4 +130,19 @@ public class SearchArgument {
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;
+ }
+ }
+
}