Skip to content

Commit

Permalink
LoreLocator - Added split queries option for metadata search.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed Aug 6, 2024
1 parent 7061bc1 commit ede7c8f
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/main/java/dev/stardust/modules/LoreLocator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.stardust.modules;

import java.util.Arrays;
import java.util.HashMap;
import dev.stardust.Stardust;
import net.minecraft.screen.*;
Expand Down Expand Up @@ -114,6 +115,14 @@ public class LoreLocator extends Module {
.build()
);

private final Setting<Boolean> splitQueries = settings.getDefaultGroup().add(
new BoolSetting.Builder()
.name("Split Queries")
.description("Split search queries into multiple items separated by commas. Disable to treat commas literally in the search instead.")
.defaultValue(true)
.build()
);

public final Setting<SettingColor> color = settings.getDefaultGroup().add(
new ColorSetting.Builder()
.name("Highlight Color")
Expand Down Expand Up @@ -161,13 +170,25 @@ public boolean shouldHighlightSlot(ItemStack stack) {
NbtCompound metadata = stack.getNbt();
String query = metadataSearch.get().toLowerCase();

if (metadata != null) {
if (metadata.toString().toLowerCase().contains(query)) return true;
else if (metadata.toString().toLowerCase().contains(query.replace(" ", "_"))) return true;
}
if (splitQueries.get() && query.contains(",")) {
String[] queries = query.split(",");

if (stack.getName().getString().toLowerCase().contains(query)) return true;
else if (stack.getItem().getDefaultStack().getName().getString().toLowerCase().contains(query)) return true;
if (metadata != null && Arrays.stream(queries).anyMatch(q -> metadata.toString().toLowerCase().contains(q.trim())
|| metadata.toString().toLowerCase().contains(q.trim().replace(" ", "_")))) {
return true;
} else if (Arrays.stream(queries).anyMatch(q -> stack.getName().getString().toLowerCase().contains(q.trim())
|| stack.getItem().getDefaultStack().getName().getString().toLowerCase().contains(q.trim()))) {
return true;
}
} else {
if (metadata != null) {
if (metadata.toString().toLowerCase().contains(query.trim())) return true;
else if (metadata.toString().toLowerCase().contains(query.trim().replace(" ", "_"))) return true;
}

if (stack.getName().getString().toLowerCase().contains(query.trim())) return true;
else if (stack.getItem().getDefaultStack().getName().getString().toLowerCase().contains(query.trim())) return true;
}
}

if (!renamedShulks.get() && stack.hasCustomName()) {
Expand Down

0 comments on commit ede7c8f

Please sign in to comment.