-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved ME Terminal Search to be more similar to REI/EMI (#7883)
This was created based on #7311, instead of relying on the functionality of JEI, REI, etc. I modified the search functionality to search similar to RS, JEI, etc. The reason behind this PR is the same reason as the previous PR (#7311): >This can be useful because it is annoying when you try to search something with the modid and the name like it is possible in JEI. For example "@ae2 crystal". Without it, it tries to search a mod with the name "ae2 crystal". --------- Co-authored-by: Sebastian Hartte <[email protected]>
- Loading branch information
1 parent
952a66c
commit 43a1e29
Showing
14 changed files
with
300 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/appeng/client/gui/me/search/AndSearchPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package appeng.client.gui.me.search; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import appeng.menu.me.common.GridInventoryEntry; | ||
|
||
final class AndSearchPredicate implements Predicate<GridInventoryEntry> { | ||
private final List<Predicate<GridInventoryEntry>> terms; | ||
|
||
private AndSearchPredicate(List<Predicate<GridInventoryEntry>> terms) { | ||
this.terms = terms; | ||
} | ||
|
||
public static Predicate<GridInventoryEntry> of(List<Predicate<GridInventoryEntry>> predicates) { | ||
if (predicates.isEmpty()) { | ||
return t -> true; | ||
} | ||
if (predicates.size() == 1) { | ||
return predicates.getFirst(); | ||
} | ||
return new AndSearchPredicate(predicates); | ||
} | ||
|
||
@Override | ||
public boolean test(GridInventoryEntry entry) { | ||
for (var term : terms) { | ||
if (!term.test(entry)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/appeng/client/gui/me/search/ItemIdSearchPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package appeng.client.gui.me.search; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
|
||
import appeng.api.stacks.AEKey; | ||
import appeng.menu.me.common.GridInventoryEntry; | ||
|
||
final class ItemIdSearchPredicate implements Predicate<GridInventoryEntry> { | ||
private final String term; | ||
|
||
public ItemIdSearchPredicate(String term) { | ||
this.term = term.toLowerCase(); | ||
} | ||
|
||
@Override | ||
public boolean test(GridInventoryEntry gridInventoryEntry) { | ||
AEKey what = Objects.requireNonNull(gridInventoryEntry.getWhat()); | ||
var id = what.getId().toString(); | ||
return id.toLowerCase(Locale.ROOT).contains(term); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/appeng/client/gui/me/search/ModSearchPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package appeng.client.gui.me.search; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
|
||
import appeng.api.stacks.AEKey; | ||
import appeng.menu.me.common.GridInventoryEntry; | ||
import appeng.util.Platform; | ||
|
||
final class ModSearchPredicate implements Predicate<GridInventoryEntry> { | ||
private final String term; | ||
|
||
public ModSearchPredicate(String term) { | ||
this.term = normalize(term); | ||
} | ||
|
||
@Override | ||
public boolean test(GridInventoryEntry gridInventoryEntry) { | ||
AEKey entryInfo = Objects.requireNonNull(gridInventoryEntry.getWhat()); | ||
String modId = entryInfo.getModId(); | ||
|
||
if (modId != null) { | ||
if (modId.contains(term)) { | ||
return true; | ||
} | ||
|
||
String modName = Platform.getModName(modId); | ||
modName = normalize(modName); | ||
return modName.contains(term); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static String normalize(String input) { | ||
return input.toLowerCase(Locale.ROOT); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/appeng/client/gui/me/search/NameSearchPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package appeng.client.gui.me.search; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
|
||
import appeng.api.stacks.AEKey; | ||
import appeng.menu.me.common.GridInventoryEntry; | ||
|
||
final class NameSearchPredicate implements Predicate<GridInventoryEntry> { | ||
private final String term; | ||
|
||
public NameSearchPredicate(String term) { | ||
this.term = term.toLowerCase(); | ||
} | ||
|
||
@Override | ||
public boolean test(GridInventoryEntry gridInventoryEntry) { | ||
AEKey entryInfo = Objects.requireNonNull(gridInventoryEntry.getWhat()); | ||
String displayName = entryInfo.getDisplayName().getString(); | ||
return displayName.toLowerCase().contains(term); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/appeng/client/gui/me/search/OrSearchPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package appeng.client.gui.me.search; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import appeng.menu.me.common.GridInventoryEntry; | ||
|
||
final class OrSearchPredicate implements Predicate<GridInventoryEntry> { | ||
private final List<Predicate<GridInventoryEntry>> terms; | ||
|
||
private OrSearchPredicate(List<Predicate<GridInventoryEntry>> terms) { | ||
this.terms = terms; | ||
} | ||
|
||
public static Predicate<GridInventoryEntry> of(List<Predicate<GridInventoryEntry>> filters) { | ||
if (filters.isEmpty()) { | ||
return t -> false; | ||
} | ||
if (filters.size() == 1) { | ||
return filters.getFirst(); | ||
} | ||
return new OrSearchPredicate(filters); | ||
} | ||
|
||
@Override | ||
public boolean test(GridInventoryEntry entry) { | ||
for (var term : terms) { | ||
if (term.test(entry)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.