From afb86636f3a73a03e8a228a623af572c6df11830 Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Sun, 29 Dec 2024 16:02:32 +1100 Subject: [PATCH] Distance Filtering --- .../nomiceu/nomilabs/event/ClientProxy.java | 5 ++ .../integration/betterp2p/LabsFilters.java | 50 ++++++++++++++++ .../betterp2p/GuiAdvancedMemoryCardMixin.java | 30 +++++++++- .../mixin/betterp2p/InfoFilterMixin.java | 60 +++++++++++++++++++ .../nomiceu/nomilabs/util/LabsTranslate.java | 14 ++++- .../resources/assets/nomilabs/lang/en_us.lang | 7 +++ .../resources/mixins.nomilabs.betterp2p.json | 1 + 7 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsFilters.java create mode 100644 src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/InfoFilterMixin.java diff --git a/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java b/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java index eaff83bc..d5dbbc7c 100644 --- a/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java +++ b/src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java @@ -20,6 +20,7 @@ import com.nomiceu.nomilabs.NomiLabs; import com.nomiceu.nomilabs.fluid.registry.LabsFluids; import com.nomiceu.nomilabs.gregtech.block.registry.LabsMetaBlocks; +import com.nomiceu.nomilabs.integration.betterp2p.LabsFilters; import com.nomiceu.nomilabs.integration.betterp2p.ModeDescriptionsHandler; import com.nomiceu.nomilabs.integration.betterquesting.LabsTierHelper; import com.nomiceu.nomilabs.integration.findme.FindMeKeybindRegister; @@ -62,6 +63,10 @@ public static void postInit() { // Register Find Me's Fluid Keyubind if (Loader.isModLoaded(LabsValues.FIND_ME_MODID)) FindMeKeybindRegister.register(); + + // Register Better P2P Custom Filters + if (Loader.isModLoaded(LabsValues.BETTER_P2P_MODID)) + LabsFilters.postInit(); } @SubscribeEvent diff --git a/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsFilters.java b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsFilters.java new file mode 100644 index 00000000..cdb0772d --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsFilters.java @@ -0,0 +1,50 @@ +package com.nomiceu.nomilabs.integration.betterp2p; + +import java.util.List; + +import net.minecraftforge.common.util.EnumHelper; + +import com.projecturanus.betterp2p.client.gui.Filter; +import com.projecturanus.betterp2p.client.gui.InfoWrapper; + +import kotlin.jvm.functions.Function2; +import kotlin.text.Regex; + +public class LabsFilters { + + public static final Filter DISTANCE_LESS = addFilter("DISTANCE_LESS", + new Regex("\\A@distless=((\\d+(\\.\\d*)?)|(\\.\\d+))m?\\z"), (info, args) -> { + double distance = Double.MAX_VALUE; + + for (String arg : args) { + distance = Math.min(Double.parseDouble(arg), distance); + } + + return ((AccessibleInfoWrapper) (Object) info).labs$getDistance() <= distance; + }); + + public static final Filter DISTANCE_MORE = addFilter("DISTANCE_MORE", + new Regex("\\A@distmore=((\\d+(\\.\\d*)?)|(\\.\\d+))m?\\z"), (info, args) -> { + double distance = 0; + + for (String arg : args) { + distance = Math.max(Double.parseDouble(arg), distance); + } + + return ((AccessibleInfoWrapper) (Object) info).labs$getDistance() >= distance; + }); + + /** + * Essentially, this loads the class, allowing the above values to be added. + *
+ * If for some reason, the values are needed before this, they will still be loaded, and calling init will have no
+ * affect on that.
+ */
+ public static void postInit() {}
+
+ private static Filter addFilter(String name, Regex regex, Function2> cir) {
+ cir.setReturnValue(ImmutableList.of(
+ format(translate("nomilabs.gui.advanced_memory_card.filter.title"), BOLD, UNDERLINE),
+ "
- * If need Text Formatting format, place it in lang.
+ * Generally, if need Text Formatting format, place it in lang.
*/
+ public static String translateFormat(String key, TextFormatting format, Object... params) {
+ return format(translate(key, params), format);
+ }
+
public static String translateFormat(String key, TooltipHelper.GTFormatCode format, Object... params) {
return format(translate(key, params), format);
}
+ /**
+ * Generally, if need Text Formatting format, place it in lang.
+ */
+ public static String translateFormat(String key, Format format, Object... params) {
+ return format(translate(key, params), format);
+ }
+
public static String format(String str, TextFormatting... formats) {
return String.join("", Arrays.stream(formats).map(TextFormatting::toString).toArray(String[]::new)) + str +
TextFormatting.RESET;
diff --git a/src/main/resources/assets/nomilabs/lang/en_us.lang b/src/main/resources/assets/nomilabs/lang/en_us.lang
index eca6176b..a6ff3f72 100644
--- a/src/main/resources/assets/nomilabs/lang/en_us.lang
+++ b/src/main/resources/assets/nomilabs/lang/en_us.lang
@@ -175,6 +175,13 @@ nomilabs.gui.advanced_memory_card.hover_info.connections.output.none=§cNo Outpu
nomilabs.gui.advanced_memory_card.hover_info.connections.output.one=§a%s Output
nomilabs.gui.advanced_memory_card.hover_info.connections.output.multi=§b%s Outputs
+nomilabs.gui.advanced_memory_card.filter.title=Filtering Tags:
+nomilabs.gui.advanced_memory_card.filter.distless=Set a Maximum Distance
+nomilabs.gui.advanced_memory_card.filter.distmore=Set a Minimum Distance
+nomilabs.gui.advanced_memory_card.filter.type=Filter by Type
+nomilabs.gui.advanced_memory_card.filter.name=Filter by Name
+nomilabs.gui.advanced_memory_card.filter.end=Tags are Separated by Spaces.
+
nomilabs.gui.advanced_memory_card.sort.default=Sorting Mode: §bDefault
nomilabs.gui.advanced_memory_card.sort.distance=Sorting Mode: §bDistance
nomilabs.gui.advanced_memory_card.sort.name=Sorting Mode: §bName
diff --git a/src/main/resources/mixins.nomilabs.betterp2p.json b/src/main/resources/mixins.nomilabs.betterp2p.json
index 725b4627..781ac8d6 100644
--- a/src/main/resources/mixins.nomilabs.betterp2p.json
+++ b/src/main/resources/mixins.nomilabs.betterp2p.json
@@ -17,6 +17,7 @@
"ClientProxyMixin",
"GuiAdvancedMemoryCardKtAccessor",
"GuiAdvancedMemoryCardMixin",
+ "InfoFilterMixin",
"InfoListMixin",
"InfoWrapperMixin",
"ModeWidgetButtonMixin",