allow searching by item description

Closes #90
This commit is contained in:
Ell 2021-12-04 13:35:04 +01:00
parent c06097f287
commit d240e03209

View file

@ -22,6 +22,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import java.util.*; import java.util.*;
@ -229,8 +230,15 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
var search = searchText; var search = searchText;
String toCompare; String toCompare;
if (search.startsWith("@")) { if (search.startsWith("@")) {
// search mod id
toCompare = s.getLeft().getItem().getCreatorModId(s.getLeft()); toCompare = s.getLeft().getItem().getCreatorModId(s.getLeft());
search = search.substring(1); search = search.substring(1);
} else if (search.startsWith("#")) {
// search item description
var hoverText = s.getLeft().getTooltipLines(this.minecraft.player,
this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL);
toCompare = hoverText.stream().map(Component::getString).collect(Collectors.joining("\n"));
search = search.substring(1);
} else { } else {
// don't use formatted text here since we want to search for name // don't use formatted text here since we want to search for name
toCompare = s.getLeft().getDisplayName().getString(); toCompare = s.getLeft().getDisplayName().getString();